From 5d36e1f987ef21e44ded2e8a1d06c28094ec1e76 Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期六, 19 四月 2025 12:39:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 zhitan-system/src/main/java/com/zhitan/alarm/services/impl/HistoryAlarmServiceImpl.java |  180 +++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 124 insertions(+), 56 deletions(-)

diff --git a/zhitan-system/src/main/java/com/zhitan/alarm/services/impl/HistoryAlarmServiceImpl.java b/zhitan-system/src/main/java/com/zhitan/alarm/services/impl/HistoryAlarmServiceImpl.java
index 9b16045..da5e081 100644
--- a/zhitan-system/src/main/java/com/zhitan/alarm/services/impl/HistoryAlarmServiceImpl.java
+++ b/zhitan-system/src/main/java/com/zhitan/alarm/services/impl/HistoryAlarmServiceImpl.java
@@ -1,5 +1,9 @@
 package com.zhitan.alarm.services.impl;
 
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zhitan.alarm.domain.HistoryAlarm;
 import com.zhitan.alarm.domain.JkHistoryAlarm;
@@ -8,83 +12,147 @@
 import com.zhitan.basicdata.domain.MeterImplement;
 import com.zhitan.basicdata.mapper.MeterImplementMapper;
 import com.zhitan.common.enums.TimeType;
+import com.zhitan.common.utils.DateUtils;
+import com.zhitan.common.utils.PageUtils;
 import com.zhitan.common.utils.StringUtils;
 import com.zhitan.model.domain.EnergyIndex;
+import com.zhitan.model.domain.ModelNode;
+import com.zhitan.model.domain.NodeIndex;
+import com.zhitan.model.domain.vo.ModelNodeIndexInfo;
 import com.zhitan.model.mapper.EnergyIndexMapper;
+import com.zhitan.model.mapper.ModelNodeMapper;
+import com.zhitan.model.mapper.NodeIndexMapper;
+import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
+
+@AllArgsConstructor
 
 @Service
 public class HistoryAlarmServiceImpl implements IHistoryAlarmService {
 
-  @Autowired
-  private HistoryAlarmMapper historyAlarmMapper;
+    @Resource
+    private HistoryAlarmMapper historyAlarmMapper;
 
-  @Autowired
-  private MeterImplementMapper meterImplementMapper;
+    @Resource
+    private MeterImplementMapper meterImplementMapper;
 
-  @Autowired
-  private EnergyIndexMapper energyIndexMapper;
+    @Resource
+    private ModelNodeMapper modelNodeMapper;
+    @Resource
+    private NodeIndexMapper nodeIndexMapper;
+    @Resource
+    private EnergyIndexMapper energyIndexMapper;
 
 
-  @Override
-  public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime) {
-    return null;
-  }
+    @Override
+    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime) {
+        return null;
+    }
 
-  @Override
-  public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, TimeType timeType) {
-    return null;
-  }
+    @Override
+    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, TimeType timeType) {
+        return null;
+    }
 
-  @Override
-  public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, String alarmType) {
-    return null;
-  }
+    @Override
+    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, String alarmType) {
+        return null;
+    }
 
-  @Override
-  public List<JkHistoryAlarm> selectJkHistoryAlarmList(JkHistoryAlarm jkHistoryAlarm) {
-    return historyAlarmMapper.selectJkHistoryAlarmList(jkHistoryAlarm);
-  }
+    @Override
+    public List<JkHistoryAlarm> selectJkHistoryAlarmList(JkHistoryAlarm jkHistoryAlarm) {
+        return historyAlarmMapper.selectJkHistoryAlarmList(jkHistoryAlarm);
+    }
 
-  @Override
-  public List<JkHistoryAlarm> selectJkHistoryAlarmListExcel(JkHistoryAlarm jkHistoryAlarm) {
-    return historyAlarmMapper.selectJkHistoryAlarmListExcel(jkHistoryAlarm);
-  }
+    @Override
+    public List<JkHistoryAlarm> selectJkHistoryAlarmListExcel(JkHistoryAlarm jkHistoryAlarm) {
+        return historyAlarmMapper.selectJkHistoryAlarmListExcel(jkHistoryAlarm);
+    }
 
-  /**
-   * 瀹炴椂妫�娴� 鍔熻兘 鐨勫 sheet椤�  灞曠ず 缁勬�佸浘  娴嬬偣 鎶ヨ淇℃伅
-   *
-   * @param jkHistoryAlarm
-   * @return
-   */
-  @Override
-  public List<JkHistoryAlarm> selectHistoryAlarmNoteList(JkHistoryAlarm jkHistoryAlarm) {
-    return historyAlarmMapper.selectHistoryAlarmNoteList(jkHistoryAlarm);
-  }
+    /**
+     * 瀹炴椂妫�娴� 鍔熻兘 鐨勫 sheet椤�  灞曠ず 缁勬�佸浘  娴嬬偣 鎶ヨ淇℃伅
+     *
+     * @param jkHistoryAlarm
+     * @return
+     */
+    @Override
+    public List<JkHistoryAlarm> selectHistoryAlarmNoteList(JkHistoryAlarm jkHistoryAlarm) {
+        return historyAlarmMapper.selectHistoryAlarmNoteList(jkHistoryAlarm);
+    }
 
-  @Override
-  public void updateHistoryAlarm(String alarmCode, HistoryAlarm historyAlarm) {
-    historyAlarmMapper.updateHistoryAlarm(alarmCode, historyAlarm);
-  }
+    @Override
+    public void updateHistoryAlarm(String alarmCode, HistoryAlarm historyAlarm) {
+        historyAlarmMapper.updateHistoryAlarm(alarmCode, historyAlarm);
+    }
 
-  @Override
-  public Page<JkHistoryAlarm> selectJkHistoryAlarmPage(JkHistoryAlarm jkHistoryAlarm, Long pageNum, Long pageSize) {
-    final Page<JkHistoryAlarm> jkHistoryAlarmPage = historyAlarmMapper.selectJkHistoryAlarmPage(jkHistoryAlarm, new Page<>(pageNum, pageSize));
-    jkHistoryAlarmPage.getRecords().forEach(alarm->{
-      final String indexType = alarm.getIndexType();
-      final String indexId = alarm.getIndexId();
-      if("COLLECT".equals(indexType) && StringUtils.isEmpty(alarm.getEnergyId())){
-        //鏍规嵁nodeId鍜宨ndexId 鍘绘煡璇㈣閲忓櫒鍏�
-        EnergyIndex energyIndex = energyIndexMapper.selectEnergyIndexById(indexId);
-        final MeterImplement meterImplement = meterImplementMapper.selectMeterImplementById(energyIndex.getMeterId());
-        alarm.setEnergyId(meterImplement.getEnergyType());
-      }
-    });
-    return jkHistoryAlarmPage;
-  }
-  
+    /**
+     * 鑾峰彇鍘嗗彶鎶ヨ鍒嗛〉鏁版嵁
+     *
+     * @param historyAlarm
+     * @return
+     */
+    @Override
+    public Page<JkHistoryAlarm> selectHistoryAlarmPageList(JkHistoryAlarm historyAlarm) {
+        Page<JkHistoryAlarm> pageInfo = PageUtils.getPageInfo(JkHistoryAlarm.class);
+
+        List<String> indexIdList = new ArrayList<>();
+        if ("ALL".equals(historyAlarm.getEierarchyFlag())) {
+
+            ModelNode modelNode = modelNodeMapper.selectModelNodeById(historyAlarm.getNodeId());
+            List<ModelNodeIndexInfo> modelNodeIndexInfoList =
+                    modelNodeMapper.getAllModelNodeIndexByAddress(modelNode.getModelCode(), modelNode.getAddress());
+            if (StringUtils.isNotEmpty(historyAlarm.getIndexName())) {
+                modelNodeIndexInfoList = modelNodeIndexInfoList.stream()
+                        .filter(modelNodeIndexInfo -> modelNodeIndexInfo.getIndexName().contains(historyAlarm.getIndexName()))
+                        .collect(Collectors.toList());
+            }
+            if (ObjectUtils.isNotEmpty(historyAlarm.getIndexType())) {
+                modelNodeIndexInfoList = modelNodeIndexInfoList.stream()
+                        .filter(modelNodeIndexInfo -> historyAlarm.getIndexType().equals(modelNodeIndexInfo.getIndexType()))
+                        .collect(Collectors.toList());
+            }
+            indexIdList = modelNodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toList());
+
+        } else {
+
+            LambdaQueryWrapper<NodeIndex> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(NodeIndex::getNodeId, historyAlarm.getNodeId());
+            List<NodeIndex> nodeIndexList = nodeIndexMapper.selectList(queryWrapper);
+            List<String> allIndexIdList = nodeIndexList.stream().map(NodeIndex::getIndexId).collect(Collectors.toList());
+            if (ObjectUtils.isNotEmpty(allIndexIdList)) {
+                List<EnergyIndex> indexList = energyIndexMapper.selectEnergyIndexByIds(allIndexIdList);
+                if (ObjectUtils.isNotEmpty(historyAlarm.getIndexName())) {
+                    indexList = indexList.stream().filter(energyIndex -> energyIndex.getName().contains(historyAlarm.getIndexName())).collect(Collectors.toList());
+                }
+                if (ObjectUtils.isNotEmpty(historyAlarm.getIndexType())) {
+                    indexList = indexList.stream().filter(energyIndex -> historyAlarm.getIndexType().equals(energyIndex.getIndexTypeCode())).collect(Collectors.toList());
+                }
+                indexIdList = indexList.stream().map(EnergyIndex::getIndexId).collect(Collectors.toList());
+            }
+        }
+
+        if (ObjectUtils.isEmpty(indexIdList)) {
+            return pageInfo;
+        }
+
+        //鏃堕棿澶勭悊 濡傛灉涓嶄紶鏃堕棿榛樿鏌ヨ褰撳ぉ鐨勬暟鎹�
+        Date endTime = DateUtils.parseDate(historyAlarm.getEndTime());
+        if (ObjectUtils.isEmpty(endTime)) {
+            endTime = DateUtil.endOfDay(DateUtils.getNowDate());
+        }
+        Date beginTime = DateUtils.parseDate(historyAlarm.getBeginTime());
+        if (ObjectUtils.isEmpty(beginTime)) {
+            beginTime = DateUtil.beginOfDay(DateUtils.getNowDate());
+        }
+
+        return historyAlarmMapper.getHistoryAlarmList(beginTime, endTime,indexIdList, pageInfo);
+    }
+
 }

--
Gitblit v1.9.3