Sfoglia il codice sorgente

Merge branch 'master' into activation

李进 1 anno fa
parent
commit
ba32e9017b
27 ha cambiato i file con 683 aggiunte e 176 eliminazioni
  1. 10 0
      device-api-cloud/src/main/java/com/xy/feign/DeviceChargingHistoryFeign.java
  2. 10 0
      device-api-cloud/src/main/java/com/xy/feign/DeviceTypeAlgorithmBeforConfigFeign.java
  3. 27 0
      device-api-service-merc-mini/src/main/java/com/xy/controller/DeviceChargingController.java
  4. 7 1
      device-api-service/src/main/java/com/xy/entity/DeviceAlgorithmCharging.java
  5. 3 0
      device-api-service/src/main/java/com/xy/entity/DeviceAlgorithmChargingHistory.java
  6. 3 0
      device-api-service/src/main/java/com/xy/entity/DeviceCharging.java
  7. 49 0
      device-api-service/src/main/java/com/xy/entity/DeviceTypeAlgorithmBeforConfig.java
  8. 1 1
      device-api-service/src/main/java/com/xy/job/DeviceChargingJob.java
  9. 10 1
      device-api-service/src/main/java/com/xy/mapper/DeviceAlgorithmChargingMapper.java
  10. 16 0
      device-api-service/src/main/java/com/xy/mapper/DeviceTypeAlgorithmBeforConfigMapper.java
  11. 0 18
      device-api-service/src/main/java/com/xy/mapper/mapper/DeviceAlgorithmChargingMapper.xml
  12. 15 0
      device-api-service/src/main/java/com/xy/mapper/mapper/DeviceTypeAlgorithmBeforConfigMapper.xml
  13. 18 0
      device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingHistoryServiceImpl.java
  14. 90 93
      device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java
  15. 5 22
      device-api-service/src/main/java/com/xy/service/DeviceChargingHistoryServiceImpl.java
  16. 70 16
      device-api-service/src/main/java/com/xy/service/DeviceChargingServiceImpl.java
  17. 71 0
      device-api-service/src/main/java/com/xy/service/DeviceTypeAlgorithmBeforConfigServiceImpl.java
  18. 16 0
      device-api-service/src/main/resources/mapper/DeviceAlgorithmChargingMapper.xml
  19. 9 6
      device-api-service/src/main/resources/mapper/DeviceChargingMapper.xml
  20. 23 1
      device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingDto.java
  21. 14 0
      device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingHistoryDto.java
  22. 99 5
      device-api/src/main/java/com/xy/dto/DeviceChargingDto.java
  23. 1 12
      device-api/src/main/java/com/xy/dto/DeviceChargingHistoryDto.java
  24. 68 0
      device-api/src/main/java/com/xy/dto/DeviceTypeAlgorithmBeforConfigDto.java
  25. 13 0
      device-api/src/main/java/com/xy/service/DeviceAlgorithmChargingHistoryService.java
  26. 13 0
      device-api/src/main/java/com/xy/service/DeviceChargingHistoryService.java
  27. 22 0
      device-api/src/main/java/com/xy/service/DeviceTypeAlgorithmBeforConfigService.java

+ 10 - 0
device-api-cloud/src/main/java/com/xy/feign/DeviceChargingHistoryFeign.java

@@ -0,0 +1,10 @@
+package com.xy.feign;
+
+import com.xy.FeignInterceptor;
+import com.xy.consts.ServiceConsts;
+import com.xy.service.DeviceChargingHistoryService;
+import org.springframework.cloud.openfeign.FeignClient;
+
+@FeignClient(value = ServiceConsts.SERVICE_NAME, configuration = FeignInterceptor.class)
+public interface DeviceChargingHistoryFeign extends DeviceChargingHistoryService {
+}

+ 10 - 0
device-api-cloud/src/main/java/com/xy/feign/DeviceTypeAlgorithmBeforConfigFeign.java

@@ -0,0 +1,10 @@
+package com.xy.feign;
+
+import com.xy.FeignInterceptor;
+import com.xy.consts.ServiceConsts;
+import com.xy.service.DeviceTypeAlgorithmBeforConfigService;
+import org.springframework.cloud.openfeign.FeignClient;
+
+@FeignClient(value = ServiceConsts.SERVICE_NAME, configuration = FeignInterceptor.class)
+public interface DeviceTypeAlgorithmBeforConfigFeign extends DeviceTypeAlgorithmBeforConfigService {
+}

+ 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()));
+    }
+}

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

@@ -33,6 +33,9 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "算法id")
     private Long algorithmId;
 
+    @ApiModelProperty(value = "名称")
+    private String name;
+
     @ApiModelProperty(value = "已用条数")
     private Integer makeSize;
 
@@ -42,9 +45,12 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "类型")
     private Integer type;
 
-    @ApiModelProperty(value = "过期时间;yyyyMM")
+    @ApiModelProperty(value = "过期时间;yyyyMMdd")
     private Integer timeout;
 
+    @ApiModelProperty(value = "生效时间;yyyyMMdd")
+    private Integer beginTime;
+
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
 

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

@@ -36,6 +36,9 @@ public class DeviceAlgorithmChargingHistory implements Serializable {
     @ApiModelProperty(value = "算法id")
     private Long algorithmId;
 
+    @ApiModelProperty(value = "名称")
+    private String name;
+
     @ApiModelProperty(value = "充值金额")
     private Integer chargingMoney;
 

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

@@ -39,6 +39,9 @@ public class DeviceCharging implements Serializable {
     @ApiModelProperty(value = "过期时间")
     private LocalDateTime timeout;
 
+    @ApiModelProperty(value = "最后续费时间")
+    private LocalDateTime lastChargingTime;
+
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
 

+ 49 - 0
device-api-service/src/main/java/com/xy/entity/DeviceTypeAlgorithmBeforConfig.java

@@ -0,0 +1,49 @@
+package com.xy.entity;
+
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 设备类型算法预充配置
+ * </p>
+ *
+ * @author lijin
+ * @since 2023-07-10
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="DeviceTypeAlgorithmBeforConfig对象", description="设备类型算法预充配置")
+public class DeviceTypeAlgorithmBeforConfig implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "id")
+    private Long id;
+
+    @ApiModelProperty(value = "商户id")
+    private Long mercId;
+
+    @ApiModelProperty(value = "设备类型")
+    private Integer deviceType;
+
+    @ApiModelProperty(value = "算法id")
+    private Long algorithmId;
+
+    @ApiModelProperty(value = "预充金额;单位:分")
+    private Integer money;
+
+    @ApiModelProperty(value = "创建时间")
+    private LocalDateTime createTime;
+
+    @ApiModelProperty(value = "更新时间")
+    private LocalDateTime updateTime;
+
+
+}

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

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

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

@@ -1,7 +1,9 @@
 package com.xy.mapper;
 
-import com.xy.entity.DeviceAlgorithmCharging;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xy.entity.DeviceAlgorithmCharging;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +15,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface DeviceAlgorithmChargingMapper extends BaseMapper<DeviceAlgorithmCharging> {
 
+    /**
+     * 扣费查询
+     *
+     * @param list
+     * @return
+     */
+    List<DeviceAlgorithmCharging> chargingQuery(List<DeviceAlgorithmCharging> list);
 }

+ 16 - 0
device-api-service/src/main/java/com/xy/mapper/DeviceTypeAlgorithmBeforConfigMapper.java

@@ -0,0 +1,16 @@
+package com.xy.mapper;
+
+import com.xy.entity.DeviceTypeAlgorithmBeforConfig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 设备类型算法预充配置 Mapper 接口
+ * </p>
+ *
+ * @author lijin
+ * @since 2023-07-10
+ */
+public interface DeviceTypeAlgorithmBeforConfigMapper extends BaseMapper<DeviceTypeAlgorithmBeforConfig> {
+
+}

+ 0 - 18
device-api-service/src/main/java/com/xy/mapper/mapper/DeviceAlgorithmChargingMapper.xml

@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.xy.mapper.DeviceAlgorithmChargingMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.xy.entity.DeviceAlgorithmCharging">
-        <id column="id" property="id" />
-        <result column="device_id" property="deviceId" />
-        <result column="algorithm_id" property="algorithmId" />
-        <result column="make_size" property="makeSize" />
-        <result column="unused_size" property="unusedSize" />
-        <result column="is_give" property="isGive" />
-        <result column="timeout" property="timeout" />
-        <result column="create_time" property="createTime" />
-        <result column="update_time" property="updateTime" />
-    </resultMap>
-
-</mapper>

+ 15 - 0
device-api-service/src/main/java/com/xy/mapper/mapper/DeviceTypeAlgorithmBeforConfigMapper.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xy.mapper.DeviceTypeAlgorithmBeforConfigMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.xy.entity.DeviceTypeAlgorithmBeforConfig">
+        <result column="id" property="id" />
+        <result column="merc_id" property="mercId" />
+        <result column="device_type" property="deviceType" />
+        <result column="money" property="money" />
+        <result column="create_time" property="createTime" />
+        <result column="update_time" property="updateTime" />
+    </resultMap>
+
+</mapper>

+ 18 - 0
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingHistoryServiceImpl.java

@@ -1,11 +1,22 @@
 package com.xy.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xy.dto.DeviceAlgorithmChargingHistoryDto;
 import com.xy.entity.DeviceAlgorithmChargingHistory;
 import com.xy.mapper.DeviceAlgorithmChargingHistoryMapper;
+import com.xy.utils.MybatisPlusQuery;
+import com.xy.utils.PageBean;
+import com.xy.utils.PlusBeans;
+import com.xy.utils.R;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import static com.xy.utils.PlusBeans.toPageBean;
 
 
 /**
@@ -21,4 +32,11 @@ import org.springframework.stereotype.Service;
 @Api(tags = "设备算法计费历史表")
 public class DeviceAlgorithmChargingHistoryServiceImpl extends ServiceImpl<DeviceAlgorithmChargingHistoryMapper, DeviceAlgorithmChargingHistory> implements DeviceAlgorithmChargingHistoryService {
 
+    @Override
+    @ApiOperation("分页查询")
+    public R<PageBean<DeviceAlgorithmChargingHistoryDto.Vo>> page(@RequestBody DeviceAlgorithmChargingHistoryDto.Page page) {
+        LambdaQueryWrapper<DeviceAlgorithmChargingHistory> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceAlgorithmChargingHistory.class).build();
+        IPage<DeviceAlgorithmChargingHistory> iPage = page(PlusBeans.toIPage(page.getPage()), lambdaQueryWrapper);
+        return R.ok(toPageBean(DeviceAlgorithmChargingHistoryDto.Vo.class, iPage));
+    }
 }

+ 90 - 93
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -2,6 +2,7 @@ package com.xy.service;
 
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.yitter.idgen.YitIdHelper;
 import com.xy.collections.list.JArrayList;
@@ -18,10 +19,7 @@ import com.xy.entity.DeviceAlgorithmChargingHistory;
 import com.xy.entity.SysDictRedis;
 import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceAlgorithmChargingMapper;
-import com.xy.utils.DataTime;
-import com.xy.utils.Emptys;
-import com.xy.utils.R;
-import com.xy.utils.SysDictUtils;
+import com.xy.utils.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
@@ -36,6 +34,8 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import static com.xy.utils.PlusBeans.toPageBean;
+
 
 /**
  * <p>
@@ -54,6 +54,16 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private DeviceInfoService deviceInfoService;
 
+    @PostMapping("page")
+    @ApiOperation("分页查询")
+    public R<PageBean<DeviceAlgorithmChargingDto.Vo>> page(@RequestBody @Validated DeviceAlgorithmChargingDto.Page page) {
+        LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceAlgorithmCharging.class)
+                .build()
+                .orderByDesc(DeviceAlgorithmCharging::getTimeout, DeviceAlgorithmCharging::getUnusedSize);
+        IPage<DeviceAlgorithmCharging> iPage = page(PlusBeans.toIPage(page.getPage()), lambdaQueryWrapper);
+        return R.ok(toPageBean(DeviceAlgorithmChargingDto.Vo.class, iPage));
+    }
+
     @PostMapping("check")
     @ApiOperation("检查")
     public R check(@RequestBody @Validated DeviceAlgorithmChargingDto.Check check) {
@@ -61,17 +71,12 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         List<DeviceAlgorithmCharging> deviceAlgorithmChargings = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
                 .eq(DeviceAlgorithmCharging::getDeviceId, deviceInfo.getDeviceId())
                 .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)) {
-            throw new CommRuntimeException("设备欠费,请充值");
-        }
-        int size = 0;
-        for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
-            size += deviceAlgorithmCharging.getUnusedSize();
-        }
-        if (size == 0) {
-            throw new CommRuntimeException("设备欠费,请充值");
+            throw new CommRuntimeException("算法费欠费");
         }
         return R.ok();
     }
@@ -91,6 +96,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                     .setChargingSize(deviceAlgorithmCharging.getChargingSize())
                     .setChargingMoney(deviceAlgorithmCharging.getMoney())
                     .setType(deviceAlgorithmCharging.getType())
+                    .setName(deviceAlgorithmCharging.getName())
                     .setChargingType(pay.getPayType())
                     .setCreateTime(now)
                     .setUpdateTime(now);
@@ -114,6 +120,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
         LocalDateTime now = LocalDateTime.now();
+        int yyyyMMdd = Integer.valueOf(DataTime.getSring("yyyyMMdd"));
         //获取算法包月字典
         Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
         //获取类型字典
@@ -136,29 +143,36 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             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::getType, type)
-                        .orderByDesc(DeviceAlgorithmCharging::getTimeout)
+                        .orderByDesc(DeviceAlgorithmCharging::getBeginTime)
                         .last("limit 1");
                 DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
+                int beginTime;
                 int timeout;
                 if (deviceAlgorithmCharging == null) {
-                    timeout = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMM"));
+                    beginTime = Integer.valueOf(DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime(), "yyyyMMdd"));
+                    String stringAround = DataTime.getStringAround(0, 1, 0, 0, 0, 0, DataTime.toString(deviceAlgorithmChargingHistory.getCreateTime()));
+                    timeout = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround), "yyyyMMdd"));
                 } 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 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), "yyyyMMdd"));
+                    String stringAround1 = DataTime.getStringAround(0, 1, 0, 0, 0, 0, stringAround);
+                    timeout = Integer.valueOf(DataTime.toString(DataTime.toLocal(stringAround1), "yyyyMMdd"));
                 }
                 DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
                         .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
                         .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                         .setUnusedSize(moon.getSize())
                         .setType(type)
+                        .setName(deviceAlgorithmChargingHistory.getName())
                         .setTimeout(timeout)
+                        .setBeginTime(beginTime)
                         .setCreateTime(now)
                         .setUpdateTime(now);
                 save(deviceAlgorithmChargingInfo);
@@ -166,54 +180,31 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         });
         //处理无期限
         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);
-            }
+            DeviceAlgorithmCharging deviceAlgorithmChargingInfo = new DeviceAlgorithmCharging()
+                    .setDeviceId(deviceAlgorithmChargingHistory.getDeviceId())
+                    .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
+                    .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
+                    .setType(deviceAlgorithmChargingHistory.getType())
+                    .setName(deviceAlgorithmChargingHistory.getName())
+                    .setTimeout(-1)
+                    .setBeginTime(yyyyMMdd)
+                    .setCreateTime(now)
+                    .setUpdateTime(now);
+            save(deviceAlgorithmChargingInfo);
         });
         //处理赠送
         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())
+                    .setName(deviceAlgorithmChargingHistory.getName())
+                    .setTimeout(payNotice.getTimeout())
+                    .setBeginTime(yyyyMMdd)
+                    .setCreateTime(now)
+                    .setUpdateTime(now);
+            save(deviceAlgorithmChargingInfo);
         });
         if (Emptys.check(deviceAlgorithmChargingHistories)) {
             Integer status = SysDictUtils.getValue(EnumDeviceAlgorithmChargingHistoryStatus.Code.CODE.getCode(), EnumDeviceAlgorithmChargingHistoryStatus.N_2.getCode(), Integer.class);
@@ -230,12 +221,15 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         Map<Long, Integer> map = new JHashMap<>(chargings.size());
         chargings.forEach(charging -> map.put(charging.getMercDeviceAlgorithmChargingId(), charging.getSize()));
         //查询数据
-        JList<DeviceAlgorithmChargingDto.Charging> list = new JArrayList<>(chargings);
-        LambdaQueryWrapper<DeviceAlgorithmCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceAlgorithmCharging>()
-                .in(DeviceAlgorithmCharging::getDeviceId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getDeviceId))
-                .in(DeviceAlgorithmCharging::getAlgorithmId, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmId))
-                .in(DeviceAlgorithmCharging::getTimeout, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate).set(-1));
-        List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = list(lambdaQueryWrapper);
+        List<DeviceAlgorithmCharging> queryList = new ArrayList<>(chargings.size());
+        for (DeviceAlgorithmChargingDto.Charging charging : chargings) {
+            DeviceAlgorithmCharging deviceAlgorithmCharging = new DeviceAlgorithmCharging()
+                    .setDeviceId(charging.getDeviceId())
+                    .setAlgorithmId(charging.getAlgorithmId())
+                    .setBeginTime(charging.getAlgorithmDate());
+            queryList.add(deviceAlgorithmCharging);
+        }
+        List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = baseMapper.chargingQuery(queryList);
         if (!Emptys.check(deviceAlgorithmChargingsList)) {
             return R.ok(map);
         }
@@ -253,13 +247,12 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
             JList<DeviceAlgorithmCharging> deviceAlgorithmChargingJlist = deviceAlgorithmChargings.filter()
                     .eq(DeviceAlgorithmCharging::getDeviceId, charging.getDeviceId())
                     .eq(DeviceAlgorithmCharging::getAlgorithmId, charging.getAlgorithmId())
-                    .in(DeviceAlgorithmCharging::getTimeout, Arrays.asList(charging.getAlgorithmDate(), -1))
                     .list();
             if (!Emptys.check(deviceAlgorithmChargingJlist)) {
                 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));
             map.put(charging.getMercDeviceAlgorithmChargingId(), size2);
         });
@@ -271,31 +264,35 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
      *
      * @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)) {
             SysDictRedis sysDictRedis = sysDictRediss.remove(0);
             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.setUnusedSize(updateDeviceAlgorithmCharging.getUnusedSize())
+                                .setMakeSize(updateDeviceAlgorithmCharging.getMakeSize());
                     }
-                    DeviceAlgorithmCharging updateDeviceAlgorithmCharging = new DeviceAlgorithmCharging()
-                            .setId(deviceAlgorithmCharging.getId())
-                            .setUnusedSize(newUnusedSize)
-                            .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
-                            .setUpdateTime(now);
-                    updateById(updateDeviceAlgorithmCharging);
                 }
             }
             if (size > 0 && Emptys.check(sysDictRediss)) {

+ 5 - 22
device-api-service/src/main/java/com/xy/service/DeviceChargingHistoryServiceImpl.java

@@ -4,10 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xy.dto.DeviceChargingHistoryDto;
-import com.xy.dto.DeviceInfoDto;
 import com.xy.entity.DeviceChargingHistory;
 import com.xy.mapper.DeviceChargingHistoryMapper;
-import com.xy.utils.Emptys;
+import com.xy.utils.MybatisPlusQuery;
 import com.xy.utils.PageBean;
 import com.xy.utils.PlusBeans;
 import com.xy.utils.R;
@@ -15,11 +14,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-
-import java.util.List;
 
 import static com.xy.utils.PlusBeans.toPageBean;
 
@@ -36,22 +30,11 @@ import static com.xy.utils.PlusBeans.toPageBean;
 @Api(tags = "设备计费历史表")
 public class DeviceChargingHistoryServiceImpl extends ServiceImpl<DeviceChargingHistoryMapper, DeviceChargingHistory> implements DeviceChargingHistoryService {
 
-    private DeviceInfoServiceImpl deviceInfoService;
-
-    @PostMapping("page")
+    @Override
     @ApiOperation("分页查询")
-    public R<PageBean<DeviceChargingHistoryDto.PageVo>> page(@RequestBody @Validated DeviceChargingHistoryDto.Page page) {
-        //查询设备计费历史
-        LambdaQueryWrapper<DeviceChargingHistory> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceChargingHistory>().eq(DeviceChargingHistory::getDeviceId, page.getDeviceId());
+    public R<PageBean<DeviceChargingHistoryDto.Vo>> page(DeviceChargingHistoryDto.Page page) {
+        LambdaQueryWrapper<DeviceChargingHistory> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceChargingHistory.class).build();
         IPage<DeviceChargingHistory> iPage = page(PlusBeans.toIPage(page.getPage()), lambdaQueryWrapper);
-        PageBean<DeviceChargingHistoryDto.PageVo> pageVoPageBean = toPageBean(DeviceChargingHistoryDto.PageVo.class, iPage);
-        List<DeviceChargingHistoryDto.PageVo> records = pageVoPageBean.getRecords();
-        if (!Emptys.check(records)) {
-            return R.ok(pageVoPageBean);
-        }
-        //查询设备信息
-        DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(page.getDeviceId())).getData();
-        records.forEach(pageVo -> pageVo.setDeviceInfo(deviceInfo));
-        return R.ok(pageVoPageBean);
+        return R.ok(toPageBean(DeviceChargingHistoryDto.Vo.class, iPage));
     }
 }

+ 70 - 16
device-api-service/src/main/java/com/xy/service/DeviceChargingServiceImpl.java

@@ -1,18 +1,19 @@
 package com.xy.service;
 
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xy.collections.list.JArrayList;
 import com.xy.collections.list.JList;
 import com.xy.collections.map.JMap;
-import com.xy.device.EnumDeviceCharging;
-import com.xy.device.EnumDeviceChargingHistoryStatus;
+import com.xy.device.*;
+import com.xy.dto.DeviceAlgorithmChargingDto;
 import com.xy.dto.DeviceChargingDto;
-import com.xy.dto.DeviceChargingHistoryDto;
 import com.xy.dto.DeviceInfoDto;
 import com.xy.entity.DeviceCharging;
 import com.xy.entity.DeviceChargingHistory;
+import com.xy.entity.DeviceTypeAlgorithmBeforConfig;
 import com.xy.entity.SysDictRedis;
 import com.xy.error.CommRuntimeException;
 import com.xy.mapper.DeviceChargingMapper;
@@ -26,11 +27,13 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
-import static com.xy.utils.PlusBeans.*;
+import static com.xy.utils.PlusBeans.toIPage;
+import static com.xy.utils.PlusBeans.toPageBean;
 
 
 /**
@@ -52,6 +55,51 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
 
     private DeviceChargingServiceImpl deviceChargingService;
 
+    private DeviceTypeAlgorithmBeforConfigServiceImpl deviceTypeAlgorithmBeforConfigService;
+
+    @PostMapping("payCheck")
+    @ApiOperation("购买反显")
+    public R<DeviceChargingDto.PayCheckVo> payCheck(@RequestBody @Validated DeviceChargingDto.PayCheck payCheck) {
+        DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(payCheck.getDeviceId()).setIsStatus(true)).getData();
+        if (deviceInfo == null) {
+            return R.fail("设备不存在");
+        }
+        //封装设备信息
+        DeviceChargingDto.PayCheckVo payCheckVo = new DeviceChargingDto.PayCheckVo();
+        String deviceTypeName = SysDictUtils.get(EnumDeviceType.Code.CODE.getCode(), String.valueOf(deviceInfo.getDeviceType())).getMsg();
+        Integer standard = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), String.valueOf(deviceInfo.getDeviceType()), Integer.class);
+        DeviceChargingDto.PayCheckVo.DeviceInfo deviceInfoObj = Beans.copy(Beans.copy(DeviceChargingDto.PayCheckVo.DeviceInfo.class, deviceInfo), deviceInfo.getDeviceStatus())
+                .setDeviceTypeName(deviceTypeName)
+                .setStandard(BigDecimal.valueOf(standard).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN).doubleValue() + "元/年")
+                .setMoney(standard);
+        //封装算法购买信息
+        DeviceTypeAlgorithmBeforConfig deviceTypeAlgorithmBeforConfig = deviceTypeAlgorithmBeforConfigService.getOne(new LambdaQueryWrapper<DeviceTypeAlgorithmBeforConfig>()
+                .eq(DeviceTypeAlgorithmBeforConfig::getDeviceType, deviceInfo.getDeviceType())
+                .eq(DeviceTypeAlgorithmBeforConfig::getMercId, deviceInfo.getMercId())
+                .eq(DeviceTypeAlgorithmBeforConfig::getAlgorithmId, deviceInfo.getAlgorithmId())
+        );
+        SysDictRedis moonAlgorithmTypes = SysDictUtils.get(EnumAlgorithmTypes.Code.CODE.getCode(), String.valueOf(deviceInfo.getAlgorithmId()));
+        String algorithmPayConfig = SysDictUtils.getValue(EnumAlgorithmPayConfig.Code.CODE.getCode(), String.valueOf(deviceInfo.getAlgorithmId()), String.class);
+        DeviceAlgorithmChargingDto.AlgorithmMoonConfig algorithmMoonConfig = JSONUtil.parseObj(algorithmPayConfig).toBean(DeviceAlgorithmChargingDto.AlgorithmMoonConfig.class);
+        DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Inf inf = algorithmMoonConfig.getInf();
+        DeviceChargingDto.PayCheckVo.DeviceAlgorithmCharging infDeviceAlgorithmCharging = Beans.copy(DeviceChargingDto.PayCheckVo.DeviceAlgorithmCharging.class, deviceInfo)
+                .setDeviceTypeName(deviceTypeName)
+                .setAlgorithmId(deviceInfo.getAlgorithmId())
+                .setAlgorithmName(moonAlgorithmTypes.getMsg())
+                .setStandard(BigDecimal.valueOf(algorithmMoonConfig.getPrice()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN).doubleValue() + "元/每笔(" + inf.getSize() + "笔)")
+                .setMoney(deviceTypeAlgorithmBeforConfig == null ? inf.getMoney() : deviceTypeAlgorithmBeforConfig.getMoney());
+        //封装算法包月信息
+        DeviceAlgorithmChargingDto.AlgorithmMoonConfig.Moon moon = algorithmMoonConfig.getMoon();
+        DeviceChargingDto.PayCheckVo.DeviceAlgorithmCharging moonDeviceAlgorithmCharging = Beans.copy(DeviceChargingDto.PayCheckVo.DeviceAlgorithmCharging.class, deviceInfo)
+                .setDeviceTypeName(deviceTypeName)
+                .setAlgorithmId(deviceInfo.getAlgorithmId())
+                .setAlgorithmName(moonAlgorithmTypes.getMsg())
+                .setStandard(BigDecimal.valueOf(algorithmMoonConfig.getPrice()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN).doubleValue() + "元/包月(" + moon.getSize() + "笔)")
+                .setMoney(moon.getMoney());
+        payCheckVo.setDeviceInfo(deviceInfoObj).setInfDeviceAlgorithmCharging(infDeviceAlgorithmCharging).setMoonDeviceAlgorithmCharging(moonDeviceAlgorithmCharging);
+        return R.ok(payCheckVo);
+    }
+
     @PostMapping("check")
     @ApiOperation("检查")
     public R check(@RequestBody @Validated DeviceChargingDto.Check check) {
@@ -63,11 +111,11 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
                     .setTimeout(now)
                     .setCreateTime(now)
             );
-            throw new CommRuntimeException("设备欠费,请充值");
+            throw new CommRuntimeException("管理费欠费");
         }
         int contrast = DataTime.stringContrast(DataTime.toString(deviceCharging.getTimeout()), DataTime.toString(now));
         if (deviceCharging.getChargingX() == 0 && contrast <= 0) {
-            throw new CommRuntimeException("设备欠费,请充值");
+            throw new CommRuntimeException("管理费欠费");
         }
         return R.ok();
     }
@@ -75,22 +123,27 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
     @PostMapping("page")
     @ApiOperation("分页查询")
     public R<PageBean<DeviceChargingDto.PageVo>> page(@RequestBody DeviceChargingDto.Page page) {
+        Integer value = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_200.getCode(), Integer.class);
+        String theTime = DataTime.getStringAround(0, 0, value, 0, 0, 0);
+        page.setThisTime(LocalDateTime.now()).setTheTime(DataTime.toLocal(theTime));
         IPage<DeviceChargingDto.PageVo> iPage = baseMapper.page(toIPage(page.getPage()), page);
         List<DeviceChargingDto.PageVo> records = iPage.getRecords();
         if (Emptys.check(records)) {
             Map<String, SysDictRedis> stringSysDictRedisMap = SysDictUtils.get(EnumDeviceCharging.Code.CODE.getCode());
             for (DeviceChargingDto.PageVo record : records) {
-                DeviceInfoDto.Vo deviceInfo = record.getDeviceInfo();
-                //封装最新计费历史信息
-                LambdaQueryWrapper<DeviceChargingHistory> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceChargingHistory>()
-                        .eq(DeviceChargingHistory::getDeviceId, deviceInfo.getDeviceId())
-                        .orderByDesc(DeviceChargingHistory::getCreateTime)
-                        .last("limit 1");
-                DeviceChargingHistory deviceChargingHistory = deviceChargingHistoryService.getOne(lambdaQueryWrapper);
-                if (deviceChargingHistory != null) {
-                    record.setDeviceChargingHistory(copy(DeviceChargingHistoryDto.Vo.class, deviceChargingHistory));
+                //封装过期状态说明
+                String timeoutStatus;
+                DeviceChargingDto.Vo deviceCharging = record.getDeviceCharging();
+                LocalDateTime timeout = deviceCharging.getTimeout();
+                long s = DataTime.diff(page.getThisTime(), timeout, "s");
+                if (s <= 0) {
+                    timeoutStatus = "欠费(" + (~(s / 86400 - 1)) + "天)";
+                } else {
+                    timeoutStatus = s <= value * 86400 ? "即将到期(" + s / 86400 + "天)" : "正常(" + s / 86400 + "天)";
                 }
+                record.getDeviceCharging().setTimeoutStatus(timeoutStatus);
                 //封装计费标准金额
+                DeviceInfoDto.Vo deviceInfo = record.getDeviceInfo();
                 SysDictRedis sysDictRedis = stringSysDictRedisMap.get(deviceInfo.getDeviceType().toString());
                 if (sysDictRedis != null) {
                     record.setChargingMoney(Integer.valueOf(sysDictRedis.getValue()));
@@ -147,7 +200,8 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
         JList<DeviceInfoDto.Update> updateDeviceInfos = new JArrayList<>();
         JList<DeviceChargingHistory> updateDeviceChargingHistory = new JArrayList<>();
         for (DeviceChargingHistory deviceChargingHistory : deviceChargingHistories) {
-            DeviceCharging deviceCharging = deviceChargingsJMaps.get(deviceChargingHistory.getDeviceId());
+            DeviceCharging deviceCharging = deviceChargingsJMaps.get(deviceChargingHistory.getDeviceId())
+                    .setLastChargingTime(now);
             Integer chargingSize = deviceChargingHistory.getChargingSize();
             boolean fal = false;
             //设备计费历史完成

+ 71 - 0
device-api-service/src/main/java/com/xy/service/DeviceTypeAlgorithmBeforConfigServiceImpl.java

@@ -0,0 +1,71 @@
+package com.xy.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xy.dto.DeviceTypeAlgorithmBeforConfigDto;
+import com.xy.entity.DeviceTypeAlgorithmBeforConfig;
+import com.xy.mapper.DeviceTypeAlgorithmBeforConfigMapper;
+import com.xy.utils.Emptys;
+import com.xy.utils.MybatisPlusQuery;
+import com.xy.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+
+import static com.xy.utils.Beans.copy;
+
+
+/**
+ * <p>
+ * 设备类型算法预充配置 服务实现类
+ * </p>
+ *
+ * @author lijin
+ * @since 2023-07-10
+ */
+@Service
+@AllArgsConstructor
+@Api(tags = "设备类型算法预充配置")
+public class DeviceTypeAlgorithmBeforConfigServiceImpl extends ServiceImpl<DeviceTypeAlgorithmBeforConfigMapper, DeviceTypeAlgorithmBeforConfig> implements DeviceTypeAlgorithmBeforConfigService {
+
+    @Override
+    @ApiOperation("对象查询")
+    public R<DeviceTypeAlgorithmBeforConfigDto.Vo> obj(@RequestBody DeviceTypeAlgorithmBeforConfigDto.Vo vo) {
+        DeviceTypeAlgorithmBeforConfigDto.SelectList selectList = copy(DeviceTypeAlgorithmBeforConfigDto.SelectList.class, vo);
+        List<DeviceTypeAlgorithmBeforConfigDto.Vo> list = list(selectList).getData();
+        if (Emptys.check(list)) {
+            return R.ok(list.get(0));
+        }
+        return R.ok();
+    }
+
+    @PostMapping("list")
+    @ApiOperation("集合查询")
+    public R<List<DeviceTypeAlgorithmBeforConfigDto.Vo>> list(@RequestBody DeviceTypeAlgorithmBeforConfigDto.SelectList selectList) {
+        LambdaQueryWrapper<DeviceTypeAlgorithmBeforConfig> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceTypeAlgorithmBeforConfig.class).build();
+        List<DeviceTypeAlgorithmBeforConfig> list = list(lambdaQueryWrapper);
+        return R.ok(copy(DeviceTypeAlgorithmBeforConfigDto.Vo.class, list));
+    }
+
+    @PostMapping("save")
+    @ApiOperation("添加")
+    public R save(@RequestBody @Validated DeviceTypeAlgorithmBeforConfigDto.Save save) {
+        DeviceTypeAlgorithmBeforConfig saveInfo = copy(DeviceTypeAlgorithmBeforConfig.class, save);
+        save(saveInfo);
+        return R.ok();
+    }
+
+    @PostMapping("update")
+    @ApiOperation("修改")
+    public R update(@RequestBody @Validated DeviceTypeAlgorithmBeforConfigDto.Update update) {
+        DeviceTypeAlgorithmBeforConfig updateInfo = copy(DeviceTypeAlgorithmBeforConfig.class, update);
+        updateById(updateInfo);
+        return R.ok();
+    }
+}

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

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xy.mapper.DeviceAlgorithmChargingMapper">
+
+    <!-- 扣费查询 -->
+    <select id="chargingQuery" resultType="com.xy.entity.DeviceAlgorithmCharging">
+        <foreach collection="list" item="item" separator="UNION">
+            select *
+            from device_algorithm_charging
+            where device_id = #{item.deviceId}
+            and algorithm_id = #{item.algorithmId}
+            and unused_size > 0
+            and ((begin_time &lt;= #{item.beginTime} and timeout >= #{item.beginTime}) or timeout = -1)
+        </foreach>
+    </select>
+</mapper>

+ 9 - 6
device-api-service/src/main/resources/mapper/DeviceChargingMapper.xml

@@ -29,13 +29,14 @@
             <result column="charging_sum_money" property="chargingSumMoney" />
             <result column="charging_x" property="chargingX" />
             <result column="timeout" property="timeout" />
+            <result column="last_charging_time" property="lastChargingTime" />
             <result column="charging_create_time" property="createTime" />
         </association>
     </resultMap>
 
     <select id="page" resultMap="queryPageMap">
         select di.*,
-        dc.charging_sum_money, dc.charging_x, dc.timeout, dc.create_time as charging_create_time
+        dc.charging_sum_money, dc.charging_x, dc.timeout, dc.last_charging_time, dc.create_time as charging_create_time
         from device_info di
         join device_charging dc on(di.device_id = dc.device_id)
         where
@@ -46,12 +47,14 @@
         <if test="queryPage.deviceId != null">
             and di.device_id = #{queryPage.deviceId}
         </if>
-        <if test="queryPage.chargingStatus != null">
-            <if test="queryPage.chargingStatus == true">
-                and dc.timeout &lt;= #{queryPage.thisTime}
+        <if test="queryPage.chargingStatus != null and queryPage.chargingStatus != ''">
+            <!-- 即将过期 -->
+            <if test="queryPage.chargingStatus == 1">
+               and dc.timeout >= #{queryPage.thisTime} and dc.timeout &lt;= #{queryPage.theTime}
             </if>
-            <if test="queryPage.chargingStatus == false">
-                and dc.timeout >= #{queryPage.thisTime}
+            <!-- 已过期 -->
+            <if test="queryPage.chargingStatus == 2">
+                and dc.timeout &lt;= #{queryPage.thisTime}
             </if>
         </if>
         order by dc.timeout asc

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

@@ -1,6 +1,7 @@
 package com.xy.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xy.utils.PageBean;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
@@ -21,6 +22,15 @@ import java.util.List;
  */
 public class DeviceAlgorithmChargingDto {
 
+    @Data
+    @Accessors(chain = true)
+    public static class Page extends Vo {
+
+        @ApiModelProperty("分页对象")
+        private PageBean page;
+
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Check {
@@ -56,6 +66,9 @@ public class DeviceAlgorithmChargingDto {
             @ApiModelProperty("算法id")
             private Long algorithmId;
 
+            @ApiModelProperty("名称")
+            private String name;
+
             @ApiModelProperty("类型")
             private Integer type;
 
@@ -74,7 +87,10 @@ public class DeviceAlgorithmChargingDto {
         @NotBlank(message = "orderId不能为空")
         private String orderId;
 
+        @ApiModelProperty("赠送过期时间")
+        private Integer timeout;
     }
+
     @Data
     @Accessors(chain = true)
     public static class Charging {
@@ -108,6 +124,9 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "算法id")
         private Long algorithmId;
 
+        @ApiModelProperty(value = "名称")
+        private String name;
+
         @ApiModelProperty(value = "已用条数")
         private Integer makeSize;
 
@@ -117,9 +136,12 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "类型")
         private Integer type;
 
-        @ApiModelProperty(value = "过期时间;yyyyMM")
+        @ApiModelProperty(value = "过期时间;yyyyMMdd")
         private Integer timeout;
 
+        @ApiModelProperty(value = "生效时间;yyyyMMdd")
+        private Integer beginTime;
+
         @ApiModelProperty(value = "创建时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;

+ 14 - 0
device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingHistoryDto.java

@@ -1,10 +1,12 @@
 package com.xy.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xy.utils.PageBean;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import javax.validation.constraints.NotNull;
 import java.time.LocalDateTime;
 
 /**
@@ -17,6 +19,15 @@ import java.time.LocalDateTime;
  */
 public class DeviceAlgorithmChargingHistoryDto {
 
+    @Data
+    @Accessors(chain = true)
+    public static class Page extends Vo {
+
+        @ApiModelProperty("分页对象")
+        private PageBean page;
+
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Vo {
@@ -33,6 +44,9 @@ public class DeviceAlgorithmChargingHistoryDto {
         @ApiModelProperty(value = "算法id")
         private Long algorithmId;
 
+        @ApiModelProperty(value = "名称")
+        private String name;
+
         @ApiModelProperty(value = "充值金额")
         private Integer chargingMoney;
 

+ 99 - 5
device-api/src/main/java/com/xy/dto/DeviceChargingDto.java

@@ -53,8 +53,14 @@ public class DeviceChargingDto {
         @ApiModelProperty("设备id")
         private Long deviceId;
 
-        @ApiModelProperty(value = "当前系统时间", hidden = true)
-        private LocalDateTime thisTime = LocalDateTime.now();
+        @ApiModelProperty("状态类型 字典=device_charging_query_type")
+        private Integer chargingStatus;
+
+        @ApiModelProperty(hidden = true)
+        private LocalDateTime thisTime;
+
+        @ApiModelProperty(hidden = true)
+        private LocalDateTime theTime;
     }
 
     @Data
@@ -100,6 +106,91 @@ public class DeviceChargingDto {
 
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class PayCheck {
+
+        @NotNull(message = "deviceId不能为空")
+        @ApiModelProperty("设备id")
+        private Long deviceId;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class PayCheckVo {
+
+        @ApiModelProperty(value = "设备信息")
+        private DeviceInfo deviceInfo;
+
+        @ApiModelProperty(value = "算法包月信息")
+        private DeviceAlgorithmCharging moonDeviceAlgorithmCharging;
+
+        @ApiModelProperty(value = "算法购买信息")
+        private DeviceAlgorithmCharging infDeviceAlgorithmCharging;
+
+        @Data
+        @Accessors(chain = true)
+        public static class DeviceInfo {
+
+            @ApiModelProperty("设备id")
+            private Long deviceId;
+
+            @ApiModelProperty("设备名称")
+            private String deviceName;
+
+            @ApiModelProperty("设备类型")
+            private Integer deviceType;
+
+            @ApiModelProperty("设备类型名称")
+            private String deviceTypeName;
+
+            @ApiModelProperty("计费标准说明")
+            private String standard;
+
+            @ApiModelProperty("激活状态")
+            private Integer activeState;
+
+            @ApiModelProperty("运营状态")
+            private Integer busyState;
+
+            @ApiModelProperty("冻结状态")
+            private Integer freezeStatus;
+
+            @ApiModelProperty("价格")
+            private Integer money;
+        }
+
+        @Data
+        @Accessors(chain = true)
+        public static class DeviceAlgorithmCharging {
+
+            @ApiModelProperty("算法id")
+            private Long algorithmId;
+
+            @ApiModelProperty("算法名称")
+            private String algorithmName;
+
+            @ApiModelProperty("设备id")
+            private Long deviceId;
+
+            @ApiModelProperty("设备名称")
+            private String deviceName;
+
+            @ApiModelProperty("设备类型")
+            private Integer deviceType;
+
+            @ApiModelProperty("设备类型名称")
+            private String deviceTypeName;
+
+            @ApiModelProperty("计费标准说明")
+            private String standard;
+
+            @ApiModelProperty("价格")
+            private Integer money;
+
+        }
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Vo {
@@ -124,6 +215,12 @@ public class DeviceChargingDto {
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;
 
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        @ApiModelProperty(value = "最后续费时间")
+        private LocalDateTime lastChargingTime;
+
+        @ApiModelProperty(value = "过期状态说明")
+        private String timeoutStatus;
     }
 
     @Data
@@ -133,9 +230,6 @@ public class DeviceChargingDto {
         @ApiModelProperty(value = "计费信息")
         private Vo deviceCharging;
 
-        @ApiModelProperty(value = "最新计费历史信息")
-        private DeviceChargingHistoryDto.Vo deviceChargingHistory;
-
         @ApiModelProperty(value = "设备信息")
         private DeviceInfoDto.Vo deviceInfo;
 

+ 1 - 12
device-api/src/main/java/com/xy/dto/DeviceChargingHistoryDto.java

@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
-import javax.validation.constraints.NotNull;
 import java.time.LocalDateTime;
 
 /**
@@ -56,21 +55,11 @@ public class DeviceChargingHistoryDto {
 
     @Data
     @Accessors(chain = true)
-    public static class Page {
+    public static class Page extends Vo {
 
         @ApiModelProperty("分页对象")
         private PageBean page;
 
-        @NotNull(message = "deviceId不能为空")
-        @ApiModelProperty("设备id")
-        private Long deviceId;
     }
 
-    @Data
-    @Accessors(chain = true)
-    public static class PageVo extends Vo {
-
-        @ApiModelProperty(value = "设备信息")
-        private DeviceInfoDto.Vo deviceInfo;
-    }
 }

+ 68 - 0
device-api/src/main/java/com/xy/dto/DeviceTypeAlgorithmBeforConfigDto.java

@@ -0,0 +1,68 @@
+package com.xy.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 设备类型算法预充配置
+ * </p>
+ *
+ * @author lijin
+ * @since 2023-07-10
+ */
+public class DeviceTypeAlgorithmBeforConfigDto {
+
+    @Data
+    @Accessors(chain = true)
+    public static class SelectList extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Save extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Update extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Vo {
+
+        @ApiModelProperty(value = "id")
+        private Long id;
+
+        @ApiModelProperty(value = "商户id")
+        private Long mercId;
+
+        @ApiModelProperty(value = "设备类型")
+        private Integer deviceType;
+
+        @ApiModelProperty(value = "算法id")
+        private Long algorithmId;
+
+        @ApiModelProperty(value = "预充金额;单位:分")
+        private Integer money;
+
+        @ApiModelProperty(value = "创建时间")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime createTime;
+
+        @ApiModelProperty(value = "更新时间")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime updateTime;
+
+
+    }
+
+}

+ 13 - 0
device-api/src/main/java/com/xy/service/DeviceAlgorithmChargingHistoryService.java

@@ -1,6 +1,11 @@
 package com.xy.service;
 
 import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceAlgorithmChargingHistoryDto;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 /**
  * <p>
@@ -13,4 +18,12 @@ import com.xy.annotate.RestMappingController;
 @RestMappingController("/device-algorithm-charging-history")
 public interface DeviceAlgorithmChargingHistoryService {
 
+    /**
+     * 分页查询
+     *
+     * @param page
+     * @return
+     */
+    @PostMapping("page")
+    R<PageBean<DeviceAlgorithmChargingHistoryDto.Vo>> page(@RequestBody DeviceAlgorithmChargingHistoryDto.Page page);
 }

+ 13 - 0
device-api/src/main/java/com/xy/service/DeviceChargingHistoryService.java

@@ -1,6 +1,11 @@
 package com.xy.service;
 
 import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceChargingHistoryDto;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 /**
  * <p>
@@ -13,4 +18,12 @@ import com.xy.annotate.RestMappingController;
 @RestMappingController("/device-charging-history")
 public interface DeviceChargingHistoryService {
 
+    /**
+     * 分页查询
+     *
+     * @param page
+     * @return
+     */
+    @PostMapping("page")
+    R<PageBean<DeviceChargingHistoryDto.Vo>> page(@RequestBody DeviceChargingHistoryDto.Page page);
 }

+ 22 - 0
device-api/src/main/java/com/xy/service/DeviceTypeAlgorithmBeforConfigService.java

@@ -0,0 +1,22 @@
+package com.xy.service;
+
+import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceTypeAlgorithmBeforConfigDto;
+import com.xy.utils.R;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * <p>
+ * 设备类型算法预充配置 服务类
+ * </p>
+ *
+ * @author lijin
+ * @since 2023-07-10
+ */
+@RestMappingController("/device-type-algorithm-befor-config")
+public interface DeviceTypeAlgorithmBeforConfigService {
+
+    @PostMapping("obj")
+    R<DeviceTypeAlgorithmBeforConfigDto.Vo> obj(@RequestBody DeviceTypeAlgorithmBeforConfigDto.Vo vo);
+}