Browse Source

设备列表销售统计

谭斌 1 năm trước cách đây
mục cha
commit
5cff236f66

+ 48 - 41
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -80,6 +80,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
 
     private final CloudWalkApiService cloudWalkApiService;
     private final AlgorithmService algorithmService;
+    private final CountApiService countApiService;
     /**
      * 质检商户code
      */
@@ -771,6 +772,9 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         deviceInfoList.stream().filter(s -> s.getPlaceLineId() == null).forEach(s -> s.setPlaceLineId(-1L));
         //根据线路id分组
         Map<Long, List<DeviceInfo>> deviceMap = deviceInfoList.stream().collect(Collectors.groupingBy(DeviceInfo::getPlaceLineId));
+        DateTime date = DateTime.now();
+        DateTime start = DateUtil.beginOfDay(date);
+        DateTime end = DateUtil.endOfDay(date);
         for (DeviceInfoDto.MercHomeCountVO v : list) {
             DeviceInfoDto.MercHomeListVO vo = new DeviceInfoDto.MercHomeListVO();
             Long placeLineId = v.getPlaceLineId();
@@ -781,20 +785,10 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             if (CollUtil.isEmpty(deviceInfos)) {
                 continue;
             }
+
             //设备销售统计
-            String todayDate = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
             List<Long> deviceIds = deviceInfos.stream().map(DeviceInfoDto.MercHomeDeviceVo::getDeviceId).collect(Collectors.toList());
 
-            //统计条件:当天
-            DeviceDataDto.ListDTO deviceDataListDTO = new DeviceDataDto.ListDTO()
-                    .setDeviceIds(deviceIds).setType(EnumDeviceDataType.DAY.getCode()).setDateValue(Integer.valueOf(todayDate)).setMercId(mercId);
-
-            List<DeviceDataDto.Vo> deviceDataList = deviceDataService.list(deviceDataListDTO);
-            Map<Long, DeviceDataDto.Vo> dataMap = new HashMap<>();
-            if (CollUtil.isNotEmpty(deviceDataList)) {
-                dataMap = deviceDataList.stream().collect(Collectors.toMap(DeviceDataDto.Vo::getDeviceId, d -> d));
-
-            }
 
             //设备状态查询
             List<DeviceStatusDto.Vo> deviceStatusList = deviceStatusService.list(new DeviceStatusDto.SelectList().setDeviceIds(deviceIds)).getData();
@@ -816,11 +810,18 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 //运营状态 反显
                 SysDictRedis dictBusyState = SysDictUtils.get(DictConsts.DEVICE_BUSY_STATUS, String.valueOf(device.getBusyState()));
                 device.setBusyStateName(dictBusyState.getMsg());
-                DeviceDataDto.Vo deviceData = dataMap.get(dId);
+
                 Integer zero = new Integer(0);
+
+                CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
+                        .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(CollUtil.newArrayList(dId));
+
+                //完成订单
+                CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
+
                 //今日销售、库存情况 反显
-                device.setDayOrderNum(deviceData != null ? deviceData.getSalesCount() : zero);
-                device.setDaySalesPrice(deviceData != null ? deviceData.getSalesMoney() : zero);
+                device.setDayOrderNum(successVo != null ? successVo.getOrdersSize() : zero);
+                device.setDaySalesPrice(successVo != null ? successVo.getOrderTotalMoney() : zero);
                 DeviceStatusDto.Vo deviceStatus = datdeviceStatusMap.get(device.getDeviceId());
                 if (CollUtil.isNotEmpty(deviceIdGoodsMap)) {
                     List<GoodsDeviceDto.Vo> goodsDevice = deviceIdGoodsMap.get(dId);
@@ -829,6 +830,8 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                         device.setFillNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum());
                     }
                 }
+
+
                 //算法類型
                 Long algorithmId = device.getAlgorithmId();
                 if (algorithmId != null) {
@@ -1010,39 +1013,43 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         Long mercId = dto.getMercId();
         DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
         //当天
-        DeviceDataDto.Vo dayData = deviceDataService.getByDay(deviceId, mercId, DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN));
-        if (dayData != null) {
-            //今日退款成功订单金额
-            OrderRefundDto.CountByDateVO countByDateVO = R.feignCheckData(
-                    refundService.countByDate(new OrderRefundDto.CountByDateDTO()
-                            .setDate(DateTime.now())
-                            .setMercId(mercId).setDeviceId(deviceId)));
-            Integer hisRefundMoney = countByDateVO.getHisRefundMoney();
-            Integer todayRefundMoney = countByDateVO.getTodayRefundMoney();
-            //今日销售额 (扣除今日的订单的退款金额)
-            if (dayData.getSalesMoney() == null) {
-                dayData.setSalesMoney(0);
-            } else {
-                dayData.setSalesMoney(dayData.getSalesMoney() - todayRefundMoney);
-            }
 
-            dayData.setRefundMoney(hisRefundMoney + todayRefundMoney);
+
+        DateTime date = DateTime.now();
+        DateTime start = DateUtil.beginOfDay(date);
+        DateTime end = DateUtil.endOfDay(date);
+        List<Long> deviceIds = CollUtil.newArrayList(deviceId);
+        CountDto.OrderByCreateTimeAndMercId orderByCreateTimeAndMercId = new CountDto.OrderByCreateTimeAndMercId()
+                .setMerdId(mercId).setBeginTime(start).setEndTime(end).setDeviceIds(deviceIds);
+
+        //完成订单
+        CountDto.SuccessVo successVo = R.feignCheckData(countApiService.orderBySuccess(orderByCreateTimeAndMercId));
+
+        DeviceDataDto.Vo dayData = new DeviceDataDto.Vo();
+        if (successVo != null) {
+            dayData.setSalesMoney(successVo.getOrderTotalMoney());
+            dayData.setRefundMoney(successVo.getRefundMoney());
+            dayData.setSalesCount(successVo.getOrdersSize());
         }
 
 
         //当月
-        DeviceDataDto.Vo monthData = deviceDataService.getByMonth(deviceId, mercId, DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN));
-        if (monthData != null) {
-            OrderRefundDto.CountByMonthVO countByMonthVO = R.feignCheckData(refundService.countByMonth(new OrderRefundDto.CountByMonthDTO().setCurMonthDate(DateTime.now()).setMercId(mercId).setDeviceId(deviceId)));
-            Integer hisMonthRefundMoney = countByMonthVO.getHisMonthRefundMoney();
-            Integer monthRefundMoney = countByMonthVO.getMonthRefundMoney();
-            monthData.setRefundMoney(hisMonthRefundMoney + monthRefundMoney);
-            if (monthData.getSalesMoney() == null) {
-                monthData.setSalesMoney(0);
-            } else {
-                monthData.setSalesMoney(monthData.getSalesMoney() - monthRefundMoney);
-            }
+        DeviceDataDto.Vo monthData = new DeviceDataDto.Vo();
+
+        //月度统计
+        DateTime startM = DateUtil.beginOfMonth(date);
+        DateTime endM = DateUtil.endOfMonth(date);
 
+        CountDto.OrderByCreateTimeAndMercId monthOrder = new CountDto.OrderByCreateTimeAndMercId()
+                .setMerdId(mercId).setBeginTime(startM).setEndTime(endM).setDeviceIds(deviceIds);
+        //完成订单
+        CountDto.SuccessVo successVoM = R.feignCheckData(countApiService.orderBySuccess(monthOrder));
+
+
+        if (monthData != null) {
+            monthData.setRefundMoney(successVoM.getRefundMoney());
+            monthData.setSalesMoney(successVoM.getOrderTotalMoney());
+            monthData.setSalesCount(successVoM.getOrdersSize());
         }
         vo.setDayBusinessData(copy(DeviceInfoDto.BusinessData.class, dayData));
         vo.setMonthBusinessData(copy(DeviceInfoDto.BusinessData.class, monthData));