NewPhotovoltaicController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package com.gyee.power.fitting.controller.gf;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.gyee.power.fitting.common.config.R;
  4. import com.gyee.power.fitting.common.config.ResultMsg;
  5. import com.gyee.power.fitting.common.config.StringUtils;
  6. import com.gyee.power.fitting.common.result.JsonResult;
  7. import com.gyee.power.fitting.common.result.ResultCode;
  8. import com.gyee.power.fitting.common.spring.InitialRunner;
  9. import com.gyee.power.fitting.model.ProBasicEquipment;
  10. import com.gyee.power.fitting.model.custom.FjjxbVo;
  11. import com.gyee.power.fitting.model.custom.PhotovoltaicInfo;
  12. import com.gyee.power.fitting.model.custom.TableTitle;
  13. import com.gyee.power.fitting.service.ProBasicEquipmentService;
  14. import com.gyee.power.fitting.service.impl.NewIvPvCurveFittingService;
  15. import io.swagger.annotations.ApiOperation;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.annotation.Resource;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.*;
  20. import java.util.stream.Collectors;
  21. @RestController
  22. @CrossOrigin
  23. @RequestMapping("/photovol")
  24. public class NewPhotovoltaicController {
  25. @Resource
  26. private NewIvPvCurveFittingService curveFittingService;
  27. @Resource
  28. private ProBasicEquipmentService equipmentService;
  29. @GetMapping("/filelist")
  30. private JSONObject getFileList(
  31. @RequestParam(value = "station", required = true) String station,
  32. @RequestParam(value = "inverters", required = true) List<String> inverters,
  33. @RequestParam(value = "startdate", required = true) long startdate,
  34. @RequestParam(value = "enddate", required = true) long enddate) {
  35. List<String> fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false);
  36. if (fileList == null) {
  37. try {
  38. curveFittingService.getDatas2File(station, startdate, enddate);
  39. curveFittingService.standardPointCalculate2();
  40. } catch (Exception e) {
  41. return JsonResult.error(ResultCode.ERROR_FILE_NO);
  42. }
  43. fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, true);
  44. }
  45. //Map<String, Object> table = curveFittingService.getTable(fileList.get(0));
  46. //table.put("filelist", fileList);
  47. List<Object> fileLists = curveFittingService.str2FileList(fileList);
  48. return JsonResult.successData(ResultCode.SUCCESS, fileLists);
  49. }
  50. @GetMapping("/allfilelist")
  51. private JSONObject getFileList() {
  52. List<String> fileList = curveFittingService.getAllFileList();
  53. List<Object> objects = curveFittingService.str2FileList(fileList);
  54. return JsonResult.successData(ResultCode.SUCCESS, objects);
  55. }
  56. /**
  57. * 单文件表格显示
  58. *
  59. * @param filename
  60. * @return
  61. */
  62. @GetMapping("/datas")
  63. private JSONObject getDatas(@RequestParam("filename") String filename) {
  64. Map<String, Object> table = curveFittingService.getTable(filename);
  65. return JsonResult.successData(ResultCode.SUCCESS, table);
  66. }
  67. //功率-时间曲线,根据文件
  68. @GetMapping("/analysis/powertimefile")
  69. private JSONObject powerTimeFile(@RequestParam("station") String station,
  70. @RequestParam("inverters") List<String> inverters,
  71. @RequestParam("startdate") long startdate,
  72. @RequestParam("enddate") long enddate) {
  73. List<String> fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false);
  74. Map<String, List<PhotovoltaicInfo>> infos = curveFittingService.calculatAnalysis(fileList);
  75. List<TableTitle> collect = curveFittingService.getTheoryTitel();
  76. Map<String, Object> table = new HashMap<>();
  77. Set<String> keys = infos.keySet();
  78. for (String key : keys) {
  79. for (ProBasicEquipment c : InitialRunner.newgfwtList) {
  80. if (key.equals(c.getId())) {
  81. table.put("name", c.getName());
  82. }
  83. }
  84. }
  85. table.put("title", collect);
  86. table.put("data", infos);
  87. return JsonResult.successData(ResultCode.SUCCESS, table);
  88. }
  89. @GetMapping("/gfjxb")
  90. public JSONObject gfjxb(@RequestParam("startdate") long startdate,
  91. @RequestParam("enddate") long enddate) {
  92. List<FjjxbVo> voList = curveFittingService.getPhotovoltaicPerformanceList(startdate, enddate);
  93. return JsonResult.successData(ResultCode.SUCCESS, voList);
  94. }
  95. //功率-光照-温度曲线
  96. @PostMapping("/analysis/powerbeam")
  97. private JSONObject powerBeamTemperature(@RequestParam("station") String station,
  98. @RequestParam("inverters") List<String> inverters,
  99. @RequestParam("startdate") long startdate,
  100. @RequestParam("enddate") long enddate) {
  101. // List<String> strings = jsonObj2List(null);
  102. // if (strings.size() > 450) return JsonResult.error(ResultCode.PARAM_NOT_VALID);
  103. List<String> fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false);
  104. List<PhotovoltaicInfo> infos = curveFittingService.calculatFitting(fileList);
  105. List<double[]> b = curveFittingService.oneFileFitting(infos);
  106. infos = infos.stream().filter(i -> i.getS() > 1).sorted(Comparator.comparing(PhotovoltaicInfo::getS)).collect(Collectors.toList());
  107. List<double[]> a = new ArrayList<>();
  108. for (PhotovoltaicInfo pi : infos) {
  109. double[] scatter = new double[3];
  110. scatter[0] = pi.getS();
  111. scatter[1] = pi.getActualP();
  112. scatter[2] = pi.getT();
  113. a.add(scatter);
  114. }
  115. HashMap<String, Object> map = new HashMap<>();
  116. map.put("scatter", a);
  117. map.put("curve", b);
  118. return JsonResult.successData(ResultCode.SUCCESS, map);
  119. }
  120. //文件删除
  121. @DeleteMapping("/delete/files")
  122. private JSONObject deleteFiles(@RequestBody JSONObject filename) {
  123. List<String> strings = jsonObj2List(filename);
  124. int i = curveFittingService.deleteFiles(strings);
  125. return JsonResult.successData(ResultCode.SUCCESS, "共删除" + i + "个文件,删除失败" + (strings.size() - i) + "个!");
  126. }
  127. private List<String> jsonObj2List(JSONObject filename) {
  128. String fn = filename.getString("filename");
  129. String[] split = fn.split(",");
  130. return Arrays.asList(split);
  131. }
  132. @GetMapping("/export/files")
  133. private void exportFiles(HttpServletResponse response, @RequestParam("filename") String filename) {
  134. String[] split = filename.split(",");
  135. curveFittingService.downFiles(Arrays.asList(split), response);
  136. }
  137. @GetMapping(value = "/wtByWplist")
  138. @ApiOperation(value = "风机列表", notes = "风机列表")
  139. public R wtByWplist(@RequestParam(value = "wpids", required = true) String wpids) {
  140. List<ProBasicEquipment> resultList = curveFittingService.wtByWplist(wpids);
  141. if (StringUtils.isNotNull(resultList)) {
  142. return R.data(ResultMsg.ok(resultList));
  143. } else {
  144. return R.error(ResultMsg.error());
  145. }
  146. }
  147. }