a552dad8 康伟

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

1 个父辈 0a31951e
......@@ -325,8 +325,8 @@ public class ReportViewUtil {
public static ReportItemVO getSumValueByTBHB(String reportId, String fields, String departIds , String startTime , String endTime,String operatorSign){
ReportItemVO reportItemVO = null;
String dataViewName3a24_value = ReportViewUtil.buildViewLike(reportId,fields, departIds, startTime,endTime,operatorSign);
String dataViewName3a24_valueHB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getHbDate(startTime),DateUtils.getHbDate(endTime),operatorSign);
String dataViewName3a24_valueTB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getTbDate(startTime),DateUtils.getTbDate(endTime),operatorSign);
String dataViewName3a24_valueHB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getHbDate(startTime),DateUtils.getHbMonthDate(endTime)+"-31",operatorSign);
String dataViewName3a24_valueTB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getTbDate(startTime),DateUtils.getHbMonthDate(endTime)+"-31",operatorSign);
String fieldsSql = "";
if(StringUtils.isNotEmpty(fields)) {
......@@ -343,6 +343,7 @@ public class ReportViewUtil {
sql += " from dual";
JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
List<ReportItemVO> dataList = masterDB.query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
if(dataList != null && !dataList.isEmpty()){
reportItemVO = dataList.get(0);
......
......@@ -10,6 +10,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
/**
......@@ -71,9 +72,34 @@ public class DateUtils {
};
public static void main(String[] args) {
System.out.println( );
System.out.println(getHbMonth(formatDate("2024-01-01","yyyy-MM")));
// System.out.println("天数差异: " + daysBetween);
}
/***
* 判断一个时间字符串是否表示当前月,并且如果它是当前月的话,再与当前时间进行比较
* @param endTime
* @return
*/
public static String checkDateByCurrentDate(String endTime){
LocalDate currentDate = LocalDate.now();
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 将字符串转换为LocalDate对象
LocalDate endDate = LocalDate.parse(endTime, formatter);
System.out.println(endDate.getYear());
// 比较年份和月份
if (endDate.getYear() == currentDate.getYear() && endDate.getMonth() == currentDate.getMonth()) {
// 如果是当前月,比较时间
if (currentDate.isBefore(endDate)) {
// 当前时间小于给定时间,返回当前时间
// System.out.println("当前时间小于给定时间,当前时间: " + currentDate);
return currentDate.toString();
}
}
return endTime;
}
/***
* 字符串日期格式化
......@@ -593,6 +619,30 @@ public class DateUtils {
return previousMonth.format(formatter); // 环比
}
/***
* 环比年月
* @param dateStr yyyy-MM-dd
* @return
*/
public static String getHbMonthDate(String dateStr) {
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
try {
// 将日期字符串转换为LocalDate对象
LocalDate date = LocalDate.parse(dateStr, formatter);
// 获取上个月的日期
LocalDate lastMonth = date.minusMonths(1);
// 格式化上个月的日期为字符串
String lastMonthStr = lastMonth.format(formatter);
// 打印结果
// System.out.println("原始日期: " + dateStr);
// System.out.println("上个月的日期字符串: " + lastMonthStr);
return lastMonthStr;
} catch (Exception e) {
System.out.println("日期字符串格式错误或解析失败: " + e.getMessage());
}
return null;
}
/**
......
......@@ -397,11 +397,11 @@ public class ReportItemvService {
ReportItemVO csl_reportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, departId, startTime, endTime);
//当月数据/环比、同比
FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000));
FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗(万kwh)", "万kwh",JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000));
//日均数据:/环比/同比
FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费",JSUtils.divide(dfValueSql,csl_reportVO.getValue()) ,JSUtils.divide(dfTBValue,csl_reportVO.getValueTb()) ,JSUtils.divide(dfHBValue,csl_reportVO.getValueHb()));
FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费(元/t)","元/t",JSUtils.divide(dfValue,csl_reportVO.getValue()) ,JSUtils.divide(dfTBValue,csl_reportVO.getValueTb()) ,JSUtils.divide(dfHBValue,csl_reportVO.getValueHb()));
//吨水消耗
FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb );
FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗(kwh/t)","kwh/t",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb );
fRportlCommandCenterVOList.add( nowMonthVO) ;
fRportlCommandCenterVOList.add( lastMonthVO) ;
fRportlCommandCenterVOList.add( lastYearVo) ;
......
......@@ -70,7 +70,7 @@ public class SysCommandCentreController {
List<FRportlCommandCenterVO> fReportItemvList = new ArrayList<>();//返回集合对象
DateVO dateVO = new DateVO(reportItemvParam.getStartDate());
String departIds = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
//本月数据
......@@ -108,7 +108,7 @@ public class SysCommandCentreController {
public Result<DepartLoadRateResultVO > statisticsByLoadRate(ReportItemvParam reportItemvParam) {
Result<DepartLoadRateResultVO > result = new Result<>();
String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
Integer loadRateType = reportItemvParam.getLoadRateType();
......@@ -126,7 +126,7 @@ public class SysCommandCentreController {
public Result<List<WaterTreatmentVO>> getCLSLXQ(ReportItemvParam reportItemvParam){
Result<List<WaterTreatmentVO>> result = new Result<>();
String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
List<WaterTreatmentVO> waterTrendVOList = commandCentreService.statisticsCLSLXQ(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(), departIds);
......@@ -141,7 +141,7 @@ public class SysCommandCentreController {
public Result<List<FRportlCommandCenterVO>> statisticsByCement(ReportItemvParam reportItemvParam) {
Result<List<FRportlCommandCenterVO>> result = new Result();
String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByCement(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -155,7 +155,7 @@ public class SysCommandCentreController {
public Result<List<ReportItemVO>> statisticsByCementList(ReportItemvParam reportItemvParam) {
Result<List<ReportItemVO>> result = new Result();
String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
List<ReportItemVO> dataList = reportItemvService.statisticsByCementList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -182,7 +182,7 @@ public class SysCommandCentreController {
public Result<List<FRportlCommandCenterVO>> statisticsByYh(ReportItemvParam reportItemvParam) {
Result<List<FRportlCommandCenterVO>> result = new Result();
String departId = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departId = reportItemvParam.getDepartIds();
}
List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByYh(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -197,7 +197,7 @@ public class SysCommandCentreController {
public Result<List<FRportlCommandCenterVO>> statisticsByElectricity(ReportItemvParam reportItemvParam) {
Result<List<FRportlCommandCenterVO>> result = new Result();
String departId = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departId = reportItemvParam.getDepartIds();
}
List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricity(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -210,7 +210,7 @@ public class SysCommandCentreController {
public Result<List<FRportlCommandCenterVO>> statisticsByElectricityNew(ReportItemvParam reportItemvParam) {
Result<List<FRportlCommandCenterVO>> result = new Result();
String departId = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departId = reportItemvParam.getDepartIds();
}
List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByElectricityNew(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -225,7 +225,7 @@ public class SysCommandCentreController {
public Result<List<ReportItemVO>> statisticsByElectricityList(ReportItemvParam reportItemvParam) {
Result<List<ReportItemVO>> result = new Result();
String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
List<ReportItemVO> dataList = reportItemvService.statisticsByElectricityList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
......@@ -242,7 +242,7 @@ public class SysCommandCentreController {
List<String> waterList = new ArrayList<>();// 水集合
List<String> consumeList = new ArrayList<>();//电耗集合
String departIds = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
List<ReportDateTrendVO> dlhjDateList = reportItemvService.getDayDateFieldList(ReportConstant.view3a24, "DLHJ", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());
......@@ -311,7 +311,7 @@ public class SysCommandCentreController {
reportItemvParam.setStartDate( DateUtils.formatDate(startDate ,"YYYY-MM"));
reportItemvParam.setEndDate( DateUtils.formatDate(endDate ,"YYYY-MM"));
String departIds = BaseContextHandler.getDeparts();
if(reportItemvParam.getDepartIds()!=null){
if(StringUtils.isNotEmpty(reportItemvParam.getDepartIds()) ){
departIds = reportItemvParam.getDepartIds();
}
reportItemvParam.setDepartIds( JSUtils.quoteEach(departIds,","));
......
......@@ -47,7 +47,13 @@ public class FRportlCommandCenterVO implements Serializable {
this.valueTb = valueTb;
this.valueHb = valueHb;
}
public FRportlCommandCenterVO(String label ,String unit,String value, String valueTb, String valueHb) {
this.label = label;
this.unit = unit;
this.value = value;
this.valueTb = valueTb;
this.valueHb = valueHb;
}
public FRportlCommandCenterVO(String label, String code, String unit, String value, String valueTb, String valueHb) {
this.label = label;
this.code = code;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!