Commit ea3f4954 by 王力

Merge branch 'dev_mp2jpa' into 'develop'

Dev mp2jpa

See merge request !314
2 parents 100b1ee7 998bd459
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.EngineerSkillGroupEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface EngineerSkillGroupDao extends JpaRepository<EngineerSkillGroupEntity, Integer> {
List<EngineerSkillGroupEntity> findByEngineerCode(String engineerCode);
List<EngineerSkillGroupEntity> findByEngineerCodeAndStatus(String engineerCode, Integer status);
List<EngineerSkillGroupEntity> findByEngineerCodeInAndStatus(List<String> engineerCodes, Integer status);
List<EngineerSkillGroupEntity> findBySkillGroupCode(String skillGroupCode);
List<EngineerSkillGroupEntity> findBySkillGroupCodeAnd(String skillGroupCode, Integer status);
}
...@@ -8,10 +8,13 @@ import org.springframework.data.jpa.repository.Query; ...@@ -8,10 +8,13 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date; import java.util.Date;
import java.util.List;
@Repository @Repository
public interface OrderEventDao extends JpaRepository<OrderEventEntity, Integer> { public interface OrderEventDao extends JpaRepository<OrderEventEntity, Integer> {
List<OrderEventEntity> findByOrderId(String orderId);
@Query("select a from OrderEventEntity a join OrderInfoEntity b on a.orderId=b.orderId where b.orgClusterId = :clusterId and DATE(a.createTime) = :date") @Query("select a from OrderEventEntity a join OrderInfoEntity b on a.orderId=b.orderId where b.orgClusterId = :clusterId and DATE(a.createTime) = :date")
Page<OrderEventEntity> findAllByClusterId(String clusterId, Date date, Pageable pageable); Page<OrderEventEntity> findAllByClusterId(String clusterId, Date date, Pageable pageable);
......
...@@ -10,6 +10,8 @@ import java.util.List; ...@@ -10,6 +10,8 @@ import java.util.List;
public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long> { public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long> {
OrderInfoEntity getByOrderId(String orderId); OrderInfoEntity getByOrderId(String orderId);
List<OrderInfoEntity> findByOrderId(String orderId);
List<OrderInfoEntity> findByDtAndEngineerCodeIn(LocalDate date, List<String> engineerCodes); List<OrderInfoEntity> findByDtAndEngineerCodeIn(LocalDate date, List<String> engineerCodes);
@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") @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")
......
...@@ -23,32 +23,31 @@ import java.util.stream.Collectors; ...@@ -23,32 +23,31 @@ import java.util.stream.Collectors;
public class OrderServiceDetailImpl implements OrderServiceDetail { public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired @Autowired
private OrderInfoMPDao orderInfoMPDao; private OrderInfoDao orderInfoDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private OrderTimelineMPDao orderTimelineMPDao; private OrderTimelineMPDao orderTimelineMPDao;
@Autowired @Autowired
private OrderEventMPDao orderEventMPDao; private OrderEventDao orderEventDao;
@Autowired @Autowired
private OrgGroupMPDao orgGroupMPDao; private OrgGroupDao orgGroupDao;
@Autowired @Autowired
private EngineerSkillGroupMPDao engineerSkillGroupMPDao; private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired @Autowired
private SkillInfoMPDao skillInfoMPDao; private SkillInfoDao skillInfoDao;
@Transactional @Transactional
@Override @Override
public Result<?> getOrderServiceDetail(String orderId) { public Result<?> getOrderServiceDetail(String orderId) {
OrderInfo order = orderInfoMPDao.getByOrderId(orderId); OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order); List<KV> items = this.packOrderDetail(order);
...@@ -82,7 +81,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -82,7 +81,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
public Result<?> getOrderServiceDynamics(String orderId) { public Result<?> getOrderServiceDynamics(String orderId) {
// 获取服务单动态 // 获取服务单动态
List<OrderEvent> events = this.queryOrderEvents(orderId); List<OrderEventEntity> events = orderEventDao.findByOrderId(orderId);
// pack 动态items // pack 动态items
List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events); List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events);
...@@ -101,7 +100,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -101,7 +100,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
OrderAppointmentListResp res = new OrderAppointmentListResp(); OrderAppointmentListResp res = new OrderAppointmentListResp();
// 查询预约单列表 // 查询预约单列表
List<OrderInfo> orders = orderInfoMPDao.selectByOrderId(orderId); List<OrderInfoEntity> orders = orderInfoDao.findByOrderId(orderId);
if (orders.isEmpty()) { if (orders.isEmpty()) {
// 没有指派单列表,返回 // 没有指派单列表,返回
res.setOrderId(orderId); res.setOrderId(orderId);
...@@ -111,15 +110,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -111,15 +110,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
// 获取工程师基础信息列表 // 获取工程师基础信息列表
Set<String> set = new HashSet<>(); Set<String> set = new HashSet<>();
orders.stream().map(OrderInfo::getEngineerCode).forEach(set::add); orders.stream().map(OrderInfoEntity::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfo::getEngineerCodeSub).forEach(set::add); orders.stream().map(OrderInfoEntity::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set); List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfo> egInfo = this.getEngineerInfos(engineerCodes); HashMap<String, EngineerInfoEntity> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息 // 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfo::getGroupId).collect(Collectors.toList()); List<String> groupIds = egInfo.values().stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroup> groups = this.queryOrgGroups(groupIds); HashMap<String, OrgGroupEntity> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills> // 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(engineerCodes); Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
...@@ -127,13 +126,13 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -127,13 +126,13 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
// 获取subOrder订单timeline // 获取subOrder订单timeline
Map<String, List<OrderTimeline>> timelines = this.getOrderTimelines(orderId); Map<String, List<OrderTimeline>> timelines = this.getOrderTimelines(orderId);
Comparator<OrderInfo> dtDesc = Comparator.comparing(OrderInfo::getDt).reversed(); Comparator<OrderInfoEntity> dtDesc = Comparator.comparing(OrderInfoEntity::getDt).reversed();
List<OrderInfo> results = orders.stream().sorted(dtDesc).collect(Collectors.toList()); List<OrderInfoEntity> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
LocalDate lastDt = results.get(0).getDt(); //最新预约 LocalDate lastDt = results.get(0).getDt(); //最新预约
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>(); List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderInfo o : results) { for (OrderInfoEntity o : results) {
EngineerInfo eg = egInfo.getOrDefault(o.getEngineerCode(), null); EngineerInfoEntity eg = egInfo.getOrDefault(o.getEngineerCode(), null);
if(eg == null) { if(eg == null) {
log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId()); log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId());
continue; continue;
...@@ -155,7 +154,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -155,7 +154,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment(); OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title); item.setTitle(title);
item.setEngineerCode(o.getEngineerCode()); item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeBegin())); item.setExpectTime(TimeUtils.IsoLocalDateTime2String(o.getExpectTimeBegin()));
item.setTimelines(this.packOrderTimeline(timelines.getOrDefault(o.getSubId(), null))); item.setTimelines(this.packOrderTimeline(timelines.getOrDefault(o.getSubId(), null)));
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId()))); item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
...@@ -173,7 +172,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -173,7 +172,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
List<String> block = new ArrayList<>(); List<String> block = new ArrayList<>();
// 获取订单详情 // 获取订单详情
OrderInfo order = orderInfoMPDao.getByOrderId(orderId); OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp(); OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId); res.setOrderId(orderId);
...@@ -183,37 +182,29 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -183,37 +182,29 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
return Result.success(res); return Result.success(res);
} }
private List<OrderEvent> queryOrderEvents(String orderId) { private HashMap<String, OrgGroupEntity> queryOrgGroups(List<String> groupIds) {
LambdaQueryWrapper<OrderEvent> lqw = new LambdaQueryWrapper<>(); HashMap<String, OrgGroupEntity> map = new HashMap<>();
lqw.eq(OrderEvent::getOrderId, orderId);
return orderEventMPDao.selectList(lqw);
}
private HashMap<String, OrgGroup> queryOrgGroups(List<String> groupIds) {
HashMap<String, OrgGroup> map = new HashMap<>();
if (groupIds.isEmpty()) { if (groupIds.isEmpty()) {
return map; return map;
} }
LambdaQueryWrapper<OrgGroup> lqw = new LambdaQueryWrapper<>(); List<OrgGroupEntity> records = orgGroupDao.findByGroupIdIn(groupIds);
lqw.in(OrgGroup::getGroupId, groupIds); for (OrgGroupEntity r : records) {
List<OrgGroup> records = orgGroupMPDao.selectList(lqw);
for (OrgGroup r : records) {
map.put(r.getGroupId(), r); map.put(r.getGroupId(), r);
} }
return map; return map;
} }
private HashMap<String, EngineerInfo> getEngineerInfos(List<String> egCodes) { private HashMap<String, EngineerInfoEntity> getEngineerInfos(List<String> egCodes) {
// 获取工程师信息列表 // 获取工程师信息列表
HashMap<String, EngineerInfo> map = new HashMap<>(); HashMap<String, EngineerInfoEntity> map = new HashMap<>();
if (egCodes.isEmpty()) { if (egCodes.isEmpty()) {
return map; return map;
} }
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.in(EngineerInfo::getEngineerCode, egCodes); lqw.in(EngineerInfo::getEngineerCode, egCodes);
List<EngineerInfo> rows = engineerInfoMPDao.selectList(lqw); List<EngineerInfoEntity> rows = engineerInfoDao.findByEngineerCodeIn(egCodes);;
for (EngineerInfo row : rows) { for (EngineerInfoEntity row : rows) {
map.put(row.getEngineerCode(), row); map.put(row.getEngineerCode(), row);
} }
return map; return map;
...@@ -226,25 +217,22 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -226,25 +217,22 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
if (egCodes.isEmpty()) { if (egCodes.isEmpty()) {
return map; return map;
} }
LambdaQueryWrapper<EngineerSkillGroup> lqw = new LambdaQueryWrapper<>(); List<EngineerSkillGroupEntity> rows = engineerSkillGroupDao.findByEngineerCodeInAndStatus(egCodes, 1);
lqw.select(EngineerSkillGroup::getEngineerCode, EngineerSkillGroup::getSkillGroupCode);
lqw.in(EngineerSkillGroup::getEngineerCode, egCodes);
lqw.eq(EngineerSkillGroup::getStatus, 1);
List<EngineerSkillGroup> rows = engineerSkillGroupMPDao.selectList(lqw);
// 根据engineerCode排序 // 根据engineerCode排序
Comparator<EngineerSkillGroup> cmp = Comparator.comparing(EngineerSkillGroup::getEngineerCode); Comparator<EngineerSkillGroupEntity> cmp = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode);
List<EngineerSkillGroup> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList()); List<EngineerSkillGroupEntity> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组 // 根据engineerCode分组
Map<String, List<EngineerSkillGroup>> results = sortedResults.stream().collect(Collectors.groupingBy(EngineerSkillGroup::getEngineerCode)); Map<String, List<EngineerSkillGroupEntity>> results = sortedResults.stream().collect(
Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
// 获取所有技能 // 获取所有技能
HashMap<String, String> skills = this.queryAllSkills(); HashMap<String, String> skills = this.queryAllSkills();
for (Map.Entry<String, List<EngineerSkillGroup>> entry : results.entrySet()) { for (Map.Entry<String, List<EngineerSkillGroupEntity>> entry : results.entrySet()) {
String engineerCode = entry.getKey(); String engineerCode = entry.getKey();
List<String> engineerSkills = new ArrayList<>(); List<String> engineerSkills = new ArrayList<>();
for (EngineerSkillGroup r : entry.getValue()) { for (EngineerSkillGroupEntity r : entry.getValue()) {
String skill = skills.getOrDefault(r.getSkillGroupCode(), ""); String skill = skills.getOrDefault(r.getSkillGroupCode(), "");
if (skill.isEmpty()) { if (skill.isEmpty()) {
continue; continue;
...@@ -275,15 +263,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -275,15 +263,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
private HashMap<String, String> queryAllSkills() { private HashMap<String, String> queryAllSkills() {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
List<SkillInfo> records = skillInfoMPDao.selectList(null); List<SkillInfoEntity> records = skillInfoDao.findAll();
Comparator<SkillInfo> cmp = Comparator.comparing(SkillInfo::getSkillGroupCode); Comparator<SkillInfoEntity> cmp = Comparator.comparing(SkillInfoEntity::getSkillGroupCode);
List<SkillInfo> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList()); List<SkillInfoEntity> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList());
Map<String, List<SkillInfo>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfo::getSkillGroupCode)); Map<String, List<SkillInfoEntity>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfoEntity::getSkillGroupCode));
for (Map.Entry<String, List<SkillInfo>> entry : results.entrySet()) { for (Map.Entry<String, List<SkillInfoEntity>> entry : results.entrySet()) {
String skillGroupCode = entry.getKey(); String skillGroupCode = entry.getKey();
HashSet<String> categories = new HashSet<>(); HashSet<String> categories = new HashSet<>();
for (SkillInfo s : entry.getValue()) { for (SkillInfoEntity s : entry.getValue()) {
categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory())); categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory()));
} }
List<String> skills = new ArrayList<>(categories); List<String> skills = new ArrayList<>(categories);
...@@ -292,7 +280,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -292,7 +280,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
return map; return map;
} }
private List<KV> packEngineerItems(EngineerInfo eg, String skill, OrgGroup group) { private List<KV> packEngineerItems(EngineerInfoEntity eg, String skill, OrgGroupEntity group) {
// 获取工程师信息 // 获取工程师信息
List<KV> items = new ArrayList<>(); List<KV> items = new ArrayList<>();
...@@ -338,7 +326,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -338,7 +326,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
return items; return items;
} }
private List<KV> packOrderDetail(OrderInfo order) { private List<KV> packOrderDetail(OrderInfoEntity order) {
List<KV> items = new ArrayList<>(); List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName())); items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone())); items.add(this.packOrderItem("客户电话", order.getPhone()));
...@@ -347,26 +335,26 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -347,26 +335,26 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
items.add(this.packOrderItem("设备", order.getType())); items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill())); items.add(this.packOrderItem("服务", order.getSkill()));
items.add(this.packOrderItem("故障描述", order.getFaultDescribe())); items.add(this.packOrderItem("故障描述", order.getFaultDescribe()));
items.add(this.packOrderItem("意向时间", TimeUtils.IsoTimestamp2DateTime(order.getExpectTimeBegin()))); items.add(this.packOrderItem("意向时间", TimeUtils.IsoLocalDateTime2String(order.getExpectTimeBegin())));
items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc())); items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc()));
items.add(this.packOrderItem("预约方式", order.getSource())); items.add(this.packOrderItem("预约方式", order.getSource()));
items.add(this.packOrderItem("标签", order.getTags())); items.add(this.packOrderItem("标签", order.getTags()));
items.add(this.packOrderItem("创建时间", TimeUtils.IsoTimestamp2DateTime(order.getCreateTime()))); items.add(this.packOrderItem("创建时间", TimeUtils.IsoLocalDateTime2String(order.getCreateTime())));
items.add(this.packOrderItem("备注", order.getApplyNote())); items.add(this.packOrderItem("备注", order.getApplyNote()));
return items; return items;
} }
private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEvent> events) { private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEventEntity> events) {
List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>(); List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>();
// 根据happen排序 // 根据happen排序
Comparator<OrderEvent> happen = Comparator.comparing(OrderEvent::getHappen); Comparator<OrderEventEntity> happen = Comparator.comparing(OrderEventEntity::getHappen);
List<OrderEvent> results = events.stream().sorted(happen).collect(Collectors.toList()); List<OrderEventEntity> results = events.stream().sorted(happen).collect(Collectors.toList());
for (OrderEvent o : results) { for (OrderEventEntity o : results) {
OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics(); OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics();
d.setTitle(o.getEvent()); d.setTitle(o.getEvent());
d.setSubTitle(String.format("操作人: %s", o.getOperatorName())); d.setSubTitle(String.format("操作人: %s", o.getOperatorName()));
d.setTime(TimeUtils.IsoTimestamp2DateTime(o.getHappen())); d.setTime(TimeUtils.IsoLocalDateTime2String(o.getHappen()));
d.setMemo(o.getMemo()); d.setMemo(o.getMemo());
dynamics.add(d); dynamics.add(d);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!