Commit c10eb803 by 刘鑫

Merge branch 'develop' of https://gitlab.dituhui.com/bsh/project/project into develop

2 parents 6cd6bfbe 1804c3ac
......@@ -151,6 +151,12 @@ public class OrderInfoServiceImpl implements OrderInfoService {
if (StringUtils.isNotBlank(request.getDescription())) {
orderInfo.setDescription(request.getDescription());
}
if (BeanServiceFlowEnum.STARTED.getStatus().equals(BeanServiceFlowEnum.getStatusByName(request.getStage()))) {
orderInfo.setActualStartTime(LocalDateTimeUtil.of(request.getHappen()));
}
if (BeanServiceFlowEnum.FINISHED.getStatus().equals(BeanServiceFlowEnum.getStatusByName(request.getStage()))) {
orderInfo.setActualEndTime(LocalDateTimeUtil.of(request.getHappen()));
}
orderInfoDao.save(orderInfo);
//记录流程
commonService.addOrderEvent(request.getOrderId(), "", "BEAN", "BEAN", OrderStatusEnum.NORMAL.getDescription(), request.getStage(), "", LocalDateTimeUtil.of(request.getHappen()));
......@@ -336,7 +342,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
//处理一家多单
// order = handleMultipleOrders(order);
if (!orderDt.isEqual(expectBegin.toLocalDate())){
if (!orderDt.isEqual(expectBegin.toLocalDate())) {
order = handleMultipleOrders(order);
}
order.setOrgClusterId(clusterId);
......
......@@ -159,7 +159,7 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
record.setIsSpecialTime(o.getIsSpecialTime());
record.setActualStartTime(ObjectUtil.isNull(o.getActualStartTime()) ? "" : TimeUtils.IsoTimestamp2DateTime(o.getActualStartTime()));
record.setActualEndTime(ObjectUtil.isNull(o.getActualStartTime()) ? "" : TimeUtils.IsoTimestamp2DateTime(o.getActualEndTime()));
record.setActualEndTime(ObjectUtil.isNull(o.getActualEndTime()) ? "" : TimeUtils.IsoTimestamp2DateTime(o.getActualEndTime()));
if (StringUtils.isNotEmpty(o.getMultipleOrders())) {
List<OrderInfoEntity> byMultipleOrders = orderInfoDao.findByMultipleOrdersAndOrderIdNot(o.getMultipleOrders(), o.getOrderId());
List<OrderServiceList> multipleItems = new ArrayList<>();
......
......@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
......@@ -33,266 +34,267 @@ import java.util.stream.Collectors;
@Service
public class WorkbenchServiceImpl implements WorkbenchService {
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EntityManager entityManager;
@Override
public Result<?> getOrderChangeList(OrderChangeListDTO.Request reqDTO) {
Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getSize());
Page<OrderEventEntity> page;
String levelType = reqDTO.getLevelType();
String levelValue = reqDTO.getLevelValue();
Date date = DateUtil.parse(reqDTO.getDate());
if ("cluster".equals(levelType)) {
page = orderEventDao.findAllByClusterId(levelValue, date, pageable);
} else if ("branch".equals(levelType)) {
page = orderEventDao.findAllByBranchId(levelValue, date, pageable);
} else {
page = orderEventDao.findAllByGroupId(levelValue, date, pageable);
}
List<OrderChangeListDTO.Content> contents = new ArrayList<>();
for (OrderEventEntity entity : page.getContent()) {
OrderChangeListDTO.Content content = new OrderChangeListDTO.Content();
OrderInfoEntity orderInfoEntity = orderInfoDao.getByOrderId(entity.getOrderId());
content.setOrderId(entity.getOrderId())
.setCustomerName(orderInfoEntity.getName())
.setOperator(entity.getOperator())
.setDescription(entity.getDescription())
.setMemo(entity.getMemo())
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private OrderInfoDao orderInfoDao;
@Autowired
private EntityManager entityManager;
@Override
public Result<?> getOrderChangeList(OrderChangeListDTO.Request reqDTO) {
Sort sort = Sort.by(Sort.Order.desc("createTime"));
Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getSize(), sort);
Page<OrderEventEntity> page;
String levelType = reqDTO.getLevelType();
String levelValue = reqDTO.getLevelValue();
Date date = DateUtil.parse(reqDTO.getDate());
if ("cluster".equals(levelType)) {
page = orderEventDao.findAllByClusterId(levelValue, date, pageable);
} else if ("branch".equals(levelType)) {
page = orderEventDao.findAllByBranchId(levelValue, date, pageable);
} else {
page = orderEventDao.findAllByGroupId(levelValue, date, pageable);
}
List<OrderChangeListDTO.Content> contents = new ArrayList<>();
for (OrderEventEntity entity : page.getContent()) {
OrderChangeListDTO.Content content = new OrderChangeListDTO.Content();
OrderInfoEntity orderInfoEntity = orderInfoDao.getByOrderId(entity.getOrderId());
content.setOrderId(entity.getOrderId())
.setCustomerName(orderInfoEntity.getName())
.setOperator(entity.getOperator())
.setDescription(entity.getDescription())
.setMemo(entity.getMemo())
.setUpdateTime(DateUtils.formatDateTime(entity.getUpdateTime()));
contents.add(content);
}
OrderChangeListDTO.Result rs = new OrderChangeListDTO.Result();
rs.setTotal(page.getTotalElements())
.setPages(page.getTotalPages())
.setPageSize(page.getSize())
.setContent(contents);
return Result.success(rs);
}
@Override
public Result<?> getWorkbenchSummary(String levelType, String levelValue, LocalDate dt) {
List<WorkbenchSummaryResp.ItemDTO> items = new ArrayList<>();
HashMap<String, Long> methodSummary = this.transAppointmentMethod(this.queryCountByAppointmentMethod(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO methodItem = new WorkbenchSummaryResp.ItemDTO();
methodItem.setType("order");
methodItem.setRows(this.packValueAppointmentMethod(methodSummary));
items.add(methodItem);
HashMap<String, Long> statusSummary = this.transOrderStatus(this.queryCountByOrderStatus(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO statusItem = new WorkbenchSummaryResp.ItemDTO();
statusItem.setType("order");
statusItem.setRows(this.packValueOrderStatus(statusSummary));
items.add(statusItem);
WorkbenchSummaryResp res = new WorkbenchSummaryResp();
res.setSummary(items);
return Result.success(res);
}
private List<Map<String, Object>> queryCountByAppointmentMethod(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("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) {
HashMap<String, Long> map = new HashMap<>();
Long manualTotal = 0L; // 人工
Long autoTotal = 0L;
Long total = 0L;
for (Map<String, Object> result : results) {
String method = (String) result.get("appointmentMethod");
String status = (String) result.get("appointmentStatus");
Long count = (long) result.get("count");
total += count;
if (method.equals("MANUAL")) {
manualTotal += count;
} else if (method.startsWith("AUTO_")) {
autoTotal += count;
}
if (method.equals("MANUAL") && status.equals("INIT")) {
map.put("manualDealing", count);
} else if (method.equals("AUTO_") && status.equals("INIT")) {
map.put("autoDealing", count);
}
}
map.put("manualTotal", manualTotal);
map.put("autoTotal", autoTotal);
map.put("total", total);
return map;
}
private HashMap<String, Long> transOrderStatus(List<Map<String, Object>> results) {
HashMap<String, Long> map = new HashMap<>();
for (Map<String, Object> result : results) {
String status = (String) result.get("serviceStatus");
Long count = (long) result.get("count");
map.put(status, count);
}
return map;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueAppointmentMethod(HashMap<String, Long> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String urlName = "DispatchBenchManage";
Long manualDealing = summary.getOrDefault("manualDealing", 0L);
Long manualTotal = summary.getOrDefault("manualTotal", 0L);
Long autoDealing = summary.getOrDefault("autoDealing", 0L);
Long autoTotal = summary.getOrDefault("autoTotal", 0L);
Long total = summary.getOrDefault("total", 0L);
HashMap<String, List<String>> p = this.packParams("appointmentStatus", OrderFlowEnum.INIT.name());
HashMap<String, List<String>> p1 = this.packParams("appointmentType", "MANUAL");
p1.putAll(p);
items.add(new WorkbenchSummaryResp.ValueDTO("待人工处理", manualDealing.toString(), manualTotal.toString(), "#FF8000", urlName, p1));
HashMap<String, List<String>> p2 = this.packParams("appointmentType", "AUTO_NOW", "AUTO_BATCH", "PROTECTION");
p2.putAll(p);
items.add(new WorkbenchSummaryResp.ValueDTO("待自动处理", autoDealing.toString(), autoTotal.toString(), "#469967", urlName, p2));
items.add(new WorkbenchSummaryResp.ValueDTO("全部订单", null, total.toString(), null, urlName, new HashMap<>()));
return items;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueOrderStatus(HashMap<String, Long> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String urlName = ""; // 不返回,前端就不跳转了
Long assigned = summary.getOrDefault("INIT", 0L);
Long pending = summary.getOrDefault("PENDING", 0L);
Long dealing = assigned + pending;
Long started = summary.getOrDefault("STARTED", 0L);
Long finished = summary.getOrDefault("FINISHED", 0L) + summary.getOrDefault("UNFINISHED", 0L);
Long cancel = 0L;
HashMap<String, List<String>> p1 = this.packParams("appointmentStatus", "ASSIGNED", "CONTACTED", "DEPARTED");
items.add(new WorkbenchSummaryResp.ValueDTO("待上门", dealing.toString(), null, "#469967", urlName, p1));
HashMap<String, List<String>> p2 = this.packParams("appointmentStatus", "STARTED");
items.add(new WorkbenchSummaryResp.ValueDTO("服务中", started.toString(), null, "#016FFF", urlName, p2));
HashMap<String, List<String>> p3 = this.packParams("appointmentStatus", "FINISHED");
items.add(new WorkbenchSummaryResp.ValueDTO("已完成", finished.toString(), null, null, urlName, p3));
HashMap<String, List<String>> p4 = this.packParams("appointmentStatus", "CANCELED");
items.add(new WorkbenchSummaryResp.ValueDTO("已取消", cancel.toString(), null, null, urlName, p4));
HashMap<String, List<String>> p5 = this.packParams("appointmentStatus", "RESCHEDULED");
items.add(new WorkbenchSummaryResp.ValueDTO("已改约", "0", null, null, urlName, p5));
items.add(new WorkbenchSummaryResp.ValueDTO("已延误", "0", null, "#FF3D44", urlName, new HashMap<>()));
return items;
}
private <T> HashMap<String, List<T>> packParams(String key, T... values) {
HashMap<String, List<T>> map = new HashMap<>();
List<T> value = new ArrayList<>();
Collections.addAll(value, values);
map.put(key, value);
return map;
}
contents.add(content);
}
OrderChangeListDTO.Result rs = new OrderChangeListDTO.Result();
rs.setTotal(page.getTotalElements())
.setPages(page.getTotalPages())
.setPageSize(page.getSize())
.setContent(contents);
return Result.success(rs);
}
@Override
public Result<?> getWorkbenchSummary(String levelType, String levelValue, LocalDate dt) {
List<WorkbenchSummaryResp.ItemDTO> items = new ArrayList<>();
HashMap<String, Long> methodSummary = this.transAppointmentMethod(this.queryCountByAppointmentMethod(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO methodItem = new WorkbenchSummaryResp.ItemDTO();
methodItem.setType("order");
methodItem.setRows(this.packValueAppointmentMethod(methodSummary));
items.add(methodItem);
HashMap<String, Long> statusSummary = this.transOrderStatus(this.queryCountByOrderStatus(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO statusItem = new WorkbenchSummaryResp.ItemDTO();
statusItem.setType("order");
statusItem.setRows(this.packValueOrderStatus(statusSummary));
items.add(statusItem);
WorkbenchSummaryResp res = new WorkbenchSummaryResp();
res.setSummary(items);
return Result.success(res);
}
private List<Map<String, Object>> queryCountByAppointmentMethod(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("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) {
HashMap<String, Long> map = new HashMap<>();
Long manualTotal = 0L; // 人工
Long autoTotal = 0L;
Long total = 0L;
for (Map<String, Object> result : results) {
String method = (String) result.get("appointmentMethod");
String status = (String) result.get("appointmentStatus");
Long count = (long) result.get("count");
total += count;
if (method.equals("MANUAL")) {
manualTotal += count;
} else if (method.startsWith("AUTO_")) {
autoTotal += count;
}
if (method.equals("MANUAL") && status.equals("INIT")) {
map.put("manualDealing", count);
} else if (method.equals("AUTO_") && status.equals("INIT")) {
map.put("autoDealing", count);
}
}
map.put("manualTotal", manualTotal);
map.put("autoTotal", autoTotal);
map.put("total", total);
return map;
}
private HashMap<String, Long> transOrderStatus(List<Map<String, Object>> results) {
HashMap<String, Long> map = new HashMap<>();
for (Map<String, Object> result : results) {
String status = (String) result.get("serviceStatus");
Long count = (long) result.get("count");
map.put(status, count);
}
return map;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueAppointmentMethod(HashMap<String, Long> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String urlName = "DispatchBenchManage";
Long manualDealing = summary.getOrDefault("manualDealing", 0L);
Long manualTotal = summary.getOrDefault("manualTotal", 0L);
Long autoDealing = summary.getOrDefault("autoDealing", 0L);
Long autoTotal = summary.getOrDefault("autoTotal", 0L);
Long total = summary.getOrDefault("total", 0L);
HashMap<String, List<String>> p = this.packParams("appointmentStatus", OrderFlowEnum.INIT.name());
HashMap<String, List<String>> p1 = this.packParams("appointmentType", "MANUAL");
p1.putAll(p);
items.add(new WorkbenchSummaryResp.ValueDTO("待人工处理", manualDealing.toString(), manualTotal.toString(), "#FF8000", urlName, p1));
HashMap<String, List<String>> p2 = this.packParams("appointmentType", "AUTO_NOW", "AUTO_BATCH", "PROTECTION");
p2.putAll(p);
items.add(new WorkbenchSummaryResp.ValueDTO("待自动处理", autoDealing.toString(), autoTotal.toString(), "#469967", urlName, p2));
items.add(new WorkbenchSummaryResp.ValueDTO("全部订单", null, total.toString(), null, urlName, new HashMap<>()));
return items;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueOrderStatus(HashMap<String, Long> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String urlName = ""; // 不返回,前端就不跳转了
Long assigned = summary.getOrDefault("INIT", 0L);
Long pending = summary.getOrDefault("PENDING", 0L);
Long dealing = assigned + pending;
Long started = summary.getOrDefault("STARTED", 0L);
Long finished = summary.getOrDefault("FINISHED", 0L) + summary.getOrDefault("UNFINISHED", 0L);
Long cancel = 0L;
HashMap<String, List<String>> p1 = this.packParams("appointmentStatus", "ASSIGNED", "CONTACTED", "DEPARTED");
items.add(new WorkbenchSummaryResp.ValueDTO("待上门", dealing.toString(), null, "#469967", urlName, p1));
HashMap<String, List<String>> p2 = this.packParams("appointmentStatus", "STARTED");
items.add(new WorkbenchSummaryResp.ValueDTO("服务中", started.toString(), null, "#016FFF", urlName, p2));
HashMap<String, List<String>> p3 = this.packParams("appointmentStatus", "FINISHED");
items.add(new WorkbenchSummaryResp.ValueDTO("已完成", finished.toString(), null, null, urlName, p3));
HashMap<String, List<String>> p4 = this.packParams("appointmentStatus", "CANCELED");
items.add(new WorkbenchSummaryResp.ValueDTO("已取消", cancel.toString(), null, null, urlName, p4));
HashMap<String, List<String>> p5 = this.packParams("appointmentStatus", "RESCHEDULED");
items.add(new WorkbenchSummaryResp.ValueDTO("已改约", "0", null, null, urlName, p5));
items.add(new WorkbenchSummaryResp.ValueDTO("已延误", "0", null, "#FF3D44", urlName, new HashMap<>()));
return items;
}
private <T> HashMap<String, List<T>> packParams(String key, T... values) {
HashMap<String, List<T>> map = new HashMap<>();
List<T> value = new ArrayList<>();
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!