package com.gyee.runeconomy.service.Comprehensive; import com.gyee.common.contant.ContantXk; import com.gyee.common.model.StringUtils; import com.gyee.common.util.DateUtils; import com.gyee.common.util.SortUtils; import com.gyee.runeconomy.dto.ComprehensiveVo; import com.gyee.runeconomy.init.CacheContext; import com.gyee.runeconomy.model.auto.ProBasicPowerstation; import com.gyee.runeconomy.model.auto.ProBasicPowerstationPoint; import com.gyee.runeconomy.model.auto.ProEconPowerstationInfoDay5; import com.gyee.runeconomy.model.auto.StationInfoDay; import com.gyee.runeconomy.service.auto.IProBasicPowerstationPointService; import com.gyee.runeconomy.service.auto.IProEconPowerstationInfoDay5Service; import com.gyee.runeconomy.service.auto.IStationInfoDayService; import com.gyee.runeconomy.util.realtimesource.IEdosUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class ComprehensiveelectricityService { @Resource private IProEconPowerstationInfoDay5Service proEconPowerstationInfoDay5Service; @Resource private IProBasicPowerstationPointService proBasicPowerstationPointService; @Resource private IEdosUtil edosUtil; @Resource private IStationInfoDayService iStationInfoDayService; public Map Comprehensive2(String wpId, String year) throws Exception { List wpls = CacheContext.wpls.stream().filter(g -> wpId.equals(g.getId())).collect(Collectors.toList()); List vos = new ArrayList(); Map map = new LinkedHashMap<>(); //当前年份 Calendar cal = Calendar.getInstance(); int dqnf = cal.get(Calendar.YEAR);//本年 //参数所传年份 int currentyear = Integer.parseInt(year); // 设置为本年一月一号0点 Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(new Date()); calendar1.set(Calendar.YEAR, currentyear); // 根据当前年份变化 calendar1.set(Calendar.MONTH, Calendar.JANUARY); // 0表示一月 calendar1.set(Calendar.DAY_OF_MONTH, 1); calendar1.set(Calendar.HOUR_OF_DAY, 0); calendar1.set(Calendar.MINUTE, 0); calendar1.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); Date firstDayZeroHour = calendar1.getTime(); // 获取firstDayZeroHour的月份 Calendar calFirstDayZeroHour = Calendar.getInstance(); calFirstDayZeroHour.setTime(firstDayZeroHour); int calFirstMonth = calFirstDayZeroHour.get(Calendar.MONTH) + 1; //当前时间月份 Calendar calendar = Calendar.getInstance(); int currentMonth = calendar.get(Calendar.MONTH); currentMonth = currentMonth + 1; // 设置为年初一月一号0点,同比计算取值时间(减去一年,比今年计算少一年) Calendar calendar3 = Calendar.getInstance(); calendar3.setTime(new Date()); calendar3.set(Calendar.YEAR, currentyear - 1); // 根据当前年份变化 calendar3.set(Calendar.MONTH, Calendar.JANUARY); // 0表示一月 calendar3.set(Calendar.DAY_OF_MONTH, 1); calendar3.set(Calendar.HOUR_OF_DAY, 0); calendar3.set(Calendar.MINUTE, 0); calendar3.set(Calendar.SECOND, 0); calendar3.set(Calendar.MILLISECOND, 0); Date tbjssj = calendar3.getTime(); // 去年十二月一号0点值,环比计算取值时间(初始设置为去年十二月,每循环一次增加一月) Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(new Date()); // 设置年份为传递的currentyear的前一年 calendar2.set(Calendar.YEAR, currentyear - 1); // 设置月份为十二月 calendar2.set(Calendar.MONTH, Calendar.DECEMBER); // 11表示十二月 // 设置日期为每月的第一天 calendar2.set(Calendar.DAY_OF_MONTH, 1); calendar2.set(Calendar.HOUR_OF_DAY, 0); calendar2.set(Calendar.MINUTE, 0); calendar2.set(Calendar.SECOND, 0); calendar2.set(Calendar.MILLISECOND, 0); Date hbjssj = calendar2.getTime(); double zhcydlsum = 0.0; double sjdlsum = 0.0; double swdlsum = 0.0; double gwdlsum = 0.0; double zhcydllsum = 0.0; for (int i = 1; i <= 12; i++) { //综合场用电量 double zhcydl = 0.0; double zhcydltb = 0.0; double zhcydlhb = 0.0; //实际电量 double sjdl = 0.0; double sjdltb = 0.0; double sjdlhb = 0.0; //上网电量 double swdl = 0.0; double swdltb = 0.0; double swdlhb = 0.0; //购网电量 double gwdl = 0.0; double gwdltb = 0.0; double gwdlhb = 0.0; //综合场用电率 double zhcydll = 0.0; double zhcydlltb = 0.0; double zhcydllhb = 0.0; for (ProBasicPowerstation wp : wpls) { //当前场站本年循环所有指标取值集合 double rfdlsj = 0.0; List zbls = proEconPowerstationInfoDay5Service.getmax(wp.getId(), firstDayZeroHour); List tbzbls = proEconPowerstationInfoDay5Service.getmax(wp.getId(), tbjssj); List hbzbls = proEconPowerstationInfoDay5Service.getmax(wp.getId(), hbjssj); ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.RFDL); rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble(); if (!zbls.isEmpty() && zbls != null) { //综合场用电量取值 zhcydl = zbls.get(0).getYzhcydldb().doubleValue() / 10000; zhcydlsum += zhcydl; //发电量取值 if (calFirstMonth == currentMonth && currentyear == dqnf) { // sjdl = (zbls.get(0).getYfdldb().doubleValue() / 10000) + (rfdlsj / 10000); sjdl = (zbls.get(0).getYfdldb().doubleValue() / 10000); } else { sjdl = zbls.get(0).getYfdldb().doubleValue() / 10000; } sjdlsum += sjdl; //上网电量取值 swdl = zbls.get(0).getYswdldb().doubleValue() / 10000; swdlsum += swdl; //购网电量取值 gwdl = zbls.get(0).getYgwgwdldb().doubleValue() / 10000; gwdlsum += gwdl; //综合场用电率计算 —— 综合场用电率=(发电量-上网电量+购网电量)/发电量 if (sjdl != 0) { zhcydll = (sjdl - swdl + gwdl) / sjdl; } else { zhcydll = (sjdl - swdl + gwdl) / 1; } zhcydllsum += zhcydll; } if (!tbzbls.isEmpty() && tbzbls != null) { zhcydltb = tbzbls.get(0).getYzhcydldb().doubleValue() / 10000; sjdltb = tbzbls.get(0).getYfdldb().doubleValue() / 10000; swdltb = tbzbls.get(0).getYswdldb().doubleValue() / 10000; gwdltb = tbzbls.get(0).getYgwgwdldb().doubleValue() / 10000; if (sjdltb != 0) { zhcydlltb = (sjdltb - swdltb + gwdltb) / sjdltb; } else { zhcydlltb = (sjdltb - swdltb + gwdltb) / 1; } } if (!hbzbls.isEmpty() && hbzbls != null) { zhcydlhb = hbzbls.get(0).getYzhcydldb().doubleValue() / 10000; sjdlhb = hbzbls.get(0).getYfdldb().doubleValue() / 10000; swdlhb = hbzbls.get(0).getYswdldb().doubleValue() / 10000; gwdlhb = hbzbls.get(0).getYgwgwdldb().doubleValue() / 10000; if (sjdlhb != 0) { zhcydllhb = (sjdlhb - swdlhb + gwdlhb) / sjdlhb; } else { zhcydllhb = (sjdlhb - swdlhb + gwdlhb) / 1; } } //添加各指标 ComprehensiveVo vo = new ComprehensiveVo(); //添加综合厂用电量数据 vo.setZhcydl(StringUtils.round(zhcydl, 2)); if (zhcydltb != 0) { // vo.setZhcydltb(StringUtils.round((zhcydl - zhcydltb) / zhcydltb * 100, 0)); vo.setZhcydltb(StringUtils.round(zhcydltb, 2)); } else { vo.setZhcydltb(0.0); } if (zhcydlhb != 0) { // vo.setZhcydlhb(StringUtils.round((zhcydl - zhcydlhb) / zhcydlhb * 100, 0)); vo.setZhcydlhb(StringUtils.round(zhcydlhb, 2)); } else { vo.setZhcydlhb(0.0); } //添加时间戳 vo.setHours(i); //添加实际电量数据 vo.setSjdl(StringUtils.round(sjdl, 2)); if (sjdltb != 0) { // vo.setSjdltb(StringUtils.round((sjdl - sjdltb) / sjdltb * 100, 0)); vo.setSjdltb(StringUtils.round(sjdltb, 2)); } else { vo.setSjdltb(0.0); } if (sjdlhb != 0) { // vo.setSjdlhb(StringUtils.round((sjdl - sjdlhb) / sjdlhb * 100, 0)); vo.setSjdlhb(StringUtils.round(sjdlhb, 2)); } else { vo.setSjdlhb(0.0); } //添加上网电量数据 vo.setSwdl(StringUtils.round(swdl, 2)); if (swdltb != 0) { // vo.setSwdltb(StringUtils.round((swdl - swdltb) / swdltb * 100, 0)); vo.setSwdltb(StringUtils.round(swdltb, 2)); } else { vo.setSwdltb(0.0); } if (swdlhb != 0) { // vo.setSwdlhb(StringUtils.round((swdl - swdlhb) / swdlhb * 100, 0)); vo.setSwdlhb(StringUtils.round(swdlhb, 2)); } else { vo.setSwdlhb(0.0); } //添加购网电量数据 vo.setGwdl(StringUtils.round(gwdl, 2)); if (gwdltb != 0) { // vo.setGwdltb(StringUtils.round((gwdl - gwdltb) / gwdltb * 100, 0)); vo.setGwdltb(StringUtils.round(gwdltb, 2)); } else { vo.setGwdltb(0.0); } if (gwdlhb != 0) { // vo.setGwdlhb(StringUtils.round((gwdl - gwdlhb) / gwdlhb * 100, 0)); vo.setGwdlhb(StringUtils.round(gwdlhb, 2)); } else { vo.setGwdlhb(0.0); } //添加综合厂用电率数据 vo.setZhcydll(StringUtils.round(zhcydll * 100, 0)); if (zhcydlltb != 0) { // vo.setZhcydlltb(StringUtils.round((zhcydll - zhcydlltb) / zhcydlltb * 100, 0)); vo.setZhcydlltb(StringUtils.round(zhcydlltb, 2)); } else { vo.setZhcydlltb(0.0); } if (zhcydllhb != 0) { // vo.setZhcydllhb(StringUtils.round((zhcydll - zhcydllhb) / zhcydllhb * 100, 0)); vo.setZhcydllhb(StringUtils.round(zhcydllhb, 2)); } else { vo.setZhcydllhb(0.0); } vos.add(vo); SortUtils.sort(vos, "hours", SortUtils.ASC); map.put("value", vos); } firstDayZeroHour = DateUtils.addMonths(firstDayZeroHour, 1); calFirstDayZeroHour.setTime(firstDayZeroHour); calFirstMonth = calFirstDayZeroHour.get(Calendar.MONTH) + 1; hbjssj = DateUtils.addMonths(hbjssj, 1); tbjssj = DateUtils.addMonths(tbjssj, 1); } map.put("zhcydlsum", StringUtils.round(zhcydlsum, 2)); map.put("sjdlsum", StringUtils.round(sjdlsum, 2)); map.put("swdlsum", StringUtils.round(swdlsum, 2)); map.put("gwdlsum", StringUtils.round(gwdlsum, 2)); map.put("zhcydllsum", StringUtils.round(zhcydllsum * 100, 0)); return map; } public Map Comprehensive(String wpId, String year) throws Exception { List wpls = CacheContext.wpls.stream().filter(g -> wpId.equals(g.getId())).collect(Collectors.toList()); List vos = new ArrayList(); Map map = new LinkedHashMap<>(); //当前年份 Calendar cal = Calendar.getInstance(); int dqnf = cal.get(Calendar.YEAR);//本年 //参数所传年份 int currentyear = Integer.parseInt(year); // 设置为本年一月一号0点 Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(new Date()); calendar1.set(Calendar.YEAR, currentyear); // 根据当前年份变化 calendar1.set(Calendar.MONTH, Calendar.JANUARY); // 0表示一月 calendar1.set(Calendar.DAY_OF_MONTH, 1); calendar1.set(Calendar.HOUR_OF_DAY, 0); calendar1.set(Calendar.MINUTE, 0); calendar1.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); Date firstDayZeroHour = calendar1.getTime(); // 获取firstDayZeroHour的月份 Calendar calFirstDayZeroHour = Calendar.getInstance(); calFirstDayZeroHour.setTime(firstDayZeroHour); int calFirstMonth = calFirstDayZeroHour.get(Calendar.MONTH) + 1; //当前时间月份 Calendar calendar = Calendar.getInstance(); int currentMonth = calendar.get(Calendar.MONTH); currentMonth = currentMonth + 1; // 设置为年初一月一号0点,同比计算取值时间(减去一年,比今年计算少一年) Calendar calendar3 = Calendar.getInstance(); calendar3.setTime(new Date()); calendar3.set(Calendar.YEAR, currentyear - 1); // 根据当前年份变化 calendar3.set(Calendar.MONTH, Calendar.JANUARY); // 0表示一月 calendar3.set(Calendar.DAY_OF_MONTH, 1); calendar3.set(Calendar.HOUR_OF_DAY, 0); calendar3.set(Calendar.MINUTE, 0); calendar3.set(Calendar.SECOND, 0); calendar3.set(Calendar.MILLISECOND, 0); Date tbjssj = calendar3.getTime(); // 去年十二月一号0点值,环比计算取值时间(初始设置为去年十二月,每循环一次增加一月) Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(new Date()); // 设置年份为传递的currentyear的前一年 calendar2.set(Calendar.YEAR, currentyear - 1); // 设置月份为十二月 calendar2.set(Calendar.MONTH, Calendar.DECEMBER); // 11表示十二月 // 设置日期为每月的第一天 calendar2.set(Calendar.DAY_OF_MONTH, 1); calendar2.set(Calendar.HOUR_OF_DAY, 0); calendar2.set(Calendar.MINUTE, 0); calendar2.set(Calendar.SECOND, 0); calendar2.set(Calendar.MILLISECOND, 0); Date hbjssj = calendar2.getTime(); double zhcydlsum = 0.0; double sjdlsum = 0.0; double swdlsum = 0.0; double gwdlsum = 0.0; double zhcydllsum = 0.0; for (int i = 1; i <= 12; i++) { //综合场用电量 double zhcydl = 0.0; double zhcydltb = 0.0; double zhcydlhb = 0.0; //实际电量 double sjdl = 0.0; double sjdltb = 0.0; double sjdlhb = 0.0; //上网电量 double swdl = 0.0; double swdltb = 0.0; double swdlhb = 0.0; //购网电量 double gwdl = 0.0; double gwdltb = 0.0; double gwdlhb = 0.0; //综合场用电率 double zhcydll = 0.0; double zhcydlltb = 0.0; double zhcydllhb = 0.0; for (ProBasicPowerstation wp : wpls) { //当前场站本年循环所有指标取值集合 double rfdlsj = 0.0; List zbls = iStationInfoDayService.getmax(wp.getId(), firstDayZeroHour); List tbzbls = iStationInfoDayService.getmax(wp.getId(), tbjssj); List hbzbls = iStationInfoDayService.getmax(wp.getId(), hbjssj); ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.RFDL); rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble(); if (!zbls.isEmpty() && zbls != null) { //综合场用电量取值 zhcydl = zbls.get(0).getZhcydl().doubleValue(); zhcydlsum += zhcydl; //发电量取值 if (calFirstMonth == currentMonth && currentyear == dqnf) { // sjdl = (zbls.get(0).getYfdldb().doubleValue() / 10000) + (rfdlsj / 10000); sjdl = (zbls.get(0).getRfdlFj().doubleValue() ); } else { sjdl = zbls.get(0).getRfdlFj().doubleValue(); } sjdlsum += sjdl; //上网电量取值 swdl = zbls.get(0).getSwdl().doubleValue(); swdlsum += swdl; //购网电量取值 gwdl = zbls.get(0).getGwdl().doubleValue(); gwdlsum += gwdl; //综合场用电率计算 —— 综合场用电率=(发电量-上网电量+购网电量)/发电量 if (sjdl != 0) { zhcydll = (sjdl - swdl + gwdl) / sjdl; } else { zhcydll = (sjdl - swdl + gwdl) / 1; } zhcydllsum += zhcydll; } if (!tbzbls.isEmpty() && tbzbls != null) { zhcydltb = tbzbls.get(0).getZhcydl().doubleValue(); sjdltb = tbzbls.get(0).getRfdlFj().doubleValue(); swdltb = tbzbls.get(0).getSwdl().doubleValue(); gwdltb = tbzbls.get(0).getGwdl().doubleValue(); if (sjdltb != 0) { zhcydlltb = (sjdltb - swdltb + gwdltb) / sjdltb; } else { zhcydlltb = (sjdltb - swdltb + gwdltb) / 1; } } if (!hbzbls.isEmpty() && hbzbls != null) { zhcydlhb = hbzbls.get(0).getZhcydl().doubleValue(); sjdlhb = hbzbls.get(0).getRfdlFj().doubleValue(); swdlhb = hbzbls.get(0).getSwdl().doubleValue(); gwdlhb = hbzbls.get(0).getGwdl().doubleValue(); if (sjdlhb != 0) { zhcydllhb = (sjdlhb - swdlhb + gwdlhb) / sjdlhb; } else { zhcydllhb = (sjdlhb - swdlhb + gwdlhb) / 1; } } //添加各指标 ComprehensiveVo vo = new ComprehensiveVo(); //添加综合厂用电量数据 vo.setZhcydl(StringUtils.round(zhcydl, 2)); if (zhcydltb != 0) { // vo.setZhcydltb(StringUtils.round((zhcydl - zhcydltb) / zhcydltb * 100, 0)); vo.setZhcydltb(StringUtils.round(zhcydltb, 2)); } else { vo.setZhcydltb(0.0); } if (zhcydlhb != 0) { // vo.setZhcydlhb(StringUtils.round((zhcydl - zhcydlhb) / zhcydlhb * 100, 0)); vo.setZhcydlhb(StringUtils.round(zhcydlhb, 2)); } else { vo.setZhcydlhb(0.0); } //添加时间戳 vo.setHours(i); //添加实际电量数据 vo.setSjdl(StringUtils.round(sjdl, 2)); if (sjdltb != 0) { // vo.setSjdltb(StringUtils.round((sjdl - sjdltb) / sjdltb * 100, 0)); vo.setSjdltb(StringUtils.round(sjdltb, 2)); } else { vo.setSjdltb(0.0); } if (sjdlhb != 0) { // vo.setSjdlhb(StringUtils.round((sjdl - sjdlhb) / sjdlhb * 100, 0)); vo.setSjdlhb(StringUtils.round(sjdlhb, 2)); } else { vo.setSjdlhb(0.0); } //添加上网电量数据 vo.setSwdl(StringUtils.round(swdl, 2)); if (swdltb != 0) { // vo.setSwdltb(StringUtils.round((swdl - swdltb) / swdltb * 100, 0)); vo.setSwdltb(StringUtils.round(swdltb, 2)); } else { vo.setSwdltb(0.0); } if (swdlhb != 0) { // vo.setSwdlhb(StringUtils.round((swdl - swdlhb) / swdlhb * 100, 0)); vo.setSwdlhb(StringUtils.round(swdlhb, 2)); } else { vo.setSwdlhb(0.0); } //添加购网电量数据 vo.setGwdl(StringUtils.round(gwdl, 2)); if (gwdltb != 0) { // vo.setGwdltb(StringUtils.round((gwdl - gwdltb) / gwdltb * 100, 0)); vo.setGwdltb(StringUtils.round(gwdltb, 2)); } else { vo.setGwdltb(0.0); } if (gwdlhb != 0) { // vo.setGwdlhb(StringUtils.round((gwdl - gwdlhb) / gwdlhb * 100, 0)); vo.setGwdlhb(StringUtils.round(gwdlhb, 2)); } else { vo.setGwdlhb(0.0); } //添加综合厂用电率数据 vo.setZhcydll(StringUtils.round(zhcydll * 100, 0)); if (zhcydlltb != 0) { // vo.setZhcydlltb(StringUtils.round((zhcydll - zhcydlltb) / zhcydlltb * 100, 0)); vo.setZhcydlltb(StringUtils.round(zhcydlltb, 2)); } else { vo.setZhcydlltb(0.0); } if (zhcydllhb != 0) { // vo.setZhcydllhb(StringUtils.round((zhcydll - zhcydllhb) / zhcydllhb * 100, 0)); vo.setZhcydllhb(StringUtils.round(zhcydllhb, 2)); } else { vo.setZhcydllhb(0.0); } vos.add(vo); SortUtils.sort(vos, "hours", SortUtils.ASC); map.put("value", vos); } firstDayZeroHour = DateUtils.addMonths(firstDayZeroHour, 1); calFirstDayZeroHour.setTime(firstDayZeroHour); calFirstMonth = calFirstDayZeroHour.get(Calendar.MONTH) + 1; hbjssj = DateUtils.addMonths(hbjssj, 1); tbjssj = DateUtils.addMonths(tbjssj, 1); } map.put("zhcydlsum", StringUtils.round(zhcydlsum, 2)); map.put("sjdlsum", StringUtils.round(sjdlsum, 2)); map.put("swdlsum", StringUtils.round(swdlsum, 2)); map.put("gwdlsum", StringUtils.round(gwdlsum, 2)); map.put("zhcydllsum", StringUtils.round(zhcydllsum * 100, 0)); return map; } }