|
@@ -28,7 +28,6 @@ import com.zksy.common.exception.ServiceException;
|
|
|
import com.zksy.manhole.dto.in.AlarmMonitorListInDTO;
|
|
import com.zksy.manhole.dto.in.AlarmMonitorListInDTO;
|
|
|
import com.zksy.manhole.dto.in.EquipmentCountByTypeInDTO;
|
|
import com.zksy.manhole.dto.in.EquipmentCountByTypeInDTO;
|
|
|
import com.zksy.manhole.dto.in.EquipmentExportInDTO;
|
|
import com.zksy.manhole.dto.in.EquipmentExportInDTO;
|
|
|
-import com.zksy.manhole.dto.in.ManholeDeviceListInDTO;
|
|
|
|
|
import com.zksy.manhole.dto.in.ManholeDevicePageInDTO;
|
|
import com.zksy.manhole.dto.in.ManholeDevicePageInDTO;
|
|
|
import com.zksy.manhole.dto.in.ManholeDeviceStatisticsInDTO;
|
|
import com.zksy.manhole.dto.in.ManholeDeviceStatisticsInDTO;
|
|
|
import com.zksy.manhole.dto.out.*;
|
|
import com.zksy.manhole.dto.out.*;
|
|
@@ -649,181 +648,6 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
return new BigDecimal(count * 100.0 / total).setScale(1, RoundingMode.HALF_UP);
|
|
return new BigDecimal(count * 100.0 / total).setScale(1, RoundingMode.HALF_UP);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 查询井盖监测设备列表
|
|
|
|
|
- * @param listInDTO
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public Page<EquipmentBaseOutDTO> getManholeDataList(ManholeDeviceListInDTO listInDTO) {
|
|
|
|
|
- log.info("查询井盖监测设备列表-入参:{}", listInDTO);
|
|
|
|
|
- List<String> equipmentIds = null;
|
|
|
|
|
- if(listInDTO.getCurrentStatus() != null || listInDTO.getAlarmStatus() != null || listInDTO.getOnlineStatus() != null){
|
|
|
|
|
- List<EquipmentStatus> equipmentStatusList = equipmentStatusMapper.selectList(new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
|
|
- .eq(listInDTO.getCurrentStatus() != null, EquipmentStatus::getCurrentStatus, listInDTO.getCurrentStatus())
|
|
|
|
|
- .eq(listInDTO.getAlarmStatus() != null, EquipmentStatus::getAlarmStatus, listInDTO.getAlarmStatus())
|
|
|
|
|
- .eq(listInDTO.getOnlineStatus() != null, EquipmentStatus::getOnlineStatus, listInDTO.getOnlineStatus()));
|
|
|
|
|
- if(CollUtil.isEmpty(equipmentStatusList)){
|
|
|
|
|
- return new Page<>(1, 10, 0);
|
|
|
|
|
- }
|
|
|
|
|
- equipmentIds = equipmentStatusList.stream().map(EquipmentStatus::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
- // 仅查询窨井类型设备:排水窨井(equipment_type_id=9)/供水窨井(equipment_type_id=10)
|
|
|
|
|
- List<String> manholeTypeIds = Arrays.asList("5", "9", "10");
|
|
|
|
|
- // 按报警级别过滤时需要 manholeData 参与判定,须全量查出后内存过滤+内存分页
|
|
|
|
|
- boolean needLevelFilter = listInDTO.getAlarmLevel() != null;
|
|
|
|
|
- boolean needManholeData = Boolean.TRUE.equals(listInDTO.getIsQueryManholeData()) || needLevelFilter;
|
|
|
|
|
- LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- queryWrapper.in(EquipmentBase::getEquipmentTypeId, manholeTypeIds)
|
|
|
|
|
- .in(CollUtil.isNotEmpty(equipmentIds), EquipmentBase::getEquipmentId, equipmentIds)
|
|
|
|
|
- .and(StringUtils.isNotBlank(listInDTO.getKeyword()), wrapper -> wrapper
|
|
|
|
|
- .like(EquipmentBase::getEquipmentCode, listInDTO.getKeyword())
|
|
|
|
|
- .or()
|
|
|
|
|
- .like(EquipmentBase::getEquipmentName, listInDTO.getKeyword())
|
|
|
|
|
- .or()
|
|
|
|
|
- .like(EquipmentBase::getEquipmentLocation, listInDTO.getKeyword()))
|
|
|
|
|
- .orderByDesc(EquipmentBase::getUpdateTime);
|
|
|
|
|
-
|
|
|
|
|
- Page<EquipmentBase> rs;
|
|
|
|
|
- if (needLevelFilter) {
|
|
|
|
|
- // 报警级别需基于最新监测数据判定,先全量查询再内存过滤/分页
|
|
|
|
|
- List<EquipmentBase> allList = this.list(queryWrapper);
|
|
|
|
|
- rs = new Page<>(1, Math.max(allList.size(), 1), allList.size());
|
|
|
|
|
- rs.setRecords(allList);
|
|
|
|
|
- } else if (listInDTO.getPageNum() != null && listInDTO.getPageSize() != null) {
|
|
|
|
|
- Page<EquipmentBase> page = new Page<>(listInDTO.getPageNum(), listInDTO.getPageSize());
|
|
|
|
|
- rs = this.page(page, queryWrapper);
|
|
|
|
|
- } else {
|
|
|
|
|
- List<EquipmentBase> allList = this.list(queryWrapper);
|
|
|
|
|
- rs = new Page<>(1, Math.max(allList.size(), 1), allList.size());
|
|
|
|
|
- rs.setRecords(allList);
|
|
|
|
|
- }
|
|
|
|
|
- List<EquipmentBaseOutDTO> outDTOList = BeanUtil.copyToList(rs.getRecords(), EquipmentBaseOutDTO.class);
|
|
|
|
|
- if (CollUtil.isNotEmpty(outDTOList)) {
|
|
|
|
|
- //查询设备类型
|
|
|
|
|
- List<Integer> equipmentTypeIdList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentTypeId).distinct().collect(Collectors.toList());
|
|
|
|
|
- LambdaQueryWrapper<EquipmentType> batchQw = new LambdaQueryWrapper<>();
|
|
|
|
|
- batchQw.in(EquipmentType::getId, equipmentTypeIdList);
|
|
|
|
|
- List<EquipmentType> equipmentTypeList = equipmentTypeMapper.selectList(batchQw);
|
|
|
|
|
- Map<Integer, EquipmentType> equipmentTypeMap = new HashMap<>();
|
|
|
|
|
- if(CollUtil.isNotEmpty(equipmentTypeList)){
|
|
|
|
|
- equipmentTypeMap.putAll(equipmentTypeList.stream().collect(
|
|
|
|
|
- Collectors.toMap(EquipmentType::getId, Function.identity(), (key1, key2) -> key2)));
|
|
|
|
|
- }
|
|
|
|
|
- //查询设备状态
|
|
|
|
|
- List<String> equipmentIdList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
|
|
- List<EquipmentStatus> equipmentStatusList = equipmentStatusMapper.selectList(new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
|
|
- .in(EquipmentStatus::getEquipmentId, equipmentIdList));
|
|
|
|
|
- Map<String, EquipmentStatus> equipmentStatusMap = new HashMap<>();
|
|
|
|
|
- if(CollUtil.isNotEmpty(equipmentStatusList)){
|
|
|
|
|
- equipmentStatusMap.putAll(equipmentStatusList.stream().collect(Collectors.toMap(EquipmentStatus::getEquipmentId, Function.identity(), (key1, key2) -> key2)));
|
|
|
|
|
- }
|
|
|
|
|
- //查询设备监测状态
|
|
|
|
|
- Map<String, List<ManholeData>> imeiCardNumberMapList = new HashMap<>();
|
|
|
|
|
- if(needManholeData){
|
|
|
|
|
- List<String> equipmentCodeList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentCode).distinct().collect(Collectors.toList());
|
|
|
|
|
- List<ManholeData> manholeDataList = manholeDataMapper.selectList(new LambdaQueryWrapper<ManholeData>()
|
|
|
|
|
- .in(ManholeData::getImeiCardNumber, equipmentCodeList)
|
|
|
|
|
- .orderByDesc(ManholeData::getCreateTime));
|
|
|
|
|
- imeiCardNumberMapList.putAll(manholeDataList.stream().collect(Collectors.groupingBy(ManholeData::getImeiCardNumber)));
|
|
|
|
|
- }
|
|
|
|
|
- List<ManholeData> manholeDataList = null;
|
|
|
|
|
- for(EquipmentBaseOutDTO outDTO : outDTOList) {
|
|
|
|
|
- EquipmentType equipmentType = equipmentTypeMap.get(outDTO.getEquipmentTypeId());
|
|
|
|
|
- if(equipmentType != null){
|
|
|
|
|
- outDTO.setEquipmentTypeName(equipmentType.getTypeName());
|
|
|
|
|
- }
|
|
|
|
|
- EquipmentStatus equipmentStatus = equipmentStatusMap.get(outDTO.getEquipmentId());
|
|
|
|
|
- if(equipmentStatus != null){
|
|
|
|
|
- EquipmentStatusOutDTO equipmentStatusOutDTO = BeanUtil.copyProperties(equipmentStatus, EquipmentStatusOutDTO.class);
|
|
|
|
|
- outDTO.setEquipmentStatus(equipmentStatusOutDTO);
|
|
|
|
|
- }
|
|
|
|
|
- if(needManholeData){
|
|
|
|
|
- manholeDataList = imeiCardNumberMapList.get(outDTO.getEquipmentCode());
|
|
|
|
|
- if(CollUtil.isNotEmpty(manholeDataList)){
|
|
|
|
|
- ManholeData manholeData = manholeDataList.get(0);
|
|
|
|
|
- ManholeDataOutDTO manholeDataOutDTO = BeanUtil.copyProperties(manholeData, ManholeDataOutDTO.class);
|
|
|
|
|
- outDTO.setManholeData(manholeDataOutDTO);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- long total;
|
|
|
|
|
- List<EquipmentBaseOutDTO> pageRecords;
|
|
|
|
|
- if (needLevelFilter) {
|
|
|
|
|
- // 内存过滤报警级别
|
|
|
|
|
- List<EquipmentBaseOutDTO> filteredList = outDTOList.stream()
|
|
|
|
|
- .filter(dto -> matchAlarmLevel(dto, listInDTO.getAlarmLevel()))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- total = filteredList.size();
|
|
|
|
|
- pageRecords = applyPage(filteredList, listInDTO.getPageNum(), listInDTO.getPageSize());
|
|
|
|
|
- } else {
|
|
|
|
|
- total = rs.getTotal();
|
|
|
|
|
- pageRecords = outDTOList;
|
|
|
|
|
- }
|
|
|
|
|
- long pageSize = listInDTO.getPageSize() != null ? listInDTO.getPageSize()
|
|
|
|
|
- : (total > 0 ? total : 1);
|
|
|
|
|
- Page<EquipmentBaseOutDTO> outPage = new Page<>(listInDTO.getPageNum() != null ? listInDTO.getPageNum() : 1, pageSize, total);
|
|
|
|
|
- outPage.setRecords(pageRecords);
|
|
|
|
|
- return outPage;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 报警级别判定(与前端 buildAlertInfo 保持一致):
|
|
|
|
|
- * 严重报警(1):设备报警状态=1 或 水位/水浸报警;
|
|
|
|
|
- * 一般报警(2):非严重报警且 低电量(<=20%)或 弱信号(<=20%);
|
|
|
|
|
- * 有报警(0):严重报警或一般报警的并集;不传则不过滤。
|
|
|
|
|
- */
|
|
|
|
|
- private boolean matchAlarmLevel(EquipmentBaseOutDTO dto, Integer alarmLevel) {
|
|
|
|
|
- if (alarmLevel == null) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- boolean isCritical = (dto.getEquipmentStatus() != null
|
|
|
|
|
- && Integer.valueOf(1).equals(dto.getEquipmentStatus().getAlarmStatus()))
|
|
|
|
|
- || (dto.getManholeData() != null
|
|
|
|
|
- && ("1".equals(dto.getManholeData().getWaterLevelAlarmStatus())
|
|
|
|
|
- || "1".equals(dto.getManholeData().getWaterInfiltrationAlarmStatus())));
|
|
|
|
|
- if (Integer.valueOf(1).equals(alarmLevel)) {
|
|
|
|
|
- return isCritical;
|
|
|
|
|
- }
|
|
|
|
|
- if (dto.getManholeData() == null) {
|
|
|
|
|
- return Integer.valueOf(0).equals(alarmLevel) && isCritical;
|
|
|
|
|
- }
|
|
|
|
|
- boolean lowBattery = dto.getManholeData().getBatteryLevel() != null
|
|
|
|
|
- && toInt(dto.getManholeData().getBatteryLevel()) <= 20;
|
|
|
|
|
- boolean weakSignal = dto.getManholeData().getSignalStrength() != null
|
|
|
|
|
- && toInt(dto.getManholeData().getSignalStrength()) <= 20;
|
|
|
|
|
- boolean hasAlarm = isCritical || lowBattery || weakSignal;
|
|
|
|
|
- if (Integer.valueOf(0).equals(alarmLevel)) {
|
|
|
|
|
- return hasAlarm;
|
|
|
|
|
- }
|
|
|
|
|
- // alarmLevel = 2:一般报警
|
|
|
|
|
- return hasAlarm && !isCritical;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private int toInt(String value) {
|
|
|
|
|
- try {
|
|
|
|
|
- return (int) Double.parseDouble(value.trim());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 内存分页(报警级别过滤后使用)
|
|
|
|
|
- */
|
|
|
|
|
- private List<EquipmentBaseOutDTO> applyPage(List<EquipmentBaseOutDTO> list, Long pageNum, Long pageSize) {
|
|
|
|
|
- if (pageNum == null || pageSize == null) {
|
|
|
|
|
- return list;
|
|
|
|
|
- }
|
|
|
|
|
- int start = (int) ((pageNum - 1) * pageSize);
|
|
|
|
|
- if (start >= list.size()) {
|
|
|
|
|
- return new ArrayList<>();
|
|
|
|
|
- }
|
|
|
|
|
- int end = (int) Math.min(start + pageSize, list.size());
|
|
|
|
|
- return new ArrayList<>(list.subList(start, end));
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 窨井盖实时监测-设备报警监控列表
|
|
* 窨井盖实时监测-设备报警监控列表
|