20260304:修复bug:网关产品修改子产品从机地址
This commit is contained in:
parent
90da58d73e
commit
09faed7bf8
@ -3,6 +3,7 @@ package com.fastbee.iot.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fastbee.common.exception.ServiceException;
|
||||||
import com.fastbee.common.utils.SecurityUtils;
|
import com.fastbee.common.utils.SecurityUtils;
|
||||||
import com.fastbee.iot.domain.ModbusParams;
|
import com.fastbee.iot.domain.ModbusParams;
|
||||||
import com.fastbee.iot.domain.ProductModbusJob;
|
import com.fastbee.iot.domain.ProductModbusJob;
|
||||||
@ -176,25 +177,28 @@ public class ProductSubGatewayServiceImpl extends ServiceImpl<ProductSubGatewayM
|
|||||||
List<ProductSubGateway> productSubGatewayList = baseMapper.selectList(queryWrapper);
|
List<ProductSubGateway> productSubGatewayList = baseMapper.selectList(queryWrapper);
|
||||||
Map<Long, Integer> productSubGatewayMap = productSubGatewayList.stream().collect(Collectors.toMap(ProductSubGateway::getSubProductId, ProductSubGateway::getSlaveId));
|
Map<Long, Integer> productSubGatewayMap = productSubGatewayList.stream().collect(Collectors.toMap(ProductSubGateway::getSubProductId, ProductSubGateway::getSlaveId));
|
||||||
List<ProductSubGateway> editList = list.stream().filter(i -> !i.getSlaveId().equals(productSubGatewayMap.get(i.getSubProductId()))).collect(Collectors.toList());
|
List<ProductSubGateway> editList = list.stream().filter(i -> !i.getSlaveId().equals(productSubGatewayMap.get(i.getSubProductId()))).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(editList)) {
|
||||||
|
throw new ServiceException("地址已修改,请勿重复修改!");
|
||||||
|
}
|
||||||
baseMapper.updateBatch(list, list.size());
|
baseMapper.updateBatch(list, list.size());
|
||||||
List<Long> editSubProductIdList = editList.stream().map(ProductSubGateway::getSubProductId).collect(Collectors.toList());
|
List<Long> editSubProductIdList = editList.stream().map(ProductSubGateway::getSubProductId).collect(Collectors.toList());
|
||||||
Map<Long, ProductSubGateway> oldEdidMap = productSubGatewayList.stream().filter(i -> editSubProductIdList.contains(i.getSubProductId())).collect(Collectors.toList())
|
Map<Long, ProductSubGateway> oldEdidMap = productSubGatewayList.stream().filter(i -> editSubProductIdList.contains(i.getSubProductId())).collect(Collectors.toList())
|
||||||
.stream().collect(Collectors.toMap(ProductSubGateway::getSubProductId, Function.identity()));
|
.stream().collect(Collectors.toMap(ProductSubGateway::getSubProductId, Function.identity()));
|
||||||
LambdaQueryWrapper<ProductModbusJob> queryWrapper1 = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ProductModbusJob> modbusJobQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper1.in(ProductModbusJob::getProductId, editSubProductIdList);
|
modbusJobQueryWrapper.in(ProductModbusJob::getProductId, editSubProductIdList);
|
||||||
List<ProductModbusJob> modbusJobList = productModbusJobMapper.selectList(queryWrapper1);
|
List<ProductModbusJob> modbusJobList = productModbusJobMapper.selectList(modbusJobQueryWrapper);
|
||||||
Map<Long, List<ProductModbusJob>> oldMap = new HashMap<>(2);
|
Map<Long, List<ProductModbusJob>> oldMap = new HashMap<>(2);
|
||||||
if (CollectionUtils.isNotEmpty(modbusJobList)) {
|
if (CollectionUtils.isNotEmpty(modbusJobList)) {
|
||||||
oldMap = modbusJobList.stream().collect(Collectors.groupingBy(ProductModbusJob::getProductId));
|
oldMap = modbusJobList.stream().collect(Collectors.groupingBy(ProductModbusJob::getProductId));
|
||||||
}
|
}
|
||||||
LambdaQueryWrapper<ModbusParams> queryWrapper2 = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ModbusParams> modbusParamsQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper2.in(ModbusParams::getProductId, editSubProductIdList);
|
modbusParamsQueryWrapper.in(ModbusParams::getProductId, editSubProductIdList);
|
||||||
List<ModbusParams> modbusParamsList = modbusParamsMapper.selectList(queryWrapper2);
|
List<ModbusParams> modbusParamsList = modbusParamsMapper.selectList(modbusParamsQueryWrapper);
|
||||||
for (ProductSubGateway productSubGateway : editList) {
|
for (ProductSubGateway productSubGateway : editList) {
|
||||||
Integer slaveId = productSubGateway.getSlaveId();
|
Integer slaveId = productSubGateway.getSlaveId();
|
||||||
ProductSubGateway oldProductSubGateway = oldEdidMap.get(productSubGateway.getSubProductId());
|
ProductSubGateway oldProductSubGateway = oldEdidMap.get(productSubGateway.getSubProductId());
|
||||||
int subIndex = String.valueOf(oldProductSubGateway.getSlaveId()).length() == 1 ? 2 : String.valueOf(oldProductSubGateway.getSlaveId()).length();
|
int subIndex = String.valueOf(oldProductSubGateway.getSlaveId()).length() == 1 ? 2 : String.valueOf(oldProductSubGateway.getSlaveId()).length();
|
||||||
List<ProductModbusJob> productModbusJobList = oldMap.get(productSubGateway.getSubProductId());
|
List<ProductModbusJob> productModbusJobList = oldMap.getOrDefault(productSubGateway.getSubProductId(), Collections.emptyList());
|
||||||
for (ProductModbusJob productModbusJob : productModbusJobList) {
|
for (ProductModbusJob productModbusJob : productModbusJobList) {
|
||||||
String oldCommand = productModbusJob.getCommand();
|
String oldCommand = productModbusJob.getCommand();
|
||||||
String substring = oldCommand.substring(subIndex);
|
String substring = oldCommand.substring(subIndex);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user