<?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.GxExchangeUnitMapper">

    <resultMap type="com.goldenwater.gx.domain.GxExchangeUnit" id="GxExchangeUnitResult">
        <id     property="id"          column="id"           />
        <result property="unitCode"    column="unit_code"    />
        <result property="unitName"    column="unit_name"    />
        <result property="type"        column="type"         />
        <result property="addr"        column="addr"         />
        <result property="linkman"     column="linkman"      />
        <result property="tele"        column="tele"         />
        <result property="mail"        column="mail"         />
        <result property="fax"         column="fax"          />
        <result property="url"         column="url"          />
        <result property="note"        column="note"         />
        <result property="orderNum"    column="order_num"    />
        <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"     />
    </resultMap>

    <select id="selectGxExchangeUnitList" parameterType="com.goldenwater.gx.domain.GxExchangeUnit" resultMap="GxExchangeUnitResult">
        select id, unit_code, unit_name, type, addr, linkman, tele, mail, fax, url, note,
               create_by, create_time, update_by, update_time, remark, del_flag
        from gx_exchange_unit
        where del_flag = '0'
        <if test="unitCode != null and unitCode != ''">
            AND unit_code like '%' || #{unitCode} || '%'
        </if>
        <if test="unitName != null and unitName != ''">
            AND unit_name like '%' || #{unitName} || '%'
        </if>
        <if test="type != null and type != ''">
            AND type = #{type}
        </if>
        order by order_num asc, create_time desc
    </select>

    <select id="selectGxExchangeUnitById" parameterType="Long" resultMap="GxExchangeUnitResult">
        select id, unit_code, unit_name, type, addr, linkman, tele, mail, fax, url, note,
               order_num, create_by, create_time, update_by, update_time, remark, del_flag
        from gx_exchange_unit
        where id = #{id} and del_flag = '0'
    </select>

    <insert id="insertGxExchangeUnit" parameterType="com.goldenwater.gx.domain.GxExchangeUnit" useGeneratedKeys="true" keyProperty="id">
        insert into gx_exchange_unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitCode != null and unitCode != ''">unit_code,</if>
            <if test="unitName != null and unitName != ''">unit_name,</if>
            <if test="type != null">type,</if>
            <if test="addr != null">addr,</if>
            <if test="linkman != null">linkman,</if>
            <if test="tele != null">tele,</if>
            <if test="mail != null">mail,</if>
            <if test="fax != null">fax,</if>
            <if test="url != null">url,</if>
            <if test="note != null">note,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="createBy != null">create_by,</if>
            <if test="remark != null">remark,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="unitCode != null and unitCode != ''">#{unitCode},</if>
            <if test="unitName != null and unitName != ''">#{unitName},</if>
            <if test="type != null">#{type},</if>
            <if test="addr != null">#{addr},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="tele != null">#{tele},</if>
            <if test="mail != null">#{mail},</if>
            <if test="fax != null">#{fax},</if>
            <if test="url != null">#{url},</if>
            <if test="note != null">#{note},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="remark != null">#{remark},</if>
            SYSDATE
        </trim>
    </insert>

    <update id="updateGxExchangeUnit" parameterType="com.goldenwater.gx.domain.GxExchangeUnit">
        update gx_exchange_unit
        <set>
            <if test="unitCode != null and unitCode != ''">unit_code = #{unitCode},</if>
            <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
            <if test="type != null">type = #{type},</if>
            <if test="addr != null">addr = #{addr},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="tele != null">tele = #{tele},</if>
            <if test="mail != null">mail = #{mail},</if>
            <if test="fax != null">fax = #{fax},</if>
            <if test="url != null">url = #{url},</if>
            <if test="note != null">note = #{note},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            update_time = SYSDATE
        </set>
        where id = #{id}
    </update>

    <select id="selectMaxOrderNum" resultType="Integer">
        select nvl(max(order_num), 0) from gx_exchange_unit where del_flag = '0'
    </select>

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

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

</mapper>
