Browse Source

Merge remote-tracking branch 'origin/master'

malijun 1 year ago
parent
commit
080509f9fb

+ 1 - 1
electricity/wind/build.gradle

@@ -15,7 +15,7 @@ buildscript {
 apply plugin: "$bootGroup"
 apply plugin: 'io.spring.dependency-management'
 
-archivesBaseName='powergen-wind'
+archivesBaseName = 'powergen-wind'
 
 dependencyManagement {
     imports {

+ 29 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/config/WebMvcConfig.java

@@ -0,0 +1,29 @@
+package com.gyee.gaia.electricity.wind.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * 拦截器
+ */
+@Configuration
+public class WebMvcConfig implements  WebMvcConfigurer  {
+
+	/** 解决跨域问题 **/
+	@Override
+	public void addCorsMappings(CorsRegistry registry){
+		// 设置允许跨域的路由
+        registry.addMapping("/**")
+			// 设置允许跨域请求的域名
+			.allowedOriginPatterns("*")
+			// 是否允许证书
+			.allowCredentials(true)
+			// 设置允许的方法
+			.allowedMethods("GET", "POST", "DELETE", "PUT")
+			// 设置允许的header属性
+			.allowedHeaders("*")
+				// 跨域允许时间
+			.maxAge(3600);
+	}
+}

+ 120 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/controller/EquipPowerGenDayController.java

@@ -0,0 +1,120 @@
+package com.gyee.gaia.electricity.wind.controller;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.common.data.windturbine.Line;
+import com.gyee.gaia.common.data.windturbine.Project;
+import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
+import com.gyee.gaia.electricity.wind.init.CacheContext;
+import com.gyee.gaia.electricity.wind.iservice.IEquipPowerGenDayService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author gfhd
+ * @date 2023-05-30
+ */
+@RestController
+@RequestMapping("/powergen")
+public class EquipPowerGenDayController {
+    @Resource
+    private IEquipPowerGenDayService equipPowerGenDayService;
+
+    @GetMapping("/data")
+    private JSONObject getTables(@RequestParam(value = "station", required = false) String station,
+                                 @RequestParam(value = "projects", required = false) String projects,
+                                 @RequestParam(value = "lines", required = false) String lines,
+                                 @RequestParam(value = "startDate", required = false) String startDate,
+                                 @RequestParam(value = "endDate", required = false) String endDate) {
+        QueryWrapper<EquipPowerGenDay> epgdWrapper = new QueryWrapper<>();
+        epgdWrapper.select("facility_id", "round(sum(generating_capacity)/1000,2) generating_capacity", "round(sum(theory_generation)/1000,2) theory_generation"
+                , "round(sum(loss_power)/1000,2) loss_power", "round(sum(fault_loss_power)/1000,2) fault_loss_power"
+                , "round(sum(maintain_loss_power)/1000,2) maintain_loss_power", "round(sum(implicate_loss_power)/1000,2) implicate_loss_power"
+                , "round(sum(limit_loss_power)/1000,2) limit_loss_power", "round(sum(performance_loss_power)/1000,2) performance_loss_power"
+                , "round(avg(mean_wind_speed),2) mean_wind_speed");
+        if (StrUtil.isNotBlank(lines)) {
+            epgdWrapper.eq("category", "line").in("facility_id", lines.split(","));
+        } else if (StrUtil.isNotBlank(projects)) {
+            epgdWrapper.eq("category", "project").in("facility_id", projects.split(","));
+        } else if (StrUtil.isNotBlank(station)) {
+            epgdWrapper.eq("category", "windturbine").eq("station", station);
+        } else {
+            epgdWrapper.eq("category", "station");
+        }
+        epgdWrapper.between("date", DateUtil.parse(startDate).toLocalDateTime().toLocalDate(), DateUtil.parse(endDate).toLocalDateTime().toLocalDate())
+                .groupBy("facility_id");
+
+        List<EquipPowerGenDay> list = equipPowerGenDayService.list(epgdWrapper);
+        list = list.stream().peek(d -> d.setUniformCode(CacheContext.splssMap.get(d.getFacilityId()))).collect(Collectors.toList());
+
+        JSONObject json = new JSONObject();
+        json.put("code", 200);
+        json.put("msg", "成功!");
+        json.put("data", list);
+
+        return json;
+    }
+
+    @GetMapping("/stationList")
+    private JSONObject stationList() {
+
+        JSONObject json = new JSONObject();
+        json.put("code", 200);
+        json.put("msg", "成功!");
+        json.put("data", CacheContext.stationList.stream().filter(s->s.getId().contains("_FDC_")).collect(Collectors.toList()));
+
+        return json;
+    }
+
+    @GetMapping("/projectList")
+    private JSONObject projectList(@RequestParam(value = "stationId", required = false) String stationId) {
+
+        JSONObject json = new JSONObject();
+        json.put("code", 200);
+        json.put("msg", "成功!");
+
+        if (StrUtil.isBlank(stationId)) {
+            json.put("data", new HashMap<String, String>());
+        } else {
+            List<Project> projects = CacheContext.stationProjectsMap.get(stationId);
+            json.put("data", projects);
+        }
+
+        return json;
+    }
+
+    @GetMapping("/lineList")
+    private JSONObject lineList(@RequestParam(value = "projects", required = false) String projects) {
+
+        JSONObject json = new JSONObject();
+        json.put("code", 200);
+        json.put("msg", "成功!");
+
+        if (StrUtil.isBlank(projects)) {
+            json.put("data", new HashMap<String, String>());
+        } else {
+            String[] split = projects.split(",");
+            List<Line> list = new ArrayList<>();
+            for (String s : split) {
+                list.addAll(CacheContext.projectLinesMap.get(s));
+            }json.put("data", list);
+        }
+
+        return json;
+    }
+
+    private boolean hasStr(String[] split, String key) {
+        for (String s : split) {
+            if (Objects.equals(s, key)) return true;
+        }
+        return false;
+    }
+}

+ 49 - 6
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/init/CacheContext.java

@@ -2,11 +2,14 @@ package com.gyee.gaia.electricity.wind.init;
 
 import com.gyee.gaia.common.data.power.ModelPowerDetails;
 import com.gyee.gaia.common.data.windturbine.Equipment;
+import com.gyee.gaia.common.data.windturbine.Line;
 import com.gyee.gaia.common.data.windturbine.Powerstation;
+import com.gyee.gaia.common.data.windturbine.Project;
 import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
+import com.gyee.gaia.dao.sql.Windturbine.ILineService;
 import com.gyee.gaia.dao.sql.Windturbine.IPowerstationService;
+import com.gyee.gaia.dao.sql.Windturbine.IProjectService;
 import com.gyee.gaia.dao.sql.power.IModelPowerDetailsService;
-import com.gyee.gaia.electricity.wind.job.CalcEquipPowerGenDay;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
@@ -14,6 +17,7 @@ import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
@@ -32,6 +36,10 @@ public class CacheContext implements ApplicationRunner {
     private IPowerstationService powerstationService;
     //@Resource
     //private CalcEquipPowerGenDay calcEquipPowerGenDay;
+    @Resource
+    private IProjectService projectService;
+    @Resource
+    private ILineService lineService;
 
     public static Map<String, Map<Double, Double>> modelPowerMap;
     /**
@@ -51,13 +59,37 @@ public class CacheContext implements ApplicationRunner {
      */
     public static Map<String, List<String>> projectEquipidMap;
     /**
-     * 期次,风机
+     * 线路,风机
      */
     public static Map<String, List<String>> lineEquipidMap;
     /**
      * 风机,机型
      */
     public static Map<String, String> equipModelMap;
+    /**
+     * 场站id,场站名
+     */
+    public static List<Powerstation> stationList;
+    /**
+     * 期次id,期次名
+     */
+    public static List<Project> pList;
+    /**
+     * 线路id,线路名
+     */
+    public static List<Line> lList;
+    /**
+     * facility_id,facility_name
+     */
+    public static Map<String, String> splssMap = new HashMap<>();
+    /**
+     * 场站id,期次
+     */
+    public static Map<String, List<Project>> stationProjectsMap;
+    /**
+     * 期次id,线路
+     */
+    public static Map<String, List<Line>> projectLinesMap;
 
     @Override
     public void run(ApplicationArguments args) throws Exception {
@@ -72,14 +104,25 @@ public class CacheContext implements ApplicationRunner {
         equipModelMap = emList.stream().collect(Collectors.toMap(Equipment::getId, Equipment::getModelId));
 
         log.info("加载风场信息!");
-        List<Powerstation> stationList = powerstationService.list();
+        stationList = powerstationService.list();
         stationMap = stationList.stream().collect(Collectors.toMap(Powerstation::getId, Function.identity()));
 
         log.info("加载线路、期次、风场信息!");
         List<Equipment> emCollect = emList.stream().filter(e -> "WT".equals(e.getSpare1())).collect(Collectors.toList());
-        stationEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId,Collectors.mapping(Equipment::getId,Collectors.toList())));
-        projectEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getProjectId,Collectors.mapping(Equipment::getId,Collectors.toList())));
-        lineEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getLineId,Collectors.mapping(Equipment::getId,Collectors.toList())));
+        stationEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getWindpowerstationId, Collectors.mapping(Equipment::getId, Collectors.toList())));
+        projectEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getProjectId, Collectors.mapping(Equipment::getId, Collectors.toList())));
+        lineEquipidMap = emCollect.stream().collect(Collectors.groupingBy(Equipment::getLineId, Collectors.mapping(Equipment::getId, Collectors.toList())));
+
+        pList = projectService.list();
+        lList = lineService.list();
+        Map<String, String> sssMap = stationList.stream().collect(Collectors.toMap(Powerstation::getId, Powerstation::getName));
+        Map<String, String> pssMap = pList.stream().collect(Collectors.toMap(Project::getId, Project::getName));
+        Map<String, String> lssMap = lList.stream().collect(Collectors.toMap(Line::getId, Line::getName));
+        splssMap.putAll(sssMap);
+        splssMap.putAll(pssMap);
+        splssMap.putAll(lssMap);
+        stationProjectsMap = pList.stream().collect(Collectors.groupingBy(Project::getWindpowerstationId, Collectors.mapping(Function.identity(), Collectors.toList())));
+        projectLinesMap = lList.stream().collect(Collectors.groupingBy(Line::getProjectId, Collectors.mapping(Function.identity(), Collectors.toList())));
 
         //calcEquipPowerGenDay.calcEquipPowerGenDay();
     }

+ 18 - 16
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/job/CalcEquipPowerGenDay.java

@@ -24,10 +24,12 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 @Component
 public class CalcEquipPowerGenDay {
@@ -98,7 +100,7 @@ public class CalcEquipPowerGenDay {
         List<EquipPowerGenDay> epgdList = equipPowerGenDayService.list(epgdWrapper);
 
         List<EquipPowerGenDay> equipPowerGenDayList = new ArrayList<>();
-        CacheContext.lineEquipidMap.forEach((line,equipidList)->{
+        CacheContext.lineEquipidMap.forEach((line, equipidList) -> {
             EquipPowerGenDay genDay = new EquipPowerGenDay();
             genDay.setDate(time1);
             genDay.setStation(CacheContext.equipMap.get(equipidList.get(0)).getWindpowerstationId());
@@ -108,7 +110,7 @@ public class CalcEquipPowerGenDay {
             extracted(genDay, filterStream);
             equipPowerGenDayList.add(genDay);
         });
-        CacheContext.projectEquipidMap.forEach((project,equipidList)->{
+        CacheContext.projectEquipidMap.forEach((project, equipidList) -> {
             EquipPowerGenDay genDay = new EquipPowerGenDay();
             genDay.setDate(time1);
             genDay.setStation(CacheContext.equipMap.get(equipidList.get(0)).getWindpowerstationId());
@@ -118,7 +120,7 @@ public class CalcEquipPowerGenDay {
             extracted(genDay, filterStream);
             equipPowerGenDayList.add(genDay);
         });
-        CacheContext.stationEquipidMap.forEach((station,equipidList)->{
+        CacheContext.stationEquipidMap.forEach((station, equipidList) -> {
             EquipPowerGenDay genDay = new EquipPowerGenDay();
             genDay.setDate(time1);
             genDay.setStation(station);
@@ -139,16 +141,16 @@ public class CalcEquipPowerGenDay {
     }
 
     private void extracted(EquipPowerGenDay genDay, List<EquipPowerGenDay> filterStream) {
-        genDay.setGeneratingCapacity(filterStream.stream().map(e->e.getGeneratingCapacity()!=null?e.getGeneratingCapacity():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setTheoryGeneration(filterStream.stream().map(e->e.getTheoryGeneration()!=null?e.getTheoryGeneration():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setLossPower(filterStream.stream().map(e->e.getLossPower()!=null?e.getLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-
-        genDay.setFaultLossPower(filterStream.stream().map(e->e.getFaultLossPower()!=null?e.getFaultLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setMaintainLossPower(filterStream.stream().map(e->e.getMaintainLossPower()!=null?e.getMaintainLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setImplicateLossPower(filterStream.stream().map(e->e.getImplicateLossPower()!=null?e.getImplicateLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setLimitLossPower(filterStream.stream().map(e->e.getLimitLossPower()!=null?e.getLimitLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setPerformanceLossPower(filterStream.stream().map(e->e.getPerformanceLossPower()!=null?e.getPerformanceLossPower():BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO,BigDecimal::add));
-        genDay.setMeanWindSpeed(BigDecimal.valueOf(filterStream.stream().filter(e->e.getMeanWindSpeed()!=null&&e.getMeanWindSpeed().doubleValue()!=0).mapToDouble(e->e.getMeanWindSpeed().doubleValue()).average().getAsDouble()).setScale(2,RoundingMode.HALF_UP));
+        genDay.setGeneratingCapacity(filterStream.stream().map(e -> e.getGeneratingCapacity() != null ? e.getGeneratingCapacity() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setTheoryGeneration(filterStream.stream().map(e -> e.getTheoryGeneration() != null ? e.getTheoryGeneration() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setLossPower(filterStream.stream().map(e -> e.getLossPower() != null ? e.getLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+
+        genDay.setFaultLossPower(filterStream.stream().map(e -> e.getFaultLossPower() != null ? e.getFaultLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setMaintainLossPower(filterStream.stream().map(e -> e.getMaintainLossPower() != null ? e.getMaintainLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setImplicateLossPower(filterStream.stream().map(e -> e.getImplicateLossPower() != null ? e.getImplicateLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setLimitLossPower(filterStream.stream().map(e -> e.getLimitLossPower() != null ? e.getLimitLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setPerformanceLossPower(filterStream.stream().map(e -> e.getPerformanceLossPower() != null ? e.getPerformanceLossPower() : BigDecimal.valueOf(0)).reduce(BigDecimal.ZERO, BigDecimal::add));
+        genDay.setMeanWindSpeed(BigDecimal.valueOf(filterStream.stream().filter(e -> e.getMeanWindSpeed() != null && e.getMeanWindSpeed().doubleValue() != 0).mapToDouble(e -> e.getMeanWindSpeed().doubleValue()).average().getAsDouble()).setScale(2, RoundingMode.HALF_UP));
     }
 
     /**
@@ -207,7 +209,7 @@ public class CalcEquipPowerGenDay {
             }
 
             epgd = sepgdMap.get(equipId);
-            if(epgd==null) continue;
+            if (epgd == null) continue;
             //损失电量
             BigDecimal losspower = epgd.getTheoryGeneration().subtract(epgd.getGeneratingCapacity());
             if (losspower.compareTo(BigDecimal.ZERO) <= 0) {