95904530 康伟

Merge remote-tracking branch 'origin/master'

2 个父辈 bcabcf16 6946f063
正在显示 29 个修改的文件 包含 2780 行增加50 行删除
......@@ -120,8 +120,8 @@ public class CommandCentreServiceImpl implements ICommandCentreService {
@Override
public DepartDrugResult getYhTotal(String month) {
// String monthTb = getTbMonth(month);//同比时间
// String monthHb = getHbMonth(month);//环比时间
String monthTb = getTbMonth(month);//同比时间
String monthHb = getHbMonth(month);//环比时间
// String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";
// String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";
// String departId = "1519193830953553920,1519200041706954752,1816759403152666624,1818214145808531456,1818214519948836864," +
......@@ -141,57 +141,12 @@ public class CommandCentreServiceImpl implements ICommandCentreService {
departDrugResult.setZyh("0");
departDrugResult.setZyhHb("0");
departDrugResult.setZyhTb("0");
DepartDrugDataVO departDrugDataVO1 = new DepartDrugDataVO();
departDrugDataVO1.setDepartId("1519193830953553920");
departDrugDataVO1.setDepartName("杨村镇污水处理厂");
departDrugDataVO1.setYjdh("0");
departDrugDataVO1.setYjdhHb("0");
departDrugDataVO1.setYjdhTb("0");
DepartDrugDataVO departDrugDataVO2 = new DepartDrugDataVO();
departDrugDataVO2.setDepartId("1519200041706954752");
departDrugDataVO2.setDepartName("秦栏镇污水处理厂");
departDrugDataVO2.setYjdh("0");
departDrugDataVO2.setYjdhHb("0");
departDrugDataVO2.setYjdhTb("0");
List<DepartDrugDataVO> drugList = new ArrayList<>();
// drugList = fReportItemvMapper.getYhList(month,monthTb,monthHb);
drugList.add(departDrugDataVO1);
drugList.add(departDrugDataVO2);
drugList = fReportItemvMapper.getYhList(month,monthTb,monthHb);
departDrugResult.setDrugList(drugList);
return departDrugResult;
}
/***
* 根据String itemCode, String reportId 查询reitId字段
* @param reportItemvParam
* @return
*/
/* private String getReitId( ReportItemvParam reportItemvParam){
List<FReportItem> reitIdList = reportItemMapper.getItemInfoByItemCode(reportItemvParam.getReportItemCode(),reportItemvParam.getReportId());
String reitId = null;
if(reitIdList != null && !reitIdList.isEmpty()){
reitId = reitIdList.get(0).getId();
}
return reitId;
}*/
/* private String getReitId( String itemCode, String reportId){
JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtils.getBean("master");
String sql = "select id from f_report_item where report_id = '"+reportId+"' and required='1' and item_code = '"+itemCode+"'";
// String sql = "SELECT column_name FROM table_name WHERE condition";
List<String> reitIdList = jdbcTemplate.query(sql, (rs, rowNum) -> rs.getString("id"));
//该方法会返回查询结果集中的第一条记录对应的指定字段值。
//String sql = "SELECT column_name FROM table_name WHERE condition";
//String reitId = jdbcTemplate.queryForObject(sql, String.class);
System.out.println(reitIdList+"----reitIdList");
String reitId = null;
if(reitIdList != null && !reitIdList.isEmpty()){
reitId = reitIdList.get(0);
}
return reitId;
}*/
/**
* 同比
* @param month
......
......@@ -142,7 +142,7 @@
FROM
report_electric_cost
WHERE
month BETWEEN '2024-01' AND '2024-09'
month BETWEEN '2024-01' AND '2024-10'
GROUP BY month
</select>
......@@ -153,7 +153,8 @@
</select>
<select id="getYhList" resultType="com.skua.modules.report.vo.DepartDrugDataVO">
select * from sys_depart where depart_type = '1'
select d.id AS depart_id,d.depart_name,'0' as yjdh,'0' as yjdh_tb,'0' as yjdh_hb from sys_depart d
where d.depart_type = '1'
</select>
</mapper>
......
package com.skua.modules.equipment.controller;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.modules.equipment.dto.DrugDto;
import com.skua.modules.equipment.service.IDrugConsumptionAnalysisService;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@Slf4j
@Api(tags = "药耗分析")
@RestController
@RequestMapping("/drug/consumption/analysis")
public class DrugConsumptionAnalysisController {
@Autowired
private IDrugConsumptionAnalysisService drugConsumptionAnalysisService;
@AutoLog(value = "数据展示")
@ApiOperation(value = "数据展示", notes = "数据展示")
@RequestMapping(value = "/data/display", method = RequestMethod.GET)
public Result<Map<String, Object>> dataDisplay(String time) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.DataDisplay(time);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "总药耗趋势")
@ApiOperation(value = "总药耗趋势", notes = "总药耗趋势")
@RequestMapping(value = "/drug/consumption/trend", method = RequestMethod.GET)
public Result<Map<String, Object>> drugConsumptionTrend(String time) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.drugConsumptionTrend(time);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "吨水药耗趋势")
@ApiOperation(value = "吨水药耗趋势", notes = "吨水药耗趋势")
@RequestMapping(value = "/consumption/ton/of/water/trend", method = RequestMethod.GET)
public Result<Map<String, Object>> consumptionTonOfWaterTrend(String time) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.consumptionTonOfWaterTrend(time);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "药剂占比统计 type 1.按明细 2.按类型")
@ApiOperation(value = "药剂占比统计 type 1.按明细 2.按类型", notes = "药剂占比统计 type 1.按明细 2.按类型")
@RequestMapping(value = "/proportion/statistics", method = RequestMethod.GET)
public Result<Map<String, Object>> proportionStatistics(String time,Integer type) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.proportionStatistics(time,type);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "药剂占比统计列表 type 1.按明细 2.按类型")
@ApiOperation(value = "药剂占比统计列表 type 1.按明细 2.按类型", notes = "药剂占比统计列表 type 1.按明细 2.按类型")
@RequestMapping(value = "/proportion/statistics/detail", method = RequestMethod.GET)
public Result<Map<String, Object>> proportionStatisticsDetail(String time,Integer type) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.proportionStatisticsDetail(time,type);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "相关性分析 type 1.絮凝剂 2.碳源 3.除磷剂")
@ApiOperation(value = "相关性分析 type 1.絮凝剂 2.碳源 3.除磷剂", notes = "相关性分析 type 1.絮凝剂 2.碳源 3.除磷剂")
@RequestMapping(value = "/correlation/analysis", method = RequestMethod.GET)
public Result<Map<String, Object>> correlationAnalysis(String time,Integer type) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.correlationAnalysis(time,type);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "总药耗趋势详情")
@ApiOperation(value = "总药耗趋势详情", notes = "总药耗趋势详情")
@RequestMapping(value = "/drug/consumption/trend/detail", method = RequestMethod.GET)
public Result<Map<String, Object>> drugConsumptionTrendDetail(DrugDto drugDto) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.drugConsumptionTrendDetail(drugDto);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "相关性分析药剂明细 type 1.絮凝剂 2.碳源 3.除磷剂")
@ApiOperation(value = "相关性分析药剂明细 type 1.絮凝剂 2.碳源 3.除磷剂", notes = "相关性分析药剂明细 type 1.絮凝剂 2.碳源 3.除磷剂")
@RequestMapping(value = "/correlation/analysis/detail", method = RequestMethod.GET)
public Result<Map<String, Object>> correlationAnalysisDetail(String time,Integer type) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = drugConsumptionAnalysisService.correlationAnalysisDetail(time,type);
result.setResult(data);
result.setSuccess(true);
return result;
}
}
package com.skua.modules.equipment.controller;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.modules.equipment.service.IPowerConsumptionAnalysisService;
import com.skua.modules.equipment.vo.AnysisParamsVO;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@Slf4j
@Api(tags = "电耗分析")
@RestController
@RequestMapping("/power/consumption/analysis")
public class PowerConsumptionAnalysisController {
@Autowired
private IPowerConsumptionAnalysisService powerConsumptionAnalysisService;
@AutoLog(value = "数据展示")
@ApiOperation(value = "数据展示", notes = "数据展示")
@RequestMapping(value = "/data/display", method = RequestMethod.GET)
public Result<Map<String, Object>> dataDisplay(AnysisParamsVO anysisParamsVO) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.dataDisplay(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "电耗趋势")
@ApiOperation(value = "电耗趋势", notes = "电耗趋势")
@RequestMapping(value = "/power/consumption/trend", method = RequestMethod.GET)
public Result<Map<String, Object>> powerConsumptionTrend(AnysisParamsVO anysisParamsVO) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.powerConsumptionTrend(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "吨水电耗趋势")
@ApiOperation(value = "吨水电耗趋势", notes = "吨水电耗趋势")
@RequestMapping(value = "/ton/of/water/trend", method = RequestMethod.GET)
public Result<Map<String, Object>> tonOfWaterTrend(AnysisParamsVO anysisParamsVO) {
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.tonOfWaterTrend(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "吨水电耗与负荷率对比")
@ApiOperation(value = "吨水电耗与负荷率对比", notes = "吨水电耗与负荷率对比")
@RequestMapping(value = "/tonOfWaterAndLoadRate", method = RequestMethod.GET)
public Result<Map<String, Object>> tonOfWaterAndLoadRate(AnysisParamsVO anysisParamsVO) throws Exception{
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.tonOfWaterAndLoadRate(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "吨水电耗与污染物浓度")
@ApiOperation(value = "吨水电耗与污染物浓度", notes = "吨水电耗与污染物浓度")
@RequestMapping(value = "/tonOfWaterAndPollutantConcentration", method = RequestMethod.GET)
public Result<Map<String, Object>> tonOfWaterAndPollutantConcentration(AnysisParamsVO anysisParamsVO) throws Exception{
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.tonOfWaterAndPollutantConcentration(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
@AutoLog(value = "吨水电耗与污染物去除率对比")
@ApiOperation(value = "吨水电耗与污染物去除率对比", notes = "吨水电耗与污染物去除率对比")
@RequestMapping(value = "/tonOfWaterAndPollutantRemovalRate", method = RequestMethod.GET)
public Result<Map<String, Object>> tonOfWaterAndPollutantRemovalRate(AnysisParamsVO anysisParamsVO) throws Exception{
Result<Map<String, Object>> result = new Result<>();
Map<String, Object> data = powerConsumptionAnalysisService.tonOfWaterAndPollutantRemovalRate(anysisParamsVO);
result.setResult(data);
result.setSuccess(true);
return result;
}
}
package com.skua.modules.equipment.dto;
import lombok.Data;
/**
* 预警统计
*/
@Data
public class AlarmCountDto {
String dateStr;
int count;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class AlarmDto {
@ApiModelProperty("超标名称")
private String name;
@ApiModelProperty("超标值")
private String v;
@ApiModelProperty("超标时间")
private String time;
@ApiModelProperty("上限")
private String upperLimit;
@ApiModelProperty("下限")
private String lowerLimit;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class ConsumptionDto {
private String time;
private String dh;
private String dsdh;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class DrugConsumptionDto {
private String time;
private String yh;
private String dsyh;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class DrugConsumptionTrendDto {
private String time;
private Double zyh;
private Double tbzyh;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class DrugDto {
@ApiModelProperty("1.日 2.月 .3自定义")
private Integer type;
@ApiModelProperty("开始时间")
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class PollutantConcentrationDto {
private String time;
private String v;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class QualityChangeDto {
private String dateStr;
private String v;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportItemCustomDetailDto {
@ApiModelProperty(value = "指标编码")
private String itemCode;
@ApiModelProperty(value = "指标名称")
private String itemName;
@ApiModelProperty("吨水耗量")
private Double dshl;
@ApiModelProperty("吨水耗量同比")
private Double dshltb;
@ApiModelProperty("吨水耗量环比")
private Double dshlhb;
@ApiModelProperty("总耗量")
private Double zhl;
@ApiModelProperty("总耗量同比")
private Double zhltb;
@ApiModelProperty("总耗量环比")
private Double zhlhb;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportItemCustomDto {
private String id;
@ApiModelProperty(value = "父ID")
private String pid;
@ApiModelProperty(value = "节点路径")
private String treePath;
@ApiModelProperty(value = "药剂类型")
private String itemType;
@ApiModelProperty(value = "指标编码")
private String itemCode;
@ApiModelProperty(value = "指标名称")
private String itemName;
private String v;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportItemCustomValueDetailDto {
@ApiModelProperty(value = "药剂类型")
private String itemType;
@ApiModelProperty(value = "指标编码")
private String itemCode;
@ApiModelProperty(value = "指标名称")
private String itemName;
@ApiModelProperty("时间")
private String time;
@ApiModelProperty("总药耗")
private String zyh;
@ApiModelProperty("吨水药耗")
private String dsyh;
}
package com.skua.modules.equipment.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportItemCustomValueDto {
@ApiModelProperty(value = "药剂类型")
private String itemType;
@ApiModelProperty(value = "指标编码")
private String itemCode;
@ApiModelProperty(value = "指标名称")
private String itemName;
@ApiModelProperty("时间")
private String time;
@ApiModelProperty("数量")
private String v;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class TonOfWaterAndLoadRateDto {
private String time;
private String dsdh;
private String fhl;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class TonOfWaterTrendDto {
private String time;
private String v;
}
package com.skua.modules.equipment.dto;
import lombok.Data;
@Data
public class powerConsumptionTrendDto {
private String time;
private String zdh;
private String tbzdh;
}
package com.skua.modules.equipment.mapper;
import com.skua.modules.equipment.dto.*;
import com.skua.modules.equipment.vo.AlarmVo;
import com.skua.modules.equipment.vo.MetricVo;
import com.skua.modules.equipment.vo.StructDictVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface ComprehensiveSupervisionMapper {
String selectDeviceName(@Param("factoryId") String factoryId);
MetricVo selectMetric(@Param("metricUidTag") String metricUidTag,@Param("factoryId") String factoryId);
String selectSJGM(@Param("factoryId") String factoryId);
List<AlarmVo> selectAlarms();
List<AlarmVo> selectInAlarms();
List<AlarmDto> selectDhByMonths(@Param("list") List<String> months, @Param("factoryId") String factoryId);
List<AlarmDto> selectAllDh(@Param("factoryId") String factoryId);
List<AlarmDto> selectDhByStartAndEnd(@Param("startTime") String startTime, @Param("endTime") String endTime,@Param("factoryId") String factoryId);
AlarmDto selectDhByYear(String year);
List<String> selectDataIdsByMonth(String month);
List<ReportItemCustomDto> selectItemCustom();
List<ReportItemCustomDto> selectValueByDataId(@Param("list") List<String> dataIds);
ReportItemCustomDto selectVByDataIdAndPid(@Param("list") List<String> dataIds, @Param("id") String id);
String selectZyhByDataIds(@Param("list") List<String> dataIds);
List<AlarmDto> selectAllYh();
List<AlarmDto> selectYhByStartTimeAndEndTime(@Param("startTime") String startTime, @Param("endTime") String endTime);
List<ReportItemCustomValueDto> selectItemDetail(@Param("list") List<String> dataIds);
String selectXnjByDataIds(@Param("list") List<String> dataIds);
String selectGwnByTime(String s);
String selectTyByDataIds(@Param("list")List<String> dataIds);
String selectBodByTime(String s);
String selectTnByTime(String s);
String selectClByDataIds(@Param("list")List<String> dataIds);
List<String> selectDataIdsByDay(String seven);
List<ReportItemCustomValueDetailDto> selectVByDay(@Param("list") List<String> dataIds);
List<ReportItemCustomValueDetailDto> selectVByMonth(@Param("list") List<String> dataIds);
List<ReportItemCustomValueDto> selectDetailVByMonth(@Param("list")List<String> dataIds, @Param("id") String s);
List<StructDictVo> structDictList();
List<StructDictVo> metricList(String id);
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);
/**
* 查询某年 每日警告的次数列表
*
* @param year
* @returnt
*/
List<AlarmCountDto> selectCountAlarmByYearForDay(@Param("year") String year, @Param("departIds") List<String> departIds);
/**
* 根据时间查询水质变化
*
* @return
*/
List<QualityChangeDto> qualityChange(List<String> days, String code, @Param("departIds") List<String> departIds);
/**
* 获取月度处理水量
* @param list
* @param factoryId
* @return
*/
List<Map<String, Object>> selectClslByMonths(List<String> list, String factoryId);
/**
* 获取所有月份处理水量
* @param factoryId
* @return
*/
List<AlarmDto> selectAllClsl(String factoryId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skua.modules.equipment.mapper.ComprehensiveSupervisionMapper">
<select id="selectDeviceName" resultType="java.lang.String">
select device_id from sys_factory_device
where depart_id = #{factoryId}
limit 1
</select>
<select id="selectMetric" resultType="com.skua.modules.equipment.vo.MetricVo">
select id,metric_uid_tag metricUidTag from sys_monitor_metric_info
where metric_uid_tag=#{metricUidTag} and depart_id = #{factoryId}
limit 1
</select>
<select id="selectSJGM" resultType="java.lang.String">
select pro_scale from sys_factory_info where depart_id = #{factoryId}
limit 1
</select>
<select id="selectAlarms" resultType="com.skua.modules.equipment.vo.AlarmVo">
SELECT alarm_param_code alarmParamCode,alarm_param_upper_limit upperLimit,alarm_param_lower_limit lowerLimit FROM `alarm_param_standard_config`
where alarm_level_standard_id =(select out_level from sys_factory_info limit 1)
and del_flag=1
</select>
<select id="selectInAlarms" resultType="com.skua.modules.equipment.vo.AlarmVo">
SELECT alarm_param_code alarmParamCode,alarm_param_upper_limit upperLimit,alarm_param_lower_limit lowerLimit FROM `alarm_param_standard_config`
where alarm_level_standard_id =(select in_level from sys_factory_info limit 1)
and del_flag=1
</select>
<select id="selectDhByMonths" resultType="com.skua.modules.equipment.dto.AlarmDto">
select sum(item_value) 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='dhkwh64bc'
and a.depart_id = #{factoryId}
<if test="list!=null and list.size>0">
and DATE_FORMAT(data_time, '%Y-%m') in
<foreach collection="list" item="list" separator="," close=")" open="(">
#{list}
</foreach>
</if>
group by DATE_FORMAT(data_time, '%Y-%m')
</select>
<select id="selectAllDh" resultType="com.skua.modules.equipment.dto.AlarmDto">
select sum(item_value) 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 = 'dhkwh64bc'
and a.depart_id = #{factoryId}
group by DATE_FORMAT(data_time, '%Y-%m')
</select>
<select id="selectDhByStartAndEnd" resultType="com.skua.modules.equipment.dto.AlarmDto">
select sum(item_value) 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='dhkwh64bc'
and a.depart_id = #{factoryId}
<if test="startTime!=null">
and DATE_FORMAT(data_time, '%Y-%m')>=#{startTime}
</if>
<if test="endTime!=null">
and DATE_FORMAT(data_time, '%Y-%m') &lt;=#{endTime}
</if>
group by DATE_FORMAT(data_time, '%Y-%m')
</select>
<select id="selectDhByYear" resultType="com.skua.modules.equipment.dto.AlarmDto">
select sum(item_value) as v from f_report_itemv a
left join f_report_item b on b.id=a.reit_id
where b.item_code='dhkwh64bc' and SUBSTRING(data_time,1,4)='2022'
</select>
<select id="selectDataIdsByMonth" resultType="java.lang.String">
SELECT DISTINCT data_id FROM `f_report_itemv` where SUBSTRING(data_time,1,7)=#{month}
</select>
<select id="selectItemCustom" resultType="com.skua.modules.equipment.dto.ReportItemCustomDto">
select id,pid,tree_path treePath,item_type itemType,item_name itemName,item_code itemCode
from f_report_item_custom where pid in (
SELECT id FROM `f_report_item_custom`
where pid is null or pid='')
</select>
<select id="selectValueByDataId" resultType="com.skua.modules.equipment.dto.ReportItemCustomDto">
SELECT b.tree_path treePath,sum(a.item_value) v FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
GROUP BY b.pid
</select>
<select id="selectVByDataIdAndPid" resultType="com.skua.modules.equipment.dto.ReportItemCustomDto">
SELECT b.item_type itemType,item_code itemCode,b.item_name itemName,sum(a.item_value) v FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
<where>
<if test="list!=null and list.size>0">
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</if>
<if test="id!=null">
and b.tree_path LIKE CONCAT(CONCAT('%', #{id}),'%')
</if>
</where>
</select>
<select id="selectZyhByDataIds" resultType="java.lang.String">
select sum(a.item_value) from `f_report_item_yyrb_ext`a
where a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="selectAllYh" resultType="com.skua.modules.equipment.dto.AlarmDto">
SELECT sum(a.item_value) v,SUBSTRING(data_time,1,7) time from f_report_item_yyrb_ext a
LEFT JOIN (select DISTINCT data_id,data_time from f_report_itemv) b on a.data_id=b.data_id
WHERE data_time is not null
GROUP BY SUBSTRING(data_time,1,7)
</select>
<select id="selectYhByStartTimeAndEndTime" resultType="com.skua.modules.equipment.dto.AlarmDto">
SELECT sum(a.item_value) v,SUBSTRING(data_time,1,7) time from f_report_item_yyrb_ext a
LEFT JOIN (select DISTINCT data_id,data_time from f_report_itemv) b on a.data_id=b.data_id
WHERE data_time is not null
<if test="startTime!=null">
and SUBSTRING(data_time,1,7)>=#{startTime}
</if>
<if test="endTime!=null">
and SUBSTRING(data_time,1,7) &lt;=#{endTime}
</if>
GROUP BY SUBSTRING(data_time,1,7)
</select>
<select id="selectItemDetail" resultType="com.skua.modules.equipment.dto.ReportItemCustomValueDto">
SELECT b.item_type itemType,item_code itemCode,b.item_name itemName,sum(a.item_value) v FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
group by a.item_name
</select>
<select id="selectXnjByDataIds" resultType="java.lang.String">
SELECT sum(a.item_value) FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.item_tree_path like '%1542412281596121088%'
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="selectGwnByTime" resultType="java.lang.String">
select sum(item_value) from f_report_itemv where reit_id='e279955361bb3e452ebd3a0f985ccc78'
and SUBSTRING(data_time,1,7)=#{s}
</select>
<select id="selectTyByDataIds" resultType="java.lang.String">
SELECT sum(a.item_value) FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.item_tree_path like '%1355031171188244480%'
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="selectBodByTime" resultType="java.lang.String">
select avg(item_value) from f_report_itemv where reit_id='99fcc640b6afc74749d1929ec0f1025f'
and SUBSTRING(data_time,1,7)=#{s}
</select>
<select id="selectTnByTime" resultType="java.lang.String">
select avg(item_value) from f_report_itemv where reit_id='e33c961b7131f980e369dba9b2decfc9'
and SUBSTRING(data_time,1,7)=#{s}
</select>
<select id="selectClByDataIds" resultType="java.lang.String">
SELECT sum(a.item_value) FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.item_tree_path like '%1354978313802571776%'
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="selectDataIdsByDay" resultType="java.lang.String">
SELECT DISTINCT data_id FROM `f_report_itemv` where SUBSTRING(data_time,1,10)=#{month}
</select>
<select id="selectVByDay" resultType="com.skua.modules.equipment.dto.ReportItemCustomValueDetailDto">
select a.item_type itemType,b.item_code itemCode,b.item_name itemName,a.item_value zyh
FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="selectVByMonth" resultType="com.skua.modules.equipment.dto.ReportItemCustomValueDetailDto">
select a.item_type itemType,b.item_code itemCode,b.item_name itemName,sum(a.item_value) zyh
FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
group by a.item_name
</select>
<select id="selectDetailVByMonth"
resultType="com.skua.modules.equipment.dto.ReportItemCustomValueDto">
select a.item_type itemType,b.item_code itemCode,b.item_name itemName,a.item_value v
FROM `f_report_item_yyrb_ext`a
LEFT JOIN f_report_item_custom b on a.item_name=b.id
where b.item_name is not null and a.item_tree_path LIKE CONCAT(CONCAT('%', #{id}),'%')
and a.data_id in
<foreach collection="list" open="(" close=")" separator="," item="list">
#{list}
</foreach>
</select>
<select id="structDictList" resultType="com.skua.modules.equipment.vo.StructDictVo">
select id,struct_name name from sys_struct_dict where del_flag=1
</select>
<select id="metricList" resultType="com.skua.modules.equipment.vo.StructDictVo">
select id,metric_name name from sys_monitor_metric_info
where struct_code=#{id} and del_flag=1 and metric_type=0
</select>
<select id="selectMetricNameById" resultType="java.lang.String">
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
from alarm_record_history
where alarm_rule_type = 1
AND create_dept in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
and DATE_FORMAT(create_time, '%Y') = #{year}
group by DATE_FORMAT(create_time, '%Y-%m-%d')
</select>
<select id="qualityChange" resultType="com.skua.modules.equipment.dto.QualityChangeDto">
SELECT
dates.dateStr,
FORMAT(IFNULL(AVG(b.v), 0),2) AS v
FROM (
<foreach collection="days" item="day" separator="UNION ALL">
SELECT #{day} as dateStr
</foreach>
) AS dates
LEFT JOIN
(
SELECT
v.item_value AS v,
DATE_FORMAT( v.data_time, '%Y-%m' ) AS dateStr
FROM
f_report_item i
LEFT JOIN f_report_itemv v ON i.id = v.reit_id
WHERE
i.report_id = '5b542809fa0821a5e0ec6c3b378fbb23'
AND i.item_code = #{code}
AND v.depart_id in
<foreach collection="departIds" item="departId" open="(" separator="," close=")">
#{departId}
</foreach>
) as b on b.dateStr = dates.dateStr
GROUP BY dates.dateStr
ORDER BY dates.dateStr
</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
left join f_report_item b on b.id=a.reit_id
where b.item_code='csl503c'
and a.depart_id = #{factoryId}
<if test="list!=null and list.size>0">
and DATE_FORMAT(data_time, '%Y-%m') in
<foreach collection="list" item="list" separator="," close=")" open="(">
#{list}
</foreach>
</if>
group by DATE_FORMAT(data_time, '%Y-%m')
</select>
<select id="selectAllClsl" resultType="com.skua.modules.equipment.dto.AlarmDto">
select sum(item_value) 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'
and a.depart_id = #{factoryId}
group by DATE_FORMAT(data_time, '%Y-%m')
</select>
</mapper>
\ No newline at end of file
package com.skua.modules.equipment.service;
import com.skua.modules.equipment.dto.DrugDto;
import java.util.Map;
public interface IDrugConsumptionAnalysisService {
Map<String, Object> DataDisplay(String time);
Map<String, Object> drugConsumptionTrend(String time);
Map<String, Object> consumptionTonOfWaterTrend(String time);
Map<String, Object> proportionStatistics(String time, Integer type);
Map<String, Object> proportionStatisticsDetail(String time, Integer type);
Map<String, Object> correlationAnalysis(String time, Integer type);
Map<String, Object> drugConsumptionTrendDetail(DrugDto drugDto);
Map<String, Object> correlationAnalysisDetail(String time, Integer type);
}
package com.skua.modules.equipment.service;
import com.skua.modules.equipment.vo.AnysisParamsVO;
import java.util.Map;
public interface IPowerConsumptionAnalysisService {
/**
* 数据展示
* @param anysisParamsVO
* @return
*/
Map<String, Object> dataDisplay(AnysisParamsVO anysisParamsVO);
/**
* 电耗趋势
* @param anysisParamsVO
* @return
*/
Map<String, Object> powerConsumptionTrend(AnysisParamsVO anysisParamsVO);
/**
* 吨水电耗趋势
* @param anysisParamsVO
* @return
*/
Map<String, Object> tonOfWaterTrend(AnysisParamsVO anysisParamsVO);
/**
* 吨水电耗和负荷率对比
* @param anysisParamsVO
* @return
*/
Map<String, Object> tonOfWaterAndLoadRate(AnysisParamsVO anysisParamsVO) throws Exception;
/**
* 吨水电耗与污染物浓度
* @param anysisParamsVO
* @return
*/
Map<String, Object> tonOfWaterAndPollutantConcentration(AnysisParamsVO anysisParamsVO);
/**
* 吨水电耗与污染物去除率对比
* @param anysisParamsVO
* @return
*/
Map<String, Object> tonOfWaterAndPollutantRemovalRate(AnysisParamsVO anysisParamsVO);
}
package com.skua.modules.equipment.service.impl;
import com.google.common.collect.Maps;
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.IDrugConsumptionAnalysisService;
import com.skua.modules.equipment.vo.MetricVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class DrugConsumptionAnalusisServiceImpl implements IDrugConsumptionAnalysisService {
@Autowired
private ComprehensiveSupervisionMapper comprehensiveSupervisionMapper;
@Override
public Map<String, Object> DataDisplay(String time) {
Map<String, Object> result =Maps.newHashMap();
//总药耗
//查询当月填报数据的data_id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(time);
if (dataIds.size()>0){
String zyh=comprehensiveSupervisionMapper.selectZyhByDataIds(dataIds);
if (zyh!=null) {
result.put("zyh", this.getValue(Double.parseDouble(zyh)));
}
}
//同比去年总药耗
String lastYear=this.getMonthBytime(-12,time);
List<String> lastYearDataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(lastYear);
if (lastYearDataIds.size()>0){
String tbqnzyh=comprehensiveSupervisionMapper.selectZyhByDataIds(lastYearDataIds);
if (tbqnzyh!=null){
result.put("tbqnzyh", this.getValue(Double.parseDouble(tbqnzyh)));
if (result.get("zyh")!=null){
Double zyh=Double.parseDouble(result.get("zyh")+"");
Double tbqnzyh1=Double.parseDouble(tbqnzyh);
result.put("tbqnzyhsl",this.getValue(zyh-tbqnzyh1));
result.put("tbqnzyhbl",this.getValue(((zyh-tbqnzyh1)/tbqnzyh1)*100));
}
}
}else{
result.put("tbqnzyh", null);
result.put("tbqnzyhsl", null);
result.put("tbqnzyhbl", null);
}
//环比上月总药耗
String lastMonth=this.getMonthBytime(-1,time);
List<String> lastMonthDataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(lastYear);
if (lastMonthDataIds.size()>0){
String hbsyzyh=comprehensiveSupervisionMapper.selectZyhByDataIds(lastMonthDataIds);
if (hbsyzyh!=null){
result.put("hbsyzyh",hbsyzyh);
if (result.get("zyh")!=null){
Double zyh=Double.parseDouble(result.get("zyh")+"");
Double hbsyzyh1=Double.parseDouble(hbsyzyh);
result.put("hbsyzyhsl",this.getValue(zyh-hbsyzyh1));
result.put("hbsyzyhbl",this.getValue(((zyh-hbsyzyh1)/hbsyzyh1)*100));
}
}
}else{
result.put("hbsyzyh", null);
result.put("hbsyzyhsl", null);
result.put("hbsyzyhbl", null);
}
//目标吨水药耗
result.put("mbdsyh","0.65");
//吨水药耗
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+time+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> currList = null;
try {
currList=pgDb.queryForList(sql);
if (currList.size()>0){
//药耗量[kg] / 处理水量[吨]
if (result.get("zyh")!=null){
Double zyh=Double.parseDouble(result.get("zyh")+"");
Double csll=Double.parseDouble(currList.get(0).get("v")+"")/10000;
result.put("dsyh",this.getValue(zyh/csll));
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//同比去年吨水药耗
String sql2="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+lastYear+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> lastYearList = null;
try {
lastYearList=pgDb.queryForList(sql2);
if (lastYearList.size()>0){
//药耗量[kg] / 处理水量[吨]
if (result.get("tbqnzyh")!=null){
Double tbqnzyh=Double.parseDouble(result.get("tbqnzyh")+"");
Double csll=Double.parseDouble(lastYearList.get(0).get("v")+"")/10000;
Double tbqndsyh = 0.0;
if (Double.compare(csll, 0.0) != 0) {
tbqndsyh=this.getValue(tbqnzyh/csll);
}
result.put("tbqndsyh",tbqndsyh);
if (result.get("dsyh")!=null){
Double dsyh=Double.parseDouble(result.get("dsyh")+"");
result.put("tbqndsyhsl",this.getValue(dsyh-tbqndsyh));
if (Double.compare(tbqndsyh, 0.0) == 0) {
result.put("tbqndsyhbl", 0.0);
}else{
result.put("tbqndsyhbl",this.getValue((dsyh-tbqndsyh)/tbqndsyh*100));
}
}
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//环比上月吨水药耗
String sql3="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+lastMonth+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> lastMonthList = null;
try {
lastMonthList=pgDb.queryForList(sql3);
if (lastMonthList.size()>0){
if (result.get("hbsyzyh")!=null){
Double hbsyzyh=Double.parseDouble(result.get("hbsyzyh")+"");
Double csll=Double.parseDouble(lastMonthList.get(0).get("v")+"")/10000;
Double hbsydsyh = 0.0;
if (Double.compare(csll, 0.0) != 0) {
hbsydsyh=this.getValue(hbsyzyh/csll);
}
result.put("hbsydsyh",hbsydsyh);
if (result.get("dsyh")!=null){
Double dsyh=Double.parseDouble(result.get("dsyh")+"");
result.put("hbsydsyhsl",this.getValue(dsyh-hbsydsyh));
if (Double.compare(hbsydsyh, 0.0) == 0) {
result.put("hbsydsyhbl",0.0);
}else{
result.put("hbsydsyhbl",this.getValue((dsyh-hbsydsyh)/hbsydsyh*100));
}
}
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//历史最低吨水药耗
Map<String,Object> lowerMap=this.getLower(pgDb,tableName,str1);
if (lowerMap.get("mindsyh")!=null){
result.put("lszddsyh",lowerMap.get("mindsyh"));
result.put("lszddsyhyf",lowerMap.get("mintime"));
}
return result;
}
@Override
public Map<String, Object> drugConsumptionTrend(String time) {
Map<String, Object> result = Maps.newHashMap();
//查询当前时间往前推12个月的数据
String startTime=this.getMonthBytime(-12,time);
String endTime=this.getMonthBytime(-1,time);
//统计时间内的药耗
List<AlarmDto> currentList=comprehensiveSupervisionMapper.selectYhByStartTimeAndEndTime(startTime,endTime);
Map<String,String> currMap=currentList.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.selectYhByStartTimeAndEndTime(yesStartTime,yesEndTime);
Map<String,String> yesMap=yes.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
List<String> months=this.getTwelve(time);
//封装数据
List<DrugConsumptionTrendDto> dtos=new ArrayList<>();
for (String month : months) {
String yesmonth=this.getMonthBytime(-12,month);
DrugConsumptionTrendDto dto=new DrugConsumptionTrendDto();
dto.setTime(month);
if (currMap.get(month)!=null){
dto.setZyh(this.getValue(Double.parseDouble(currMap.get(month))));
}
if (yesMap.get(yesmonth)!=null){
dto.setTbzyh(this.getValue(Double.parseDouble(yesMap.get(yesmonth))));
}
dtos.add(dto);
}
result.put("data",dtos);
return result;
}
@Override
public Map<String, Object> consumptionTonOfWaterTrend(String time) {
Map<String, Object> result = Maps.newHashMap();
//查询当前时间往前推12个月的数据
String startTime=this.getMonthBytime(-12,time);
String endTime=this.getMonthBytime(-1,time);
//查询药耗
List<AlarmDto> currentList=comprehensiveSupervisionMapper.selectYhByStartTimeAndEndTime(startTime,endTime);
Map<String,String> currMap=currentList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='"+endTime+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='"+startTime+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> monitorList2 = null;
List<AlarmDto> CSList=new ArrayList<>();
try {
monitorList2=pgDb.queryForList(sql);
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);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
List<String> months=this.getTwelve(time);
List<Map<String,Object>> list=new ArrayList<>();
for (String month : months) {
//药耗量[kg] / 处理水量[吨]
Map<String,Object> map=new HashMap<>();
map.put("time",month);
if (csMap.get(month)!=null&&currMap.get(month)!=null){
Double cs=Double.parseDouble(csMap.get(month))/10000;
Double yh=Double.parseDouble(currMap.get(month));
map.put("v",this.getValue(yh/cs));
}else{
map.put("v",null);
}
list.add(map);
}
result.put("data",list);
return result;
}
@Override
public Map<String, Object> proportionStatistics(String time, Integer type) {
Map<String, Object> result = Maps.newHashMap();
//查询当月填报数据的data_id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(time);
if (type!=null&&type==1&&dataIds.size()>0){
//按药剂明细统计
List<ReportItemCustomValueDto> dtoList=comprehensiveSupervisionMapper.selectItemDetail(dataIds);
result.put("data",dtoList);
}else if (type!=null&&type==2&&dataIds.size()>0){
//按类型统计
//查询当前药耗类型
List<ReportItemCustomDto> customDtos=comprehensiveSupervisionMapper.selectItemCustom();
if (customDtos.size()>0){
List<ReportItemCustomValueDto> list=new ArrayList<>();
for (ReportItemCustomDto dto : customDtos) {
ReportItemCustomDto customDto=comprehensiveSupervisionMapper.selectVByDataIdAndPid(dataIds,dto.getId());
if (customDto!=null) {
ReportItemCustomValueDto valueDto = new ReportItemCustomValueDto();
valueDto.setItemType(dto.getItemType());
valueDto.setItemName(dto.getItemName());
valueDto.setItemCode(dto.getItemCode());
valueDto.setV(customDto.getV());
list.add(valueDto);
}
}
result.put("data",list);
}
}
return result;
}
@Override
public Map<String, Object> proportionStatisticsDetail(String time, Integer type) {
Map<String, Object> result = Maps.newHashMap();
//查询当月填报数据的data_id
List<String> currDataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(time);
//查询去年填报数据的data_id
List<String> yearDataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(this.getMonthBytime(-12,time));
//查询上月填报数据的data_id
List<String> monthDataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(this.getMonthBytime(-1,time));
if (type!=null&&type==1&&currDataIds.size()>0){
//按药剂明细统计
//查询当月药剂明细的数据
List<ReportItemCustomValueDto> dtoList=comprehensiveSupervisionMapper.selectItemDetail(currDataIds);
Map<String, ReportItemCustomValueDto> yearMap=new HashMap<>();
if (yearDataIds.size()>0) {
yearMap = comprehensiveSupervisionMapper.selectItemDetail(yearDataIds).stream()
.collect(Collectors.toMap(ReportItemCustomValueDto::getItemCode, a -> a, (k1, k2) -> k1));
}
Map<String, ReportItemCustomValueDto> monthMap=new HashMap<>();
if (monthDataIds.size()>0) {
monthMap = comprehensiveSupervisionMapper.selectItemDetail(monthDataIds).stream()
.collect(Collectors.toMap(ReportItemCustomValueDto::getItemCode, a -> a, (k1, k2) -> k1));
}
//查询出水流量
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql1="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+time+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
String sql2="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+this.getMonthBytime(-12,time)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
String sql3="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+this.getMonthBytime(-1,time)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> lastMonthList1 = null;
List<Map<String, Object>> lastMonthList2 = null;
List<Map<String, Object>> lastMonthList3 = null;
Double csll=0d;
Double yearcsll=0d;
Double monthcsll=0d;
try {
lastMonthList1 = pgDb.queryForList(sql1);
lastMonthList2 = pgDb.queryForList(sql2);
lastMonthList3 = pgDb.queryForList(sql3);
if (lastMonthList1.size()>0){
csll=Double.parseDouble(lastMonthList1.get(0).get("v")+"")/10000;
}
if (lastMonthList2.size()>0){
yearcsll=Double.parseDouble(lastMonthList2.get(0).get("v")+"")/10000;
}
if (lastMonthList3.size()>0){
monthcsll=Double.parseDouble(lastMonthList3.get(0).get("v")+"")/10000;
}
}catch (DataAccessException e) {
e.printStackTrace();
}
//封装数据
List<ReportItemCustomDetailDto> dtos=new ArrayList<>();
for (ReportItemCustomValueDto dto : dtoList) {
ReportItemCustomDetailDto customDto=new ReportItemCustomDetailDto();
customDto.setItemCode(dto.getItemCode());
customDto.setItemName(dto.getItemName());
//总耗量
Double zhl=this.getValue(Double.parseDouble(dto.getV()));
customDto.setZhl(zhl);
if (csll.compareTo(0d)!=0){
Double dshl=zhl/csll;
customDto.setDshl(this.getValue(dshl));
if (yearMap.get(dto.getItemCode())!=null&&yearcsll.compareTo(0d)!=0){
//去年药耗量
Double yearzhl=Double.parseDouble(yearMap.get(dto.getItemCode()).getV());
Double yeardshl=yearzhl/yearcsll;
//吨水耗量同比
customDto.setDshltb(this.getValue((dshl-yeardshl)/yeardshl*100));
customDto.setZhltb(this.getValue((zhl-yearzhl)/yearzhl*100));
}
if (monthMap.get(dto.getItemCode())!=null&&monthcsll.compareTo(0d)!=0){
//上月药耗量
Double monthzhl=Double.parseDouble(monthMap.get(dto.getItemCode()).getV());
Double monthdshl=monthzhl/monthcsll;
//吨水耗量环比
customDto.setDshlhb(this.getValue((dshl-monthdshl)/monthdshl*100));
customDto.setZhlhb(this.getValue((zhl-monthzhl)/monthzhl*100));
}
}
dtos.add(customDto);
}
result.put("data",dtos);
}else if (type!=null&&type==2&&currDataIds.size()>0){
//按类型统计
List<ReportItemCustomDto> customDtos=comprehensiveSupervisionMapper.selectItemCustom();
if (customDtos.size()>0){
//查询出水流量
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql1="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+time+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
String sql2="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+this.getMonthBytime(-12,time)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
String sql3="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)='"+this.getMonthBytime(-1,time)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)";
List<Map<String, Object>> lastMonthList1 = null;
List<Map<String, Object>> lastMonthList2 = null;
List<Map<String, Object>> lastMonthList3 = null;
Double csll=0d;
Double yearcsll=0d;
Double monthcsll=0d;
try {
lastMonthList1 = pgDb.queryForList(sql1);
lastMonthList2 = pgDb.queryForList(sql2);
lastMonthList3 = pgDb.queryForList(sql3);
if (lastMonthList1.size()>0){
csll=Double.parseDouble(lastMonthList1.get(0).get("v")+"")/10000;
}
if (lastMonthList2.size()>0){
yearcsll=Double.parseDouble(lastMonthList2.get(0).get("v")+"")/10000;
}
if (lastMonthList3.size()>0){
monthcsll=Double.parseDouble(lastMonthList3.get(0).get("v")+"")/10000;
}
}catch (DataAccessException e) {
e.printStackTrace();
}
//封装数据
List<ReportItemCustomDetailDto> dtos=new ArrayList<>();
for (ReportItemCustomDto dto : customDtos) {
//当前时间
ReportItemCustomDto curr=comprehensiveSupervisionMapper.selectVByDataIdAndPid(currDataIds,dto.getId());
//去年
ReportItemCustomDto year=comprehensiveSupervisionMapper.selectVByDataIdAndPid(yearDataIds,dto.getId());
//上月
ReportItemCustomDto month=comprehensiveSupervisionMapper.selectVByDataIdAndPid(monthDataIds,dto.getId());
ReportItemCustomDetailDto detailDto=new ReportItemCustomDetailDto();
detailDto.setItemName(dto.getItemName());
detailDto.setItemCode(dto.getItemCode());
//总药耗
if (curr!=null){
Double zhl=Double.parseDouble(curr.getV());
detailDto.setZhl(zhl);
if (csll.compareTo(0d)!=0){
Double dshl=zhl/csll;
detailDto.setDshl(this.getValue(dshl));
if (year!=null&&yearcsll.compareTo(0d)!=0){
//去年药耗量
Double yearzhl=Double.parseDouble(year.getV());
Double yeardshl=yearzhl/yearcsll;
//吨水耗量同比
detailDto.setDshltb(this.getValue((dshl-yeardshl)/yeardshl*100));
detailDto.setZhltb(this.getValue((zhl-yearzhl)/yearzhl*100));
}
if (month!=null&&monthcsll.compareTo(0d)!=0){
//上月药耗量
Double monthzhl=Double.parseDouble(month.getV());
Double monthdshl=monthzhl/monthcsll;
//吨水耗量环比
detailDto.setDshlhb(this.getValue((dshl-monthdshl)/monthdshl*100));
detailDto.setZhlhb(this.getValue((zhl-monthzhl)/monthzhl*100));
}
}
}
dtos.add(detailDto);
}
result.put("data",dtos);
}
}
return result;
}
@Override
public Map<String, Object> correlationAnalysis(String time, Integer type) {
Map<String, Object> result = Maps.newHashMap();
//查询当前时间往前推12个月的数据
List<String> months=this.getTwelve(time);
//查询JSSS
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("JSSS","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="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 (" + 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)";
List<Map<String, Object>> monitorList2 = null;
List<AlarmDto> ssList=new ArrayList<>();
try {
monitorList2=pgDb.queryForList(sql);
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());
ssList.add(dto);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
Map<String,String> jsssMap=ssList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
//1.絮凝剂 2.碳源 3.除磷剂
if (type==1){
List<Map<String,Object>> list=new ArrayList<>();
//查询絮凝剂 吨泥耗量 进水ss
for (String s : months) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(s);
Map<String,Object> map=new HashMap<>();
map.put("time",s);
if (dataIds.size()>0){
//查询当月絮凝剂总量
String xnj=comprehensiveSupervisionMapper.selectXnjByDataIds(dataIds);
if (xnj!=null){
map.put("xnj",this.getValue(Double.parseDouble(xnj)));
//查询当月干污泥总量
String gwn=comprehensiveSupervisionMapper.selectGwnByTime(s);
if (gwn!=null&&!"0".equals(gwn)){
//吨泥耗量=絮凝剂总量/干污泥总量
map.put("dnhl",this.getValue(Double.parseDouble(xnj)/Double.parseDouble(gwn)));
}else{
map.put("dnhl",null);
}
}
//当月jsss
if (jsssMap.get(s)!=null){
map.put("jsss",this.getValue(Double.parseDouble(jsssMap.get(s))));
}
list.add(map);
}
}
result.put("data",list);
}else if (type==2){
//碳源 BOD/TN
List<Map<String,Object>> list=new ArrayList<>();
for (String s : months) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(s);
Map<String,Object> map=new HashMap<>();
map.put("time",s);
if (dataIds.size()>0){
//查询本月碳源总量
String ty=comprehensiveSupervisionMapper.selectTyByDataIds(dataIds);
if (ty!=null){
map.put("ty",this.getValue(Double.parseDouble(ty)));
}
//查询本月JSBOD总量
String bod=comprehensiveSupervisionMapper.selectBodByTime(s);
//查询本月JSTN总量
String tn=comprehensiveSupervisionMapper.selectTnByTime(s);
if (bod!=null&&tn!=null){
if (!tn.equals("0")) {
map.put("bod/tn", this.getValue(Double.parseDouble(bod) / Double.parseDouble(tn)));
}
}
list.add(map);
}
}
result.put("data",list);
}else if (type==3){
//除磷剂 与tp去除率
MetricVo metricVo2 = comprehensiveSupervisionMapper.selectMetric("JSTP","");
StringBuilder str2 = new StringBuilder();
str2.append("'" + metricVo2.getId() + "'");
String sq2="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 (" + str2.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)";
MetricVo metricVo3 = comprehensiveSupervisionMapper.selectMetric("CSTP","");
StringBuilder str3 = new StringBuilder();
str3.append("'" + metricVo3.getId() + "'");
String sq3="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 (" + str3.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>> monitorList3 = null;
List<Map<String, Object>> monitorList4 = null;
Map<String,Double> js=new HashMap<>();
Map<String,Double> cs=new HashMap<>();
try {
monitorList3=pgDb.queryForList(sq2);
monitorList4=pgDb.queryForList(sq3);
if (monitorList3.size()>0){
for (Map<String, Object> map : monitorList3) {
//进水
js.put(map.get("time")+"",Double.parseDouble(map.get("v")+""));
}
}
if (monitorList4.size()>0){
for (Map<String, Object> map : monitorList4) {
//出水
cs.put(map.get("time")+"",Double.parseDouble(map.get("v")+""));
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
List<Map<String,Object>> list=new ArrayList<>();
for (String s : months) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(s);
Map<String,Object> map=new HashMap<>();
map.put("time",s);
if (dataIds.size()>0){
//查询当前月份除磷总量
String cl=comprehensiveSupervisionMapper.selectClByDataIds(dataIds);
if (cl!=null){
map.put("cl",this.getValue(Double.parseDouble(cl)));
}
if (js.get(s)!=null&&cs.get(s)!=null){
//TP去除率=(JSTP-CSTP)/JSTP*100%
Double jstp=js.get(s);
Double cstp=cs.get(s);
map.put("tp",this.getValue((jstp-cstp)/jstp*100));
}
list.add(map);
}
}
result.put("data",list);
}
return result;
}
@Override
public Map<String, Object> drugConsumptionTrendDetail(DrugDto drugDto) {
Map<String, Object> results =Maps.newHashMap();
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
Set<String> strings=new HashSet<>();
if (drugDto.getType()==1){
//查询近7日的数据
List<String> sevens=this.getSeven(drugDto.getStartTime());
//查询每一天的数据
//查询每天的出水流量
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="select sum(cast(v as float8)) as v,substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11) 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,11)<='"+sevens.get(6)+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11)>='"+sevens.get(0)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11)";
List<Map<String, Object>> monitorList2 = null;
List<AlarmDto> CSList=new ArrayList<>();
try {
monitorList2=pgDb.queryForList(sql);
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);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String seven : sevens) {
//查询当天填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByDay(seven);
if (dataIds.size()>0){
List<ReportItemCustomValueDetailDto> valueDtoList=new ArrayList<>();
//查询具体的数据
List<ReportItemCustomValueDetailDto> dtoList=comprehensiveSupervisionMapper.selectVByDay(dataIds);
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(seven);
Double zyh=Double.parseDouble(n.getZyh());
n.setZyh(this.getValue(zyh)+"");
if (csMap.get(seven)!=null){
Double cs=Double.parseDouble(csMap.get(seven)+"")/10000;
n.setDsyh(this.getValue(zyh/cs)+"");
}
});
valueDtoList.addAll(dtoList);
result.put(seven,valueDtoList);
}else {
result.put(seven,new ArrayList<>());
}
}
}else if (drugDto.getType()==2){
//往前推12个月
List<String> list=this.getTwelve(drugDto.getStartTime());
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="select sum(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 (" + str1.toString() + ") \n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)<='"+list.get(11)+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,8)>='"+list.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>> monitorList2 = null;
List<AlarmDto> CSList=new ArrayList<>();
try {
monitorList2=pgDb.queryForList(sql);
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);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String month : list) {
//查询当月填报数据的data_id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByMonth(month);
if (dataIds.size()>0){
List<ReportItemCustomValueDetailDto> valueDtoList=new ArrayList<>();
//查询具体的数据
List<ReportItemCustomValueDetailDto> dtoList=comprehensiveSupervisionMapper.selectVByMonth(dataIds);
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(month);
Double zyh=Double.parseDouble(n.getZyh());
n.setZyh(this.getValue(zyh)+"");
if (csMap.get(month)!=null){
Double cs=Double.parseDouble(csMap.get(month)+"")/10000;
n.setDsyh(this.getValue(zyh/cs)+"");
}
});
valueDtoList.addAll(dtoList);
result.put(month,valueDtoList);
}else {
result.put(month,new ArrayList<>());
}
}
}else if (drugDto.getType()==3){
List<String> sevens=this.findEveryDay(drugDto.getStartTime(),drugDto.getEndTime());
//查询每一天的数据
//查询每天的出水流量
String device=comprehensiveSupervisionMapper.selectDeviceName("");
JdbcTemplate pgDb = (JdbcTemplate) SpringContextUtils.getBean("pg-db");
String tableName=device+"_count";
//查询每月出水流量
MetricVo metricVo1 = comprehensiveSupervisionMapper.selectMetric("CSLL","");
StringBuilder str1 = new StringBuilder();
str1.append("'" + metricVo1.getId() + "'");
String sql="select sum(cast(v as float8)) as v,substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11) 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,11)<='"+sevens.get(sevens.size()-1)+"'\n" +
"and substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11)>='"+sevens.get(0)+"'\n" +
"GROUP BY substring(to_char ( to_timestamp ( to_number ( ts, '9999999999' ) ), 'yyyy-MM-dd HH24:MI:SS' ),0,11)";
List<Map<String, Object>> monitorList2 = null;
List<AlarmDto> CSList=new ArrayList<>();
try {
monitorList2=pgDb.queryForList(sql);
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);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
Map<String,String> csMap=CSList.stream().collect(Collectors.toMap(AlarmDto::getTime, AlarmDto::getV,(k1, k2)->k1));
for (String seven : sevens) {
//查询当天填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByDay(seven);
if (dataIds.size()>0){
List<ReportItemCustomValueDetailDto> valueDtoList=new ArrayList<>();
//查询具体的数据
List<ReportItemCustomValueDetailDto> dtoList=comprehensiveSupervisionMapper.selectVByDay(dataIds);
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(seven);
Double zyh=Double.parseDouble(n.getZyh());
n.setZyh(this.getValue(zyh)+"");
if (csMap.get(seven)!=null){
Double cs=Double.parseDouble(csMap.get(seven)+"")/10000;
n.setDsyh(this.getValue(zyh/cs)+"");
}
});
valueDtoList.addAll(dtoList);
result.put(seven,valueDtoList);
}else {
result.put(seven,new ArrayList<>());
}
}
}
results.put("data",result);
results.put("itemName",strings);
return results;
}
@Override
public Map<String, Object> correlationAnalysisDetail(String time, Integer type) {
Map<String, Object> results =Maps.newHashMap();
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
Set<String> strings=new HashSet<>();
//获取当月的每一天
List<String> days=this.getDayByMonth(time);
if (type==1){
//查询絮凝剂明细
for (String day : days) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByDay(day);
if (dataIds.size()>0){
List<ReportItemCustomValueDto> valueDtoList=new ArrayList<>();
//查询絮凝剂数据
//查询具体的数据
List<ReportItemCustomValueDto> dtoList=comprehensiveSupervisionMapper.selectDetailVByMonth(dataIds,"1542412281596121088");
if (dtoList.size()>0){
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(day);
});
}
result.put(day,dtoList);
}else {
result.put(day,new ArrayList<>());
}
}
}else if (type==2){
//查询碳源明细
for (String day : days) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByDay(day);
if (dataIds.size()>0){
List<ReportItemCustomValueDto> valueDtoList=new ArrayList<>();
//查询碳源数据
//查询具体的数据
List<ReportItemCustomValueDto> dtoList=comprehensiveSupervisionMapper.selectDetailVByMonth(dataIds,"1355031171188244480");
if (dtoList.size()>0){
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(day);
});
}
result.put(day,dtoList);
}else {
result.put(day,new ArrayList<>());
}
}
}else if (type==3){
//查询除磷剂
for (String day : days) {
//查询当月填报的数据id
List<String> dataIds=comprehensiveSupervisionMapper.selectDataIdsByDay(day);
if (dataIds.size()>0){
List<ReportItemCustomValueDto> valueDtoList=new ArrayList<>();
//查询除磷剂
//查询具体的数据
List<ReportItemCustomValueDto> dtoList=comprehensiveSupervisionMapper.selectDetailVByMonth(dataIds,"1354978313802571776");
if (dtoList.size()>0){
dtoList.stream().forEach(n->{
strings.add(n.getItemName());
n.setTime(day);
});
}
result.put(day,dtoList);
}else {
result.put(day,new ArrayList<>());
}
}
}
results.put("data",result);
results.put("itemName",strings);
return results;
}
private List<String> getDayByMonth(String time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
List<String> list = new ArrayList<String>();
Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
try {
aCalendar.setTime(sdf.parse(time));
} catch (ParseException e) {
e.printStackTrace();
}
int year = aCalendar.get(Calendar.YEAR);//年份
int month = aCalendar.get(Calendar.MONTH) + 1;//月份
int day = aCalendar.getActualMaximum(Calendar.DATE);
for (int i = 1; i <= day; i++) {
String aDate = String.valueOf(year)+"-"+month+"-"+i;
list.add(aDate);
}
return list;
}
private List<String> findEveryDay(String beginTime, String endTime) {
//1.创建一个放所有日期的集合
List<String> dates = new ArrayList();
//2.创建时间解析对象规定解析格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//3.将传入的时间解析成Date类型,相当于格式化
Date dBegin = null;
try {
dBegin = sdf.parse(beginTime);
} catch (ParseException e) {
e.printStackTrace();
}
Date dEnd = null;
try {
dEnd = sdf.parse(endTime);
} catch (ParseException e) {
e.printStackTrace();
}
//4.将格式化后的第一天添加进集合
dates.add(sdf.format(dBegin));
//5.使用本地的时区和区域获取日历
Calendar calBegin = Calendar.getInstance();
//6.传入起始时间将此日历设置为起始日历
calBegin.setTime(dBegin);
//8.判断结束日期是否在起始日历的日期之后
while (dEnd.after(calBegin.getTime())) {
// 9.根据日历的规则:月份中的每一天,为起始日历加一天
calBegin.add(Calendar.DAY_OF_MONTH, 1);
//10.得到的每一天就添加进集合
dates.add(sdf.format(calBegin.getTime()));
//11.如果当前的起始日历超过结束日期后,就结束循环
}
return dates;
}
private List<String> getSeven(String startTime) {
List<String> list=new ArrayList<>();
for (int i=7;i>=1;i--){
list.add(this.getDayBytime(-i,startTime));
}
return list;
}
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(JdbcTemplate pgDb, String tableName, StringBuilder str1) {
Map<String, Object> result = Maps.newHashMap();
//查询所有月份的出水流量
String sql="select sum(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 (" + str1.toString() + ") \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;
List<AlarmDto> csList=new ArrayList<>();
try {
monitorList=pgDb.queryForList(sql);
if (monitorList.size()>0){
for (Map<String, Object> map : monitorList) {
AlarmDto dto=new AlarmDto();
dto.setV(map.get("v").toString());
dto.setTime(map.get("time").toString());
csList.add(dto);
}
}
} catch (DataAccessException e) {
e.printStackTrace();
}
//查询所有月份的药耗量
List<AlarmDto> dhList=comprehensiveSupervisionMapper.selectAllYh();
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 mindsyh=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 dsyh=this.getValue(Double.parseDouble(dh)/(Double.parseDouble(cs)/10000));
if (mindsyh==null){
mindsyh=dsyh;
mintime=s;
}else {
if (mindsyh>dsyh){
mindsyh=dsyh;
mintime=s;
}
}
}
}
result.put("mindsyh",mindsyh);
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());
}
private String getDayBytime(int i,String time) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(format.parse(time));
} catch (ParseException e) {
e.printStackTrace();
}
calendar.add(Calendar.DAY_OF_MONTH,i);
return format.format(calendar.getTime());
}
}
package com.skua.modules.equipment.service.impl;
import com.google.common.collect.Maps;
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 lombok.extern.slf4j.Slf4j;
import org.apache.shiro.dao.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class PowerConsumptionAnalusisServiceImpl implements IPowerConsumptionAnalysisService {
@Autowired
private ComprehensiveSupervisionMapper comprehensiveSupervisionMapper;
@Override
public Map<String, Object> dataDisplay(AnysisParamsVO anysisParamsVO) {
String time = anysisParamsVO.getTime();
String factoryId = null;
Map<String, Object> result = Maps.newHashMap();
//目标吨水电耗
result.put("mbdsdh","0.5");
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);
List<AlarmDto> current=comprehensiveSupervisionMapper.selectDhByMonths(months,factoryId);
if (current.size()>0){
result.put("zhdl",this.getValue(Double.parseDouble(current.get(0).getV())/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())));
}
}
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","");
}
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));
}
}
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));
}
}
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));
}
}
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 = null;
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 = null;
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 = null;
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 = null;
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 = null;
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());
}
}
package com.skua.modules.equipment.vo;
import lombok.Data;
@Data
public class AlarmVo {
private String alarmParamCode;
private String upperLimit;
private String lowerLimit;
}
package com.skua.modules.equipment.vo;
import lombok.Data;
@Data
public class AnysisParamsVO {
private String time;
private String factoryId;
}
package com.skua.modules.equipment.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class MetricVo {
private String id;
private String metricUidTag;
@ApiModelProperty("格式: yyyy-MM-dd")
private String startTIme;
@ApiModelProperty("格式: yyyy-MM-dd")
private String endTime;
}
package com.skua.modules.equipment.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class StructDictVo {
private String id;
private String name;
@ApiModelProperty("指标")
private List<StructDictVo> metrics=new ArrayList<>();
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!