Commit beb4ea05 by huangjinxin

fix:格式化代码

1 parent 05eb6669
......@@ -20,334 +20,335 @@ import java.util.stream.Collectors;
@Service
public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Transactional
@Override
public Result<?> getOrderServiceDetail(String orderId) {
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order);
// 设置订单详情信息
OrderServiceDetailResp.OrderDetail detail = new OrderServiceDetailResp.OrderDetail();
detail.setAddress(String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress()));
detail.setLocation(String.format("%s,%s", order.getX(), order.getY()));
detail.setDate(TimeUtils.IsoLocalDate2String(order.getDt()));
detail.setBrand(order.getBrand());
detail.setType(order.getType());
detail.setSkill(order.getSkill());
OrderServiceDetailResp res = new OrderServiceDetailResp();
res.setOrderId(orderId);
res.setRisk("");
res.setRiskDesc("");
res.setStatusDesc("正常");
res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus());
res.setOrderStatus(order.getOrderStatus());
res.setServiceStatus(order.getServiceStatus());
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setReschedulingParams(detail);
res.setItems(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderServiceDynamics(String orderId) {
// 获取服务单动态
List<OrderEventEntity> events = orderEventDao.findByOrderId(orderId);
// pack 动态items
List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events);
OrderServiceDynamicsResp res = new OrderServiceDynamicsResp();
res.setOrderId(orderId);
res.setDynamics(dynamics);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderAppointmentList(String orderId) throws BusinessException {
// 获取预约单里列表
OrderAppointmentListResp res = new OrderAppointmentListResp();
// 查询预约单列表
List<OrderInfoEntity> orders = orderInfoDao.findByOrderId(orderId);
if (orders.isEmpty()) {
// 没有指派单列表,返回
res.setOrderId(orderId);
res.setOrders(new ArrayList<>());
return Result.success(res);
}
// 获取工程师基础信息列表
Set<String> set = new HashSet<>();
orders.stream().map(OrderInfoEntity::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfoEntity::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfoEntity> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroupEntity> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
Comparator<OrderInfoEntity> dtDesc = Comparator.comparing(OrderInfoEntity::getDt).reversed();
List<OrderInfoEntity> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
LocalDate lastDt = results.get(0).getDt(); //最新预约
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderInfoEntity o : results) {
EngineerInfoEntity eg = egInfo.getOrDefault(o.getEngineerCode(), null);
if(eg == null) {
log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId());
continue;
}
String skill = egSkill.getOrDefault(o.getEngineerCode(), null);
if(skill == null) {
log.warn("未获得工程师{}基础技能, 订单:{}", o.getEngineerCode(), o.getOrderId());
}
// 获取工程师姓名
String engineerName = (eg != null) ? eg.getName() : o.getEngineerCode();
// 获取title
String title = engineerName;
if (o.getDt().isBefore(lastDt)) {
title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt()));
}
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title);
item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoLocalDateTime2String(o.getExpectTimeBegin()));
item.setTimelines(null); // TODO
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
items.add(item);
}
res.setOrderId(orderId);
res.setOrders(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderTeamBlock(String orderId) {
List<String> block = new ArrayList<>();
// 获取订单详情
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId);
res.setBlock(block);
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setSkill(order.getSkill());
return Result.success(res);
}
private HashMap<String, OrgGroupEntity> queryOrgGroups(List<String> groupIds) {
HashMap<String, OrgGroupEntity> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> records = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity r : records) {
map.put(r.getGroupId(), r);
}
return map;
}
private HashMap<String, EngineerInfoEntity> getEngineerInfos(List<String> egCodes) {
// 获取工程师信息列表
HashMap<String, EngineerInfoEntity> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerInfoEntity> rows = engineerInfoDao.findByEngineerCodeIn(egCodes);;
for (EngineerInfoEntity row : rows) {
map.put(row.getEngineerCode(), row);
}
return map;
}
private Map<String, String> getEngineerSkills(List<String> egCodes) {
// 获取工程师技能列表
Map<String, String> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> rows = engineerSkillGroupDao.findByEngineerCodeInAndStatus(egCodes, true);
// 根据engineerCode排序
Comparator<EngineerSkillGroupEntity> cmp = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode);
List<EngineerSkillGroupEntity> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> results = sortedResults.stream().collect(
Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
// 获取所有技能
HashMap<String, String> skills = this.queryAllSkills();
for (Map.Entry<String, List<EngineerSkillGroupEntity>> entry : results.entrySet()) {
String engineerCode = entry.getKey();
List<String> engineerSkills = new ArrayList<>();
for (EngineerSkillGroupEntity r : entry.getValue()) {
String skill = skills.getOrDefault(r.getSkillGroupCode(), "");
if (skill.isEmpty()) {
continue;
}
engineerSkills.add(skill);
}
map.put(engineerCode, String.join("、", engineerSkills));
}
return map;
}
private HashMap<String, String> queryAllSkills() {
HashMap<String, String> map = new HashMap<>();
List<SkillInfoEntity> records = skillInfoDao.findAll();
Comparator<SkillInfoEntity> cmp = Comparator.comparing(SkillInfoEntity::getSkillGroupCode);
List<SkillInfoEntity> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList());
Map<String, List<SkillInfoEntity>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfoEntity::getSkillGroupCode));
for (Map.Entry<String, List<SkillInfoEntity>> entry : results.entrySet()) {
String skillGroupCode = entry.getKey();
HashSet<String> categories = new HashSet<>();
for (SkillInfoEntity s : entry.getValue()) {
categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory()));
}
List<String> skills = new ArrayList<>(categories);
map.put(skillGroupCode, String.join("、", skills));
}
return map;
}
private List<KV> packEngineerItems(EngineerInfoEntity eg, String skill, OrgGroupEntity group) {
// 获取工程师信息
List<KV> items = new ArrayList<>();
if (eg == null && skill == null) {
return items;
}
if (eg != null) {
String groupName = "";
String kind = "";
if (group != null) {
groupName = group.getGroupName();
switch (group.getKind()) {
case 1:
kind = "分站";
break;
case 2:
kind = "外围";
break;
case 3:
kind = "小组";
break;
case 4:
kind = "网点";
break;
case 5:
kind = "自保点";
break;
default:
break;
}
}
items.add(this.packEngineer("技术员", eg.getName(), "engineer"));
items.add(this.packEngineer("小组", groupName, ""));
items.add(this.packEngineer("类型", kind, ""));
items.add(this.packEngineer("性别", eg.getGender(), ""));
items.add(this.packEngineer("工号", eg.getEngineerCode(), ""));
items.add(this.packEngineer("手机号", eg.getPhone(), ""));
}
items.add(this.packEngineer("技能", skill, ""));
return items;
}
private List<KV> packOrderDetail(OrderInfoEntity order) {
List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone()));
items.add(this.packOrderItem("客户地址", String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress())));
items.add(this.packOrderItem("品牌", order.getBrand()));
items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill()));
items.add(this.packOrderItem("故障描述", order.getFaultDescribe()));
items.add(this.packOrderItem("意向时间", TimeUtils.IsoLocalDateTime2String(order.getExpectTimeBegin())));
items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc()));
items.add(this.packOrderItem("预约方式", order.getSource()));
items.add(this.packOrderItem("标签", order.getTags()));
items.add(this.packOrderItem("创建时间", TimeUtils.IsoLocalDateTime2String(order.getCreateTime())));
items.add(this.packOrderItem("备注", order.getApplyNote()));
return items;
}
private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEventEntity> events) {
List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>();
// 根据happen排序
Comparator<OrderEventEntity> happen = Comparator.comparing(OrderEventEntity::getHappen);
List<OrderEventEntity> results = events.stream().sorted(happen).collect(Collectors.toList());
for (OrderEventEntity o : results) {
OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics();
d.setTitle(o.getEvent());
d.setSubTitle(String.format("操作人: %s", o.getOperatorName()));
d.setTime(TimeUtils.IsoLocalDateTime2String(o.getHappen()));
d.setMemo(o.getMemo());
dynamics.add(d);
}
return dynamics;
}
private KV packEngineer(String title, String value, String type) {
return this.PackKV(title, value, type, null, null);
}
private KV packOrderItem(String title, String value) {
return this.PackKV(title, value, null, null, null);
}
private KV PackKV(String title, String value, String type, String status, Object params) {
KV item = new KV();
item.setLabel(title);
item.setValue(value);
item.setType(type);
item.setStatus(status);
item.setParams(params);
return item;
}
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired
private SkillInfoDao skillInfoDao;
@Transactional
@Override
public Result<?> getOrderServiceDetail(String orderId) {
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order);
// 设置订单详情信息
OrderServiceDetailResp.OrderDetail detail = new OrderServiceDetailResp.OrderDetail();
detail.setAddress(String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress()));
detail.setLocation(String.format("%s,%s", order.getX(), order.getY()));
detail.setDate(TimeUtils.IsoLocalDate2String(order.getDt()));
detail.setBrand(order.getBrand());
detail.setType(order.getType());
detail.setSkill(order.getSkill());
OrderServiceDetailResp res = new OrderServiceDetailResp();
res.setOrderId(orderId);
res.setRisk("");
res.setRiskDesc("");
res.setStatusDesc("正常");
res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus());
res.setOrderStatus(order.getOrderStatus());
res.setServiceStatus(order.getServiceStatus());
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setReschedulingParams(detail);
res.setItems(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderServiceDynamics(String orderId) {
// 获取服务单动态
List<OrderEventEntity> events = orderEventDao.findByOrderId(orderId);
// pack 动态items
List<OrderServiceDynamicsResp.Dynamics> dynamics = this.packOrderDynamics(events);
OrderServiceDynamicsResp res = new OrderServiceDynamicsResp();
res.setOrderId(orderId);
res.setDynamics(dynamics);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderAppointmentList(String orderId) throws BusinessException {
// 获取预约单里列表
OrderAppointmentListResp res = new OrderAppointmentListResp();
// 查询预约单列表
List<OrderInfoEntity> orders = orderInfoDao.findByOrderId(orderId);
if (orders.isEmpty()) {
// 没有指派单列表,返回
res.setOrderId(orderId);
res.setOrders(new ArrayList<>());
return Result.success(res);
}
// 获取工程师基础信息列表
Set<String> set = new HashSet<>();
orders.stream().map(OrderInfoEntity::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfoEntity::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfoEntity> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfoEntity::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroupEntity> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
Comparator<OrderInfoEntity> dtDesc = Comparator.comparing(OrderInfoEntity::getDt).reversed();
List<OrderInfoEntity> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
LocalDate lastDt = results.get(0).getDt(); //最新预约
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderInfoEntity o : results) {
EngineerInfoEntity eg = egInfo.getOrDefault(o.getEngineerCode(), null);
if (eg == null) {
log.warn("未获得工程师{}基础信息, 订单:{}", o.getEngineerCode(), o.getOrderId());
continue;
}
String skill = egSkill.getOrDefault(o.getEngineerCode(), null);
if (skill == null) {
log.warn("未获得工程师{}基础技能, 订单:{}", o.getEngineerCode(), o.getOrderId());
}
// 获取工程师姓名
String engineerName = (eg != null) ? eg.getName() : o.getEngineerCode();
// 获取title
String title = engineerName;
if (o.getDt().isBefore(lastDt)) {
title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt()));
}
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title);
item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoLocalDateTime2String(o.getExpectTimeBegin()));
item.setTimelines(null); // TODO
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
items.add(item);
}
res.setOrderId(orderId);
res.setOrders(items);
return Result.success(res);
}
@Transactional
@Override
public Result<?> getOrderTeamBlock(String orderId) {
List<String> block = new ArrayList<>();
// 获取订单详情
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId);
res.setBlock(block);
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setSkill(order.getSkill());
return Result.success(res);
}
private HashMap<String, OrgGroupEntity> queryOrgGroups(List<String> groupIds) {
HashMap<String, OrgGroupEntity> map = new HashMap<>();
if (groupIds.isEmpty()) {
return map;
}
List<OrgGroupEntity> records = orgGroupDao.findByGroupIdIn(groupIds);
for (OrgGroupEntity r : records) {
map.put(r.getGroupId(), r);
}
return map;
}
private HashMap<String, EngineerInfoEntity> getEngineerInfos(List<String> egCodes) {
// 获取工程师信息列表
HashMap<String, EngineerInfoEntity> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerInfoEntity> rows = engineerInfoDao.findByEngineerCodeIn(egCodes);
;
for (EngineerInfoEntity row : rows) {
map.put(row.getEngineerCode(), row);
}
return map;
}
private Map<String, String> getEngineerSkills(List<String> egCodes) {
// 获取工程师技能列表
Map<String, String> map = new HashMap<>();
if (egCodes.isEmpty()) {
return map;
}
List<EngineerSkillGroupEntity> rows = engineerSkillGroupDao.findByEngineerCodeInAndStatus(egCodes, true);
// 根据engineerCode排序
Comparator<EngineerSkillGroupEntity> cmp = Comparator.comparing(EngineerSkillGroupEntity::getEngineerCode);
List<EngineerSkillGroupEntity> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组
Map<String, List<EngineerSkillGroupEntity>> results = sortedResults.stream().collect(
Collectors.groupingBy(EngineerSkillGroupEntity::getEngineerCode));
// 获取所有技能
HashMap<String, String> skills = this.queryAllSkills();
for (Map.Entry<String, List<EngineerSkillGroupEntity>> entry : results.entrySet()) {
String engineerCode = entry.getKey();
List<String> engineerSkills = new ArrayList<>();
for (EngineerSkillGroupEntity r : entry.getValue()) {
String skill = skills.getOrDefault(r.getSkillGroupCode(), "");
if (skill.isEmpty()) {
continue;
}
engineerSkills.add(skill);
}
map.put(engineerCode, String.join("、", engineerSkills));
}
return map;
}
private HashMap<String, String> queryAllSkills() {
HashMap<String, String> map = new HashMap<>();
List<SkillInfoEntity> records = skillInfoDao.findAll();
Comparator<SkillInfoEntity> cmp = Comparator.comparing(SkillInfoEntity::getSkillGroupCode);
List<SkillInfoEntity> sortedResults = records.stream().sorted(cmp).collect(Collectors.toList());
Map<String, List<SkillInfoEntity>> results = sortedResults.stream().collect(Collectors.groupingBy(SkillInfoEntity::getSkillGroupCode));
for (Map.Entry<String, List<SkillInfoEntity>> entry : results.entrySet()) {
String skillGroupCode = entry.getKey();
HashSet<String> categories = new HashSet<>();
for (SkillInfoEntity s : entry.getValue()) {
categories.add(String.format("%s%s", s.getTypeCategory(), s.getSkillCategory()));
}
List<String> skills = new ArrayList<>(categories);
map.put(skillGroupCode, String.join("、", skills));
}
return map;
}
private List<KV> packEngineerItems(EngineerInfoEntity eg, String skill, OrgGroupEntity group) {
// 获取工程师信息
List<KV> items = new ArrayList<>();
if (eg == null && skill == null) {
return items;
}
if (eg != null) {
String groupName = "";
String kind = "";
if (group != null) {
groupName = group.getGroupName();
switch (group.getKind()) {
case 1:
kind = "分站";
break;
case 2:
kind = "外围";
break;
case 3:
kind = "小组";
break;
case 4:
kind = "网点";
break;
case 5:
kind = "自保点";
break;
default:
break;
}
}
items.add(this.packEngineer("技术员", eg.getName(), "engineer"));
items.add(this.packEngineer("小组", groupName, ""));
items.add(this.packEngineer("类型", kind, ""));
items.add(this.packEngineer("性别", eg.getGender(), ""));
items.add(this.packEngineer("工号", eg.getEngineerCode(), ""));
items.add(this.packEngineer("手机号", eg.getPhone(), ""));
}
items.add(this.packEngineer("技能", skill, ""));
return items;
}
private List<KV> packOrderDetail(OrderInfoEntity order) {
List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone()));
items.add(this.packOrderItem("客户地址", String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress())));
items.add(this.packOrderItem("品牌", order.getBrand()));
items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill()));
items.add(this.packOrderItem("故障描述", order.getFaultDescribe()));
items.add(this.packOrderItem("意向时间", TimeUtils.IsoLocalDateTime2String(order.getExpectTimeBegin())));
items.add(this.packOrderItem("时间要求", order.getExpectTimeDesc()));
items.add(this.packOrderItem("预约方式", order.getSource()));
items.add(this.packOrderItem("标签", order.getTags()));
items.add(this.packOrderItem("创建时间", TimeUtils.IsoLocalDateTime2String(order.getCreateTime())));
items.add(this.packOrderItem("备注", order.getApplyNote()));
return items;
}
private List<OrderServiceDynamicsResp.Dynamics> packOrderDynamics(List<OrderEventEntity> events) {
List<OrderServiceDynamicsResp.Dynamics> dynamics = new ArrayList<>();
// 根据happen排序
Comparator<OrderEventEntity> happen = Comparator.comparing(OrderEventEntity::getHappen);
List<OrderEventEntity> results = events.stream().sorted(happen).collect(Collectors.toList());
for (OrderEventEntity o : results) {
OrderServiceDynamicsResp.Dynamics d = new OrderServiceDynamicsResp.Dynamics();
d.setTitle(o.getEvent());
d.setSubTitle(String.format("操作人: %s", o.getOperatorName()));
d.setTime(TimeUtils.IsoLocalDateTime2String(o.getHappen()));
d.setMemo(o.getMemo());
dynamics.add(d);
}
return dynamics;
}
private KV packEngineer(String title, String value, String type) {
return this.PackKV(title, value, type, null, null);
}
private KV packOrderItem(String title, String value) {
return this.PackKV(title, value, null, null, null);
}
private KV PackKV(String title, String value, String type, String status, Object params) {
KV item = new KV();
item.setLabel(title);
item.setValue(value);
item.setType(type);
item.setStatus(status);
item.setParams(params);
return item;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!