<?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.elephant.framework.galaxy.aroad.module.zhtj.mapper.ZhtjGllmqkMapper">

    <resultMap id="zhtjGllmqkMap" type="com.elephant.framework.galaxy.aroad.module.zhtj.entity.ZhtjGllmqk">
        <id property="id" column="id"/>
        <result property="year" column="year"/>
        <result property="area" column="area"/>
        <result property="type" column="type"/>
        <result property="xzdj" column="xzdj"/>
        <result property="total" column="total"/>
        <result property="ypzlmSum" column="ypzlm_sum"/>
        <result property="ypzlmLqhnt" column="ypzlm_lqhnt"/>
        <result property="ypzlmSnhnt" column="ypzlm_snhnt"/>
        <result property="jypzlm" column="jypzlm"/>
        <result property="wpzlm" column="wpzlm"/>
        <result property="sort" column="sort"/>
        <result property="creator" column="creator"/>
        <result property="createTime" column="create_time"/>
        <result property="updatePerson" column="update_person"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="remarks" column="remarks"/>
    </resultMap>
    <sql id="maxYear">
            select max(year) maxyear from `t_zhtj_gllmqk`
      </sql>
    <select id="electZhtjGllmqks" resultMap="zhtjGllmqkMap">
        SELECT * FROM `t_zhtj_gllmqk` where type = #{type}
        <if test="year==null or year==''">
            and year=(
            <include refid="maxYear"/>
            )
        </if>
        <if test="year!=null and year!=''">
            and year=#{year}
        </if>
        <if test="area!=null and area!=''">
            and area=#{area}
        </if>
    </select>
    <select id="selectOrdinary" resultType="Map">
        SELECT sum(ypzlm_lqhnt) as ypzlm_lqhnt,sum(ypzlm_snhnt) as ypzlm_snhnt,sum(jypzlm) as jypzlm,sum(wpzlm) as wpzlm
        FROM `t_zhtj_gllmqk` where type in (${type})
        <if test="year==null or year==''">
            and year=(
            <include refid="maxYear"/>
            )
        </if>
        <if test="year!=null and year!=''">
            and year=#{year}
        </if>
        <if test="area!=null and area!=''">
            and area=#{area}
        </if>
    </select>
    <select id="newYear" resultType="string">
        <include refid="maxYear"/>
        <if test="type!=null and type!=''">
            where type=#{type}
        </if>
    </select>


    <select id="selectLmqkForPtgsd" resultMap="zhtjGllmqkMap">
        SELECT * FROM t_zhtj_gllmqk_ptgsd
        <where>
            <if test="lm.year!=null and lm.year!=''">
                and year=#{lm.year}
            </if>
            <if test="lm.area!=null and lm.area!=''">
                and area=#{lm.area}
            </if>
            <if test="lm.type!=null and lm.type!=''">
                and type=#{lm.type}
            </if>
        </where>
    </select>
</mapper>
