李进 1 anno fa
parent
commit
5ed9fca356

+ 27 - 0
device-api-service-merc-mini/src/main/java/com/xy/controller/DeviceChargingController.java

@@ -0,0 +1,27 @@
+package com.xy.controller;
+
+import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceChargingDto;
+import com.xy.service.DeviceChargingServiceImpl;
+import com.xy.utils.MercAuthUtils;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+@AllArgsConstructor
+@Api(tags = "小程序-设备计费表")
+@RestMappingController("merc-mini/device-charging")
+public class DeviceChargingController {
+
+    private DeviceChargingServiceImpl deviceChargingService;
+
+    @PostMapping("page")
+    @ApiOperation("分页查询")
+    public R<PageBean<DeviceChargingDto.PageVo>> page(@RequestBody DeviceChargingDto.Page page) {
+        return deviceChargingService.page(page.setMercId(MercAuthUtils.getMercId()));
+    }
+}

+ 4 - 1
device-api-service/src/main/java/com/xy/entity/DeviceAlgorithmCharging.java

@@ -42,9 +42,12 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "类型")
     @ApiModelProperty(value = "类型")
     private Integer type;
     private Integer type;
 
 
-    @ApiModelProperty(value = "过期时间;yyyyMM")
+    @ApiModelProperty(value = "过期时间;")
     private Integer timeout;
     private Integer timeout;
 
 
+    @ApiModelProperty(value = "生效时间")
+    private Integer beginTime;
+
     @ApiModelProperty(value = "创建时间")
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
     private LocalDateTime createTime;
 
 

+ 59 - 0
device-api-service/src/main/java/com/xy/job/DeviceAlgorithmChargingJob.java

@@ -0,0 +1,59 @@
+package com.xy.job;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xy.entity.DeviceAlgorithmCharging;
+import com.xy.service.DeviceAlgorithmChargingServiceImpl;
+import com.xy.utils.DataTime;
+import com.xy.utils.Emptys;
+import com.xy.utils.PageBean;
+import com.xy.utils.PlusBeans;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 设备算法计费job
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+public class DeviceAlgorithmChargingJob {
+
+    private DeviceAlgorithmChargingServiceImpl deviceAlgorithmChargingService;
+
+    /**
+     * 扣除设备算法计费过期时间
+     *
+     * @return
+     */
+    @XxlJob("deviceAlgorithmChargingTimeout")
+    public ReturnT<String> deviceAlgorithmChargingTimeout() {
+        deviceAlgorithmCharging(1, 50, Integer.valueOf(DataTime.getSring("yyyyMM")));
+        return ReturnT.SUCCESS;
+    }
+
+    public void deviceAlgorithmCharging(int current, int size, Integer beginTime) {
+        log.info("扣除设备算法计费过期时间开始第{}页", current);
+        LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                .gt(DeviceAlgorithmCharging::getTimeout, 0)
+                .le(DeviceAlgorithmCharging::getBeginTime, beginTime);
+        IPage<DeviceAlgorithmCharging> iPage = deviceAlgorithmChargingService.page(PlusBeans.toIPage(new PageBean().setCurrent(current).setSize(size)), lambdaQueryWrapper);
+        List<DeviceAlgorithmCharging> records = iPage.getRecords();
+        if (!Emptys.check(records)) {
+            return;
+        }
+        records.forEach(deviceAlgorithmCharging -> deviceAlgorithmCharging.setTimeout(deviceAlgorithmCharging.getTimeout() - 1));
+        deviceAlgorithmChargingService.updateBatchById(records);
+        //判断是否继续下一页
+        if (iPage.getPages() <= current) {
+            return;
+        } else {
+            deviceAlgorithmCharging(current + 1, size, beginTime);
+        }
+    }
+}

+ 1 - 1
device-api-service/src/main/java/com/xy/job/DeviceChargingJob.java

@@ -98,7 +98,7 @@ public class DeviceChargingJob {
                 update.setBusyState(2);
                 update.setBusyState(2);
                 deviceCharging.setIsJob(false);
                 deviceCharging.setIsJob(false);
                 updateDeviceChargings.add(deviceCharging);
                 updateDeviceChargings.add(deviceCharging);
-                updateDeviceInfos.add(update);
+                //updateDeviceInfos.add(update);
             }
             }
         });
         });
         //修改设备计费记录
         //修改设备计费记录

+ 65 - 82
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -61,18 +61,13 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         List<DeviceAlgorithmCharging> deviceAlgorithmChargings = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
         List<DeviceAlgorithmCharging> deviceAlgorithmChargings = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                 .eq(DeviceAlgorithmCharging::getDeviceId, deviceInfo.getDeviceId())
                 .eq(DeviceAlgorithmCharging::getDeviceId, deviceInfo.getDeviceId())
                 .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceInfo.getAlgorithmId())
                 .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceInfo.getAlgorithmId())
-                .in(DeviceAlgorithmCharging::getTimeout, Arrays.asList(DataTime.getSring("yyyyMM"), -1))
+                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                .gt(DeviceAlgorithmCharging::getTimeout, 0)
+                .in(DeviceAlgorithmCharging::getBeginTime, Arrays.asList(DataTime.getSring("yyyyMM"), -1))
         );
         );
         if (!Emptys.check(deviceAlgorithmChargings)) {
         if (!Emptys.check(deviceAlgorithmChargings)) {
             throw new CommRuntimeException("设备欠费,请充值");
             throw new CommRuntimeException("设备欠费,请充值");
         }
         }
-        int size = 0;
-        for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
-            size += deviceAlgorithmCharging.getUnusedSize();
-        }
-        if (size == 0) {
-            throw new CommRuntimeException("设备欠费,请充值");
-        }
         return R.ok();
         return R.ok();
     }
     }
 
 
@@ -114,6 +109,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime now = LocalDateTime.now();
+        int yyyyMM = Integer.valueOf(DataTime.getSring("yyyyMM"));
         //获取算法包月字典
         //获取算法包月字典
         Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
         Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
         //获取类型字典
         //获取类型字典
@@ -136,29 +132,30 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Moon moon = algorithmMoonConfig.getMoon();
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Moon moon = algorithmMoonConfig.getMoon();
             Integer chargingSize = deviceAlgorithmChargingHistory.getChargingSize();
             Integer chargingSize = deviceAlgorithmChargingHistory.getChargingSize();
             for (Integer integer = 0; integer < chargingSize; integer++) {
             for (Integer integer = 0; integer < chargingSize; integer++) {
-                //查询过期时间最大的算法计费
+                //查询生效时间最大的算法计费
                 LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                 LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                         .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
                         .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
                         .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
                         .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
                         .eq(DeviceAlgorithmCharging::getType, type)
                         .eq(DeviceAlgorithmCharging::getType, type)
-                        .orderByDesc(DeviceAlgorithmCharging::getTimeout)
+                        .orderByDesc(DeviceAlgorithmCharging::getBeginTime)
                         .last("limit 1");
                         .last("limit 1");
                 DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
                 DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
-                int timeout;
+                int beginTime;
                 if (deviceAlgorithmCharging == null) {
                 if (deviceAlgorithmCharging == null) {
-                    timeout = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
+                    beginTime = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
                 } else {
                 } else {
-                    LocalDateTime localDateTime = DataTime.toLocal(deviceAlgorithmCharging.getTimeout() + "01000000", "yyyyMMddHHmmss");
+                    LocalDateTime localDateTime = DataTime.toLocal(deviceAlgorithmCharging.getBeginTime() + "01000000", "yyyyMMddHHmmss");
                     String s = DataTime.toString(localDateTime, "yyyy-MM-dd HH:mm:ss");
                     String s = DataTime.toString(localDateTime, "yyyy-MM-dd HH:mm:ss");
                     String stringAround = DataTime.getStringAround(0, 1, 0, 0, 0, 0, s);
                     String stringAround = DataTime.getStringAround(0, 1, 0, 0, 0, 0, s);
-                    timeout = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround), "yyyyMM"));
+                    beginTime = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround), "yyyyMM"));
                 }
                 }
                 DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
                 DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setUnusedSize(moon.getSize())
                         .setUnusedSize(moon.getSize())
                         .setType(type)
                         .setType(type)
-                        .setTimeout(timeout)
+                        .setTimeout(30)
+                        .setBeginTime(beginTime)
                         .setCreateTime(now)
                         .setCreateTime(now)
                         .setUpdateTime(now);
                         .setUpdateTime(now);
                 save(deviceAlgorithmChargingInfo);
                 save(deviceAlgorithmChargingInfo);
@@ -166,54 +163,32 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         });
         //处理无期限
         //处理无期限
         infs.forEach(deviceAlgorithmChargingHistory -> {
         infs.forEach(deviceAlgorithmChargingHistory -> {
-            LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
-                    .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
-                    .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
-                    .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType());
-            DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
             SysDictRedis algorithmMoonConfigDict = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
             SysDictRedis algorithmMoonConfigDict = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Inf inf = algorithmMoonConfig.getInf();
             DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Inf inf = algorithmMoonConfig.getInf();
-            if (deviceAlgorithmCharging == null) {
-                DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                        .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
-                        .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
-                        .setUnusedSize(inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize())
-                        .setType(deviceAlgorithmChargingHistory.getType())
-                        .setTimeout(-1)
-                        .setCreateTime(now)
-                        .setUpdateTime(now);
-                save(deviceAlgorithmChargingInfo);
-            } else {
-                deviceAlgorithmCharging.setUnusedSize(deviceAlgorithmCharging.getUnusedSize() + (inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize()))
-                        .setUpdateTime(now);
-                updateById(deviceAlgorithmCharging);
-            }
+            DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
+                    .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
+                    .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
+                    .setUnusedSize(inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize())
+                    .setType(deviceAlgorithmChargingHistory.getType())
+                    .setTimeout(-1)
+                    .setBeginTime(yyyyMM)
+                    .setCreateTime(now)
+                    .setUpdateTime(now);
+            save(deviceAlgorithmChargingInfo);
         });
         });
         //处理赠送
         //处理赠送
         gives.forEach(deviceAlgorithmChargingHistory -> {
         gives.forEach(deviceAlgorithmChargingHistory -> {
-            int timeout = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
-            LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
-                    .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
-                    .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
-                    .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType())
-                    .eq(DeviceAlgorithmCharging::getTimeout, timeout);
-            DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
-            if (deviceAlgorithmCharging == null) {
-                DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                        .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
-                        .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
-                        .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
-                        .setType(deviceAlgorithmChargingHistory.getType())
-                        .setTimeout(timeout)
-                        .setCreateTime(now)
-                        .setUpdateTime(now);
-                save(deviceAlgorithmChargingInfo);
-            } else {
-                deviceAlgorithmCharging.setUnusedSize(deviceAlgorithmCharging.getUnusedSize() + deviceAlgorithmChargingHistory.getChargingSize())
-                        .setUpdateTime(now);
-                updateById(deviceAlgorithmCharging);
-            }
+            DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
+                    .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
+                    .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
+                    .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
+                    .setType(deviceAlgorithmChargingHistory.getType())
+                    .setTimeout(30)
+                    .setBeginTime(yyyyMM)
+                    .setCreateTime(now)
+                    .setUpdateTime(now);
+            save(deviceAlgorithmChargingInfo);
         });
         });
         if (Emptys.check(deviceAlgorithmChargingHistories)) {
         if (Emptys.check(deviceAlgorithmChargingHistories)) {
             Integer status = SysDictUtils.getValue(EnumDeviceAlgorithmChargingHistoryStatus.Code.CODE.getCode(), EnumDeviceAlgorithmChargingHistoryStatus.N_2.getCode(), Integer.class);
             Integer status = SysDictUtils.getValue(EnumDeviceAlgorithmChargingHistoryStatus.Code.CODE.getCode(), EnumDeviceAlgorithmChargingHistoryStatus.N_2.getCode(), Integer.class);
@@ -234,7 +209,14 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
         LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                 .in(DeviceAlgorithmCharging::getDeviceId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getDeviceId))
                 .in(DeviceAlgorithmCharging::getDeviceId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getDeviceId))
                 .in(DeviceAlgorithmCharging::getAlgorithmId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmId))
                 .in(DeviceAlgorithmCharging::getAlgorithmId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmId))
-                .in(DeviceAlgorithmCharging::getTimeout, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate).set(-1));
+                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
+                        .gt(DeviceAlgorithmCharging::getTimeout, 0)
+                        .or()
+                        .eq(DeviceAlgorithmCharging::getTimeout, -1)
+                )
+                .in(DeviceAlgorithmCharging::getBeginTime, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate))
+                .orderByAsc(DeviceAlgorithmCharging::getBeginTime, DeviceAlgorithmCharging::getCreateTime);
         List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = list(lambdaQueryWrapper);
         List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = list(lambdaQueryWrapper);
         if (!Emptys.check(deviceAlgorithmChargingsList)) {
         if (!Emptys.check(deviceAlgorithmChargingsList)) {
             return R.ok(map);
             return R.ok(map);
@@ -253,13 +235,12 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             JList<DeviceAlgorithmCharging> deviceAlgorithmChargingJlist = deviceAlgorithmChargings.filter()
             JList<DeviceAlgorithmCharging> deviceAlgorithmChargingJlist = deviceAlgorithmChargings.filter()
                     .eq(DeviceAlgorithmCharging::getDeviceId, charging.getDeviceId())
                     .eq(DeviceAlgorithmCharging::getDeviceId, charging.getDeviceId())
                     .eq(DeviceAlgorithmCharging::getAlgorithmId, charging.getAlgorithmId())
                     .eq(DeviceAlgorithmCharging::getAlgorithmId, charging.getAlgorithmId())
-                    .in(DeviceAlgorithmCharging::getTimeout, Arrays.asList(charging.getAlgorithmDate(), -1))
                     .list();
                     .list();
             if (!Emptys.check(deviceAlgorithmChargingJlist)) {
             if (!Emptys.check(deviceAlgorithmChargingJlist)) {
                 return;
                 return;
             }
             }
-            JMap<Integer, DeviceAlgorithmCharging> deviceAlgorithmChargingJMap = deviceAlgorithmChargingJlist.toMap(DeviceAlgorithmCharging::getType).cover();
-            //递归扣费
+            JMap<Integer, List<DeviceAlgorithmCharging>> deviceAlgorithmChargingJMap = deviceAlgorithmChargingJlist.toMap(DeviceAlgorithmCharging::getType).group();
+            //递归扣费 扣费顺序为:赠送 -> 有期限 -> 无期限
             int size2 = charging(size, deviceAlgorithmChargingJMap, new JArrayList<SysDictRedis>().set(sysDictRedis3).set(sysDictRedis1).set(sysDictRedis2));
             int size2 = charging(size, deviceAlgorithmChargingJMap, new JArrayList<SysDictRedis>().set(sysDictRedis3).set(sysDictRedis1).set(sysDictRedis2));
             map.put(charging.getMercDeviceAlgorithmChargingId(), size2);
             map.put(charging.getMercDeviceAlgorithmChargingId(), size2);
         });
         });
@@ -271,31 +252,33 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
      *
      *
      * @return 未扣条数
      * @return 未扣条数
      */
      */
-    private int charging(int size, JMap<Integer, DeviceAlgorithmCharging> deviceAlgorithmChargingJMap, List<SysDictRedis> sysDictRediss) {
+    private int charging(int size, JMap<Integer, List<DeviceAlgorithmCharging>> deviceAlgorithmChargingJMap, List<SysDictRedis> sysDictRediss) {
         if (size > 0 && Emptys.check(sysDictRediss)) {
         if (size > 0 && Emptys.check(sysDictRediss)) {
             SysDictRedis sysDictRedis = sysDictRediss.remove(0);
             SysDictRedis sysDictRedis = sysDictRediss.remove(0);
             LocalDateTime now = LocalDateTime.now();
             LocalDateTime now = LocalDateTime.now();
-            DeviceAlgorithmCharging deviceAlgorithmCharging = deviceAlgorithmChargingJMap.get(Integer.valueOf(sysDictRedis.getValue()));
-            if (deviceAlgorithmCharging != null) {
-                int unusedSize = deviceAlgorithmCharging.getUnusedSize();
-                if (unusedSize > 0) {
-                    int newUnusedSize = unusedSize - size;
-                    int makeSize;
-                    //扣除后=负数则算法条数不足
-                    if (newUnusedSize < 0) {
-                        size = (~(newUnusedSize - 1));
-                        newUnusedSize = 0;
-                        makeSize = unusedSize;
-                    } else {
-                        makeSize = size;
-                        size = 0;
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings = deviceAlgorithmChargingJMap.get(Integer.valueOf(sysDictRedis.getValue()));
+            if (Emptys.check(deviceAlgorithmChargings)) {
+                for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
+                    int unusedSize = deviceAlgorithmCharging.getUnusedSize();
+                    if (unusedSize > 0) {
+                        int newUnusedSize = unusedSize - size;
+                        int makeSize;
+                        //扣除后=负数则算法条数不足
+                        if (newUnusedSize < 0) {
+                            size = (~(newUnusedSize - 1));
+                            newUnusedSize = 0;
+                            makeSize = unusedSize;
+                        } else {
+                            makeSize = size;
+                            size = 0;
+                        }
+                        DeviceAlgorithmCharging updateDeviceAlgorithmCharging = new DeviceAlgorithmCharging()
+                                .setId(deviceAlgorithmCharging.getId())
+                                .setUnusedSize(newUnusedSize)
+                                .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
+                                .setUpdateTime(now);
+                        updateById(updateDeviceAlgorithmCharging);
                     }
                     }
-                    DeviceAlgorithmCharging updateDeviceAlgorithmCharging = new DeviceAlgorithmCharging()
-                            .setId(deviceAlgorithmCharging.getId())
-                            .setUnusedSize(newUnusedSize)
-                            .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
-                            .setUpdateTime(now);
-                    updateById(updateDeviceAlgorithmCharging);
                 }
                 }
             }
             }
             if (size > 0 && Emptys.check(sysDictRediss)) {
             if (size > 0 && Emptys.check(sysDictRediss)) {

+ 2 - 1
device-api-service/src/main/java/com/xy/service/DeviceChargingServiceImpl.java

@@ -192,7 +192,8 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
         JList<DeviceInfoDto.Update> updateDeviceInfos = new JArrayList<>();
         JList<DeviceInfoDto.Update> updateDeviceInfos = new JArrayList<>();
         JList<DeviceChargingHistory> updateDeviceChargingHistory = new JArrayList<>();
         JList<DeviceChargingHistory> updateDeviceChargingHistory = new JArrayList<>();
         for (DeviceChargingHistory deviceChargingHistory : deviceChargingHistories) {
         for (DeviceChargingHistory deviceChargingHistory : deviceChargingHistories) {
-            DeviceCharging deviceCharging = deviceChargingsJMaps.get(deviceChargingHistory.getDeviceId());
+            DeviceCharging deviceCharging = deviceChargingsJMaps.get(deviceChargingHistory.getDeviceId())
+                    .setLastChargingTime(now);
             Integer chargingSize = deviceChargingHistory.getChargingSize();
             Integer chargingSize = deviceChargingHistory.getChargingSize();
             boolean fal = false;
             boolean fal = false;
             //设备计费历史完成
             //设备计费历史完成

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

@@ -117,9 +117,12 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "类型")
         @ApiModelProperty(value = "类型")
         private Integer type;
         private Integer type;
 
 
-        @ApiModelProperty(value = "过期时间;yyyyMM")
+        @ApiModelProperty(value = "过期时间;")
         private Integer timeout;
         private Integer timeout;
 
 
+        @ApiModelProperty(value = "生效时间")
+        private Integer beginTime;
+
         @ApiModelProperty(value = "创建时间")
         @ApiModelProperty(value = "创建时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;
         private LocalDateTime createTime;