鞍钢鲅鱼圈能源管控系统后端代码
dongyukun
4 天以前 23b9c4e1023c4566ccb179f16fcb2abef9ac1a5e
ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/admin/PowerController.java
@@ -1,13 +1,18 @@
package com.iailab.module.ansteel.api.controller.admin;
import cn.hutool.core.util.NumberUtil;
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.ansteel.power.service.*;
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;
@@ -19,6 +24,8 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.iailab.framework.common.pojo.CommonResult.success;
@@ -50,6 +57,12 @@
    @Autowired
    private PowerGenStatusDaoService powerGenStatusDaoService;
    @Autowired
    private PowerDemandService powerDemandService;
    @Autowired
    private PowerAdjustedFactorService powerAdjustedFactorService;
    @Resource
    private DataPointApi dataPointApi;
@@ -71,6 +84,7 @@
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        for (PowerNetFactorDTO dto : result) {
            boolean cosFlag = false;
            try {
                List<String> points = new ArrayList<>();
                if (StringUtils.isNotBlank(dto.getCurP())) {
@@ -89,6 +103,7 @@
                    }
                    if (pointsRealValue.get(dto.getCurCos()) != null) {
                        dto.setCurCos(pointsRealValue.get(dto.getCurCos()).toString());
                        cosFlag = true;
                    }
                }
            } catch (Exception ex) {
@@ -125,7 +140,26 @@
            } catch (Exception ex) {
                log.info(dto.getNodeName() + "获取预测值异常," + ex.getMessage());
            }
            // 设置状态
            if (cosFlag && StringUtils.isNotBlank(dto.getCurCos()) && NumberUtil.isNumber(dto.getCurCos())) {
                BigDecimal curCos = new BigDecimal(dto.getCurCos());
                if (dto.getLimitL() != null && dto.getLimitH() != null &&
                        curCos.compareTo(dto.getLimitL()) < 0 || curCos.compareTo(dto.getLimitH()) > 0) {
                    dto.setStatus(1);
                } else {
                    dto.setStatus(0);
                }
            }
        }
        return success(result);
    }
    @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);
    }
@@ -269,4 +303,190 @@
        });
        return success(result);
    }
    @GetMapping("/demand/list")
    @Operation(summary = "负荷移植-月最大需量,实测需量,有功功率")
    public CommonResult<List<PowerDemandDTO>> getPowerDemandList(@RequestParam Map<String, Object> params) {
        List<PowerDemandEntity> list = powerDemandService.list(params);
        List<PowerDemandDTO> result = ConvertUtils.sourceToTarget(list, PowerDemandDTO.class);
        if (CollectionUtils.isEmpty(result)) {
            return success(result);
        }
        for (PowerDemandDTO dto : result) {
            List<String> points = new ArrayList<>();
            if (StringUtils.isNotBlank(dto.getCurDemand())) {
                points.add(dto.getCurDemand());
            }
            if (StringUtils.isNotBlank(dto.getActivePower())) {
                points.add(dto.getActivePower());
            }
            if (!CollectionUtils.isEmpty(points)) {
                Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
                if (pointsRealValue.get(dto.getCurDemand()) != null) {
                    dto.setCurDemand(pointsRealValue.get(dto.getCurDemand()).toString());
                }
                if (pointsRealValue.get(dto.getActivePower()) != null) {
                    dto.setActivePower(pointsRealValue.get(dto.getActivePower()).toString());
                }
            }
            if (!StringUtils.isEmpty(dto.getMaxDemand())) {
                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);
                Date start = calendar.getTime();
                ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO();
                apiPointValueQueryDTO.setStart(start);
                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()) {
                        max = monthValues.get(i).getV();
                    }
                }
                dto.setMaxDemand(String.valueOf(max));
            }
        }
        return success(result);
    }
    @GetMapping("/net-factor/historyData")
    @Operation(summary = "功率因数-根据nodeName获取最近1440min历史数据,月最大,最小值")
    public CommonResult<PowerHistoryDTO> getPowerHistoryData(@RequestParam Map<String, Object> params) {
        PowerNetFactorEntity powerNetFactor = powerNetFactorService.list(params).get(0);
        PowerHistoryDTO result = new PowerHistoryDTO();
        if (powerNetFactor == null) {
            return success(result);
        }
        ApiPointValueQueryDTO apiPointValueQueryDTO = new ApiPointValueQueryDTO();
        String pointNo = "";
        Date start = null;
        Date end = null;
        switch (params.get("queryType").toString()) {
            case "p":
                pointNo = powerNetFactor.getCurP();
            case "q":
                pointNo = powerNetFactor.getCurQ();
            case "cos":
                pointNo = powerNetFactor.getCurCos();
        }
        //查询图表
        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();
        }
        apiPointValueQueryDTO.setEnd(end);
        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);
            dataList.add(data);
        }
        List<String> categories = DateUtils.getTimeScale(start, end, 5);
        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<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);
        }
        result.setMax(getMax(monthDataList));
        result.setMin(getMin(monthDataList));
        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)) {
            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);
    }
}