|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
|
import com.zksy.base.domain.EquipmentPointRel;
|
|
import com.zksy.base.domain.EquipmentPointRel;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
import com.zksy.base.domain.MonitorPoint;
|
|
import com.zksy.base.domain.MonitorPoint;
|
|
|
import com.zksy.base.enums.MonitorPointTypeEnum;
|
|
import com.zksy.base.enums.MonitorPointTypeEnum;
|
|
|
import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
@@ -105,10 +106,15 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public boolean updateWithCheck(MonitorPoint entity) {
|
|
public boolean updateWithCheck(MonitorPoint entity) {
|
|
|
String pointId = entity.getPointId();
|
|
String pointId = entity.getPointId();
|
|
|
- if (this.getById(pointId) == null) {
|
|
|
|
|
|
|
+ MonitorPoint existingPoint = this.getById(pointId);
|
|
|
|
|
+ if (existingPoint == null) {
|
|
|
throw new ServiceException("监测点不存在,无法修改:" + pointId);
|
|
throw new ServiceException("监测点不存在,无法修改:" + pointId);
|
|
|
}
|
|
}
|
|
|
validatePointType(entity.getPointType());
|
|
validatePointType(entity.getPointType());
|
|
|
|
|
+ if (!Objects.equals(existingPoint.getPointType(), entity.getPointType())
|
|
|
|
|
+ && equipmentCount(pointId) > 0) {
|
|
|
|
|
+ throw new ServiceException("监测点已关联设备,不能修改监测点类型,请先解除全部设备关联");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
String newCode = entity.getPointCode();
|
|
String newCode = entity.getPointCode();
|
|
|
if (newCode != null) {
|
|
if (newCode != null) {
|
|
@@ -182,12 +188,16 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
throw new ServiceException("设备ID列表不能为空");
|
|
throw new ServiceException("设备ID列表不能为空");
|
|
|
}
|
|
}
|
|
|
equipmentIds = new ArrayList<>(new LinkedHashSet<>(equipmentIds));
|
|
equipmentIds = new ArrayList<>(new LinkedHashSet<>(equipmentIds));
|
|
|
|
|
+ Map<Integer, EquipmentType> equipmentTypeMap = loadEquipmentTypeMap();
|
|
|
|
|
|
|
|
for (String equipmentId : equipmentIds) {
|
|
for (String equipmentId : equipmentIds) {
|
|
|
EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
|
|
EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
|
|
|
if (equipment == null) {
|
|
if (equipment == null) {
|
|
|
throw new ServiceException("设备不存在:" + equipmentId);
|
|
throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!belongsToPointType(equipment.getEquipmentTypeId(), point.getPointType(), equipmentTypeMap)) {
|
|
|
|
|
+ throw new ServiceException("设备[" + equipment.getEquipmentCode() + "]类型与监测点类型不匹配");
|
|
|
|
|
+ }
|
|
|
LambdaQueryWrapper<EquipmentPointRel> checkWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<EquipmentPointRel> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
checkWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
checkWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
|
List<EquipmentPointRel> existing = equipmentPointRelMapper.selectList(checkWrapper);
|
|
List<EquipmentPointRel> existing = equipmentPointRelMapper.selectList(checkWrapper);
|
|
@@ -271,11 +281,18 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<Map<String, Object>> listEquipmentForAssociation(String pointId) {
|
|
public List<Map<String, Object>> listEquipmentForAssociation(String pointId) {
|
|
|
|
|
+ MonitorPoint point = this.getById(pointId);
|
|
|
|
|
+ if (point == null) {
|
|
|
|
|
+ throw new ServiceException("监测点不存在:" + pointId);
|
|
|
|
|
+ }
|
|
|
Map<String, String> ownerByEquipment = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
|
|
Map<String, String> ownerByEquipment = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
|
|
|
.filter(rel -> rel.getEquipmentId() != null)
|
|
.filter(rel -> rel.getEquipmentId() != null)
|
|
|
.collect(Collectors.toMap(EquipmentPointRel::getEquipmentId, EquipmentPointRel::getPointId, (left, right) -> left));
|
|
.collect(Collectors.toMap(EquipmentPointRel::getEquipmentId, EquipmentPointRel::getPointId, (left, right) -> left));
|
|
|
- List<EquipmentBase> devices = equipmentBaseMapper.selectList(null);
|
|
|
|
|
- fillEquipmentTypeNames(devices);
|
|
|
|
|
|
|
+ Map<Integer, EquipmentType> equipmentTypeMap = loadEquipmentTypeMap();
|
|
|
|
|
+ List<EquipmentBase> devices = equipmentBaseMapper.selectList(null).stream()
|
|
|
|
|
+ .filter(device -> belongsToPointType(device.getEquipmentTypeId(), point.getPointType(), equipmentTypeMap))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ fillEquipmentTypeNames(devices, equipmentTypeMap);
|
|
|
return devices.stream().map(device -> {
|
|
return devices.stream().map(device -> {
|
|
|
Map<String, Object> row = new LinkedHashMap<>();
|
|
Map<String, Object> row = new LinkedHashMap<>();
|
|
|
row.put("equipmentId", device.getEquipmentId());
|
|
row.put("equipmentId", device.getEquipmentId());
|
|
@@ -291,14 +308,35 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
|
|
|
|
|
private void fillEquipmentTypeNames(List<EquipmentBase> devices) {
|
|
private void fillEquipmentTypeNames(List<EquipmentBase> devices) {
|
|
|
if (devices == null || devices.isEmpty()) return;
|
|
if (devices == null || devices.isEmpty()) return;
|
|
|
- Set<Integer> typeIds = devices.stream()
|
|
|
|
|
- .map(EquipmentBase::getEquipmentTypeId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
- if (typeIds.isEmpty()) return;
|
|
|
|
|
- equipmentTypeMapper.selectBatchIds(typeIds).forEach(type -> devices.stream()
|
|
|
|
|
- .filter(device -> Objects.equals(device.getEquipmentTypeId(), type.getId()))
|
|
|
|
|
- .forEach(device -> device.setEquipmentTypeName(type.getTypeName())));
|
|
|
|
|
|
|
+ fillEquipmentTypeNames(devices, loadEquipmentTypeMap());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void fillEquipmentTypeNames(List<EquipmentBase> devices, Map<Integer, EquipmentType> equipmentTypeMap) {
|
|
|
|
|
+ if (devices == null || devices.isEmpty()) return;
|
|
|
|
|
+ devices.forEach(device -> {
|
|
|
|
|
+ EquipmentType type = equipmentTypeMap.get(device.getEquipmentTypeId());
|
|
|
|
|
+ device.setEquipmentTypeName(type == null ? null : type.getTypeName());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<Integer, EquipmentType> loadEquipmentTypeMap() {
|
|
|
|
|
+ return equipmentTypeMapper.selectList(null).stream()
|
|
|
|
|
+ .collect(Collectors.toMap(EquipmentType::getId, type -> type, (left, right) -> left));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean belongsToPointType(Integer equipmentTypeId, Integer pointType,
|
|
|
|
|
+ Map<Integer, EquipmentType> equipmentTypeMap) {
|
|
|
|
|
+ if (pointType == null) return true;
|
|
|
|
|
+ if (equipmentTypeId == null) return false;
|
|
|
|
|
+ Integer currentTypeId = equipmentTypeId;
|
|
|
|
|
+ Set<Integer> visited = new HashSet<>();
|
|
|
|
|
+ while (currentTypeId != null && currentTypeId != 0 && visited.add(currentTypeId)) {
|
|
|
|
|
+ if (Objects.equals(currentTypeId, pointType)) return true;
|
|
|
|
|
+ EquipmentType currentType = equipmentTypeMap.get(currentTypeId);
|
|
|
|
|
+ if (currentType == null) return false;
|
|
|
|
|
+ currentTypeId = currentType.getParentId();
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private long equipmentCount(String pointId) {
|
|
private long equipmentCount(String pointId) {
|