fix: 微信小程序接口对接修改,联调测试问题修复。
This commit is contained in:
@@ -1,22 +1,31 @@
|
||||
package com.intc.fishery.service.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.intc.common.core.utils.MapstructUtils;
|
||||
import com.intc.common.core.utils.StringUtils;
|
||||
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.DeviceCorrectRecord;
|
||||
import com.intc.fishery.domain.DeviceSwitch;
|
||||
import com.intc.fishery.domain.LinkedCtrl;
|
||||
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.DeviceCorrectRecordMapper;
|
||||
import com.intc.fishery.mapper.DeviceMapper;
|
||||
import com.intc.fishery.mapper.DeviceSwitchMapper;
|
||||
import com.intc.fishery.mapper.LinkedCtrlMapper;
|
||||
import com.intc.fishery.mapper.TimingCtrlMapper;
|
||||
import com.intc.fishery.service.IDeviceService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
@@ -36,6 +45,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class DeviceServiceImpl implements IDeviceService {
|
||||
|
||||
private final DeviceMapper baseMapper;
|
||||
private final DeviceCorrectRecordMapper deviceCorrectRecordMapper;
|
||||
private final DeviceSwitchMapper deviceSwitchMapper;
|
||||
private final LinkedCtrlMapper linkedCtrlMapper;
|
||||
private final TimingCtrlMapper timingCtrlMapper;
|
||||
|
||||
/**
|
||||
* 查询设备管理
|
||||
@@ -206,16 +219,79 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
|
||||
/**
|
||||
* 校验并批量删除设备管理信息
|
||||
* 删除顺序:校准记录 -> 定时控制 -> 开关(先解除联动控制引用)-> 联动控制 -> 设备
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
|
||||
// 1. 删除设备关联的校准记录
|
||||
deviceCorrectRecordMapper.delete(
|
||||
new LambdaQueryWrapper<DeviceCorrectRecord>()
|
||||
.in(DeviceCorrectRecord::getDeviceId, ids)
|
||||
);
|
||||
|
||||
// 2. 查询设备关联的开关
|
||||
List<DeviceSwitch> switches = deviceSwitchMapper.selectList(
|
||||
new LambdaQueryWrapper<DeviceSwitch>()
|
||||
.in(DeviceSwitch::getDeviceId, ids)
|
||||
);
|
||||
|
||||
if (!switches.isEmpty()) {
|
||||
// 收集开关ID
|
||||
List<Long> switchIds = switches.stream()
|
||||
.map(DeviceSwitch::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 3. 删除开关关联的定时控制
|
||||
timingCtrlMapper.delete(
|
||||
new LambdaQueryWrapper<TimingCtrl>()
|
||||
.in(TimingCtrl::getSwitchId, switchIds)
|
||||
);
|
||||
|
||||
// 收集开关关联的联动控制ID
|
||||
List<Long> linkedCtrlIds = switches.stream()
|
||||
.map(DeviceSwitch::getLinkedCtrlId)
|
||||
.filter(id -> id != null && id > 0)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 4. 解除开关与联动控制的绑定
|
||||
deviceSwitchMapper.update(null,
|
||||
new LambdaUpdateWrapper<DeviceSwitch>()
|
||||
.set(DeviceSwitch::getLinkedCtrlId, null)
|
||||
.in(DeviceSwitch::getDeviceId, ids)
|
||||
);
|
||||
|
||||
// 5. 删除联动控制(如果有)
|
||||
if (!linkedCtrlIds.isEmpty()) {
|
||||
linkedCtrlMapper.delete(
|
||||
new LambdaQueryWrapper<LinkedCtrl>()
|
||||
.in(LinkedCtrl::getId, linkedCtrlIds)
|
||||
);
|
||||
}
|
||||
|
||||
// 6. 删除开关
|
||||
deviceSwitchMapper.delete(
|
||||
new LambdaQueryWrapper<DeviceSwitch>()
|
||||
.in(DeviceSwitch::getDeviceId, ids)
|
||||
);
|
||||
}
|
||||
|
||||
// 7. 删除设备本身关联的联动控制
|
||||
linkedCtrlMapper.delete(
|
||||
new LambdaQueryWrapper<LinkedCtrl>()
|
||||
.in(LinkedCtrl::getDeviceId, ids)
|
||||
);
|
||||
|
||||
// 8. 最后删除设备
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user