|
|
@@ -10,6 +10,7 @@ import com.dcs.common.utils.StringUtils;
|
|
|
import com.dcs.common.utils.StringUtils;
|
|
|
import com.dcs.common.utils.bean.BeanUtils;
|
|
|
import com.dcs.equipment.task.ModbusTcpTask;
|
|
|
+import com.dcs.hnyz.cache.CacheCenter;
|
|
|
import com.dcs.hnyz.domain.Equipment;
|
|
|
import com.dcs.hnyz.domain.EquipmentParam;
|
|
|
import com.dcs.hnyz.domain.vo.EquipmentParamFormVO;
|
|
|
@@ -156,7 +157,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
}
|
|
|
DeviceTypeEnum type = DeviceTypeEnum.fromCode(e.getEquipmentType());
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, parentId);
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, CacheCenter.deviceCodeToIdMap.get(parentId));
|
|
|
switch (type) {
|
|
|
case SENSOR:
|
|
|
case VALVE_WITH_FEEDBACK:
|
|
|
@@ -196,7 +197,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
}
|
|
|
DeviceTypeEnum type = DeviceTypeEnum.fromCode(e.getEquipmentType());
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, parentId);
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, CacheCenter.deviceCodeToIdMap.get(parentId));
|
|
|
switch (type) {
|
|
|
case SENSOR:
|
|
|
case VALVE_WITH_FEEDBACK:
|
|
|
@@ -240,7 +241,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
|
|
|
// 初始化查询 wrapper
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, parentId);
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, CacheCenter.deviceCodeToIdMap.get(parentId));
|
|
|
|
|
|
List<String> paramTypes = new ArrayList<>();
|
|
|
|
|
|
@@ -309,13 +310,13 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<Long, String> getCodeMapByParentIds(List<Long> validEquipmentIds) {
|
|
|
- if (CollectionUtils.isEmpty(validEquipmentIds)) {
|
|
|
+ public Map<Long, String> getCodeMapByParentCodes(List<String> validEquipmentCodes) {
|
|
|
+ if (CollectionUtils.isEmpty(validEquipmentCodes)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
|
|
|
// 1. 批量查询设备信息
|
|
|
- List<Equipment> equipments = equipmentService.selectBatchIds(validEquipmentIds);
|
|
|
+ List<Equipment> equipments = equipmentService.selectByCodes(validEquipmentCodes);
|
|
|
if (CollectionUtils.isEmpty(equipments)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
@@ -323,20 +324,20 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
// 2. 批量查询设备参数
|
|
|
List<EquipmentParam> params = equipmentParamMapper.selectList(
|
|
|
new LambdaQueryWrapper<EquipmentParam>()
|
|
|
- .in(EquipmentParam::getRelationId, validEquipmentIds)
|
|
|
+ .in(EquipmentParam::getRelationCode, validEquipmentCodes)
|
|
|
);
|
|
|
if (CollectionUtils.isEmpty(params)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
- // relationId → 该设备的所有参数
|
|
|
- Map<Long, List<EquipmentParam>> paramMap = params.stream()
|
|
|
- .collect(Collectors.groupingBy(EquipmentParam::getRelationId));
|
|
|
+ // relationCode → 该设备的所有参数
|
|
|
+ Map<String, List<EquipmentParam>> paramMap = params.stream()
|
|
|
+ .collect(Collectors.groupingBy(EquipmentParam::getRelationCode));
|
|
|
|
|
|
// 3. 按设备类型过滤参数,挑选对应的 code
|
|
|
Map<Long, String> result = new HashMap<>();
|
|
|
for (Equipment eq : equipments) {
|
|
|
DeviceTypeEnum type = DeviceTypeEnum.fromCode(eq.getEquipmentType());
|
|
|
- List<EquipmentParam> eps = paramMap.get(eq.getEquipmentId());
|
|
|
+ List<EquipmentParam> eps = paramMap.get(eq.getCode());
|
|
|
if (CollectionUtils.isEmpty(eps)) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -379,7 +380,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
public EquipmentParam getMainSetParam(String code) {
|
|
|
Equipment e = equipmentService.getEquipmentByCode(code);
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, e.getEquipmentId());
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, code);
|
|
|
wrapper.eq(EquipmentParam::getParamType, RegisterTypeEnum.MASTER_SET.getCode());
|
|
|
EquipmentParam ep = equipmentParamMapper.selectOne(wrapper);
|
|
|
|
|
|
@@ -396,7 +397,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
throw new CustomException("未找到设备:" + code);
|
|
|
}
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, e.getEquipmentId());
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, code);
|
|
|
wrapper.in(EquipmentParam::getParamType, RegisterTypeEnum.MASTER_SET.getCode(), RegisterTypeEnum.SLAVE_SET.getCode());
|
|
|
wrapper.eq(EquipmentParam::getStatus, GeneralStatus.ENABLE.getCode());
|
|
|
//按ParamType升序(主设置,从设置)
|
|
|
@@ -467,7 +468,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
|
|
|
String eqName = equipment.getEquipmentName();
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, equipment.getEquipmentId())
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, equipment.getCode())
|
|
|
.eq(EquipmentParam::getStatus, GeneralStatus.ENABLE.getCode());
|
|
|
|
|
|
List<EquipmentParam> epList = equipmentParamMapper.selectList(wrapper);
|
|
|
@@ -534,7 +535,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
|
|
|
public Map<String, List<Object>> getAllParamConfigDataByCodeList(List<String> codeList) {
|
|
|
// 1. 获取设备code与id的映射(原逻辑保留)
|
|
|
- Map<String, Long> equipmentIdCodeMap = equipmentService.getEquipmentIdCodeMap();
|
|
|
+ Map<String, Long> equipmentIdCodeMap = CacheCenter.deviceCodeToIdMap;
|
|
|
if (equipmentIdCodeMap.isEmpty()) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
@@ -549,18 +550,18 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
));
|
|
|
|
|
|
// 3. 收集有效的equipmentId(过滤不存在的code,去重)
|
|
|
- Set<Long> validEquipmentIds = codeList.stream()
|
|
|
- .filter(equipmentIdCodeMap::containsKey) // 只保留存在的code
|
|
|
- .map(equipmentIdCodeMap::get) // 转为equipmentId
|
|
|
- .collect(Collectors.toSet()); // 去重,避免重复查询
|
|
|
-
|
|
|
- if (validEquipmentIds.isEmpty()) {
|
|
|
- return Collections.emptyMap();
|
|
|
- }
|
|
|
+// Set<Long> validEquipmentIds = codeList.stream()
|
|
|
+// .filter(equipmentIdCodeMap::containsKey) // 只保留存在的code
|
|
|
+// .map(equipmentIdCodeMap::get) // 转为equipmentId
|
|
|
+// .collect(Collectors.toSet()); // 去重,避免重复查询
|
|
|
+//
|
|
|
+// if (validEquipmentIds.isEmpty()) {
|
|
|
+// return Collections.emptyMap();
|
|
|
+// }
|
|
|
|
|
|
// 4. 批量查询所有有效的EquipmentParam(一次数据库查询)
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.in(EquipmentParam::getRelationId, validEquipmentIds) // 批量匹配equipmentId
|
|
|
+ wrapper.in(EquipmentParam::getRelationCode, codeList) // 批量匹配codeList
|
|
|
.eq(EquipmentParam::getStatus, GeneralStatus.ENABLE.getCode())
|
|
|
.in(EquipmentParam::getParamType,
|
|
|
RegisterTypeEnum.PARAM_CONFIG1.getCode(),
|
|
|
@@ -573,9 +574,9 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
|
|
|
List<EquipmentParam> allEpList = equipmentParamMapper.selectList(wrapper);
|
|
|
|
|
|
- // 5. 按relationId(即equipmentId)分组,便于后续快速获取
|
|
|
- Map<Long, List<EquipmentParam>> epGroupByEquipmentId = allEpList.stream()
|
|
|
- .collect(Collectors.groupingBy(EquipmentParam::getRelationId));
|
|
|
+ // 5. 按relationCode分组,便于后续快速获取
|
|
|
+ Map<String, List<EquipmentParam>> epGroupByEquipmentCode = allEpList.stream()
|
|
|
+ .collect(Collectors.groupingBy(EquipmentParam::getRelationCode));
|
|
|
|
|
|
// 6. 构建结果(遍历codeList,填充数据)
|
|
|
Map<String, List<Object>> result = new HashMap<>(codeList.size()); // 预设容量
|
|
|
@@ -587,8 +588,8 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 从分组中获取当前equipmentId对应的参数列表
|
|
|
- List<EquipmentParam> epList = epGroupByEquipmentId.getOrDefault(equipmentId, Collections.emptyList());
|
|
|
+ // 从分组中获取当前equipmentCode对应的参数列表
|
|
|
+ List<EquipmentParam> epList = epGroupByEquipmentCode.getOrDefault(code, Collections.emptyList());
|
|
|
for (EquipmentParam ep : epList) {
|
|
|
// 从预构建的map中快速获取VO,避免遍历
|
|
|
EquipmentParamFormVO vo = broadCastCodeMap.get(ep.getCode());
|
|
|
@@ -607,7 +608,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
throw new CustomException("未找到设备:" + code);
|
|
|
}
|
|
|
LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(EquipmentParam::getRelationId, e.getEquipmentId());
|
|
|
+ wrapper.eq(EquipmentParam::getRelationCode, code);
|
|
|
wrapper.eq(EquipmentParam::getStatus, GeneralStatus.ENABLE.getCode());
|
|
|
wrapper.in(EquipmentParam::getParamType, RegisterTypeEnum.PARAM_CONFIG1.getCode(), RegisterTypeEnum.PARAM_CONFIG2.getCode(), RegisterTypeEnum.PARAM_CONFIG3.getCode(), RegisterTypeEnum.PARAM_CONFIG4.getCode(), RegisterTypeEnum.PARAM_CONFIG5.getCode());
|
|
|
wrapper.orderByAsc(EquipmentParam::getParamType);//按ParamType升序(参数配置1,2,3,4,5)
|
|
|
@@ -621,9 +622,9 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<EquipmentParam> getAllEquipmentParamByRelationIds(List<Long> equipmentIds) {
|
|
|
+ public List<EquipmentParam> getAllEquipmentParamByRelationCodes(List<String> codes) {
|
|
|
return equipmentParamMapper.selectList(new LambdaQueryWrapper<EquipmentParam>()
|
|
|
- .in(EquipmentParam::getRelationId, equipmentIds));
|
|
|
+ .in(EquipmentParam::getRelationCode, codes));
|
|
|
}
|
|
|
|
|
|
}
|