Browse Source

Merge remote-tracking branch 'origin/master'

李进 2 years ago
parent
commit
0a568eb352

+ 31 - 16
device-api-service-merc-mini/src/main/java/com/xy/controller/MercMiniDeviceController.java

@@ -116,20 +116,20 @@ public class MercMiniDeviceController {
         dto.setMercId(MercAuthUtils.getMercId());
         return deviceInfoService.dataCount(dto);
     }
-
-    @PostMapping("active")
-    @ApiOperation("激活设备")
-    public R active(@RequestBody MercMiniDeviceDto.Active active) {
-        DeviceInfo deviceInfo = deviceInfoService.getById(active.getDeviceId());
-        if (deviceInfo.getActiveState().equals(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))) {
-            return R.fail("机器已激活");
-        }
+    @PostMapping("getActiveInfo")
+    @ApiOperation("激活设备前判断")
+    public R getActiveInfo(@RequestBody MercMiniDeviceDto.Active active){
         Long mercId = MercAuthUtils.getMercId();
         //商户是否已通过审核
         MercDto.Vo mercInfo = mercFeignService.obj(new MercDto.ListDTO().setId(mercId)).getData();
         if (!mercInfo.getStatus().equals(String.valueOf(MercStatus.APPROVED.getCode()))) {
             return R.fail("商户未通过审核");
         }
+        DeviceInfo deviceInfo = deviceInfoService.getById(active.getDeviceId());
+        //设备是否存在
+        if(!Emptys.check(deviceInfo)){
+            return R.fail("机器不存在");
+        }
         //机器是否已授权给该商户
         if (!deviceInfo.getMercId().equals(mercId)) {
             return R.fail("机器未授权给商户");
@@ -138,17 +138,32 @@ public class MercMiniDeviceController {
         if (deviceInfo.getFreezeStatus().equals(Integer.valueOf(DictSonEnum.DEVICE_FREEZE_STATUS_2.getKey()))) {
             return R.fail("机器已冻结");
         }
-        //激活设备
-        DeviceInfo updateDeviceInfo = new DeviceInfo()
-                .setDeviceId(active.getDeviceId())
-                .setActiveState(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))
-                .setBusyState(Integer.valueOf(DictSonEnum.DEVICE_BUSY_STATUS_1.getKey()))
-                .setActiveTime(LocalDateTime.now())
-                .setShowStatus(true);
-        deviceInfoService.updateById(updateDeviceInfo);
+        if (deviceInfo.getActiveState().equals(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))) {
+            return R.fail("机器已激活");
+        }
         return R.ok();
     }
 
+    @PostMapping("active")
+    @ApiOperation("激活设备")
+    public R active(@RequestBody MercMiniDeviceDto.Active active) {
+        R activeInfo = this.getActiveInfo(active);
+        if(activeInfo.getCode() == R.Enum.SUCCESS.getCode()){
+            //激活设备
+            DeviceInfo updateDeviceInfo = new DeviceInfo()
+                    .setDeviceId(active.getDeviceId())
+                    .setActiveState(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))
+                    .setBusyState(Integer.valueOf(DictSonEnum.DEVICE_BUSY_STATUS_1.getKey()))
+                    .setActiveTime(LocalDateTime.now())
+                    .setShowStatus(true);
+            deviceInfoService.updateById(updateDeviceInfo);
+            return R.ok();
+        }else{
+            return activeInfo;
+        }
+
+    }
+
     @PostMapping("modifyBusyStage")
     @ApiOperation("运营状态修改")
     public R modifyBusyStage(@RequestBody @Validated MercMiniDeviceDto.BusySate busySate) {

+ 56 - 10
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.StrBuilder;
 import cn.hutool.core.util.BooleanUtil;
@@ -26,7 +27,6 @@ import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceInfoMapper;
 import com.xy.mapper.entity.DeviceInfoQueryPage;
 import com.xy.util.ExcelUtils;
-import com.xy.util.FileUtils;
 import com.xy.utils.*;
 import com.xy.utils.enums.DeviceActiveStateEnum;
 import com.xy.utils.enums.DeviceNetSateType;
@@ -87,9 +87,10 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
 
     private final GoodsService goodsService;
 
+    private final OrderRefundService refundService;
+
     private final String keyPrefix = "device:history:";
 
-    private final FileUtils fileUtils;
 
     @Override
     @ApiOperation("对象查询")
@@ -600,8 +601,10 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             if (CollUtil.isNotEmpty(deviceStatusList)) {
                 datdeviceStatusMap = deviceStatusList.stream().collect(Collectors.toMap(DeviceStatusDto.Vo::getDeviceId, d -> d));
             }
-            List<GoodsDeviceDto.Vo> goodsDeviceList = R.feignCheckData(goodsService.queryGoodsDeviceInfo(new GoodsDto.QueryGoodsDeviceInfo().setDeviceIds(deviceIds)));
-            Map<Long, GoodsDeviceDto.Vo> deviceIdGoodsMap = goodsDeviceList.stream().collect(Collectors.toMap(GoodsDeviceDto.Vo::getDeviceId, d -> d));
+            List<GoodsDeviceDto.Vo> goodsDeviceList = R.feignCheckData(goodsService.queryGoodsDeviceInfo(new GoodsDto.QueryGoodsDeviceInfo().setMercId(mercId).setDeviceIds(deviceIds)));
+            Map<Long, List<GoodsDeviceDto.Vo>> deviceIdGoodsMap = goodsDeviceList.stream()
+                    .collect(Collectors.groupingBy(GoodsDeviceDto.Vo::getDeviceId));
+
             for (DeviceInfoDto.MercHomeDeviceVo device : deviceInfos) {
                 Long dId = device.getDeviceId();
                 //设备类型 反显
@@ -616,9 +619,14 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 device.setDayOrderNum(deviceData != null ? deviceData.getSalesCount() : zero);
                 device.setDaySalesPrice(deviceData != null ? deviceData.getSalesMoney() : zero);
                 DeviceStatusDto.Vo deviceStatus = datdeviceStatusMap.get(device.getDeviceId());
-                GoodsDeviceDto.Vo goodsDevice = deviceIdGoodsMap.get(dId);
-                device.setOnSaleNum(goodsDevice == null ? zero : goodsDevice.getStock());
-                device.setFillNum(goodsDevice == null ? zero : goodsDevice.getFillCount());
+                if (CollUtil.isNotEmpty(deviceIdGoodsMap)) {
+                    List<GoodsDeviceDto.Vo> goodsDevice = deviceIdGoodsMap.get(dId);
+                    if (CollUtil.isNotEmpty(goodsDevice)) {
+                        device.setOnSaleNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum());
+                        device.setFillNum(goodsDevice.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum());
+                    }
+                }
+
                 //联网状态
                 Integer netState = deviceStatus == null ? DeviceNetSateType.DISCONNECT.getCode() : deviceStatus.getNetState();
                 device.setNetState(netState);
@@ -765,8 +773,39 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         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);
+        }
+
+
         //当月
         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);
+            }
+
+        }
         vo.setDayBusinessData(copy(DeviceInfoDto.BusinessData.class, dayData));
         vo.setMonthBusinessData(copy(DeviceInfoDto.BusinessData.class, monthData));
         return vo;
@@ -977,8 +1016,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
     private DeviceInfoDto.DeviceDataCountVO dataCount5(DeviceInfoDto.DeviceDataCountDTO dto) {
         Long deviceId = dto.getDeviceId();
         DeviceInfoDto.DeviceDataCountVO vo = new DeviceInfoDto.DeviceDataCountVO();
-        DeviceStatus deviceStatus = deviceStatusService.getById(dto.getDeviceId());
-        DeviceInfoDto.GoodsData goodsData = copy(DeviceInfoDto.GoodsData.class, deviceStatus);
+        DeviceInfoDto.GoodsData goodsData = new DeviceInfoDto.GoodsData();
         //在售商品种类
         //根据设备ID查商品id
         GoodsDeviceDto.SelectList selectList = new GoodsDeviceDto.SelectList();
@@ -986,7 +1024,15 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         selectList.setMercId(dto.getMercId());
         R<List<GoodsDeviceDto.Vo>> r = R.feignCheck(goodsDeviceService.list(selectList));
         List<GoodsDeviceDto.Vo> goodsDeviceList = r.getData();
-        goodsData.setCategoryNum(CollUtil.isNotEmpty(goodsDeviceList) ? goodsDeviceList.size() : 0);
+        Integer stock = 0;
+        Integer afterFillStock = 0;
+        if (CollUtil.isNotEmpty(goodsDeviceList)) {
+            stock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getStock).sum();
+            afterFillStock = goodsDeviceList.stream().mapToInt(GoodsDeviceDto.Vo::getFillCount).sum();
+        }
+        goodsData.setAfterFillStock(afterFillStock);
+        goodsData.setStock(stock);
+        goodsData.setCategoryNum(CollUtil.isNotEmpty(goodsDeviceList) ? goodsDeviceList.size() : new Integer(0));
         vo.setGoodsData(goodsData);
         return vo;
     }

+ 0 - 0
device-api-service-merc-mini/src/main/java/com/xy/dto/MercMiniDeviceDto.java → device-api/src/main/java/com/xy/dto/MercMiniDeviceDto.java