Răsfoiți Sursa

设备管理费修改

李进 2 ani în urmă
părinte
comite
81867a22d3

+ 7 - 14
device-api-service-merc-mini/src/main/java/com/xy/controller/MercMiniDeviceController.java

@@ -186,30 +186,23 @@ public class MercMiniDeviceController {
         R activeInfo = this.getActiveInfo(active);
         //激活设备
         if (activeInfo.getCode() == R.Enum.SUCCESS.getCode()) {
-            DeviceInfo deviceInfo = deviceInfoService.getById(active.getDeviceId());
+            LocalDateTime now = LocalDateTime.now();
             DeviceInfo updateDeviceInfo = new DeviceInfo()
                     .setDeviceId(active.getDeviceId())
                     .setActiveState(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))
                     .setBusyState(Integer.valueOf(DictSonEnum.DEVICE_BUSY_STATUS_1.getKey()))
-                    .setActiveTime(LocalDateTime.now())
+                    .setActiveTime(now)
                     .setShowStatus(true);
-            //首次激活可使用x天
-            if (!deviceInfo.getIsChargingX()) {
-                SysDictRedis sysDictRedis = SysDictUtils.get(DictEnum.DEVICE_CHARGING.getKey(), DictSonEnum.DEVICE_CHARGING_X.getKey());
-                updateDeviceInfo.setIsChargingX(true)
-                        .setChargingX(Integer.valueOf(sysDictRedis.getValue()));
-            }
             deviceInfoService.updateById(updateDeviceInfo);
-            //添加设备计费
-            DeviceCharging deviceCharging = deviceChargingService.getById(deviceInfo.getDeviceId());
+            //首次激活可试用x天
+            DeviceCharging deviceCharging = deviceChargingService.getById(active.getDeviceId());
             if (deviceCharging == null) {
-                LocalDateTime now = LocalDateTime.now();
+                SysDictRedis sysDictRedis = SysDictUtils.get(DictEnum.DEVICE_CHARGING.getKey(), DictSonEnum.DEVICE_CHARGING_X.getKey());
                 deviceChargingService.save(new DeviceCharging()
-                        .setDeviceId(deviceInfo.getDeviceId())
-                        .setDeviceType(deviceInfo.getDeviceType())
+                        .setDeviceId(active.getDeviceId())
+                        .setChargingX(Integer.valueOf(sysDictRedis.getValue()))
                         .setTimeout(now)
                         .setCreateTime(now)
-                        .setUpdateTime(now)
                 );
             }
             return R.ok();

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

@@ -30,20 +30,11 @@ public class DeviceCharging implements Serializable {
     @ApiModelProperty(value = "设备id")
     private Long deviceId;
 
-    @ApiModelProperty(value = "设备类型")
-    private Integer deviceType;
-
-    @ApiModelProperty(value = "续费金额")
-    private Integer chargingMoney;
-
     @ApiModelProperty(value = "累计续费金额")
     private Integer chargingSumMoney;
 
-    @ApiModelProperty(value = "续费方式")
-    private Integer chargingType;
-
-    @ApiModelProperty(value = "状态")
-    private Boolean status;
+    @ApiModelProperty(value = "试用剩余天")
+    private Integer chargingX;
 
     @ApiModelProperty(value = "过期时间")
     private LocalDateTime timeout;
@@ -51,8 +42,4 @@ public class DeviceCharging implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
 
-    @ApiModelProperty(value = "更新时间")
-    private LocalDateTime updateTime;
-
-
 }

+ 8 - 19
device-api-service/src/main/java/com/xy/entity/DeviceChargingHistory.java

@@ -1,15 +1,15 @@
 package com.xy.entity;
 
-import java.time.LocalDateTime;
-import java.io.Serializable;
-
-import com.baomidou.mybatisplus.annotation.TableId;
+import com.xy.base.BaseEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 设备计费历史表
@@ -21,35 +21,24 @@ import lombok.experimental.Accessors;
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
-@ApiModel(value="DeviceChargingHistory对象", description="设备计费历史表")
-public class DeviceChargingHistory implements Serializable {
+@ApiModel(value = "DeviceChargingHistory对象", description = "设备计费历史表")
+public class DeviceChargingHistory extends BaseEntity<DeviceChargingHistory> implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @TableId
-    @ApiModelProperty(value = "id")
-    private Long id;
-
     @ApiModelProperty(value = "设备id")
     private Long deviceId;
 
-    @ApiModelProperty(value = "设备类型")
-    private Integer deviceType;
-
     @ApiModelProperty(value = "续费金额")
     private Integer chargingMoney;
 
     @ApiModelProperty(value = "续费方式")
     private Integer chargingType;
 
-    @ApiModelProperty(value = "状态")
-    private Boolean status;
-
-    @ApiModelProperty(value = "过期时间")
-    private LocalDateTime timeout;
+    @ApiModelProperty(value = "续费有效期")
+    private LocalDateTime chargingDateTime;
 
     @ApiModelProperty(value = "创建时间")
     private LocalDateTime createTime;
 
-
 }

+ 0 - 10
device-api-service/src/main/java/com/xy/entity/DeviceInfo.java

@@ -111,16 +111,6 @@ public class DeviceInfo {
      */
     private Integer faultLevel;
 
-    /**
-     * 是否已使用计费x
-     */
-    private Boolean isChargingX;
-
-    /**
-     * 计费x剩余天
-     */
-    private Integer chargingX;
-
     /**
      * 创建时间
      */

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

@@ -13,7 +13,7 @@ import com.xy.entity.DeviceCharging;
 import com.xy.entity.DeviceChargingHistory;
 import com.xy.entity.DeviceInfo;
 import com.xy.entity.SysDictRedis;
-import com.xy.mapper.DeviceInfoMapper;
+import com.xy.mapper.DeviceChargingMapper;
 import com.xy.service.DeviceChargingHistoryServiceImpl;
 import com.xy.service.DeviceChargingServiceImpl;
 import com.xy.service.DeviceInfoServiceImpl;
@@ -46,7 +46,7 @@ public class DeviceChargingJob {
 
     private MercAccountService mercAccountService;
 
-    private DeviceInfoMapper deviceInfoMapper;
+    private DeviceChargingMapper deviceChargingMapper;
 
     /**
      * 扣除设备服务费试用天数
@@ -55,7 +55,7 @@ public class DeviceChargingJob {
      */
     @XxlJob("deviceChargingX")
     public ReturnT<String> deviceChargingX() {
-        deviceInfoMapper.updateChargingX(LocalDateTime.now());
+        deviceChargingMapper.updateChargingX();
         log.info("设备试用时间扣除完成~");
         return ReturnT.SUCCESS;
     }
@@ -108,7 +108,6 @@ public class DeviceChargingJob {
         Integer y = Integer.valueOf(sysDictRedisY.getValue());
         //开始计费
         deviceChargingsJMaps.forEach((deviceId, deviceCharging) -> {
-            deviceCharging.setUpdateTime(now);
             //发起扣款
             DeviceInfo deviceInfo = deviceInfosJMaps.get(deviceId);
             if (deviceInfo.getMercId() == -1) {
@@ -124,27 +123,22 @@ public class DeviceChargingJob {
             //扣款成功
             if (r.getCode() == R.Enum.SUCCESS.getCode()) {
                 LocalDateTime newTimeOut = DataTime.toLocal(DataTime.getStringAround(1, 0, 0, 0, 0, 0, DataTime.toString(deviceCharging.getTimeout())));
-                deviceCharging.setChargingMoney(balance)
-                        .setChargingSumMoney(deviceCharging.getChargingSumMoney() + balance)
-                        .setChargingType(DictSonEnum.DEVICE_CHARGING_100.getKeyInt())
-                        .setStatus(true)
+                deviceCharging.setChargingSumMoney(deviceCharging.getChargingSumMoney() + balance)
                         .setTimeout(newTimeOut);
                 DeviceChargingHistory deviceChargingHistory = new DeviceChargingHistory()
+                        .createId()
                         .setDeviceId(deviceId)
-                        .setDeviceType(deviceCharging.getDeviceType())
                         .setChargingMoney(balance)
                         .setChargingType(DictSonEnum.DEVICE_CHARGING_100.getKeyInt())
-                        .setStatus(true)
-                        .setCreateTime(now)
-                        .setTimeout(newTimeOut);
+                        .setChargingDateTime(newTimeOut)
+                        .setCreateTime(now);
                 deviceChargingHistories.add(deviceChargingHistory);
             }
             //扣款失败
             if (r.getCode() == R.Enum.FAIL.getCode()) {
-                deviceCharging.setStatus(false);
                 //当前时间 - 过期时间 > y && 试用期 <= 0 则冻结设备
                 long day = DataTime.diff(now, deviceCharging.getTimeout(), "d");
-                if (day > y && deviceInfo.getChargingX() <= 0) {
+                if (day > y && deviceCharging.getChargingX() <= 0) {
                     DeviceInfoDto.Update update = new DeviceInfoDto.Update()
                             .setDeviceId(deviceId);
                     update.setFreezeStatus(2);

+ 9 - 1
device-api-service/src/main/java/com/xy/mapper/DeviceChargingMapper.java

@@ -1,7 +1,8 @@
 package com.xy.mapper;
 
-import com.xy.entity.DeviceCharging;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xy.entity.DeviceCharging;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * <p>
@@ -13,4 +14,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface DeviceChargingMapper extends BaseMapper<DeviceCharging> {
 
+    /**
+     * 扣除设备服务费试用天数
+     *
+     * @return
+     */
+    @Select("update device_charging set charging_x = charging_x - 1 where charging_x > 0")
+    int updateChargingX();
 }

+ 0 - 10
device-api-service/src/main/java/com/xy/mapper/DeviceInfoMapper.java

@@ -6,9 +6,7 @@ import com.xy.dto.DeviceInfoDto;
 import com.xy.entity.DeviceInfo;
 import com.xy.mapper.entity.DeviceInfoQueryPage;
 import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
 
-import java.time.LocalDateTime;
 import java.util.List;
 
 /**
@@ -38,12 +36,4 @@ public interface DeviceInfoMapper extends BaseMapper<DeviceInfo> {
      */
     List<DeviceInfoDto.MercHomeCountVO> merHomeCountList(@Param("query") DeviceInfoDto.MercHomeQueryDTO queryDTO);
 
-    /**
-     * 扣除设备服务费试用天数
-     *
-     * @param updateTime
-     * @return
-     */
-    @Select("update device_info set charging_x = charging_x - 1, update_time = #{updateTime} where is_charging_x = true and charging_x > 0")
-    int updateChargingX(@Param("updateTime") LocalDateTime updateTime);
 }

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

@@ -36,20 +36,11 @@ public class DeviceChargingDto {
         @ApiModelProperty(value = "设备id")
         private Long deviceId;
 
-        @ApiModelProperty(value = "设备类型")
-        private Integer deviceType;
-
-        @ApiModelProperty(value = "续费金额")
-        private Integer chargingMoney;
-
         @ApiModelProperty(value = "累计续费金额")
         private Integer chargingSumMoney;
 
-        @ApiModelProperty(value = "续费方式")
-        private Integer chargingType;
-
-        @ApiModelProperty(value = "状态")
-        private Boolean status;
+        @ApiModelProperty(value = "试用剩余天")
+        private Integer chargingX;
 
         @ApiModelProperty(value = "过期时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -59,11 +50,6 @@ public class DeviceChargingDto {
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;
 
-        @ApiModelProperty(value = "更新时间")
-        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-        private LocalDateTime updateTime;
-
-
     }
 
 }

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

@@ -1,6 +1,5 @@
 package com.xy.dto;
 
-import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
@@ -27,27 +26,18 @@ public class DeviceChargingHistoryDto {
         @ApiModelProperty(value = "设备id")
         private Long deviceId;
 
-        @ApiModelProperty(value = "设备类型")
-        private Integer deviceType;
-
         @ApiModelProperty(value = "续费金额")
         private Integer chargingMoney;
 
         @ApiModelProperty(value = "续费方式")
         private Integer chargingType;
 
-        @ApiModelProperty(value = "状态")
-        private Boolean status;
-
-        @ApiModelProperty(value = "过期时间")
-        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-        private LocalDateTime timeout;
+        @ApiModelProperty(value = "续费有效期")
+        private LocalDateTime chargingDateTime;
 
         @ApiModelProperty(value = "创建时间")
-        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;
 
-
     }
 
 }

+ 0 - 6
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -328,12 +328,6 @@ public class DeviceInfoDto {
         @ApiModelProperty("故障等级")
         private Integer faultLevel;
 
-        @ApiModelProperty("是否已使用计费x")
-        private Boolean isChargingX;
-
-        @ApiModelProperty("计费x剩余天")
-        private Integer chargingX;
-
         @ApiModelProperty("创建时间")
         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
         private LocalDateTime createTime;