删除设备前关闭订单

This commit is contained in:
墨大叔 2024-10-06 14:29:59 +08:00
parent c38bcae036
commit 6348f52646
2 changed files with 52 additions and 18 deletions
smart-switch-service/src/main/java/com/ruoyi/ss/device/service

View File

@ -1,9 +1,6 @@
package com.ruoyi.ss.device.service;
import com.ruoyi.ss.device.domain.Device;
import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceCountVO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.*;
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
@ -91,7 +88,7 @@ public interface DeviceService
/**
* 逻辑删除
*/
boolean logicDel(List<Long> deviceIds);
int logicDel(List<Long> deviceIds);
/**
* 通过型号id列表查询设备列表并分组
@ -350,4 +347,9 @@ public interface DeviceService
int setTime(DeviceVO device, LocalDateTime expireTime, boolean withIot, int tryCount);
int setWifi(DeviceWifiDTO dto);
/**
* 根据设备ID列表查询
*/
List<DeviceVO> selectByDeviceIds(List<Long> deviceIds);
}

View File

@ -13,7 +13,6 @@ 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.dashboard.vo.BillCountVo;
import com.ruoyi.ss.device.domain.Device;
import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceCountVO;
@ -287,16 +286,6 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(device == null, String.format("设备“%s”不存在请刷新后重试", deviceId));
}
// 拉取最新数据
this.pullDeviceInfo(deviceIds);
// 查询是否有未完成的订单
TransactionBillQuery query = new TransactionBillQuery();
query.setDeviceIds(deviceIds);
query.setIsFinished(false);
query.setType(TransactionBillType.RECHARGE.getType());
int billCount = transactionBillService.selectSimpleCount(query);
ServiceUtil.assertion(billCount > 0, "设备存在未完成订单,无法删除");
}
/**
@ -651,6 +640,13 @@ public class DeviceServiceImpl implements DeviceService
return 1;
}
@Override
public List<DeviceVO> selectByDeviceIds(List<Long> deviceIds) {
DeviceQuery query = new DeviceQuery();
query.setDeviceIds(deviceIds);
return this.selectSmDeviceList(query);
}
@Override
public boolean addTime(Long deviceId, long seconds, boolean withIot) {
@ -766,9 +762,45 @@ public class DeviceServiceImpl implements DeviceService
}
@Override
public boolean logicDel(List<Long> deviceIds) {
public int logicDel(List<Long> deviceIds) {
// 校验
this.validatePreLogicDelete(deviceIds);
return deviceMapper.logicDel(deviceIds) > 0;
// 拉取最新数据
this.pullDeviceInfo(deviceIds);
// 查询设备列表
List<DeviceVO> deviceList = this.selectByDeviceIds(deviceIds);
Integer result = transactionTemplate.execute(status -> {
// 关闭设备订单
for (Long deviceId : deviceIds) {
if (deviceId == null) {
continue;
}
DeviceVO device = deviceList.stream().filter(item -> Objects.equals(item.getDeviceId(), deviceId)).findFirst().orElse(null);
if (device == null) {
continue;
}
// 关闭设备未结束的订单
TransactionBillQuery query = new TransactionBillQuery();
query.setType(TransactionBillType.RECHARGE.getType());
query.setStatusList(TransactionBillStatus.canClose());
query.setDeviceId(deviceId);
query.setIsFinished(false);
List<TransactionBillVO> billList = transactionBillService.selectSmTransactionBillList(query);
int closeCount = transactionBillService.batchCloseBillByDevice(billList, false, device);
ServiceUtil.assertion(closeCount != billList.size(), "关闭订单失败:closeCount =" + closeCount);
}
int i = deviceMapper.logicDel(deviceIds);
ServiceUtil.assertion(i != deviceIds.size(), "删除设备失败,请刷新后重试");
return i;
});
return result == null ? 0 : result;
}
@Override