<?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.goldenwater.yjjt.mapper.YjjtStationMapper">

    <resultMap type="com.goldenwater.yjjt.domain.YjjtStation" id="YjjtStationResult">
        <id     property="id"        column="id"         />
        <result property="stcd"      column="stcd"       />
        <result property="stnm"      column="stnm"       />
        <result property="sttp"      column="sttp"       />
        <result property="rvnm"      column="rvnm"       />
        <result property="hnnm"      column="hnnm"       />
        <result property="bsnm"      column="bsnm"       />
        <result property="stlc"      column="stlc"       />
        <result property="lgtd"      column="lgtd"       />
        <result property="lttd"      column="lttd"       />
        <result property="addvcd"    column="addvcd"     />
        <result property="dtmnm"     column="dtmnm"      />
        <result property="admunit"   column="admunit"    />
        <result property="jcdw"      column="jcdw"       />
        <result property="jcpc"      column="jcpc"       />
        <result property="jcxm"      column="jcxm"       />
        <result property="flag"      column="flag"       />
        <result property="dbcd"      column="dbcd"       />
        <result property="stgrd"     column="stgrd"      />
        <result property="nt"        column="nt"         />
        <result property="year"      column="year"       />
        <result property="newstcd"   column="newstcd"    />
        <result property="newstnm"   column="newstnm"    />
        <result property="prov"      column="prov"       />
        <result property="delFlag"   column="del_flag"   />
        <result property="createBy"  column="create_by"  />
        <result property="createTime" column="create_time"/>
        <result property="updateBy"  column="update_by"  />
        <result property="updateTime" column="update_time"/>
        <result property="remark"    column="remark"     />
    </resultMap>

    <sql id="selectStationVo">
        select id, stcd, stnm, sttp, rvnm, hnnm, bsnm, stlc, lgtd, lttd,
               addvcd, dtmnm, admunit, jcdw, jcpc, jcxm, flag, dbcd, stgrd, nt,
               year, newstcd, newstnm, prov, del_flag, create_by, create_time,
               update_by, update_time, remark
        from gx_yjjt_station
    </sql>

    <select id="selectYjjtStationList" parameterType="com.goldenwater.yjjt.domain.YjjtStation" resultMap="YjjtStationResult">
        <include refid="selectStationVo"/>
        where del_flag = '0'
        <if test="stcd != null and stcd != ''">
            AND stcd like '%' || #{stcd} || '%'
        </if>
        <if test="stnm != null and stnm != ''">
            AND stnm like '%' || #{stnm} || '%'
        </if>
        <if test="sttp != null and sttp != ''">
            AND sttp = #{sttp}
        </if>
        <if test="rvnm != null and rvnm != ''">
            AND rvnm like '%' || #{rvnm} || '%'
        </if>
        <if test="addvcd != null and addvcd != ''">
            AND addvcd = #{addvcd}
        </if>
        <if test="jcdw != null and jcdw != ''">
            AND jcdw like '%' || #{jcdw} || '%'
        </if>
        <if test="jcxm != null and jcxm != ''">
            AND jcxm = #{jcxm}
        </if>
        <if test="year != null and year != ''">
            AND year like '%' || #{year} || '%'
        </if>
        <if test="prov != null and prov != ''">
            AND prov = #{prov}
        </if>
        <if test="flag != null and flag != ''">
            AND flag = #{flag}
        </if>
        order by year desc, rvnm, stcd
    </select>

    <select id="selectYjjtStationById" parameterType="Long" resultMap="YjjtStationResult">
        <include refid="selectStationVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectByStcd" parameterType="String" resultMap="YjjtStationResult">
        <include refid="selectStationVo"/>
        where stcd = #{stcd} and del_flag = '0'
    </select>

    <select id="countByStcdAndYear" resultType="int">
        select count(1) from gx_yjjt_station
        where stcd = #{stcd} and year like '%' || #{year} || '%' and del_flag = '0'
    </select>

    <select id="selectCountGroupByStcdYear" resultType="java.util.Map">
        select count(stcd) as cnt, stcd as stcd, year as year
        from gx_yjjt_station
        where del_flag = '0'
        group by stcd, year
    </select>

    <insert id="insertYjjtStation" parameterType="com.goldenwater.yjjt.domain.YjjtStation" useGeneratedKeys="true" keyProperty="id">
        insert into gx_yjjt_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stcd != null and stcd != ''">stcd,</if>
            <if test="stnm != null">stnm,</if>
            <if test="sttp != null">sttp,</if>
            <if test="rvnm != null">rvnm,</if>
            <if test="hnnm != null">hnnm,</if>
            <if test="bsnm != null">bsnm,</if>
            <if test="stlc != null">stlc,</if>
            <if test="lgtd != null">lgtd,</if>
            <if test="lttd != null">lttd,</if>
            <if test="addvcd != null">addvcd,</if>
            <if test="dtmnm != null">dtmnm,</if>
            <if test="admunit != null">admunit,</if>
            <if test="jcdw != null">jcdw,</if>
            <if test="jcpc != null">jcpc,</if>
            <if test="jcxm != null">jcxm,</if>
            <if test="flag != null">flag,</if>
            <if test="dbcd != null">dbcd,</if>
            <if test="stgrd != null">stgrd,</if>
            <if test="nt != null">nt,</if>
            <if test="year != null">year,</if>
            <if test="newstcd != null">newstcd,</if>
            <if test="newstnm != null">newstnm,</if>
            <if test="prov != null">prov,</if>
            <if test="createBy != null">create_by,</if>
            <if test="remark != null">remark,</if>
            del_flag, create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stcd != null and stcd != ''">#{stcd},</if>
            <if test="stnm != null">#{stnm},</if>
            <if test="sttp != null">#{sttp},</if>
            <if test="rvnm != null">#{rvnm},</if>
            <if test="hnnm != null">#{hnnm},</if>
            <if test="bsnm != null">#{bsnm},</if>
            <if test="stlc != null">#{stlc},</if>
            <if test="lgtd != null">#{lgtd},</if>
            <if test="lttd != null">#{lttd},</if>
            <if test="addvcd != null">#{addvcd},</if>
            <if test="dtmnm != null">#{dtmnm},</if>
            <if test="admunit != null">#{admunit},</if>
            <if test="jcdw != null">#{jcdw},</if>
            <if test="jcpc != null">#{jcpc},</if>
            <if test="jcxm != null">#{jcxm},</if>
            <if test="flag != null">#{flag},</if>
            <if test="dbcd != null">#{dbcd},</if>
            <if test="stgrd != null">#{stgrd},</if>
            <if test="nt != null">#{nt},</if>
            <if test="year != null">#{year},</if>
            <if test="newstcd != null">#{newstcd},</if>
            <if test="newstnm != null">#{newstnm},</if>
            <if test="prov != null">#{prov},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="remark != null">#{remark},</if>
            '0', SYSDATE
        </trim>
    </insert>

    <update id="updateYjjtStation" parameterType="com.goldenwater.yjjt.domain.YjjtStation">
        update gx_yjjt_station
        <set>
            <if test="stcd != null and stcd != ''">stcd = #{stcd},</if>
            <if test="stnm != null">stnm = #{stnm},</if>
            <if test="sttp != null">sttp = #{sttp},</if>
            <if test="rvnm != null">rvnm = #{rvnm},</if>
            <if test="hnnm != null">hnnm = #{hnnm},</if>
            <if test="bsnm != null">bsnm = #{bsnm},</if>
            <if test="stlc != null">stlc = #{stlc},</if>
            <if test="lgtd != null">lgtd = #{lgtd},</if>
            <if test="lttd != null">lttd = #{lttd},</if>
            <if test="addvcd != null">addvcd = #{addvcd},</if>
            <if test="dtmnm != null">dtmnm = #{dtmnm},</if>
            <if test="admunit != null">admunit = #{admunit},</if>
            <if test="jcdw != null">jcdw = #{jcdw},</if>
            <if test="jcpc != null">jcpc = #{jcpc},</if>
            <if test="jcxm != null">jcxm = #{jcxm},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="dbcd != null">dbcd = #{dbcd},</if>
            <if test="stgrd != null">stgrd = #{stgrd},</if>
            <if test="nt != null">nt = #{nt},</if>
            <if test="year != null">year = #{year},</if>
            <if test="newstcd != null">newstcd = #{newstcd},</if>
            <if test="newstnm != null">newstnm = #{newstnm},</if>
            <if test="prov != null">prov = #{prov},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            update_time = SYSDATE
        </set>
        where id = #{id}
    </update>

    <update id="deleteYjjtStationById" parameterType="Long">
        update gx_yjjt_station set del_flag = '1' where id = #{id}
    </update>

    <update id="deleteYjjtStationByIds" parameterType="Long">
        update gx_yjjt_station set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
