Commit 49edbc50 by 王力

Merge branch 'dev_mp2jpa0809' into 'develop'

Dev mp2jpa0809

See merge request !325
2 parents cfc5e307 aa4c0747
...@@ -52,6 +52,10 @@ public class TimeUtils { ...@@ -52,6 +52,10 @@ public class TimeUtils {
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
} }
public static final String localDateTime2String(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
public static final String IsoLocalDate2String(LocalDate localDate) { public static final String IsoLocalDate2String(LocalDate localDate) {
return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT)); return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
} }
......
...@@ -2,12 +2,13 @@ package com.dituhui.pea.order.dao; ...@@ -2,12 +2,13 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrderInfoEntity; import com.dituhui.pea.order.entity.OrderInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long> { public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaSpecificationExecutor<OrderInfoEntity> {
OrderInfoEntity getByOrderId(String orderId); OrderInfoEntity getByOrderId(String orderId);
OrderInfoEntity getByOrderIdAndDt(String orderId, LocalDate dt); OrderInfoEntity getByOrderIdAndDt(String orderId, LocalDate dt);
List<OrderInfoEntity> findByOrderId(String orderId); List<OrderInfoEntity> findByOrderId(String orderId);
......
...@@ -4,6 +4,7 @@ import com.dituhui.pea.order.entity.OrgTeamEntity; ...@@ -4,6 +4,7 @@ import com.dituhui.pea.order.entity.OrgTeamEntity;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -11,7 +12,7 @@ import org.springframework.stereotype.Repository; ...@@ -11,7 +12,7 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository @Repository
public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer> { public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer>, JpaSpecificationExecutor<OrgTeamEntity> {
@Query("select t from OrgTeamEntity t where t.clusterId = :clusterId and t.status=1") @Query("select t from OrgTeamEntity t where t.clusterId = :clusterId and t.status=1")
List<OrgTeamEntity> findAllByClusterId(String clusterId); List<OrgTeamEntity> findAllByClusterId(String clusterId);
......
package com.dituhui.pea.order.service.impl; package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dituhui.pea.common.BusinessException; import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.ListUtils; import com.dituhui.pea.order.common.ListUtils;
...@@ -17,10 +16,12 @@ import com.dituhui.pea.order.service.DispatchService; ...@@ -17,10 +16,12 @@ import com.dituhui.pea.order.service.DispatchService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp; import javax.persistence.EntityManager;
import javax.persistence.criteria.*;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
...@@ -29,7 +30,7 @@ import java.util.stream.Collectors; ...@@ -29,7 +30,7 @@ import java.util.stream.Collectors;
interface GroupTag { interface GroupTag {
// 订单分类tag // 订单分类tag
String getGroupTag(OrderInfo order); String getGroupTag(OrderInfoEntity order);
} }
...@@ -38,19 +39,22 @@ interface GroupTag { ...@@ -38,19 +39,22 @@ interface GroupTag {
public class DispatchServiceImpl implements DispatchService { public class DispatchServiceImpl implements DispatchService {
@Autowired @Autowired
private OrderInfoMPDao orderInfoMPDao; private OrderInfoDao orderInfoDao;
@Autowired @Autowired
private OrgTeamMPDao orgTeamMPDao; private OrgTeamDao orgTeamDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private SkillInfoMPDao skillInfoMPDao; private SkillInfoDao skillInfoDao;
@Autowired @Autowired
private CapacityEngineerStatMPDao capacityEngineerStatMPDao; private CapacityEngineerStatDao capacityEngineerStatDao;
@Autowired
private EntityManager entityManager;
@Transactional @Transactional
@Override @Override
...@@ -58,16 +62,16 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -58,16 +62,16 @@ public class DispatchServiceImpl implements DispatchService {
// 获取派工台订单列表 // 获取派工台订单列表
// 获取技能信息 // 获取技能信息
HashMap<String, SkillInfo> skillInfo = this.querySkillInfo(); HashMap<String, SkillInfoEntity> skillInfo = this.querySkillInfo();
// 获取工单列表 // 获取工单列表
List<OrderInfo> orders = this.queryOrders(reqDTO); List<OrderInfoEntity> orders = this.queryOrders(reqDTO);
// 获取分组标签 // 获取分组标签
GroupTag gt = new GroupTagFactory().getGroupTag(reqDTO.getGroupTagId()); GroupTag gt = new GroupTagFactory().getGroupTag(reqDTO.getGroupTagId());
List<DispatchOrderListResp.Order> items = new ArrayList<>(); List<DispatchOrderListResp.Order> items = new ArrayList<>();
for (OrderInfo o : orders) { for (OrderInfoEntity o : orders) {
DispatchOrderListResp.Order item = new DispatchOrderListResp.Order(); DispatchOrderListResp.Order item = new DispatchOrderListResp.Order();
item.setOrderId(o.getOrderId()); item.setOrderId(o.getOrderId());
...@@ -80,7 +84,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -80,7 +84,7 @@ public class DispatchServiceImpl implements DispatchService {
item.setApplyNote(o.getApplyNote()); item.setApplyNote(o.getApplyNote());
String key = String.format("%s%s%s", o.getBrand(), o.getType(), o.getSkill()); String key = String.format("%s%s%s", o.getBrand(), o.getType(), o.getSkill());
SkillInfo skill = skillInfo.get(key); SkillInfoEntity skill = skillInfo.get(key);
if (skill != null) { if (skill != null) {
item.setDuration(skill.getTakeTime()); item.setDuration(skill.getTakeTime());
item.setSkillCategory(skill.getSkillCategory()); item.setSkillCategory(skill.getSkillCategory());
...@@ -103,7 +107,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -103,7 +107,7 @@ public class DispatchServiceImpl implements DispatchService {
item.setAppointmentStatus(o.getAppointmentStatus()); item.setAppointmentStatus(o.getAppointmentStatus());
item.setOrderStatus(o.getOrderStatus()); item.setOrderStatus(o.getOrderStatus());
item.setServiceStatus(o.getServiceStatus()); item.setServiceStatus(o.getServiceStatus());
item.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime())); item.setCreateTime(TimeUtils.IsoLocalDateTime2String(o.getCreateTime()));
String[] tags = gt.getGroupTag(o).split("#"); String[] tags = gt.getGroupTag(o).split("#");
item.setGroupTag(tags[0]); // 设置tag名称 item.setGroupTag(tags[0]); // 设置tag名称
...@@ -125,7 +129,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -125,7 +129,7 @@ public class DispatchServiceImpl implements DispatchService {
LocalDate date = TimeUtils.IsoDate2LocalDate(reqDTO.getDate()); LocalDate date = TimeUtils.IsoDate2LocalDate(reqDTO.getDate());
// 获取技能信息 // 获取技能信息
HashMap<String, SkillInfo> skillInfo = this.querySkillInfo(); HashMap<String, SkillInfoEntity> skillInfo = this.querySkillInfo();
// 获取teamIds // 获取teamIds
List<String> teamIds = this.queryOrgTeamIds(reqDTO.getLevelType(), reqDTO.getLevelValue(), reqDTO.getBranchIds(), List<String> teamIds = this.queryOrgTeamIds(reqDTO.getLevelType(), reqDTO.getLevelValue(), reqDTO.getBranchIds(),
...@@ -135,7 +139,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -135,7 +139,7 @@ public class DispatchServiceImpl implements DispatchService {
} }
// 获取engineer列表 // 获取engineer列表
List<EngineerInfo> engineers = this.queryEngineers(teamIds, reqDTO.getEngineerCodes(), reqDTO.getKey()); List<EngineerInfoEntity> engineers = this.queryEngineers(teamIds, reqDTO.getEngineerCodes(), reqDTO.getKey());
if (engineers.isEmpty()) { if (engineers.isEmpty()) {
// 该group下没有技术员,返回空 // 该group下没有技术员,返回空
log.warn("没有找到技术员"); log.warn("没有找到技术员");
...@@ -146,23 +150,23 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -146,23 +150,23 @@ public class DispatchServiceImpl implements DispatchService {
} }
// 获取engineerCodes // 获取engineerCodes
List<String> engineerCodes = engineers.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList()); List<String> engineerCodes = engineers.stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
// 获取技术员已指派单列表 // 获取技术员已指派单列表
Map<String, List<OrderInfo>> engineerOrders = this.queryEngineerOrders(engineerCodes, date); Map<String, List<OrderInfoEntity>> engineerOrders = this.queryEngineerOrders(engineerCodes, date);
// 获取技术员的容量 // 获取技术员的容量
HashMap<String, CapacityEngineerStat> engineerCap = this.queryCapacityEngineerStat(engineerCodes, reqDTO.getDate()); HashMap<String, CapacityEngineerStatEntity> engineerCap = this.queryCapacityEngineerStat(engineerCodes, reqDTO.getDate());
// 获取技术员已指派单列表 // 获取技术员已指派单列表
List<DispatchEngineerOrderListResp.EngineerInfo> egs = new ArrayList<>(); List<DispatchEngineerOrderListResp.EngineerInfo> egs = new ArrayList<>();
for (EngineerInfo e : engineers) { for (EngineerInfoEntity e : engineers) {
List<DispatchEngineerOrderListResp.OrderInfo> items = new ArrayList<>(); List<DispatchEngineerOrderListResp.OrderInfo> items = new ArrayList<>();
// 技术员已指派的订单列表 // 技术员已指派的订单列表
List<OrderInfo> records = engineerOrders.getOrDefault(e.getEngineerCode(), new ArrayList<>()); List<OrderInfoEntity> records = engineerOrders.getOrDefault(e.getEngineerCode(), new ArrayList<>());
for (OrderInfo o : records) { for (OrderInfoEntity o : records) {
DispatchEngineerOrderListResp.OrderInfo item = new DispatchEngineerOrderListResp.OrderInfo(); DispatchEngineerOrderListResp.OrderInfo item = new DispatchEngineerOrderListResp.OrderInfo();
item.setOrderId(o.getOrderId()); item.setOrderId(o.getOrderId());
...@@ -175,7 +179,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -175,7 +179,7 @@ public class DispatchServiceImpl implements DispatchService {
item.setApplyNote(o.getApplyNote()); item.setApplyNote(o.getApplyNote());
String key = String.format("%s%s%s", o.getBrand(), o.getType(), o.getSkill()); String key = String.format("%s%s%s", o.getBrand(), o.getType(), o.getSkill());
SkillInfo skill = skillInfo.get(key); SkillInfoEntity skill = skillInfo.get(key);
if (skill != null) { if (skill != null) {
item.setDuration(skill.getTakeTime()); item.setDuration(skill.getTakeTime());
item.setSkillCategory(skill.getSkillCategory()); item.setSkillCategory(skill.getSkillCategory());
...@@ -193,7 +197,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -193,7 +197,7 @@ public class DispatchServiceImpl implements DispatchService {
item.setName(o.getName()); item.setName(o.getName());
item.setPhone(o.getPhone()); item.setPhone(o.getPhone());
String time = TimeUtils.timestamp2DateTime(o.getPlanStartTime(), "HH:mm"); String time = TimeUtils.localDateTime2String(o.getPlanStartTime(), "HH:mm");
String timeSlot = this.parseTimeSlot(o.getPlanStartTime()); String timeSlot = this.parseTimeSlot(o.getPlanStartTime());
item.setExpectTimeDesc(String.format("%s/%s", time, timeSlot)); item.setExpectTimeDesc(String.format("%s/%s", time, timeSlot));
...@@ -204,7 +208,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -204,7 +208,7 @@ public class DispatchServiceImpl implements DispatchService {
item.setOrderStatus(o.getOrderStatus()); // 订单状态 item.setOrderStatus(o.getOrderStatus()); // 订单状态
item.setServiceStatus(o.getServiceStatus()); item.setServiceStatus(o.getServiceStatus());
item.setOrderStatusDesc(OrderStatus.valueOf(o.getOrderStatus()).getDescription()); item.setOrderStatusDesc(OrderStatus.valueOf(o.getOrderStatus()).getDescription());
item.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime())); item.setCreateTime(TimeUtils.IsoLocalDateTime2String(o.getCreateTime()));
items.add(item); items.add(item);
} }
...@@ -213,7 +217,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -213,7 +217,7 @@ public class DispatchServiceImpl implements DispatchService {
int capUsed = 0; int capUsed = 0;
int capTotal = 0; int capTotal = 0;
String capacityStatus = "less"; String capacityStatus = "less";
CapacityEngineerStat cap = engineerCap.get(e.getEngineerCode()); CapacityEngineerStatEntity cap = engineerCap.get(e.getEngineerCode());
if (cap != null) { if (cap != null) {
capUsed = cap.getCapUsed(); capUsed = cap.getCapUsed();
capTotal = cap.getCapTotal(); capTotal = cap.getCapTotal();
...@@ -243,107 +247,147 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -243,107 +247,147 @@ public class DispatchServiceImpl implements DispatchService {
LocalDate localDate = TimeUtils.IsoDate2LocalDate(date); LocalDate localDate = TimeUtils.IsoDate2LocalDate(date);
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode); EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode);
if (engineer == null) { if (engineer == null) {
throw new BusinessException("技术员不存在"); throw new BusinessException("技术员不存在");
} }
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndEngineerCodeIn(localDate, orderIds);
LambdaQueryWrapper<OrderInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderInfo::getDt, localDate);
wrapper.in(OrderInfo::getOrderId, orderIds);
List<OrderInfo> orders = orderInfoMPDao.selectList(wrapper);
if (ListUtils.isEmpty(orders)) { if (ListUtils.isEmpty(orders)) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
// 已经指派的订单 // 已经指派的订单
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>(); List<OrderInfoEntity> engineerOrders = orderInfoDao.findByDtAndEngineerCode(localDate, engineerCode);
lqw.eq(OrderInfo::getEngineerCode, engineerCode); engineerOrders.sort(Comparator.comparing(OrderInfoEntity::getPlanStartTime)); // 按照planStartTime排序
lqw.eq(OrderInfo::getDt, date); List<OrderInfoEntity> orderAppointments = engineerOrders.stream()
lqw.orderByAsc(OrderInfo::getPlanStartTime); .filter(o -> o.getOrderStatus().equals("NORMAL"))
List<OrderInfo> orderAppointments = orderInfoMPDao.selectList(lqw); .collect(Collectors.toList()); // 过滤,只有NORMAL订单才需要处理,取消订单不需要处理
// TODO,临时处理方案,后续调用派单引擎处理 // TODO,临时处理方案,后续调用派单引擎处理
OrderRequestScheduler scheduler = new OrderRequestScheduler(); OrderRequestScheduler scheduler = new OrderRequestScheduler();
List<LineSegment> results = scheduler.scheduler(orders, orderAppointments); List<LineSegment> results = scheduler.scheduler(orders, orderAppointments);
for (LineSegment r : results) { for (LineSegment r : results) {
String orderId = r.id; String orderId = r.id;
Timestamp planStartTime = scheduler.linePoint2Timestamp(r.start, date); LocalDateTime planStartTime = scheduler.linePoint2DateTime(r.start, date);
Timestamp planEndTime = scheduler.linePoint2Timestamp(r.end, date); LocalDateTime planEndTime = scheduler.linePoint2DateTime(r.end, date);
// 更新order request表状态 CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
LambdaUpdateWrapper<OrderInfo> updateWrapper = new LambdaUpdateWrapper<>(); CriteriaUpdate<OrderInfoEntity> update = criteriaBuilder.createCriteriaUpdate(OrderInfoEntity.class);
updateWrapper.set(OrderInfo::getPlanStartTime, planStartTime); Root<OrderInfoEntity> root = update.from(OrderInfoEntity.class);
updateWrapper.set(OrderInfo::getPlanEndTime, planEndTime); update.set(root.get("planStartTime"), planStartTime);
updateWrapper.set(OrderInfo::getAppointmentStatus, "CONFIRM"); update.set(root.get("planEndTime"), planEndTime);
updateWrapper.set(OrderInfo::getAppointmentMethod, "MANUAL"); update.set(root.get("appointmentStatus"), "CONFIRM");
updateWrapper.eq(OrderInfo::getOrderId, orderId); update.set(root.get("appointmentMethod"), "MANUAL");
updateWrapper.eq(OrderInfo::getDt, localDate); update.where(
criteriaBuilder.equal(root.get("orderId"), orderId),
orderInfoMPDao.update(null, updateWrapper); criteriaBuilder.equal(root.get("dt"), localDate)
);
entityManager.createQuery(update).executeUpdate();
} }
return Result.success(null); return Result.success(null);
} }
private List<OrderInfo> queryOrders(DispatchOrderListReq reqDTO) { private List<OrderInfoEntity> queryOrders(DispatchOrderListReq reqDTO) {
// 获取服务单列表 // 获取服务单列表
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, TimeUtils.IsoDate2LocalDate(reqDTO.getDate())); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
lqw.eq(OrderInfo::getAppointmentStatus, "INIT"); // 明确未派工订单 CriteriaQuery<OrderInfoEntity> criteriaQuery = criteriaBuilder.createQuery(OrderInfoEntity.class);
lqw.eq(reqDTO.getLevelType().equals("cluster"), OrderInfo::getOrgClusterId, reqDTO.getLevelValue()); Root<OrderInfoEntity> root = criteriaQuery.from(OrderInfoEntity.class);
lqw.eq(reqDTO.getLevelType().equals("branch"), OrderInfo::getOrgBranchId, reqDTO.getLevelValue()); List<Predicate> predicates = new ArrayList<>();
lqw.eq(reqDTO.getLevelType().equals("group"), OrderInfo::getOrgGroupId, reqDTO.getLevelValue());
//筛选项 predicates.add(criteriaBuilder.equal(root.get("dt"), TimeUtils.IsoDate2LocalDate(reqDTO.getDate())));
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderInfo::getPhone, reqDTO.getPhone()); predicates.add(criteriaBuilder.equal(root.get("appointmentStatus"), "INIT"));
lqw.eq(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderInfo::getOrderId, reqDTO.getOrderId());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderInfo::getOrgBranchId, reqDTO.getBranchIds()); String levelType = reqDTO.getLevelType();
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderInfo::getOrgGroupId, reqDTO.getGroupIds()); String levelValue = reqDTO.getLevelValue();
lqw.in(ListUtils.isNotEmpty(reqDTO.getTeamIds()), OrderInfo::getOrgTeamId, reqDTO.getTeamIds()); if ("cluster".equals(levelType)) {
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderInfo::getAppointmentMethod, reqDTO.getAppointmentType()); predicates.add(criteriaBuilder.equal(root.get("orgClusterId"), levelValue));
} else if ("branch".equals(levelType)) {
predicates.add(criteriaBuilder.equal(root.get("orgBranchId"), levelValue));
} else if ("group".equals(levelType)) {
predicates.add(criteriaBuilder.equal(root.get("orgGroupId"), levelValue));
}
// 筛选项
if (StringUtils.isNotEmpty(reqDTO.getPhone())) {
predicates.add(criteriaBuilder.equal(root.get("phone"), reqDTO.getPhone()));
}
if (StringUtils.isNotEmpty(reqDTO.getOrderId())) {
predicates.add(criteriaBuilder.equal(root.get("orderId"), reqDTO.getOrderId()));
}
if (ListUtils.isNotEmpty(reqDTO.getBranchIds())) {
predicates.add(root.get("orgBranchId").in(reqDTO.getBranchIds()));
}
if (ListUtils.isNotEmpty(reqDTO.getGroupIds())) {
predicates.add(root.get("orgGroupId").in(reqDTO.getGroupIds()));
}
if (ListUtils.isNotEmpty(reqDTO.getTeamIds())) {
predicates.add(root.get("orgTeamId").in(reqDTO.getTeamIds()));
}
if (ListUtils.isNotEmpty(reqDTO.getAppointmentType())) {
predicates.add(root.get("appointmentMethod").in(reqDTO.getAppointmentType()));
}
if (ListUtils.isNotEmpty(reqDTO.getPriorities())) { if (ListUtils.isNotEmpty(reqDTO.getPriorities())) {
List<Integer> p = reqDTO.getPriorities(); List<Integer> p = reqDTO.getPriorities();
if (p.contains(0) && p.contains(1)) { if (p.contains(0) && p.contains(1)) {
lqw.ge(OrderInfo::getPriority, 1); predicates.add(criteriaBuilder.ge(root.get("priority"), 1));
} else if (p.contains(0) && !p.contains(1)) { } else if (p.contains(0) && !p.contains(1)) {
lqw.le(OrderInfo::getPriority, 1); predicates.add(criteriaBuilder.le(root.get("priority"), 1));
} else if (p.contains(1) && !p.contains(0)) { } else if (p.contains(1) && !p.contains(0)) {
lqw.ge(OrderInfo::getPriority, 5); predicates.add(criteriaBuilder.ge(root.get("priority"), 5));
} }
} }
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())) { if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())) {
lqw.and(w -> Predicate engineerCodePredicate = root.get("engineerCode").in(reqDTO.getEngineerCodes());
w.in(OrderInfo::getEngineerCode, reqDTO.getEngineerCodes()) Predicate engineerCodeSubPredicate = root.get("engineerCodeSub").in(reqDTO.getEngineerCodes());
.or() predicates.add(criteriaBuilder.or(engineerCodePredicate, engineerCodeSubPredicate));
.in(OrderInfo::getEngineerCodeSub, reqDTO.getEngineerCodes())
);
} }
if (ListUtils.isNotEmpty(reqDTO.getTypeCategory())) { if (ListUtils.isNotEmpty(reqDTO.getTypeCategory())) {
String types = "'" + String.join("','", reqDTO.getTypeCategory()) + "'"; Subquery<OrderInfoEntity> typeCategorySubquery = criteriaQuery.subquery(OrderInfoEntity.class);
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and type_category in (%s)", types); Root<SkillInfoEntity> skillInfoRoot = typeCategorySubquery.from(SkillInfoEntity.class);
lqw.exists(sql); typeCategorySubquery.select(root)
.where(
criteriaBuilder.equal(skillInfoRoot.get("brand"), root.get("brand")),
criteriaBuilder.equal(skillInfoRoot.get("type"), root.get("type")),
criteriaBuilder.equal(skillInfoRoot.get("skill"), root.get("skill")),
skillInfoRoot.get("typeCategory").in(reqDTO.getTypeCategory())
);
predicates.add(criteriaBuilder.exists(typeCategorySubquery));
} }
if (ListUtils.isNotEmpty(reqDTO.getSkillCategory())) { if (ListUtils.isNotEmpty(reqDTO.getSkillCategory())) {
String skills = "'" + String.join("','", reqDTO.getSkillCategory()) + "'"; Subquery<OrderInfoEntity> skillCategorySubquery = criteriaQuery.subquery(OrderInfoEntity.class);
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and skill_category in (%s)", skills); Root<SkillInfoEntity> skillInfoRoot = skillCategorySubquery.from(SkillInfoEntity.class);
lqw.exists(sql); skillCategorySubquery.select(root) // 注意这里的 select 使用主查询的 root
.where(
criteriaBuilder.equal(skillInfoRoot.get("brand"), root.get("brand")),
criteriaBuilder.equal(skillInfoRoot.get("type"), root.get("type")),
criteriaBuilder.equal(skillInfoRoot.get("skill"), root.get("skill")),
skillInfoRoot.get("skillCategory").in(reqDTO.getSkillCategory())
);
predicates.add(criteriaBuilder.exists(skillCategorySubquery));
} }
if (ListUtils.isNotEmpty(reqDTO.getGroupCategory())) { if (ListUtils.isNotEmpty(reqDTO.getGroupCategory())) {
String groupCategory = reqDTO.getGroupCategory().stream().map(Object::toString).collect(Collectors.joining(",")); Subquery<OrderInfoEntity> skillGroupCategorySubquery = criteriaQuery.subquery(OrderInfoEntity.class);
String sql = String.format("select 1 from org_group g where g.group_id = order_info.org_group_id and g.category in (%s)", groupCategory); Root<SkillInfoEntity> skillInfoRoot = skillGroupCategorySubquery.from(SkillInfoEntity.class);
lqw.exists(sql); skillGroupCategorySubquery.select(root) // 注意这里的 select 使用主查询的 root
.where(
criteriaBuilder.equal(skillInfoRoot.get("brand"), root.get("brand")),
criteriaBuilder.equal(skillInfoRoot.get("type"), root.get("type")),
criteriaBuilder.equal(skillInfoRoot.get("skill"), root.get("skill")),
skillInfoRoot.get("groupCategory").in(reqDTO.getGroupCategory())
);
predicates.add(criteriaBuilder.exists(skillGroupCategorySubquery));
} }
return orderInfoMPDao.selectList(lqw); criteriaQuery.where(predicates.toArray(new Predicate[0]));
return entityManager.createQuery(criteriaQuery).getResultList();
} }
private Map<String, List<OrderInfo>> queryEngineerOrders(List<String> engineerCodes, LocalDate date) { private Map<String, List<OrderInfoEntity>> queryEngineerOrders(List<String> engineerCodes, LocalDate date) {
// 获取工程师服务单列表 // 获取工程师服务单列表
Map<String, List<OrderInfo>> map = new HashMap<>(); Map<String, List<OrderInfo>> map = new HashMap<>();
...@@ -353,85 +397,109 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -353,85 +397,109 @@ public class DispatchServiceImpl implements DispatchService {
lqw.in(OrderInfo::getAppointmentStatus, List.of("VIRTUAL", "PRE", "CONFIRM")); lqw.in(OrderInfo::getAppointmentStatus, List.of("VIRTUAL", "PRE", "CONFIRM"));
lqw.in(OrderInfo::getEngineerCode, engineerCodes); lqw.in(OrderInfo::getEngineerCode, engineerCodes);
lqw.orderByAsc(OrderInfo::getEngineerCode); List<OrderInfoEntity> records = orderInfoDao.findByDtAndEngineerCodeIn(date, engineerCodes);
lqw.orderByAsc(OrderInfo::getPlanStartTime); // 排序
records.sort(Comparator.comparing(OrderInfoEntity::getEngineerCode));
List<OrderInfo> records = orderInfoMPDao.selectList(lqw); records.sort(Comparator.comparing(OrderInfoEntity::getPlanStartTime));
return records.stream().collect(Collectors.groupingBy(OrderInfo::getEngineerCode)); //过滤
List<OrderInfoEntity> orders = records.stream()
.filter(r -> !r.getAppointmentStatus().equals("INIT"))
.collect(Collectors.toList());
return orders.stream().collect(Collectors.groupingBy(OrderInfoEntity::getEngineerCode));
} }
private List<EngineerInfo> queryEngineers(List<String> teamIds, List<String> engineerCodes, String key) { public List<EngineerInfoEntity> queryEngineers(List<String> teamIds, List<String> engineerCodes, String key) {
// 通过groupIds获取技术员列表 CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>(); CriteriaQuery<EngineerInfoEntity> criteriaQuery = criteriaBuilder.createQuery(EngineerInfoEntity.class);
lqw.eq(EngineerInfo::getBeanStatus, 1); Root<EngineerInfoEntity> root = criteriaQuery.from(EngineerInfoEntity.class);
lqw.in(ListUtils.isNotEmpty(engineerCodes), EngineerInfo::getEngineerCode, engineerCodes); List<Predicate> predicates = new ArrayList<>();
String inTeamIds = "'" + teamIds.stream().map(Object::toString).collect(Collectors.joining("','")) + "'"; predicates.add(criteriaBuilder.equal(root.get("beanStatus"), 1));
String sql = String.format("select 1 from org_team_engineer ot where ot.engineer_code = engineer_info.engineer_code and ot.team_id in (%s)", inTeamIds); if (ListUtils.isNotEmpty(engineerCodes)) {
lqw.exists(sql); predicates.add(root.get("engineerCode").in(engineerCodes));
}
if (StringUtils.isNotEmpty(key)) { Subquery<Integer> teamSubquery = criteriaQuery.subquery(Integer.class);
lqw.and(w -> Root<OrgTeamEngineerEntity> teamRoot = teamSubquery.from(OrgTeamEngineerEntity.class);
w.like(EngineerInfo::getPhone, key) teamSubquery.select(criteriaBuilder.literal(1))
.or() .where(
.like(EngineerInfo::getName, key) criteriaBuilder.equal(teamRoot.get("engineerCode"), root.get("engineerCode")),
.or() teamRoot.get("teamId").in(teamIds)
.like(EngineerInfo::getEngineerCode, key)
); );
predicates.add(criteriaBuilder.exists(teamSubquery));
if (StringUtils.isNotEmpty(key)) {
predicates.add(criteriaBuilder.or(
criteriaBuilder.like(root.get("phone"), "%" + key + "%"),
criteriaBuilder.like(root.get("name"), "%" + key + "%"),
criteriaBuilder.like(root.get("engineerCode"), "%" + key + "%")
));
} }
lqw.orderByAsc(EngineerInfo::getName);
return engineerInfoMPDao.selectList(lqw); criteriaQuery.where(predicates.toArray(new Predicate[0]));
criteriaQuery.orderBy(criteriaBuilder.asc(root.get("name")));
return entityManager.createQuery(criteriaQuery).getResultList();
} }
private List<String> queryOrgTeamIds(String levelType, String levelIds, List<String> branchIds, List<String> groupIds, List<String> teamIds) { private List<String> queryOrgTeamIds(String levelType, String levelIds, List<String> branchIds, List<String> groupIds, List<String> teamIds) {
LambdaQueryWrapper<OrgTeam> lqw = new LambdaQueryWrapper<>();
lqw.eq(levelType.equals("cluster"), OrgTeam::getClusterId, levelIds);
lqw.eq(levelType.equals("branch"), OrgTeam::getBranchId, levelIds);
lqw.eq(levelType.equals("group"), OrgTeam::getGroupId, levelIds);
lqw.in(ListUtils.isNotEmpty(branchIds), OrgTeam::getBranchId, branchIds);
lqw.in(ListUtils.isNotEmpty(groupIds), OrgTeam::getGroupId, groupIds);
lqw.in(ListUtils.isNotEmpty(teamIds), OrgTeam::getTeamId, teamIds);
List<OrgTeam> teams = orgTeamMPDao.selectList(lqw); Specification<OrgTeamEntity> specification = (root, query, criteriaBuilder) -> {
return teams.stream().map(OrgTeam::getTeamId).collect(Collectors.toList()); List<Predicate> predicates = new ArrayList<>();
if ("cluster".equals(levelType)) {
predicates.add(criteriaBuilder.in(root.get("clusterId")).value(levelIds));
} else if ("branch".equals(levelType)) {
predicates.add(criteriaBuilder.in(root.get("branchId")).value(levelIds));
} else if ("group".equals(levelType)) {
predicates.add(criteriaBuilder.in(root.get("groupId")).value(levelIds));
}
if (ListUtils.isNotEmpty(branchIds)) {
predicates.add(root.get("branchId").in(branchIds));
}
if (ListUtils.isNotEmpty(groupIds)) {
predicates.add(root.get("groupId").in(groupIds));
}
if (ListUtils.isNotEmpty(teamIds)) {
predicates.add(root.get("teamId").in(teamIds));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
};
List<OrgTeamEntity> teams = orgTeamDao.findAll(specification);
return teams.stream().map(OrgTeamEntity::getTeamId).collect(Collectors.toList());
} }
private HashMap<String, Integer> querySkillTakeTime() { private HashMap<String, Integer> querySkillTakeTime() {
HashMap<String, Integer> map = new HashMap<>(); HashMap<String, Integer> map = new HashMap<>();
List<SkillInfo> records = skillInfoMPDao.selectList(null); List<SkillInfoEntity> records = skillInfoDao.findAll();
for (SkillInfo r : records) { for (SkillInfoEntity r : records) {
String key = String.format("%s%s%s", r.getBrand(), r.getType(), r.getSkill()); String key = String.format("%s%s%s", r.getBrand(), r.getType(), r.getSkill());
map.put(key, r.getTakeTime()); map.put(key, r.getTakeTime());
} }
return map; return map;
} }
private HashMap<String, SkillInfo> querySkillInfo() { private HashMap<String, SkillInfoEntity> querySkillInfo() {
HashMap<String, SkillInfo> map = new HashMap<>(); HashMap<String, SkillInfoEntity> map = new HashMap<>();
List<SkillInfo> records = skillInfoMPDao.selectList(null); List<SkillInfoEntity> records = skillInfoDao.findAll();
for (SkillInfo r : records) { for (SkillInfoEntity r : records) {
String key = String.format("%s%s%s", r.getBrand(), r.getType(), r.getSkill()); String key = String.format("%s%s%s", r.getBrand(), r.getType(), r.getSkill());
map.put(key, r); map.put(key, r);
} }
return map; return map;
} }
private HashMap<String, CapacityEngineerStat> queryCapacityEngineerStat(List<String> engineerCodes, String date) { private HashMap<String, CapacityEngineerStatEntity> queryCapacityEngineerStat(List<String> engineerCodes, String date) {
LambdaQueryWrapper<CapacityEngineerStat> lqw = new LambdaQueryWrapper<>(); List<CapacityEngineerStatEntity> records = capacityEngineerStatDao.getByWorkdayAndEngineerCodeIn(date, engineerCodes);
lqw.eq(CapacityEngineerStat::getWorkday, date);
lqw.in(CapacityEngineerStat::getEngineerCode, engineerCodes);
List<CapacityEngineerStat> records = capacityEngineerStatMPDao.selectList(lqw);
HashMap<String, CapacityEngineerStat> map = new HashMap<>(); HashMap<String, CapacityEngineerStatEntity> map = new HashMap<>();
for (CapacityEngineerStat r : records) { for (CapacityEngineerStatEntity r : records) {
map.put(r.getEngineerCode(), r); map.put(r.getEngineerCode(), r);
} }
return map; return map;
} }
private String parseTimeSlot(Timestamp t) { private String parseTimeSlot(LocalDateTime t) {
String h = TimeUtils.timestamp2DateTime(t, "HH"); String h = TimeUtils.localDateTime2String(t, "HH");
Integer hour = Integer.parseInt(h); Integer hour = Integer.parseInt(h);
if (hour <= 12) { if (hour <= 12) {
return "上午"; return "上午";
...@@ -457,7 +525,7 @@ class GroupTagFactory { ...@@ -457,7 +525,7 @@ class GroupTagFactory {
class GroupTagUrgency implements GroupTag { class GroupTagUrgency implements GroupTag {
// 根据紧急程度来分组 // 根据紧急程度来分组
public String getGroupTag(OrderInfo order) { public String getGroupTag(OrderInfoEntity order) {
String s = order.getTags(); String s = order.getTags();
if (s == null) { if (s == null) {
return "正常#1"; return "正常#1";
...@@ -476,7 +544,7 @@ class GroupTagUrgency implements GroupTag { ...@@ -476,7 +544,7 @@ class GroupTagUrgency implements GroupTag {
class GroupTagOmit implements GroupTag { class GroupTagOmit implements GroupTag {
public String getGroupTag(OrderInfo order) { public String getGroupTag(OrderInfoEntity order) {
return "默认分类#5"; return "默认分类#5";
} }
} }
...@@ -555,18 +623,18 @@ class LineSegmentScheduler { ...@@ -555,18 +623,18 @@ class LineSegmentScheduler {
class OrderRequestScheduler { class OrderRequestScheduler {
public List<LineSegment> scheduler(List<OrderInfo> orderRequests, List<OrderInfo> orderAppointments) { public List<LineSegment> scheduler(List<OrderInfoEntity> orderRequests, List<OrderInfoEntity> orderAppointments) {
List<LineSegment> used = new ArrayList<>(); List<LineSegment> used = new ArrayList<>();
for (OrderInfo o : orderAppointments) { for (OrderInfoEntity o : orderAppointments) {
LineSegment s = new LineSegment(o.getOrderId(), LineSegment s = new LineSegment(o.getOrderId(),
this.Timestamp2LinePoint(o.getPlanStartTime()), this.localTime2LinePoint(o.getPlanStartTime()),
this.Timestamp2LinePoint(o.getPlanEndTime())); this.localTime2LinePoint(o.getPlanEndTime()));
used.add(s); used.add(s);
} }
List<Line> newTasks = new ArrayList<>(); List<Line> newTasks = new ArrayList<>();
for (OrderInfo o : orderRequests) { for (OrderInfoEntity o : orderRequests) {
if (!o.getAppointmentStatus().equals("NOT_ASSIGNED")) { if (!o.getAppointmentStatus().equals("NOT_ASSIGNED")) {
continue; continue;
} }
...@@ -583,16 +651,15 @@ class OrderRequestScheduler { ...@@ -583,16 +651,15 @@ class OrderRequestScheduler {
return scheduler.scheduleLineSegments(used, newTasks); return scheduler.scheduleLineSegments(used, newTasks);
} }
public int Timestamp2LinePoint(Timestamp t) { public int localTime2LinePoint(LocalDateTime datetime) {
LocalDateTime datetime = t.toLocalDateTime();
return datetime.getHour() * 60 + datetime.getMinute(); return datetime.getHour() * 60 + datetime.getMinute();
} }
public Timestamp linePoint2Timestamp(int x, String date) { public LocalDateTime linePoint2DateTime(int x, String date) {
int base = 60; int base = 60;
int hour = x / base; int hour = x / base;
int minute = x % base; int minute = x % base;
String datetime = String.format("%s %d:%d:00", date, hour, minute); String datetime = String.format("%s %d:%d:00", date, hour, minute);
return Timestamp.valueOf(datetime); return TimeUtils.IsoDateTime2LocalDateTime(datetime);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!