a552dad8 康伟

kangwei: 完善能耗分析,添加单位,解决value空值,解决环比、同比数据数据错误问题

1 个父辈 0a31951e
...@@ -325,8 +325,8 @@ public class ReportViewUtil { ...@@ -325,8 +325,8 @@ public class ReportViewUtil {
325 public static ReportItemVO getSumValueByTBHB(String reportId, String fields, String departIds , String startTime , String endTime,String operatorSign){ 325 public static ReportItemVO getSumValueByTBHB(String reportId, String fields, String departIds , String startTime , String endTime,String operatorSign){
326 ReportItemVO reportItemVO = null; 326 ReportItemVO reportItemVO = null;
327 String dataViewName3a24_value = ReportViewUtil.buildViewLike(reportId,fields, departIds, startTime,endTime,operatorSign); 327 String dataViewName3a24_value = ReportViewUtil.buildViewLike(reportId,fields, departIds, startTime,endTime,operatorSign);
328 String dataViewName3a24_valueHB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getHbDate(startTime),DateUtils.getHbDate(endTime),operatorSign); 328 String dataViewName3a24_valueHB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getHbDate(startTime),DateUtils.getHbMonthDate(endTime)+"-31",operatorSign);
329 String dataViewName3a24_valueTB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getTbDate(startTime),DateUtils.getTbDate(endTime),operatorSign); 329 String dataViewName3a24_valueTB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getTbDate(startTime),DateUtils.getHbMonthDate(endTime)+"-31",operatorSign);
330 330
331 String fieldsSql = ""; 331 String fieldsSql = "";
332 if(StringUtils.isNotEmpty(fields)) { 332 if(StringUtils.isNotEmpty(fields)) {
...@@ -343,6 +343,7 @@ public class ReportViewUtil { ...@@ -343,6 +343,7 @@ public class ReportViewUtil {
343 343
344 sql += " from dual"; 344 sql += " from dual";
345 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); 345 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
346
346 List<ReportItemVO> dataList = masterDB.query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class)); 347 List<ReportItemVO> dataList = masterDB.query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
347 if(dataList != null && !dataList.isEmpty()){ 348 if(dataList != null && !dataList.isEmpty()){
348 reportItemVO = dataList.get(0); 349 reportItemVO = dataList.get(0);
......
...@@ -10,6 +10,7 @@ import java.time.LocalDate; ...@@ -10,6 +10,7 @@ import java.time.LocalDate;
10 import java.time.LocalDateTime; 10 import java.time.LocalDateTime;
11 import java.time.YearMonth; 11 import java.time.YearMonth;
12 import java.time.format.DateTimeFormatter; 12 import java.time.format.DateTimeFormatter;
13 import java.time.temporal.ChronoUnit;
13 import java.util.*; 14 import java.util.*;
14 15
15 /** 16 /**
...@@ -71,9 +72,34 @@ public class DateUtils { ...@@ -71,9 +72,34 @@ public class DateUtils {
71 }; 72 };
72 73
73 public static void main(String[] args) { 74 public static void main(String[] args) {
74 System.out.println( );
75
76 System.out.println(getHbMonth(formatDate("2024-01-01","yyyy-MM"))); 75 System.out.println(getHbMonth(formatDate("2024-01-01","yyyy-MM")));
76
77
78 // System.out.println("天数差异: " + daysBetween);
79 }
80
81 /***
82 * 判断一个时间字符串是否表示当前月,并且如果它是当前月的话,再与当前时间进行比较
83 * @param endTime
84 * @return
85 */
86 public static String checkDateByCurrentDate(String endTime){
87 LocalDate currentDate = LocalDate.now();
88 // 定义日期格式
89 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
90 // 将字符串转换为LocalDate对象
91 LocalDate endDate = LocalDate.parse(endTime, formatter);
92 System.out.println(endDate.getYear());
93 // 比较年份和月份
94 if (endDate.getYear() == currentDate.getYear() && endDate.getMonth() == currentDate.getMonth()) {
95 // 如果是当前月,比较时间
96 if (currentDate.isBefore(endDate)) {
97 // 当前时间小于给定时间,返回当前时间
98 // System.out.println("当前时间小于给定时间,当前时间: " + currentDate);
99 return currentDate.toString();
100 }
101 }
102 return endTime;
77 } 103 }
78 /*** 104 /***
79 * 字符串日期格式化 105 * 字符串日期格式化
...@@ -593,6 +619,30 @@ public class DateUtils { ...@@ -593,6 +619,30 @@ public class DateUtils {
593 return previousMonth.format(formatter); // 环比 619 return previousMonth.format(formatter); // 环比
594 } 620 }
595 621
622 /***
623 * 环比年月
624 * @param dateStr yyyy-MM-dd
625 * @return
626 */
627 public static String getHbMonthDate(String dateStr) {
628 // 定义日期格式
629 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
630 try {
631 // 将日期字符串转换为LocalDate对象
632 LocalDate date = LocalDate.parse(dateStr, formatter);
633 // 获取上个月的日期
634 LocalDate lastMonth = date.minusMonths(1);
635 // 格式化上个月的日期为字符串
636 String lastMonthStr = lastMonth.format(formatter);
637 // 打印结果
638 // System.out.println("原始日期: " + dateStr);
639 // System.out.println("上个月的日期字符串: " + lastMonthStr);
640 return lastMonthStr;
641 } catch (Exception e) {
642 System.out.println("日期字符串格式错误或解析失败: " + e.getMessage());
643 }
644 return null;
645 }
596 646
597 647
598 /** 648 /**
......
...@@ -397,11 +397,11 @@ public class ReportItemvService { ...@@ -397,11 +397,11 @@ public class ReportItemvService {
397 ReportItemVO csl_reportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, departId, startTime, endTime); 397 ReportItemVO csl_reportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, departId, startTime, endTime);
398 398
399 //当月数据/环比、同比 399 //当月数据/环比、同比
400 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000)); 400 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗(万kwh)", "万kwh",JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000));
401 //日均数据:/环比/同比 401 //日均数据:/环比/同比
402 FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费",JSUtils.divide(dfValueSql,csl_reportVO.getValue()) ,JSUtils.divide(dfTBValue,csl_reportVO.getValueTb()) ,JSUtils.divide(dfHBValue,csl_reportVO.getValueHb())); 402 FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费(元/t)","元/t",JSUtils.divide(dfValue,csl_reportVO.getValue()) ,JSUtils.divide(dfTBValue,csl_reportVO.getValueTb()) ,JSUtils.divide(dfHBValue,csl_reportVO.getValueHb()));
403 //吨水消耗 403 //吨水消耗
404 FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb ); 404 FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗(kwh/t)","kwh/t",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb );
405 fRportlCommandCenterVOList.add( nowMonthVO) ; 405 fRportlCommandCenterVOList.add( nowMonthVO) ;
406 fRportlCommandCenterVOList.add( lastMonthVO) ; 406 fRportlCommandCenterVOList.add( lastMonthVO) ;
407 fRportlCommandCenterVOList.add( lastYearVo) ; 407 fRportlCommandCenterVOList.add( lastYearVo) ;
......
...@@ -70,7 +70,7 @@ public class SysCommandCentreController { ...@@ -70,7 +70,7 @@ public class SysCommandCentreController {
70 List<FRportlCommandCenterVO> fReportItemvList = new ArrayList<>();//返回集合对象 70 List<FRportlCommandCenterVO> fReportItemvList = new ArrayList<>();//返回集合对象
71 DateVO dateVO = new DateVO(reportItemvParam.getStartDate()); 71 DateVO dateVO = new DateVO(reportItemvParam.getStartDate());
72 String departIds = BaseContextHandler.getDeparts(); 72 String departIds = BaseContextHandler.getDeparts();
73 if(reportItemvParam.getDepartIds()!=null){ 73 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
74 departIds = reportItemvParam.getDepartIds(); 74 departIds = reportItemvParam.getDepartIds();
75 } 75 }
76 //本月数据 76 //本月数据
...@@ -108,7 +108,7 @@ public class SysCommandCentreController { ...@@ -108,7 +108,7 @@ public class SysCommandCentreController {
108 public Result<DepartLoadRateResultVO > statisticsByLoadRate(ReportItemvParam reportItemvParam) { 108 public Result<DepartLoadRateResultVO > statisticsByLoadRate(ReportItemvParam reportItemvParam) {
109 Result<DepartLoadRateResultVO > result = new Result<>(); 109 Result<DepartLoadRateResultVO > result = new Result<>();
110 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674 110 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
111 if(reportItemvParam.getDepartIds()!=null){ 111 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
112 departIds = reportItemvParam.getDepartIds(); 112 departIds = reportItemvParam.getDepartIds();
113 } 113 }
114 Integer loadRateType = reportItemvParam.getLoadRateType(); 114 Integer loadRateType = reportItemvParam.getLoadRateType();
...@@ -126,7 +126,7 @@ public class SysCommandCentreController { ...@@ -126,7 +126,7 @@ public class SysCommandCentreController {
126 public Result<List<WaterTreatmentVO>> getCLSLXQ(ReportItemvParam reportItemvParam){ 126 public Result<List<WaterTreatmentVO>> getCLSLXQ(ReportItemvParam reportItemvParam){
127 Result<List<WaterTreatmentVO>> result = new Result<>(); 127 Result<List<WaterTreatmentVO>> result = new Result<>();
128 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674 128 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
129 if(reportItemvParam.getDepartIds()!=null){ 129 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
130 departIds = reportItemvParam.getDepartIds(); 130 departIds = reportItemvParam.getDepartIds();
131 } 131 }
132 List<WaterTreatmentVO> waterTrendVOList = commandCentreService.statisticsCLSLXQ(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(), departIds); 132 List<WaterTreatmentVO> waterTrendVOList = commandCentreService.statisticsCLSLXQ(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(), departIds);
...@@ -141,7 +141,7 @@ public class SysCommandCentreController { ...@@ -141,7 +141,7 @@ public class SysCommandCentreController {
141 public Result<List<FRportlCommandCenterVO>> statisticsByCement(ReportItemvParam reportItemvParam) { 141 public Result<List<FRportlCommandCenterVO>> statisticsByCement(ReportItemvParam reportItemvParam) {
142 Result<List<FRportlCommandCenterVO>> result = new Result(); 142 Result<List<FRportlCommandCenterVO>> result = new Result();
143 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674 143 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
144 if(reportItemvParam.getDepartIds()!=null){ 144 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
145 departIds = reportItemvParam.getDepartIds(); 145 departIds = reportItemvParam.getDepartIds();
146 } 146 }
147 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByCement(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 147 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByCement(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -155,7 +155,7 @@ public class SysCommandCentreController { ...@@ -155,7 +155,7 @@ public class SysCommandCentreController {
155 public Result<List<ReportItemVO>> statisticsByCementList(ReportItemvParam reportItemvParam) { 155 public Result<List<ReportItemVO>> statisticsByCementList(ReportItemvParam reportItemvParam) {
156 Result<List<ReportItemVO>> result = new Result(); 156 Result<List<ReportItemVO>> result = new Result();
157 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674 157 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
158 if(reportItemvParam.getDepartIds()!=null){ 158 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
159 departIds = reportItemvParam.getDepartIds(); 159 departIds = reportItemvParam.getDepartIds();
160 } 160 }
161 List<ReportItemVO> dataList = reportItemvService.statisticsByCementList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 161 List<ReportItemVO> dataList = reportItemvService.statisticsByCementList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -182,7 +182,7 @@ public class SysCommandCentreController { ...@@ -182,7 +182,7 @@ public class SysCommandCentreController {
182 public Result<List<FRportlCommandCenterVO>> statisticsByYh(ReportItemvParam reportItemvParam) { 182 public Result<List<FRportlCommandCenterVO>> statisticsByYh(ReportItemvParam reportItemvParam) {
183 Result<List<FRportlCommandCenterVO>> result = new Result(); 183 Result<List<FRportlCommandCenterVO>> result = new Result();
184 String departId = BaseContextHandler.getDeparts(); 184 String departId = BaseContextHandler.getDeparts();
185 if(reportItemvParam.getDepartIds()!=null){ 185 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
186 departId = reportItemvParam.getDepartIds(); 186 departId = reportItemvParam.getDepartIds();
187 } 187 }
188 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByYh(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 188 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByYh(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -197,7 +197,7 @@ public class SysCommandCentreController { ...@@ -197,7 +197,7 @@ public class SysCommandCentreController {
197 public Result<List<FRportlCommandCenterVO>> statisticsByElectricity(ReportItemvParam reportItemvParam) { 197 public Result<List<FRportlCommandCenterVO>> statisticsByElectricity(ReportItemvParam reportItemvParam) {
198 Result<List<FRportlCommandCenterVO>> result = new Result(); 198 Result<List<FRportlCommandCenterVO>> result = new Result();
199 String departId = BaseContextHandler.getDeparts(); 199 String departId = BaseContextHandler.getDeparts();
200 if(reportItemvParam.getDepartIds()!=null){ 200 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
201 departId = reportItemvParam.getDepartIds(); 201 departId = reportItemvParam.getDepartIds();
202 } 202 }
203 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricity(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 203 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricity(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -210,7 +210,7 @@ public class SysCommandCentreController { ...@@ -210,7 +210,7 @@ public class SysCommandCentreController {
210 public Result<List<FRportlCommandCenterVO>> statisticsByElectricityNew(ReportItemvParam reportItemvParam) { 210 public Result<List<FRportlCommandCenterVO>> statisticsByElectricityNew(ReportItemvParam reportItemvParam) {
211 Result<List<FRportlCommandCenterVO>> result = new Result(); 211 Result<List<FRportlCommandCenterVO>> result = new Result();
212 String departId = BaseContextHandler.getDeparts(); 212 String departId = BaseContextHandler.getDeparts();
213 if(reportItemvParam.getDepartIds()!=null){ 213 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
214 departId = reportItemvParam.getDepartIds(); 214 departId = reportItemvParam.getDepartIds();
215 } 215 }
216 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricityNew(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 216 List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricityNew(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -225,7 +225,7 @@ public class SysCommandCentreController { ...@@ -225,7 +225,7 @@ public class SysCommandCentreController {
225 public Result<List<ReportItemVO>> statisticsByElectricityList(ReportItemvParam reportItemvParam) { 225 public Result<List<ReportItemVO>> statisticsByElectricityList(ReportItemvParam reportItemvParam) {
226 Result<List<ReportItemVO>> result = new Result(); 226 Result<List<ReportItemVO>> result = new Result();
227 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674 227 String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
228 if(reportItemvParam.getDepartIds()!=null){ 228 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
229 departIds = reportItemvParam.getDepartIds(); 229 departIds = reportItemvParam.getDepartIds();
230 } 230 }
231 List<ReportItemVO> dataList = reportItemvService.statisticsByElectricityList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate()); 231 List<ReportItemVO> dataList = reportItemvService.statisticsByElectricityList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
...@@ -242,7 +242,7 @@ public class SysCommandCentreController { ...@@ -242,7 +242,7 @@ public class SysCommandCentreController {
242 List<String> waterList = new ArrayList<>();// 水集合 242 List<String> waterList = new ArrayList<>();// 水集合
243 List<String> consumeList = new ArrayList<>();//电耗集合 243 List<String> consumeList = new ArrayList<>();//电耗集合
244 String departIds = BaseContextHandler.getDeparts(); 244 String departIds = BaseContextHandler.getDeparts();
245 if(reportItemvParam.getDepartIds()!=null){ 245 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
246 departIds = reportItemvParam.getDepartIds(); 246 departIds = reportItemvParam.getDepartIds();
247 } 247 }
248 List<ReportDateTrendVO> dlhjDateList = reportItemvService.getDayDateFieldList(ReportConstant.view3a24, "DLHJ", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate()); 248 List<ReportDateTrendVO> dlhjDateList = reportItemvService.getDayDateFieldList(ReportConstant.view3a24, "DLHJ", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());
...@@ -311,7 +311,7 @@ public class SysCommandCentreController { ...@@ -311,7 +311,7 @@ public class SysCommandCentreController {
311 reportItemvParam.setStartDate( DateUtils.formatDate(startDate ,"YYYY-MM")); 311 reportItemvParam.setStartDate( DateUtils.formatDate(startDate ,"YYYY-MM"));
312 reportItemvParam.setEndDate( DateUtils.formatDate(endDate ,"YYYY-MM")); 312 reportItemvParam.setEndDate( DateUtils.formatDate(endDate ,"YYYY-MM"));
313 String departIds = BaseContextHandler.getDeparts(); 313 String departIds = BaseContextHandler.getDeparts();
314 if(reportItemvParam.getDepartIds()!=null){ 314 if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
315 departIds = reportItemvParam.getDepartIds(); 315 departIds = reportItemvParam.getDepartIds();
316 } 316 }
317 reportItemvParam.setDepartIds( JSUtils.quoteEach(departIds,",")); 317 reportItemvParam.setDepartIds( JSUtils.quoteEach(departIds,","));
......
...@@ -47,7 +47,13 @@ public class FRportlCommandCenterVO implements Serializable { ...@@ -47,7 +47,13 @@ public class FRportlCommandCenterVO implements Serializable {
47 this.valueTb = valueTb; 47 this.valueTb = valueTb;
48 this.valueHb = valueHb; 48 this.valueHb = valueHb;
49 } 49 }
50 50 public FRportlCommandCenterVO(String label ,String unit,String value, String valueTb, String valueHb) {
51 this.label = label;
52 this.unit = unit;
53 this.value = value;
54 this.valueTb = valueTb;
55 this.valueHb = valueHb;
56 }
51 public FRportlCommandCenterVO(String label, String code, String unit, String value, String valueTb, String valueHb) { 57 public FRportlCommandCenterVO(String label, String code, String unit, String value, String valueTb, String valueHb) {
52 this.label = label; 58 this.label = label;
53 this.code = code; 59 this.code = code;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!