소스 검색

Merge branch 'master' into test

李进 1 년 전
부모
커밋
6db855a65c

+ 67 - 22
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -17,7 +17,10 @@ import com.xy.device.EnumDeviceAlgorithmChargingType;
 import com.xy.device.EnumDeviceType;
 import com.xy.dto.*;
 import com.xy.dto.be.MercDto;
-import com.xy.entity.*;
+import com.xy.entity.DeviceAlgorithmCharging;
+import com.xy.entity.DeviceAlgorithmChargingHistory;
+import com.xy.entity.DeviceInfo;
+import com.xy.entity.SysDictRedis;
 import com.xy.mapper.DeviceAlgorithmChargingMapper;
 import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
 import com.xy.service.be.MercService;
@@ -32,7 +35,6 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
-import javax.validation.constraints.NotEmpty;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -65,42 +67,85 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private AlipayDeviceService alipayDeviceService;
 
+    private MercDeviceAlgorithmChargingService mercDeviceAlgorithmChargingService;
+
     @PostMapping("count")
     @ApiOperation("查询条数")
     public R<List<DeviceAlgorithmChargingDto.CountVo>> count(@RequestBody @Validated DeviceAlgorithmChargingDto.Count count) {
+        MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(count.getMercId())).getData();
         //默认值
-        List<Long> deviceIds = count.getDeviceIds();
+        JList<Long> deviceIds = new JArrayList<>(count.getDeviceIds());
         JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
         deviceIds.forEach(deviceId -> {
             DeviceAlgorithmChargingDto.CountVo countVo = new DeviceAlgorithmChargingDto.CountVo()
                     .setDeviceId(deviceId)
-                    .setCount(0)
-                    .setSize(0)
+                    .setUnusedCount(0)
+                    .setUnusedSize(0)
+                    .setMakeSize(0)
                     .setArrearageBalance(0);
             countVos.add(countVo);
         });
         JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = countVos.toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
-        //查询数据
+        //查询全部
+        JList<JList<Long>> partition = deviceIds.partition(100);
+        JList<DeviceAlgorithmCharging> deviceAlgorithmChargings = new JArrayList<>();
+        partition.forEach(longs -> {
+            List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                    .select(DeviceAlgorithmCharging::getDeviceId, DeviceAlgorithmCharging::getMakeSize, DeviceAlgorithmCharging::getUnusedSize, DeviceAlgorithmCharging::getTimeout, DeviceAlgorithmCharging::getBeginTime)
+                    .in(DeviceAlgorithmCharging::getDeviceId, longs)
+                    .eq(DeviceAlgorithmCharging::getMercCode, merc.getMercCode())
+            );
+            deviceAlgorithmChargings.addAll(list);
+        });
+        JMap<Long, List<DeviceAlgorithmCharging>> allGroup = deviceAlgorithmChargings.toMap(DeviceAlgorithmCharging::getDeviceId).group();
+        //查询未使用
         String thisTime = DataTime.getSring("yyyyMMdd");
-        List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
-                .in(DeviceAlgorithmCharging::getDeviceId, deviceIds)
+        JList<DeviceAlgorithmCharging> unuseds = deviceAlgorithmChargings.filter()
                 .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
-                .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
-                        .eq(DeviceAlgorithmCharging::getTimeout, -1)
-                        .or()
-                        .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
-                )
+                .eq(DeviceAlgorithmCharging::getTimeout, -1)
                 .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
-        );
-        JMap<Long, List<DeviceAlgorithmCharging>> group = new JArrayList<>(list).toMap(DeviceAlgorithmCharging::getDeviceId).group();
-        group.forEach((deviceId, deviceAlgorithmChargings) -> {
-            DeviceAlgorithmChargingDto.CountVo countVo = cover.get(deviceId);
-            countVo.setCount(deviceAlgorithmChargings.size());
-            int size = 0;
-            for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
-                size += deviceAlgorithmCharging.getUnusedSize();
+                .list();
+        JList<DeviceAlgorithmCharging> unuseds2 = deviceAlgorithmChargings.filter()
+                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
+                .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
+                .list();
+        if (Emptys.check(unuseds2)) {
+            unuseds.addAll(unuseds2);
+        }
+        JMap<Long, List<DeviceAlgorithmCharging>> unusedGroup = unuseds.toMap(DeviceAlgorithmCharging::getDeviceId).group();
+        //统计设备欠费金额
+        List<MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVos = mercDeviceAlgorithmChargingService.countArrearageBalance(new MercDeviceAlgorithmChargingDto.CountArrearageBalance()
+                .setDeviceIds(deviceIds)
+                .setMercId(merc.getId())
+        ).getData();
+        JMap<Long, MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVosJMaps = new JArrayList<>(countArrearageBalanceVos).toMap(MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo::getDeviceId).cover();
+        //封装数据
+        cover.forEach((deviceId, countVo) -> {
+            //未使用
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings1 = unusedGroup.get(deviceId);
+            if (Emptys.check(deviceAlgorithmChargings1)) {
+                countVo.setUnusedCount(deviceAlgorithmChargings1.size());
+                int unusedSize = 0;
+                for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings1) {
+                    unusedSize += deviceAlgorithmCharging.getUnusedSize();
+                }
+                countVo.setUnusedSize(unusedSize);
+            }
+            //已使用
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings2 = allGroup.get(deviceId);
+            if (Emptys.check(deviceAlgorithmChargings2)) {
+                int makeSize = 0;
+                for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings2) {
+                    makeSize += deviceAlgorithmCharging.getMakeSize();
+                }
+                countVo.setMakeSize(makeSize);
+            }
+            //欠费金额
+            MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo countArrearageBalanceVo = countArrearageBalanceVosJMaps.get(deviceId);
+            if (Emptys.check(countArrearageBalanceVo)) {
+                countVo.setArrearageBalance(countArrearageBalanceVo.getArrearageBalance());
             }
-            countVo.setSize(size);
         });
         return R.ok(countVos);
     }

+ 8 - 6
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -108,12 +108,12 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
 
     @ApiOperation("点位设备数量查询")
     @Override
-    public R<List<DeviceInfoDto.PlaceDeviceNumVo>> placeDeviceNum(@RequestBody @Validated DeviceInfoDto.PlaceDeviceNumDto dto){
+    public R<List<DeviceInfoDto.PlaceDeviceNumVo>> placeDeviceNum(@RequestBody @Validated DeviceInfoDto.PlaceDeviceNumDto dto) {
         return R.ok(baseMapper.placeDeviceNum(dto));
     }
 
+    @Override
     @ApiOperation("设备列表带卡包数")
-    @PostMapping("algorithmChargingDevice")
     public R<PageBean<DeviceInfoDto.AlgorithmChargingVo>> algorithmChargingDevice(@RequestBody @Validated DeviceInfoDto.AlgorithmCharging algorithmCharging) {
         PageBean pageBean = algorithmCharging.getPage();
         //查询设备
@@ -121,6 +121,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         LambdaUpdateWrapper<DeviceInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<DeviceInfo>()
                 .eq(DeviceInfo::getMercId, algorithmCharging.getMercId())
                 .eq(DeviceInfo::getActiveState, value)
+                .in(Emptys.check(algorithmCharging.getDeviceIds()), DeviceInfo::getDeviceId, algorithmCharging.getDeviceIds())
                 .orderByDesc(DeviceInfo::getCreateTime);
         IPage<DeviceInfo> page = page(toIPage(pageBean), lambdaUpdateWrapper);
         PageBean<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVoPageBean = toPageBean(DeviceInfoDto.AlgorithmChargingVo.class, page);
@@ -129,13 +130,14 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             return R.ok(algorithmChargingVoPageBean);
         }
         //查询卡包数量
-        List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count().setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))).getData();
+        List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count()
+                .setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))
+                .setMercId(algorithmCharging.getMercId())
+        ).getData();
         JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = new JArrayList<>(data).toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
         algorithmChargingVos.forEach(algorithmChargingVo -> {
             DeviceAlgorithmChargingDto.CountVo countVo = cover.get(algorithmChargingVo.getDeviceId());
-            algorithmChargingVo.setAlgorithmChargingSize(countVo.getCount())
-                    .setAlgorithmChargingLength(countVo.getSize())
-                    .setArrearageBalance(countVo.getArrearageBalance());
+            Beans.copy(algorithmChargingVo, countVo);
         });
         return R.ok(algorithmChargingVoPageBean);
     }

+ 10 - 4
device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingDto.java

@@ -29,6 +29,9 @@ public class DeviceAlgorithmChargingDto {
         @NotEmpty(message = "设备id不能为空")
         @ApiModelProperty(value = "设备id")
         private List<Long> deviceIds;
+
+        @ApiModelProperty(value = "商户ID")
+        private Long mercId;
     }
 
     @Data
@@ -38,11 +41,14 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "设备id")
         private Long deviceId;
 
-        @ApiModelProperty(value = "卡包个数")
-        private Integer count;
+        @ApiModelProperty(value = "剩余个数")
+        private Integer unusedCount;
 
-        @ApiModelProperty(value = "卡包条数")
-        private Integer size;
+        @ApiModelProperty(value = "剩余条数")
+        private Integer unusedSize;
+
+        @ApiModelProperty(value = "已用条数")
+        private Integer makeSize;
 
         @ApiModelProperty(value = "欠费金额")
         private Integer arrearageBalance;

+ 10 - 4
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -48,6 +48,9 @@ public class DeviceInfoDto {
 
         @ApiModelProperty(value = "商户ID", hidden = true)
         private Long mercId;
+
+        @ApiModelProperty(value = "设备ID")
+        private List<Long> deviceIds;
     }
 
     @Data
@@ -427,11 +430,14 @@ public class DeviceInfoDto {
     @Accessors(chain = true)
     public static class AlgorithmChargingVo extends Vo {
 
-        @ApiModelProperty(value = "卡包个数")
-        private Integer algorithmChargingSize;
+        @ApiModelProperty(value = "剩余个数")
+        private Integer unusedCount;
+
+        @ApiModelProperty(value = "剩余条数")
+        private Integer unusedSize;
 
-        @ApiModelProperty(value = "卡包条数")
-        private Integer algorithmChargingLength;
+        @ApiModelProperty(value = "已用条数")
+        private Integer makeSize;
 
         @ApiModelProperty(value = "欠费金额")
         private Integer arrearageBalance;

+ 12 - 1
device-api/src/main/java/com/xy/service/DeviceInfoService.java

@@ -24,7 +24,8 @@ import java.util.Map;
 public interface DeviceInfoService {
 
     @PostMapping("netStateCount")
-    R<Map<Long,DeviceInfoDto.NetStateCountVo>> netStateCount(@RequestBody DeviceInfoDto.NetStateCountDto dto);
+    R<Map<Long, DeviceInfoDto.NetStateCountVo>> netStateCount(@RequestBody DeviceInfoDto.NetStateCountDto dto);
+
     /**
      * 查询对象
      *
@@ -98,6 +99,7 @@ public interface DeviceInfoService {
 
     @PostMapping("page")
     R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page);
+
     /**
      * 更新商户点位
      *
@@ -182,4 +184,13 @@ public interface DeviceInfoService {
      */
     @PostMapping("placeDeviceNum")
     R<List<DeviceInfoDto.PlaceDeviceNumVo>> placeDeviceNum(@RequestBody @Validated DeviceInfoDto.PlaceDeviceNumDto dto);
+
+    /**
+     * 设备列表带卡包数
+     *
+     * @param algorithmCharging
+     * @return
+     */
+    @PostMapping("algorithmChargingDevice")
+    R<PageBean<DeviceInfoDto.AlgorithmChargingVo>> algorithmChargingDevice(@RequestBody @Validated DeviceInfoDto.AlgorithmCharging algorithmCharging);
 }