Forráskód Böngészése

光伏逆变器负荷率利用小时接口

xushili 2 éve
szülő
commit
44932c8b54

+ 2 - 1
src/main/java/com/gyee/frame/common/feign/IAdapterService.java

@@ -10,6 +10,7 @@ import feign.Param;
 import feign.RequestLine;
 
 import java.util.List;
+import java.util.Map;
 
 
 public interface IAdapterService {
@@ -37,7 +38,7 @@ public interface IAdapterService {
 
     @Headers({"Content-Type: application/json", "Accept: application/json"})
     @RequestLine("GET /ts/history/section?tagNames={tagNames}&ts={ts}")
-    List<TsPointData> getHistorySection(@Param(value = "tagNames") String tagNames, @Param(value = "ts") long ts);
+    Map<String,TsPointData> getHistorySection(@Param(value = "tagNames") String tagNames, @Param(value = "ts") long ts);
 
     @Headers({"Content-Type: application/json", "Accept: application/json"})
     @RequestLine("GET /alarm/count/query/new2?stationid={stationid}&startdate={startdate}&enddate={enddate}")

+ 46 - 0
src/main/java/com/gyee/frame/controller/file/LoadrateHourlyController.java

@@ -0,0 +1,46 @@
+package com.gyee.frame.controller.file;
+
+import com.gyee.frame.common.conf.AjaxStatus;
+import com.gyee.frame.common.domain.AjaxResult;
+import com.gyee.frame.model.excel.LoadrateHourly;
+import com.gyee.frame.service.export.LoadrateHourlyService;
+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.io.File;
+import java.util.List;
+
+@RestController
+@RequestMapping("/loadrate")
+public class LoadrateHourlyController {
+
+    @Resource
+    private LoadrateHourlyService loadrateHourlyService;
+
+    /**
+     * 光伏逆变器负荷率
+     */
+    @GetMapping("/info")
+    public AjaxResult getInfo(@RequestParam("stationid") String stationid,
+                              @RequestParam("date") String date,
+                              @RequestParam("time") String time){
+        List<LoadrateHourly> loadrateHourlies = loadrateHourlyService.readExcel(stationid, date, time);
+        if(loadrateHourlies==null){
+            return AjaxResult.error("文件不存在!");
+        }
+        return AjaxResult.successData(AjaxStatus.success.code,loadrateHourlies);
+    }
+    @GetMapping("/down")
+    public AjaxResult getDownInfo(@RequestParam(value = "stationid",required = false) String stationid,
+                                  @RequestParam("date") String date,
+                                  @RequestParam("time") String time){
+        File file = loadrateHourlyService.getPath(date, time);
+        if(file.exists()){
+            return AjaxResult.successData(AjaxStatus.success.code,file.getPath());
+        }
+        return AjaxResult.error("文件不存在!");
+    }
+}

+ 28 - 0
src/main/java/com/gyee/frame/model/config/FilePathConfig.java

@@ -0,0 +1,28 @@
+package com.gyee.frame.model.config;
+
+import org.springframework.boot.system.ApplicationHome;
+
+import java.io.File;
+
+public class FilePathConfig {
+    private static String filePath;
+    private static String dataPath;
+
+    public static String getFilePath() {
+        if(filePath==null){
+            ApplicationHome home = new ApplicationHome(FilePathConfig.class);
+            filePath=home.getSource().getParentFile().getAbsolutePath();
+        }
+        return filePath;
+    }
+
+    public static String getDataPath() {
+        if(dataPath==null){
+            getFilePath();
+            dataPath = filePath.substring(0, filePath.lastIndexOf("\\"));
+            File file = new File(dataPath + "\\光伏逆变器负荷率利用小时计算");
+            if(!file.exists()) file.mkdir();
+        }
+        return dataPath;
+    }
+}

+ 16 - 0
src/main/java/com/gyee/frame/model/excel/LoadrateHourly.java

@@ -0,0 +1,16 @@
+package com.gyee.frame.model.excel;
+
+import lombok.Data;
+
+@Data
+public class LoadrateHourly {
+    private String id;
+    private String branchcount;
+    private String platecount;
+    private String platecapacity;
+    private String time;
+    private String power;
+    private String loadfactor;
+    private String generatedenergy;
+    private String utilizationhour;
+}

+ 211 - 0
src/main/java/com/gyee/frame/schdule/windturbinestatetime/TaskLoadrateHourlyStatistics.java

@@ -0,0 +1,211 @@
+package com.gyee.frame.schdule.windturbinestatetime;
+
+import com.gyee.frame.common.feign.RemoteServiceBuilder;
+import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
+import com.gyee.frame.model.auto.WindTurbineTestingPointAi2Example;
+import com.gyee.frame.model.config.FilePathConfig;
+import com.gyee.frame.model.custom.export.TsPointData;
+import com.gyee.frame.service.WindTurbineTestingPointAiService;
+import com.gyee.frame.service.export.LoadrateHourlyService;
+import com.gyee.frame.util.DateUtils;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.xssf.usermodel.*;
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 光伏负荷率、利用小时计算
+ */
+@Component
+public class TaskLoadrateHourlyStatistics {
+
+    @Resource
+    private WindTurbineTestingPointAiService windTurbineTestingPointAiService;
+    @Resource
+    private RemoteServiceBuilder remoteServiceBuilder;
+    @Resource
+    private LoadrateHourlyService loadrateHourlyService;
+
+    private String powerTags;
+    private String electricityTags;
+    private List<WindTurbineTestingPointAi2> ai2ForPower;
+    private List<WindTurbineTestingPointAi2> ai2ForElectricity;
+    //场站、风机、标签点
+    Map<String, List<String>> powerCollect;
+    Map<String, List<String>> electricityCollect;
+
+    //利用小时计算
+    private void creatExcel(XSSFWorkbook sheets) {
+        getPowerTags();
+        getElectricityTags();
+        Calendar instance = Calendar.getInstance();
+        //Map<String,TsPointData> powerPoint = remoteServiceBuilder.ShardingService().getHistorySection(powerTags, instance.getTimeInMillis());
+        Map<String,TsPointData> electricityPoint = remoteServiceBuilder.ShardingService().getHistorySection(electricityTags, instance.getTimeInMillis());
+        //getPowerCollect();
+        getElectricityCollect();
+        Map<Integer, String> ptMap = loadrateHourlyService.getPtMap();
+        for (int i = 0; i <5; i++) {
+            XSSFSheet sheetAt = sheets.getSheetAt(i);
+            for (int i1 = 0; i1 < sheetAt.getLastRowNum()-1; i1++) {
+                sheetAt.getRow(i1+2).getCell(4).setCellValue(DateUtils.format(instance.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                //sheetAt.getRow(i1+2).getCell(5).setCellValue(powerPoint.get(powerCollect.get(ptMap.get(i)).get(i1)).getDoubleValue());
+                sheetAt.getRow(i1+2).getCell(5).setCellValue(electricityPoint.get(electricityCollect.get(ptMap.get(i)).get(i1)).getDoubleValue());
+            }
+        }
+        FormulaEvaluator evaluator = new XSSFFormulaEvaluator(sheets);
+        evaluator.evaluateAll();
+        //通过输出流将workbook对象下载到磁盘
+        FileOutputStream out = null;
+        try {
+            out = new FileOutputStream(FilePathConfig.getDataPath()+"\\光伏逆变器负荷率利用小时计算\\"+DateUtils.format(new Date(),"yyyyMMdd")+"2200.xlsx");
+            sheets.write(out);
+            out.flush();
+            out.close();
+            //sheets.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    //负荷率计算
+    private void creatExcel(String t) {
+        XSSFWorkbook sheets = readExceltemplate();
+        getPowerTags();
+        getElectricityTags();
+        Calendar instance = Calendar.getInstance();
+        Map<String,TsPointData> powerPoint = remoteServiceBuilder.ShardingService().getHistorySection(powerTags, instance.getTimeInMillis());
+        getPowerCollect();
+        Map<Integer, String> ptMap = loadrateHourlyService.getPtMap();
+        for (int i = 0; i <5; i++) {
+            XSSFSheet sheetAt = sheets.getSheetAt(i);
+            for (int i1 = 0; i1 < sheetAt.getLastRowNum()-1; i1++) {
+                sheetAt.getRow(i1+2).getCell(4).setCellValue(DateUtils.format(instance.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                sheetAt.getRow(i1+2).getCell(5).setCellValue(powerPoint.get(powerCollect.get(ptMap.get(i)).get(i1)).getDoubleValue());
+            }
+        }
+        FormulaEvaluator evaluator = new XSSFFormulaEvaluator(sheets);
+        evaluator.evaluateAll();
+        //通过输出流将workbook对象下载到磁盘
+        FileOutputStream out = null;
+        try {
+            out = new FileOutputStream(FilePathConfig.getDataPath()+"\\光伏逆变器负荷率利用小时计算\\"+DateUtils.format(new Date(),"yyyyMMdd")+t+".xlsx");
+            sheets.write(out);
+            out.flush();
+            out.close();
+            //sheets.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 9点半
+     */
+    @Scheduled(cron = "0 30 9 * * ?")
+    public void getLoadrateHourly930(){
+        creatExcel("0930");
+    }
+
+    /**
+     * 12点半
+     */
+    @Scheduled(cron = "0 30 12 * * ?")
+    public void getLoadrateHourly1230(){
+        creatExcel("1230");
+    }
+
+    /**
+     * 18点半
+     */
+    @Scheduled(cron = "0 30 18 * * ?")
+    public void getLoadrateHourly1830(){
+        creatExcel("1830");
+    }
+
+    /**
+     * 22点
+     */
+    @Scheduled(cron = "0 0 20 * * ?")
+    public void getLoadrateHourly2200(){
+        String path = FilePathConfig.getFilePath()+"\\template\\公司光伏逆变器利用小时计算模板.xlsx";
+        XSSFWorkbook sheets = readExceltemplate(path);
+        creatExcel(sheets);
+    }
+
+    private XSSFWorkbook readExceltemplate(String path){
+        //在内存中创建一个Excel文件
+        XSSFWorkbook sheets = null;
+        try {
+            sheets = new XSSFWorkbook(path);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return sheets;
+    }
+
+    private XSSFWorkbook readExceltemplate(){
+        String path = FilePathConfig.getFilePath()+"\\template\\公司光伏逆变器负荷率计算模板.xlsx";
+        return readExceltemplate(path);
+    }
+
+    public String getPowerTags() {
+        if(powerTags==null){
+            getAi2ForPower();
+            powerTags = ai2ForPower.stream().map(wttpai2 -> wttpai2.getId()).collect(Collectors.joining(","));
+        }
+        return powerTags;
+    }
+
+    public String getElectricityTags() {
+        if(electricityTags==null){
+            getAi2ForElectricity();
+            electricityTags = ai2ForElectricity.stream().map(wttpai2 -> wttpai2.getId()).collect(Collectors.joining(","));
+        }
+        return electricityTags;
+    }
+
+    public List<WindTurbineTestingPointAi2> getAi2ForPower() {
+        if(ai2ForPower==null){
+            WindTurbineTestingPointAi2Example example = new WindTurbineTestingPointAi2Example();
+            example.createCriteria().andUniformcodeEqualTo("AI130").andWindpowerstationidLike("%GDC");
+            ai2ForPower = windTurbineTestingPointAiService.selectByExample(example);
+        }
+        return ai2ForPower;
+    }
+
+    public List<WindTurbineTestingPointAi2> getAi2ForElectricity() {
+        if(ai2ForElectricity==null){
+            WindTurbineTestingPointAi2Example example = new WindTurbineTestingPointAi2Example();
+            example.createCriteria().andUniformcodeEqualTo("RFDLREAD").andWindpowerstationidLike("%GDC");
+            ai2ForElectricity = windTurbineTestingPointAiService.selectByExample(example);
+        }
+        return ai2ForElectricity;
+    }
+
+    public Map<String, List<String>> getPowerCollect() {
+        if(powerCollect==null){
+            powerCollect = ai2ForPower.stream().sorted((ai1,ai2)->{
+                return Integer.parseInt(ai1.getWindturbineid().substring(ai1.getWindturbineid().indexOf("_")+1))
+                        - Integer.parseInt(ai2.getWindturbineid().substring(ai2.getWindturbineid().indexOf("_")+1));
+            }).collect(Collectors.groupingBy(WindTurbineTestingPointAi2::getWindpowerstationid,Collectors.mapping(WindTurbineTestingPointAi2::getId,Collectors.toList())));
+        }
+        return powerCollect;
+    }
+
+    public Map<String, List<String>> getElectricityCollect() {
+        if(electricityCollect==null){
+            electricityCollect = ai2ForElectricity.stream().sorted((ai1,ai2)->{
+                return Integer.parseInt(ai1.getWindturbineid().substring(ai1.getWindturbineid().indexOf("_")+1))
+                        - Integer.parseInt(ai2.getWindturbineid().substring(ai2.getWindturbineid().indexOf("_")+1));
+            }).collect(Collectors.groupingBy(WindTurbineTestingPointAi2::getWindpowerstationid,Collectors.mapping(WindTurbineTestingPointAi2::getId,Collectors.toList())));
+        }
+        return electricityCollect;
+    }
+}

+ 184 - 0
src/main/java/com/gyee/frame/service/export/LoadrateHourlyService.java

@@ -0,0 +1,184 @@
+package com.gyee.frame.service.export;
+
+import com.gyee.frame.model.config.FilePathConfig;
+import com.gyee.frame.model.excel.LoadrateHourly;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class LoadrateHourlyService {
+
+    private Map<Integer, String> ptMap;
+    private Map<String, Integer> tpMap;
+
+    public Map<Integer, String> getPtMap() {
+        if (ptMap == null) {
+            ptMap = new HashMap<>(5);
+            ptMap.put(0, "PL_GDC");
+            ptMap.put(1, "DWK_GDC");
+            ptMap.put(2, "XH_GDC");
+            ptMap.put(3, "MCH_GDC");
+            ptMap.put(4, "HZJ_GDC");
+        }
+        return ptMap;
+    }
+
+    public Map<String, Integer> getTpMap() {
+        if (tpMap == null) {
+            tpMap = new HashMap<>(5);
+            tpMap.put("PL_GDC",0);
+            tpMap.put("DWK_GDC",1);
+            tpMap.put("XH_GDC",2);
+            tpMap.put("MCH_GDC",3);
+            tpMap.put("HZJ_GDC",4);
+        }
+        return tpMap;
+    }
+
+    public File getPath(String time, String s) {
+        String stime = time.replaceAll("-", "");
+        String path = FilePathConfig.getDataPath() + "\\光伏逆变器负荷率利用小时计算\\" + stime + s + ".xlsx";
+        return new File(path);
+    }
+
+    public Map<String, File> getAllPath(String time) {
+        Map<String, File> fileMap = new HashMap<>();
+        File file1 = getPath(time, "0930");
+        if (file1.exists()) fileMap.put("0930", file1);
+        File file2 = getPath(time, "1230");
+        if (file2.exists()) fileMap.put("1230", file2);
+        File file3 = getPath(time, "1830");
+        if (file3.exists()) fileMap.put("1830", file3);
+        File file4 = getPath(time, "2200");
+        if (file4.exists()) fileMap.put("2200", file4);
+        return fileMap;
+    }
+
+    private Map<String, List<LoadrateHourly>> sheets2LoadrateHourly(File file) {
+        XSSFWorkbook sheets = null;
+        try {
+            sheets = new XSSFWorkbook(file);
+        } catch (IOException | InvalidFormatException e) {
+            e.printStackTrace();
+        }
+
+        getPtMap();
+        Map<String, List<LoadrateHourly>> loadrateHourlysMap = new HashMap<>();
+        //表
+        for (int i = 0; i < 5; i++) {
+            XSSFSheet sheetAt = sheets.getSheetAt(i);
+            List<LoadrateHourly> loadrateHourlys = new ArrayList<>();
+            //行
+            for (int i1 = 0; i1 < sheetAt.getLastRowNum() - 1; i1++) {
+                XSSFRow row = sheetAt.getRow(i1 + 2);
+                LoadrateHourly lrh = new LoadrateHourly();
+                lrh.setId(getCellValue(row.getCell(0)));
+                lrh.setBranchcount(getCellValue(row.getCell(1)));
+                lrh.setPlatecount(getCellValue(row.getCell(2)));
+                lrh.setPlatecapacity(getCellValue(row.getCell(3)));
+                lrh.setTime(getCellValue(row.getCell(4)));
+                lrh.setPower(getCellValue(row.getCell(5)));
+                lrh.setLoadfactor(getCellValue(row.getCell(6)));
+                lrh.setGeneratedenergy(getCellValue(row.getCell(7)));
+                lrh.setUtilizationhour(getCellValue(row.getCell(8)));
+                loadrateHourlys.add(lrh);
+            }
+            loadrateHourlysMap.put(ptMap.get(i), loadrateHourlys);
+        }
+        return loadrateHourlysMap;
+    }
+
+    public String getCellValue(Cell cell) {
+        if (cell == null) return "";
+        String cellValue = "";
+        //判断数据的类型
+        switch (cell.getCellType()) {
+            case NUMERIC: //数字
+                cellValue = String.valueOf(cell.getNumericCellValue());
+                break;
+            case STRING: //字符串
+                cellValue = String.valueOf(cell.getStringCellValue());
+                break;
+            case BOOLEAN: //Boolean
+                cellValue = String.valueOf(cell.getBooleanCellValue());
+                break;
+            case FORMULA: //公式
+                cellValue = String.format("%.2f", cell.getNumericCellValue());
+                break;
+            default:
+                break;
+        }
+        return cellValue;
+    }
+
+    public Map<String, Map<String, List<LoadrateHourly>>> readExcel(String time) {
+        Map<String, Map<String, List<LoadrateHourly>>> lrhs = new HashMap<>();
+        Map<String, File> allPath = getAllPath(time);
+        for (Map.Entry<String, File> stringFileEntry : allPath.entrySet()) {
+            Map<String, List<LoadrateHourly>> stringListMap = sheets2LoadrateHourly(stringFileEntry.getValue());
+            lrhs.put(stringFileEntry.getKey(), stringListMap);
+        }
+        return lrhs;
+    }
+
+    public List<LoadrateHourly> readExcel(String stationid, String date, String time) {
+        File file = getPath(date, time);
+        List<LoadrateHourly> stringListMap = null;
+        if (file.exists()) {
+            stringListMap = sheets2LoadrateHourly(stationid, file,time);
+        }
+        return stringListMap;
+    }
+
+    private List<LoadrateHourly> sheets2LoadrateHourly(String stationid, File file, String time) {
+        XSSFWorkbook sheets = null;
+        try {
+            sheets = new XSSFWorkbook(file);
+        } catch (IOException | InvalidFormatException e) {
+            e.printStackTrace();
+        }
+        getPtMap();
+        getTpMap();
+        XSSFSheet sheetAt = sheets.getSheetAt(tpMap.get(stationid));
+        List<LoadrateHourly> loadrateHourlys = new ArrayList<>();
+        if(time.equals("2200")){
+            for (int i1 = 0; i1 < sheetAt.getLastRowNum() - 1; i1++) {
+                XSSFRow row = sheetAt.getRow(i1 + 2);
+                LoadrateHourly lrh = new LoadrateHourly();
+                lrh.setId(getCellValue(row.getCell(0)));
+                lrh.setBranchcount(getCellValue(row.getCell(1)));
+                lrh.setPlatecount(getCellValue(row.getCell(2)));
+                lrh.setPlatecapacity(getCellValue(row.getCell(3)));
+                lrh.setTime(getCellValue(row.getCell(4)));
+                lrh.setGeneratedenergy(getCellValue(row.getCell(5)));
+                lrh.setUtilizationhour(getCellValue(row.getCell(6)));
+                loadrateHourlys.add(lrh);
+            }
+        }else {
+            for (int i1 = 0; i1 < sheetAt.getLastRowNum() - 1; i1++) {
+                XSSFRow row = sheetAt.getRow(i1 + 2);
+                LoadrateHourly lrh = new LoadrateHourly();
+                lrh.setId(getCellValue(row.getCell(0)));
+                lrh.setBranchcount(getCellValue(row.getCell(1)));
+                lrh.setPlatecount(getCellValue(row.getCell(2)));
+                lrh.setPlatecapacity(getCellValue(row.getCell(3)));
+                lrh.setTime(getCellValue(row.getCell(4)));
+                lrh.setPower(getCellValue(row.getCell(5)));
+                lrh.setLoadfactor(getCellValue(row.getCell(6)));
+                loadrateHourlys.add(lrh);
+            }
+        }
+        return loadrateHourlys;
+    }
+}

+ 1 - 1
src/main/resources/application-dev.yml

@@ -25,7 +25,7 @@ spring:
      #两票数据源
      ticket:
        #url: jdbc:sqlserver://123.60.213.70:1433;DatabaseName=fdeam
-       url: jdbc:sqlserver://10.155.32.2:1433;DatabaseName=fdeam
+       url: jdbc:sqlserver://192.168.1.82:1433;DatabaseName=fdeam
        username: sa
        password: Gyee@321#!
        driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver