|
|
@@ -2,18 +2,31 @@ package com.sckw.transport.service;
|
|
|
|
|
|
|
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
|
+import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.transport.common.config.AmapProperties;
|
|
|
+import com.sckw.transport.model.KwtLogisticsOrder;
|
|
|
import com.sckw.transport.model.KwtWaybillOrder;
|
|
|
+import com.sckw.transport.model.KwtWaybillOrderSubtask;
|
|
|
import com.sckw.transport.model.TaskStatisticsVo;
|
|
|
+import com.sckw.transport.model.param.LogisticsOrderStatisticsReq;
|
|
|
+import com.sckw.transport.model.vo.LogOrderStatisticsVo;
|
|
|
+import com.sckw.transport.repository.KwtLogisticsOrderRepository;
|
|
|
import com.sckw.transport.repository.KwtWaybillOrderRepository;
|
|
|
+import com.sckw.transport.repository.KwtWaybillOrderSubtaskRepository;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author PC
|
|
|
@@ -24,6 +37,8 @@ import java.util.Objects;
|
|
|
public class KwfTaskService {
|
|
|
private final KwtWaybillOrderRepository kwtWaybillOrderRepository;
|
|
|
private final AmapProperties amapProperties;
|
|
|
+ private final KwtWaybillOrderSubtaskRepository kwtWaybillOrderSubtaskRepository;
|
|
|
+ private final KwtLogisticsOrderRepository kwtLogisticsOrderRepository;
|
|
|
public TaskStatisticsVo getTaskStatistics() {
|
|
|
log.info("开始获取任务统计信息请求参数");
|
|
|
List<KwtWaybillOrder> waybillOrder= kwtWaybillOrderRepository.findAll();
|
|
|
@@ -41,6 +56,26 @@ public class KwfTaskService {
|
|
|
long completedCount = waybillOrder.stream()
|
|
|
.filter(w -> Objects.equals(w.getStatus(), CarWaybillEnum.COMPLETION_UNLOADING.getCode()))
|
|
|
.count();
|
|
|
+ //昨日累计任务数
|
|
|
+ long yesterdayTaskCount = getYesterdayTaskCount(waybillOrder);
|
|
|
+ // 前一天累计任务数
|
|
|
+ long taskTotalBeforeYesterday = getTaskTotalBeforeYesterday(waybillOrder);
|
|
|
+
|
|
|
+ //计算上月卸货吨数
|
|
|
+ double unloadTon = getUnloadTon(waybillOrder);
|
|
|
+
|
|
|
+ //获取本月初到当前时间的数据
|
|
|
+ double unloadTonThisMonth = getUnloadTonThisMonth(waybillOrder);
|
|
|
+ //获取上个月初到某个时间点的数据
|
|
|
+ double unloadTonBeforeMonth = getUnloadTonBeforeMonth(waybillOrder);
|
|
|
+ // 计算增长率
|
|
|
+ double growthRate = (double) (yesterdayTaskCount - taskTotalBeforeYesterday) / taskTotalBeforeYesterday * 100;
|
|
|
+ return getTaskStatisticsVo(totalCount, taskingCount, completedCount, yesterdayTaskCount,
|
|
|
+ taskTotalBeforeYesterday, growthRate, unloadTon, unloadTonThisMonth, unloadTonBeforeMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private TaskStatisticsVo getTaskStatisticsVo(int totalCount, long taskingCount, long completedCount, long yesterdayTaskCount, long taskTotalBeforeYesterday, double growthRate, double unloadTon, double unloadTonThisMonth, double unloadTonBeforeMonth) {
|
|
|
TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo();
|
|
|
taskStatisticsVo.setTaskTotal(String.valueOf(totalCount));
|
|
|
taskStatisticsVo.setTaskRunning(String.valueOf(taskingCount));
|
|
|
@@ -48,9 +83,76 @@ public class KwfTaskService {
|
|
|
taskStatisticsVo.setTaskPercent(taskingCount == 0 ? "0" : String.format("%.2f", (double) taskingCount / totalCount * 100));
|
|
|
taskStatisticsVo.setTruckAbnormal("0");
|
|
|
taskStatisticsVo.setWarningTotal("0");
|
|
|
+ taskStatisticsVo.setTaskTotalYesterday(String.valueOf(yesterdayTaskCount));
|
|
|
+ taskStatisticsVo.setTaskTotalBeforeYesterday(String.valueOf(taskTotalBeforeYesterday));
|
|
|
+ taskStatisticsVo.setTaskPercentChange(String.format("%.2f", growthRate));
|
|
|
+ taskStatisticsVo.setUnloadTon(String.valueOf(unloadTon));
|
|
|
+ taskStatisticsVo.setUnloadTonThisMonth(String.valueOf(unloadTonThisMonth));
|
|
|
+ taskStatisticsVo.setUnloadTonBeforeMonth(String.valueOf(unloadTonBeforeMonth));
|
|
|
+ taskStatisticsVo.setWaybillTotalYesterday(String.valueOf(yesterdayTaskCount));
|
|
|
+ taskStatisticsVo.setWaybillTotalBeforeYesterday(String.valueOf(taskTotalBeforeYesterday));
|
|
|
+ taskStatisticsVo.setWaybillPercentChange(String.format("%.2f", growthRate));
|
|
|
return taskStatisticsVo;
|
|
|
}
|
|
|
|
|
|
+ private double getUnloadTonBeforeMonth(List<KwtWaybillOrder> waybillOrder) {
|
|
|
+ Date startBeforeMonth = Date.from(DateUtils.getStartMonth(1).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date endBeforeMonth = Date.from(LocalDateTime.now().minusMonths(1).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ return geUnloadAmount(waybillOrder, startBeforeMonth, endBeforeMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+ private double geUnloadAmount(List<KwtWaybillOrder> waybillOrder, Date startBeforeMonth, Date endBeforeMonth) {
|
|
|
+ Set<Long> wOrderIds = waybillOrder.stream()
|
|
|
+ .filter(w -> w.getCreateTime() != null)
|
|
|
+ .filter(w -> !w.getCreateTime().before(startBeforeMonth) && w.getCreateTime().before(endBeforeMonth))
|
|
|
+ .map(KwtWaybillOrder::getId).collect(Collectors.toSet());
|
|
|
+ if (CollectionUtils.isEmpty(wOrderIds)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ List<KwtWaybillOrderSubtask> beforeMonthWaybillOrderSubtasks = kwtWaybillOrderSubtaskRepository.findOneByWOrderIds(wOrderIds);
|
|
|
+ if (CollectionUtils.isEmpty(beforeMonthWaybillOrderSubtasks)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return beforeMonthWaybillOrderSubtasks.stream()
|
|
|
+ .filter(w -> w.getUnloadAmount() != null)
|
|
|
+ .mapToDouble(x -> x.getUnloadAmount().doubleValue())
|
|
|
+ .sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ private double getUnloadTonThisMonth(List<KwtWaybillOrder> waybillOrder) {
|
|
|
+ Date startThisMonth = Date.from(DateUtils.getStartMonth(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date endThisMonth = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ return geUnloadAmount(waybillOrder, startThisMonth, endThisMonth);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private double getUnloadTon(List<KwtWaybillOrder> waybillOrder) {
|
|
|
+ Date startMonth = Date.from(DateUtils.getStartMonth(1).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date endMonth = Date.from(DateUtils.getStartMonth(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ //获取运单id列表
|
|
|
+ return geUnloadAmount(waybillOrder, startMonth, endMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long getTaskTotalBeforeYesterday(List<KwtWaybillOrder> waybillOrder) {
|
|
|
+ Date startOfDay = Date.from(DateUtils.getStartDay(2).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date endOfDay = Date.from(DateUtils.getStartDay(1).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ return waybillOrder.stream()
|
|
|
+ .filter(w -> w.getCreateTime() != null)
|
|
|
+ .filter(w -> !w.getCreateTime().before(startOfDay) && w.getCreateTime().before(endOfDay))
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long getYesterdayTaskCount(List<KwtWaybillOrder> waybillOrder) {
|
|
|
+ Date startOfYesterday = Date.from(DateUtils.getStartDay(1).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date startOfToday = Date.from(DateUtils.getStartDay(0).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ // 昨日累计任务数
|
|
|
+ return waybillOrder.stream()
|
|
|
+ .filter(w -> w.getCreateTime() != null)
|
|
|
+ .filter(w -> !w.getCreateTime().before(startOfYesterday) && w.getCreateTime().before(startOfToday))
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取高德地图apiKey
|
|
|
* @return apiKey
|
|
|
@@ -58,4 +160,9 @@ public class KwfTaskService {
|
|
|
public String getMapApikey() {
|
|
|
return amapProperties.getKey();
|
|
|
}
|
|
|
+
|
|
|
+ public LogOrderStatisticsVo getLogisticsOrderStatistics(LogisticsOrderStatisticsReq req) {
|
|
|
+ kwtLogisticsOrderRepository.query();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|