鞍钢鲅鱼圈能源管控系统后端代码
dongyukun
19 小时以前 9a772cdec621410aa02130e54fd31df79d80669f
ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
@@ -556,4 +556,75 @@
        return success(result);
    }
    @PostMapping("/gen/history")
    @Operation(summary = "功率因数-发电机组功率历史")
    public CommonResult<PowerHistoryDTO> getPowerGenStatusHistory(@RequestBody PowerGenStatusHisReqDTO dto) {
        log.info("请求参数: {}", JSONObject.toJSONString(dto));
        // 参数校验
        if (StringUtils.isBlank(dto.getId())) {
            return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST, "id不能为空");
        }
        if (StringUtils.isBlank(dto.getQueryType())) {
            return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST, "queryType不能为空");
        }
        PowerGenStatusEntity powerGenStatus = powerGenStatusDaoService.getById(dto.getId());
        if (powerGenStatus == null) {
            log.info("未找到code对应的数据: {}", dto.getId());
            return success(new PowerHistoryDTO());
        }
        String queryType = dto.getQueryType().toUpperCase();
        String pointNo;
        switch (queryType.toUpperCase()) {
            case "D":
                pointNo = powerGenStatus.getCurP();
                break;
            case "P":
                pointNo = powerGenStatus.getCurQ();
                break;
            case "COS":
                pointNo = powerGenStatus.getCurCOS();
                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);
    }
}