Commit 15e1d11b by chamberone

Merge branch 'develop' of https://zhangguoping@gitlab.dituhui.com/bsh/project/pr…

…oject.git into develop
2 parents b78322c4 da048815
Showing with 387 additions and 228 deletions
......@@ -2,13 +2,13 @@ package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.CalendarDetailDTO;
import com.dituhui.pea.order.dto.EngineerCalendarDTO;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.service.EngineerCalendarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -46,11 +46,54 @@ public class EngineerCalendarController {
public Result<?> getCalendarPlanDetail(@Validated CalendarDetailDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerCalendarService.getCalendarPlanDetail(reqDTO);
res = engineerCalendarService.getPlanDetail(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
@PostMapping("/engineer/calendar/plan/update")
public Result<?> updateCalendarPlan(@Validated CalendarUpdateDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerCalendarService.updatePlan(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
@PostMapping("/engineer/calendar/plan/delete")
public Result<?> deleteCalendarPlan(@Validated CalendarDeleteDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerCalendarService.deletePlan(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
@PostMapping("/engineer/calendar/batch/add")
public Result<?> BatchAddPlan(@Validated CalendarBatAddDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerCalendarService.batchAddPlan(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
@GetMapping("/engineer/calendar/plan/num")
public Result<?> getEngineerPlanNum(@Validated CalendarQueryNumDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerCalendarService.queryEngineerPlanNum(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
......@@ -4,10 +4,17 @@ import com.dituhui.pea.order.entity.CapacityEngineerCalendarEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
public interface CapacityEngineerCalendarDao extends JpaRepository<CapacityEngineerCalendarEntity, Integer> {
@Query("select a from CapacityEngineerCalendarEntity a where a.engineerCode=:engineerCode and a.workday between :beginDate and :endDate")
List<CapacityEngineerCalendarEntity> findCalendarByEngineerCodeAndDateBetween(String engineerCode, String beginDate, String endDate);
CapacityEngineerCalendarEntity getByPlanId(String planId);
@Query("select count(*) from CapacityEngineerCalendarEntity a where a.type = :type and a.startTime >= :startDate and a.endTime <= :endDate and a.engineerCode in :engineers")
Integer queryEngineerPlanNum(List<String> engineers, LocalDateTime startDate, LocalDateTime endDate, String type);
}
......@@ -10,13 +10,12 @@ import java.util.List;
public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long> {
OrderInfoEntity getByOrderId(String orderId);
OrderInfoEntity getByOrderIdAndDt(String orderId, LocalDate dt);
List<OrderInfoEntity> findByOrderId(String orderId);
List<OrderInfoEntity> findByDtAndEngineerCodeIn(LocalDate date, List<String> engineerCodes);
List<OrderInfoEntity> findByDtAndEngineerCode(LocalDate date, String engineerCode);
@Query("SELECT o.orderId, s.skillCategory as skillCaption FROM OrderInfoEntity o JOIN SkillInfoEntity s on o.brand=s.brand and o.type=s.type and o.skill=s.skill WHERE o.orderId = :orderId")
OrderSkillProjection getOrderSkillCaptionByOrderId(String orderId);
List<OrderInfoEntity> findAllByOrderIdIn(List<String> orderIds);
List<OrderInfoEntity> findAllByDtAndOrderIdIn(LocalDate dt, List<String> orderIds);
List<OrderInfoEntity> findByEngineerCodeAndDtAndAppointmentStatusIn(String engineerCode, LocalDate dt, List<String> appointmentStatus);
}
......@@ -15,6 +15,8 @@ public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> {
List<OrgGroupEntity> findAllByClusterId(String clusterId);
List<OrgGroupEntity> findAllByGroupId(String groupId);
OrgGroupEntity getByGroupId(String groupId);
public List<OrgGroupEntity> findByGroupIdIn(List<String> ids);
......
......@@ -22,6 +22,9 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer> {
@Query("select t from OrgTeamEntity t where t.groupId = :groupId and t.status=1")
List<OrgTeamEntity> findAllByGroupId(String groupId);
@Query("select t from OrgTeamEntity t where t.teamId = :teamId and t.status=1")
List<OrgTeamEntity> findAllByTeamId(String teamId);
@Query("select t from OrgTeamEntity t where t.groupId = :groupId and t.status=1")
Page<OrgTeamEntity> findAllByGroupId(String groupId, Pageable pageable);
......
......@@ -23,4 +23,6 @@ public interface WarehouseInfoDao extends JpaRepository<OrgWarehouseInfoEntity,
OrgWarehouseInfoEntity getOrgWarehouseInfoEntityByWarehouseId(String wareHouseId);
List<OrgWarehouseInfoEntity> findByBranchId(String branchId);
}
package com.dituhui.pea.order.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import java.util.List;
import static com.dituhui.pea.order.config.OrderConfig.DEFAULT_PAGE_SIZE;
......@@ -44,10 +39,8 @@ public class BusinessSkillListDTO {
public static class Content {
private String brand;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
private String createTime;
private Boolean gasCert;
private String layerId;
private String layerName;
......@@ -64,9 +57,7 @@ public class BusinessSkillListDTO {
private String type;
private String typeCategory;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
private String updateTime;
}
}
package com.dituhui.pea.order.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
public class CalendarDetailDTO {
@lombok.Data
......@@ -30,20 +24,14 @@ public class CalendarDetailDTO {
private String type;
private String typeName;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
private String startTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
private String endTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
private String updateTime;
}
}
package com.dituhui.pea.order.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.List;
public class CalendarQueryNumDTO {
@lombok.Data
public static class Request {
private String code;
private String message;
private Result result;
private List<String> engineerCodes;
private String type;
@JsonFormat(pattern = "yyyy-MM-dd")
private String startDate;
@JsonFormat(pattern = "yyyy-MM-dd")
private String endDate;
}
@lombok.Data
......
package com.dituhui.pea.order.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
public class CapacityAdjustDTO {
......@@ -20,15 +13,11 @@ public class CapacityAdjustDTO {
@NotNull(message = "teamId不能为空")
private String teamId;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
private String startDate;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
private String endDate;
private Integer capAdjust;
}
......
package com.dituhui.pea.order.dto;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.config.OrderConfig;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
......@@ -54,10 +51,8 @@ public class CapacityStatQueryDTO {
private long capUsed;
private long capLeft;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
private String updateTime;
private String date;
private long engineerNum;
......@@ -67,7 +62,7 @@ public class CapacityStatQueryDTO {
private String showName;
public Content(){
updateTime = LocalDateTime.now();
updateTime = DateUtils.formatDateTime(LocalDateTime.now());
}
}
}
......@@ -4,13 +4,8 @@ package com.dituhui.pea.order.dto;
import com.dituhui.pea.order.config.OrderConfig;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.experimental.Accessors;
import java.time.LocalDate;
import java.util.List;
......@@ -25,10 +20,8 @@ public class EngineersGanttDTO {
private Integer page = OrderConfig.DEFAULT_PAGE_INDEX;
private Integer size = OrderConfig.DEFAULT_PAGE_SIZE;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate date;
private String date;
private List<String> engineerCodes;
private List<String> branchIds;
private List<String> groupIds;
......
......@@ -3,14 +3,9 @@ package com.dituhui.pea.order.dto;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.config.OrderConfig;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.experimental.Accessors;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
......@@ -30,7 +25,7 @@ public class OrderChangeListDTO {
private String levelValue;
private int page = OrderConfig.DEFAULT_PAGE_INDEX;
private int size = OrderConfig.DEFAULT_PAGE_SIZE;
private String date = DateUtils.formatDate(LocalDate.now(), PATTERN_DATE);
private String date = DateUtils.formatDate(LocalDate.now());
/**
* 排序
*/
......@@ -73,9 +68,7 @@ public class OrderChangeListDTO {
/**
* 更新时间
*/
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
private String updateTime;
}
}
......@@ -27,6 +27,10 @@ public class CapacityEngineerCalendarEntity {
@Column(name = "end_time", nullable = false)
private LocalDateTime endTime;
@Column(name = "plan_id")
private String planId;
@Column(nullable = false)
private String type;
......
package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.CalendarDetailDTO;
import com.dituhui.pea.order.dto.EngineerCalendarDTO;
import com.dituhui.pea.order.dto.*;
public interface EngineerCalendarService {
......@@ -10,5 +9,13 @@ public interface EngineerCalendarService {
Result<?> getCalendarTypeList();
Result<?> getCalendarPlanDetail(CalendarDetailDTO.Request reqDTO);
Result<?> getPlanDetail(CalendarDetailDTO.Request reqDTO);
Result<?> updatePlan(CalendarUpdateDTO.Request reqDTO);
Result<?> deletePlan(CalendarDeleteDTO.Request reqDTO);
Result<?> batchAddPlan(CalendarBatAddDTO.Request reqDTO);
Result<?> queryEngineerPlanNum(CalendarQueryNumDTO.Request reqDTO);
}
......@@ -5,9 +5,7 @@ import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.CalendarDetailDTO;
import com.dituhui.pea.order.dto.CalendarTypeDTO;
import com.dituhui.pea.order.dto.EngineerCalendarDTO;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.CapacityEngineerCalendarEntity;
import com.dituhui.pea.order.entity.EngineerInfoEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity;
......@@ -99,8 +97,8 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
}
@Override
public Result<?> getCalendarPlanDetail(CalendarDetailDTO.Request reqDTO) {
CapacityEngineerCalendarEntity entity = capacityEngineerCalendarDao.getById(Integer.parseInt(reqDTO.getPlanId()));
public Result<?> getPlanDetail(CalendarDetailDTO.Request reqDTO) {
CapacityEngineerCalendarEntity entity = capacityEngineerCalendarDao.getByPlanId(reqDTO.getPlanId());
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(entity.getEngineerCode());
CalendarDetailDTO.Result rs = new CalendarDetailDTO.Result();
rs.setPlanId(entity.getId().toString());
......@@ -108,11 +106,71 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
rs.setEngineerName(engineerInfo.getName());
rs.setType(entity.getType());
rs.setTypeName(entity.getReason());
rs.setStartTime(entity.getStartTime());
rs.setEndTime(entity.getEndTime());
rs.setStartTime(DateUtils.formatDateTime(entity.getStartTime()));
rs.setEndTime(DateUtils.formatDateTime(entity.getEndTime()));
return Result.success(rs);
}
@Override
public Result<?> updatePlan(CalendarUpdateDTO.Request reqDTO) {
CapacityEngineerCalendarEntity entity = capacityEngineerCalendarDao.getByPlanId(reqDTO.getPlanId());
if (entity == null) {
return Result.failed("日历配置信息不存在");
}
// todo 业务检查,暂时只需要检查日期时间必须为将来; 后面还需要检查配置项是否与其他配置项在时间上有交叉
LocalDateTime time1 = fixFrontDatetime(reqDTO.getStartTime());
LocalDateTime time2 = fixFrontDatetime(reqDTO.getEndTime());
if (time1.isAfter(time2)) {
return Result.failed("开始/结束时间输入错误");
}
if (time1.isBefore(LocalDateTime.now()) || time2.isBefore(LocalDateTime.now())) {
return Result.failed("只能更新未来时间");
}
entity.setStartTime(time1);
entity.setEndTime(time2);
entity.setMemo(reqDTO.getRemark());
// todo 操作员信息
capacityEngineerCalendarDao.save(entity);
return Result.success(null);
}
@Override
public Result<?> deletePlan(CalendarDeleteDTO.Request reqDTO) {
CapacityEngineerCalendarEntity entity = capacityEngineerCalendarDao.getByPlanId(reqDTO.getPlanId());
if (entity == null) {
return Result.failed("日历配置信息不存在");
}
capacityEngineerCalendarDao.delete(entity);
return Result.success(null);
}
@Override
public Result<?> batchAddPlan(CalendarBatAddDTO.Request reqDTO) {
if (reqDTO.getIsAllday() == 1) {
// 如果是全天只需要填写日期yyyy-MM-dd;否则填写日期+时间 yyyy-MM-dd HH:mm
}
return null;
}
@Override
public Result<?> queryEngineerPlanNum(CalendarQueryNumDTO.Request reqDTO) {
if (reqDTO.getEngineerCodes().isEmpty()) {
return Result.failed("没有选中工程师");
}
LocalDateTime startDate = LocalDate.parse(reqDTO.getStartDate()).atTime(LocalTime.MIDNIGHT);
LocalDateTime endDate = LocalDate.parse(reqDTO.getEndDate()).atTime(LocalTime.MIDNIGHT);
Integer num = capacityEngineerCalendarDao.queryEngineerPlanNum(reqDTO.getEngineerCodes(), startDate, endDate, reqDTO.getType());
CalendarQueryNumDTO.Result rs = new CalendarQueryNumDTO.Result();
rs.setPlanNum(num);
return Result.success(rs);
}
private LocalDateTime fixFrontDatetime(String s) {
return LocalDateTime.parse(s);
}
private List<EngineerCalendarDTO.Calendar> getOneEngineerCalendars(String engineerCode, String bdate, String edate) {
// 返回某一个技术员,日期范围内的日历列表
......@@ -139,6 +197,7 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
// 有配置
for (CapacityEngineerCalendarEntity e : configs.get(sDate)) {
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
content.setPlanId(e.getPlanId());
content.setType("LEAVE");
content.setTitle(e.getType());
content.setValue(getCalendarDuration(e.getStartTime(), e.getEndTime()));
......@@ -186,17 +245,11 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
calendar.setWeek(DateUtils.toWeekChinese(dayOfWeek));
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
List<String> workdays = Arrays.asList(e.getWorkdays().split(","));
if (workdays.contains(String.valueOf(dayOfWeek))) {
content.setType("WORKING");
content.setTitle(String.format("%s-%s", e.getWorkOn(), e.getWorkOff()));
content.setValue(getCalendarDuration(e.getWorkOn(), e.getWorkOff()));
} else {
if (!workdays.contains(String.valueOf(dayOfWeek))) {
content.setType("REST");
content.setTitle("休息");
}
calendar.setContent(Collections.singletonList(content));
return calendar;
}
}
......@@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -46,13 +47,13 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
// 按日期返回技术员们当天的服务甘特图,不需要翻页
log.info("getEngineersGanttList: {}", reqDTO);
List<String> engineerCodes = reqDTO.getEngineerCodes();
if (engineerCodes == null || engineerCodes.size() == 0) {
if (engineerCodes == null || engineerCodes.isEmpty()) {
// 需要根据levelType/levelValue/brandIds/branchIds/groupIds/teamIds/key,后端查询匹配
engineerCodes = findEngineers(reqDTO.getLevelType(), reqDTO.getLevelValue(), reqDTO.getBranchIds(), reqDTO.getGroupIds(), reqDTO.getTeamIds(), reqDTO.getKey());
log.info("根据多条件,查询返回符合条件的技术员列表:{}", engineerCodes);
}
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndEngineerCodeIn(reqDTO.getDate(), engineerCodes);
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndEngineerCodeIn(LocalDate.parse(reqDTO.getDate()), engineerCodes);
HashMap<String, List<EngineersGanttDTO.Slot>> mapEngineers = new HashMap<>();
for (OrderInfoEntity order : orders) {
// 服务工单本体
......@@ -117,7 +118,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
.setEngineerName(engineerInfo.getName())
.setGrade(engineerInfo.getGrade());
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByWorkdayAndEngineerCode(DateUtils.formatDate(reqDTO.getDate()), engineerCode);
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByWorkdayAndEngineerCode(reqDTO.getDate(), engineerCode);
if (capacityEngineerStat == null) {
log.warn("技术员当日的容量数据不存在,{}{}", engineerCode, reqDTO.getDate());
} else {
......@@ -133,7 +134,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
engineers.sort(Comparator.comparing(EngineersGanttDTO.GanttChart::getEngineerName));
EngineersGanttDTO.Result res = new EngineersGanttDTO.Result();
res.setDate(DateUtils.formatDate(reqDTO.getDate())).setEngineers(engineers);
res.setDate(reqDTO.getDate()).setEngineers(engineers);
return Result.success(res);
}
......
......@@ -11,6 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
......@@ -21,19 +27,19 @@ import java.util.stream.Stream;
public class EngineerTimelineServiceImpl implements EngineerTimelineService {
@Autowired
private OrderInfoMPDao orderInfoMPDao;
private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
private EngineerInfoDao engineerInfoDao;
@Autowired
private WarehouseInfoMPDao warehouseInfoMPDao;
private WarehouseInfoDao warehouseInfoDao;
@Autowired
private OrgGroupMPDao orgGroupMPDao;
private OrgGroupDao orgGroupDao;
@Autowired
private OrderEventMPDao orderEventMPDao;
private EntityManager entityManager;
@Transactional
@Override
......@@ -42,14 +48,14 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
LocalDate localDate = TimeUtils.IsoDate2LocalDate(date);
// 工程師信息
EngineerInfo engineerInfo = engineerInfoMPDao.getByEngineerCode(engineerCode);
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(engineerCode);
// 获取工程师date日的订单数据
List<OrderInfo> orders = this.selectEngineerOrders(engineerCode, localDate);
List<OrderInfoEntity> orders = this.selectEngineerOrders(engineerCode, localDate);
// 获取工程师已完成的timeline数据
List<String> orderIds = orders.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
List<OrderEvent> timelines = this.engineerTimelines(orderIds, date);
List<String> orderIds = orders.stream().map(OrderInfoEntity::getOrderId).collect(Collectors.toList());
List<OrderEventEntity> timelines = this.engineerTimelines(orderIds, date);
// 获取客户地址
HashMap<String, String> orderLocations = this.orderRequestsLocation(orders);
......@@ -67,30 +73,39 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
return Result.success(res);
}
private List<OrderInfo> selectEngineerOrders(String engineerCode, LocalDate dt){
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, dt);
lqw.eq(OrderInfo::getEngineerCode, engineerCode);
lqw.ne(OrderInfo::getAppointmentStatus, "INIT");
lqw.ne(OrderInfo::getOrderStatus, "CANCEL");
return orderInfoMPDao.selectList(lqw);
private List<OrderInfoEntity> selectEngineerOrders(String engineerCode, LocalDate dt){
List<OrderInfoEntity> orders = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
engineerCode, dt, List.of("PRE", "CONFIRM"));
return orders.stream().filter(o -> !o.getOrderStatus().equals("CANCEL")).collect(Collectors.toList());
}
private List<OrderEvent> engineerTimelines(List<String> orderIds, String date){
// 获取工程师timeline
List<String> events = Stream.of("分站取还配件", "已出发", "加单").collect(Collectors.toList());
LambdaQueryWrapper<OrderEvent> lqw = new LambdaQueryWrapper<>();
lqw.in(OrderEvent::getOrderId, orderIds);
lqw.ge(OrderEvent::getHappen, date+" 00:00:00");
lqw.le(OrderEvent::getHappen, date + " 23:59:59");
lqw.in(OrderEvent::getEvent, events);
return orderEventMPDao.selectList(lqw);
public List<OrderEventEntity> engineerTimelines(List<String> orderIds, String date) {
List<String> events = Arrays.asList("分站取还配件", "已出发", "加单");
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<OrderEventEntity> criteriaQuery = criteriaBuilder.createQuery(OrderEventEntity.class);
Root<OrderEvent> root = criteriaQuery.from(OrderEvent.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(root.get("orderId").in(orderIds));
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("happen"), date + " 00:00:00"));
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("happen"), date + " 23:59:59"));
predicates.add(root.get("event").in(events));
criteriaQuery.where(predicates.toArray(new Predicate[0]));
TypedQuery<OrderEventEntity> typedQuery = entityManager.createQuery(criteriaQuery);
List<OrderEventEntity> result = typedQuery.getResultList();
return result;
}
private HashMap<String, String> orderRequestsLocation(List<OrderInfo> orders) {
private HashMap<String, String> orderRequestsLocation(List<OrderInfoEntity> orders) {
// 获取客户地址location
HashMap<String, String> map = new HashMap<>();
for(OrderInfo o: orders){
for(OrderInfoEntity o: orders){
map.put(o.getOrderId(), String.format("%s,%s", o.getX(), o.getY()));
}
return map;
......@@ -98,38 +113,30 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
private String getWarehouseLocation(String branchId) {
// 获取配送站location
LambdaQueryWrapper<OrgWarehouseInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrgWarehouseInfo::getBranchId, branchId);
List<OrgWarehouseInfo> wares = warehouseInfoMPDao.selectList(lqw);
OrgWarehouseInfo w = wares.get(0);
List<OrgWarehouseInfoEntity> wares = warehouseInfoDao.findByBranchId(branchId);
OrgWarehouseInfoEntity w = wares.get(0);
return String.format("%s,%s", w.getX(), w.getY());
}
private String getEngineerBranchId(String engineerCode) {
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.select(EngineerInfo::getGroupId);
lqw.eq(EngineerInfo::getEngineerCode, engineerCode);
EngineerInfo e = engineerInfoMPDao.selectOne(lqw);
EngineerInfoEntity e = engineerInfoDao.getByEngineerCode(engineerCode);
if (e == null) {
return "";
}
LambdaQueryWrapper<OrgGroup> lqw2 = new LambdaQueryWrapper<>();
lqw2.select(OrgGroup::getBranchId);
lqw2.eq(OrgGroup::getGroupId, e.getGroupId());
OrgGroup g = orgGroupMPDao.selectOne(lqw2);
OrgGroupEntity g = orgGroupDao.getByGroupId(e.getGroupId());
return (g==null)? "": g.getBranchId();
}
private List<EngineerTimelineResp.DynamicItem> packItems(List<OrderEvent> timelines, List<OrderInfo> orders, HashMap<String, String> locations, String warehouseLocation) {
private List<EngineerTimelineResp.DynamicItem> packItems(List<OrderEventEntity> timelines, List<OrderInfoEntity> orders,
HashMap<String, String> locations, String warehouseLocation) {
int index = 0;
String order_id, title, type, text, location;
List<EngineerTimelineResp.DynamicItem> items = new ArrayList<>();
Set<String> s = new HashSet<>();
for (OrderEvent t: timelines){
for (OrderEventEntity t: timelines){
EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem();
if (t.getEvent().equals("分站取还配件")) {
......@@ -146,7 +153,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
continue;
}
item.setTitle(title);
item.setTime(TimeUtils.IsoTimestamp2DateTime(t.getHappen()));
item.setTime(TimeUtils.IsoLocalDateTime2String(t.getHappen()));
item.setStatus(1);
item.setText(text);
......@@ -157,8 +164,8 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
s.add(t.getOrderId() + t.getSuborderId());
}
List<OrderInfo> records = orders.stream().sorted(Comparator.comparing(OrderInfo::getPlanStartTime)).collect(Collectors.toList());
for(OrderInfo o: records){
List<OrderInfoEntity> records = orders.stream().sorted(Comparator.comparing(OrderInfoEntity::getPlanStartTime)).collect(Collectors.toList());
for(OrderInfoEntity o: records){
order_id = o.getOrderId() + o.getSubId();
if (s.contains(order_id)) {
continue;
......@@ -166,7 +173,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
index += 1;
EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem();
item.setTitle(String.format("第%d单出发", index));
item.setTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanStartTime()));
item.setTime(TimeUtils.IsoLocalDateTime2String(o.getPlanStartTime()));
item.setStatus(0);
item.setText(String.format("%d", index));
item.setLocation(locations.get(o.getOrderId()));
......
......@@ -210,9 +210,9 @@ public class OrderCreateServiceImpl implements OrderCreateService {
OrderAssignCheck.Result checkResult = null;
log.info("=== 准备调用指派,候选的技术员列表: {}", matchEngineerCodes);
for (String engineerCode : matchEngineerCodes) {
checkResult = orderAssignCheck.orderAssignCheck(entity.getOrderId(), engineerCode);
checkResult = orderAssignCheck.orderAssignCheck(entity.getOrderId(), entity.getDt(), engineerCode);
log.info("orderAssignCheck ===> orderId[{}]engineerCode[{}] ==> result[{}]", entity.getOrderId(), engineerCode, checkResult);
if (checkResult.getCanAssign()) {
if (checkResult.getIndex() < 0) {
assignEngineerCode = engineerCode;
break;
}
......@@ -221,16 +221,18 @@ public class OrderCreateServiceImpl implements OrderCreateService {
// 虚拟指派
if (StringUtils.isNotBlank(assignEngineerCode)) {
// 修改当前工单
OrderAssignCheck.OrderNode insertNode = checkResult.getCurOrderNode();
entity.setEngineerCode(assignEngineerCode);
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode);
entity.setEngineerName(engineerInfo.getName());
entity.setEngineerPhone(engineerInfo.getPhone());
entity.setAppointmentStatus("PRE");
entity.setDispatcher("AUTO_NOW");
entity.setPlanStartTime(checkResult.getStart());
entity.setPlanEndTime(checkResult.getEnd());
entity.setArriveDistance(checkResult.getDistanceAddition());
entity.setArriveElapsed(checkResult.getMinuteAddition());
entity.setPlanStartTime(insertNode.getPlanStartTime());
entity.setPlanEndTime(insertNode.getPlanEndTime());
entity.setArriveDistance(checkResult.getAdditionDistance());
entity.setArriveElapsed(checkResult.getAdditionElapsed());
orderInfoDao.save(entity);
// 如果影响到原有工单,修改原有工单
......
......@@ -28,10 +28,10 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgBranchMPDao orgBranchMPDao;
private OrgBranchDao orgBranchDao;
@Transactional
@Override
......@@ -167,8 +167,8 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
if(engineerCodes.isEmpty()){
return new HashMap<>();
}
List<EngineerInfo> engineers = engineerInfoMPDao.selectByEngineerCodes(new ArrayList<>(engineerCodes));
return engineers.stream().collect(Collectors.toMap(EngineerInfo::getEngineerCode, EngineerInfo::getName));
List<EngineerInfoEntity> engineers = engineerInfoDao.findByEngineerCodeIn(new ArrayList<>(engineerCodes));
return engineers.stream().collect(Collectors.toMap(EngineerInfoEntity::getEngineerCode, EngineerInfoEntity::getName));
}
private Map<String, String> getBranchNames(List<OrderInfo> orders){
......@@ -182,10 +182,8 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
if(branches.isEmpty()){
return new HashMap<>();
}
LambdaQueryWrapper<OrgBranch> lqw = new LambdaQueryWrapper<>();
lqw.in(OrgBranch::getBranchId, new ArrayList<>(branches));
List<OrgBranch> records = orgBranchMPDao.selectList(lqw);
return records.stream().collect(Collectors.toMap(OrgBranch::getBranchId, OrgBranch::getBranchName));
List<OrgBranchEntity> records = orgBranchDao.findByBranchIdIn(new ArrayList<>(branches));
return records.stream().collect(Collectors.toMap(OrgBranchEntity::getBranchId, OrgBranchEntity::getBranchName));
}
private List<String> getOrderEngineerNames(String engineerCode, String engineerCodeSub, Map<String,String> engineerNames){
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.CapacityAdjustDTO;
import com.dituhui.pea.order.dto.CapacityStatQueryDTO;
......@@ -87,7 +88,7 @@ public class OrgCapacityServiceImpl implements OrgCapacityService {
.setCapUsed(e.getCapUsedTotal())
.setCapLeft(e.getCapLeft())
.setEngineerNum(e.getEngineerCount())
.setUpdateTime(e.getUpdateTime());
.setUpdateTime(DateUtils.formatDateTime(e.getUpdateTime()));
} else {
// group查询,是capacity_team_stat
CapacityTeamStatEntity e = (CapacityTeamStatEntity) item;
......@@ -102,7 +103,7 @@ public class OrgCapacityServiceImpl implements OrgCapacityService {
.setCapLeft(e.getCapLeft())
.setCapAdjust(e.getCapAdjust())
.setEngineerNum(e.getEngineerCount())
.setUpdateTime(e.getUpdateTime());
.setUpdateTime(DateUtils.formatDateTime(e.getUpdateTime()));
}
contents.add(content);
}
......@@ -115,12 +116,13 @@ public class OrgCapacityServiceImpl implements OrgCapacityService {
@Override
public Result<?> adjustCapacity(CapacityAdjustDTO.Request reqDTO) {
if (reqDTO.getStartDate().isBefore(LocalDate.now())) {
if (LocalDate.parse(reqDTO.getStartDate()).isBefore(LocalDate.now())) {
return Result.failed("日期不能小于当天");
}
// 遍历 startDate 到 endDate 之间的所有日期
LocalDate currentDate = reqDTO.getStartDate();
while (!currentDate.isAfter(reqDTO.getEndDate())) {
LocalDate currentDate = LocalDate.parse(reqDTO.getStartDate());
LocalDate endDate = LocalDate.parse(reqDTO.getEndDate());
while (!currentDate.isAfter(endDate)) {
float adjuest = (float) (reqDTO.getCapAdjust() / 100.0);
ajustCapacityByDate(reqDTO.getTeamId(), currentDate, adjuest);
currentDate = currentDate.plusDays(1); // 增加一天
......
......@@ -27,16 +27,22 @@ public class ScheduleServiceImpl implements ScheduleService {
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private OrgTeamMPDao orgTeamMPDao;
@Autowired
private OrgTeamEngineerMPDao orgTeamEngineerMPDao;
private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired
private OrgGroupMPDao orgGroupMPDao;
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private SkillInfoMPDao skillInfoMPDao;
......@@ -97,18 +103,19 @@ public class ScheduleServiceImpl implements ScheduleService {
}
// 获取team技术员列表
List<OrgTeamEngineer> teamEngineers = this.queryOrgTeamEngineers(t.getTeamId());
List<String> engineerCodes = teamEngineers.stream().map(OrgTeamEngineer::getEngineerCode).collect(Collectors.toList());
List<EngineerInfo> engineerInfoList = engineerInfoMPDao.selectByEngineerCodes(engineerCodes);
Map<String, List<EngineerInfo>> engineers = engineerInfoList.stream().collect(Collectors.groupingBy(EngineerInfo::getEngineerCode));
List<OrgTeamEngineerEntity> teamEngineers = orgTeamEngineerDao.findAllByTeamId(t.getTeamId());
List<String> engineerCodes = teamEngineers.stream().map(OrgTeamEngineerEntity::getEngineerCode).collect(Collectors.toList());
List<EngineerInfoEntity> engineerInfoList = engineerInfoDao.findByEngineerCodeIn(engineerCodes);
Map<String, List<EngineerInfoEntity>> engineers = engineerInfoList.stream().collect(
Collectors.groupingBy(EngineerInfoEntity::getEngineerCode));
List<ScheduleOverviewResp.Item> children = new ArrayList<>();
for (Map.Entry<String, List<EngineerInfo>> entry : engineers.entrySet()) {
for (Map.Entry<String, List<EngineerInfoEntity>> entry : engineers.entrySet()) {
ScheduleOverviewResp.Item child = new ScheduleOverviewResp.Item();
//技术员信息
String engineerCode = entry.getKey();
EngineerInfo engineerInfo = entry.getValue().get(0);
EngineerInfoEntity engineerInfo = entry.getValue().get(0);
// 获取技术员已经指派的订单列表
List<OrderInfo> orders2 = engineerOrders.getOrDefault(engineerCode, new ArrayList<>());
......@@ -144,28 +151,27 @@ public class ScheduleServiceImpl implements ScheduleService {
public Result<?> getScheduleEngineerOverview(LocalDate date, String engineerCode) throws BusinessException {
// 获取技术员已排班概况
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode);
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("分销员不存在");
}
List<LabelValueDTO> emptyTips = new ArrayList<>();
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, date).eq(OrderInfo::getEngineerCode, engineerCode).in(OrderInfo::getAppointmentStatus, List.of("PRE", "CONFIRM"));
List<OrderInfo> orderAppointments = orderInfoMPDao.selectList(lqw);
List<OrderInfoEntity> orderAppointments = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
engineerCode, date, List.of("PRE", "CONFIRM"));
List<TimeLineDTO> timelines = new ArrayList<>();
for (OrderInfo o : orderAppointments) {
for (OrderInfoEntity o : orderAppointments) {
TimeLineDTO item = new TimeLineDTO();
item.setOrderId(o.getOrderId());
item.setAppointmentStatus(o.getAppointmentStatus());
item.setStartTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanStartTime()));
item.setEndTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanEndTime()));
item.setStartTime(TimeUtils.IsoLocalDateTime2String(o.getPlanStartTime()));
item.setEndTime(TimeUtils.IsoLocalDateTime2String(o.getPlanEndTime()));
item.setTips(emptyTips);
timelines.add(item);
}
Map<String, List<OrderInfo>> statusGroup = orderAppointments.stream().collect(Collectors.groupingBy(OrderInfo::getServiceStatus));
List<OrderInfo> empty = new ArrayList<>();
Map<String, List<OrderInfoEntity>> statusGroup = orderAppointments.stream().collect(Collectors.groupingBy(OrderInfoEntity::getServiceStatus));
List<OrderInfoEntity> empty = new ArrayList<>();
Integer countPending = statusGroup.getOrDefault("INIT", empty).size() + statusGroup.getOrDefault("CONTACTED", empty).size() + statusGroup.getOrDefault("PENDING", empty).size();
List<LabelValueDTO> dynamics = new ArrayList<>();
......@@ -182,13 +188,13 @@ public class ScheduleServiceImpl implements ScheduleService {
dynamics.add(new LabelValueDTO("工作时间", "08:00-18:00"));
dynamics.add(new LabelValueDTO("交通工具", "电动车"));
List<String> orderIds = orderAppointments.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
List<OrderInfo> orderRequests = new ArrayList<>();
List<String> orderIds = orderAppointments.stream().map(OrderInfoEntity::getOrderId).collect(Collectors.toList());
List<OrderInfoEntity> orderRequests = new ArrayList<>();
if (orderIds != null && !orderIds.isEmpty()) {
orderRequests = orderInfoMPDao.selectByDtAndOrderIds(date, orderIds);
orderRequests = orderInfoDao.findAllByDtAndOrderIdIn(date, orderIds);
}
List<ScheduleEngineerOverviewResp.Order> orders = new ArrayList<>();
for (OrderInfo o : orderRequests) {
for (OrderInfoEntity o : orderRequests) {
ScheduleEngineerOverviewResp.Order item = new ScheduleEngineerOverviewResp.Order();
item.setOrderId(o.getOrderId());
item.setLocation(String.format("%s,%s", o.getX(), o.getY()));
......@@ -207,7 +213,7 @@ public class ScheduleServiceImpl implements ScheduleService {
}
String groupName = "";
OrgGroup group = orgGroupMPDao.getByGroupId(engineer.getGroupId());
OrgGroupEntity group = orgGroupDao.getByGroupId(engineer.getGroupId());
if (group != null) {
groupName = group.getGroupName();
}
......@@ -240,13 +246,6 @@ public class ScheduleServiceImpl implements ScheduleService {
return pg;
}
private List<OrgTeamEngineer> queryOrgTeamEngineers(String teamId) {
LambdaQueryWrapper<OrgTeamEngineer> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrgTeamEngineer::getTeamId, teamId);
lqw.eq(OrgTeamEngineer::getStatus, 1);
return orgTeamEngineerMPDao.selectList(lqw);
}
private List<OrderInfo> queryOrderRequests(String teamId, LocalDate date) {
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, date);
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dao.SkillGroupMPDao;
import com.dituhui.pea.order.entity.SkillGroup;
import com.dituhui.pea.order.dao.SkillGroupDao;
import com.dituhui.pea.order.entity.SkillGroupEntity;
import com.dituhui.pea.order.service.SkillGroupCategoryService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,15 +17,15 @@ import java.util.stream.Collectors;
public class SkillGroupCategoryServiceImpl implements SkillGroupCategoryService {
@Autowired
SkillGroupMPDao skillGroupMPDao;
SkillGroupDao skillGroupDao;
@Override
public Result<?> querySkillGroupCategoryService() {
List<SkillGroup> records = skillGroupMPDao.selectList(null).stream().sorted(
Comparator.comparing(SkillGroup::getCategory)).collect(Collectors.toList());
List<SkillGroupEntity> records = skillGroupDao.findAll().stream().sorted(
Comparator.comparing(SkillGroupEntity::getCategory)).collect(Collectors.toList());
List<Category> items = new ArrayList<>();
for (SkillGroup r : records) {
for (SkillGroupEntity r : records) {
items.add(new Category(r.getSkillGroupCode(), r.getSkillGroup(), r.getCategory()));
}
Response res = new Response();
......
......@@ -3,12 +3,13 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.OrderEventDao;
import com.dituhui.pea.order.dao.OrderInfoDao;
import com.dituhui.pea.order.dto.OrderChangeListDTO;
import com.dituhui.pea.order.dto.WorkbenchSummaryResp;
import com.dituhui.pea.order.entity.OrderEventEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrderInfo;
import com.dituhui.pea.order.service.WorkbenchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,8 +18,15 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
......@@ -28,10 +36,10 @@ public class WorkbenchServiceImpl implements WorkbenchService {
private OrderEventDao orderEventDao;
@Autowired
private OrderInfoMPDao orderInfoMPDao;
private OrderInfoDao orderInfoDao;
@Autowired
private OrderInfoDao orderInfoDao;
private EntityManager entityManager;
@Override
public Result<?> getOrderChangeList(OrderChangeListDTO.Request reqDTO) {
......@@ -56,7 +64,7 @@ public class WorkbenchServiceImpl implements WorkbenchService {
.setOperator(entity.getOperator())
.setDescription(entity.getDescription())
.setMemo(entity.getMemo())
.setUpdateTime(entity.getUpdateTime());
.setUpdateTime(DateUtils.formatDateTime(entity.getUpdateTime()));
contents.add(content);
}
OrderChangeListDTO.Result rs = new OrderChangeListDTO.Result();
......@@ -89,27 +97,95 @@ public class WorkbenchServiceImpl implements WorkbenchService {
}
private List<Map<String, Object>> queryCountByAppointmentMethod(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("appointment_method, appointment_status, COUNT(*) as count")
.lambda()
.eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getAppointmentMethod, OrderInfo::getAppointmentStatus);
return orderInfoMPDao.selectMaps(wrapper);
}
private List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("service_status, COUNT(*) as count")
.lambda()
.eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getServiceStatus);
return orderInfoMPDao.selectMaps(wrapper);
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
Root<OrderInfoEntity> root = criteriaQuery.from(OrderInfoEntity.class);
criteriaQuery.multiselect(
root.get("appointmentMethod"),
root.get("appointmentStatus"),
criteriaBuilder.count(root).alias("count")
);
Predicate datePredicate = criteriaBuilder.equal(root.get("dt"), dt);
Predicate levelPredicate = null;
if ("cluster".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgClusterId"), levelValue);
} else if ("branch".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgBranchId"), levelValue);
} else if ("group".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgGroupId"), levelValue);
}
if (levelPredicate != null) {
criteriaQuery.where(datePredicate, levelPredicate);
} else {
criteriaQuery.where(datePredicate);
}
criteriaQuery.groupBy(root.get("appointmentMethod"), root.get("appointmentStatus"));
TypedQuery<Object[]> typedQuery = entityManager.createQuery(criteriaQuery);
List<Object[]> results = typedQuery.getResultList();
List<Map<String, Object>> mappedResults = results.stream()
.map(result -> {
Map<String, Object> map = Map.of(
"appointmentMethod", result[0],
"appointmentStatus", result[1],
"count", result[2]
);
return map;
})
.collect(Collectors.toList());
return mappedResults;
}
public List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
Root<OrderInfoEntity> root = criteriaQuery.from(OrderInfoEntity.class);
criteriaQuery.multiselect(
root.get("serviceStatus"),
criteriaBuilder.count(root).alias("count")
);
Predicate datePredicate = criteriaBuilder.equal(root.get("dt"), dt);
Predicate levelPredicate = null;
if ("cluster".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgClusterId"), levelValue);
} else if ("branch".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgBranchId"), levelValue);
} else if ("group".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgGroupId"), levelValue);
}
if (levelPredicate != null) {
criteriaQuery.where(datePredicate, levelPredicate);
} else {
criteriaQuery.where(datePredicate);
}
criteriaQuery.groupBy(root.get("serviceStatus"));
TypedQuery<Object[]> typedQuery = entityManager.createQuery(criteriaQuery);
List<Object[]> results = typedQuery.getResultList();
List<Map<String, Object>> mappedResults = results.stream()
.map(result -> {
Map<String, Object> map = Map.of(
"serviceStatus", result[0],
"count", result[1]
);
return map;
})
.collect(Collectors.toList());
return mappedResults;
}
private HashMap<String, Long> transAppointmentMethod(List<Map<String, Object>> results) {
......@@ -119,8 +195,8 @@ public class WorkbenchServiceImpl implements WorkbenchService {
Long autoTotal = 0L;
Long total = 0L;
for (Map<String, Object> result : results) {
String method = (String) result.get("appointment_method");
String status = (String) result.get("appointment_status");
String method = (String) result.get("appointmentMethod");
String status = (String) result.get("appointmentStatus");
Long count = (long) result.get("count");
total += count;
......@@ -147,7 +223,7 @@ public class WorkbenchServiceImpl implements WorkbenchService {
HashMap<String, Long> map = new HashMap<>();
for (Map<String, Object> result : results) {
String status = (String) result.get("service_status");
String status = (String) result.get("serviceStatus");
Long count = (long) result.get("count");
map.put(status, count);
}
......@@ -211,12 +287,10 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return items;
}
private <T> HashMap<String, List<T>> packParams(String key, T ...values) {
private <T> HashMap<String, List<T>> packParams(String key, T... values) {
HashMap<String, List<T>> map = new HashMap<>();
List<T> value = new ArrayList<>();
for(T v: values){
value.add(v);
}
Collections.addAll(value, values);
map.put(key, value);
return map;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!