9a72d6f5 康伟

kangwei: 完善能耗分析,添加单位,解决value空值

1 个父辈 de88b37b
1 package com.skua.tool.util; 1 package com.skua.tool.util;
2 2
3 import com.skua.constant.BaseConstant; 3 import com.skua.constant.BaseConstant;
4 import com.skua.modules.common.vo.DateVO;
5
4 import java.math.BigDecimal; 6 import java.math.BigDecimal;
5 import java.text.ParseException; 7 import java.text.ParseException;
6 import java.text.ParsePosition; 8 import java.text.ParsePosition;
...@@ -72,9 +74,25 @@ public class DateUtils { ...@@ -72,9 +74,25 @@ public class DateUtils {
72 }; 74 };
73 75
74 public static void main(String[] args) { 76 public static void main(String[] args) {
75 System.out.println(getHbMonth(formatDate("2024-01-01","yyyy-MM"))); 77 // System.out.println(getHbMonth(formatDate("2024-01-01","yyyy-MM")));
78 // 获取当前日期的Calendar实例
79 Calendar calendar = Calendar.getInstance();
80 // 将当前日期减去一个月
81 calendar.add(Calendar.MONTH, -1);
82 // 创建日期格式化对象
83 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
84 // 格式化上个月的日期
85 String lastMonth = dateFormat.format(calendar.getTime());
86
87 calendar.add(Calendar.MONTH, -1);
88 String lastMonth2 = dateFormat.format(calendar.getTime());
76 89
90 calendar.add(Calendar.MONTH, -11);
91 String lastMonth3 = dateFormat.format(calendar.getTime());
77 92
93 System.out.println("上月"+lastMonth);
94 System.out.println("上上月"+lastMonth2);
95 System.out.println("同比"+lastMonth3);
78 // System.out.println("天数差异: " + daysBetween); 96 // System.out.println("天数差异: " + daysBetween);
79 } 97 }
80 98
......
...@@ -21,10 +21,8 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; ...@@ -21,10 +21,8 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
21 import org.springframework.jdbc.core.JdbcTemplate; 21 import org.springframework.jdbc.core.JdbcTemplate;
22 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
23 23
24 import java.util.ArrayList; 24 import java.text.SimpleDateFormat;
25 import java.util.HashMap; 25 import java.util.*;
26 import java.util.List;
27 import java.util.Map;
28 26
29 27
30 /** 28 /**
...@@ -85,8 +83,8 @@ public class ReportItemvService { ...@@ -85,8 +83,8 @@ public class ReportItemvService {
85 public List<FRportlCommandCenterVO> statisticsByElectricity(String departId, String startTime, String endTime) { 83 public List<FRportlCommandCenterVO> statisticsByElectricity(String departId, String startTime, String endTime) {
86 List<FRportlCommandCenterVO> fRportlCommandCenterVOList = new ArrayList<>(); 84 List<FRportlCommandCenterVO> fRportlCommandCenterVOList = new ArrayList<>();
87 DateVO dateVO = new DateVO(startTime); 85 DateVO dateVO = new DateVO(startTime);
88 // String dataViewName3a24 = ReportViewUtil.buildViewLike(ReportConstant.view3a24,"DLHJ", departId, startTime,endTime); 86 // String dataViewName3a24 = ReportViewUtil.buildViewLike(ReportConstant.view3a24,"DLHJ", departId, startTime,endTime);
89 // String sql = "select ROUND( SUM( IFNULL(aaa.DLHJ,0) ), 2 ) AS DLHJ from " + dataViewName3a24+ "aaa"; 87 // String sql = "select ROUND( SUM( IFNULL(aaa.DLHJ,0) ), 2 ) AS DLHJ from " + dataViewName3a24+ "aaa";
90 88
91 ReportItemVO dlhjData = ReportViewUtil.getSumValueByTBHB(ReportConstant.view3a24, "DLHJ", departId, startTime, endTime); 89 ReportItemVO dlhjData = ReportViewUtil.getSumValueByTBHB(ReportConstant.view3a24, "DLHJ", departId, startTime, endTime);
92 90
...@@ -99,12 +97,12 @@ public class ReportItemvService { ...@@ -99,12 +97,12 @@ public class ReportItemvService {
99 String csl_avg_valueHB = getSumCSL(departId, dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime()); 97 String csl_avg_valueHB = getSumCSL(departId, dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime());
100 String csl_avg_valueTB = getSumCSL(departId, dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime());*/ 98 String csl_avg_valueTB = getSumCSL(departId, dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime());*/
101 99
102 String dsdh_value = ReportViewUtil.getValueByDSDH(departId,startTime, endTime) ; 100 String dsdh_value = ReportViewUtil.getValueByDSDH(departId,startTime, endTime) ;
103 String dsdh_value_Hb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime()) ; 101 String dsdh_value_Hb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime()) ;
104 String dsdh_value_Tb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime()) ; 102 String dsdh_value_Tb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime()) ;
105 // long nowDifferDay = DateUtils.differenceDay(dateVO.getNowMonthStartDate(),dateVO.getNowMonthEndDate()); 103 // long nowDifferDay = DateUtils.differenceDay(dateVO.getNowMonthStartDate(),dateVO.getNowMonthEndDate());
106 // long lastMonthDifferDay = DateUtils.differenceDay(dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime()); 104 // long lastMonthDifferDay = DateUtils.differenceDay(dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime());
107 // long lastYearDifferDay = DateUtils.differenceDay(dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime()); 105 // long lastYearDifferDay = DateUtils.differenceDay(dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime());
108 106
109 //当月数据/环比、同比 107 //当月数据/环比、同比
110 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000)); 108 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000));
...@@ -247,7 +245,7 @@ public class ReportItemvService { ...@@ -247,7 +245,7 @@ public class ReportItemvService {
247 private Map<String,String> commonQueryByField(String departIds ,String startTime ,String endTime,String dataViewName,String field){ 245 private Map<String,String> commonQueryByField(String departIds ,String startTime ,String endTime,String dataViewName,String field){
248 Map<String,String> cslMap = new HashMap<>(); 246 Map<String,String> cslMap = new HashMap<>();
249 String dataViewNameSql = ReportViewUtil.buildViewLike(dataViewName,field, departIds, startTime,endTime); 247 String dataViewNameSql = ReportViewUtil.buildViewLike(dataViewName,field, departIds, startTime,endTime);
250 //System.out.println("dataViewNameSql ="+dataViewNameSql ); 248 //System.out.println("dataViewNameSql ="+dataViewNameSql );
251 List<Map<String, Object>> dataMapList = getJdbcTemplate().queryForList(dataViewNameSql); 249 List<Map<String, Object>> dataMapList = getJdbcTemplate().queryForList(dataViewNameSql);
252 if(dataMapList != null){ 250 if(dataMapList != null){
253 for(Map<String, Object> dataMap : dataMapList){ 251 for(Map<String, Object> dataMap : dataMapList){
...@@ -382,6 +380,9 @@ public class ReportItemvService { ...@@ -382,6 +380,9 @@ public class ReportItemvService {
382 String dsdh_value_Tb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime()) ; 380 String dsdh_value_Tb = ReportViewUtil.getValueByDSDH(departId,dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime()) ;
383 381
384 382
383 startTime = dateVO.getLastMonthStartTime();
384 endTime = dateVO.getLastMonthEndTime();
385
385 String dfValueSql = "select sum(cost) cost from report_electric_cost t where t.month >='"+DateUtils.formatDate(startTime,"yyyy-MM")+"' and t.month<='"+DateUtils.formatDate(endTime,"yyyy-MM")+"' "; 386 String dfValueSql = "select sum(cost) cost from report_electric_cost t where t.month >='"+DateUtils.formatDate(startTime,"yyyy-MM")+"' and t.month<='"+DateUtils.formatDate(endTime,"yyyy-MM")+"' ";
386 dfValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")"; 387 dfValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")";
387 String dfValue = getJdbcTemplate().queryForObject(dfValueSql,String.class); 388 String dfValue = getJdbcTemplate().queryForObject(dfValueSql,String.class);
...@@ -424,13 +425,42 @@ public class ReportItemvService { ...@@ -424,13 +425,42 @@ public class ReportItemvService {
424 ReportItemVO zyhReportVO = ReportViewUtil.getSumValueByTBHB( ReportConstant.view3a24,ReportConstant.fieldYj, departIds, startDate,endDate); 425 ReportItemVO zyhReportVO = ReportViewUtil.getSumValueByTBHB( ReportConstant.view3a24,ReportConstant.fieldYj, departIds, startDate,endDate);
425 //日均 value ,同比,环比 426 //日均 value ,同比,环比
426 //ReportItemVO zyhReportAVG = ReportViewUtil.getSumValueByTBHB( ReportConstant.view3a24,ReportConstant.fieldYj, departIds, startDate,endDate,"avg"); 427 //ReportItemVO zyhReportAVG = ReportViewUtil.getSumValueByTBHB( ReportConstant.view3a24,ReportConstant.fieldYj, departIds, startDate,endDate,"avg");
427 //月吨水药费 428 // 获取当前日期的Calendar实例
428 ReportItemVO dsyfReportVO = ReportViewUtil.getSumValueByTBHB( ReportConstant.view4411,"yyh", departIds, startDate,endDate); 429 Calendar calendar = Calendar.getInstance();
430 // 将当前日期减去一个月
431 calendar.add(Calendar.MONTH, -1);
432 // 创建日期格式化对象
433 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
434 // 格式化上个月的日期
435 String month = dateFormat.format(calendar.getTime());
436 calendar.add(Calendar.MONTH, -1);
437 String monthHB = dateFormat.format(calendar.getTime());
438 calendar.add(Calendar.MONTH, -11);
439 String monthTB = dateFormat.format(calendar.getTime());
440
441 String dataViewName3a24_value = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, month,month);
442 String dataViewName3a24_valueHB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthHB,monthHB);
443 String dataViewName3a24_valueTB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthTB,monthTB);
444 String sql = "select ";
445 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_value+ "aaa) 'value',";
446 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueHB+ "aaa) 'valueHb',";
447 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueTB+ "aaa) 'valueTb' ";
448 sql += " from dual";
449 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
450 ReportItemVO dsyfReportVO = null;
451 List<ReportItemVO> dsyfReportList = masterDB.query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
452 if( dsyfReportList!= null && !dsyfReportList.isEmpty()){
453 dsyfReportVO = dsyfReportList.get(0);
454 }else{
455 dsyfReportVO = new ReportItemVO();
456 }
429 457
458 //出水量:+同比+环比
459 // ReportItemVO csl_reportVO2 = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, departIds, dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime());
430 460
431 List<FRportlCommandCenterVO> dataList = new ArrayList<>(); 461 List<FRportlCommandCenterVO> dataList = new ArrayList<>();
432 dataList.add( new FRportlCommandCenterVO("月总药耗" ,"monthValue","万吨",JSUtils.divide(zyhReportVO.getValue(),"10000"),JSUtils.divide(zyhReportVO.getValueTb(),"10000"),JSUtils.divide(zyhReportVO.getValueHb(),"10000")) ); 462 dataList.add( new FRportlCommandCenterVO("月总药耗" ,"monthValue","万吨",JSUtils.divide(zyhReportVO.getValue(),"10000"),JSUtils.divide(zyhReportVO.getValueTb(),"10000"),JSUtils.divide(zyhReportVO.getValueHb(),"10000")) );
433 dataList.add( new FRportlCommandCenterVO("吨水药费" ,"dsyfValue","元/吨",dsyfReportVO.getValue(),dsyfReportVO.getValueTb(),dsyfReportVO.getValueHb()) ); 463 dataList.add( new FRportlCommandCenterVO("吨水药费" ,"dsyfValue","元/吨",dsyfReportVO.getValue(),dsyfReportVO.getValueTb(),dsyfReportVO.getValueHb()) );
434 dataList.add( new FRportlCommandCenterVO("吨水药耗" ,"dsyhValue","kg/吨",JSUtils.divide(zyhReportVO.getValue(), csl_reportVO.getValue()),JSUtils.divide(zyhReportVO.getValueTb(), csl_reportVO.getValueTb()),JSUtils.divide(zyhReportVO.getValueHb(), csl_reportVO.getValueHb())) ); 464 dataList.add( new FRportlCommandCenterVO("吨水药耗" ,"dsyhValue","kg/吨",JSUtils.divide(zyhReportVO.getValue(), csl_reportVO.getValue()),JSUtils.divide(zyhReportVO.getValueTb(), csl_reportVO.getValueTb()),JSUtils.divide(zyhReportVO.getValueHb(), csl_reportVO.getValueHb())) );
435 return dataList; 465 return dataList;
436 } 466 }
......
...@@ -147,7 +147,7 @@ public class CommandCentreServiceImpl implements ICommandCentreService { ...@@ -147,7 +147,7 @@ public class CommandCentreServiceImpl implements ICommandCentreService {
147 sql += " where aaa.equipment_level = '6bf727eb7e7cca6a95c694dab0036b2c'";//A类设备 147 sql += " where aaa.equipment_level = '6bf727eb7e7cca6a95c694dab0036b2c'";//A类设备
148 List<EquipmentRepairAnalysisVO> dataList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<EquipmentRepairAnalysisVO>(EquipmentRepairAnalysisVO.class));; 148 List<EquipmentRepairAnalysisVO> dataList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<EquipmentRepairAnalysisVO>(EquipmentRepairAnalysisVO.class));;
149 149
150 dataMap.put("totalCost",JSUtils.multiply(repairCost,maintainCost)); 150 dataMap.put("totalCost",JSUtils.subtract(repairCost,maintainCost));
151 dataMap.put("dataList",dataList); 151 dataMap.put("dataList",dataList);
152 return dataMap; 152 return dataMap;
153 } 153 }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!