Commit 9203cb82 by wangli

mp2jpa

1 parent 413634a1
...@@ -17,9 +17,11 @@ import com.dituhui.pea.order.service.DispatchService; ...@@ -17,9 +17,11 @@ 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 javax.persistence.criteria.Predicate;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -41,16 +43,19 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -41,16 +43,19 @@ public class DispatchServiceImpl implements DispatchService {
private OrderInfoMPDao orderInfoMPDao; private OrderInfoMPDao orderInfoMPDao;
@Autowired @Autowired
private OrgTeamMPDao orgTeamMPDao; private OrgTeamDao orgTeamDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoMPDao engineerInfoMPDao;
@Autowired @Autowired
private SkillInfoMPDao skillInfoMPDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private CapacityEngineerStatMPDao capacityEngineerStatMPDao; private SkillInfoDao skillInfoDao;
@Autowired
private CapacityEngineerStatDao capacityEngineerStatDao;
@Transactional @Transactional
@Override @Override
...@@ -58,7 +63,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -58,7 +63,7 @@ public class DispatchServiceImpl implements DispatchService {
// 获取派工台订单列表 // 获取派工台订单列表
// 获取技能信息 // 获取技能信息
HashMap<String, SkillInfo> skillInfo = this.querySkillInfo(); HashMap<String, SkillInfoEntity> skillInfo = this.querySkillInfo();
// 获取工单列表 // 获取工单列表
List<OrderInfo> orders = this.queryOrders(reqDTO); List<OrderInfo> orders = this.queryOrders(reqDTO);
...@@ -80,7 +85,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -80,7 +85,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());
...@@ -125,7 +130,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -125,7 +130,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(),
...@@ -152,7 +157,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -152,7 +157,7 @@ public class DispatchServiceImpl implements DispatchService {
Map<String, List<OrderInfo>> engineerOrders = this.queryEngineerOrders(engineerCodes, date); Map<String, List<OrderInfo>> 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<>();
...@@ -175,7 +180,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -175,7 +180,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());
...@@ -213,7 +218,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -213,7 +218,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,7 +248,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -243,7 +248,7 @@ 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("技术员不存在");
} }
...@@ -385,46 +390,56 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -385,46 +390,56 @@ public class DispatchServiceImpl implements DispatchService {
} }
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); Specification<OrgTeamEntity> specification = (root, query, criteriaBuilder) -> {
lqw.eq(levelType.equals("branch"), OrgTeam::getBranchId, levelIds); List<Predicate> predicates = new ArrayList<>();
lqw.eq(levelType.equals("group"), OrgTeam::getGroupId, levelIds); if ("cluster".equals(levelType)) {
lqw.in(ListUtils.isNotEmpty(branchIds), OrgTeam::getBranchId, branchIds); predicates.add(criteriaBuilder.in(root.get("clusterId")).value(levelIds));
lqw.in(ListUtils.isNotEmpty(groupIds), OrgTeam::getGroupId, groupIds); } else if ("branch".equals(levelType)) {
lqw.in(ListUtils.isNotEmpty(teamIds), OrgTeam::getTeamId, teamIds); predicates.add(criteriaBuilder.in(root.get("branchId")).value(levelIds));
} else if ("group".equals(levelType)) {
List<OrgTeam> teams = orgTeamMPDao.selectList(lqw); predicates.add(criteriaBuilder.in(root.get("groupId")).value(levelIds));
return teams.stream().map(OrgTeam::getTeamId).collect(Collectors.toList()); }
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;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!