<?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.gx.mapper.GxExchangeStationMapper">

    <resultMap type="com.goldenwater.gx.domain.GxExchangeStation" id="GxExchangeStationResult">
        <id     property="id"           column="id"            />
        <result property="bizCode"      column="biz_code"      />
        <result property="unitCode"     column="unit_code"     />
        <result property="stcd"         column="stcd"          />
        <result property="stnm"         column="stnm"          />
        <result property="dbcd"         column="dbcd"          />
        <result property="stlc"         column="stlc"          />
        <result property="lgtd"         column="lgtd"          />
        <result property="lttd"         column="lttd"          />
        <result property="rvnm"         column="rvnm"          />
        <result property="hnnm"         column="hnnm"          />
        <result property="bsnm"         column="bsnm"          />
        <result property="admauth"      column="admauth"       />
        <result property="state"        column="state"         />
        <result property="flag1h3h"     column="flag_1h3h"     />
        <result property="gcdl"         column="gcdl"          />
        <result property="note"         column="note"          />
        <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"        />
        <result property="delFlag"      column="del_flag"      />
        <result property="bizName"      column="biz_name"      />
        <result property="unitName"     column="unit_name"     />
    </resultMap>

    <sql id="selectStationVo">
        select s.id, s.biz_code, s.unit_code, s.stcd, s.stnm, s.dbcd, s.stlc, s.lgtd, s.lttd,
               s.rvnm, s.hnnm, s.bsnm, s.admauth, s.state, s.flag_1h3h, s.gcdl, s.note,
               s.create_by, s.create_time, s.update_by, s.update_time, s.remark, s.del_flag,
               b.biz_name, u.unit_name
        from gx_exchange_station s
        left join gx_exchange_biz b on s.biz_code = b.biz_code and b.del_flag = '0'
        left join gx_exchange_unit u on s.unit_code = u.unit_code and u.del_flag = '0'
    </sql>

    <select id="selectGxExchangeStationList" parameterType="com.goldenwater.gx.domain.GxExchangeStation" resultMap="GxExchangeStationResult">
        <include refid="selectStationVo"/>
        where s.del_flag = '0'
        <if test="unitCode != null and unitCode != ''">
            AND s.unit_code = #{unitCode}
        </if>
        <if test="bizCode != null and bizCode != ''">
            AND s.biz_code = #{bizCode}
        </if>
        <if test="stcd != null and stcd != ''">
            AND s.stcd like '%' || #{stcd} || '%'
        </if>
        <if test="stnm != null and stnm != ''">
            AND s.stnm like '%' || #{stnm} || '%'
        </if>
        <if test="delFlag != null and delFlag != ''">
            AND s.del_flag = #{delFlag}
        </if>
        order by s.create_time desc
    </select>

    <select id="selectGxExchangeStationById" parameterType="Long" resultMap="GxExchangeStationResult">
        <include refid="selectStationVo"/>
        where s.id = #{id} and s.del_flag = '0'
    </select>

    <select id="selectStationByBizCode" parameterType="String" resultMap="GxExchangeStationResult">
        <include refid="selectStationVo"/>
        where s.biz_code = #{bizCode} and s.del_flag = '0'
        order by s.stcd
    </select>

    <select id="selectStationByStcd" parameterType="String" resultMap="GxExchangeStationResult">
        <include refid="selectStationVo"/>
        where s.stcd = #{stcd} and s.del_flag = '0'
    </select>

    <insert id="insertGxExchangeStation" parameterType="com.goldenwater.gx.domain.GxExchangeStation" useGeneratedKeys="true" keyProperty="id">
        insert into gx_exchange_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bizCode != null and bizCode != ''">biz_code,</if>
            <if test="unitCode != null and unitCode != ''">unit_code,</if>
            <if test="stcd != null and stcd != ''">stcd,</if>
            <if test="stnm != null">stnm,</if>
            <if test="dbcd != null">dbcd,</if>
            <if test="stlc != null">stlc,</if>
            <if test="lgtd != null">lgtd,</if>
            <if test="lttd != null">lttd,</if>
            <if test="rvnm != null">rvnm,</if>
            <if test="hnnm != null">hnnm,</if>
            <if test="bsnm != null">bsnm,</if>
            <if test="admauth != null">admauth,</if>
            <if test="state != null">state,</if>
            <if test="flag1h3h != null">flag_1h3h,</if>
            <if test="gcdl != null">gcdl,</if>
            <if test="note != null">note,</if>
            <if test="createBy != null">create_by,</if>
            <if test="remark != null">remark,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bizCode != null and bizCode != ''">#{bizCode},</if>
            <if test="unitCode != null and unitCode != ''">#{unitCode},</if>
            <if test="stcd != null and stcd != ''">#{stcd},</if>
            <if test="stnm != null">#{stnm},</if>
            <if test="dbcd != null">#{dbcd},</if>
            <if test="stlc != null">#{stlc},</if>
            <if test="lgtd != null">#{lgtd},</if>
            <if test="lttd != null">#{lttd},</if>
            <if test="rvnm != null">#{rvnm},</if>
            <if test="hnnm != null">#{hnnm},</if>
            <if test="bsnm != null">#{bsnm},</if>
            <if test="admauth != null">#{admauth},</if>
            <if test="state != null">#{state},</if>
            <if test="flag1h3h != null">#{flag1h3h},</if>
            <if test="gcdl != null">#{gcdl},</if>
            <if test="note != null">#{note},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="remark != null">#{remark},</if>
            SYSDATE
        </trim>
    </insert>

    <update id="updateGxExchangeStation" parameterType="com.goldenwater.gx.domain.GxExchangeStation">
        update gx_exchange_station
        <set>
            <if test="bizCode != null and bizCode != ''">biz_code = #{bizCode},</if>
            <if test="unitCode != null and unitCode != ''">unit_code = #{unitCode},</if>
            <if test="stcd != null and stcd != ''">stcd = #{stcd},</if>
            <if test="stnm != null">stnm = #{stnm},</if>
            <if test="dbcd != null">dbcd = #{dbcd},</if>
            <if test="stlc != null">stlc = #{stlc},</if>
            <if test="lgtd != null">lgtd = #{lgtd},</if>
            <if test="lttd != null">lttd = #{lttd},</if>
            <if test="rvnm != null">rvnm = #{rvnm},</if>
            <if test="hnnm != null">hnnm = #{hnnm},</if>
            <if test="bsnm != null">bsnm = #{bsnm},</if>
            <if test="admauth != null">admauth = #{admauth},</if>
            <if test="state != null">state = #{state},</if>
            <if test="flag1h3h != null">flag_1h3h = #{flag1h3h},</if>
            <if test="gcdl != null">gcdl = #{gcdl},</if>
            <if test="note != null">note = #{note},</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="deleteGxExchangeStationById" parameterType="Long">
        update gx_exchange_station set del_flag = '1' where id = #{id}
    </update>

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

</mapper>
