优化烘料,规则缓存优化
This commit is contained in:
parent
4044f17048
commit
32079101cd
@ -154,7 +154,7 @@ alarm:
|
||||
devices:
|
||||
- deviceId: ALARM_LIGHT_01
|
||||
host: 192.168.29.191
|
||||
port: 9999
|
||||
port: 9990
|
||||
reconnect-interval: 10
|
||||
connection-timeout: 30
|
||||
keepalive: true
|
||||
@ -164,9 +164,10 @@ alarm:
|
||||
reconnect-interval: 10
|
||||
connection-timeout: 30
|
||||
keepalive: true
|
||||
#3BE2
|
||||
- deviceId: ALARM_LIGHT_03
|
||||
host: 192.168.29.195
|
||||
port: 9997
|
||||
port: 9994
|
||||
reconnect-interval: 10
|
||||
connection-timeout: 30
|
||||
keepalive: true
|
||||
|
||||
@ -3,17 +3,21 @@ package com.shgx.dryingroom.web.service.impl;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.shgx.common.utils.DateUtils;
|
||||
import com.shgx.common.utils.SecurityUtils;
|
||||
import com.shgx.common.utils.StringUtils;
|
||||
import com.shgx.common.utils.uuid.UUID;
|
||||
import com.shgx.dryingroom.collect.AutoCollectService;
|
||||
import com.shgx.dryingroom.web.domain.DryEquipmentInfo;
|
||||
import com.shgx.dryingroom.web.domain.DryEquipmentParamRelation;
|
||||
import com.shgx.dryingroom.web.mapper.DryEquipmentInfoMapper;
|
||||
import com.shgx.dryingroom.web.mapper.DryEquipmentParamRelationMapper;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||
@ -38,7 +42,7 @@ import static org.apache.naming.SelectorContext.prefix;
|
||||
*/
|
||||
@Service
|
||||
@DS("postgres")
|
||||
public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
{
|
||||
@Autowired
|
||||
private DryParamThresholdMapper dryParamThresholdMapper;
|
||||
@ -49,9 +53,12 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
@Autowired
|
||||
private DryEquipmentParamRelationMapper relationMapper;
|
||||
|
||||
@Autowired
|
||||
private DryEquipmentInfoMapper infoMapper;
|
||||
|
||||
/**
|
||||
* 查询参数阈值
|
||||
*
|
||||
*
|
||||
* @param id 参数阈值主键
|
||||
* @return 参数阈值
|
||||
*/
|
||||
@ -63,7 +70,7 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
|
||||
/**
|
||||
* 查询参数阈值列表
|
||||
*
|
||||
*
|
||||
* @param dryParamThreshold 参数阈值
|
||||
* @return 参数阈值
|
||||
*/
|
||||
@ -80,7 +87,7 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
|
||||
/**
|
||||
* 新增参数阈值
|
||||
*
|
||||
*
|
||||
* @param dryParamThreshold 参数阈值
|
||||
* @return 结果
|
||||
*/
|
||||
@ -115,7 +122,7 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
|
||||
/**
|
||||
* 修改参数阈值
|
||||
*
|
||||
*
|
||||
* @param dryParamThreshold 参数阈值
|
||||
* @return 结果
|
||||
*/
|
||||
@ -134,7 +141,7 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
|
||||
/**
|
||||
* 批量删除参数阈值
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的参数阈值主键
|
||||
* @return 结果
|
||||
*/
|
||||
@ -174,8 +181,8 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数阈值信息
|
||||
*
|
||||
* 删除参数阈值信息(含级联置空设备关联的ruleCode)
|
||||
*
|
||||
* @param id 参数阈值主键
|
||||
* @return 结果
|
||||
*/
|
||||
@ -195,18 +202,38 @@ public class DryParamThresholdServiceImpl implements IDryParamThresholdService
|
||||
}
|
||||
String ruleCode = threshold.getRuleCode();
|
||||
|
||||
// 3. 级联删除DryEquipmentParamRelation中匹配ruleCode的所有数据
|
||||
if (StringUtils.hasText(ruleCode)) { // 过滤空ruleCode,避免删全表
|
||||
// 3. 核心逻辑:处理设备关联的ruleCode置空
|
||||
if (StringUtils.hasText(ruleCode)) {
|
||||
// 3.1 查询relation表中该ruleCode绑定的所有equipmentCode
|
||||
LambdaQueryWrapper<DryEquipmentParamRelation> relationQueryWrapper = new LambdaQueryWrapper<>();
|
||||
relationQueryWrapper.eq(DryEquipmentParamRelation::getRuleCode, ruleCode);
|
||||
// 删除记录的关联数据条数
|
||||
relationMapper.delete(relationQueryWrapper);
|
||||
// 日志示例:便于排查问题
|
||||
// log.info("级联删除DryEquipmentParamRelation数据,ruleCode={},删除条数={}", ruleCode, relationDeleteCount);
|
||||
relationQueryWrapper.eq(DryEquipmentParamRelation::getRuleCode, ruleCode)
|
||||
.select(DryEquipmentParamRelation::getEquipmentCode); // 只查需要的字段,提升性能
|
||||
// 获取所有关联的equipmentCode列表
|
||||
List<String> equipmentCodeList = relationMapper.selectObjs(relationQueryWrapper)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.distinct() // 去重,避免重复更新
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 3.2 批量置空这些equipmentCode对应的ruleCode(DryEquipmentInfo表)
|
||||
if (!equipmentCodeList.isEmpty()) {
|
||||
LambdaUpdateWrapper<DryEquipmentInfo> infoUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
infoUpdateWrapper.in(DryEquipmentInfo::getEquipmentCode, equipmentCodeList) // 匹配所有关联设备
|
||||
.set(DryEquipmentInfo::getRuleCode, null); // 将ruleCode置为null
|
||||
int updateCount = infoMapper.update(null, infoUpdateWrapper);
|
||||
}
|
||||
|
||||
// 3.3 级联删除DryEquipmentParamRelation中该ruleCode的所有关联数据
|
||||
LambdaQueryWrapper<DryEquipmentParamRelation> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(DryEquipmentParamRelation::getRuleCode, ruleCode);
|
||||
int relationDeleteCount = relationMapper.delete(deleteWrapper);
|
||||
}
|
||||
|
||||
// 4. 删除DryParamThreshold主表数据
|
||||
return dryParamThresholdMapper.deleteById(id);
|
||||
int mainDeleteCount = dryParamThresholdMapper.deleteById(id);
|
||||
|
||||
return mainDeleteCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user