Explorar el Código

update 更新APP 运单看板统计数据接口

chenlin hace 2 años
padre
commit
1313eeebff

+ 37 - 3
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/enterpriseApp/AppWayBillController.java

@@ -24,12 +24,12 @@ public class AppWayBillController {
     WaybillManagementService waybillManagementService;
 
     /**
-     * APP 运单统计分类 - [运输中|已完成]
+     * APP 运单统计分类 - [运输中|已完成] - 数据库
      * @param keyword   查询关键字
      * @return  统计响应结果
      */
     @Valid
-    @RequestMapping(name = "APP运单统计分类", value = "/waybillStatistic", method = RequestMethod.GET)
+    @RequestMapping(name = "APP运单统计分类", value = "/waybillStatistica", method = RequestMethod.GET)
     public HttpResult waybillStatistic(@RequestParam("keyword") String keyword,
                                        @RequestParam("startDate") String startDate,
                                        @RequestParam("endDate") String endDate) {
@@ -41,6 +41,24 @@ public class AppWayBillController {
         }
     }
 
+    /**
+     * APP 运单统计分类 - [运输中|已完成] - mongo查询
+     * @param keyword   查询关键字
+     * @return  统计响应结果
+     */
+    @Valid
+    @RequestMapping(name = "APP运单统计分类", value = "/waybillStatistic", method = RequestMethod.GET)
+    public HttpResult waybillStatisticCount(@RequestParam("keyword") String keyword,
+                                       @RequestParam("startDate") String startDate,
+                                       @RequestParam("endDate") String endDate) {
+        try {
+            return waybillManagementService.waybillStatisticCountApp(keyword, startDate, endDate);
+        } catch (Exception e) {
+            log.error("APP运单统计分类:订单id {},error {} ", keyword, e.getMessage(), e);
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
+        }
+    }
+
     /**
      * APP 运单列表 - [运输中|已完成]
      * @param waybillOrderDTO   运单查询请求dto
@@ -63,7 +81,7 @@ public class AppWayBillController {
      * @return  运单重量响应结果
      */
     @Valid
-    @RequestMapping(name = "APP运单吨量统计", value = "/waybillAmountStatistic", method = RequestMethod.POST)
+    @RequestMapping(name = "APP运单吨量统计", value = "/waybillAmountStatistic2", method = RequestMethod.POST)
     public HttpResult waybillAmountStatistic(@Validated @RequestBody WaybillListAppDTO waybillOrderDTO) {
         try {
             return waybillManagementService.waybillAmountStatistic(waybillOrderDTO);
@@ -73,6 +91,22 @@ public class AppWayBillController {
         }
     }
 
+    /**
+     * APP 运单列表吨量统计 - [运输中|已完成] - mongo
+     * @param waybillOrderDTO   统计运单数据查询
+     * @return  运单重量响应结果
+     */
+    @Valid
+    @RequestMapping(name = "APP运单吨量统计", value = "/waybillAmountStatistic", method = RequestMethod.POST)
+    public HttpResult waybillAmountStatisticCount(@Validated @RequestBody WaybillListAppDTO waybillOrderDTO) {
+        try {
+            return waybillManagementService.waybillAmountStatisticCount(waybillOrderDTO);
+        } catch (Exception e) {
+            log.error("APP运单列表:订单id {},error {} ", waybillOrderDTO, e.getMessage(), e);
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
+        }
+    }
+
     /**
      * APP 物流订单-运单列表
      * @param waybillOrderDTO   物流订单查询

+ 152 - 2
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/WaybillManagementService.java

@@ -24,6 +24,7 @@ import com.sckw.transport.model.dto.*;
 import com.sckw.transport.model.vo.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.poi.hpsf.Decimal;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
@@ -317,9 +318,9 @@ public class WaybillManagementService {
                     if (statusVO.getCode().equals(kwtWaybillOrderTrack.getStatus())) {
                         statusVO.setStatus(true);
                         statusVO.setId(kwtWaybillOrderTrack.getId());
-                        statusVO.setCreateTime(DateUtil.getDateTime(kwtWaybillOrderTrack.getCreateTime()));
+                        statusVO.setCreateTime(DateUtil.getDateTime(kwtWaybillOrderTrack.getCreateTime()).substring(0, 15));
                         statusVO.setOperateTime(kwtWaybillOrderTrack.getOperateTime() == null
-                                ? null : DateUtil.getDateTime(kwtWaybillOrderTrack.getOperateTime()));
+                                ? null : DateUtil.getDateTime(kwtWaybillOrderTrack.getOperateTime()).substring(0, 15));
                         statusVO.setCreateByName(usersMap.get(kwtWaybillOrderTrack.getCreateBy()) == null
                                 ? null : usersMap.get(kwtWaybillOrderTrack.getCreateBy()).getName());
                         break;
@@ -769,6 +770,86 @@ public class WaybillManagementService {
         return HttpResult.ok(_list);
     }
 
+    /**
+     * app 运单分类统计数据 [运输中|已完成] - mongo查询
+     *
+     * @param keyword
+     * @return
+     */
+    public HttpResult waybillStatisticCountApp(String keyword, String startDate, String endDate) {
+        Long entId = LoginUserHolder.getEntId();
+        if (StringUtils.isNotBlank(startDate)) {
+            startDate = StringTimeUtil.fillStart(startDate);
+        }
+        if (StringUtils.isNotBlank(endDate)) {
+            endDate = StringTimeUtil.fillEnd(endDate);
+        }
+
+        Criteria criteria = new Criteria();
+        criteria.and("entId").is(entId);
+        criteria.and("delFlag").is(NumberConstant.ZERO);
+        // 多条件模糊查询
+        List<Criteria> orCriteria = new ArrayList<>();
+        if (StringUtils.isNotBlank(keyword)) {
+            Pattern pattern = Pattern.compile("^.*" + keyword + ".*$", Pattern.CASE_INSENSITIVE);
+            orCriteria.add(Criteria.where("wOrderNo").regex(pattern));
+            orCriteria.add(Criteria.where("truckNo").regex(pattern));
+            orCriteria.add(Criteria.where("driverName").regex(pattern));
+            orCriteria.add(Criteria.where("driverPhone").regex(pattern));
+            orCriteria.add(Criteria.where("firmName").regex(pattern));
+            criteria.orOperator(orCriteria);
+        }
+        // in查询
+        List<Long> onWayStates = getWallBillStatues("onway");
+        List<Long> finishStates = getWallBillStatues("finish");
+        List<Long> statuses = new ArrayList<Long>();
+        statuses.addAll(onWayStates);
+        statuses.addAll(finishStates);
+        if (CollectionUtils.isNotEmpty(statuses)) {
+            criteria.and("status").in(statuses);
+        }
+        // 查询时间段
+        if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate)) {
+            criteria.and("updateTime")
+                    .gte(DateUtil.strDateTimeToDateTime(startDate))
+                    .lte(DateUtil.strDateTimeToDateTime(endDate));
+        }
+        Aggregation aggregation = Aggregation.newAggregation(
+                Aggregation.match(criteria),
+                Aggregation.group("status").count().as("total"),
+                Aggregation.project("total").and("value").previousOperation()
+        );
+        AggregationResults<TableTops> outputTypeCount = mongoTemplate.aggregate(aggregation, SckwWaybillOrder.class, TableTops.class);
+        List<TableTops> results = outputTypeCount.getMappedResults();
+        Map<String, String> _onway = new HashMap<>(Global.NUMERICAL_SIXTEEN);
+        _onway.put("name", "运输中");
+        _onway.put("value", "onway");
+        _onway.put("total", "0");
+
+        Map<String, String> _finish = new HashMap<>(Global.NUMERICAL_SIXTEEN);
+        _finish.put("name", "已完成");
+        _finish.put("value", "finish");
+        _finish.put("total", "0");
+        long wayCount = 0L;
+        long finishCount = 0L;
+        if (CollectionUtils.isNotEmpty(results)) {
+            for (TableTops tableTops:results) {
+                if (onWayStates.contains(Long.parseLong(tableTops.getValue()))){
+                    wayCount += tableTops.getTotal().longValue();
+                }
+                if (finishStates.contains(Long.parseLong(tableTops.getValue()))){
+                    finishCount += tableTops.getTotal().longValue();
+                }
+            }
+        }
+        _onway.put("total", String.valueOf(wayCount));
+        _finish.put("total", String.valueOf(finishCount));
+        List<Map<String, String>> _list = new ArrayList<>();
+        _list.add(_onway);
+        _list.add(_finish);
+        return HttpResult.ok(_list);
+    }
+
     /**
      * app 运单列表 [运输中|已完成]
      *
@@ -929,6 +1010,75 @@ public class WaybillManagementService {
         return HttpResult.ok(amount);
     }
 
+    /**
+     * app 运单分类吨量统计数据 [运输中|已完成] - mongo
+     *
+     * @param query
+     * @return
+     */
+    public HttpResult waybillAmountStatisticCount(WaybillListAppDTO query) {
+        Long entId = LoginUserHolder.getEntId();
+        Criteria criteria = new Criteria();
+        criteria.and("entId").is(entId);
+        criteria.and("delFlag").is(NumberConstant.ZERO);
+        // 多条件模糊查询
+        List<Criteria> orCriteria = new ArrayList<>();
+        if (StringUtils.isNotBlank(query.getKeyword())) {
+            Pattern pattern = Pattern.compile("^.*" + query.getKeyword() + ".*$", Pattern.CASE_INSENSITIVE);
+            orCriteria.add(Criteria.where("wOrderNo").regex(pattern));
+            orCriteria.add(Criteria.where("truckNo").regex(pattern));
+            orCriteria.add(Criteria.where("driverName").regex(pattern));
+            orCriteria.add(Criteria.where("driverPhone").regex(pattern));
+            orCriteria.add(Criteria.where("firmName").regex(pattern));
+            criteria.orOperator(orCriteria);
+        }
+        // in查询
+        List<Long> finishStates = getWallBillStatues("finish");
+        if (CollectionUtils.isNotEmpty(finishStates)) {
+            criteria.and("status").in(finishStates);
+        }
+        // 查询时间段
+        if (!StringUtils.isEmpty(query.getStartDate()) && !StringUtils.isEmpty(query.getEndDate())) {
+            criteria.and("updateTime")
+                    .gte(DateUtil.strDateTimeToDateTime(StringTimeUtil.fillStart(query.getStartDate())))
+                    .lte(DateUtil.strDateTimeToDateTime(StringTimeUtil.fillStart(query.getEndDate())));
+        }
+        Query queryFormat = new Query(criteria);
+        List<SckwWaybillOrder> list = mongoTemplate.find(queryFormat, SckwWaybillOrder.class);
+        int total = 0;
+        BigDecimal loadAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal unloadAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal lossAmount = new BigDecimal(Global.AMOUNT);
+        BigDecimal deficitRealAmount = new BigDecimal(Global.AMOUNT);
+        if (CollectionUtils.isNotEmpty(list)) {
+            for (SckwWaybillOrder wOrder:list) {
+                total += 1;
+                loadAmount = loadAmount.add(wOrder.getLoadAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getLoadAmount());
+                unloadAmount = unloadAmount.add(wOrder.getUnloadAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getUnloadAmount());
+                lossAmount = lossAmount.add(wOrder.getDeficitAmount() == null ? new BigDecimal(Global.AMOUNT) : wOrder.getDeficitAmount());
+                BigDecimal _deficitRealAmount = commonService.deficitLossAmount(
+                        wOrder.getLoadAmount(),
+                        wOrder.getDeficitAmount(),
+                        wOrder.getLoss(),
+                        wOrder.getLossUnit()
+                );
+                deficitRealAmount.add(_deficitRealAmount);
+            }
+        }
+        Map<String, String> amount = new HashMap<>(Global.NUMERICAL_SIXTEEN);
+        // 总计条数
+        amount.put("total", String.valueOf(total));
+        // 总计装货量
+        amount.put("loadAmount",  String.valueOf(loadAmount));
+        // 总计卸货量
+        amount.put("unloadAmount",  String.valueOf(unloadAmount));
+        // 总计货损量
+        amount.put("lossAmount",  String.valueOf(lossAmount));
+        // 总计扣亏量
+        amount.put("deficitRealAmount",  String.valueOf(deficitRealAmount));
+        return HttpResult.ok(amount);
+    }
+
     /**
      * 获取 [运输中|已完成] 状态列表
      *