Browse Source

代码优化

全业务考评 1 year ago
parent
commit
2d17806bab

+ 79 - 76
power-fitting-JN/src/main/java/com.gyee.power.fitting/service/custom/fiveloss/FiveLossService.java

@@ -1,13 +1,10 @@
 package com.gyee.power.fitting.service.custom.fiveloss;
 
-import com.alibaba.fastjson.JSONObject;
-import com.gyee.power.fitting.common.constants.Constants;
 import com.gyee.power.fitting.common.exception.CustomException;
 import com.gyee.power.fitting.common.feign.RemoteServiceBuilder;
 import com.gyee.power.fitting.common.result.ResultCode;
 import com.gyee.power.fitting.common.spring.InitialRunner;
 import com.gyee.power.fitting.common.util.CollectUtil;
-import com.gyee.power.fitting.common.util.DateUtil;
 import com.gyee.power.fitting.common.util.FileUtil;
 import com.gyee.power.fitting.model.*;
 import com.gyee.power.fitting.model.anno.AnnotationTool;
@@ -52,7 +49,8 @@ public class FiveLossService {
         if (status == 0.0 || status == 2.0 || status == 3.0 || status == 4.0 || status == 9.0 || status == 10.0 || status == 11.0) {
             for (PowerPointData obj : pointData) {
                 double speed = new BigDecimal(obj.getSpeed()).setScale(2, RoundingMode.FLOOR).doubleValue();
-                double zsgl = zsglData.get(speed);
+                System.out.println("0000----------"+speed);
+                double zsgl = null == zsglData.get(speed) ? 0:zsglData.get(speed);
                 double power = obj.getPower();
                 double temp = (zsgl - power) > 0 ? zsgl - power : 0;
                 ssdl = ssdl + (temp / 60) * (interval / 60);
@@ -61,7 +59,7 @@ public class FiveLossService {
             for (PowerPointData obj : pointData) {
                 if (obj.getSpeed() < 3.0) continue;
                 double speed = new BigDecimal(obj.getSpeed()).setScale(2, RoundingMode.FLOOR).doubleValue();
-                double zsgl = zsglData.get(speed);
+                double zsgl =  null == zsglData.get(speed) ? 0:zsglData.get(speed);
                 ssdl = ssdl + (zsgl / 60) * (interval / 60);
             }
         }
@@ -70,7 +68,7 @@ public class FiveLossService {
             for (PowerPointData obj : ztmxData) {
                 if (obj.getSpeed() < 3.0) continue;
                 double speed = new BigDecimal(obj.getSpeed()).setScale(2, RoundingMode.FLOOR).doubleValue();
-                double zsgl = zsglData.get(speed);
+                double zsgl =  null == zsglData.get(speed) ? 0:zsglData.get(speed);
                 ssdl = ssdl + (zsgl / 60) * (interval / 60);
             }
         }
@@ -84,81 +82,86 @@ public class FiveLossService {
      * @param ids  准备的数据ID
      */
     public Map<String, Object> fiveLossCalByZSGL(String ids) {
-        log.info("======风机绩效榜计算开始.............");
-        Map<String, Object> promise = new HashMap<>();
-        List<FjjxbVo> result = new ArrayList<>();
-        Map<String, Map<Double, Double>> zsglmap = InitialRunner.zsllglNewMap;
+        Map<String, Object> promise = null;
+        try {
+            log.info("======风机绩效榜计算开始.............");
+            promise = new HashMap<>();
+            List<FjjxbVo> result = new ArrayList<>();
+            Map<String, Map<Double, Double>> zsglmap = InitialRunner.zsllglNewMap;
 
-        List<ProEconPowerFittingAnalySis> analyses = analysisService.selectListByIds(ids);
-        if (analyses.size() == 0){
-            log.info("======风机榜效帮计算结束,数据为空.............");
-            throw new CustomException(ResultCode.ERROR);
-        }
-
-        for (ProEconPowerFittingAnalySis p : analyses) {
-            List<String> content = FileUtil.readFile(p.getPath(), true);
-            if (content.size() == 0 || zsglmap.size() == 0 || zsglmap.get(p.getWindturbineId()) == null){
-                log.info("======风机榜效帮计算结束," + p.getWindturbineId() + "文件内容或当前风机的自算功率为空.............");
-                continue;
+            List<ProEconPowerFittingAnalySis> analyses = analysisService.selectListByIds(ids);
+            if (analyses.size() == 0){
+                log.info("======风机榜效帮计算结束,数据为空.............");
+                throw new CustomException(ResultCode.ERROR);
             }
-            log.info("======风机绩效榜计算:" + p.getWindturbineId());
-            double llfdl = 0.0; //理论发电量
-            double rfdl = 0.0; //日发电量
-            double jhjxssdl = 0.0;//计划检修损失电量
-            double fjhjxssdl =0.0;//非计划检修电量
-            double xdssdl = 0.0;//限电损失电量
-            double slssdl = 0.0;//受累损失电量
-            double xnssdl = 0.0;//性能损失电量
-            double speed = 0.0;//风速
-            content.remove(0); //去掉标题栏
-            int count = 86400 / p.getInterp(); //一天86400s  一天的条数
-            List<List<String>> coll = CollectUtil.groupListByQty(content, count);
-            for (List<String> ls : coll) {
-                List<PowerPointData> pdl = ls.stream().map(mp -> new PowerPointData(mp.split(","), false)).collect(Collectors.toList());
-                double lldl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), -1); //理论发电量
-                double dj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 0); //待机
-                double sdtj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 1); //手动停机
-                double zcfd = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 2); //正常发电
-                double xdss = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 5);  //限电损失电量
-                double qxjcl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 3); //缺陷降出力损失电量
-                double xdjcl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 4); //限电降出力损失电量
-                double cnsltj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 7); //场内受累停机损失电量
-                double cnsljx = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 9); //场内受累检修损失电量
-                double dwsl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 10); //电网受累损失电量
-                double hjsl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 11); //环境受累损失电量
-                double gzss = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 6); //故障损失电量
-                double tjjx = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 8); //停机检修
 
-                llfdl += lldl;
-                jhjxssdl += (tjjx + cnsljx);
-                fjhjxssdl += (gzss + cnsltj);
-                xdssdl += (xdjcl + xdss);
-                slssdl += (dwsl + hjsl);
-                xnssdl += (dj + sdtj + zcfd + qxjcl);
-                rfdl += pdl.get(pdl.size() - 1).getDl();
-                speed += pdl.stream().mapToDouble(PowerPointData::getSpeed).sum();
+            for (ProEconPowerFittingAnalySis p : analyses) {
+                List<String> content = FileUtil.readFile(p.getPath(), true);
+                if (content.size() == 0 || zsglmap.size() == 0 || zsglmap.get(p.getWindturbineId()) == null){
+                    log.info("======风机榜效帮计算结束," + p.getWindturbineId() + "文件内容或当前风机的自算功率为空.............");
+                    continue;
+                }
+                log.info("======风机绩效榜计算:" + p.getWindturbineId());
+                double llfdl = 0.0; //理论发电量
+                double rfdl = 0.0; //日发电量
+                double jhjxssdl = 0.0;//计划检修损失电量
+                double fjhjxssdl =0.0;//非计划检修电量
+                double xdssdl = 0.0;//限电损失电量
+                double slssdl = 0.0;//受累损失电量
+                double xnssdl = 0.0;//性能损失电量
+                double speed = 0.0;//风速
+                content.remove(0); //去掉标题栏
+                int count = 86400 / p.getInterp(); //一天86400s  一天的条数
+                List<List<String>> coll = CollectUtil.groupListByQty(content, count);
+                for (List<String> ls : coll) {
+                    List<PowerPointData> pdl = ls.stream().map(mp -> new PowerPointData(mp.split(","), false)).collect(Collectors.toList());
+                    double lldl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), -1); //理论发电量
+                    double dj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 0); //待机
+                    double sdtj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 1); //手动停机
+                    double zcfd = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 2); //正常发电
+                    double xdss = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 5);  //限电损失电量
+                    double qxjcl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 3); //缺陷降出力损失电量
+                    double xdjcl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 4); //限电降出力损失电量
+                    double cnsltj = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 7); //场内受累停机损失电量
+                    double cnsljx = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 9); //场内受累检修损失电量
+                    double dwsl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 10); //电网受累损失电量
+                    double hjsl = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 11); //环境受累损失电量
+                    double gzss = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 6); //故障损失电量
+                    double tjjx = generalLoss(pdl, zsglmap.get(p.getWindturbineId()), p.getInterp(), 8); //停机检修
+
+                    llfdl += lldl;
+                    jhjxssdl += (tjjx + cnsljx);
+                    fjhjxssdl += (gzss + cnsltj);
+                    xdssdl += (xdjcl + xdss);
+                    slssdl += (dwsl + hjsl);
+                    xnssdl += (dj + sdtj + zcfd + qxjcl);
+                    rfdl += pdl.get(pdl.size() - 1).getDl();
+                    speed += pdl.stream().mapToDouble(PowerPointData::getSpeed).sum();
+                }
+                FjjxbVo vo = new FjjxbVo();
+                vo.setId(p.getWindturbineId());
+                vo.setName(p.getWindturbineId());
+                vo.setLlfdl(new BigDecimal(llfdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setSjfdl(new BigDecimal(rfdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setJhjx(new BigDecimal(jhjxssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setFjhjx(new BigDecimal(fjhjxssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setXd(new BigDecimal(xdssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setXn(new BigDecimal(xnssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setSl(new BigDecimal(slssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setSpeed(new BigDecimal(speed/content.size()).setScale(2, RoundingMode.FLOOR).doubleValue());
+                vo.setFnlly(llfdl > 0 ? new BigDecimal(rfdl / llfdl).setScale(2, RoundingMode.FLOOR).doubleValue() : 0);
+                result.add(vo);
             }
-            FjjxbVo vo = new FjjxbVo();
-            vo.setId(p.getWindturbineId());
-            vo.setName(p.getWindturbineId());
-            vo.setLlfdl(new BigDecimal(llfdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setSjfdl(new BigDecimal(rfdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setJhjx(new BigDecimal(jhjxssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setFjhjx(new BigDecimal(fjhjxssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setXd(new BigDecimal(xdssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setXn(new BigDecimal(xnssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setSl(new BigDecimal(slssdl).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setSpeed(new BigDecimal(speed/content.size()).setScale(2, RoundingMode.FLOOR).doubleValue());
-            vo.setFnlly(llfdl > 0 ? new BigDecimal(rfdl / llfdl).setScale(2, RoundingMode.FLOOR).doubleValue() : 0);
-            result.add(vo);
+            log.info("======风机榜效帮计算结束.............");
+            result.stream().sorted(Comparator.comparing(FjjxbVo::getId));
+            /** 添加标题 **/
+            List<FixedVo> fxList = AnnotationTool.getFixedVoList(FjjxbVo.class);
+            List<TableTitle> lt = fxList.stream().map(d -> new TableTitle(d.getName(), d.getDes())).collect(Collectors.toList());
+            promise.put("title", lt);
+            promise.put("data", result);
+        } catch (Exception e) {
+            e.printStackTrace();
         }
-        log.info("======风机榜效帮计算结束.............");
-        result.stream().sorted(Comparator.comparing(FjjxbVo::getId));
-        /** 添加标题 **/
-        List<FixedVo> fxList = AnnotationTool.getFixedVoList(FjjxbVo.class);
-        List<TableTitle> lt = fxList.stream().map(d -> new TableTitle(d.getName(), d.getDes())).collect(Collectors.toList());
-        promise.put("title", lt);
-        promise.put("data", result);
 
         return promise;
     }