cjl
2023-09-12 ea1373d4e1511b620bb87872e692643e2edb81f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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.moral.api.mapper.CityAqiDailyMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqiDaily">
        <result column="city_code" property="cityCode"/>
        <result column="time" property="time"/>
        <result column="value" property="value"/>
    </resultMap>
 
    <select id="CityAqiDailyMap" resultType="com.moral.api.dto.CityAqiDailyListDTO">
        SELECT c.city_code, avg(c.value ->'$.AQI')as aqi,avg(c.value ->'$.compositeIndex')
        as comp,sum(c.value ->'$.compositeIndex') as nums FROM city_aqi_daily c
        INNER JOIN sys_area s on s.area_code = c.city_code and parent_code = #{cityCode}
        where 1 =1
        <if test="type == 1">
            and c.time <![CDATA[=]]> #{start}
            GROUP BY c.city_code order by aqi
        </if>
        <if test=" type == 2 ">
            and c.time  <![CDATA[>=]]> #{start} and  c.time <![CDATA[<=]]> #{end}
            GROUP BY c.city_code order by nums
        </if>
        <if test="type == 3 ">
            and DATE_FORMAT(c.time,'%Y') <![CDATA[>=]]> #{start}
            GROUP BY c.city_code order by nums
        </if>
    </select>
</mapper>