e8480097 康伟

kangwei: 重构电耗分析相关接口,数据查询将pg数据改为日报报数

1 个父辈 4914a3cd
package com.skua.common.report.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* 水质水量报表
* @auther kangwei
* @create 2024-11-27-9:10
*/
@Data
public class DataViewVO {
@ApiModelProperty(value = "时间")
private String time;
@ApiModelProperty(value = "水厂")
private String departId;
@ApiModelProperty(value = "负荷率")
private String fhl;
@ApiModelProperty(value = "进水量")
private BigDecimal JSL;
@ApiModelProperty(value = "出水量")
private BigDecimal CSL;
@ApiModelProperty(value = "处理水量")
private BigDecimal CLSL;
@ApiModelProperty(value = "进水总磷")
private String JSZL;
@ApiModelProperty(value = "进水总磷")
private String CSZL;
@ApiModelProperty(value = "进水COD")
private String JSCOD;
@ApiModelProperty(value = "进水COD")
private String CSCOD;
@ApiModelProperty(value = "进水氨氮")
private String JSAD;
@ApiModelProperty(value = "出水氨氮")
private String CSAD;
@ApiModelProperty(value = "进水总氮")
private String JSZD;
@ApiModelProperty(value = "出水总氮")
private String CSTN;
@ApiModelProperty(value = "进水PH")
private String JSPH;
@ApiModelProperty(value = "出水PH")
private String CSPH;
@ApiModelProperty(value = "进水SS")
private String JSSS;
@ApiModelProperty(value = "出水SS")
private String CSSS;
public DataViewVO(){
}
public void initData(){
this.JSL = BigDecimal.ZERO;
this.CSL= BigDecimal.ZERO;
this.JSZL = "0.0";
this.JSAD = "0.0";
this.CSSS="0.0";
this.JSSS="0.0";
this.CSPH="0.0";
this.JSPH = "0.0";
this.JSZL="0.0";
this.CSZL="0.0";
this.JSCOD="0.0";
this.CSCOD="0.0";
this.JSAD="0.0";
this.CSAD="0.0";
this.JSZD="0.0";
this.CSTN="0.0";
}
//计算一组数据的标准差
public void calculateStandardDeviation(){
}
}
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;
import java.util.ArrayList;
import java.util.List;
/**
* @auther kangwei
* @create 2024-11-26-15:21
*/
@Data
@ApiModel(value="折线图对象", description="折线图对象")
public class DrugChartsVO {
@ApiModelProperty(value = "时间参数")
private List<String> timeList;
@ApiModelProperty(value = "value:数值数组")
private List<String> valueList;
@ApiModelProperty(value = "同比:数值数组")
private List<String> valueTBList;
@ApiModelProperty(value = "总电耗数值数组")
private List<String> dhDataList;
@ApiModelProperty(value = "吨水电耗数值数组")
private List<String> dsdhDataList;
@ApiModelProperty(value = "(负荷率)数值数组")
private List<String> fhlDataList;
@ApiModelProperty(value = "(COD)数值数组")
private List<String> codDataList;
@ApiModelProperty(value = "(氨氮)数值数组")
private List<String> adDataList;
@ApiModelProperty(value = "(总磷)数值数组")
private List<String> zlDataList;
public DrugChartsVO(){
}
public void setDsdhData(String time ,String dsdh){
this.getTimeList().add(time);
this.getDsdhDataList().add(ConvertUtils.getString(dsdh,"0.0"));
}
public void setDsdhData(String time ,String dsdh,String fhl){
this.getTimeList().add(time);
this.getDsdhDataList().add(ConvertUtils.getString(dsdh,"0.0"));
this.getFhlDataList().add(ConvertUtils.getString(fhl,"0.0") );
}
public void setFhlData(String time ,String fhl){
this.getTimeList().add(time);
this.getFhlDataList().add(ConvertUtils.getString(fhl,"0.0") );
}
//设置污染物
public void setCodAdZlData(String time ,String cod,String ad,String zl){
this.getTimeList().add(time);
this.getCodDataList().add(ConvertUtils.getString(cod,"0.0") );
this.getAdDataList().add(ConvertUtils.getString(ad,"0.0"));
this.getZlDataList().add(ConvertUtils.getString(zl,"0.0") );
}
//设置污染物去除率
public void setCodAdZlRateData(DataViewVO dataViewVO2119){
this.getTimeList().add(dataViewVO2119.getTime());
String expressionCod ="(" +dataViewVO2119.getJSCOD() +"-"+ dataViewVO2119.getCSAD() +") *100/ "+dataViewVO2119.getJSCOD();
this.getCodDataList().add(JSUtils.executeExpression( expressionCod ,"0.0"));
String expressionAD ="(" +dataViewVO2119.getJSAD() +"-"+ dataViewVO2119.getCSAD() +") *100/ "+dataViewVO2119.getJSAD();
this.getAdDataList().add(JSUtils.executeExpression( expressionAD ,"0.0"));
String expressionZL ="(" +dataViewVO2119.getJSZL() +"-"+ dataViewVO2119.getCSZL() +") *100/ "+dataViewVO2119.getJSZL();
this.getZlDataList().add(JSUtils.executeExpression( expressionZL ,"0.0"));
}
//设置进水浓度
public void setJSCodAdZlData(DataViewVO dataViewVO2119){
this.getTimeList().add(dataViewVO2119.getTime());
this.getCodDataList().add( dataViewVO2119.getJSCOD() );
this.getAdDataList().add(dataViewVO2119.getJSAD());
this.getZlDataList().add( dataViewVO2119.getJSZL());
}
//设置出水浓度
public void setCSCodAdZlData(DataViewVO dataViewVO2119){
this.getTimeList().add(dataViewVO2119.getTime());
this.getCodDataList().add( dataViewVO2119.getCSCOD() );
this.getAdDataList().add(dataViewVO2119.getCSCOD());
this.getZlDataList().add( dataViewVO2119.getCSZL());
}
public List<String> getValueList() {
if(valueList == null ) valueList = new ArrayList<>();
return valueList;
}
public List<String> getValueTBList() {
if(valueTBList == null ) valueTBList = new ArrayList<>();
return valueTBList;
}
public List<String> getTimeList() {
if(timeList == null ) timeList = new ArrayList<>();
return timeList;
}
public List<String> getDsdhDataList() {
if(dsdhDataList == null ) dsdhDataList = new ArrayList<>();
return dsdhDataList;
}
public List<String> getFhlDataList() {
if(fhlDataList == null ) fhlDataList = new ArrayList<>();
return fhlDataList;
}
public List<String> getCodDataList() {
if(codDataList == null ) codDataList = new ArrayList<>();
return codDataList;
}
public List<String> getAdDataList() {
if(adDataList == null ) adDataList = new ArrayList<>();
return adDataList;
}
public List<String> getZlDataList() {
if(zlDataList == null ) zlDataList = new ArrayList<>();
return zlDataList;
}
}
......@@ -7,10 +7,9 @@ import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -377,6 +376,28 @@ public class JSUtils {
return str;
}
/***
* 计算时间的前几个月的月份
* @param month
* @param time
* @return
*/
public static String getMonthBytime(int month,String time) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(format.parse(time));
} catch (ParseException e) {
e.printStackTrace();
}
calendar.add(Calendar.MONTH, month);
return format.format(calendar.getTime());
}
public static void main(String[] args) {
System.out.println(getMonthBytime(-12,"2024-12"));
}
/* ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript");
Object eval = null;
try {
......
......@@ -10,4 +10,13 @@ public class TonOfWaterAndLoadRateDto {
private String dsdh;
private String fhl;
public TonOfWaterAndLoadRateDto(){
}
public TonOfWaterAndLoadRateDto(String time, String dsdh, String fhl) {
this.time = time;
this.dsdh = dsdh;
this.fhl = fhl;
}
}
......
......@@ -7,4 +7,12 @@ public class TonOfWaterTrendDto {
private String time;
private String v;
public TonOfWaterTrendDto(){
}
public TonOfWaterTrendDto(String time, String v) {
this.time = time;
this.v = v;
}
}
......
......@@ -73,28 +73,6 @@ public interface ComprehensiveSupervisionMapper {
String selectMetricNameById(String id);
/**
* 月度电耗水耗统计
*
* @return
*/
ConsumptionDto selectMonthlyPowerConsumption(@Param("dataStr") String dataStr, @Param("departIds") List<String> departIds);
/**
* 月度药耗统计
*
* @return
*/
DrugConsumptionDto selectMonthlyDrugConsumptionStatistics(@Param("dataStr") String dataStr, @Param("departIds") List<String> departIds);
/**
* 天出水量统计
*
* @return
*/
Integer selectShByDay(@Param("date") String date, @Param("departIds") List<String> departIds);
/**
......
......@@ -230,144 +230,8 @@
select metric_name from sys_monitor_metric_info
where id=#{id}
</select>
<select id="selectMonthlyPowerConsumption" resultType="com.skua.modules.equipment.dto.ConsumptionDto">
SELECT
dateStr AS TIME,
sum( dh ) AS dh,
FORMAT(
sum( dh )/ sum( csl ),2) AS dsdh
FROM
(
SELECT
v.item_value AS dh,
DATE_FORMAT( v.data_time, '%Y-%m' ) AS dateStr,
0 AS csl
FROM
f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE
i.report_id = '07079703413c58fd96d79298f23af854'
AND i.item_code = 'dhkwh64bc'
and v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
AND DATE_FORMAT( v.data_time, '%Y-%m' ) = #{dataStr} UNION ALL
SELECT
0 AS dh,
DATE_FORMAT( v.data_time, '%Y-%m' ) AS dateStr,
v.item_value AS csl
FROM
f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE
i.report_id = '2044b09220b8413eeda84ce4c861305b'
AND i.item_code = 'csl50c'
and v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
AND DATE_FORMAT( v.data_time, '%Y-%m' ) = #{dataStr}
) AS d
GROUP BY
dateStr
</select>
<select id="selectMonthlyDrugConsumptionStatistics"
resultType="com.skua.modules.equipment.dto.DrugConsumptionDto">
SELECT dateStr AS TIME,
sum(yh) AS yh,
FORMAT(
sum(yh) / sum(csl),2) AS dsyh
FROM (SELECT DATE_FORMAT(v.data_time, '%Y-%m') as dateStr,
v.item_value AS yh,
0 AS csl
FROM f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE i.report_id = '07079703413c58fd96d79298f23af854'
AND i.item_code IN (
'lsytgtxhldc44',
'lsytytxhlda760',
'sysytxhld95e',
'pamylzgtxhldb77',
'pamylzgtxhldb0f',
'fmhxtgtxhldc0',
'klhxtgtxhldfc1d',
'jhlytxhld4f41',
'jhlgtxhld17d',
'lygtxhldf2d5',
'fhtyytxhld55ce',
'fhtygtxhld046f',
'pttgtxhlda01c',
'pttytxhldea55',
'clsnnacloytxhld09ea',
'qljgtxhldf9e1',
'yyytxhld84d',
'gyygtxhlde2ca',
'nmsytxhld245a',
'zgjytxhld49a5',
'qyhnnaohgtxhld2fde',
'qyhnnaohytxhld8bae',
'tsnna2cogtxhld6e21',
'jhlstytxhld29d8',
'nlsytxhld6dff',
'xpjgtxhldc22',
'cfjytxhlda2a1',
'hyjnahsogtxhlde7e',
'fyhsjjytxhld959',
'chjcyyxhldbcd6',
'jzytxhldea44',
'mzyqxjytxhld52f',
'lsqengtxhlde976',
'edta4nagtxhld06e2',
'qthxyj1xhldf66f',
'qthxyj2xhld2f0a',
'qthxyjxhldb97b',
'qthxyj4xhld2645',
'qthxyj5xhldaf94',
'qthxyj6xhld2152'
)
AND v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
AND DATE_FORMAT(v.data_time, '%Y-%m') = #{dataStr}
UNION ALL
SELECT DATE_FORMAT(v.data_time, '%Y-%m') as dateStr,
0 AS yh,
v.item_value AS csl
FROM f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE i.report_id = '2044b09220b8413eeda84ce4c861305b'
AND i.item_code = 'csl50c'
AND v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
AND DATE_FORMAT(v.data_time, '%Y-%m') = #{dataStr}) d
GROUP BY dateStr
</select>
<select id="selectShByDay" resultType="java.lang.Integer">
SELECT sum(b.item_value)
FROM (SELECT v.item_value,
DATE_FORMAT(v.data_time, '%Y-%m-%d') AS dateStr
FROM f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE-- 今日出水
i.report_id = '2044b09220b8413eeda84ce4c861305b'
AND i.item_code = 'csl50c'
AND v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
AND DATE_FORMAT(v.data_time, '%Y-%m-%d') = #{date}) AS b
GROUP BY dateStr
</select>
<select id="selectCountAlarmByYearForDay" resultType="com.skua.modules.equipment.dto.AlarmCountDto">
select count(1),
DATE_FORMAT(create_time, '%Y-%m-%d') as dateStr
......@@ -416,9 +280,9 @@
</select>
<select id="selectClslByMonths" resultType="java.util.HashMap">
select sum(item_value) as v,DATE_FORMAT(data_time, '%Y-%m') as time from f_report_itemv a
select round(sum(item_value),2) as v,DATE_FORMAT(data_time, '%Y-%m') as time from f_report_itemv a
left join f_report_item b on b.id=a.reit_id
where b.item_code='csl503c'
where b.item_code='CSL'
and a.depart_id = #{factoryId}
<if test="list!=null and list.size>0">
and DATE_FORMAT(data_time, '%Y-%m') in
......
......@@ -3,8 +3,10 @@ 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.DataViewVO;
import com.skua.common.report.vo.ReportItemVO;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.equipment.dto.*;
import com.skua.modules.equipment.mapper.ComprehensiveSupervisionMapper;
import com.skua.modules.equipment.service.IPowerConsumptionAnalysisService;
......@@ -13,6 +15,7 @@ import com.skua.modules.equipment.vo.MetricVo;
import com.skua.tool.util.JSUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
......@@ -134,7 +137,7 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
}*/
return result;
}
//总电耗趋势
@Override
public Map<String, Object> powerConsumptionTrend(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
......@@ -178,305 +181,301 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
return result;
}
//吨水电耗趋势
@Override
public Map<String, Object> tonOfWaterTrend(AnysisParamsVO anysisParamsVO) {
List<TonOfWaterTrendDto> dtos=new ArrayList<>();//封装数据
String time = anysisParamsVO.getTime();
String startDate = JSUtils.getMonthBytime(-12,time)+"-01";
String endDate = JSUtils.getMonthBytime(-0,time)+"-31";
/* String startTime = time+"-01" ;
String endTime = time + "-31";*/
//查询前推十二个月的数据
List<String> months=this.getTwelve(time);
List<String> monthList = this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
dtos.add(dto);
}
result.put("data",dtos);
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
List<AlarmDto> CSList=new ArrayList<>();
List<Map<String, Object>> monitorList2 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
if (monitorList2.size()>0){
for (Map<String, Object> map : monitorList2) {
AlarmDto dto=new AlarmDto();
dto.setV(map.get("v").toString());
dto.setTime(map.get("time").toString());
CSList.add(dto);
}
}
List<AlarmDto> DHList=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=DHList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
if (dhMap.get(month)!=null){
String v=dhMap.get(month);
if (csMap.get(month)!=null){
//本月累计电耗量[kW·h]/本月累计处理水量[吨]
dto.setV(this.getValue((Double.parseDouble(v)/(Double.parseDouble(csMap.get(month)))))+"");
//查询数据
List<ReportItemVO> dsdhTrendListList =queryDSDHTrendList( factoryId, startDate, endDate,false);
for (String dateTime : monthList) {
String dsValue = null;
//String yesmonth = this.getMonthBytime(-12, dateTime);//同比
if (dsdhTrendListList != null) {
for (ReportItemVO reportItemVO : dsdhTrendListList) {
if (dateTime.equals(reportItemVO.getTime())) {
dsValue = reportItemVO.getDsValue();
break;
}
}
}
dtos.add(dto);
dtos.add( new TonOfWaterTrendDto(dateTime, ConvertUtils.getString(dsValue,"0.0")));
}
result.put("data",dtos);
return result;
}
//吨水电耗与负荷率对比
@Override
public Map<String, Object> tonOfWaterAndLoadRate(AnysisParamsVO anysisParamsVO) throws Exception{
//封装数据
List<TonOfWaterAndLoadRateDto> dtos = new ArrayList<>();
String time = anysisParamsVO.getTime();
String startTime = JSUtils.getMonthBytime(-12,time)+"-01";
String endTime = JSUtils.getMonthBytime(-0,time)+"-31";
//查询前推十二个月的数据
List<String> months=this.getTwelve(time);
//查询吨水电耗
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
for (String month : months) {
TonOfWaterAndLoadRateDto dto=new TonOfWaterAndLoadRateDto();
dto.setTime(month);
dtos.add(dto);
}
result.put("data",dtos);
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
List<Map<String, Object>> monitorList2 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
List<AlarmDto> CSList=new ArrayList<>();
if (monitorList2.size()>0){
for (Map<String, Object> map : monitorList2) {
AlarmDto dto=new AlarmDto();
dto.setV(map.get("v").toString());
dto.setTime(map.get("time").toString());
CSList.add(dto);
// {time: "2023-11", dsdh: null, fhl: null}
//查询数据
List<ReportItemVO> dsdhTrendListList =queryDSDHTrendList( factoryId, startTime, endTime,false);
List<ReportItemVO> fhlTrendList = queryFhlTrendList( factoryId, startTime, endTime);// 负荷率
//获取12个月时间集合
String dsValue = null;String fhl = null;
List<String> monthList=this.getTwelve(time);
for (String dateTime : monthList) {
//String yesmonth = this.getMonthBytime(-12, dateTime);//同比
if (dsdhTrendListList != null) {
for (ReportItemVO reportItemVO : dsdhTrendListList) {
if (dateTime.equals(reportItemVO.getTime())) {
dsValue = reportItemVO.getDsValue();
break;
}
}
}
}
//查询设计规模
String sjgm=comprehensiveSupervisionMapper.selectSJGM(factoryId);
//封装数据
List<AlarmDto> DHList=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=DHList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : months) {
TonOfWaterAndLoadRateDto dto=new TonOfWaterAndLoadRateDto();
dto.setTime(month);
if (dhMap.get(month)!=null){
String v=dhMap.get(month);
if (csMap.get(month)!=null){
//本月累计电耗量[kW·h]/本月累计处理水量[吨]
dto.setDsdh(this.getValue((Double.parseDouble(v)/(Double.parseDouble(csMap.get(month))))).toString());
//负荷率
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
calendar.setTime(sdf.parse(time));
Integer num = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//负荷率=该月的日均处理水量/设计规模
dto.setFhl(this.getValue(Double.parseDouble(csMap.get(month))/(Double.valueOf(sjgm)*num*10000)).toString());
if (fhlTrendList != null) {
for (ReportItemVO reportItemVO : fhlTrendList) {
if (dateTime.equals(reportItemVO.getTime())) {
fhl = reportItemVO.getValue();
break;
}
}
}
dtos.add(dto);
dtos.add( new TonOfWaterAndLoadRateDto(dateTime, ConvertUtils.getString(dsValue,"0.0"), ConvertUtils.getString(fhl,"0.0")));
}
result.put("data",dtos);
return result;
}
//吨水电耗与污染物浓度
@Override
public Map<String, Object> tonOfWaterAndPollutantConcentration(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
String startTime = JSUtils.getMonthBytime(-12,time)+"-01";
String endTime = JSUtils.getMonthBytime(-0,time)+"-31";
//查询前推十二个月的数据
List<String> months = this.getTwelve(time);
List<String> monthList = this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String[] strings={"JSCOD","CSCOD","CSNH3N","JSNH3N","JSTP","CSTP"};
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
List<PollutantConcentrationDto> dtodsdh = new ArrayList<>();
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtodsdh.add(dto);
}
result.put("DSDH", dtodsdh);
for (String string : strings) {
List<PollutantConcentrationDto> dtos1 = new ArrayList<>();
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
result.put(string, dtos1);
}
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
//查询吨水电耗
String device=comprehensiveSupervisionMapper.selectDeviceName(factoryId);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//吨水电耗数据
List<ReportItemVO> dsdhTrendListList =queryDSDHTrendList( factoryId, startTime, endTime,false);
//查询数据:水质水量报表
List<DataViewVO> dataViewVO2119List = queryDataView2119( factoryId, startTime, endTime);
//吨水电耗
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));
for (String string : strings) {
MetricVo metricVo = comprehensiveSupervisionMapper.selectMetric(string,factoryId);
List<PollutantConcentrationDto> dtos1 = new ArrayList<>();
if(metricVo==null){
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
result.put(string, dtos1);
}else {
StringBuilder str = new StringBuilder();
str.append("'" + metricVo.getId() + "'");
String sql1 = "select avg(cast(v as float8)) as v,substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8) as time\n" +
" FROM " + tableName + "\n" +
"where nm in (" + str.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='" + months.get(11) + "'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='" + months.get(0) + "'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> monitorList = null;
try {
monitorList = pgDb.queryForList(sql1);
Map<String, Object> monitorMap = new HashMap<>();
if (monitorList.size() > 0) {
for (Map<String, Object> map : monitorList) {
monitorMap.put(map.get("time").toString(),this.getValue(Double.parseDouble(map.get("v").toString())).toString());
}
for (String month : months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
if(monitorMap.get(month)!=null){
dto.setV(monitorMap.get(month).toString());
}
dto.setTime(month);
dtos1.add(dto);
List<TonOfWaterTrendDto> trend_dsdh = new ArrayList<>();
//进水
List<TonOfWaterTrendDto> trend_JSCOD = new ArrayList<>();
List<TonOfWaterTrendDto> trend_JSNH3N = new ArrayList<>();
List<TonOfWaterTrendDto> trend_JSTP = new ArrayList<>();
//出水
List<TonOfWaterTrendDto> trend_CSCOD = new ArrayList<>();
List<TonOfWaterTrendDto> trend_CSNH3N = new ArrayList<>();
List<TonOfWaterTrendDto> trend_CSTP = new ArrayList<>();
if (monthList != null) {
for (String month : monthList) {
String dsdh = null;
String js_cod = null;
String js_nh3n = null;
String jd_tp = null;
String cs_cod = null;
String cs_nh3n = null;
String cs_tp = null;
//遍历吨水电耗
if(dsdhTrendListList != null ){
for(ReportItemVO reportItemVO : dsdhTrendListList){
if (month.equals(reportItemVO.getTime())) {
dsdh = reportItemVO.getDsValue();
break;
}
}else{
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
}
if (dataViewVO2119List != null) { //遍历集合
for (DataViewVO dataView : dataViewVO2119List) {
if (month.equals(dataView.getTime())) {
js_cod = dataView.getJSCOD();
js_nh3n = dataView.getJSAD();
jd_tp = dataView.getJSZL();
cs_cod = dataView.getCSCOD();
cs_nh3n = dataView.getCSAD();
cs_tp = dataView.getCSZL();
break;
}
}
result.put(string, dtos1);
} catch (DataAccessException e) {
e.printStackTrace();
}
trend_dsdh.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( dsdh, "0.0")) ) ;
trend_JSCOD.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( js_cod, "0.0")) ) ;
trend_JSNH3N.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( js_nh3n, "0.0")) ) ;
trend_JSTP.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( jd_tp, "0.0")) ) ;
trend_CSCOD.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( cs_cod, "0.0")) ) ;
trend_CSNH3N.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( cs_nh3n, "0.0")) ) ;
trend_CSTP.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( cs_tp, "0.0")) ) ;
}
}
result.put("DSDH",trend_dsdh);
result.put("JSCOD",trend_JSCOD);
result.put("JSNH3N",trend_JSNH3N);
result.put("JSTP",trend_JSTP);
result.put("CSCOD",trend_CSCOD);
result.put("CSNH3N",trend_CSNH3N);
result.put("CSTP",trend_CSTP);
return result;
}
//吨水电耗与污染物去除率对比
@Override
public Map<String, Object> tonOfWaterAndPollutantRemovalRate(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
String startTime = JSUtils.getMonthBytime(-12,time)+"-01";
String endTime = JSUtils.getMonthBytime(-0,time)+"-31";
//查询近12个月的数据
List<String> months=this.getTwelve(time);
List<String> monthList = this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));//吨水电耗
result.put("COD",this.getRemovalRate("","",null,null,months,factoryId));
result.put("NH3N",this.getRemovalRate("","",null,null,months,factoryId));
result.put("TP",this.getRemovalRate("","",null,null,months,factoryId));
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
String device=comprehensiveSupervisionMapper.selectDeviceName(factoryId);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//吨水电耗数据
List<ReportItemVO> dsdhTrendListList =queryDSDHTrendList( factoryId, startTime, endTime,false);
//查询数据:水质水量报表
List<DataViewVO> dataViewVO2119List = queryDataView2119( factoryId, startTime, endTime);
//吨水电耗
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));
List<TonOfWaterTrendDto> trend_dsdh = new ArrayList<>();
//计算去除率
List<TonOfWaterTrendDto> analyVos=this.getRemovalRate("JSCOD","CSCOD",pgDb,tableName,months,factoryId);
result.put("COD",analyVos);
List<TonOfWaterTrendDto> analyVos1=this.getRemovalRate("JSNH3N","CSNH3N",pgDb,tableName,months,factoryId);
result.put("NH3N",analyVos1);
List<TonOfWaterTrendDto> analyVos2=this.getRemovalRate("JSTP","CSTP",pgDb,tableName,months,factoryId);
result.put("TP",analyVos2);
return result;
}
List<TonOfWaterTrendDto> trend_cod = new ArrayList<>();
List<TonOfWaterTrendDto> trend_nh3n = new ArrayList<>();
List<TonOfWaterTrendDto> trend_tp = new ArrayList<>();
private List<TonOfWaterTrendDto> getRemovalRate(String jscod, String cscod, JdbcTemplate pgDb, String tableName, List<String> months, String factoryId) {
List<TonOfWaterTrendDto> dtos=new ArrayList<>();
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric(jscod,factoryId);
if(metricVo1==null){
for (String month :months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
dtos.add(dto);
}
return dtos;
}
StringBuilder str1 = new StringBuilder();
MetricVo metricVo2 = comprehensiveSupervisionMapper.selectMetric(cscod,factoryId);
if(metricVo2==null){
str1.append("'" + metricVo1.getId() + "'");
}else{
str1.append("'" + metricVo1.getId() + "'"+","+"'" + metricVo2.getId() + "'");
}
String sql="select avg(cast(v as float8)) as v,nm,\n" +
"substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8) as time\n" +
" FROM " + tableName + "\n" +
"where nm in (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='"+months.get(11)+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='"+months.get(0)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8),nm";
List<Map<String, Object>> monitorList1 = null;
List<AlarmDto> alarmDtos=new ArrayList<>();
try {
monitorList1 = pgDb.queryForList(sql);
if (monitorList1.size()>0){
for (Map<String, Object> map : monitorList1) {
AlarmDto dto=new AlarmDto();
dto.setName(map.get("nm").toString());
dto.setTime(map.get("time").toString());
dto.setV(map.get("v").toString());
alarmDtos.add(dto);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//封装数据
Map<String,List<AlarmDto>> map=alarmDtos.stream().collect(Collectors.groupingBy(AlarmDto::getTime));
List<String> stringList=map.keySet().stream().collect(Collectors.toList());
Collections.sort(stringList);
Map<String, Object> qclMap = new HashMap<>();
for (String s : stringList) {
List<AlarmDto> dtoList=map.get(s);
Double jsV=0d;
Double csV=0d;
for (AlarmDto dto : dtoList) {
if (dto.getName().equals(metricVo1.getId())){
jsV=Double.valueOf(dto.getV());
if (monthList != null) {
for (String month : monthList) {
String dsdh = null;
String cod = null;
String nh3n = null;
String tp = null;
//遍历吨水电耗
if(dsdhTrendListList != null ){
for(ReportItemVO reportItemVO : dsdhTrendListList){
if (month.equals(reportItemVO.getTime())) {
dsdh = reportItemVO.getDsValue();
break;
}
}
}
if (dto.getName().equals(metricVo2.getId())){
csV=Double.valueOf(dto.getV());
if (dataViewVO2119List != null) { //遍历集合
for (DataViewVO dataView : dataViewVO2119List) {
if (month.equals(dataView.getTime())) {
String expressionCod ="(" +dataView.getJSCOD() +"-"+ dataView.getCSAD() +") *100/ "+dataView.getJSCOD();
cod = JSUtils.executeExpression( expressionCod ,"0.0");
String expressionAD ="(" +dataView.getJSAD() +"-"+ dataView.getCSAD() +") *100/ "+dataView.getJSAD();
nh3n = JSUtils.executeExpression( expressionAD ,"0.0");
String expressionZL ="(" +dataView.getJSZL() +"-"+ dataView.getCSZL() +") *100/ "+dataView.getJSZL();
tp = JSUtils.executeExpression( expressionZL ,"0.0");
break;
}
}
}
trend_dsdh.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( dsdh, "0.0")) ) ;
trend_cod.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( cod, "0.0")) ) ;
trend_nh3n.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( nh3n, "0.0")) ) ;
trend_tp.add( new TonOfWaterTrendDto(month ,ConvertUtils.getString( tp, "0.0")) ) ;
}
TonOfWaterTrendDto vo1=new TonOfWaterTrendDto();
vo1.setTime(s);
//污染物去除率=(进水指标(mg/L)-出水指标(mg/L))/进水指标(mg/L)*100%。
double result=(double)(Math.round((jsV-csV)*100/jsV)/100.0);
vo1.setV(this.getValue(result)+"");
qclMap.put(s,this.getValue(result)+"");
}
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
if(qclMap.get(month)!=null){
dto.setV(qclMap.get(month).toString());
}
dto.setTime(month);
dtos.add(dto);
result.put("DSDH",trend_dsdh);
result.put("NH3N",trend_nh3n);
result.put("TP",trend_tp);
result.put("COD",trend_cod);
return result;
}
/**************************************/
// 水质水量报表
private List<DataViewVO> queryDataView2119(String departIds, String startTime, String endTime) {
//ReportConstant.fieldSz = JSZL,CSZL,JSCOD,CSCOD,JSAD,CSAD,JSZD,CSTN,JSPH,JSSS,CSPH,CSSS";
String dataViewName2119 = ReportViewUtil.buildView(ReportConstant.view2119, ReportConstant.fieldSz, departIds, startTime, endTime);
String sql = " select DATE_FORMAT(aaa.time,'%Y-%m') 'time' , ROUND( SUM( IFNULL(aaa.JSCOD,0) ), 2 ) AS JSCOD, ROUND( SUM( IFNULL(aaa.CSCOD,0) ), 2 ) AS CSCOD,";
sql += " ROUND( SUM( IFNULL(aaa.JSZL,0) ), 2 ) AS JSZL, ROUND( SUM( IFNULL(aaa.CSZL,0) ), 2 ) AS CSZL,";
sql += "ROUND( SUM( IFNULL(aaa.JSAD,0) ), 2 ) AS JSAD, ROUND( SUM( IFNULL(aaa.CSAD,0) ), 2 ) AS CSAD ";
sql += "from "+ dataViewName2119 +" aaa ";
sql += " group by DATE_FORMAT(aaa.time,'%Y-%m') ";
//查询数据
List<DataViewVO> dataViewVO2119List = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<DataViewVO>(DataViewVO.class));
return dataViewVO2119List;
}
// 负荷率
private List<ReportItemVO> queryFhlTrendList(String departIds, String startTime, String endTime) {
String dataViewName3a24 = ReportViewUtil.buildView(ReportConstant.view2119,ReportConstant.field_CSL, departIds, startTime, endTime);
String sql = " select bbb.time,ROUND(avg(bbb.wsfhl),2) 'value' from ( ";
sql += " select DATE_FORMAT(aaa.time,'%Y-%m') 'time' ,aaa.depart_id , sum(aaa.CSL) CSL, ROUND( IFNULL( 100 * ( sum(aaa.CSL)/( f.pro_scale * 31*10000 ) ),0), 2 ) AS wsfhl from "+ dataViewName3a24 +" aaa ";
sql += " LEFT JOIN sys_factory_info f ON f.depart_id = aaa.depart_id " ;
sql += " group by DATE_FORMAT(aaa.time,'%Y-%m') , aaa.depart_id ";
sql += ")bbb group by bbb.time ";
//查询数据
List<ReportItemVO> trendVOList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
return trendVOList;
}
/***
* 时间 + 吨水电耗处理集合
* @param departIds
* @param startTime
* @param endTime
* @param isLowFlag true 只显示一条最小吨水电耗、 false显示所有
* @return
*/
private List<ReportItemVO> queryDSDHTrendList(String departIds, String startTime, String endTime,boolean isLowFlag ) {
String sql = getDSDHSql(departIds, startTime, endTime, isLowFlag);
List<ReportItemVO> trendVOList = getJdbcTemplate().query(sql,new BeanPropertyRowMapper<ReportItemVO>(ReportItemVO.class));
return trendVOList;
}
/***
* 获取吨水电耗sql语句
* @return
*/
private String getDSDHSql(String departIds, String startTime, String endTime,boolean isLowFlag){
String dataViewName2119 = ReportViewUtil.buildView(ReportConstant.view2119,ReportConstant.field_CSL, departIds, startTime, endTime);
String dataViewName3a24 = ReportViewUtil.buildView(ReportConstant.view3a24,ReportConstant.fieldDl, departIds, startTime,endTime);
String sql = " select bbb.time,round(IFNULL( bbb.DLHJ /ddd.CSL,0 ),2) as 'dsValue' ,round(IFNULL( bbb.DLHJ,0 ),2) as 'value' from ( ";
sql += " select DATE_FORMAT(aaa.time,'%Y-%m') 'time' , ROUND(sum(aaa.DLHJ),2) DLHJ from "+dataViewName3a24 +" aaa group by DATE_FORMAT(aaa.time,'%Y-%m') ";
sql += " )bbb ";
sql += " left join ( ";
sql += " select DATE_FORMAT(ccc.time,'%Y-%m') 'time' , ROUND(sum(ccc.CSL),2) CSL from "+dataViewName2119 +" ccc group by DATE_FORMAT(ccc.time,'%Y-%m') ";
sql += " )ddd on bbb.time = ddd.time ";
if(isLowFlag ){
sql += " order by (bbb.DLHJ - ddd.CSL) limit 1";
}
return dtos;
return sql;
}
private JdbcTemplate getJdbcTemplate(){
JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
return masterDB;
}
private List<String> getTwelve(String time) {
......@@ -487,47 +486,6 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
return list;
}
private Map<String, Object> getLower(String factoryId){
//查询历史最低吨水电耗
Map<String, Object> result = Maps.newHashMap();
//查询所有月份的出水流量 v time
List<AlarmDto> csList = comprehensiveSupervisionMapper.selectAllClsl(factoryId);
//查询所有月份的耗电量
List<AlarmDto> dhList=comprehensiveSupervisionMapper.selectAllDh(factoryId);
Map<String,String> csMap=csList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=dhList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
List<String> list=csMap.keySet().stream().collect(Collectors.toList());
Double mindsdh=null;
String mintime=new String();
for (String s : list) {
//查询当前吨水电耗
String cs=csMap.get(s);
if (dhMap.get(s)!=null){
String dh=dhMap.get(s);
Double dsdh=Double.parseDouble(dh)/Double.parseDouble(cs);
if (mindsdh==null){
mindsdh=dsdh;
mintime=s;
}else {
if (mindsdh>dsdh){
mindsdh=dsdh;
mintime=s;
}
}
}
}
result.put("mindsdh",mindsdh);
result.put("mintime",mintime);
return result;
}
private Double getValue(Double d) {
BigDecimal two = new BigDecimal(d);
double three = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
return three;
}
private String getMonthBytime(int i,String time) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM");
Calendar calendar = Calendar.getInstance();
......@@ -539,4 +497,10 @@ public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAna
calendar.add(Calendar.MONTH, i);
return format.format(calendar.getTime());
}
private Double getValue(Double d) {
BigDecimal two = new BigDecimal(d);
double three = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
return three;
}
}
......
/*
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.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.tool.util.JSUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class PowerConsumptionAnalusisServiceImplBak implements IPowerConsumptionAnalysisService {
@Resource
private ComprehensiveSupervisionMapper comprehensiveSupervisionMapper;
@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.65");
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
result.put("zhdl","-");
result.put("dsdh","-");
result.put("tbqnzhdl","-");
result.put("hbsyzhdl","-");
result.put("mindsdh","-");
result.put("mindsdhyf","-");
result.put("tbqnzhdlsl","-");
result.put("tbqnzhdlbl","-");
result.put("hbsyzhdlsl","-");
result.put("hbsyzhdlbl","-");
result.put("tbqndsdhsl","-");
result.put("tbqndsdhbl","-");
result.put("hbsydsdhsl","-");
result.put("hbsydsdhbl","-");
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
//总耗电量
List<String> months=new ArrayList<>();
months.add(time);
//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));
//吨水电耗
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()));
//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());
}
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));
if (Double.compare(tbqnzhdl, 0.0) == 0) {
result.put("tbqnzhdlbl", 0.0);
} else {
result.put("tbqnzhdlbl",this.getValue(((dsdh-tbqnzhdl)/tbqnzhdl)*100));
}
}*//*
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));
if (Double.compare(hbsyzhdl, 0.0) == 0) {
result.put("hbsyzhdlbl", 0.0);
} else {
result.put("hbsyzhdlbl",this.getValue(((dsdh-hbsyzhdl)/hbsyzhdl)*100));
}
}*//*
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));
if (Double.compare(tbqndsdh, 0.0) == 0) {
result.put("tbqndsdhbl", 0.0);
} else {
result.put("tbqndsdhbl",this.getValue(((dsdh-tbqndsdh)/tbqndsdh)*100));
}
}*//*
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));
if (Double.compare(hbqndsdh, 0.0) == 0) {
result.put("hbsydsdhbl", 0.0);
} else {
result.put("hbsydsdhbl",this.getValue(((dsdh-hbqndsdh)/hbqndsdh)*100));
}
}*//*
return result;
}
@Override
public Map<String, Object> powerConsumptionTrend(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
List<String> months=this.getTwelve(time);
List<powerConsumptionTrendDto> dtos=new ArrayList<>();//封装数据
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
for (String month : months) {
powerConsumptionTrendDto dto=new powerConsumptionTrendDto();
dto.setTime(month);
dtos.add(dto);
}
result.put("data", dtos);
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
//查询当前时间往前推12个月的数据
String startTime=this.getMonthBytime(-12,time);
String endTime=this.getMonthBytime(-1,time);
List<AlarmDto> current=comprehensiveSupervisionMapper.selectDhByStartAndEnd(startTime,endTime,factoryId);
Map<String,String> currMap=current.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
String yesStartTime=this.getMonthBytime(-12,startTime);
String yesEndTime=this.getMonthBytime(-1,startTime);
List<AlarmDto> yes=comprehensiveSupervisionMapper.selectDhByStartAndEnd(yesStartTime,yesEndTime,factoryId);
Map<String,String> yesMap=yes.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : months) {
String yesmonth=this.getMonthBytime(-12,month);
powerConsumptionTrendDto dto=new powerConsumptionTrendDto();
dto.setTime(month);
if (currMap.get(month)!=null){
dto.setZdh(this.getValue(Double.parseDouble(currMap.get(month))/10000).toString());
}
if (yesMap.get(yesmonth)!=null){
dto.setTbzdh(this.getValue(Double.parseDouble(yesMap.get(yesmonth))/10000).toString());
}
dtos.add(dto);
}
result.put("data",dtos);
return result;
}
@Override
public Map<String, Object> tonOfWaterTrend(AnysisParamsVO anysisParamsVO) {
List<TonOfWaterTrendDto> dtos=new ArrayList<>();//封装数据
String time = anysisParamsVO.getTime();
//查询前推十二个月的数据
List<String> months=this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
dtos.add(dto);
}
result.put("data",dtos);
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
List<AlarmDto> CSList=new ArrayList<>();
List<Map<String, Object>> monitorList2 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
if (monitorList2.size()>0){
for (Map<String, Object> map : monitorList2) {
AlarmDto dto=new AlarmDto();
dto.setV(map.get("v").toString());
dto.setTime(map.get("time").toString());
CSList.add(dto);
}
}
List<AlarmDto> DHList=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=DHList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
if (dhMap.get(month)!=null){
String v=dhMap.get(month);
if (csMap.get(month)!=null){
//本月累计电耗量[kW·h]/本月累计处理水量[吨]
dto.setV(this.getValue((Double.parseDouble(v)/(Double.parseDouble(csMap.get(month)))))+"");
}
}
dtos.add(dto);
}
result.put("data",dtos);
return result;
}
@Override
public Map<String, Object> tonOfWaterAndLoadRate(AnysisParamsVO anysisParamsVO) throws Exception{
//封装数据
List<TonOfWaterAndLoadRateDto> dtos = new ArrayList<>();
String time = anysisParamsVO.getTime();
//查询前推十二个月的数据
List<String> months=this.getTwelve(time);
//查询吨水电耗
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
for (String month : months) {
TonOfWaterAndLoadRateDto dto=new TonOfWaterAndLoadRateDto();
dto.setTime(month);
dtos.add(dto);
}
result.put("data",dtos);
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
List<Map<String, Object>> monitorList2 = comprehensiveSupervisionMapper.selectClslByMonths(months,factoryId);
List<AlarmDto> CSList=new ArrayList<>();
if (monitorList2.size()>0){
for (Map<String, Object> map : monitorList2) {
AlarmDto dto=new AlarmDto();
dto.setV(map.get("v").toString());
dto.setTime(map.get("time").toString());
CSList.add(dto);
}
}
//查询设计规模
String sjgm=comprehensiveSupervisionMapper.selectSJGM(factoryId);
//封装数据
List<AlarmDto> DHList=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=DHList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : months) {
TonOfWaterAndLoadRateDto dto=new TonOfWaterAndLoadRateDto();
dto.setTime(month);
if (dhMap.get(month)!=null){
String v=dhMap.get(month);
if (csMap.get(month)!=null){
//本月累计电耗量[kW·h]/本月累计处理水量[吨]
dto.setDsdh(this.getValue((Double.parseDouble(v)/(Double.parseDouble(csMap.get(month))))).toString());
//负荷率
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
calendar.setTime(sdf.parse(time));
Integer num = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//负荷率=该月的日均处理水量/设计规模
dto.setFhl(this.getValue(Double.parseDouble(csMap.get(month))/(Double.valueOf(sjgm)*num*10000)).toString());
}
}
dtos.add(dto);
}
result.put("data",dtos);
return result;
}
@Override
public Map<String, Object> tonOfWaterAndPollutantConcentration(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
//查询前推十二个月的数据
List<String> months = this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String[] strings={"JSCOD","CSCOD","CSNH3N","JSNH3N","JSTP","CSTP"};
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
List<PollutantConcentrationDto> dtodsdh = new ArrayList<>();
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtodsdh.add(dto);
}
result.put("DSDH", dtodsdh);
for (String string : strings) {
List<PollutantConcentrationDto> dtos1 = new ArrayList<>();
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
result.put(string, dtos1);
}
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
//查询吨水电耗
String device=comprehensiveSupervisionMapper.selectDeviceName(factoryId);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//吨水电耗
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));
for (String string : strings) {
MetricVo metricVo = comprehensiveSupervisionMapper.selectMetric(string,factoryId);
List<PollutantConcentrationDto> dtos1 = new ArrayList<>();
if(metricVo==null){
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
result.put(string, dtos1);
}else {
StringBuilder str = new StringBuilder();
str.append("'" + metricVo.getId() + "'");
String sql1 = "select avg(cast(v as float8)) as v,substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8) as time\n" +
" FROM " + tableName + "\n" +
"where nm in (" + str.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='" + months.get(11) + "'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='" + months.get(0) + "'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> monitorList = null;
try {
monitorList = pgDb.queryForList(sql1);
Map<String, Object> monitorMap = new HashMap<>();
if (monitorList.size() > 0) {
for (Map<String, Object> map : monitorList) {
monitorMap.put(map.get("time").toString(),this.getValue(Double.parseDouble(map.get("v").toString())).toString());
}
for (String month : months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
if(monitorMap.get(month)!=null){
dto.setV(monitorMap.get(month).toString());
}
dto.setTime(month);
dtos1.add(dto);
}
}else{
for (String month :months) {
PollutantConcentrationDto dto = new PollutantConcentrationDto();
dto.setTime(month);
dtos1.add(dto);
}
}
result.put(string, dtos1);
} catch (DataAccessException e) {
e.printStackTrace();
}
}
}
return result;
}
@Override
public Map<String, Object> tonOfWaterAndPollutantRemovalRate(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
//查询近12个月的数据
List<String> months=this.getTwelve(time);
Map<String, Object> result = Maps.newHashMap();
String factoryId = anysisParamsVO.getFactoryId();
if(anysisParamsVO.getFactoryId()==null||"".equals(anysisParamsVO.getFactoryId())){
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));//吨水电耗
result.put("COD",this.getRemovalRate("","",null,null,months,factoryId));
result.put("NH3N",this.getRemovalRate("","",null,null,months,factoryId));
result.put("TP",this.getRemovalRate("","",null,null,months,factoryId));
return result;
}else{
factoryId = anysisParamsVO.getFactoryId();
}
String device=comprehensiveSupervisionMapper.selectDeviceName(factoryId);
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//吨水电耗
result.put("DSDH",this.tonOfWaterTrend(anysisParamsVO).get("data"));
//计算去除率
List<TonOfWaterTrendDto> analyVos=this.getRemovalRate("JSCOD","CSCOD",pgDb,tableName,months,factoryId);
result.put("COD",analyVos);
List<TonOfWaterTrendDto> analyVos1=this.getRemovalRate("JSNH3N","CSNH3N",pgDb,tableName,months,factoryId);
result.put("NH3N",analyVos1);
List<TonOfWaterTrendDto> analyVos2=this.getRemovalRate("JSTP","CSTP",pgDb,tableName,months,factoryId);
result.put("TP",analyVos2);
return result;
}
private List<TonOfWaterTrendDto> getRemovalRate(String jscod, String cscod, JdbcTemplate pgDb, String tableName, List<String> months, String factoryId) {
List<TonOfWaterTrendDto> dtos=new ArrayList<>();
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric(jscod,factoryId);
if(metricVo1==null){
for (String month :months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
dto.setTime(month);
dtos.add(dto);
}
return dtos;
}
StringBuilder str1 = new StringBuilder();
MetricVo metricVo2 = comprehensiveSupervisionMapper.selectMetric(cscod,factoryId);
if(metricVo2==null){
str1.append("'" + metricVo1.getId() + "'");
}else{
str1.append("'" + metricVo1.getId() + "'"+","+"'" + metricVo2.getId() + "'");
}
String sql="select avg(cast(v as float8)) as v,nm,\n" +
"substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8) as time\n" +
" FROM " + tableName + "\n" +
"where nm in (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='"+months.get(11)+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='"+months.get(0)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8),nm";
List<Map<String, Object>> monitorList1 = null;
List<AlarmDto> alarmDtos=new ArrayList<>();
try {
monitorList1 = pgDb.queryForList(sql);
if (monitorList1.size()>0){
for (Map<String, Object> map : monitorList1) {
AlarmDto dto=new AlarmDto();
dto.setName(map.get("nm").toString());
dto.setTime(map.get("time").toString());
dto.setV(map.get("v").toString());
alarmDtos.add(dto);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//封装数据
Map<String,List<AlarmDto>> map=alarmDtos.stream().collect(Collectors.groupingBy(AlarmDto::getTime));
List<String> stringList=map.keySet().stream().collect(Collectors.toList());
Collections.sort(stringList);
Map<String, Object> qclMap = new HashMap<>();
for (String s : stringList) {
List<AlarmDto> dtoList=map.get(s);
Double jsV=0d;
Double csV=0d;
for (AlarmDto dto : dtoList) {
if (dto.getName().equals(metricVo1.getId())){
jsV=Double.valueOf(dto.getV());
}
if (dto.getName().equals(metricVo2.getId())){
csV=Double.valueOf(dto.getV());
}
}
TonOfWaterTrendDto vo1=new TonOfWaterTrendDto();
vo1.setTime(s);
//污染物去除率=(进水指标(mg/L)-出水指标(mg/L))/进水指标(mg/L)*100%。
double result=(double)(Math.round((jsV-csV)*100/jsV)/100.0);
vo1.setV(this.getValue(result)+"");
qclMap.put(s,this.getValue(result)+"");
}
for (String month : months) {
TonOfWaterTrendDto dto=new TonOfWaterTrendDto();
if(qclMap.get(month)!=null){
dto.setV(qclMap.get(month).toString());
}
dto.setTime(month);
dtos.add(dto);
}
return dtos;
}
private List<String> getTwelve(String time) {
List<String> list=new ArrayList<>();
for (int i=12;i>=1;i--){
list.add(this.getMonthBytime(-i,time));
}
return list;
}
private Map<String, Object> getLower(String factoryId){
//查询历史最低吨水电耗
Map<String, Object> result = Maps.newHashMap();
//查询所有月份的出水流量 v time
List<AlarmDto> csList = comprehensiveSupervisionMapper.selectAllClsl(factoryId);
//查询所有月份的耗电量
List<AlarmDto> dhList=comprehensiveSupervisionMapper.selectAllDh(factoryId);
Map<String,String> csMap=csList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
Map<String,String> dhMap=dhList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
List<String> list=csMap.keySet().stream().collect(Collectors.toList());
Double mindsdh=null;
String mintime=new String();
for (String s : list) {
//查询当前吨水电耗
String cs=csMap.get(s);
if (dhMap.get(s)!=null){
String dh=dhMap.get(s);
Double dsdh=Double.parseDouble(dh)/Double.parseDouble(cs);
if (mindsdh==null){
mindsdh=dsdh;
mintime=s;
}else {
if (mindsdh>dsdh){
mindsdh=dsdh;
mintime=s;
}
}
}
}
result.put("mindsdh",mindsdh);
result.put("mintime",mintime);
return result;
}
private Double getValue(Double d) {
BigDecimal two = new BigDecimal(d);
double three = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
return three;
}
private String getMonthBytime(int i,String time) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM");
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(format.parse(time));
} catch (ParseException e) {
e.printStackTrace();
}
calendar.add(Calendar.MONTH, i);
return format.format(calendar.getTime());
}
}
*/
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!