|
|
@@ -7,12 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
|
import com.zksy.base.domain.EquipmentPointRel;
|
|
|
import com.zksy.base.domain.MonitorPoint;
|
|
|
-import com.zksy.base.domain.PipeNetworkBase;
|
|
|
-import com.zksy.base.dto.MonitorPointPageInDTO;
|
|
|
import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
import com.zksy.base.mapper.EquipmentPointRelMapper;
|
|
|
+import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
import com.zksy.base.mapper.MonitorPointMapper;
|
|
|
-import com.zksy.base.mapper.PipeNetworkBaseMapper;
|
|
|
import com.zksy.base.service.MonitorPointService;
|
|
|
import com.zksy.common.exception.ServiceException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -20,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -35,22 +34,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private PipeNetworkBaseMapper pipeNetworkBaseMapper;
|
|
|
+ private EquipmentTypeMapper equipmentTypeMapper;
|
|
|
|
|
|
@Override
|
|
|
- public Page<MonitorPoint> queryByPage(MonitorPointPageInDTO dto) {
|
|
|
- Page<MonitorPoint> page = new Page<>(dto.getPageNum(), dto.getPageSize());
|
|
|
- LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.like(dto.getPointName() != null && !dto.getPointName().isEmpty(), MonitorPoint::getPointName, dto.getPointName());
|
|
|
- wrapper.eq(dto.getPointType() != null && !dto.getPointType().isEmpty(), MonitorPoint::getPointType, dto.getPointType());
|
|
|
- wrapper.orderByDesc(MonitorPoint::getCreateTime);
|
|
|
- return this.page(page, wrapper);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<MonitorPoint> findByPage(long pageNum, long pageSize,
|
|
|
- String pointCode, String pointName,
|
|
|
- String pointType, String status) {
|
|
|
+ public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus) {
|
|
|
Page<MonitorPoint> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
if (pointCode != null && !pointCode.isEmpty()) {
|
|
|
@@ -59,24 +46,24 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
if (pointName != null && !pointName.isEmpty()) {
|
|
|
queryWrapper.like(MonitorPoint::getPointName, pointName);
|
|
|
}
|
|
|
- if (pointType != null && !pointType.isEmpty()) {
|
|
|
- queryWrapper.eq(MonitorPoint::getPointType, pointType);
|
|
|
- }
|
|
|
- if (status != null && !status.isEmpty()) {
|
|
|
- queryWrapper.eq(MonitorPoint::getStatus, status);
|
|
|
+ if ("linked".equalsIgnoreCase(associationStatus) || "pending".equalsIgnoreCase(associationStatus)) {
|
|
|
+ List<String> linkedPointIds = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
|
|
|
+ .map(EquipmentPointRel::getPointId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ if ("linked".equalsIgnoreCase(associationStatus)) {
|
|
|
+ queryWrapper.in(!linkedPointIds.isEmpty(), MonitorPoint::getPointId, linkedPointIds);
|
|
|
+ if (linkedPointIds.isEmpty()) queryWrapper.eq(MonitorPoint::getPointId, "__none__");
|
|
|
+ } else if (!linkedPointIds.isEmpty()) {
|
|
|
+ queryWrapper.notIn(MonitorPoint::getPointId, linkedPointIds);
|
|
|
+ }
|
|
|
}
|
|
|
queryWrapper.orderByDesc(MonitorPoint::getCreateTime);
|
|
|
- return this.page(page, queryWrapper);
|
|
|
+ Page<MonitorPoint> result = this.page(page, queryWrapper);
|
|
|
+ result.getRecords().forEach(point -> point.setEquipmentCount(equipmentCount(point.getPointId())));
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean saveWithCheck(MonitorPoint entity) {
|
|
|
- if (entity.getNetworkId() != null) {
|
|
|
- PipeNetworkBase network = pipeNetworkBaseMapper.selectById(entity.getNetworkId());
|
|
|
- if (network == null) {
|
|
|
- throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
|
|
|
- }
|
|
|
- }
|
|
|
LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
|
|
|
long count = this.count(queryWrapper);
|
|
|
@@ -98,11 +85,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
}
|
|
|
|
|
|
for (MonitorPoint entity : entityList) {
|
|
|
- if (entity.getNetworkId() != null) {
|
|
|
- if (pipeNetworkBaseMapper.selectById(entity.getNetworkId()) == null) {
|
|
|
- throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
|
|
|
- }
|
|
|
- }
|
|
|
LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
|
|
|
if (this.count(wrapper) > 0) {
|
|
|
@@ -120,12 +102,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
throw new ServiceException("监测点不存在,无法修改:" + pointId);
|
|
|
}
|
|
|
|
|
|
- if (entity.getNetworkId() != null) {
|
|
|
- if (pipeNetworkBaseMapper.selectById(entity.getNetworkId()) == null) {
|
|
|
- throw new ServiceException("关联管网设施不存在:" + entity.getNetworkId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
String newCode = entity.getPointCode();
|
|
|
if (newCode != null) {
|
|
|
LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
|
|
|
@@ -148,8 +124,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
|
|
|
LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
relWrapper.eq(EquipmentPointRel::getPointId, pointId);
|
|
|
- equipmentPointRelMapper.delete(relWrapper);
|
|
|
- log.info("已删除监测点[{}]的设备关联关系", pointId);
|
|
|
+ if (equipmentPointRelMapper.selectCount(relWrapper) > 0) {
|
|
|
+ throw new ServiceException("监测点仍有关联设备,请先解除关联");
|
|
|
+ }
|
|
|
|
|
|
return this.removeById(pointId);
|
|
|
}
|
|
|
@@ -179,8 +156,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
|
|
|
LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
relWrapper.in(EquipmentPointRel::getPointId, existIds);
|
|
|
- equipmentPointRelMapper.delete(relWrapper);
|
|
|
- log.info("已批量删除{}条监测点的设备关联关系", existIds.size());
|
|
|
+ if (equipmentPointRelMapper.selectCount(relWrapper) > 0) {
|
|
|
+ throw new ServiceException("选中的监测点仍有关联设备,请先解除关联");
|
|
|
+ }
|
|
|
|
|
|
return this.removeByIds(existIds);
|
|
|
}
|
|
|
@@ -192,6 +170,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
if (point == null) {
|
|
|
throw new ServiceException("监测点不存在:" + pointId);
|
|
|
}
|
|
|
+ if (CollectionUtils.isEmpty(equipmentIds)) {
|
|
|
+ throw new ServiceException("设备ID列表不能为空");
|
|
|
+ }
|
|
|
+ equipmentIds = new ArrayList<>(new LinkedHashSet<>(equipmentIds));
|
|
|
|
|
|
for (String equipmentId : equipmentIds) {
|
|
|
EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
|
|
|
@@ -199,18 +181,21 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
}
|
|
|
LambdaQueryWrapper<EquipmentPointRel> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
- checkWrapper.eq(EquipmentPointRel::getPointId, pointId)
|
|
|
- .eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
|
- if (equipmentPointRelMapper.selectCount(checkWrapper) > 0) {
|
|
|
- throw new ServiceException("设备已绑定此监测点:" + equipmentId);
|
|
|
+ checkWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
|
+ List<EquipmentPointRel> existing = equipmentPointRelMapper.selectList(checkWrapper);
|
|
|
+ if (!existing.isEmpty() && existing.stream().noneMatch(rel -> pointId.equals(rel.getPointId()))) {
|
|
|
+ throw new ServiceException("设备已归属其他监测点:" + equipmentId);
|
|
|
}
|
|
|
+ if (!existing.isEmpty()) throw new ServiceException("设备已绑定此监测点:" + equipmentId);
|
|
|
}
|
|
|
|
|
|
List<EquipmentPointRel> relList = new ArrayList<>();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
for (String equipmentId : equipmentIds) {
|
|
|
EquipmentPointRel rel = new EquipmentPointRel();
|
|
|
rel.setPointId(pointId);
|
|
|
rel.setEquipmentId(equipmentId);
|
|
|
+ rel.setCreateTime(now);
|
|
|
relList.add(rel);
|
|
|
}
|
|
|
|
|
|
@@ -241,11 +226,6 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("pointInfo", point);
|
|
|
|
|
|
- if (point.getNetworkId() != null) {
|
|
|
- PipeNetworkBase network = pipeNetworkBaseMapper.selectById(point.getNetworkId());
|
|
|
- result.put("networkInfo", network);
|
|
|
- }
|
|
|
-
|
|
|
LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
relWrapper.eq(EquipmentPointRel::getPointId, pointId);
|
|
|
List<EquipmentPointRel> relList = equipmentPointRelMapper.selectList(relWrapper);
|
|
|
@@ -254,17 +234,59 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
.map(EquipmentPointRel::getEquipmentId)
|
|
|
.collect(Collectors.toList());
|
|
|
List<EquipmentBase> equipmentList = equipmentBaseMapper.selectBatchIds(equipmentIds);
|
|
|
+ fillEquipmentTypeNames(equipmentList);
|
|
|
result.put("equipmentList", equipmentList);
|
|
|
}
|
|
|
|
|
|
+ result.put("equipmentList", result.getOrDefault("equipmentList", Collections.emptyList()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> statistics() {
|
|
|
+ List<EquipmentPointRel> relations = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ Set<String> linkedPointIds = relations.stream().map(EquipmentPointRel::getPointId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ result.put("totalPoints", this.count());
|
|
|
+ result.put("linkedPoints", linkedPointIds.size());
|
|
|
+ result.put("pendingPoints", Math.max(0, this.count() - linkedPointIds.size()));
|
|
|
+ result.put("totalDevices", relations.stream().map(EquipmentPointRel::getEquipmentId).filter(Objects::nonNull).distinct().count());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<MonitorPoint> getPointsByNetwork(String networkId) {
|
|
|
- LambdaQueryWrapper<MonitorPoint> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(MonitorPoint::getNetworkId, networkId);
|
|
|
- wrapper.orderByDesc(MonitorPoint::getCreateTime);
|
|
|
- return this.list(wrapper);
|
|
|
+ public List<Map<String, Object>> listEquipmentForAssociation(String pointId) {
|
|
|
+ Map<String, String> ownerByEquipment = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>()).stream()
|
|
|
+ .filter(rel -> rel.getEquipmentId() != null)
|
|
|
+ .collect(Collectors.toMap(EquipmentPointRel::getEquipmentId, EquipmentPointRel::getPointId, (left, right) -> left));
|
|
|
+ List<EquipmentBase> devices = equipmentBaseMapper.selectList(null);
|
|
|
+ fillEquipmentTypeNames(devices);
|
|
|
+ return devices.stream().map(device -> {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("equipmentId", device.getEquipmentId());
|
|
|
+ row.put("equipmentCode", device.getEquipmentCode());
|
|
|
+ row.put("equipmentName", device.getEquipmentName());
|
|
|
+ row.put("equipmentTypeName", device.getEquipmentTypeName());
|
|
|
+ row.put("equipmentLocation", device.getEquipmentLocation());
|
|
|
+ String owner = ownerByEquipment.get(device.getEquipmentId());
|
|
|
+ if (owner != null && !owner.equals(pointId)) row.put("boundPointId", owner);
|
|
|
+ return row;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillEquipmentTypeNames(List<EquipmentBase> devices) {
|
|
|
+ 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())));
|
|
|
+ }
|
|
|
+
|
|
|
+ private long equipmentCount(String pointId) {
|
|
|
+ return equipmentPointRelMapper.selectCount(new LambdaQueryWrapper<EquipmentPointRel>().eq(EquipmentPointRel::getPointId, pointId));
|
|
|
}
|
|
|
}
|