Browse Source

设备管理费改版

李进 1 năm trước cách đây
mục cha
commit
f4e2111204

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

@@ -27,8 +27,8 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "id")
     private Long id;
 
-    @ApiModelProperty(value = "商户id")
-    private Long mercId;
+    @ApiModelProperty(value = "商户编码")
+    private String mercCode;
 
     @ApiModelProperty(value = "设备id")
     private Long deviceId;

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

@@ -50,7 +50,4 @@ public class DeviceCharging implements Serializable {
 
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
-
-    @ApiModelProperty(value = "是否需要定时计费")
-    private Boolean isJob;
 }

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

@@ -2,6 +2,7 @@ package com.xy.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xy.entity.DeviceAlgorithmCharging;
+import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
 
 import java.util.List;
 
@@ -21,5 +22,5 @@ public interface DeviceAlgorithmChargingMapper extends BaseMapper<DeviceAlgorith
      * @param list
      * @return
      */
-    List<DeviceAlgorithmCharging> chargingQuery(List<DeviceAlgorithmCharging> list);
+    List<DeviceAlgorithmCharging> chargingQuery(List<DeviceAlgorithmChargingChargingQueryParams> list);
 }

+ 17 - 0
device-api-service/src/main/java/com/xy/mapper/entity/DeviceAlgorithmChargingChargingQueryParams.java

@@ -0,0 +1,17 @@
+package com.xy.mapper.entity;
+
+import com.xy.entity.DeviceAlgorithmCharging;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+@Data
+@Accessors(chain = true)
+public class DeviceAlgorithmChargingChargingQueryParams extends DeviceAlgorithmCharging {
+
+    @ApiModelProperty("商户编码")
+    private List<String> mercCodes;
+
+}

+ 42 - 8
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -14,10 +14,13 @@ import com.xy.device.EnumDeviceAlgorithmChargingHistoryStatus;
 import com.xy.device.EnumDeviceAlgorithmChargingType;
 import com.xy.dto.DeviceAlgorithmChargingDto;
 import com.xy.dto.DeviceInfoDto;
+import com.xy.dto.be.MercDto;
 import com.xy.entity.DeviceAlgorithmCharging;
 import com.xy.entity.DeviceAlgorithmChargingHistory;
 import com.xy.entity.SysDictRedis;
 import com.xy.mapper.DeviceAlgorithmChargingMapper;
+import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
+import com.xy.service.be.MercService;
 import com.xy.utils.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -52,6 +55,8 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private DeviceInfoService deviceInfoService;
 
+    private MercService mercService;
+
     @PostMapping("page")
     @ApiOperation("分页查询")
     public R<PageBean<DeviceAlgorithmChargingDto.Vo>> page(@RequestBody @Validated DeviceAlgorithmChargingDto.Page page) {
@@ -130,6 +135,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
         //获取类型字典
         Map<String, SysDictRedis> deviceAlgorithmChargingTypeMaps = SysDictUtils.get(EnumDeviceAlgorithmChargingType.Code.CODE.getCode());
+        //查询商户信息
+        List<MercDto.Vo> mercs = mercService.list(new MercDto.SelectList().setMercIds(deviceAlgorithmChargingHistories.getProperty(DeviceAlgorithmChargingHistory::getMercId))).getData();
+        JMap<Long, MercDto.Vo> mercsMaps = new JArrayList<>(mercs).toMap(MercDto.Vo::getId).cover();
         //处理有效期
         deviceAlgorithmChargingHistories.forEach(deviceAlgorithmChargingHistory -> {
             Integer type = deviceAlgorithmChargingHistory.getType();
@@ -170,8 +178,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                     String stringAround1 = DataTime.getStringAround(0, 1, 0, 0, 0, 0, stringAround);
                     timeout = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround1), "yyyyMMdd"));
                 }
+                MercDto.Vo merc = mercsMaps.get(deviceAlgorithmChargingHistory.getMercId());
                 DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                        .setMercId(deviceAlgorithmChargingHistory.getMercId())
+                        .setMercCode(merc.getMercCode())
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setUnusedSize(moon.getSize())
@@ -186,8 +195,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         //处理无期限
         infs.forEach(deviceAlgorithmChargingHistory -> {
+            MercDto.Vo merc = mercsMaps.get(deviceAlgorithmChargingHistory.getMercId());
             DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                    .setMercId(deviceAlgorithmChargingHistory.getMercId())
+                    .setMercCode(merc.getMercCode())
                     .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
@@ -201,8 +211,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         //处理赠送
         gives.forEach(deviceAlgorithmChargingHistory -> {
+            MercDto.Vo merc = mercsMaps.get(deviceAlgorithmChargingHistory.getMercId());
             DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                    .setMercId(deviceAlgorithmChargingHistory.getMercId())
+                    .setMercCode(merc.getMercCode())
                     .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
@@ -225,16 +236,24 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
     @Override
     @ApiOperation("扣费")
     public R<Map<Long, Integer>> charging(List<DeviceAlgorithmChargingDto.Charging> chargings) {
+        //查询商户信息
+        List<MercDto.Vo> mercs = mercService.list(new MercDto.SelectList().setMercIds(new JArrayList<>(chargings).getProperty(DeviceAlgorithmChargingDto.Charging::getMercId))).getData();
+        JMap<Long, MercDto.Vo> mercsMaps = new JArrayList<>(mercs).toMap(MercDto.Vo::getId).cover();
         //封装默认返回值
         Map<Long, Integer> map = new JHashMap<>(chargings.size());
         chargings.forEach(charging -> map.put(charging.getMercDeviceAlgorithmChargingId(), charging.getSize()));
         //查询数据
-        List<DeviceAlgorithmCharging> queryList = new ArrayList<>(chargings.size());
+        List<DeviceAlgorithmChargingChargingQueryParams> queryList = new ArrayList<>(chargings.size());
         for (DeviceAlgorithmChargingDto.Charging charging : chargings) {
-            DeviceAlgorithmCharging deviceAlgorithmCharging = new DeviceAlgorithmCharging()
-                    .setDeviceId(charging.getDeviceId())
-                    .setAlgorithmId(charging.getAlgorithmId())
-                    .setBeginTime(charging.getAlgorithmDate());
+            MercDto.Vo merc = mercsMaps.get(charging.getMercId());
+            String mercCode = merc.getMercCode();
+            List<String> mercCodes = new ArrayList<>();
+            getMercCodes(mercCode, mercCodes);
+            DeviceAlgorithmChargingChargingQueryParams deviceAlgorithmCharging = new DeviceAlgorithmChargingChargingQueryParams()
+                    .setMercCodes(mercCodes);
+            deviceAlgorithmCharging.setDeviceId(charging.getDeviceId());
+            deviceAlgorithmCharging.setAlgorithmId(charging.getAlgorithmId());
+            deviceAlgorithmCharging.setBeginTime(charging.getAlgorithmDate());
             queryList.add(deviceAlgorithmCharging);
         }
         List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = baseMapper.chargingQuery(queryList);
@@ -309,4 +328,19 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         }
         return size;
     }
+
+    /**
+     * 解析商户编码,获取上级及自身编码
+     *
+     * @return
+     */
+    private void getMercCodes(String mercCode, List<String> mercCodes) {
+        mercCodes.add(mercCode);
+        int length = mercCode.length();
+        if (length == 5) {
+            return;
+        }
+        String parentCode = mercCode.substring(0, length - 3);
+        getMercCodes(parentCode, mercCodes);
+    }
 }

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

@@ -12,7 +12,6 @@ import com.xy.dto.DeviceAlgorithmChargingDto;
 import com.xy.dto.DeviceChargingDto;
 import com.xy.dto.DeviceInfoDto;
 import com.xy.entity.*;
-import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceChargingMapper;
 import com.xy.utils.*;
 import io.swagger.annotations.Api;
@@ -242,8 +241,6 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
                 }
             }
             if (fal) {
-                //设备重新计费
-                deviceCharging.setIsJob(true);
                 //解冻设备
                 DeviceInfoDto.Update updateDeviceInfo = new DeviceInfoDto.Update()
                         .setDeviceId(deviceChargingHistory.getDeviceId());

+ 4 - 0
device-api-service/src/main/resources/mapper/DeviceAlgorithmChargingMapper.xml

@@ -11,6 +11,10 @@
             and algorithm_id = #{item.algorithmId}
             and unused_size > 0
             and ((begin_time &lt;= #{item.beginTime} and timeout >= #{item.beginTime}) or timeout = -1)
+            and merc_code in
+            <foreach collection="item.mercCodes" item="mercCode" separator="," open="(" close=")">
+                    #{mercCode}
+            </foreach>
         </foreach>
     </select>
 </mapper>

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

@@ -111,6 +111,9 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "算法id")
         private Long algorithmId;
 
+        @ApiModelProperty(value = "商户id")
+        private Long mercId;
+
         @ApiModelProperty(value = "扣除条数")
         private Integer size;
 
@@ -125,8 +128,8 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "id")
         private Long id;
 
-        @ApiModelProperty(value = "商户id")
-        private Long mercId;
+        @ApiModelProperty(value = "商户编码")
+        private String mercCode;
 
         @ApiModelProperty(value = "设备id")
         private Long deviceId;

+ 0 - 3
device-api/src/main/java/com/xy/dto/DeviceChargingDto.java

@@ -211,9 +211,6 @@ public class DeviceChargingDto {
         @ApiModelProperty(value = "管理费剩余天数,权重最高")
         private Integer chargingX;
 
-        @ApiModelProperty(value = "是否需要定时计费")
-        private Boolean isJob;
-
         @ApiModelProperty(value = "过期时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime timeout;