fix: 绑定解绑记录,新增接口。
This commit is contained in:
@@ -11,6 +11,7 @@ import com.intc.common.mybatis.core.page.PageQuery;
|
||||
import com.intc.common.mybatis.core.page.TableDataInfo;
|
||||
import com.intc.fishery.domain.AquUser;
|
||||
import com.intc.fishery.domain.Device;
|
||||
import com.intc.fishery.domain.DeviceBindRecord;
|
||||
import com.intc.fishery.domain.DeviceCorrectRecord;
|
||||
import com.intc.fishery.domain.DeviceSwitch;
|
||||
import com.intc.fishery.domain.LinkedCtrl;
|
||||
@@ -18,6 +19,7 @@ import com.intc.fishery.domain.Pond;
|
||||
import com.intc.fishery.domain.TimingCtrl;
|
||||
import com.intc.fishery.domain.bo.DeviceBo;
|
||||
import com.intc.fishery.domain.vo.DeviceVo;
|
||||
import com.intc.fishery.mapper.DeviceBindRecordMapper;
|
||||
import com.intc.fishery.mapper.DeviceCorrectRecordMapper;
|
||||
import com.intc.fishery.mapper.DeviceMapper;
|
||||
import com.intc.fishery.mapper.DeviceSwitchMapper;
|
||||
@@ -45,6 +47,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class DeviceServiceImpl implements IDeviceService {
|
||||
|
||||
private final DeviceMapper baseMapper;
|
||||
private final DeviceBindRecordMapper deviceBindRecordMapper;
|
||||
private final DeviceCorrectRecordMapper deviceCorrectRecordMapper;
|
||||
private final DeviceSwitchMapper deviceSwitchMapper;
|
||||
private final LinkedCtrlMapper linkedCtrlMapper;
|
||||
@@ -291,7 +294,33 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
.in(LinkedCtrl::getDeviceId, ids)
|
||||
);
|
||||
|
||||
// 8. 最后删除设备
|
||||
// 8. 查询要删除的设备信息,添加解绑记录
|
||||
List<Device> devicesToDelete = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<Device>()
|
||||
.in(Device::getId, ids)
|
||||
.select(Device::getId, Device::getUserId, Device::getIotId,
|
||||
Device::getDeviceType, Device::getSerialNum)
|
||||
);
|
||||
|
||||
// 为每个设备添加解绑记录
|
||||
for (Device device : devicesToDelete) {
|
||||
try {
|
||||
DeviceBindRecord unbindRecord = new DeviceBindRecord();
|
||||
unbindRecord.setUserId(device.getUserId());
|
||||
unbindRecord.setIsBind(0); // 0表示解绑
|
||||
unbindRecord.setIotId(device.getIotId());
|
||||
unbindRecord.setDeviceType(device.getDeviceType() != null ? Long.valueOf(device.getDeviceType()) : null);
|
||||
unbindRecord.setSerialNum(device.getSerialNum());
|
||||
deviceBindRecordMapper.insert(unbindRecord);
|
||||
log.info("添加设备解绑记录: deviceId={}, userId={}, serialNum={}",
|
||||
device.getId(), device.getUserId(), device.getSerialNum());
|
||||
} catch (Exception e) {
|
||||
log.error("添加设备解绑记录失败: deviceId={}, error={}", device.getId(), e.getMessage(), e);
|
||||
// 不影响删除流程,继续执行
|
||||
}
|
||||
}
|
||||
|
||||
// 9. 最后删除设备
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user