From e2392116cd6f875cdc2f46bc04b04d5305f21b56 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期四, 23 十一月 2023 13:25:04 +0800 Subject: [PATCH] 1. 修改日统计值的排序查询逻辑 --- src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml | 158 +++++++++++++++++++++++++++++++++------------------- 1 files changed, 100 insertions(+), 58 deletions(-) diff --git a/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml b/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml index 4726f1b..a19b0b5 100644 --- a/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml +++ b/src/main/resources/mapper/ds1/DustStatisticsValueMapper.xml @@ -1,63 +1,105 @@ <?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.flightfeather.monitor.domain.ds1.mapper.DustStatisticsValueMapper"> - <resultMap id="BaseResultMap" type="com.flightfeather.monitor.domain.ds1.entity.DustStatisticsValue"> - <!-- - WARNING - @mbg.generated - --> - <id column="id" jdbcType="INTEGER" property="id" /> - <result column="mn_code" jdbcType="VARCHAR" property="mnCode" /> - <result column="lst" jdbcType="DATE" property="lst" /> - <result column="day_avg" jdbcType="VARCHAR" property="dayAvg" /> - <result column="min" jdbcType="VARCHAR" property="min" /> - <result column="max" jdbcType="VARCHAR" property="max" /> - <result column="day_online" jdbcType="VARCHAR" property="dayOnline" /> - <result column="day_valid" jdbcType="VARCHAR" property="dayValid" /> - <result column="day_exceeding" jdbcType="VARCHAR" property="dayExceeding" /> - <result column="type" jdbcType="VARCHAR" property="type" /> - </resultMap> - <sql id="Base_Column_List"> - <!-- - WARNING - @mbg.generated - --> - id, mn_code, lst, day_avg, min, max, day_online, day_valid, day_exceeding, type - </sql> + <resultMap id="BaseResultMap" type="com.flightfeather.monitor.domain.ds1.entity.DustStatisticsValue"> + <!-- + WARNING - @mbg.generated + --> + <id column="id" jdbcType="INTEGER" property="id"/> + <result column="mn_code" jdbcType="VARCHAR" property="mnCode"/> + <result column="lst" jdbcType="DATE" property="lst"/> + <result column="day_avg" jdbcType="VARCHAR" property="dayAvg"/> + <result column="min" jdbcType="VARCHAR" property="min"/> + <result column="max" jdbcType="VARCHAR" property="max"/> + <result column="day_online" jdbcType="VARCHAR" property="dayOnline"/> + <result column="day_valid" jdbcType="VARCHAR" property="dayValid"/> + <result column="day_exceeding" jdbcType="VARCHAR" property="dayExceeding"/> + <result column="type" jdbcType="VARCHAR" property="type"/> + </resultMap> + <sql id="Base_Column_List"> + <!-- + WARNING - @mbg.generated + --> + id, mn_code, lst, day_avg, min, max, day_online, day_valid, day_exceeding, type + </sql> - <insert id="dailyStatics"> - insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) - select a.* - from (select - mn_code as mn_code, - DATE(lst) as lst, - ROUND(AVG(dust_value),3) as day_avg, - min(dust_value) as min, - max(dust_value) as max, - CONCAT(ROUND(COUNT(*)/96*100, 2), '%') as day_online, - CONCAT(ROUND(SUM(CASE WHEN dust_value >0 THEN 1 ELSE 0 END)/96 *100, 2), '%') as day_valid, - CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END)/96*100,2),'%') as day_exceeding, - 'day' as type - from ja_t_dust_site_data_info - where lst between #{beginTime} and #{endTime} - GROUP BY mn_code,DATE(lst) - ) as a - </insert> - <insert id="monthlyStatics"> - insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) - select a.* - from ( - SELECT - mn_code AS mn_code, - DATE_FORMAT(lst, '%Y-%m-01') AS month, - ROUND(AVG(dust_value), 3) AS month_avg, - MIN(dust_value) AS min, - MAX(dust_value) AS max, - CONCAT(ROUND(COUNT(*) / #{count} * 100, 2), '%') AS month_online, - CONCAT(ROUND(SUM(CASE WHEN flag = 'N' OR flag = 'A' THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_valid, - CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_exceeding, - 'month' as type - FROM ja_t_dust_site_data_info - WHERE lst BETWEEN #{beginTime} and #{endTime} - GROUP BY mn_code, DATE_FORMAT(lst, '%Y-%m-01') - ) as a - </insert> + <insert id="dailyStatics"> + insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) + select a.* + from (select + mn_code as mn_code, + DATE(lst) as lst, + ROUND(AVG(dust_value),3) as day_avg, + min(dust_value) as min, + max(dust_value) as max, + ROUND(COUNT(*)/96, 4) as day_online, + ROUND(SUM(CASE WHEN dust_value >0 THEN 1 ELSE 0 END)/96, 4) as day_valid, + ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END)/96, 4) as day_exceeding, + 'day' as type + from ja_t_dust_site_data_info + where lst between #{beginTime} and #{endTime} + GROUP BY mn_code,DATE(lst) + ) as a + </insert> + <insert id="monthlyStatics"> + insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) + select a.* + from ( + SELECT + mn_code AS mn_code, + DATE_FORMAT(lst, '%Y-%m-01') AS month, + ROUND(AVG(dust_value), 3) AS month_avg, + MIN(dust_value) AS min, + MAX(dust_value) AS max, + ROUND(COUNT(*) / #{count}, 4) AS month_online, + ROUND(SUM(CASE WHEN flag = 'N' OR flag = 'A' THEN 1 ELSE 0 END) / #{count}, 4) AS month_valid, + ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END) / #{count}, 4) AS month_exceeding, + 'month' as type + FROM ja_t_dust_site_data_info + WHERE lst BETWEEN #{beginTime} and #{endTime} + GROUP BY mn_code, DATE_FORMAT(lst, '%Y-%m-01') + ) as a + </insert> + + <!-- 鏍规嵁绔欑偣鍚嶅瓧鍜屾椂娈佃繘琛岀粺璁″垎鏋�--> + <select id="selectByOrder" resultType="com.flightfeather.monitor.pojo.AnalysisDustData"> + select c.name,d.* + from dust_statistics_value as d + left join ja_t_dust_site_info as c on c.mn_code = d.mn_code + <where> + <if test="siteName != null and siteName != ''"> + and c.name = #{siteName} + </if> + <if test="beginTime != null and endTime != null"> + and d.lst between #{beginTime} and #{endTime} and d.type = 'day' + </if> + </where> + <if test="orderProp == 'lst'"> + order by d.lst + </if> + <if test="orderProp == 'day_avg'"> + order by d.day_avg + </if> + <if test="orderProp == 'min'"> + order by d.min + </if> + <if test="orderProp == 'max'"> + order by d.max + </if> + <if test="orderProp == 'day_online'"> + order by d.day_online + </if> + <if test="orderProp == 'day_valid'"> + order by d.day_valid + </if> + <if test="orderProp == 'day_exceeding'"> + order by d.day_exceeding + </if> + <if test="orderProp != null and asc"> + asc + </if> + <if test="orderProp != null and !asc"> + desc + </if> + </select> </mapper> \ No newline at end of file -- Gitblit v1.9.3