소스 검색

Merge remote-tracking branch 'origin/test' into test

谭斌 1 년 전
부모
커밋
4043d722ac

+ 5 - 2
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,10 +45,10 @@ public class DeviceAlgorithmCharging implements Serializable {
     @ApiModelProperty(value = "类型")
     private Integer type;
 
-    @ApiModelProperty(value = "过期时间;")
+    @ApiModelProperty(value = "过期时间;yyyyMMdd")
     private Integer timeout;
 
-    @ApiModelProperty(value = "生效时间")
+    @ApiModelProperty(value = "生效时间;yyyyMMdd")
     private Integer beginTime;
 
     @ApiModelProperty(value = "创建时间")

+ 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;
 

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

+ 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>

+ 27 - 20
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -86,6 +86,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);
@@ -109,7 +110,7 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
         JList<DeviceAlgorithmChargingHistory> infs = new JArrayList<>();
         JList<DeviceAlgorithmChargingHistory> gives = new JArrayList<>();
         LocalDateTime now = LocalDateTime.now();
-        int yyyyMM = Integer.valueOf(DataTime.getSring("yyyyMM"));
+        int yyyyMMdd = Integer.valueOf(DataTime.getSring("yyyyMMdd"));
         //获取算法包月字典
         Map<String, SysDictRedis> algorithmMoonConfigMaps = SysDictUtils.get(EnumAlgorithmPayConfig.Code.CODE.getCode());
         //获取类型字典
@@ -141,20 +142,26 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                         .last("limit 1");
                 DeviceAlgorithmCharging deviceAlgorithmCharging = getOne(lambdaQueryWrapper);
                 int beginTime;
+                int timeout;
                 if (deviceAlgorithmCharging == null) {
-                    beginTime = 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.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);
-                    beginTime = 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)
-                        .setTimeout(30)
+                        .setName(deviceAlgorithmChargingHistory.getName())
+                        .setTimeout(timeout)
                         .setBeginTime(beginTime)
                         .setCreateTime(now)
                         .setUpdateTime(now);
@@ -171,8 +178,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(inf.getSize() * deviceAlgorithmChargingHistory.getChargingSize())
                     .setType(deviceAlgorithmChargingHistory.getType())
+                    .setName(deviceAlgorithmChargingHistory.getName())
                     .setTimeout(-1)
-                    .setBeginTime(yyyyMM)
+                    .setBeginTime(yyyyMMdd)
                     .setCreateTime(now)
                     .setUpdateTime(now);
             save(deviceAlgorithmChargingInfo);
@@ -184,8 +192,9 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                     .setAlgorithmId(deviceAlgorithmChargingHistory.getAlgorithmId())
                     .setUnusedSize(deviceAlgorithmChargingHistory.getChargingSize())
                     .setType(deviceAlgorithmChargingHistory.getType())
-                    .setTimeout(30)
-                    .setBeginTime(yyyyMM)
+                    .setName(deviceAlgorithmChargingHistory.getName())
+                    .setTimeout(payNotice.getTimeout())
+                    .setBeginTime(yyyyMMdd)
                     .setCreateTime(now)
                     .setUpdateTime(now);
             save(deviceAlgorithmChargingInfo);
@@ -205,19 +214,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))
-                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
-                .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
-                        .gt(DeviceAlgorithmCharging::getTimeout, 0)
-                        .or()
-                        .eq(DeviceAlgorithmCharging::getTimeout, -1)
-                )
-                .in(DeviceAlgorithmCharging::getBeginTime, list.getProperty(DeviceAlgorithmChargingDto.Charging::getAlgorithmDate))
-                .orderByAsc(DeviceAlgorithmCharging::getBeginTime, DeviceAlgorithmCharging::getCreateTime);
-        List<DeviceAlgorithmCharging> deviceAlgorithmChargingsList = list(lambdaQueryWrapper);
+        List<DeviceAlgorithmCharging> 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);
         }
@@ -278,6 +283,8 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
                                 .setMakeSize(deviceAlgorithmCharging.getMakeSize() + makeSize)
                                 .setUpdateTime(now);
                         updateById(updateDeviceAlgorithmCharging);
+                        deviceAlgorithmCharging.setUnusedSize(updateDeviceAlgorithmCharging.getUnusedSize())
+                                .setMakeSize(updateDeviceAlgorithmCharging.getMakeSize());
                     }
                 }
             }

+ 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>

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

@@ -56,6 +56,9 @@ public class DeviceAlgorithmChargingDto {
             @ApiModelProperty("算法id")
             private Long algorithmId;
 
+            @ApiModelProperty("名称")
+            private String name;
+
             @ApiModelProperty("类型")
             private Integer type;
 
@@ -74,7 +77,10 @@ public class DeviceAlgorithmChargingDto {
         @NotBlank(message = "orderId不能为空")
         private String orderId;
 
+        @ApiModelProperty("赠送过期时间")
+        private Integer timeout;
     }
+
     @Data
     @Accessors(chain = true)
     public static class Charging {
@@ -108,6 +114,9 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "算法id")
         private Long algorithmId;
 
+        @ApiModelProperty(value = "名称")
+        private String name;
+
         @ApiModelProperty(value = "已用条数")
         private Integer makeSize;
 
@@ -117,10 +126,10 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "类型")
         private Integer type;
 
-        @ApiModelProperty(value = "过期时间;")
+        @ApiModelProperty(value = "过期时间;yyyyMMdd")
         private Integer timeout;
 
-        @ApiModelProperty(value = "生效时间")
+        @ApiModelProperty(value = "生效时间;yyyyMMdd")
         private Integer beginTime;
 
         @ApiModelProperty(value = "创建时间")

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

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