1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.orisdom.modules.analyze.mapper.StatisticAnalysisMapper">
    4. <select id="selectDataStabilityAnalyze" resultType="com.orisdom.modules.analyze.dto.output.DataStabilityAnalyzeVO$DataStabilityAnalyze">
    5. SELECT
    6. df.factory_id,
    7. IFNULL( round(avg(COD),2) ,0) cod,
    8. IFNULL( round(avg(SS),2) ,0) ss,
    9. IFNULL( round(avg(TN),2) ,0) tn,
    10. IFNULL( round(avg(TP),2) ,0) tp,
    11. IFNULL( round(avg(NH3_N),2) ,0) nh3n,
    12. IFNULL( round(avg(PH),2) ,0) ph,
    13. IFNULL( round(avg(BOD5),2) ,0) bod5,
    14. <choose>
    15. <when test="filter.dateType == 1">
    16. qwd.hour
    17. </when>
    18. <when test="filter.dateType == 2">
    19. qwd.date_recv
    20. </when>
    21. <when test="filter.dateType == 3">
    22. qwd.month
    23. </when>
    24. </choose>
    25. AS `date`
    26. FROM
    27. <choose>
    28. <when test="filter.dateType == 1">
    29. qms_water_data_hour qwd
    30. </when>
    31. <when test="filter.dateType == 2">
    32. qms_water_data_day qwd
    33. </when>
    34. <when test="filter.dateType == 3">
    35. qms_water_data_month qwd
    36. </when>
    37. </choose>
    38. INNER JOIN dm_factory df ON (qwd.factory_id = df.factory_id)
    39. INNER JOIN bs_area ba ON (df.factory_area_id = ba.id)
    40. WHERE
    41. <choose>
    42. <when test="filter.dateType == 1">
    43. qwd.hour
    44. </when>
    45. <when test="filter.dateType == 2">
    46. qwd.date_recv
    47. </when>
    48. <when test="filter.dateType == 3">
    49. qwd.month
    50. </when>
    51. </choose>
    52. LIKE '${filter.date}%'
    53. <if test="filter.factoryId!=null">
    54. AND df.factory_id = #{filter.factoryId}
    55. </if>
    56. <if test="filter.areaId!=null">
    57. AND ba.id = #{filter.areaId}
    58. </if>
    59. GROUP BY `date`
    60. ORDER BY `date` ASC
    61. </select>
    62. </mapper>
    1. package com.orisdom.modules.analyze.service.impl;
    2. import com.orisdom.modules.analyze.dto.input.DataStabilityAnalyzeQueryPara;
    3. import com.orisdom.modules.analyze.dto.output.DataStabilityAnalyzeVO;
    4. import com.orisdom.modules.analyze.mapper.StatisticAnalysisMapper;
    5. import com.orisdom.modules.analyze.service.IStatisticAnalysisService;
    6. import lombok.extern.slf4j.Slf4j;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Service;
    9. import org.springframework.transaction.annotation.Transactional;
    10. import java.util.LinkedList;
    11. import java.util.List;
    12. /**
    13. * <p> 统计分析 服务实现类 </p>
    14. *
    15. * @author : zhengqing
    16. * @description :
    17. * @date : 2019/11/5 16:42
    18. */
    19. @Service
    20. @Transactional(rollbackFor = Exception.class)
    21. @Slf4j
    22. public class StatisticAnalysisServiceImpl implements IStatisticAnalysisService {
    23. @Autowired
    24. StatisticAnalysisMapper statisticAnalysisMapper;
    25. @Override
    26. public DataStabilityAnalyzeVO getDataStabilityAnalyze(DataStabilityAnalyzeQueryPara para) {
    27. DataStabilityAnalyzeVO result = new DataStabilityAnalyzeVO();
    28. // 7种水质指标数据
    29. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> codList = new LinkedList<>();
    30. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> bod5List = new LinkedList<>();
    31. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> nh3nList = new LinkedList<>();
    32. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> ssList = new LinkedList<>();
    33. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> tpList = new LinkedList<>();
    34. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> tnList = new LinkedList<>();
    35. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> phList = new LinkedList<>();
    36. List<DataStabilityAnalyzeVO.DataStabilityAnalyze> dataList = statisticAnalysisMapper.selectDataStabilityAnalyze(para);
    37. dataList.forEach(e -> {
    38. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    39. item.setDate(e.getDate());
    40. item.setValue(e.getCod());
    41. codList.add(item);
    42. });
    43. dataList.forEach(e -> {
    44. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    45. item.setDate(e.getDate());
    46. item.setValue(e.getBod5());
    47. bod5List.add(item);
    48. });
    49. dataList.forEach(e -> {
    50. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    51. item.setDate(e.getDate());
    52. item.setValue(e.getNh3n());
    53. nh3nList.add(item);
    54. });
    55. dataList.forEach(e -> {
    56. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    57. item.setDate(e.getDate());
    58. item.setValue(e.getSs());
    59. ssList.add(item);
    60. });
    61. dataList.forEach(e -> {
    62. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    63. item.setDate(e.getDate());
    64. item.setValue(e.getTp());
    65. tpList.add(item);
    66. });
    67. dataList.forEach(e -> {
    68. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    69. item.setDate(e.getDate());
    70. item.setValue(e.getTn());
    71. tnList.add(item);
    72. });
    73. dataList.forEach(e -> {
    74. DataStabilityAnalyzeVO.DataStabilityAnalyze item = new DataStabilityAnalyzeVO.DataStabilityAnalyze();
    75. item.setDate(e.getDate());
    76. item.setValue(e.getPh());
    77. phList.add(item);
    78. });
    79. result.setCodcr(codList);
    80. result.setBod(bod5List);
    81. result.setNh3n(nh3nList);
    82. result.setSs(ssList);
    83. result.setTp(tpList);
    84. result.setTn(tnList);
    85. result.setPh(phList);
    86. return result;
    87. }
    88. }