fix: 绑定解绑数据时,没有添加操作记录,bug修复。
This commit is contained in:
@@ -53,6 +53,9 @@ import com.intc.fishery.constant.DefineDeviceErrorCode;
|
|||||||
import com.intc.fishery.mapper.TimingCtrlMapper;
|
import com.intc.fishery.mapper.TimingCtrlMapper;
|
||||||
import com.intc.fishery.domain.TimingCtrl;
|
import com.intc.fishery.domain.TimingCtrl;
|
||||||
import com.intc.fishery.utils.MessageOpRecordUtil;
|
import com.intc.fishery.utils.MessageOpRecordUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import com.intc.fishery.service.IMessageWarnService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 塘口管理
|
* 塘口管理
|
||||||
@@ -60,6 +63,7 @@ import com.intc.fishery.utils.MessageOpRecordUtil;
|
|||||||
* @author intc
|
* @author intc
|
||||||
* @date 2025-10-11
|
* @date 2025-10-11
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Validated
|
@Validated
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@@ -76,6 +80,12 @@ public class PondController extends BaseController {
|
|||||||
private final DeviceErrorCodeMapper deviceErrorCodeMapper;
|
private final DeviceErrorCodeMapper deviceErrorCodeMapper;
|
||||||
private final TimingCtrlMapper timingCtrlMapper;
|
private final TimingCtrlMapper timingCtrlMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警消息服务
|
||||||
|
*/
|
||||||
|
@Autowired(required = false)
|
||||||
|
private IMessageWarnService messageWarnService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询塘口管理列表
|
* 查询塘口管理列表
|
||||||
*/
|
*/
|
||||||
@@ -441,6 +451,7 @@ public class PondController extends BaseController {
|
|||||||
@PutMapping("/bind/device")
|
@PutMapping("/bind/device")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R<Void> selectDeviceOrSwitch(
|
public R<Void> selectDeviceOrSwitch(
|
||||||
|
@RequestParam("rootUserId") Long rootUserId,
|
||||||
@Validated @RequestBody PondSelectDeviceOrSwitchBo request) {
|
@Validated @RequestBody PondSelectDeviceOrSwitchBo request) {
|
||||||
// 查询塘口信息并验证权限
|
// 查询塘口信息并验证权限
|
||||||
Pond pond = pondMapper.selectById(request.getPondId());
|
Pond pond = pondMapper.selectById(request.getPondId());
|
||||||
@@ -576,17 +587,114 @@ public class PondController extends BaseController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 清除设备报警数据(类似C#中的EventHelper.RemoveDeviceWarnWaitAndNotice)
|
// 5. 清除设备报警数据(类似C#中的EventHelper.RemoveDeviceWarnWaitAndNotice)
|
||||||
// for (Long deviceId : hashDeviceRemove) {
|
// 清除从塘口移除的设备的告警消息记录
|
||||||
// // 清除该设备的报警等待和通知数据
|
if (messageWarnService != null && !hashDeviceRemove.isEmpty()) {
|
||||||
// }
|
for (Long deviceId : hashDeviceRemove) {
|
||||||
|
try {
|
||||||
|
// 查询该设备的所有告警消息
|
||||||
|
com.intc.fishery.domain.bo.MessageWarnBo query = new com.intc.fishery.domain.bo.MessageWarnBo();
|
||||||
|
query.setDeviceId(deviceId);
|
||||||
|
List<com.intc.fishery.domain.vo.MessageWarnVo> messageWarns = messageWarnService.queryList(query);
|
||||||
|
|
||||||
|
if (!messageWarns.isEmpty()) {
|
||||||
|
List<Long> messageWarnIds = messageWarns.stream()
|
||||||
|
.map(com.intc.fishery.domain.vo.MessageWarnVo::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 删除告警消息
|
||||||
|
messageWarnService.deleteWithValidByIds(messageWarnIds, false);
|
||||||
|
log.info("清除设备 {} 的 {} 条告警消息", deviceId, messageWarnIds.size());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 清除报警数据失败不应影响主流程
|
||||||
|
log.warn("清除设备 {} 的告警消息失败: {}", deviceId, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 记录操作日志
|
||||||
|
Long userId = LoginHelper.getUserId();
|
||||||
|
|
||||||
// 记录操作日志
|
|
||||||
// 记录设备添加到塘口的操作
|
// 记录设备添加到塘口的操作
|
||||||
|
for (Device device : dictDeviceAdd.values()) {
|
||||||
|
if (device.getPondId() != null && device.getPondId() > 0) {
|
||||||
|
// 转移到塘口
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"设备操作",
|
||||||
|
String.format("%s(%s),转移到塘口:%s。", device.getDeviceName(), device.getSerialNum(), pond.getPondName())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 分配塘口
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"设备操作",
|
||||||
|
String.format("%s(%s),分配塘口:%s。", device.getDeviceName(), device.getSerialNum(), pond.getPondName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 记录设备从塘口移除的操作
|
// 记录设备从塘口移除的操作
|
||||||
|
for (Device device : dictDeviceRemove.values()) {
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"设备操作",
|
||||||
|
String.format("%s(%s) 从 %s 移除。", device.getDeviceName(), device.getSerialNum(), pond.getPondName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 记录开关添加到塘口的操作
|
// 记录开关添加到塘口的操作
|
||||||
|
for (DeviceSwitch sw : dictSwitchAdd.values()) {
|
||||||
|
// 查询开关关联的设备
|
||||||
|
Device switchDevice = deviceMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<Device>()
|
||||||
|
.eq(Device::getId, sw.getDeviceId())
|
||||||
|
.select(Device::getId, Device::getDeviceName)
|
||||||
|
);
|
||||||
|
|
||||||
|
String deviceName = switchDevice != null ? switchDevice.getDeviceName() : "未知设备";
|
||||||
|
|
||||||
|
if (sw.getPondId() != null && sw.getPondId() > 0) {
|
||||||
|
// 转移到塘口
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"开关操作",
|
||||||
|
String.format("%s(%s),转移到塘口:%s。", deviceName, sw.getSwitchName(), pond.getPondName())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 分配到塘口
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"开关操作",
|
||||||
|
String.format("%s(%s),分配到塘口:%s。", deviceName, sw.getSwitchName(), pond.getPondName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 记录开关从塘口移除的操作
|
// 记录开关从塘口移除的操作
|
||||||
// 具体操作记录可根据业务需求在dictDeviceAdd等集合遍历时添加
|
for (DeviceSwitch sw : dictSwitchRemove.values()) {
|
||||||
|
// 查询开关关联的设备
|
||||||
|
Device switchDevice = deviceMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<Device>()
|
||||||
|
.eq(Device::getId, sw.getDeviceId())
|
||||||
|
.select(Device::getId, Device::getDeviceName)
|
||||||
|
);
|
||||||
|
|
||||||
|
String deviceName = switchDevice != null ? switchDevice.getDeviceName() : "未知设备";
|
||||||
|
|
||||||
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
|
rootUserId,
|
||||||
|
userId,
|
||||||
|
"开关操作",
|
||||||
|
String.format("%s(%s) 从 %s 移除。", deviceName, sw.getSwitchName(), pond.getPondName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.intc.fishery.domain.AquUser;
|
|||||||
import com.intc.fishery.domain.Device;
|
import com.intc.fishery.domain.Device;
|
||||||
import com.intc.fishery.domain.DeviceBindRecord;
|
import com.intc.fishery.domain.DeviceBindRecord;
|
||||||
import com.intc.fishery.domain.DeviceCorrectRecord;
|
import com.intc.fishery.domain.DeviceCorrectRecord;
|
||||||
|
import com.intc.fishery.domain.DeviceErrorCode;
|
||||||
import com.intc.fishery.domain.DeviceSwitch;
|
import com.intc.fishery.domain.DeviceSwitch;
|
||||||
import com.intc.fishery.domain.LinkedCtrl;
|
import com.intc.fishery.domain.LinkedCtrl;
|
||||||
import com.intc.fishery.domain.Pond;
|
import com.intc.fishery.domain.Pond;
|
||||||
@@ -21,6 +22,7 @@ import com.intc.fishery.domain.bo.DeviceBo;
|
|||||||
import com.intc.fishery.domain.vo.DeviceVo;
|
import com.intc.fishery.domain.vo.DeviceVo;
|
||||||
import com.intc.fishery.mapper.DeviceBindRecordMapper;
|
import com.intc.fishery.mapper.DeviceBindRecordMapper;
|
||||||
import com.intc.fishery.mapper.DeviceCorrectRecordMapper;
|
import com.intc.fishery.mapper.DeviceCorrectRecordMapper;
|
||||||
|
import com.intc.fishery.mapper.DeviceErrorCodeMapper;
|
||||||
import com.intc.fishery.mapper.DeviceMapper;
|
import com.intc.fishery.mapper.DeviceMapper;
|
||||||
import com.intc.fishery.mapper.DeviceSwitchMapper;
|
import com.intc.fishery.mapper.DeviceSwitchMapper;
|
||||||
import com.intc.fishery.mapper.LinkedCtrlMapper;
|
import com.intc.fishery.mapper.LinkedCtrlMapper;
|
||||||
@@ -49,6 +51,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
private final DeviceMapper baseMapper;
|
private final DeviceMapper baseMapper;
|
||||||
private final DeviceBindRecordMapper deviceBindRecordMapper;
|
private final DeviceBindRecordMapper deviceBindRecordMapper;
|
||||||
private final DeviceCorrectRecordMapper deviceCorrectRecordMapper;
|
private final DeviceCorrectRecordMapper deviceCorrectRecordMapper;
|
||||||
|
private final DeviceErrorCodeMapper deviceErrorCodeMapper;
|
||||||
private final DeviceSwitchMapper deviceSwitchMapper;
|
private final DeviceSwitchMapper deviceSwitchMapper;
|
||||||
private final LinkedCtrlMapper linkedCtrlMapper;
|
private final LinkedCtrlMapper linkedCtrlMapper;
|
||||||
private final TimingCtrlMapper timingCtrlMapper;
|
private final TimingCtrlMapper timingCtrlMapper;
|
||||||
@@ -222,7 +225,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验并批量删除设备管理信息
|
* 校验并批量删除设备管理信息
|
||||||
* 删除顺序:校准记录 -> 定时控制 -> 开关(先解除联动控制引用)-> 联动控制 -> 设备
|
* 删除顺序:故障码 -> 校准记录 -> 定时控制 -> 开关(先解除联动控制引用) -> 联动控制 -> 设备
|
||||||
*
|
*
|
||||||
* @param ids 待删除的主键集合
|
* @param ids 待删除的主键集合
|
||||||
* @param isValid 是否进行有效性校验
|
* @param isValid 是否进行有效性校验
|
||||||
@@ -232,16 +235,22 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if(isValid){
|
if(isValid){
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 删除设备关联的校准记录
|
// 1. 删除设备关联的故障码记录
|
||||||
|
deviceErrorCodeMapper.delete(
|
||||||
|
new LambdaQueryWrapper<DeviceErrorCode>()
|
||||||
|
.in(DeviceErrorCode::getDeviceId, ids)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2. 删除设备关联的校准记录
|
||||||
deviceCorrectRecordMapper.delete(
|
deviceCorrectRecordMapper.delete(
|
||||||
new LambdaQueryWrapper<DeviceCorrectRecord>()
|
new LambdaQueryWrapper<DeviceCorrectRecord>()
|
||||||
.in(DeviceCorrectRecord::getDeviceId, ids)
|
.in(DeviceCorrectRecord::getDeviceId, ids)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 2. 查询设备关联的开关
|
// 3. 查询设备关联的开关
|
||||||
List<DeviceSwitch> switches = deviceSwitchMapper.selectList(
|
List<DeviceSwitch> switches = deviceSwitchMapper.selectList(
|
||||||
new LambdaQueryWrapper<DeviceSwitch>()
|
new LambdaQueryWrapper<DeviceSwitch>()
|
||||||
.in(DeviceSwitch::getDeviceId, ids)
|
.in(DeviceSwitch::getDeviceId, ids)
|
||||||
@@ -253,7 +262,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
.map(DeviceSwitch::getId)
|
.map(DeviceSwitch::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 3. 删除开关关联的定时控制
|
// 4. 删除开关关联的定时控制
|
||||||
timingCtrlMapper.delete(
|
timingCtrlMapper.delete(
|
||||||
new LambdaQueryWrapper<TimingCtrl>()
|
new LambdaQueryWrapper<TimingCtrl>()
|
||||||
.in(TimingCtrl::getSwitchId, switchIds)
|
.in(TimingCtrl::getSwitchId, switchIds)
|
||||||
@@ -266,14 +275,14 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 4. 解除开关与联动控制的绑定
|
// 5. 解除开关与联动控制的绑定
|
||||||
deviceSwitchMapper.update(null,
|
deviceSwitchMapper.update(null,
|
||||||
new LambdaUpdateWrapper<DeviceSwitch>()
|
new LambdaUpdateWrapper<DeviceSwitch>()
|
||||||
.set(DeviceSwitch::getLinkedCtrlId, null)
|
.set(DeviceSwitch::getLinkedCtrlId, null)
|
||||||
.in(DeviceSwitch::getDeviceId, ids)
|
.in(DeviceSwitch::getDeviceId, ids)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 5. 删除联动控制(如果有)
|
// 6. 删除联动控制(如果有)
|
||||||
if (!linkedCtrlIds.isEmpty()) {
|
if (!linkedCtrlIds.isEmpty()) {
|
||||||
linkedCtrlMapper.delete(
|
linkedCtrlMapper.delete(
|
||||||
new LambdaQueryWrapper<LinkedCtrl>()
|
new LambdaQueryWrapper<LinkedCtrl>()
|
||||||
@@ -281,20 +290,20 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. 删除开关
|
// 7. 删除开关
|
||||||
deviceSwitchMapper.delete(
|
deviceSwitchMapper.delete(
|
||||||
new LambdaQueryWrapper<DeviceSwitch>()
|
new LambdaQueryWrapper<DeviceSwitch>()
|
||||||
.in(DeviceSwitch::getDeviceId, ids)
|
.in(DeviceSwitch::getDeviceId, ids)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. 删除设备本身关联的联动控制
|
// 8. 删除设备本身关联的联动控制
|
||||||
linkedCtrlMapper.delete(
|
linkedCtrlMapper.delete(
|
||||||
new LambdaQueryWrapper<LinkedCtrl>()
|
new LambdaQueryWrapper<LinkedCtrl>()
|
||||||
.in(LinkedCtrl::getDeviceId, ids)
|
.in(LinkedCtrl::getDeviceId, ids)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 8. 查询要删除的设备信息,添加解绑记录
|
// 9. 查询要删除的设备信息,添加解绑记录
|
||||||
List<Device> devicesToDelete = baseMapper.selectList(
|
List<Device> devicesToDelete = baseMapper.selectList(
|
||||||
new LambdaQueryWrapper<Device>()
|
new LambdaQueryWrapper<Device>()
|
||||||
.in(Device::getId, ids)
|
.in(Device::getId, ids)
|
||||||
@@ -320,7 +329,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. 最后删除设备
|
// 10. 最后删除设备
|
||||||
return baseMapper.deleteByIds(ids) > 0;
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user