鞍钢鲅鱼圈能源管控系统后端代码
dongyukun
7 天以前 3d4783b231a4af203cb42c4bd6d87b1ca4d2239b
ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPeakValleyFlatTask.java
@@ -43,68 +43,69 @@
            //根据测点分组
            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);
                Calendar cal = (Calendar) calendar.clone();
                cal.set(Calendar.MILLISECOND, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.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);
                cal.add(Calendar.DAY_OF_YEAR, -1);
                Date startTime = cal.getTime();
                cal.add(Calendar.DAY_OF_YEAR, -29);
                Date monthStartTime = cal.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);
                dataPointApi.writePointRealValue(dto);
                ApiPointValueWriteDTO percentDto = new ApiPointValueWriteDTO();
                percentDto.setPointNo(entry.getValue().get(0).getPointNo());
                double percent = totalValue == 0 ? 0 : value / totalValue * 100;
                percentDto.setValue(percent);
                dataPointApi.writePointRealValue(percentDto);
                if(entry.getValue().get(0).getPointNoMonth()!=null){
                    //计算前三十日累积量
                    double value30 = 0;
                    for (int i = 1; i < 31; i++) {
                        //计算前三十日累积量
                        value30 = value30 + getSumValue(entry.getValue(), i, calendar);
                    }
                //下发昨日峰/谷累积量
                ApiPointValueWriteDTO totalDto = new ApiPointValueWriteDTO();
                percentDto.setPointNo(entry.getValue().get(0).getPointNoTotal());
                percentDto.setValue(value);
                dataPointApi.writePointRealValue(totalDto);
                    //计算前三十日总电耗
                    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);
                //计算前三十日峰/谷累积量
                double valueMonth = getSumValueTotal(entry.getValue().get(0).getPointNoTotal(), monthStartTime, endTime);
                    //下发前三十日占比
                    ApiPointValueWriteDTO monthDto = new ApiPointValueWriteDTO();
                    monthDto.setPointNo(entry.getValue().get(0).getPointNoMonth());
                    monthDto.setValue(value30/totalValueMonth*100);
                    dataPointApi.writePointRealValue(monthDto);
                }
                //计算前三十日总电耗
                double totalValueMonth = getSumValueTotal(entry.getValue().get(0).getPowerNo(), monthStartTime, endTime);
                //下发前三十日占比
                ApiPointValueWriteDTO monthDto = new ApiPointValueWriteDTO();
                monthDto.setPointNo(entry.getValue().get(0).getPointNoMonth());
                double percentMonth = totalValueMonth == 0 ? 0 : valueMonth / totalValueMonth * 100;
                monthDto.setValue(percentMonth);
                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,9 +170,14 @@
            dto.setPointNo(entity.getPowerNo());
            dto.setStart(startTime);
            dto.setEnd(endTime);
            logger.info("开始查询,测点:" + entity.getPowerNo() + "startTime:" + startTime + "endTime:" + endTime);
            List<ApiPointValueDTO> valueList;
            //查找数据
            List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(dto);
            try {
                valueList = dataPointApi.queryPointHistoryValue(dto);
            } catch (Exception e) {
                throw new RuntimeException("查询测点异常");
            }
            //补全数据
            valueList = fillMissingData(valueList, startTime, endTime);
            //累加
@@ -192,6 +198,6 @@
        //补全数据
        valueList = fillMissingData(valueList, startTime, endTime);
        //累加
        return valueList.stream().mapToDouble(ApiPointValueDTO::getV).sum()/ 60;
        return valueList.stream().mapToDouble(ApiPointValueDTO::getV).sum() / 60;
    }
}