| | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private PowerDemandService powerDemandService; |
| | | |
| | | @Autowired |
| | | private PowerAdjustedFactorService powerAdjustedFactorService; |
| | | |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | |
| | | return success(result); |
| | | } |
| | | |
| | | @GetMapping("/net-factor/historyData") |
| | | @PostMapping("/net-factor/history") |
| | | @Operation(summary = "功率因数-根据nodeName获取最近1440min历史数据,月最大,最小值") |
| | | public CommonResult<PowerHistoryDTO> getPowerHistoryData(@RequestParam Map<String, Object> params) { |
| | | |
| | | PowerNetFactorEntity powerNetFactor = powerNetFactorService.list(params).get(0); |
| | | public CommonResult<PowerHistoryDTO> getPowerHistoryData(@RequestBody PowerNetFactorHisReqDTO dto) { |
| | | log.info("PowerNetFactorHisReqDTO=" + JSONObject.toJSONString(dto)); |
| | | String nodeCode = dto.getNodeCode(); |
| | | if (StringUtils.isBlank(nodeCode)) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST); |
| | | } |
| | | String queryType = dto.getQueryType(); |
| | | if (StringUtils.isBlank(queryType)) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST); |
| | | } |
| | | PowerNetFactorEntity powerNetFactor = powerNetFactorService.getByNodeName(nodeCode); |
| | | PowerHistoryDTO result = new PowerHistoryDTO(); |
| | | if (powerNetFactor == null) { |
| | | log.info("powerNetFactor is null"); |
| | | return success(result); |
| | | } |
| | | log.info("开始查询,"); |
| | | |
| | | ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO(); |
| | | String pointNo = ""; |
| | | Date start = null; |
| | | Date end = null; |
| | | |
| | | switch (params.get("queryType").toString()) { |
| | | case "p": |
| | | switch (queryType.toUpperCase()) { |
| | | case "P": |
| | | pointNo = powerNetFactor.getCurP(); |
| | | |
| | | case "q": |
| | | break; |
| | | case "Q": |
| | | pointNo = powerNetFactor.getCurQ(); |
| | | |
| | | case "cos": |
| | | break; |
| | | case "COS": |
| | | pointNo = powerNetFactor.getCurCos(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //查询图表 |
| | | apiPointValueQueryDTO.setPointNo(pointNo); |
| | | SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | if (params.get("startTime") != null) { |
| | | try { |
| | | start = ft.parse(params.get("startTime").toString()); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } else { |
| | | start = new Date(System.currentTimeMillis() - 1440L * 60 * 1000); |
| | | } |
| | | apiPointValueQueryDTO.setStart(start); |
| | | if (params.get("endTime") != null) { |
| | | try { |
| | | end = ft.parse(params.get("endTime").toString()); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } else { |
| | | end = new Date(); |
| | | } |
| | | Calendar calendar0 = Calendar.getInstance(); |
| | | calendar0.set(Calendar.MILLISECOND, 0); |
| | | calendar0.set(Calendar.SECOND, 0); |
| | | Date end = dto.getEndTime() == null ? calendar0.getTime() : dto.getEndTime(); |
| | | calendar0.add(Calendar.MINUTE, -1440); |
| | | Date start = dto.getStartTime() == null ? calendar0.getTime() : dto.getStartTime(); |
| | | apiPointValueQueryDTO.setEnd(end); |
| | | apiPointValueQueryDTO.setStart(start); |
| | | List<ApiPointValueDTO> chartData = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO); |
| | | List<List<Object>> dataList = new ArrayList<>(); |
| | | for (ApiPointValueDTO dto : chartData) { |
| | | List<Object> data = new ArrayList<>(); |
| | | String time = ft.format(dto.getT()); |
| | | double value = dto.getV(); |
| | | data.add(time); |
| | | data.add(value); |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | for (ApiPointValueDTO pv : chartData) { |
| | | Object[] data = new Object[2]; |
| | | data[0] = DateUtils.format(pv.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | data[1] = pv.getV(); |
| | | dataList.add(data); |
| | | } |
| | | List<String> categories = DateUtils.getTimeScale(start, end, 60); |
| | |
| | | apiPointValueQueryDTO.setStart(start); |
| | | apiPointValueQueryDTO.setEnd(new Date()); |
| | | List<ApiPointValueDTO> monthChartData = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO); |
| | | List<List<Object>> monthDataList = new ArrayList<>(); |
| | | for (ApiPointValueDTO dto : monthChartData) { |
| | | List<Object> data = new ArrayList<>(); |
| | | String time = ft.format(dto.getT()); |
| | | double value = dto.getV(); |
| | | data.add(time); |
| | | data.add(value); |
| | | monthDataList.add(data); |
| | | List<Double> monthValues = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(monthChartData)) { |
| | | monthValues = monthChartData.stream().map(item -> { |
| | | return item.getV(); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | result.setMax(monthValues.stream().max(Double::compareTo).get()); |
| | | result.setMin(monthValues.stream().min(Double::compareTo).get()); |
| | | } |
| | | result.setMax(getMax(monthDataList)); |
| | | result.setMin(getMin(monthDataList)); |
| | | return success(result); |
| | | } |
| | | |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @GetMapping("/adjust-factor") |
| | | @Operation(summary = "负荷移植-调整后的功率因数与无功倒送量") |
| | | public CommonResult<Map<String, Double>> getPowerAdjustFactor(@RequestParam Map<String, Object> params) { |
| | | List<PowerAdjustedFactorEntity> list = powerAdjustedFactorService.list(params); |
| | | List<PowerAdjustedFactorDTO> dtoList = ConvertUtils.sourceToTarget(list, PowerAdjustedFactorDTO.class); |
| | | Map<String, Double> result = new HashMap<>(); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return success(result); |
| | | } |
| | | List<String> points = new ArrayList<>(); |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | for (PowerAdjustedFactorDTO dto : dtoList) { |
| | | points.add(dto.getPointNo()); |
| | | } |
| | | dataMap = dataPointApi.queryPointsRealValue(points); |
| | | for (PowerAdjustedFactorDTO powerAdjustedFactorDTO : dtoList) { |
| | | result.put(powerAdjustedFactorDTO.getName(), Double.parseDouble(dataMap.get(powerAdjustedFactorDTO.getPointNo()).toString())); |
| | | } |
| | | return success(result); |
| | | } |
| | | } |