|
|
@@ -7,6 +7,7 @@ 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.enums.MonitorPointTypeEnum;
|
|
|
import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
import com.zksy.base.mapper.EquipmentPointRelMapper;
|
|
|
import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
@@ -37,7 +38,8 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
private EquipmentTypeMapper equipmentTypeMapper;
|
|
|
|
|
|
@Override
|
|
|
- public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName, String associationStatus) {
|
|
|
+ public Page<MonitorPoint> findByPage(long pageNum, long pageSize, String pointCode, String pointName,
|
|
|
+ String associationStatus, Integer pointType) {
|
|
|
Page<MonitorPoint> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
if (pointCode != null && !pointCode.isEmpty()) {
|
|
|
@@ -46,6 +48,9 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
if (pointName != null && !pointName.isEmpty()) {
|
|
|
queryWrapper.like(MonitorPoint::getPointName, pointName);
|
|
|
}
|
|
|
+ if (pointType != null) {
|
|
|
+ queryWrapper.eq(MonitorPoint::getPointType, pointType);
|
|
|
+ }
|
|
|
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());
|
|
|
@@ -64,6 +69,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
|
|
|
@Override
|
|
|
public boolean saveWithCheck(MonitorPoint entity) {
|
|
|
+ validatePointType(entity.getPointType());
|
|
|
LambdaQueryWrapper<MonitorPoint> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(MonitorPoint::getPointCode, entity.getPointCode());
|
|
|
long count = this.count(queryWrapper);
|
|
|
@@ -77,6 +83,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
public boolean saveBatchWithCheck(List<MonitorPoint> entityList) {
|
|
|
Set<String> codeSet = new HashSet<>();
|
|
|
for (MonitorPoint entity : entityList) {
|
|
|
+ validatePointType(entity.getPointType());
|
|
|
String code = entity.getPointCode();
|
|
|
if (codeSet.contains(code)) {
|
|
|
throw new ServiceException("列表中存在重复编码:" + code);
|
|
|
@@ -101,6 +108,7 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
if (this.getById(pointId) == null) {
|
|
|
throw new ServiceException("监测点不存在,无法修改:" + pointId);
|
|
|
}
|
|
|
+ validatePointType(entity.getPointType());
|
|
|
|
|
|
String newCode = entity.getPointCode();
|
|
|
if (newCode != null) {
|
|
|
@@ -243,13 +251,20 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> statistics() {
|
|
|
- List<EquipmentPointRel> relations = equipmentPointRelMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ public Map<String, Object> statistics(Integer pointType) {
|
|
|
+ LambdaQueryWrapper<MonitorPoint> pointWrapper = new LambdaQueryWrapper<>();
|
|
|
+ pointWrapper.eq(pointType != null, MonitorPoint::getPointType, pointType);
|
|
|
+ List<MonitorPoint> points = this.list(pointWrapper);
|
|
|
+ Set<String> pointIds = points.stream().map(MonitorPoint::getPointId).collect(Collectors.toSet());
|
|
|
+ List<EquipmentPointRel> relations = pointIds.isEmpty()
|
|
|
+ ? Collections.emptyList()
|
|
|
+ : equipmentPointRelMapper.selectList(new LambdaQueryWrapper<EquipmentPointRel>()
|
|
|
+ .in(EquipmentPointRel::getPointId, pointIds));
|
|
|
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("totalPoints", points.size());
|
|
|
result.put("linkedPoints", linkedPointIds.size());
|
|
|
- result.put("pendingPoints", Math.max(0, this.count() - linkedPointIds.size()));
|
|
|
+ result.put("pendingPoints", Math.max(0, points.size() - linkedPointIds.size()));
|
|
|
result.put("totalDevices", relations.stream().map(EquipmentPointRel::getEquipmentId).filter(Objects::nonNull).distinct().count());
|
|
|
return result;
|
|
|
}
|
|
|
@@ -289,4 +304,10 @@ public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, Mon
|
|
|
private long equipmentCount(String pointId) {
|
|
|
return equipmentPointRelMapper.selectCount(new LambdaQueryWrapper<EquipmentPointRel>().eq(EquipmentPointRel::getPointId, pointId));
|
|
|
}
|
|
|
+
|
|
|
+ private void validatePointType(Integer pointType) {
|
|
|
+ if (!MonitorPointTypeEnum.isValid(pointType)) {
|
|
|
+ throw new ServiceException("监测点类型无效:" + pointType);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|