Эх сурвалжийг харах

算法卡包修改业务逻辑

李进 1 жил өмнө
parent
commit
951792d5ea

+ 1 - 1
device-api-service-merc-mini/src/main/java/com/xy/controller/DeviceAlgorithmChargingController.java

@@ -23,7 +23,7 @@ public class DeviceAlgorithmChargingController {
     @PostMapping("page")
     @ApiOperation("分页查询")
     public R<PageBean<DeviceAlgorithmChargingDto.Vo>> page(@RequestBody @Validated DeviceAlgorithmChargingDto.Page page) {
-        page.setMercCode(MercAuthUtils.getMercAuth().getMerc().getMercCode());
+        page.setMercId(MercAuthUtils.getMercId());
         return deviceAlgorithmChargingService.page(page);
     }
 

+ 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 = "商户编码")
-    private String mercCode;
+    @ApiModelProperty(value = "商户id")
+    private Long mercId;
 
     @ApiModelProperty(value = "设备id")
     private Long deviceId;

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

@@ -0,0 +1,102 @@
+package com.xy.job;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xy.annotate.RestMappingController;
+import com.xy.collections.list.JArrayList;
+import com.xy.collections.list.JList;
+import com.xy.collections.map.JMap;
+import com.xy.dto.MercAccountDto;
+import com.xy.entity.DeviceAlgorithmCharging;
+import com.xy.entity.DeviceInfo;
+import com.xy.service.DeviceAlgorithmChargingServiceImpl;
+import com.xy.service.DeviceInfoServiceImpl;
+import com.xy.service.MercAccountService;
+import com.xy.utils.Emptys;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 设备算法费job
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+@RestMappingController("test")
+public class DeviceAlgorithmChargingJob {
+
+    private MercAccountService mercAccountService;
+
+    private DeviceInfoServiceImpl deviceInfoService;
+
+    private DeviceAlgorithmChargingServiceImpl deviceAlgorithmChargingService;
+
+    /**
+     * 算法费设备停机
+     *
+     * @return
+     */
+    @GetMapping("test")
+    @XxlJob("deviceAlgorithmChargingHalt")
+    public ReturnT<String> deviceAlgorithmChargingHalt() {
+        //查询余额<=0商户
+        List<MercAccountDto.Vo> mercAccounts = mercAccountService.list(new MercAccountDto.SelectList().setEndBalance(0)).getData();
+        if (!Emptys.check(mercAccounts)) {
+            return ReturnT.SUCCESS;
+        }
+        mercAccounts.forEach(mercAccount -> {
+            List<DeviceInfo> updateDeviceInfos = new ArrayList<>();
+            //查询商户未冻结设备
+            List<DeviceInfo> deviceInfos = deviceInfoService.list(new LambdaQueryWrapper<DeviceInfo>()
+                    .eq(DeviceInfo::getMercId, mercAccount.getMercId())
+                    .eq(DeviceInfo::getActiveState, 1)
+                    .eq(DeviceInfo::getFreezeStatus, 1)
+            );
+            if (!Emptys.check(deviceInfos)) {
+                return;
+            }
+            JMap<Long, DeviceInfo> deviceInfosJMaps = new JArrayList<>(deviceInfos).toMap(DeviceInfo::getDeviceId).cover();
+            //分组统计设备可用算法卡包
+            LocalDateTime now = LocalDateTime.now();
+            LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                    .select(DeviceAlgorithmCharging::getDeviceId)
+                    .gt(DeviceAlgorithmCharging::getMercId, mercAccount.getMercId())
+                    .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                    .in(DeviceAlgorithmCharging::getDeviceId, deviceInfosJMaps.getKeys())
+                    .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
+                            .eq(DeviceAlgorithmCharging::getTimeout, -1)
+                            .or(deviceAlgorithmChargingLambdaQueryWrapper1 -> deviceAlgorithmChargingLambdaQueryWrapper1
+                                    .le(DeviceAlgorithmCharging::getBeginTime, now)
+                                    .ge(DeviceAlgorithmCharging::getTimeout, now)
+                            )
+                    )
+                    .groupBy(DeviceAlgorithmCharging::getDeviceId);
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings = deviceAlgorithmChargingService.list(lambdaQueryWrapper);
+            JMap<Long, DeviceAlgorithmCharging> deviceAlgorithmChargingsJMaps = new JArrayList<>(deviceAlgorithmChargings).toMap(DeviceAlgorithmCharging::getDeviceId).cover();
+            //判断是否过期
+            deviceInfosJMaps.forEach((deviceId, deviceInfo) -> {
+                if (deviceAlgorithmChargingsJMaps.containsKey(deviceId)) {
+                    return;
+                }
+                //冻结and停运设备
+                DeviceInfo updateDeviceInfo = new DeviceInfo()
+                        .setDeviceId(deviceId)
+                        .setFreezeStatus(2)
+                        .setBusyState(2)
+                        .setUpdateTime(now);
+                updateDeviceInfos.add(updateDeviceInfo);
+            });
+            if (Emptys.check(updateDeviceInfos)) {
+                deviceInfoService.updateBatchById(updateDeviceInfos);
+            }
+        });
+        return ReturnT.SUCCESS;
+    }
+}

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

@@ -21,6 +21,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -45,10 +46,12 @@ public class DeviceChargingJob {
      */
     @XxlJob("deviceChargingHalt")
     public ReturnT<String> deviceChargingHalt() {
+        LocalDateTime now = LocalDateTime.now();
         Map<String, SysDictRedis> stringSysDictRedisMap = SysDictUtils.get(EnumMercCostMsgConfig.Code.CODE.getCode());
         int day = Integer.valueOf(stringSysDictRedisMap.get(EnumMercCostMsgConfig.ARREARAGE_DAY.getCode()).getValue());
         String timeout = DataTime.getStringAround(0, 0, (~(day - 1)), 0, 0, 0);
         LambdaQueryWrapper<DeviceCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceCharging>()
+                .select(DeviceCharging::getDeviceId)
                 .le(DeviceCharging::getTimeout, timeout);
         RecursionUtils.recursion(current -> {
             //查询已过期设备管理费
@@ -57,20 +60,19 @@ public class DeviceChargingJob {
             if (!Emptys.check(records)) {
                 return false;
             }
-            //查询未冻结or未停运设备
+            //查询未冻结设备
             LambdaQueryWrapper<DeviceInfo> deviceInfoLambdaQueryWrapper = new LambdaQueryWrapper<DeviceInfo>()
+                    .select(DeviceInfo::getDeviceId)
                     .in(DeviceInfo::getDeviceId, new JArrayList<>(records).getProperty(DeviceCharging::getDeviceId))
-                    .and(deviceInfoLambdaQueryWrappers -> deviceInfoLambdaQueryWrappers
-                            .eq(DeviceInfo::getFreezeStatus, 1)
-                            .or()
-                            .eq(DeviceInfo::getBusyState, 1)
-                    );
+                    .eq(DeviceInfo::getActiveState, 1)
+                    .eq(DeviceInfo::getFreezeStatus, 1);
             List<DeviceInfo> deviceInfos = deviceInfoService.list(deviceInfoLambdaQueryWrapper);
             //冻结and停运设备
             if (Emptys.check(deviceInfos)) {
                 deviceInfos.forEach(deviceInfo -> deviceInfo
                         .setFreezeStatus(2)
                         .setBusyState(2)
+                        .setUpdateTime(now)
                 );
                 deviceInfoService.updateBatchById(deviceInfos);
             }

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

@@ -2,7 +2,6 @@ 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;
 
@@ -22,5 +21,5 @@ public interface DeviceAlgorithmChargingMapper extends BaseMapper<DeviceAlgorith
      * @param list
      * @return
      */
-    List<DeviceAlgorithmCharging> chargingQuery(List<DeviceAlgorithmChargingChargingQueryParams> list);
+    List<DeviceAlgorithmCharging> chargingQuery(List<DeviceAlgorithmCharging> list);
 }

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

@@ -1,17 +0,0 @@
-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;
-
-}

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

@@ -16,14 +16,11 @@ import com.xy.device.EnumDeviceAlgorithmChargingHistoryStatus;
 import com.xy.device.EnumDeviceAlgorithmChargingType;
 import com.xy.device.EnumDeviceType;
 import com.xy.dto.*;
-import com.xy.dto.be.MercDto;
 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;
 import com.xy.utils.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -61,8 +58,6 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private DeviceInfoServiceImpl deviceInfoService;
 
-    private MercService mercService;
-
     private DeviceSysinfoServiceImpl deviceSysinfoService;
 
     private AlipayDeviceService alipayDeviceService;
@@ -72,7 +67,6 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
     @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();
         //默认值
         JList<Long> deviceIds = new JArrayList<>(count.getDeviceIds());
         JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
@@ -93,7 +87,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             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())
+                    .eq(DeviceAlgorithmCharging::getMercId, count.getMercId())
             );
             deviceAlgorithmChargings.addAll(list);
         });
@@ -117,7 +111,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         //统计设备欠费金额
         List<MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVos = mercDeviceAlgorithmChargingService.countArrearageBalance(new MercDeviceAlgorithmChargingDto.CountArrearageBalance()
                 .setDeviceIds(deviceIds)
-                .setMercId(merc.getId())
+                .setMercId(count.getMercId())
         ).getData();
         JMap<Long, MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVosJMaps = new JArrayList<>(countArrearageBalanceVos).toMap(MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo::getDeviceId).cover();
         //封装数据
@@ -166,6 +160,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         int yyyyMMdd = Integer.valueOf(DataTime.getSring("yyyyMMdd"));
         DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(check.getDeviceId())).getData();
         List<DeviceAlgorithmCharging> deviceAlgorithmChargings = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                .eq(DeviceAlgorithmCharging::getMercId, deviceInfo.getMercId())
                 .eq(DeviceAlgorithmCharging::getDeviceId, deviceInfo.getDeviceId())
                 .eq(DeviceAlgorithmCharging::getAlgorithmId, deviceInfo.getAlgorithmId())
                 .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
@@ -234,9 +229,6 @@ 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();
         JList<DeviceInfoDto.Update> updateDeviceInfos = new JArrayList<>();
         JList<Tuple.Tuple2<BindDeviceDTO, BindActiveDTO>> ailiActive = new JArrayList<>();
         int aliDeviceType = SysDictUtils.getValue(EnumDeviceType.Code.CODE.getCode(), EnumDeviceType.N_5.getCode(), Integer.class);
@@ -311,9 +303,8 @@ 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()
-                        .setMercCode(merc.getMercCode())
+                        .setMercId(deviceAlgorithmChargingHistory.getMercId())
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setUnusedSize(moon.getSize())
@@ -328,9 +319,8 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         //处理无期限
         infs.forEach(deviceAlgorithmChargingHistory -> {
-            MercDto.Vo merc = mercsMaps.get(deviceAlgorithmChargingHistory.getMercId());
             DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                    .setMercCode(merc.getMercCode())
+                    .setMercId(deviceAlgorithmChargingHistory.getMercId())
                     .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
@@ -344,9 +334,8 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         //处理赠送
         gives.forEach(deviceAlgorithmChargingHistory -> {
-            MercDto.Vo merc = mercsMaps.get(deviceAlgorithmChargingHistory.getMercId());
             DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
-                    .setMercCode(merc.getMercCode())
+                    .setMercId(deviceAlgorithmChargingHistory.getMercId())
                     .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
@@ -369,7 +358,6 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             deviceInfoService.updateBatch(updateDeviceInfos);
         }
         //支付宝刷脸柜激活请求
-        log.info("支付宝刷脸柜激活请求参数:{}", ailiActive.toString());
         if (Emptys.check(ailiActive)) {
             ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.ALI_DEVICE_ACTIVE, ailiActive.size());
             ailiActive.forEach(bindDeviceDTOBindActiveDTOTuple2 -> execute.execute(() -> {
@@ -385,24 +373,17 @@ 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()));
+        chargings.forEach(charging -> map.put(charging.getMercDeviceAlgorithmChargingId(), 0));
         //查询数据
-        List<DeviceAlgorithmChargingChargingQueryParams> queryList = new ArrayList<>(chargings.size());
+        List<DeviceAlgorithmCharging> queryList = new ArrayList<>(chargings.size());
         for (DeviceAlgorithmChargingDto.Charging charging : chargings) {
-            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());
+            DeviceAlgorithmCharging deviceAlgorithmCharging = new DeviceAlgorithmCharging()
+                    .setMercId(charging.getMercId())
+                    .setDeviceId(charging.getDeviceId())
+                    .setAlgorithmId(charging.getAlgorithmId())
+                    .setBeginTime(charging.getAlgorithmDate());
             queryList.add(deviceAlgorithmCharging);
         }
         List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = baseMapper.chargingQuery(queryList);

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

@@ -11,10 +11,7 @@
             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>
+            and merc_id = #{item.mercId}
         </foreach>
     </select>
 </mapper>

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

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