From 94edae17520c05ed638e23324a2fe478693287f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com>
Date: Fri, 12 Jul 2024 17:53:39 +0800
Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E7=BD=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/ruoyi/iot/enums/IotHttpStatus.java | 23 +++++
.../com/ruoyi/iot/service/IotService.java | 2 +-
.../com/ruoyi/iot/service/IotServiceImpl.java | 8 +-
.../com/ruoyi/ss/device/domain/SmDevice.java | 1 -
.../ruoyi/ss/device/mapper/SmDeviceMapper.xml | 7 +-
.../ss/device/service/DeviceValidator.java | 7 +-
.../ss/device/service/ISmDeviceService.java | 13 +--
.../service/impl/DeviceAssemblerImpl.java | 4 +-
.../service/impl/DeviceValidatorImpl.java | 12 ++-
.../service/impl/SmDeviceServiceImpl.java | 96 +++++++++----------
.../com/ruoyi/ss/suit/mapper/SuitMapper.java | 5 +
.../com/ruoyi/ss/suit/mapper/SuitMapper.xml | 6 ++
.../{ISuitService.java => SuitService.java} | 7 +-
.../ss/suit/service/impl/SuitServiceImpl.java | 12 ++-
.../suit/service/impl/SuitValidatorImpl.java | 4 +-
.../domain/TransactionBill.java | 7 +-
.../domain/TransactionBillQuery.java | 3 +
.../mapper/TransactionBillMapper.java | 1 +
.../mapper/TransactionBillMapper.xml | 8 ++
.../service/TransactionBillService.java | 5 +
.../impl/TransactionBillServiceImpl.java | 34 ++++++-
.../impl/TransactionBillValidatorImpl.java | 4 +-
.../com/ruoyi/ss/user/mapper/SmUserMapper.xml | 1 -
.../controller/app/AppDeviceController.java | 11 ++-
.../web/controller/app/AppSuitController.java | 5 +-
.../web/controller/ss/SmUserController.java | 1 +
.../web/controller/ss/SuitController.java | 4 +-
27 files changed, 199 insertions(+), 92 deletions(-)
create mode 100644 smart-switch-service/src/main/java/com/ruoyi/iot/enums/IotHttpStatus.java
rename smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/{ISuitService.java => SuitService.java} (94%)
diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/enums/IotHttpStatus.java b/smart-switch-service/src/main/java/com/ruoyi/iot/enums/IotHttpStatus.java
new file mode 100644
index 00000000..ad5d8a4c
--- /dev/null
+++ b/smart-switch-service/src/main/java/com/ruoyi/iot/enums/IotHttpStatus.java
@@ -0,0 +1,23 @@
+package com.ruoyi.iot.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author wjh
+ * 2024/7/11
+ */
+@Getter
+@AllArgsConstructor
+public enum IotHttpStatus {
+
+ SUCCESS(0, "成功"),
+ DEVICE_EXIST(10406, "设备已存在");
+
+ private final Integer code;
+ private final String msg;
+
+ public boolean equalCode(int code) {
+ return this.code == code;
+ }
+}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java
index b313e563..b9ce9190 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java
@@ -99,5 +99,5 @@ public interface IotService {
/**
* 注册设备
*/
- boolean create(String mac);
+ int create(String mac);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java
index efc4bb1a..56aff563 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java
@@ -234,7 +234,7 @@ public class IotServiceImpl implements IotService {
}
@Override
- public boolean create(String mac) {
+ public int create(String mac) {
String sendUrl = iotHost + IotConstants.CREATE_DEVICE;
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
createDeviceVo.setDevice_name(mac);
@@ -242,12 +242,10 @@ public class IotServiceImpl implements IotService {
String result = HttpUtils.sendPostWithToken(sendUrl, JSON.toJSONString(createDeviceVo), Token.getToken());
if (!StringUtils.hasText(result)) {
log.error("与OneNet通信异常");
- return false;
+ return HttpStatus.NOT_FOUND;
}
JSONObject paramsObj = JSON.parseObject(result);
- Integer code = paramsObj.getInteger("code");
- //记录命令
- return HttpStatus.IOT_SUCCESS.equals(code);
+ return paramsObj.getInteger("code");
}
// 发送MQTT命令
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/SmDevice.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/SmDevice.java
index 0e78ee2e..f4d9cb63 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/SmDevice.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/SmDevice.java
@@ -51,7 +51,6 @@ public class SmDevice extends BaseEntity
@Excel(name = "设备名称")
@ApiModelProperty("设备名称")
@JsonView({DeviceView.SuitList.class, JsonViewProfile.App.class})
- @NotNull(message = "设备名称不允许为空", groups = {ValidGroup.Create.class, ValidGroup.Update.class})
private String deviceName;
/** 型号id */
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/SmDeviceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/SmDeviceMapper.xml
index ac6764c5..73ff1746 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/SmDeviceMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/SmDeviceMapper.xml
@@ -341,14 +341,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update sm_device
set store_id = #{storeId},
- user_id = #{userId}
+ user_id = #{userId},
+ activation_time = now()
where device_id = #{deviceId} and user_id is null
update sm_device
set store_id = null,
- user_id = null
+ user_id = null,
+ device_name = '未命名',
+ activation_time = null
where device_id = #{deviceId}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceValidator.java
index 50600099..b656c25a 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceValidator.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceValidator.java
@@ -41,5 +41,10 @@ public interface DeviceValidator {
/**
* 判断SN是否重复
*/
- boolean isRepeat(Long deviceId, String sn);
+ boolean isRepeatSn(Long deviceId, String sn);
+
+ /**
+ * 判断MAC是否重复
+ */
+ boolean isRepeatMac(Long deviceId, String mac);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/ISmDeviceService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/ISmDeviceService.java
index 97b7972a..7f20e177 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/ISmDeviceService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/ISmDeviceService.java
@@ -122,9 +122,10 @@ public interface ISmDeviceService
/**
* 商户解绑设备
+ *
* @param deviceId 设备id
*/
- boolean unbindStore(Long deviceId);
+ int unbind(Long deviceId);
/**
* 通过mac查询设备
@@ -176,11 +177,6 @@ public interface ISmDeviceService
*/
SmDeviceVO selectByDeviceNo(String deviceNo);
- /**
- * 初始设备录入
- * @param smDevice
- */
- int addInitDevice(SmDevice smDevice);
/**
* 设备绑定SN码
@@ -232,4 +228,9 @@ public interface ISmDeviceService
* 查询一个
*/
SmDeviceVO selectOne(SmDeviceQuery query);
+
+ /**
+ * 获取当前用户正在使用中的设备
+ */
+ List selectUsingDevice(Long userId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java
index d2c9771a..082537de 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java
@@ -15,7 +15,7 @@ import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.service.IStoreService;
import com.ruoyi.ss.suit.domain.SuitQuery;
import com.ruoyi.ss.suit.domain.SuitVo;
-import com.ruoyi.ss.suit.service.ISuitService;
+import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
@@ -41,7 +41,7 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
private ISmDeviceTenantService deviceTenantService;
@Autowired
- private ISuitService suitService;
+ private SuitService suitService;
@Autowired
private IStoreService storeService;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java
index 6077a857..ec5284d2 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java
@@ -11,6 +11,7 @@ import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.device.service.ISmDeviceService;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.user.service.UserValidator;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -119,11 +120,20 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
}
@Override
- public boolean isRepeat(Long deviceId, String sn) {
+ public boolean isRepeatSn(Long deviceId, String sn) {
if (StringUtil.isBlank(sn)) {
return false;
}
SmDeviceVO device = deviceService.selectByDeviceNo(sn);
return device != null && !Objects.equals(deviceId, device.getDeviceId());
}
+
+ @Override
+ public boolean isRepeatMac(Long deviceId, String mac) {
+ if (StringUtils.isBlank(mac)) {
+ return false;
+ }
+ SmDeviceVO device = deviceService.selectByMac(mac);
+ return device != null && !Objects.equals(deviceId, device.getDeviceId());
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java
index 40026635..bfb29003 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/SmDeviceServiceImpl.java
@@ -7,6 +7,7 @@ import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.iot.domain.IotDeviceInfo;
import com.ruoyi.iot.domain.response.CommandResponse;
+import com.ruoyi.iot.enums.IotHttpStatus;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.ss.device.domain.SmDevice;
import com.ruoyi.ss.device.domain.SmDeviceCountVO;
@@ -21,13 +22,13 @@ import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.device.service.ISmDeviceService;
import com.ruoyi.ss.deviceBindRecord.service.ISmDeviceBindRecordService;
-import com.ruoyi.ss.model.domain.SmModelVo;
-import com.ruoyi.ss.model.service.ModelService;
import com.ruoyi.ss.record.time.service.IRecordTimeService;
import com.ruoyi.ss.record.time.service.RecordTimeConverter;
-import com.ruoyi.ss.resetRecord.service.ISmResetRecordService;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.service.IStoreService;
+import com.ruoyi.ss.suit.service.SuitService;
+import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
+import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.ss.user.domain.SmUserVo;
import com.ruoyi.ss.user.service.ISmUserService;
import lombok.SneakyThrows;
@@ -84,15 +85,18 @@ public class SmDeviceServiceImpl implements ISmDeviceService
@Autowired
private RecordTimeConverter recordTimeConverter;
- @Autowired
- private ModelService smModelService;
-
@Autowired
private ISmUserService userService;
@Autowired
private DeviceValidator deviceValidator;
+ @Autowired
+ private SuitService suitService;
+
+ @Autowired
+ private TransactionBillService transactionBillService;
+
/**
* 查询设备
*
@@ -119,16 +123,18 @@ public class SmDeviceServiceImpl implements ISmDeviceService
/**
* 新增设备
- * F
* @param data 设备
* @return 结果
*/
@Override
- public int insertSmDevice(SmDevice data)
- {
- if (StringUtils.hasText(data.getDeviceNo())) {
- ServiceUtil.assertion(deviceValidator.isRepeat(data.getDeviceId(), data.getDeviceNo()), "SN重复");
- }
+ public int insertSmDevice(SmDevice data) {
+ ServiceUtil.assertion(deviceValidator.isRepeatMac(data.getDeviceId(), data.getMac()), "MAC重复");
+ ServiceUtil.assertion(deviceValidator.isRepeatSn(data.getDeviceId(), data.getDeviceNo()), "SN重复");
+
+ // 创建OneNet设备
+ int code = iotService.create(data.getMac());
+ ServiceUtil.assertion(!IotHttpStatus.SUCCESS.equalCode(code) && !IotHttpStatus.DEVICE_EXIST.equalCode(code), "设备注册失败");
+
data.setCreateTime(DateUtils.getNowDate());
data.setStatus(DeviceStatus.NORMAL.getStatus());
return smDeviceMapper.insertSmDevice(data);
@@ -145,7 +151,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
public int updateSmDevice(SmDevice data)
{
if (StringUtils.hasText(data.getDeviceNo())) {
- ServiceUtil.assertion(deviceValidator.isRepeat(data.getDeviceId(), data.getDeviceNo()), "SN重复");
+ ServiceUtil.assertion(deviceValidator.isRepeatSn(data.getDeviceId(), data.getDeviceNo()), "SN重复");
}
// 修改数据库
@@ -255,7 +261,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
device.setDeviceName("未命名");
device.setMac(dto.getMac());
device.setDeviceNo(dto.getSn());
- return this.addInitDevice(device);
+ return this.insertSmDevice(device);
}
@Override
@@ -268,6 +274,16 @@ public class SmDeviceServiceImpl implements ISmDeviceService
return smDeviceMapper.selectOne(query);
}
+ @Override
+ public List selectUsingDevice(Long userId) {
+ // 查询正在使用中的订单
+ List usingBills = transactionBillService.selectUsingBill(userId);
+ List deviceIds = usingBills.stream().map(TransactionBillVo::getDeviceId).distinct().collect(Collectors.toList());
+ // 查询设备列表
+ return this.selectListByIds(deviceIds);
+ }
+
+
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean addTime(Long deviceId, BigDecimal num, boolean withIot) {
@@ -645,7 +661,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
*/
@Override
public List selectListByIds(List ids) {
- if (CollectionUtils.isEmpty(ids)) {
+ if (CollectionUtils.isEmptyElement(ids)) {
return Collections.emptyList();
}
SmDeviceQuery dto = new SmDeviceQuery();
@@ -716,48 +732,24 @@ public class SmDeviceServiceImpl implements ISmDeviceService
return smDeviceMapper.selectByDeviceNo(deviceNo);
}
- /**
- * 初始设备录入
- *
- * @param smDevice 设备信息
- */
- @Override
- public int addInitDevice(SmDevice smDevice) {
- if (smDevice == null) {
- return 0;
- }
-
- // 查询设备是否存在,存在则忽略
- SmDeviceVO device = selectByMac(smDevice.getMac());
- ServiceUtil.assertion(device != null, "该设备Mac已存在,无需重复录入");
-
- device = selectByDeviceNo(smDevice.getDeviceNo());
- ServiceUtil.assertion(device != null, "该设备SN已存在,无需重复录入");
-
- Integer result = transactionTemplate.execute(status -> {
- int i = this.insertSmDevice(smDevice); // 添加设备
- ServiceUtil.assertion(i != 1, "添加设备失败");
-
- // 创建OneNet设备
- boolean create = iotService.create(smDevice.getMac());
- ServiceUtil.assertion(!create, "创建OneNet设备失败");
-
- return i;
- });
-
- return result == null ? 0 : result;
- }
-
@Override
@Transactional
- public boolean unbindStore(Long deviceId) {
+ public int unbind(Long deviceId) {
SmDeviceVO device = smDeviceMapper.selectSmDeviceByDeviceId(deviceId);
ServiceUtil.assertion(device == null || device.getDeleted(), "设备不存在");
ServiceUtil.assertion(DeviceStatus.USING.getStatus().equals(device.getStatus()), "设备正在使用中,无法解除绑定");
- int updateCount = smDeviceMapper.unbindStore(deviceId);
- ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试");
- return true;
+ Integer result = transactionTemplate.execute(status -> {
+ int updateCount = smDeviceMapper.unbindStore(deviceId);
+ ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试");
+
+ // 删除套餐
+ suitService.logicDelByDeviceId(deviceId);
+
+ return updateCount;
+ });
+
+ return result == null ? 0 : result;
}
/**
@@ -769,7 +761,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
@Override
public int bindSn(Long deviceId, String sn) {
Integer result = transactionTemplate.execute(status -> {
- ServiceUtil.assertion(deviceValidator.isRepeat(deviceId, sn), "SN重复");
+ ServiceUtil.assertion(deviceValidator.isRepeatSn(deviceId, sn), "SN重复");
int i = smDeviceMapper.bindSn(deviceId, sn);
ServiceUtil.assertion(i != 1, "设备SN已发生变化,请刷新后重试");
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.java
index 3c94d0d6..7df2c8f4 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.java
@@ -75,4 +75,9 @@ public interface SuitMapper
* @return
*/
int selectCount(SuitQuery query);
+
+ /**
+ * 根据设备ID删除套餐
+ */
+ int logicDelByDeviceId(Long deviceId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.xml
index 9b13c9ee..3cf6660b 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/mapper/SuitMapper.xml
@@ -120,6 +120,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+ update sm_suit
+ set deleted = true
+ where device_id = #{deviceId}
+
+
delete from sm_suit where suit_id = #{suitId}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/ISuitService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/SuitService.java
similarity index 94%
rename from smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/ISuitService.java
rename to smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/SuitService.java
index 8e06ea88..2c6b3672 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/ISuitService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/SuitService.java
@@ -14,7 +14,7 @@ import java.util.function.Function;
* @author ruoyi
* @date 2024-04-25
*/
-public interface ISuitService
+public interface SuitService
{
/**
* 查询套餐
@@ -98,4 +98,9 @@ public interface ISuitService
* @return
*/
int selectCount(SuitQuery query);
+
+ /**
+ * 根据设备ID删除套餐
+ */
+ int logicDelByDeviceId(Long deviceId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitServiceImpl.java
index 901b11be..c6b346a8 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitServiceImpl.java
@@ -6,7 +6,7 @@ import com.ruoyi.ss.suit.domain.Suit;
import com.ruoyi.ss.suit.domain.SuitQuery;
import com.ruoyi.ss.suit.domain.SuitVo;
import com.ruoyi.ss.suit.mapper.SuitMapper;
-import com.ruoyi.ss.suit.service.ISuitService;
+import com.ruoyi.ss.suit.service.SuitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -23,7 +23,7 @@ import java.util.stream.Collectors;
* @date 2024-04-25
*/
@Service
-public class SuitServiceImpl implements ISuitService
+public class SuitServiceImpl implements SuitService
{
@Autowired
private SuitMapper suitMapper;
@@ -168,4 +168,12 @@ public class SuitServiceImpl implements ISuitService
public int selectCount(SuitQuery query) {
return suitMapper.selectCount(query);
}
+
+ @Override
+ public int logicDelByDeviceId(Long deviceId) {
+ if (deviceId == null) {
+ return 0;
+ }
+ return suitMapper.logicDelByDeviceId(deviceId);
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitValidatorImpl.java
index 22b8ff81..97158437 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitValidatorImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/suit/service/impl/SuitValidatorImpl.java
@@ -7,7 +7,7 @@ import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.suit.domain.SuitBO;
import com.ruoyi.ss.suit.domain.SuitQuery;
-import com.ruoyi.ss.suit.service.ISuitService;
+import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.suit.service.SuitValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -28,7 +28,7 @@ public class SuitValidatorImpl extends BaseValidator implements SuitValidator {
private DeviceValidator deviceValidator;
@Autowired
- private ISuitService suitService;
+ private SuitService suitService;
@Override
public ValidateResult preLogicDel(List suitIds) {
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java
index 75041241..c52017be 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java
@@ -12,6 +12,7 @@ import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@@ -129,13 +130,13 @@ public class TransactionBill extends BaseEntity
private BigDecimal suitTime;
@ApiModelProperty("套餐开始使用时间")
- private Integer suitStartTime;
+ private LocalDateTime suitStartTime;
@ApiModelProperty("套餐结束使用时间")
- private Integer suitEndTime;
+ private LocalDateTime suitEndTime;
@ApiModelProperty("套餐到期时间")
- private Integer suitExpireTime;
+ private LocalDateTime suitExpireTime;
@ApiModelProperty("店铺ID")
@JsonView(JsonViewProfile.App.class)
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java
index 07d9906a..e3d17c8c 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBillQuery.java
@@ -73,4 +73,7 @@ public class TransactionBillQuery extends TransactionBill {
@ApiModelProperty("设备ID列表")
private List deviceIds;
+
+ @ApiModelProperty("是否使用中")
+ private Boolean using;
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java
index 1b1365fb..dd16ab1d 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java
@@ -7,6 +7,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml
index a66b6621..4b3cab02 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml
@@ -73,6 +73,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and stb.device_recharge_status = #{query.deviceRechargeStatus}
and stb.suit_id = #{query.suitId}
and stb.store_id = #{query.storeId}
+
+
+ and now() >= stb.suit_start_time and now() <= stb.suit_end_time and now() <= stb.suit_expire_time
+
+
+ and ( now() <= stb.suit_start_time or now() >= stb.suit_end_time or now() >= stb.suit_expire_time)
+
+
and stb.bill_id in
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java
index 130698ea..a3ad29ae 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java
@@ -254,4 +254,9 @@ public interface TransactionBillService
* @param refundServiceAmount 退款手续费
*/
int addRefundAmount(Long billId, BigDecimal refundAmount, BigDecimal refundMchAmount, BigDecimal refundServiceAmount);
+
+ /**
+ * 查询用户正在使用中的订单
+ */
+ List selectUsingBill(Long userId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
index 5bd32a9d..64515094 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
@@ -23,7 +23,7 @@ import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.service.IStoreService;
import com.ruoyi.ss.suit.domain.SuitVo;
-import com.ruoyi.ss.suit.service.ISuitService;
+import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillVo;
@@ -53,6 +53,7 @@ import org.springframework.transaction.support.TransactionTemplate;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -105,7 +106,7 @@ public class TransactionBillServiceImpl implements TransactionBillService {
private IStoreService storeService;
@Autowired
- private ISuitService suitService;
+ private SuitService suitService;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
@@ -571,11 +572,26 @@ public class TransactionBillServiceImpl implements TransactionBillService {
// 修改设备充值状态:成功
if (success) {
transactionBillMapper.updateDeviceRechargeStatus(bill.getBillId(), TransactionBillDeviceRechargeStatus.SUCCESS.getStatus());
+ SmDeviceVO device = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
+ this.updateSuitTimeAfterDevice(billId, device.getExpireTime());
}
return true;
}
+ /**
+ * 在设备充值成功后,更新套餐时间
+ * 开始时间 = 设备过期时间 - 套餐时间,过期时间 = 设备过期时间
+ */
+ private int updateSuitTimeAfterDevice(Long billId, LocalDateTime deviceExpireTime) {
+ TransactionBill bill = new TransactionBill();
+ bill.setBillId(billId);
+ bill.setSuitStartTime(deviceExpireTime.plusMinutes(-bill.getSuitTime().longValue()));
+ bill.setSuitEndTime(deviceExpireTime);
+ bill.setSuitExpireTime(deviceExpireTime);
+ return transactionBillMapper.updateSmTransactionBill(bill);
+ }
+
/**
* 处理设备充值失败
*/
@@ -618,7 +634,7 @@ public class TransactionBillServiceImpl implements TransactionBillService {
TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillNo(billNo);
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "充值订单不存在");
- // 修改订单状态为成功
+ // 修改订单状态
int updateCount = transactionBillMapper.rechargeSuccess(bill.getBillId(), payTime);
ServiceUtil.assertion(updateCount != 1, "修改订单状态失败,请刷新后重试");
@@ -820,6 +836,10 @@ public class TransactionBillServiceImpl implements TransactionBillService {
boolean result = transactionBillMapper.bluetoothRechargeSuccess(billNo) == 1;
ServiceUtil.assertion(!result, "蓝牙充值回调失败");
+ // 更新套餐时间
+ SmDeviceVO afterDevice = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
+ this.updateSuitTimeAfterDevice(bill.getBillId(), afterDevice.getExpireTime());
+
boolean addTime = deviceService.addTime(bill.getDeviceId(), bill.getSuitTime(), false);
ServiceUtil.assertion(!addTime, "修改剩余时间失败");
@@ -926,4 +946,12 @@ public class TransactionBillServiceImpl implements TransactionBillService {
}
return transactionBillMapper.addRefundAmount(billId, refundAmount, refundMchAmount, refundServiceAmount);
}
+
+ @Override
+ public List selectUsingBill(Long userId) {
+ TransactionBillQuery query = new TransactionBillQuery();
+ query.setUsing(true);
+ query.setStatus(TransactionBillStatus.SUCCESS.getStatus());
+ return this.selectSmTransactionBillList(query);
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java
index b7f8e47d..35529227 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillValidatorImpl.java
@@ -10,7 +10,7 @@ import com.ruoyi.ss.device.service.ISmDeviceService;
import com.ruoyi.ss.model.domain.enums.ModelTag;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.suit.domain.SuitVo;
-import com.ruoyi.ss.suit.service.ISuitService;
+import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.ss.transactionBill.service.TransactionBillValidator;
@@ -39,7 +39,7 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans
private ISmChannelService channelService;
@Autowired
- private ISuitService suitService;
+ private SuitService suitService;
@Autowired
private StoreValidator storeValidator;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
index f5e23ef4..bc1e22b0 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
@@ -107,7 +107,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and su.del_flag = '0'
- order by su.create_time desc