鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
2025-06-17 314732a211804507b775deeb06eb7f9d08e451e6
ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
@@ -8,8 +8,11 @@
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.framework.excel.core.util.ExcelUtils;
import com.iailab.module.ansteel.api.dto.*;
import com.iailab.module.ansteel.api.vo.PowerCapacitorHisPageReqVO;
import com.iailab.module.ansteel.api.vo.PowerExportCosVO;
import com.iailab.module.ansteel.api.vo.PowerExportPqVO;
import com.iailab.module.ansteel.api.vo.PowerMaxDemandMainPageReqVO;
import com.iailab.module.ansteel.common.constant.CommonConstant;
import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum;
@@ -33,6 +36,9 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -839,10 +845,24 @@
        return success(result);
    }
    /**
     * 导出功率日累计
     * 月报表导出:最大值、最小值、平均值、受电累计、返送累计
     * 日功率因数二级界面:最大值、最小值、平均值、日功率因数
     * 月功率因数二级界面:最大值、最小值、平均值、月功率因数
     *
     * @param response
     * @param request
     * @param dto
     */
    @PostMapping("/net-factor/export-day")
    @Operation(summary = "功率因数-电网拓扑功率导出(功率日累计)")
    public CommonResult<List<PowerFactorExcelDTO>> getPowerFactorExportDay(@RequestBody PowerFactorExcelReqDTO dto) {
        List<PowerFactorExcelDTO> result = new ArrayList<>();
    public void getPowerFactorExportDay(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PowerFactorExcelReqDTO dto) throws IOException {
        List<PowerExportPqVO> exportPqList = new ArrayList<>();
        List<PowerExportCosVO> exportCos = new ArrayList<>();
        if (dto.getStartTime() == null) {
            dto.setStartTime(new Date());
        }
@@ -864,6 +884,7 @@
        Date endTime = calendar.getTime();
        String pointNo = "=";
        String[] pointNoArr = new String[2];
        String queryType = dto.getQueryType();
        PowerNetFactorEntity powerNetFactorEntity = powerNetFactorService.getByNodeCode(dto.getNodeCode());
        Calendar curDay = Calendar.getInstance();
@@ -878,19 +899,27 @@
                case "Q":
                    pointNo = powerNetFactorEntity.getCurQ();
                    break;
                case "DAYCOS":
                    pointNoArr[0] = powerNetFactorEntity.getPDay();
                    pointNoArr[1] = powerNetFactorEntity.getQDay();
                    break;
                case "MONTHCOS":
                    pointNoArr[0] = powerNetFactorEntity.getPMon();
                    pointNoArr[1] = powerNetFactorEntity.getQMon();
                    break;
                default:
                    return success(result);
            }
            if (StringUtils.isEmpty(pointNo)) {
                return success(result);
                    return;
            }
            List<Double> valueList = new ArrayList<>();
            ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO();
            apiPointValueQueryDTO.setPointNo(pointNo);
            apiPointValueQueryDTO.setStart(curDay.getTime());
            curDay.add(Calendar.DAY_OF_YEAR, 1);
            apiPointValueQueryDTO.setEnd(curDay.getTime());
            List<Double> valueList = new ArrayList<>();
            Double lastValue = null;
            if (StringUtils.isNotBlank(pointNo)) {
                // 单点
                apiPointValueQueryDTO.setPointNo(pointNo);
            List<ApiPointValueDTO> chartData = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO);
            for (ApiPointValueDTO pv : chartData) {
                Object[] data = new Object[2];
@@ -898,47 +927,91 @@
                data[1] = pv.getV();
                valueList.add(pv.getV());
            }
            } else if (StringUtils.isNotBlank(pointNoArr[0]) && StringUtils.isNotBlank(pointNoArr[1])) {
                List<String> categories = new ArrayList<>();
                // P/Q
                apiPointValueQueryDTO.setPointNo(pointNoArr[0]);
                List<ApiPointValueDTO> chartDataP = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO);
                Map<String, Double> dataMapP = new HashMap<>();
                for (ApiPointValueDTO pv : chartDataP) {
                    categories.add(DateUtils.format(pv.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
                    dataMapP.put(DateUtils.format(pv.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), pv.getV());
                }
            double day = 0;
                apiPointValueQueryDTO.setPointNo(pointNoArr[1]);
                List<ApiPointValueDTO> chartDataQ = dataPointApi.queryPointHistoryValue(apiPointValueQueryDTO);
                Map<String, Double> dataMapQ = new HashMap<>();
                for (ApiPointValueDTO pv : chartDataQ) {
                    dataMapQ.put(DateUtils.format(pv.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), pv.getV());
                }
                for (String cate : categories) {
                    Double cos = PowerUtil.calculateCos(dataMapP.get(cate), dataMapQ.get(cate));
                    valueList.add(cos);
                }
            }
            double max = 0;
            double min = 0;
            double avg = 0;
            double fsl = 0;
            if (!CollectionUtils.isEmpty(valueList)) {
                day = valueList.stream().mapToDouble(Double::doubleValue).sum();
                max = valueList.stream().mapToDouble(Double::doubleValue).max().getAsDouble();
                min = valueList.stream().mapToDouble(Double::doubleValue).min().getAsDouble();
                avg = valueList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
            }
            if ("P".equals(queryType.toUpperCase()) || "Q".equals(queryType.toUpperCase())) {
                PowerExportPqVO evo = new PowerExportPqVO();
                double sdl = 0;
                double fsl = 0;
                if (!CollectionUtils.isEmpty(valueList)) {
                if (powerNetFactorEntity.getCurFlag() != null && powerNetFactorEntity.getCurFlag().intValue() != 0) {
                    for ( Double val : valueList) {
                        if (new BigDecimal(val).compareTo(BigDecimal.ZERO) != powerNetFactorEntity.getCurFlag()) {
                            // 未发生返送
                            continue;
                        }
                                sdl += val;
                            } else {
                                // 发生返送
                        fsl += val;
                    }
                }
            }
            excelDTO.setDay(new BigDecimal(day).setScale(2, BigDecimal.ROUND_HALF_UP));
            excelDTO.setMax(new BigDecimal(max).setScale(2, BigDecimal.ROUND_HALF_UP));
            excelDTO.setMin(new BigDecimal(min).setScale(2, BigDecimal.ROUND_HALF_UP));
            excelDTO.setAvg(new BigDecimal(avg).setScale(2, BigDecimal.ROUND_HALF_UP));
            // 当查询为P, Q,且有返送flag时 计算 返送累计
            if (("P".equals(queryType.toUpperCase()) || "Q".equals(queryType.toUpperCase())) &&
                    powerNetFactorEntity.getCurFlag() != null &&
                    powerNetFactorEntity.getCurFlag().intValue() != 0) {
                excelDTO.setFsl(new BigDecimal(fsl).setScale(2, BigDecimal.ROUND_HALF_UP));
                }
                evo.setSdl(new BigDecimal(sdl).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setFsl(new BigDecimal(fsl).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setMax(new BigDecimal(max).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setMin(new BigDecimal(min).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setAvg(new BigDecimal(avg).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setDate(DateUtils.format(apiPointValueQueryDTO.getStart()));
                exportPqList.add(evo);
            } else if ("DAYCOS".equals(queryType.toUpperCase()) || "MONTHCOS".equals(queryType.toUpperCase())) {
                double dayLast = 0;
                if (!CollectionUtils.isEmpty(valueList)) {
                    dayLast = valueList.get(valueList.size() - 1);
                }
                PowerExportCosVO evo = new PowerExportCosVO();
                evo.setCos(new BigDecimal(dayLast).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setMax(new BigDecimal(max).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setMin(new BigDecimal(min).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setAvg(new BigDecimal(avg).setScale(2, BigDecimal.ROUND_HALF_UP));
                evo.setDate(DateUtils.format(apiPointValueQueryDTO.getStart()));
                exportCos.add(evo);
            }
            excelDTO.setDate(DateUtils.format(apiPointValueQueryDTO.getStart()));
            result.add(excelDTO);
        } while (curDay.getTime().getTime() <= endTime.getTime());
        return success(result);
        if ("P".equals(queryType.toUpperCase()) || "Q".equals(queryType.toUpperCase())) {
            String name = powerNetFactorEntity.getNodeName() +
                    queryType.toUpperCase().replace("P", "有功").replace("Q", "无功") +
                    "功率报表.xls";
            ExcelUtils.write(response, name, "功率数据", PowerExportPqVO.class, exportPqList);
        } else if ("DAYCOS".equals(queryType.toUpperCase()) || "MONTHCOS".equals(queryType.toUpperCase())) {
            String name = powerNetFactorEntity.getNodeName() +
                    queryType.toUpperCase().replace("DAYCOS", "日").replace("MONTHCOS", "月") +
                    "功率因数报表.xls";
            ExcelUtils.write(response, name, "功率数据", PowerExportPqVO.class, exportPqList);
        }
    }
    @PostMapping("/net-factor/history")