<?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.orisdom.modules.analyze.mapper.StatisticAnalysisMapper">
<select id="selectDataStabilityAnalyze" resultType="com.orisdom.modules.analyze.dto.output.DataStabilityAnalyzeVO$DataStabilityAnalyze">
SELECT
df.factory_id,
IFNULL( round(avg(COD),2) ,0) cod,
IFNULL( round(avg(SS),2) ,0) ss,
IFNULL( round(avg(TN),2) ,0) tn,
IFNULL( round(avg(TP),2) ,0) tp,
IFNULL( round(avg(NH3_N),2) ,0) nh3n,
IFNULL( round(avg(PH),2) ,0) ph,
IFNULL( round(avg(BOD5),2) ,0) bod5,
<choose>
<when test="filter.dateType == 1">
qwd.hour
</when>
<when test="filter.dateType == 2">
qwd.date_recv
</when>
<when test="filter.dateType == 3">
qwd.month
</when>
</choose>
AS `date`
FROM
<choose>
<when test="filter.dateType == 1">
qms_water_data_hour qwd
</when>
<when test="filter.dateType == 2">
qms_water_data_day qwd
</when>
<when test="filter.dateType == 3">
qms_water_data_month qwd
</when>
</choose>
INNER JOIN dm_factory df ON (qwd.factory_id = df.factory_id)
INNER JOIN bs_area ba ON (df.factory_area_id = ba.id)
WHERE
<choose>
<when test="filter.dateType == 1">
qwd.hour
</when>
<when test="filter.dateType == 2">
qwd.date_recv
</when>
<when test="filter.dateType == 3">
qwd.month
</when>
</choose>
LIKE '${filter.date}%'
<if test="filter.factoryId!=null">
AND df.factory_id = #{filter.factoryId}
</if>
<if test="filter.areaId!=null">
AND ba.id = #{filter.areaId}
</if>
GROUP BY `date`
ORDER BY `date` ASC
</select>
</mapper>
package com.orisdom.modules.analyze.service.impl;
import com.orisdom.modules.analyze.dto.input.DataStabilityAnalyzeQueryPara;
import com.orisdom.modules.analyze.dto.output.DataStabilityAnalyzeVO;
import com.orisdom.modules.analyze.mapper.StatisticAnalysisMapper;
import com.orisdom.modules.analyze.service.IStatisticAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedList;
import java.util.List;
/**
* <p> 统计分析 服务实现类 </p>
*
* @author : zhengqing
* @description :
* @date : 2019/11/5 16:42
*/
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class StatisticAnalysisServiceImpl implements IStatisticAnalysisService {
@Autowired
StatisticAnalysisMapper statisticAnalysisMapper;
@Override
public DataStabilityAnalyzeVO getDataStabilityAnalyze(DataStabilityAnalyzeQueryPara para) {
DataStabilityAnalyzeVO result = new DataStabilityAnalyzeVO();
// 7种水质指标数据
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> codList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> bod5List = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> nh3nList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> ssList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> tpList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> tnList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> phList = new LinkedList<>();
List<DataStabilityAnalyzeVO.DataStabilityAnalyze> dataList = statisticAnalysisMapper.selectDataStabilityAnalyze(para);
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getCod());
codList.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getBod5());
bod5List.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getNh3n());
nh3nList.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getSs());
ssList.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getTp());
tpList.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getTn());
tnList.add(item);
});
dataList.forEach(e -> {
DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
item.setDate(e.getDate());
item.setValue(e.getPh());
phList.add(item);
});
result.setCodcr(codList);
result.setBod(bod5List);
result.setNh3n(nh3nList);
result.setSs(ssList);
result.setTp(tpList);
result.setTn(tnList);
result.setPh(phList);
return result;
}
}