Procházet zdrojové kódy

修改DateUtils工具类

宁檬 před 1 rokem
rodič
revize
16f3ed3c86

+ 5 - 1
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/controller/goodness/StationAnalysisController.java

@@ -1,5 +1,6 @@
 package com.gyee.runeconomy.controller.goodness;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gyee.common.model.StringUtils;
 import com.gyee.runeconomy.dto.R;
 import com.gyee.runeconomy.dto.ResultMsg;
@@ -61,11 +62,14 @@ public class StationAnalysisController {
     public R inverterAnalysis(@RequestParam(value = "companys", required = true) String companys,
                               @RequestParam(value = "type", required = true) String type,
                               @RequestParam(value = "wpid", required = true) String wpid,
+                              @RequestParam(value = "pageSize", required = true) Long pageSize,
+                              @RequestParam(value = "pageNum", required = true) Long pageNum,
                               @RequestParam(value = "target", required = false) String target,
                               @RequestParam(value = "sort", required = false) String sort
+
     ) throws Exception {
 
-        Map<String, List<InverterAnalysis>> resultList = windturbinegoodnessService.inverterAnalysis(companys, type, wpid, target, sort);
+        Map<String, Page<InverterAnalysis>> resultList = windturbinegoodnessService.inverterAnalysis(companys, type, wpid, pageSize, pageNum, target, sort);
 
         if (com.gyee.common.model.StringUtils.isNotNull(resultList)) {
             return R.data(ResultMsg.ok(resultList));

+ 65 - 1
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/dto/response/InverterAnalysis.java

@@ -2,9 +2,18 @@ package com.gyee.runeconomy.dto.response;
 
 import lombok.Data;
 
-@Data
 public class InverterAnalysis {
     /**
+     * 逆变器id
+     */
+    private String inverterId;
+
+    /**
+     * 逆变器名称
+     */
+    private String inverterName;
+
+    /**
      * 输入功率
      */
     private Double inputPower;
@@ -23,4 +32,59 @@ public class InverterAnalysis {
      * 转换率
      */
     private Double conversionRate;
+
+    public String getInverterId() {
+        return inverterId;
+    }
+
+    public void setInverterId(String inverterId) {
+        this.inverterId = inverterId;
+    }
+
+    public String getInverterName() {
+        return inverterName;
+    }
+
+    public void setInverterName(String inverterName) {
+        this.inverterName = inverterName;
+    }
+
+    public Double getInputPower() {
+        return inputPower;
+    }
+
+    public void setInputPower(Double inputPower) {
+        if (inputPower == null) {
+            this.inputPower = 0.0;
+        }
+
+    }
+
+    public Double getOutputPower() {
+        return outputPower;
+    }
+
+    public void setOutputPower(Double outputPower) {
+        if (inputPower == null) {
+            this.inputPower = 0.0;
+        }
+    }
+
+    public Double getInputVoltage() {
+        return inputVoltage;
+    }
+
+    public void setInputVoltage(Double inputVoltage) {
+        if (inputPower == null) {
+            this.inputPower = 0.0;
+        }
+    }
+
+    public Double getConversionRate() {
+        return conversionRate;
+    }
+
+    public void setConversionRate(Double conversionRate) {
+        this.conversionRate = conversionRate;
+    }
 }

+ 58 - 26
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/service/goodness/WindturbinegoodnessService.java

@@ -19,6 +19,7 @@ import com.gyee.runeconomy.util.DateUtils;
 import com.gyee.runeconomy.util.StringUtils;
 import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -27,6 +28,7 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @ClassName : WindturbinegoodnessService
@@ -1079,38 +1081,68 @@ public class WindturbinegoodnessService {
     /**
      * 逆变器分析
      */
-    public Map<String, List<InverterAnalysis>> inverterAnalysis(String companys, String type, String wpid, String target, String sort) throws Exception {
-        Map<String, List<InverterAnalysis>> resultMap = new HashMap<>();
-        List<InverterAnalysis> lias = new ArrayList<>();
-        InverterAnalysis ia = new InverterAnalysis();
-        Optional<ProBasicEquipmentPoint> srg = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "AIG010".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).findFirst();
-        String srgl = null;
-        if (srg.isPresent()) {
-            srgl = srg.get().getNemCode();
+    public Map<String, Page<InverterAnalysis>> inverterAnalysis(String companys, String type, String wpid, long pageSize, long pageNum, String target, String sort) throws Exception {
+        Map<String, Page<InverterAnalysis>> resultMap = new HashMap<>();
+        if ("-1".equals(type)) {
+            resultMap.put("list", new Page<>());
+            resultMap.put("chanrt", new Page<>());
+            return resultMap;
         }
-        PointData realSrgData = edosUtil.getRealData(srgl);
-        ia.setInputPower(realSrgData.getPointValueInDouble());
+        List<InverterAnalysis> lias = new ArrayList<>();
 
-        Optional<ProBasicEquipmentPoint> scg = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "AIG007".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).findFirst();
-        String scgl = null;
-        if (scg.isPresent()) {
-            scgl = scg.get().getNemCode();
+        List<ProBasicEquipmentPoint> srg = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "AIG010".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).collect(Collectors.toList());
+
+        List<ProBasicEquipmentPoint> scg = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "AIG007".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).collect(Collectors.toList());
+
+        List<ProBasicEquipmentPoint> srd = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "DIHW050".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).collect(Collectors.toList());
+        if (srd.size() == 0) {
+            srd = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "AIG019".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).collect(Collectors.toList());
         }
-        PointData realScgData = edosUtil.getRealData(scgl);
-        ia.setInputPower(realScgData.getPointValueInDouble());
 
-        Optional<ProBasicEquipmentPoint> srd = CacheContext.proBasicEquipmentPointList.stream().filter(pbep -> "DIHW050".equals(pbep.getUniformCode()) && wpid.equals(pbep.getWindpowerstationId())).findFirst();
-        String srdy = null;
-        if (srd.isPresent()) {
-            srdy = srd.get().getNemCode();
+        //所有逆变器的输入功率测点
+        List<String> srgCollect = srg.stream().map(epp -> epp.getNemCode()).collect(Collectors.toList());
+        //输入功率测点,输入功率测点实时值
+        Map<String, Double> srgRealDataMap = edosUtil.getRealDataMap(srgCollect);
+        //逆变器的id,输入功率测点
+        Map<String, String> srgEquipmentIdMap = srg.stream().collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+
+        //所有逆变器的输出功率测点
+        List<String> scgCollect = scg.stream().map(epp -> epp.getNemCode()).collect(Collectors.toList());
+        //输出功率测点,输出功率测点实时值
+        Map<String, Double> scgRealDataMap = edosUtil.getRealDataMap(scgCollect);
+        //逆变器的id,输出功率测点
+        Map<String, String> scgEquipmentIdMap = srg.stream().collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+
+        //所有逆变器的输出电压测点
+        List<String> srdCollect = srd.stream().map(epp -> epp.getNemCode()).collect(Collectors.toList());
+        //输出电压测点,输出电压测点实时值
+        Map<String, Double> srdRealDataMap = edosUtil.getRealDataMap(srdCollect);
+        //逆变器的id,输出电压测点
+        Map<String, String> srdEquipmentIdMap = srg.stream().collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
+
+        for (String epid : srgEquipmentIdMap.keySet()) {
+            InverterAnalysis ia = new InverterAnalysis();
+            ia.setInverterId(epid);
+            ia.setInverterName(CacheContext.proBasicOrganizeTreesMap.get(epid).getNemName());
+            ia.setInputPower(srgRealDataMap.get(srgEquipmentIdMap.get(epid)));
+            ia.setOutputPower(scgRealDataMap.get(scgEquipmentIdMap.get(epid)));
+            ia.setInputVoltage(srdRealDataMap.get(srdEquipmentIdMap.get(epid)));
+            if (srgRealDataMap.get(srgEquipmentIdMap.get(epid)) == 0.0) {
+                ia.setConversionRate(0.0);
+            } else {
+                ia.setConversionRate(scgRealDataMap.get(scgEquipmentIdMap.get(epid)) / srgRealDataMap.get(srgEquipmentIdMap.get(epid)) * 100);
+            }
+            lias.add(ia);
         }
-        PointData realSrdData = edosUtil.getRealData(srdy);
-        ia.setInputPower(realSrdData.getPointValueInDouble());
-        ia.setConversionRate(realScgData.getPointValueInDouble() / realSrgData.getPointValueInDouble() * 100);
 
-        lias.add(ia);
-        resultMap.put("list", lias);
-        resultMap.put("chanrt", lias);
+        Page<InverterAnalysis> analysisPage = new Page<>();
+        analysisPage.setRecords(lias);
+        analysisPage.setTotal(lias.size());
+        analysisPage.setCurrent(pageNum);
+        analysisPage.setSize(pageSize);
+
+        resultMap.put("list", analysisPage);
+        resultMap.put("chanrt", analysisPage);
 
         return resultMap;
     }

+ 4 - 2
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/util/DateUtils.java

@@ -23,6 +23,8 @@ public class DateUtils {
     // 第一次调用get将返回null
 
     private static ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>();
+    private static final ThreadLocal<SimpleDateFormat> sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));
+    private static final ThreadLocal<SimpleDateFormat> sdf1 = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
 
     // 获取线程的变量副本,如果不覆盖initialValue,第一次get返回null,故需要初始化一个SimpleDateFormat,并set到threadLocal中
 
@@ -466,7 +468,7 @@ public class DateUtils {
 
     public static Date parseDate(String date) {
         try {
-            return getFormat().parse(date);
+            return sdf.get().parse(date);
         } catch (ParseException e) {
             e.printStackTrace();
         }
@@ -475,7 +477,7 @@ public class DateUtils {
 
     public static Date parseDate1(String date) {
         try {
-            return getFormat1().parse(date);
+            return sdf1.get().parse(date);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 1 - 1
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/util/realtimesource/EdosUtil.java

@@ -929,7 +929,7 @@ public class EdosUtil implements IEdosUtil {
     }
 
     @Override
-    public Map<String, Double> getRealDataMap(String... pointids) throws Exception {
+    public Map<String, Double> getRealDataMap(List<String> pointids) throws Exception {
 
 
         if(StringUtils.notEmp(pointids) )

+ 1 - 1
web/runeconomy-jjyx/src/main/java/com/gyee/runeconomy/util/realtimesource/IEdosUtil.java

@@ -132,7 +132,7 @@ public interface IEdosUtil {
      * @return Map集合
      * @throws Exception
      */
-    public Map<String,Double> getRealDataMap(String... pointids) throws Exception;
+    public Map<String,Double> getRealDataMap(List<String> pointids) throws Exception;
 
     /**
      * 通过全局点名获得历史数据快照