鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
昨天 dc014eb097de2fbf2664b3164076361019dcfcbb
ansteel-biz/src/main/java/com/iailab/module/ansteel/api/service/impl/DataServiceImpl.java
@@ -3,15 +3,20 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.module.ansteel.api.dao.*;
import com.iailab.module.ansteel.api.dao.MainProcessIndexDayDao;
import com.iailab.module.ansteel.api.dao.MainProcessIndexTeamDao;
import com.iailab.module.ansteel.api.dto.*;
import com.iailab.module.ansteel.api.service.DataService;
import com.iailab.module.ansteel.common.constant.CommonConstant;
import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum;
import com.iailab.module.ansteel.power.dao.*;
import com.iailab.module.ansteel.power.entity.PowerCapacitorStatusEntity;
import com.iailab.module.ansteel.power.entity.PowerControlDetEntity;
import com.iailab.module.ansteel.power.entity.PowerControlMainEntity;
import com.iailab.module.ansteel.power.entity.PowerNetFactorEntity;
import com.iailab.module.ansteel.api.service.DataService;
import com.iailab.module.ansteel.common.constant.CommonConstant;
import com.iailab.module.data.api.ind.IndItemApi;
import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO;
import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
import com.iailab.module.data.api.plan.PlanItemApi;
import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
import com.iailab.module.data.api.point.DataPointApi;
@@ -28,6 +33,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Slf4j
@@ -36,6 +42,8 @@
    @Autowired
    private DataPointApi dataPointApi;
    @Autowired
    private IndItemApi indItemApi;
    @Autowired
    private McsApi mcsApi;
@@ -105,9 +113,9 @@
    @Override
    public List<MainProcessIndexDTO> getIndexList(Map<String, Object> params) {
        List<MainProcessIndexDTO> list = new ArrayList<>();
        if("day".equals(params.get("type"))) {
        if ("day".equals(params.get("type"))) {
            list = ConvertUtils.sourceToTarget(mainProcessIndexDayDao.selectList(new QueryWrapper<>()), MainProcessIndexDTO.class);
        }else if("team".equals(params.get("type"))){
        } else if ("team".equals(params.get("type"))) {
            list = ConvertUtils.sourceToTarget(mainProcessIndexTeamDao.selectList(new QueryWrapper<>()), MainProcessIndexDTO.class);
        }
        if (!CollectionUtils.isEmpty(list)) {
@@ -139,6 +147,11 @@
    }
    @Override
    public Boolean ignoreSuggest(StAlarmAndSuggestReqVO ReqVO) {
        return mcsApi.ignoreSuggest(ReqVO);
    }
    @Override
    public PreDataChartRespVO getPreDataChart(PreDataSingleChartReqVO reqVO) {
        Map<String, String> tMap = new HashMap<>();
        List<ChartParamDTO> list = mcsApi.getChartParamList(reqVO.getChartCode());
@@ -167,6 +180,7 @@
        int lengthRight = tMap.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(tMap.get(CommonConstant.LENGTH_RIGHT)).intValue();
        String trendsDataH = tMap.get(CommonConstant.TRENDSDATA_H) == null ? null : tMap.get(CommonConstant.TRENDSDATA_H);
        String trendsDataL = tMap.get(CommonConstant.TRENDSDATA_L) == null ? null : tMap.get(CommonConstant.TRENDSDATA_L);
        String culIndex = tMap.get(CommonConstant.CUL_INDEX) == null ? null : tMap.get(CommonConstant.CUL_INDEX);//累计量
        Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight);
        Date startTime = timeArray[1];
@@ -175,9 +189,12 @@
        PreDataSingleChartRespVO resultOld = mcsApi.getPreDataSingleChart(reqVO);
        PreDataChartRespVO result = ConvertUtils.sourceToTarget(resultOld, PreDataChartRespVO.class);
        PreDataViewDTO preDataView = ConvertUtils.sourceToTarget(resultOld.getDataView(), PreDataViewDTO.class);
        if(trendsDataH != null) {
        if (StringUtils.isNotBlank(trendsDataH)) {
            // 动态上限
            ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO();
            pointValueQueryDTO.setPointNo(trendsDataH);
            pointValueQueryDTO.setStart(startTime);
            pointValueQueryDTO.setEnd(endTime);
            List<ApiPointValueDTO> trendsDataHList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class);
            List<Object[]> newList = new ArrayList<>();
            trendsDataHList.forEach(item -> {
@@ -188,9 +205,12 @@
            });
            preDataView.setTrendsDataH(newList);
        }
        if(trendsDataL != null) {
        if (StringUtils.isNotBlank(trendsDataL)) {
            // 动态下限
            ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO();
            pointValueQueryDTO.setPointNo(trendsDataL);
            pointValueQueryDTO.setStart(startTime);
            pointValueQueryDTO.setEnd(endTime);
            List<ApiPointValueDTO> trendsDataLList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class);
            List<Object[]> newList = new ArrayList<>();
            trendsDataLList.forEach(item -> {
@@ -202,8 +222,20 @@
            preDataView.setTrendsDataL(newList);
        }
        List<Object[]> culData = new ArrayList<>();
        double leiji = 0;
        if (StringUtils.isNotBlank(culIndex) && !CollectionUtils.isEmpty(preDataView.getCurData())) {
            for(int i = 0; i < preDataView.getCurData().size(); i++) {
                Object[] item = preDataView.getCurData().get(i);
                Object[] dataItem = new Object[2];
                dataItem[0] = item[0];
                leiji = leiji + new BigDecimal(item[1].toString()).doubleValue();
                dataItem[1] = new BigDecimal(leiji).divide(new BigDecimal(60), 2, BigDecimal.ROUND_HALF_UP) ;
                culData.add(dataItem);
            }
        }
        preDataView.setCulData(culData);
        preDataView.setPreData(resultOld.getDataView().getPreDataL());
        result.setPreDataView(preDataView);
        return result;
    }
@@ -239,7 +271,7 @@
    }
    /**
     *  查询原始计划、修正计划数据
     * 查询原始计划、修正计划数据
     */
    @Override
    public Map<String, Object> getPlanDataChart(PlanDataChartReqVO reqVO) {
@@ -271,6 +303,9 @@
        }
        result.put("planData", planData);
        result.put("predData", predData);
        result.put("predictTime", DateUtils.format(predictTime, "yyyy-MM-dd HH:mm:00"));
        result.put("startTime", DateUtils.format(startTime, "yyyy-MM-dd HH:mm:00"));
        result.put("endTime", DateUtils.format(endTime, "yyyy-MM-dd HH:mm:00"));
        return result;
    }
@@ -365,4 +400,79 @@
        wrapper.orderByAsc("sort");
        return ConvertUtils.sourceToTarget(powerControlDetDao.selectList(wrapper), PowerControlDetDTO.class);
    }
    @Override
    public List<Object[]> getHistoryValue(Map<String, Object> params) {
        List<Object[]> dataList = new ArrayList<>();
        if (!params.containsKey("dataType") || !params.containsKey("dataNo")) {
            return dataList;
        }
        String dataType = params.get("dataType").toString();
        String dataNo = params.get("dataNo").toString();
        Date startTime = null;
        Date endTime = null;
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        if (!params.containsKey("endTime") || StringUtils.isBlank(params.get("endTime").toString())) {
            endTime = calendar.getTime();
        } else {
            endTime = DateUtils.parse(params.get("endTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
        }
        if (!params.containsKey("startTime") || StringUtils.isBlank(params.get("startTime").toString())) {
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            startTime = calendar.getTime();
        } else {
            startTime = DateUtils.parse(params.get("startTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
        }
        switch (ProcessConfDataTypeEnum.getEumByCode(dataType)) {
            case DATAPOINT:
                ApiPointValueQueryDTO queryParams1 = new ApiPointValueQueryDTO();
                queryParams1.setPointNo(dataNo);
                queryParams1.setStart(startTime);
                queryParams1.setEnd(endTime);
                List<com.iailab.module.data.api.point.dto.ApiPointValueDTO> pointHisValue = dataPointApi.queryPointHistoryValue(queryParams1);
                pointHisValue.forEach(item -> {
                    Object[] values = new Object[2];
                    values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
                    values[1] = new BigDecimal(item.getV()).setScale(3, BigDecimal.ROUND_HALF_UP);
                    dataList.add(values);
                });
                break;
            case IND:
                log.info("IND");
                ApiIndItemQueryDTO queryParams2 = new ApiIndItemQueryDTO();
                queryParams2.setItemNo(dataNo);
                queryParams2.setStart(startTime);
                queryParams2.setEnd(endTime);
                List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemHistoryValue(queryParams2);
                indValues.forEach(item -> {
                    Object[] values = new Object[2];
                    values[0] = item.getDataTime();
                    values[1] = item.getDataValue();
                    dataList.add(values);
                });
                break;
            default:
                break;
        }
        return dataList;
    }
    @Override
    public List<PreDataViewSimpleDTO> getPreDataByOutIds(PreDataBarLineReqVO reqVO) {
        PreDataBarLineRespVO preDataBarLineRespVO = mcsApi.getPreDataCharts(reqVO);
        List<PreDataViewSimpleDTO> preDataViewSimpleDTOList = new ArrayList<>();
        preDataBarLineRespVO.getDataViewList().forEach(item -> {
            PreDataViewSimpleDTO preDataViewSimpleDTO = new PreDataViewSimpleDTO();
            preDataViewSimpleDTO.setItemName(item.getResultName());
            preDataViewSimpleDTO.setPredictTime(preDataBarLineRespVO.getPredictTime());
            preDataViewSimpleDTO.setCurData(item.getCurData());
            preDataViewSimpleDTO.setRealData(item.getRealData());
            preDataViewSimpleDTOList.add(preDataViewSimpleDTO);
        });
        return preDataViewSimpleDTOList;
    }
}