|
|
@@ -5,14 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zksy.base.domain.EquipmentBase;
|
|
|
-import com.zksy.base.domain.EquipmentMaintain;
|
|
|
-import com.zksy.base.domain.EquipmentStatus;
|
|
|
-import com.zksy.base.domain.EquipmentType;
|
|
|
-import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentMaintainMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
+import com.zksy.base.domain.*;
|
|
|
+import com.zksy.base.mapper.*;
|
|
|
+import com.zksy.base.alarm.domain.WarningThreshold;
|
|
|
+import com.zksy.base.alarm.mapper.WarningThresholdMapper;
|
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
|
import com.zksy.common.exception.ServiceException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -20,9 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -39,13 +34,19 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
@Autowired
|
|
|
private EquipmentStatusMapper equipmentStatusMapper;
|
|
|
|
|
|
-// @Autowired
|
|
|
-// private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
+ @Autowired
|
|
|
+ private EquipmentPointRelMapper equipmentPointRelMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquipmentTestMapper equipmentTestMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WarningThresholdMapper warningThresholdMapper;
|
|
|
|
|
|
@Override
|
|
|
public Page<EquipmentBase> findByPage(long pageNum, long pageSize,
|
|
|
- String equipmentCode,String equipmentName,
|
|
|
- String equipmentModel,String manufacturer) {
|
|
|
+ String equipmentCode, String equipmentName,
|
|
|
+ String equipmentModel, String manufacturer) {
|
|
|
Page<EquipmentBase> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
if (equipmentCode != null && !equipmentCode.isEmpty()) {
|
|
|
@@ -60,22 +61,17 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
if (manufacturer != null && !manufacturer.isEmpty()) {
|
|
|
queryWrapper.like(EquipmentBase::getManufacturer, manufacturer);
|
|
|
}
|
|
|
+ queryWrapper.orderByDesc(EquipmentBase::getCreateTime);
|
|
|
return this.page(page, queryWrapper);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增仪器信息
|
|
|
- * @param entity
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
public boolean saveWithCheck(EquipmentBase entity) {
|
|
|
String equipmentTypeId = entity.getEquipmentTypeId();
|
|
|
EquipmentType equipmentType = equipmentTypeMapper.selectById(equipmentTypeId);
|
|
|
- if(equipmentType==null){
|
|
|
+ if (equipmentType == null) {
|
|
|
throw new ServiceException("设备类型不存在,请检查equipment_type_id:");
|
|
|
}
|
|
|
- //校验设备编码是否已存在
|
|
|
LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(EquipmentBase::getEquipmentCode, entity.getEquipmentCode());
|
|
|
long count = this.count(queryWrapper);
|
|
|
@@ -85,15 +81,8 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
return this.save(entity);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 批量新增
|
|
|
- * @param entityList
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
public boolean saveBatchWithCheck(List<EquipmentBase> entityList) {
|
|
|
-
|
|
|
- //是否有重复编码
|
|
|
Set<String> codeSet = new HashSet<>();
|
|
|
for (EquipmentBase entity : entityList) {
|
|
|
String code = entity.getEquipmentCode();
|
|
|
@@ -103,93 +92,81 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
codeSet.add(code);
|
|
|
}
|
|
|
|
|
|
- //校验
|
|
|
for (EquipmentBase entity : entityList) {
|
|
|
- //校验设备类型是否存在
|
|
|
if (equipmentTypeMapper.selectById(entity.getEquipmentTypeId()) == null) {
|
|
|
throw new ServiceException("设备类型不存在:" + entity.getEquipmentTypeId());
|
|
|
}
|
|
|
- //校验设备编码是否已存在
|
|
|
LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(EquipmentBase::getEquipmentCode, entity.getEquipmentCode());
|
|
|
if (this.count(wrapper) > 0) {
|
|
|
throw new ServiceException("设备编码已存在:" + entity.getEquipmentCode());
|
|
|
}
|
|
|
}
|
|
|
- //保存
|
|
|
return this.saveBatch(entityList);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 修改仪器信息
|
|
|
- * @param entity
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean updateWithCheck(EquipmentBase entity) {
|
|
|
- //设备是否存在
|
|
|
String equipmentId = entity.getEquipmentId();
|
|
|
if (this.getById(equipmentId) == null) {
|
|
|
throw new ServiceException("设备不存在,无法修改:" + equipmentId);
|
|
|
}
|
|
|
|
|
|
- //修改设备类型ID,需要校验新类型是否存在
|
|
|
String newTypeId = entity.getEquipmentTypeId();
|
|
|
if (newTypeId != null && equipmentTypeMapper.selectById(newTypeId) == null) {
|
|
|
throw new ServiceException("设备类型不存在:" + newTypeId);
|
|
|
}
|
|
|
|
|
|
- //修改设备编码,需要校验新编码是否已被使用
|
|
|
String newCode = entity.getEquipmentCode();
|
|
|
if (newCode != null) {
|
|
|
LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(EquipmentBase::getEquipmentCode, newCode)
|
|
|
- .ne(EquipmentBase::getEquipmentId, equipmentId); // 排除自身
|
|
|
+ .ne(EquipmentBase::getEquipmentId, equipmentId);
|
|
|
if (this.count(wrapper) > 0) {
|
|
|
throw new ServiceException("设备编码已被使用:" + newCode);
|
|
|
}
|
|
|
}
|
|
|
- //修改
|
|
|
return this.updateById(entity);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除设备基础信息
|
|
|
- * @param equipmentId
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean removeWithCheck(String equipmentId) {
|
|
|
- //校验设备是否存在
|
|
|
EquipmentBase equipment = this.getById(equipmentId);
|
|
|
if (equipment == null) {
|
|
|
throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
}
|
|
|
|
|
|
- //删除关联的维护记录
|
|
|
LambdaQueryWrapper<EquipmentMaintain> maintainWrapper = new LambdaQueryWrapper<>();
|
|
|
maintainWrapper.eq(EquipmentMaintain::getEquipmentId, equipmentId);
|
|
|
equipmentMaintainMapper.delete(maintainWrapper);
|
|
|
log.info("已删除设备[{}]的维护记录", equipmentId);
|
|
|
|
|
|
- //删除关联的状态记录
|
|
|
LambdaQueryWrapper<EquipmentStatus> statusWrapper = new LambdaQueryWrapper<>();
|
|
|
statusWrapper.eq(EquipmentStatus::getEquipmentId, equipmentId);
|
|
|
equipmentStatusMapper.delete(statusWrapper);
|
|
|
log.info("已删除设备[{}]的状态记录", equipmentId);
|
|
|
|
|
|
- //删除设备
|
|
|
- boolean deleted = this.baseMapper.deleteById(equipmentId) > 0;
|
|
|
- return deleted;
|
|
|
+ LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
+ relWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
|
+ equipmentPointRelMapper.delete(relWrapper);
|
|
|
+ log.info("已删除设备[{}]的监测点关联", equipmentId);
|
|
|
+
|
|
|
+ // 现在 WarningThreshold 有了 equipmentId 字段,直接匹配
|
|
|
+ LambdaQueryWrapper<WarningThreshold> thresholdWrapper = new LambdaQueryWrapper<>();
|
|
|
+ thresholdWrapper.eq(WarningThreshold::getEquipmentId, equipmentId);
|
|
|
+ warningThresholdMapper.delete(thresholdWrapper);
|
|
|
+ log.info("已删除设备[{}]的预警阈值配置", equipmentId);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentTest> testWrapper = new LambdaQueryWrapper<>();
|
|
|
+ testWrapper.eq(EquipmentTest::getEquipmentId, equipmentId);
|
|
|
+ equipmentTestMapper.delete(testWrapper);
|
|
|
+ log.info("已删除设备[{}]的测试记录", equipmentId);
|
|
|
+
|
|
|
+ return this.baseMapper.deleteById(equipmentId) > 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设备基础信息批量删除
|
|
|
- * @param equipmentIds
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean removeBatchWithCheck(List<String> equipmentIds) {
|
|
|
@@ -197,16 +174,14 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
throw new ServiceException("批量删除失败:设备ID列表不能为空");
|
|
|
}
|
|
|
|
|
|
- //校验设备是否存在
|
|
|
List<EquipmentBase> existEquipments = this.listByIds(equipmentIds);
|
|
|
if (existEquipments.isEmpty()) {
|
|
|
throw new ServiceException("批量删除失败:所有设备ID均不存在");
|
|
|
}
|
|
|
- // 提取存在的设备ID
|
|
|
List<String> existIds = existEquipments.stream()
|
|
|
.map(EquipmentBase::getEquipmentId)
|
|
|
.collect(Collectors.toList());
|
|
|
- //无效ID
|
|
|
+
|
|
|
List<String> invalidIds = equipmentIds.stream()
|
|
|
.filter(id -> !existIds.contains(id))
|
|
|
.collect(Collectors.toList());
|
|
|
@@ -214,19 +189,140 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
log.warn("批量删除中存在无效设备ID:{}", invalidIds);
|
|
|
}
|
|
|
|
|
|
- //批量删除关联的维护记录
|
|
|
LambdaQueryWrapper<EquipmentMaintain> maintainWrapper = new LambdaQueryWrapper<>();
|
|
|
maintainWrapper.in(EquipmentMaintain::getEquipmentId, existIds);
|
|
|
equipmentMaintainMapper.delete(maintainWrapper);
|
|
|
log.info("已批量删除{}条设备的维护记录", existIds.size());
|
|
|
|
|
|
- //批量删除关联的状态记录
|
|
|
LambdaQueryWrapper<EquipmentStatus> statusWrapper = new LambdaQueryWrapper<>();
|
|
|
statusWrapper.in(EquipmentStatus::getEquipmentId, existIds);
|
|
|
equipmentStatusMapper.delete(statusWrapper);
|
|
|
log.info("已批量删除{}条设备的状态记录", existIds.size());
|
|
|
- //删除
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
+ relWrapper.in(EquipmentPointRel::getEquipmentId, existIds);
|
|
|
+ equipmentPointRelMapper.delete(relWrapper);
|
|
|
+ log.info("已批量删除{}条设备的监测点关联", existIds.size());
|
|
|
+
|
|
|
+ // 现在 WarningThreshold 有了 equipmentId 字段,直接匹配
|
|
|
+ LambdaQueryWrapper<WarningThreshold> thresholdWrapper = new LambdaQueryWrapper<>();
|
|
|
+ thresholdWrapper.in(WarningThreshold::getEquipmentId, existIds);
|
|
|
+ warningThresholdMapper.delete(thresholdWrapper);
|
|
|
+ log.info("已批量删除{}条设备的预警阈值配置", existIds.size());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentTest> testWrapper = new LambdaQueryWrapper<>();
|
|
|
+ testWrapper.in(EquipmentTest::getEquipmentId, existIds);
|
|
|
+ equipmentTestMapper.delete(testWrapper);
|
|
|
+ log.info("已批量删除{}条设备的测试记录", existIds.size());
|
|
|
+
|
|
|
return this.removeByIds(existIds);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean updateEquipmentStatus(String equipmentId, Integer currentStatus) {
|
|
|
+ EquipmentBase equipment = this.getById(equipmentId);
|
|
|
+ if (equipment == null) {
|
|
|
+ throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentStatus> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(EquipmentStatus::getEquipmentId, equipmentId);
|
|
|
+ EquipmentStatus status = equipmentStatusMapper.selectOne(wrapper);
|
|
|
+
|
|
|
+ if (status == null) {
|
|
|
+ status = new EquipmentStatus();
|
|
|
+ status.setEquipmentId(equipmentId);
|
|
|
+ status.setCurrentStatus(currentStatus);
|
|
|
+ status.setAlarmStatus(0);
|
|
|
+ status.setOnlineStatus(1);
|
|
|
+ status.setStatusUpdateTime(LocalDateTime.now());
|
|
|
+ return equipmentStatusMapper.insert(status) > 0;
|
|
|
+ } else {
|
|
|
+ status.setCurrentStatus(currentStatus);
|
|
|
+ status.setStatusUpdateTime(LocalDateTime.now());
|
|
|
+ return equipmentStatusMapper.updateById(status) > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean testEquipment(String equipmentId, String testType, String testDetail, String testUser) {
|
|
|
+ EquipmentBase equipment = this.getById(equipmentId);
|
|
|
+ if (equipment == null) {
|
|
|
+ throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ EquipmentTest test = new EquipmentTest();
|
|
|
+ test.setEquipmentId(equipmentId);
|
|
|
+ test.setTestType(testType);
|
|
|
+ test.setTestResult("SUCCESS");
|
|
|
+ test.setTestDetail(testDetail);
|
|
|
+ test.setTestTime(LocalDateTime.now());
|
|
|
+ test.setTestUser(testUser);
|
|
|
+ return equipmentTestMapper.insert(test) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getEquipmentDetail(String equipmentId) {
|
|
|
+ EquipmentBase equipment = this.getById(equipmentId);
|
|
|
+ if (equipment == null) {
|
|
|
+ throw new ServiceException("设备不存在:" + equipmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("equipmentInfo", equipment);
|
|
|
+
|
|
|
+ if (equipment.getEquipmentTypeId() != null) {
|
|
|
+ EquipmentType type = equipmentTypeMapper.selectById(equipment.getEquipmentTypeId());
|
|
|
+ result.put("typeInfo", type);
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentStatus> statusWrapper = new LambdaQueryWrapper<>();
|
|
|
+ statusWrapper.eq(EquipmentStatus::getEquipmentId, equipmentId);
|
|
|
+ EquipmentStatus status = equipmentStatusMapper.selectOne(statusWrapper);
|
|
|
+ result.put("statusInfo", status);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentMaintain> maintainWrapper = new LambdaQueryWrapper<>();
|
|
|
+ maintainWrapper.eq(EquipmentMaintain::getEquipmentId, equipmentId);
|
|
|
+ maintainWrapper.orderByDesc(EquipmentMaintain::getMaintainDate);
|
|
|
+ List<EquipmentMaintain> maintainList = equipmentMaintainMapper.selectList(maintainWrapper);
|
|
|
+ result.put("maintainList", maintainList);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
+ relWrapper.eq(EquipmentPointRel::getEquipmentId, equipmentId);
|
|
|
+ List<EquipmentPointRel> relList = equipmentPointRelMapper.selectList(relWrapper);
|
|
|
+ result.put("pointRelList", relList);
|
|
|
+
|
|
|
+ // 现在 WarningThreshold 有了 equipmentId 字段,直接匹配
|
|
|
+ LambdaQueryWrapper<WarningThreshold> thresholdWrapper = new LambdaQueryWrapper<>();
|
|
|
+ thresholdWrapper.eq(WarningThreshold::getEquipmentId, equipmentId);
|
|
|
+ List<WarningThreshold> thresholdList = warningThresholdMapper.selectList(thresholdWrapper);
|
|
|
+ result.put("thresholdList", thresholdList);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<EquipmentTest> testWrapper = new LambdaQueryWrapper<>();
|
|
|
+ testWrapper.eq(EquipmentTest::getEquipmentId, equipmentId);
|
|
|
+ testWrapper.orderByDesc(EquipmentTest::getTestTime);
|
|
|
+ List<EquipmentTest> testList = equipmentTestMapper.selectList(testWrapper);
|
|
|
+ result.put("testList", testList);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EquipmentBase> getEquipmentByPoint(String pointId) {
|
|
|
+ LambdaQueryWrapper<EquipmentPointRel> relWrapper = new LambdaQueryWrapper<>();
|
|
|
+ relWrapper.eq(EquipmentPointRel::getPointId, pointId);
|
|
|
+ List<EquipmentPointRel> relList = equipmentPointRelMapper.selectList(relWrapper);
|
|
|
+
|
|
|
+ if (relList.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> equipmentIds = relList.stream()
|
|
|
+ .map(EquipmentPointRel::getEquipmentId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return this.listByIds(equipmentIds);
|
|
|
+ }
|
|
|
}
|