kangwei:重构电耗分析的,数据展示接口

1 个父辈 9747c812
......@@ -29,7 +29,7 @@ public interface ReportConstant {
//水量字段
public static final String fieldClsl = "CSL,JSL";
public static final String field_CSL= "CSL";
//电字段
public static final String fieldDl = "DLHJ";
......
package com.skua.common.report;
import java.text.DateFormat;
import java.util.List;
import java.util.Map;
import com.skua.common.constant.ReportConstant;
import com.skua.common.report.vo.ReportItemVO;
import com.skua.tool.util.DateUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import com.skua.core.context.SpringContextUtils;
......@@ -300,4 +306,80 @@ public class ReportViewUtil {
return sb.toString();
}
/***
* 某一个字段的同比环比
* @param reportId
* @param fields
* @param departIds
* @param startTime
* @param endTime
* @return
*/
public static ReportItemVO getSumValueByTBHB(String reportId, String fields, String departIds , String startTime , String endTime){
ReportItemVO reportItemVO = null;
String dataViewName3a24_value = ReportViewUtil.buildViewLike(reportId,fields, departIds, startTime,endTime);
String dataViewName3a24_valueHB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getHbDate(startTime),DateUtils.getHbDate(startTime));
String dataViewName3a24_valueTB = ReportViewUtil.buildViewLike(reportId,fields, departIds, DateUtils.getTbDate(startTime),DateUtils.getTbDate(startTime));
String fieldsSql = "";
if(StringUtils.isNotEmpty(fields)) {
String[] fieldArray = fields.split(",");
for (String field : fieldArray) {
if(StringUtils.isNotEmpty(fieldsSql) ) fieldsSql+="+";
fieldsSql += " sum(IFNULL(aaa."+field+",0) ) ";
}
}
String sql = "select ";
sql += "(select ROUND("+fieldsSql+",2) 'value' from " + dataViewName3a24_value+ "aaa) 'value',";
sql += "(select ROUND("+fieldsSql+",2) 'value' from " + dataViewName3a24_valueHB+ "aaa) 'valueHB',";
sql += "(select ROUND("+fieldsSql+",2) 'value' from " + dataViewName3a24_valueTB+ "aaa) 'valueTB' ";
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);
}else{
reportItemVO = new ReportItemVO();
}
return reportItemVO;
}
/***
* 某一个字段的时间+吨水消耗
* @param reportId
* @param fields
* @param departIds
* @param timeType :时间类型 timeType =1 yyyy-MM ,timeType =2 yyyy-MM-dd
* @param isLowFlag isLowFlag = true 只显示最低值
* @return
*/
public static List<ReportItemVO> getDateValueByDS(String reportId, String fields, String departIds , String startTime , String endTime, Integer timeType,boolean isLowFlag){
if(timeType == null) timeType =1;
String dataViewName2119 = ReportViewUtil.buildView(ReportConstant.view2119,ReportConstant.field_CSL, departIds, startTime, endTime);
String dataViewName3a24 = ReportViewUtil.buildView(reportId,fields, departIds, startTime,endTime);
String sql = " select bbb.time,round(IFNULL( bbb."+fields+"/ddd.CLSL,0 ),2) as 'dsValue' ,round(IFNULL( bbb."+fields+",0 ),2) as 'value' from ( ";
if(timeType ==1){
sql += " select DATE_FORMAT(aaa.time,'%Y-%m') 'time' , ROUND(sum(aaa."+fields+"),2) "+fields+" from "+dataViewName3a24 +" aaa group by DATE_FORMAT(aaa.time,'%Y-%m') ";
}else{
sql += " select aaa.time , ROUND(sum(aaa."+fields+"),2) "+fields+" from "+dataViewName3a24 +" aaa group by aaa.time ";
}
sql += " )bbb ";
sql += " left join ( ";
if(timeType ==1){
sql += " select DATE_FORMAT(ccc.time,'%Y-%m') 'time' , ROUND(sum(ccc."+ReportConstant.field_CSL+"),2) CLSL from "+dataViewName2119 +" ccc group by DATE_FORMAT(ccc.time,'%Y-%m') ";
}else{
sql += " select ccc.time , ROUND(sum(ccc."+ReportConstant.field_CSL+"),2) CLSL from "+dataViewName2119 +" ccc ccc.time ";
}
sql += " )ddd on bbb.time = ddd.time ";
if(isLowFlag ){
sql += " order by (bbb."+fields+" - ddd.CLSL) limit 1";
}
JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
List<ReportItemVO> dataList = masterDB.query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
return dataList;
}
}
......
package com.skua.common.report.vo;
import com.skua.core.util.ConvertUtils;
import com.skua.tool.util.JSUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value="指挥中心:ReportItemVO", description="指挥中心:ReportItemVO详情类)")
public class ReportItemVO {
@ApiModelProperty(value = "厂站编号")
private String departId;
@ApiModelProperty(value = "厂站名称")
private String departName;
@ApiModelProperty(value = "时间")
private String time;
@ApiModelProperty(value = "label描述")
private String label;
@ApiModelProperty(value = "code")
private String code;
@ApiModelProperty(value = "结果")
private String value;
@ApiModelProperty(value = "日均数据")
private String avgDayValue;
@ApiModelProperty(value = "同比")
private String valueTb;
@ApiModelProperty(value = "同比比例")
private String valueTbBl;
/* @ApiModelProperty(value = "同比差值")
private String valueTbDifference;*/
@ApiModelProperty(value = "环比")
private String valueHb;
@ApiModelProperty(value = "环比比例")
private String valueHbBl;
@ApiModelProperty(value = "吨水消耗")
private String dsValue;
/* @ApiModelProperty(value = "环比差值")
private String valueHbDifference;
@ApiModelProperty(value = "单位")
private String unit;
*/
public ReportItemVO(){
}
public ReportItemVO(String label, String code, String value, String valueHb, String valueTb) {
this.label = label;
this.code = code;
this.value = value;
this.valueTb = valueTb;
this.valueHb = valueHb;
}
public ReportItemVO(String value, String valueTb, String valueHb) {
this.value = ConvertUtils.getString(value,"0.0");
this.valueTb = ConvertUtils.getString(valueTb,"0.0");
this.valueHb = ConvertUtils.getString(valueHb,"0.0");
}
public String getValueTbBl() {
valueTbBl = JSUtils.executeExpression("("+this.getValue() + " - " + this.getValueTb() + ") / " +this.getValueTb(),"0.0") ;
return valueTbBl;
}
public String getValueHbBl() {
valueHbBl = JSUtils.executeExpression("("+this.getValue() + " - " + this.getValueHb() + ") / " +this.getValueHb(),"0.0") ;
return valueHbBl;
}
}
......@@ -3,6 +3,7 @@ package com.skua.modules.equipment.controller;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.modules.equipment.service.IPowerConsumptionAnalysisService;
import com.skua.modules.equipment.vo.AnysisParamsVO;
import io.swagger.annotations.Api;
......@@ -31,6 +32,7 @@ public class PowerConsumptionAnalysisController {
@RequestMapping(value = "/data/display", method = RequestMethod.GET)
public Result<Map<String, Object>> dataDisplay(AnysisParamsVO anysisParamsVO) {
Result<Map<String, Object>> result = new Result<>();
anysisParamsVO.setFactoryId(BaseContextHandler.getDeparts());
Map<String, Object> data = powerConsumptionAnalysisService.dataDisplay(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
......
package com.skua.modules.equipment.service.impl;
import com.google.common.collect.Maps;
import com.skua.common.constant.ReportConstant;
import com.skua.common.report.ReportViewUtil;
import com.skua.common.report.vo.ReportItemVO;
import com.skua.core.context.SpringContextUtils;
import com.skua.modules.common.mapper.CommonSqlMapper;
import com.skua.modules.equipment.dto.*;
import com.skua.modules.equipment.mapper.ComprehensiveSupervisionMapper;
import com.skua.modules.equipment.service.IPowerConsumptionAnalysisService;
import com.skua.modules.equipment.vo.AnysisParamsVO;
import com.skua.modules.equipment.vo.MetricVo;
import com.skua.modules.system.service.ReportViewService;
import com.skua.tool.util.JSUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,14 +32,17 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
@Resource
private ComprehensiveSupervisionMapper comprehensiveSupervisionMapper;
@Resource
private CommonSqlMapper commonSqlMapper;
@Override
public Map<String, Object> dataDisplay(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
String factoryId = anysisParamsVO.getFactoryId();
String startTime = time+"-01" ;
String endTime = time + "-31";
Map<String, Object> result = Maps.newHashMap();
//目标吨水电耗
result.put("mbdsdh","0.5");
result.put("mbdsdh","0.65");
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
result.put("zhdl","-");
result.put("dsdh","-");
......@@ -56,61 +65,29 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
//总耗电量
List<String> months=new ArrayList<>();
months.add(time);
List<AlarmDto> current=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
if (current.size()>0){
result.put("zhdl",this.getValue(Double.parseDouble(current.get(0).getV())/10000));
}
//String dataViewName3a24_value = ReportViewUtil.buildViewLike(ReportConstant.view2119,fields, departIds, startTime,endTime);
ReportItemVO dlhjReportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view3a24,ReportConstant.fieldDl, factoryId, startTime,endTime);
result.put("zhdl", JSUtils.divide(dlhjReportVO.getValue(),10000));
result.put("tbqnzhdl",JSUtils.divide(dlhjReportVO.getValueTb(),10000));
result.put("hbsyzhdl",JSUtils.divide(dlhjReportVO.getValueHb(),10000));
//吨水电耗
List<Map<String, Object>> monitorList = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
if (monitorList.size()>0){
//吨水电耗 本月累计电耗量[kW·h]/本月累计处理水量[吨]
if (current.size()>0) {
result.put("dsdh", this.getValue(Double.parseDouble(current.get(0).getV()) / Double.parseDouble(monitorList.get(0).get("v").toString())));
}
}
//同比去年总耗电量
String lastYear=this.getMonthBytime(-12,time);
months.clear();
months.add(lastYear);
List<AlarmDto> last=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
if (last.size()>0){
result.put("tbqnzhdl",this.getValue(Double.parseDouble(last.get(0).getV())/10000));
}
//同比去年吨水电耗
List<Map<String, Object>> monitorList2 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
if (monitorList2.size()>0){
//吨水电耗 累计电耗量[kW·h]/本月累计处理水量[吨]
if (last.size()>0) {
result.put("tbqndsdh", this.getValue(Double.parseDouble(last.get(0).getV()) / Double.parseDouble(monitorList2.get(0).get("v").toString())));
}
}
//环比上月总耗电量
String lastMonth=this.getMonthBytime(-1,time);
months.clear();
months.add(lastMonth);
List<AlarmDto> lastMon=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
if (lastMon.size()>0){
result.put("hbsyzhdl",this.getValue(Double.parseDouble(lastMon.get(0).getV())/10000));
}
//环比上月吨水电耗
List<Map<String, Object>> monitorList3 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
if (monitorList3.size()>0){
//吨水电耗 累计电耗量[kW·h]/本月累计处理水量[吨]
if (lastMon.size()>0) {
result.put("hbsydsdh", this.getValue(Double.parseDouble(lastMon.get(0).getV()) / Double.parseDouble(monitorList3.get(0).get("v").toString())));
}
}
ReportItemVO cslReportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, factoryId, startTime,endTime);//出水量
result.put("dsdh", JSUtils.divide(dlhjReportVO.getValue(),cslReportVO.getValue()));
result.put("tbqndsdh", JSUtils.divide(dlhjReportVO.getValue(),cslReportVO.getValueTb()));
result.put("hbsydsdh", JSUtils.divide(dlhjReportVO.getValue(),cslReportVO.getValueHb()));
Map<String,Object> lowerMap=this.getLower(factoryId);
//历史最低吨水电耗
if (lowerMap.get("mindsdh")!=null){
result.put("mindsdh",this.getValue(Double.parseDouble(lowerMap.get("mindsdh")+"")));
result.put("mindsdhyf",lowerMap.get("mintime"));
}else {
result.put("mindsdh","");
result.put("mindsdhyf","");
//4 历史最低吨水电耗
List<ReportItemVO> dsdhList = ReportViewUtil.getDateValueByDS(ReportConstant.view3a24,ReportConstant.fieldDl, factoryId, startTime,endTime,1,true);//吨水电耗集合
if(dsdhList != null && !dsdhList.isEmpty()){
result.put("mindsdh",dsdhList.get(0).getDsValue());
result.put("mindsdhyf",dsdhList.get(0).getTime());
}
if (result.get("zhdl")!=null&&result.get("tbqnzhdl")!=null){
result.put("tbqnzhdlsl", JSUtils.subtract(result.get("zhdl"),result.get("tbqnzhdl")));
result.put("tbqnzhdlbl",JSUtils.divide( result.get("tbqnzhdlsl") , result.get("tbqnzhdl")));
/*if (result.get("zhdl")!=null&&result.get("tbqnzhdl")!=null){
Double dsdh=Double.parseDouble(result.get("zhdl")+"");
Double tbqnzhdl=Double.parseDouble(result.get("tbqnzhdl")+"");
result.put("tbqnzhdlsl",this.getValue(dsdh-tbqnzhdl));
......@@ -119,8 +96,11 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
} else {
result.put("tbqnzhdlbl",this.getValue(((dsdh-tbqnzhdl)/tbqnzhdl)*100));
}
}
if (result.get("zhdl")!=null&&result.get("hbsyzhdl")!=null){
}*/
result.put("hbsyzhdlsl", JSUtils.subtract(result.get("zhdl"),result.get("hbsyzhdl")));
result.put("hbsyzhdlbl",JSUtils.divide( result.get("hbsyzhdlbl") , result.get("hbsyzhdl")));
/*if (result.get("zhdl")!=null&&result.get("hbsyzhdl")!=null){
Double dsdh=Double.parseDouble(result.get("zhdl")+"");
Double hbsyzhdl=Double.parseDouble(result.get("hbsyzhdl")+"");
result.put("hbsyzhdlsl",this.getValue(dsdh-hbsyzhdl));
......@@ -129,8 +109,12 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
} else {
result.put("hbsyzhdlbl",this.getValue(((dsdh-hbsyzhdl)/hbsyzhdl)*100));
}
}
if (result.get("dsdh")!=null&&result.get("tbqndsdh")!=null){
}*/
result.put("tbqndsdhsl", JSUtils.subtract(result.get("dsdh"),result.get("tbqndsdh")));
result.put("tbqndsdhbl",JSUtils.multiply(JSUtils.divide( result.get("tbqndsdhsl") , result.get("tbqndsdh")),100));
/*if (result.get("dsdh")!=null&&result.get("tbqndsdh")!=null){
Double dsdh=Double.parseDouble(result.get("dsdh")+"");
Double tbqndsdh=Double.parseDouble(result.get("tbqndsdh")+"");
result.put("tbqndsdhsl",this.getValue(dsdh-tbqndsdh));
......@@ -139,8 +123,11 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
} else {
result.put("tbqndsdhbl",this.getValue(((dsdh-tbqndsdh)/tbqndsdh)*100));
}
}
if (result.get("dsdh")!=null&&result.get("hbsydsdh")!=null){
}*/
result.put("hbsydsdhsl", JSUtils.subtract(result.get("dsdh"),result.get("hbsydsdh")));
result.put("hbsydsdhbl",JSUtils.multiply(JSUtils.divide( result.get("hbsydsdhsl") , result.get("hbsydsdh")),100));
/*if (result.get("dsdh")!=null&&result.get("hbsydsdh")!=null){
Double dsdh=Double.parseDouble(result.get("dsdh")+"");
Double hbqndsdh=Double.parseDouble(result.get("hbsydsdh")+"");
result.put("hbsydsdhsl",this.getValue(dsdh-hbqndsdh));
......@@ -149,7 +136,7 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
} else {
result.put("hbsydsdhbl",this.getValue(((dsdh-hbqndsdh)/hbqndsdh)*100));
}
}
}*/
return result;
}
......
package com.skua.modules.system.service;
import org.springframework.stereotype.Service;
/**
* @auther kangwei
* @create 2024-12-11-10:04
*/
@Service
public class ReportViewService {
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!