鞍钢鲅鱼圈能源管控系统后端代码
dongyukun
8 天以前 0ff042d1a14255067b2368066c533c0d3ef86078
ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPeakValleyFlatTask.java
@@ -43,68 +43,36 @@
            //根据测点分组
            Map<String, List<PeakValleyFlatEntity>> groupedByPointNo = list.stream()
                    .collect(Collectors.groupingBy(PeakValleyFlatEntity::getPowerNo));
                    .collect(Collectors.groupingBy(PeakValleyFlatEntity::getPointNo));
            groupedByPointNo.entrySet().stream().forEach(entry -> {
                //计算昨日的累积量
                double value = getSumValue(entry.getValue(), 1, calendar);
                //计算昨日总电耗
                calendar.set(Calendar.MILLISECOND, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                Date endTime = calendar.getTime();
                calendar.add(Calendar.DAY_OF_YEAR, -1);
                Date startTime = calendar.getTime();
                double totalValue = getSumValueTotal(entry.getValue().get(0).getPowerNo(), startTime,endTime);
                //下发昨日占比
                //下发昨日的累积量
                ApiPointValueWriteDTO dto = new ApiPointValueWriteDTO();
                dto.setPointNo(entry.getValue().get(0).getPointNo());
                dto.setValue(value/totalValue*100);
                dto.setValue(value);
                dataPointApi.writePointRealValue(dto);
                if(entry.getValue().get(0).getPointNoMonth()!=null){
                    //计算前三十日累积量
                    double value30 = 0;
                    for (int i = 1; i < 31; i++) {
                        //计算前三十日累积量
                        value30 = value30 + getSumValue(entry.getValue(), i, calendar);
                    }
                    //计算前三十日总电耗
                    calendar.set(Calendar.MILLISECOND, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.add(Calendar.DAY_OF_YEAR, -30);
                    Date startTimeMonth = calendar.getTime();
                    double totalValueMonth = getSumValueTotal(entry.getValue().get(0).getPowerNo(), startTimeMonth,endTime);
                    //下发前三十日占比
                    ApiPointValueWriteDTO monthDto = new ApiPointValueWriteDTO();
                    monthDto.setPointNo(entry.getValue().get(0).getPointNoMonth());
                    monthDto.setValue(value30/totalValueMonth*100);
                    dataPointApi.writePointRealValue(monthDto);
                }
            });
        } catch (Exception ex) {
            logger.error("runPeakValleyFlatTask运行异常");
            ex.printStackTrace();
            logger.error("runPeakValleyFlatTask运行异常", ex);
        }
    }
    private Date getTime(String timeStr, int ago, Calendar calendar) {
        Calendar cal = (Calendar) calendar.clone();
        String[] timeSplit = timeStr.split(":");
        if (timeSplit.length != 2) {
            throw new IllegalArgumentException("时间配置格式不合法");
        }
        //根据配置获取startTime、endTime
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeSplit[0]));
        calendar.set(Calendar.MINUTE, Integer.parseInt(timeSplit[1]));
        calendar.add(Calendar.DAY_OF_YEAR, -ago);
        return calendar.getTime();
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeSplit[0]));
        cal.set(Calendar.MINUTE, Integer.parseInt(timeSplit[1]));
        cal.add(Calendar.DAY_OF_YEAR, -ago);
        return cal.getTime();
    }
    private List<ApiPointValueDTO> fillMissingData(List<ApiPointValueDTO> valueList,
@@ -169,6 +137,7 @@
            dto.setPointNo(entity.getPowerNo());
            dto.setStart(startTime);
            dto.setEnd(endTime);
            logger.info("开始查询,测点:"+entity.getPowerNo()+"startTime:"+startTime+"endTime:"+endTime);
            //查找数据
            List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(dto);
@@ -179,19 +148,5 @@
            value = value + sum;
        }
        return value / 60;
    }
    private double getSumValueTotal(String pointNo, Date startTime, Date endTime) {
        ApiPointValueQueryDTO dto = new ApiPointValueQueryDTO();
        dto.setPointNo(pointNo);
        dto.setStart(startTime);
        dto.setEnd(endTime);
        //查找数据
        List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(dto);
        //补全数据
        valueList = fillMissingData(valueList, startTime, endTime);
        //累加
        return valueList.stream().mapToDouble(ApiPointValueDTO::getV).sum()/ 60;
    }
}