package com.gyee.power.fitting.controller.gf; import com.alibaba.fastjson.JSONObject; import com.gyee.power.fitting.common.config.R; import com.gyee.power.fitting.common.config.ResultMsg; import com.gyee.power.fitting.common.config.StringUtils; import com.gyee.power.fitting.common.result.JsonResult; import com.gyee.power.fitting.common.result.ResultCode; import com.gyee.power.fitting.common.spring.InitialRunner; import com.gyee.power.fitting.model.ProBasicEquipment; import com.gyee.power.fitting.model.custom.FjjxbVo; import com.gyee.power.fitting.model.custom.PhotovoltaicInfo; import com.gyee.power.fitting.model.custom.TableTitle; import com.gyee.power.fitting.service.ProBasicEquipmentService; import com.gyee.power.fitting.service.impl.NewIvPvCurveFittingService; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.*; import java.util.stream.Collectors; @RestController @CrossOrigin @RequestMapping("/photovol") public class NewPhotovoltaicController { @Resource private NewIvPvCurveFittingService curveFittingService; @Resource private ProBasicEquipmentService equipmentService; @GetMapping("/filelist") private JSONObject getFileList( @RequestParam(value = "station", required = true) String station, @RequestParam(value = "inverters", required = true) List inverters, @RequestParam(value = "startdate", required = true) long startdate, @RequestParam(value = "enddate", required = true) long enddate) { List fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false); if (fileList == null) { try { curveFittingService.getDatas2File(station, startdate, enddate); curveFittingService.standardPointCalculate2(); } catch (Exception e) { return JsonResult.error(ResultCode.ERROR_FILE_NO); } fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, true); } //Map table = curveFittingService.getTable(fileList.get(0)); //table.put("filelist", fileList); List fileLists = curveFittingService.str2FileList(fileList); return JsonResult.successData(ResultCode.SUCCESS, fileLists); } @GetMapping("/allfilelist") private JSONObject getFileList() { List fileList = curveFittingService.getAllFileList(); List objects = curveFittingService.str2FileList(fileList); return JsonResult.successData(ResultCode.SUCCESS, objects); } /** * 单文件表格显示 * * @param filename * @return */ @GetMapping("/datas") private JSONObject getDatas(@RequestParam("filename") String filename) { Map table = curveFittingService.getTable(filename); return JsonResult.successData(ResultCode.SUCCESS, table); } //功率-时间曲线,根据文件 @GetMapping("/analysis/powertimefile") private JSONObject powerTimeFile(@RequestParam("station") String station, @RequestParam("inverters") List inverters, @RequestParam("startdate") long startdate, @RequestParam("enddate") long enddate) { List fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false); Map> infos = curveFittingService.calculatAnalysis(fileList); List collect = curveFittingService.getTheoryTitel(); Map table = new HashMap<>(); Set keys = infos.keySet(); for (String key : keys) { for (ProBasicEquipment c : InitialRunner.newgfwtList) { if (key.equals(c.getId())) { table.put("name", c.getName()); } } } table.put("title", collect); table.put("data", infos); return JsonResult.successData(ResultCode.SUCCESS, table); } @GetMapping("/gfjxb") public JSONObject gfjxb(@RequestParam("startdate") long startdate, @RequestParam("enddate") long enddate) { List voList = curveFittingService.getPhotovoltaicPerformanceList(startdate, enddate); return JsonResult.successData(ResultCode.SUCCESS, voList); } //功率-光照-温度曲线 @PostMapping("/analysis/powerbeam") private JSONObject powerBeamTemperature(@RequestParam("station") String station, @RequestParam("inverters") List inverters, @RequestParam("startdate") long startdate, @RequestParam("enddate") long enddate) { // List strings = jsonObj2List(null); // if (strings.size() > 450) return JsonResult.error(ResultCode.PARAM_NOT_VALID); List fileList = curveFittingService.getFileList(station, inverters, startdate, enddate, false); List infos = curveFittingService.calculatFitting(fileList); List b = curveFittingService.oneFileFitting(infos); infos = infos.stream().filter(i -> i.getS() > 1).sorted(Comparator.comparing(PhotovoltaicInfo::getS)).collect(Collectors.toList()); List a = new ArrayList<>(); for (PhotovoltaicInfo pi : infos) { double[] scatter = new double[3]; scatter[0] = pi.getS(); scatter[1] = pi.getActualP(); scatter[2] = pi.getT(); a.add(scatter); } HashMap map = new HashMap<>(); map.put("scatter", a); map.put("curve", b); return JsonResult.successData(ResultCode.SUCCESS, map); } //文件删除 @DeleteMapping("/delete/files") private JSONObject deleteFiles(@RequestBody JSONObject filename) { List strings = jsonObj2List(filename); int i = curveFittingService.deleteFiles(strings); return JsonResult.successData(ResultCode.SUCCESS, "共删除" + i + "个文件,删除失败" + (strings.size() - i) + "个!"); } private List jsonObj2List(JSONObject filename) { String fn = filename.getString("filename"); String[] split = fn.split(","); return Arrays.asList(split); } @GetMapping("/export/files") private void exportFiles(HttpServletResponse response, @RequestParam("filename") String filename) { String[] split = filename.split(","); curveFittingService.downFiles(Arrays.asList(split), response); } @GetMapping(value = "/wtByWplist") @ApiOperation(value = "风机列表", notes = "风机列表") public R wtByWplist(@RequestParam(value = "wpids", required = true) String wpids) { List resultList = curveFittingService.wtByWplist(wpids); if (StringUtils.isNotNull(resultList)) { return R.data(ResultMsg.ok(resultList)); } else { return R.error(ResultMsg.error()); } } }