| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.ansteel.api.dto.*; |
| | | import com.iailab.module.ansteel.power.entity.*; |
| | |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.PredictLastValueReqVO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | 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; |
| | |
| | | |
| | | @GetMapping("/net-factor-dropdown/list") |
| | | @Operation(summary = "功率因数-电网拓扑下拉列表") |
| | | public CommonResult<List<PowerNetFactorDropdownDTO>> getPowerNetFactorDropdownList(@RequestParam String nodeName) { |
| | | List<PowerNetFactorEntity> list = powerNetFactorService.listDropdown(nodeName); |
| | | List<PowerNetFactorDropdownDTO> result = ConvertUtils.sourceToTarget(list, PowerNetFactorDropdownDTO.class); |
| | | return success(result); |
| | | public CommonResult<List<PowerNetFactorDropdownDTO>> getPowerNetFactorDropdownList(@RequestParam String nodeCode) { |
| | | log.info("nodeCode=" + nodeCode); |
| | | List<PowerNetFactorEntity> list = powerNetFactorService.listDropdown(nodeCode); |
| | | return success(ConvertUtils.sourceToTarget(list, PowerNetFactorDropdownDTO.class)); |
| | | } |
| | | |
| | | /** |
| | |
| | | }); |
| | | return success(result); |
| | | } |
| | | |
| | | @GetMapping("/demand/list") |
| | | @Operation(summary = "负荷移植-月最大需量,实测需量,有功功率") |
| | | public CommonResult<List<PowerDemandDTO>> getPowerDemandList(@RequestParam Map<String, Object> params) { |
| | |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | Date start = calendar.getTime(); |
| | | calendar.add(Calendar.MONTH, 1); |
| | | Date end = calendar.getTime(); |
| | | ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO(); |
| | | apiPointValueQueryDTO.setStart(start); |
| | | apiPointValueQueryDTO.setEnd(end); |
| | | apiPointValueQueryDTO.setEnd(new Date()); |
| | | apiPointValueQueryDTO.setPointNo(dto.getMaxDemand()); |
| | | |
| | | List<ApiPointValueDTO> monthValues = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO); |
| | | double max = 0; |
| | | for (int i = 0; i < monthValues.size()-1; i++) { |
| | | if(max < monthValues.get(i).getV()){ |
| | | for (int i = 0; i < monthValues.size() - 1; i++) { |
| | | if (max < monthValues.get(i).getV()) { |
| | | max = monthValues.get(i).getV(); |
| | | } |
| | | } |
| | |
| | | |
| | | return success(result); |
| | | } |
| | | |
| | | @PostMapping("/net-factor/history") |
| | | @Operation(summary = "功率因数-根据nodeName获取最近1440min历史数据,月最大,最小值") |
| | | 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.getByNodeCode(nodeCode); |
| | | PowerHistoryDTO result = new PowerHistoryDTO(); |
| | | if (powerNetFactor == null) { |
| | | log.info("powerNetFactor is null"); |
| | | return success(result); |
| | | } |
| | | log.info("开始查询,"); |
| | | |
| | | ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO(); |
| | | String pointNo = ""; |
| | | switch (queryType.toUpperCase()) { |
| | | case "P": |
| | | pointNo = powerNetFactor.getCurP(); |
| | | break; |
| | | case "Q": |
| | | pointNo = powerNetFactor.getCurQ(); |
| | | break; |
| | | case "COS": |
| | | pointNo = powerNetFactor.getCurCos(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //查询图表 |
| | | apiPointValueQueryDTO.setPointNo(pointNo); |
| | | 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<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); |
| | | result.setCategories(categories); |
| | | result.setDataList(dataList); |
| | | |
| | | //查询月最大最小值 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | start = calendar.getTime(); |
| | | apiPointValueQueryDTO.setStart(start); |
| | | apiPointValueQueryDTO.setEnd(new Date()); |
| | | List<ApiPointValueDTO> monthChartData = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO); |
| | | List<Double> monthValues = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(monthChartData)) { |
| | | monthValues = monthChartData.stream().map(item -> item.getV()).collect(Collectors.toList()); |
| | | result.setMax(monthValues.stream().max(Double::compareTo).get()); |
| | | result.setMin(monthValues.stream().min(Double::compareTo).get()); |
| | | } |
| | | return success(result); |
| | | } |
| | | |
| | | private double getMin(List<List<Object>> dataList) { |
| | | double result = Double.parseDouble(dataList.get(0).get(1).toString()); |
| | | for (int i = 0; i < dataList.size() - 1; i++) { |
| | | if (result > Double.parseDouble(dataList.get(i).get(1).toString())) { |
| | | result = Double.parseDouble(dataList.get(i).get(1).toString()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private double getMax(List<List<Object>> dataList) { |
| | | double result = 0; |
| | | for (int i = 0; i < dataList.size() - 1; i++) { |
| | | if (result < Double.parseDouble(dataList.get(i).get(1).toString())) { |
| | | result = Double.parseDouble(dataList.get(i).get(1).toString()); |
| | | } |
| | | } |
| | | 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)) { |
| | | log.info("PowerAdjustedFactor List is empty"); |
| | | return success(result); |
| | | } |
| | | List<String> points = new ArrayList<>(); |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | for (PowerAdjustedFactorDTO dto : dtoList) { |
| | | if (StringUtils.isNotBlank(dto.getPointNo())) { |
| | | points.add(dto.getPointNo()); |
| | | } |
| | | } |
| | | if (!CollectionUtils.isEmpty(points)) { |
| | | dataMap = dataPointApi.queryPointsRealValue(points); |
| | | } |
| | | |
| | | for (PowerAdjustedFactorDTO powerAdjustedFactorDTO : dtoList) { |
| | | Double value = dataMap.get(powerAdjustedFactorDTO.getPointNo()) == null ? 0 : Double.parseDouble(dataMap.get(powerAdjustedFactorDTO.getPointNo()).toString()); |
| | | result.put(powerAdjustedFactorDTO.getName(), value); |
| | | } |
| | | return success(result); |
| | | } |
| | | |
| | | @PostMapping("/demand/history") |
| | | @Operation(summary = "负荷移植-实测需量,有功功率 历史") |
| | | public CommonResult<PowerHistoryDTO> getPowerDemandHistory(@RequestBody PowerDemandHisReqDTO dto) { |
| | | log.info("请求参数: {}", JSONObject.toJSONString(dto)); |
| | | |
| | | // 参数校验 |
| | | if (StringUtils.isBlank(dto.getCode())) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST, "code不能为空"); |
| | | } |
| | | if (StringUtils.isBlank(dto.getQueryType())) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST, "queryType不能为空"); |
| | | } |
| | | |
| | | PowerDemandEntity powerDemand = powerDemandService.getByCode(dto.getCode()); |
| | | if (powerDemand == null) { |
| | | log.info("未找到code对应的数据: {}", dto.getCode()); |
| | | return success(new PowerHistoryDTO()); |
| | | } |
| | | |
| | | String queryType = dto.getQueryType().toUpperCase(); |
| | | String pointNo; |
| | | switch (queryType.toUpperCase()) { |
| | | case "D": |
| | | pointNo = powerDemand.getCurDemand(); |
| | | break; |
| | | case "P": |
| | | pointNo = powerDemand.getActivePower(); |
| | | break; |
| | | default: |
| | | throw new IllegalArgumentException("不支持的queryType: " + queryType); |
| | | } |
| | | |
| | | // 默认查最近24小时 |
| | | Date end = Optional.ofNullable(dto.getEndTime()).orElseGet(() -> { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | return cal.getTime(); |
| | | }); |
| | | |
| | | Date start = Optional.ofNullable(dto.getStartTime()).orElseGet(() -> { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(end); |
| | | cal.add(Calendar.MINUTE, -1440); // 24小时前 |
| | | return cal.getTime(); |
| | | }); |
| | | |
| | | // 查询历史数据 |
| | | ApiPointValueQueryDTO query = new ApiPointValueQueryDTO(); |
| | | query.setPointNo(pointNo); |
| | | query.setStart(start); |
| | | query.setEnd(end); |
| | | |
| | | log.info("开始查询实测需量/有功功率历史数据,测点: {}", pointNo); |
| | | List<ApiPointValueDTO> chartData = dataPointApi.queryPointHistoryValue(query); |
| | | |
| | | // 构建返回结果 |
| | | PowerHistoryDTO result = new PowerHistoryDTO(); |
| | | result.setCategories(DateUtils.getTimeScale(start, end, 60)); |
| | | result.setDataList(chartData.stream() |
| | | .map(pv -> new Object[]{ |
| | | DateUtils.format(pv.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), |
| | | pv.getV() |
| | | }) |
| | | .collect(Collectors.toList())); |
| | | |
| | | return success(result); |
| | | } |
| | | } |