061214b5 康伟

kangwei:指挥中心,电耗改为万吨水电耗,CSL改为万吨水

1 个父辈 12d66bdb
......@@ -79,9 +79,13 @@ public class ReportViewUtil {
if(StringUtils.isNotEmpty(departIds)){
sb.append(" and depart_id in ("+inSqlPart+") ");
}
if(!StringUtils.isEmpty(startTime)) {
sb.append(" and data_time>='"+startTime+"' and data_time<='"+endTime+"' ");
if(StringUtils.isNotEmpty(startTime)) {
sb.append(" and data_time>='"+startTime+"' ");
}
if(StringUtils.isNotEmpty(endTime)) {
sb.append(" and data_time<='"+endTime+"' ");
}
sb.append(" and reit_id in ("+itemIds+")) `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`data_id`,`a`.`depart_id`,`a`.`data_time` order by `a`.`data_time`)");
return sb.toString();
}
......
package com.skua.tool.util;
import org.apache.commons.lang3.StringUtils;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
......@@ -36,9 +38,14 @@ public class JSUtils {
return executeExpression(expression,"0.00");
}
public static String divide(Object obj1 , Object obj2){
if(StringUtils.isNotEmpty(obj1.toString())){
if(StringUtils.isNotEmpty(obj2.toString()) && Double.parseDouble(obj2.toString())!=0){
String expression = obj1+ "/" + obj2;
return executeExpression(expression,"0.00");
}
}
return "0";
}
/***
* 格式化结果,保留两位小数
......
......@@ -2,9 +2,11 @@ package com.skua.modules.algorithm.controller;
import com.skua.common.constant.ReportConstant;
import com.skua.common.report.ReportViewUtil;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.algorithm.service.ICommandCentreService;
import com.skua.modules.algorithm.service.impl.ReportItemvService;
......@@ -22,6 +24,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -44,8 +47,6 @@ public class SysCommandCentreController {
@Autowired
private ICommandCentreService commandCentreService;
@Autowired
private ISysConfigService sysConfigService;
@Autowired
private ReportItemvService reportItemvService;
/**
......@@ -177,53 +178,47 @@ public class SysCommandCentreController {
@ApiOperation(value="指挥中心-水量电耗趋势", notes="指挥中心-水量电耗趋势")
@GetMapping(value = "/statisticsBySewage")
public Result<StackedAreaChartDataVO> statisticsBySewage(ReportItemvParam reportItemvParam) throws Exception {
//报表数据项值
String reitId = sysConfigService.queryValueByKey("REIT_ID_DLHJ");
//reportItemvParam.setReportId(reportId);
reportItemvParam.setReitId( reitId );
//电
List<ReportDateTrendVO> electricityMapList = commandCentreService.getReportItemvByReitIdAndDate7Day(reportItemvParam );
//reportItemCode = "CSL";//查询字段
reitId = sysConfigService.queryValueByKey("REIT_ID_CSL");
//水集合
reportItemvParam.setReitId( reitId );
List<ReportDateTrendVO> waterMapList = commandCentreService.getReportItemvByReitIdAndDate7Day(reportItemvParam );
List<String > dateList = new ArrayList<>();//日期数据
List<String> electricityList = new ArrayList<>();//电能数据数据;
List<String> waterList = new ArrayList<>();// 水集合
List<String> consumeList = new ArrayList<>();//电小号集合
List<String> consumeList = new ArrayList<>();//电耗集合
String departIds = BaseContextHandler.getDeparts();
List<ReportDateTrendVO> dlhjDateList = reportItemvService.getDayDateFieldList(ReportConstant.view3a24, "DLHJ", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());
List<ReportDateTrendVO> cslDateList = reportItemvService.getDayDateFieldList(ReportConstant.view2119, "CSL", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());
List<String > dateTimeList = DateUtil.getInstance().getBetweenDate(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(),null);
Map<String,String > electricityMap = new HashMap<String,String >();//电能数据数据;
Map<String,String > waterMap = new HashMap<String,String >();//水
if(electricityMapList != null){
for( ReportDateTrendVO reportDateTrendVO : electricityMapList){
electricityMap.put(reportDateTrendVO.getTime(),reportDateTrendVO.getValue() );
String dlhj = null; String csl = null; String dh = null;
if(dateTimeList != null){
for(String dateTime : dateTimeList){
csl = null;
dlhj = null;
dateList.add( DateUtil.getInstance().formatDate(dateTime,"MM-dd") ) ;
//水
if( cslDateList != null ){
for(ReportDateTrendVO cslVo : cslDateList){
if(dateTime.equals(cslVo.getTime())){
csl = cslVo.getValue();
break;
}
}
if(waterMapList != null){
for( ReportDateTrendVO reportDateTrendVO : waterMapList){
waterMap.put(reportDateTrendVO.getTime(),reportDateTrendVO.getValue() );
}
waterList.add(JSUtils.divide(csl,10000));
//电
if( dlhjDateList != null ){
for(ReportDateTrendVO dlhjVo : dlhjDateList){
if(dateTime.equals(dlhjVo.getTime())){
dlhj = dlhjVo.getValue();
break;
}
String electricity = null; String water = null; String consume = null;
for(String dateTime : dateTimeList){
electricity = electricityMap.get(dateTime ) ;
water = waterMap.get(dateTime ) ;
consume = "0";
if(electricity == null ) electricity = "0";
if(water == null ){
water = "0";
}else{
consume = DigitalUtils.division( electricity ,water );
}
electricityList.add( electricity ) ; waterList.add(water) ; consumeList.add( consume);
dateList.add( DateUtil.getInstance().formatDate(dateTime,"MM-dd") ) ;
}
electricityList.add(ConvertUtils.getString(dlhj,"0"));
//电耗
consumeList.add(JSUtils.divide(JSUtils.divide(dlhj,csl),10000) );
}
}
StackedAreaChartDataVO stackedAreaChartDataVO = new StackedAreaChartDataVO();
stackedAreaChartDataVO.setElectricityList(electricityList);//电集合
stackedAreaChartDataVO.setWaterList(waterList);//水集合
......
......@@ -29,7 +29,7 @@ import java.util.Map;
* @auther kangwei
* @create 2024-11-01-10:09
*/
@Service("reportItemvService")
@Service
public class ReportItemvService {
private JdbcTemplate getJdbcTemplate(){
......@@ -262,6 +262,13 @@ public class ReportItemvService {
String sql = "select DATE_FORMAT( aaa.time, '%Y-%m' ) time , ROUND(SUM(IFNULL(aaa."+field+",0)),2) AS 'value' from " + dataViewName2119+ "aaa group by DATE_FORMAT( aaa.time, '%Y-%m' ) ";
return getJdbcTemplate().query(sql,new BeanPropertyRowMapper<ReportDateTrendVO>(ReportDateTrendVO.class));
}
public List<ReportDateTrendVO> getDayDateFieldList(String reportId, String field, String departId , String startTime , String endTime){
String dataViewName2119 = ReportViewUtil.buildView(reportId,field, departId, startTime,endTime);
String sql = "select aaa.time , ROUND(SUM(IFNULL(aaa."+field+",0)),2) AS 'value' from " + dataViewName2119+ "aaa group by aaa.time order by aaa.time";
return getJdbcTemplate().query(sql,new BeanPropertyRowMapper<ReportDateTrendVO>(ReportDateTrendVO.class));
}
public String getSumCSL(String departId ,String startTime ,String endTime){
String dataViewName2119 = ReportViewUtil.buildViewLike(ReportConstant.view2119,"CSL", departId, startTime,endTime);
String sql = "select ROUND( sum( IFNULL( aaa.CSL,0) ),2) from " + dataViewName2119+ "aaa";
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!