Ver Fonte

设备算法计费

李进 há 2 anos atrás
pai
commit
314fc94980

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

@@ -39,8 +39,8 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "未用条数")
     private Integer unusedSize;
 
-    @ApiModelProperty(value = "是否赠送")
-    private Boolean isGive;
+    @ApiModelProperty(value = "类型")
+    private Integer type;
 
     @ApiModelProperty(value = "过期时间;yyyyMM")
     private Integer timeout;

+ 3 - 0
device-api-service/src/main/java/com/xy/entity/DeviceAlgorithmChargingHistory.java

@@ -45,6 +45,9 @@ public class DeviceAlgorithmChargingHistory implements Serializable {
     @ApiModelProperty(value = "充值方式")
     private Integer chargingType;
 
+    @ApiModelProperty(value = "类型")
+    private Integer type;
+
     @ApiModelProperty(value = "状态")
     private Integer status;
 

+ 50 - 13
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -6,8 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.yitter.idgen.YitIdHelper;
 import com.xy.collections.list.JArrayList;
 import com.xy.collections.list.JList;
-import com.xy.device.EnumAlgorithmMoonConfig;
+import com.xy.device.EnumAlgorithmPayConfig;
 import com.xy.device.EnumDeviceAlgorithmChargingHistoryStatus;
+import com.xy.device.EnumDeviceAlgorithmChargingType;
 import com.xy.dto.DeviceAlgorithmChargingDto;
 import com.xy.entity.DeviceAlgorithmCharging;
 import com.xy.entity.DeviceAlgorithmChargingHistory;
@@ -57,6 +58,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                     .setAlgorithmId(deviceAlgorithmCharging.getAlgorithmId())
                     .setChargingSize(deviceAlgorithmCharging.getChargingSize())
                     .setChargingMoney(deviceAlgorithmCharging.getMoney())
+                    .setType(deviceAlgorithmCharging.getType())
                     .setChargingType(pay.getPayType())
                     .setCreateTime(now)
                     .setUpdateTime(now);
@@ -76,28 +78,37 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         if (!Emptys.check(list)) {
             return R.ok();
         }
-        int give = 100;
         JList<DeviceAlgorithmChargingHistory> deviceAlgorithmChargingHistories = new JArrayList<>(list);
+        JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
         LocalDateTime now = LocalDateTime.now();
         //获取算法包月字典
-        Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmMoonConfig.Code.CODE.getCode());
-        //处理购买
+        Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
+        //获取类型字典
+        Map<String, SysDictRedis> deviceAlgorithmChargingTypeMaps = SysDictUtils.get(EnumDeviceAlgorithmChargingType.Code.CODE.getCode());
+        //处理有效期
         deviceAlgorithmChargingHistories.forEach(deviceAlgorithmChargingHistory -> {
-            Integer chargingType = deviceAlgorithmChargingHistory.getChargingType();
-            if (chargingType == give) {
+            Integer type = deviceAlgorithmChargingHistory.getType();
+            SysDictRedis deviceAlgorithmChargingType2 = deviceAlgorithmChargingTypeMaps.get(EnumDeviceAlgorithmChargingType.N_2.getCode());
+            if (type.equals(Integer.valueOf(deviceAlgorithmChargingType2.getValue()))) {
+                infs.add(deviceAlgorithmChargingHistory);
+                return;
+            }
+            SysDictRedis deviceAlgorithmChargingType3 = deviceAlgorithmChargingTypeMaps.get(EnumDeviceAlgorithmChargingType.N_3.getCode());
+            if (type.equals(Integer.valueOf(deviceAlgorithmChargingType3.getValue()))) {
                 gives.add(deviceAlgorithmChargingHistory);
                 return;
             }
-            SysDictRedis sysDictRedis = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
-            DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(sysDictRedis.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
+            SysDictRedis algorithmMoonConfigDict = algorithmMoonConfigMaps.get(deviceAlgorithmChargingHistory.getAlgorithmId().toString());
+            DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
+            DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Moon moon = algorithmMoonConfig.getMoon();
             Integer chargingSize = deviceAlgorithmChargingHistory.getChargingSize();
             for (Integer integer = 0; integer < chargingSize; integer++) {
                 //查询过期时间最大的算法计费
                 LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                         .eq(DeviceAlgorithmCharging::getDeviceId, deviceAlgorithmChargingHistory.getDeviceId())
                         .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceAlgorithmChargingHistory.getAlgorithmId())
-                        .eq(DeviceAlgorithmCharging::getIsGive, false)
+                        .eq(DeviceAlgorithmCharging::getType, type)
                         .orderByDesc(DeviceAlgorithmCharging::getTimeout)
                         .last("limit 1");
                 DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
@@ -113,21 +124,47 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                 DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
-                        .setUnusedSize(algorithmMoonConfig.getSize())
-                        .setIsGive(false)
+                        .setUnusedSize(moon.getSize())
+                        .setType(type)
                         .setTimeout(timeout)
                         .setCreateTime(now)
                         .setUpdateTime(now);
                 save(deviceAlgorithmChargingInfo);
             }
         });
+        //处理无期限
+        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());
+            DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmMoonConfigDict.getValue()).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
+            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);
+            }
+        });
         //处理赠送
         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::getIsGive, true)
+                    .eq(DeviceAlgorithmCharging::getType, deviceAlgorithmChargingHistory.getType())
                     .eq(DeviceAlgorithmCharging::getTimeout, timeout);
             DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
             if (deviceAlgorithmCharging == null) {
@@ -135,7 +172,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
-                        .setIsGive(true)
+                        .setType(deviceAlgorithmChargingHistory.getType())
                         .setTimeout(timeout)
                         .setCreateTime(now)
                         .setUpdateTime(now);

+ 28 - 5
device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingDto.java

@@ -47,6 +47,9 @@ public class DeviceAlgorithmChargingDto {
             @ApiModelProperty("算法id")
             private Long algorithmId;
 
+            @ApiModelProperty("类型")
+            private Integer type;
+
             @ApiModelProperty("充值数量")
             private Integer chargingSize;
 
@@ -83,8 +86,8 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "未用条数")
         private Integer unusedSize;
 
-        @ApiModelProperty(value = "是否赠送")
-        private Boolean isGive;
+        @ApiModelProperty(value = "类型")
+        private Integer type;
 
         @ApiModelProperty(value = "过期时间;yyyyMM")
         private Integer timeout;
@@ -103,11 +106,31 @@ public class DeviceAlgorithmChargingDto {
     @Accessors(chain = true)
     public static class AlgorithmMoonConfig {
 
-        private Long id;
+        private Moon moon;
+
+        private Inf inf;
 
-        private Integer money;
+        @Data
+        @Accessors(chain = true)
+        public static class Moon {
 
-        private Integer size;
+            private Long id;
+
+            private Integer money;
+
+            private Integer size;
+        }
+
+        @Data
+        @Accessors(chain = true)
+        public static class Inf {
+
+            private Long id;
+
+            private Integer money;
+
+            private Integer size;
+        }
 
     }
 }