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

    <resultMap type="com.goldenwater.gx.domain.GxExchangeBiz" id="GxExchangeBizResult">
        <id     property="id"           column="id"            />
        <result property="bizCode"      column="biz_code"      />
        <result property="bizName"      column="biz_name"      />
        <result property="bizType"      column="biz_type"      />
        <result property="bizUnit"      column="biz_unit"      />
        <result property="bizImplType"  column="biz_impl_type" />
        <result property="bizImplUrl"   column="biz_impl_url"  />
        <result property="bizState"     column="biz_state"     />
        <result property="dataFreq"     column="data_freq"     />
        <result property="bizNote"      column="biz_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>

    <sql id="selectGxExchangeBizVo">
        select id, biz_code, biz_name, biz_type, biz_unit, biz_impl_type, biz_impl_url,
               biz_state, data_freq, biz_note, order_num, create_by, create_time, update_by, update_time, remark, del_flag
        from gx_exchange_biz
    </sql>

    <select id="selectGxExchangeBizList" parameterType="com.goldenwater.gx.domain.GxExchangeBiz" resultMap="GxExchangeBizResult">
        <include refid="selectGxExchangeBizVo"/>
        where del_flag = '0'
        <if test="bizCode != null and bizCode != ''">
            AND biz_code like '%' || #{bizCode} || '%'
        </if>
        <if test="bizName != null and bizName != ''">
            AND biz_name like '%' || #{bizName} || '%'
        </if>
        <if test="bizType != null and bizType != ''">
            AND biz_type = #{bizType}
        </if>
        <if test="bizUnit != null and bizUnit != ''">
            AND biz_unit = #{bizUnit}
        </if>
        <if test="bizState != null and bizState != ''">
            AND biz_state = #{bizState}
        </if>
        order by order_num asc, create_time desc
    </select>

    <select id="selectGxExchangeBizById" parameterType="Long" resultMap="GxExchangeBizResult">
        <include refid="selectGxExchangeBizVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectByBizCode" parameterType="String" resultMap="GxExchangeBizResult">
        <include refid="selectGxExchangeBizVo"/>
        where biz_code = #{bizCode} and del_flag = '0'
    </select>

    <insert id="insertGxExchangeBiz" parameterType="com.goldenwater.gx.domain.GxExchangeBiz" useGeneratedKeys="true" keyProperty="id">
        insert into gx_exchange_biz
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bizCode != null and bizCode != ''">biz_code,</if>
            <if test="bizName != null and bizName != ''">biz_name,</if>
            <if test="bizType != null and bizType != ''">biz_type,</if>
            <if test="bizUnit != null">biz_unit,</if>
            <if test="bizImplType != null">biz_impl_type,</if>
            <if test="bizImplUrl != null">biz_impl_url,</if>
            <if test="bizState != null">biz_state,</if>
            <if test="dataFreq != null">data_freq,</if>
            <if test="bizNote != null">biz_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="bizCode != null and bizCode != ''">#{bizCode},</if>
            <if test="bizName != null and bizName != ''">#{bizName},</if>
            <if test="bizType != null and bizType != ''">#{bizType},</if>
            <if test="bizUnit != null">#{bizUnit},</if>
            <if test="bizImplType != null">#{bizImplType},</if>
            <if test="bizImplUrl != null">#{bizImplUrl},</if>
            <if test="bizState != null">#{bizState},</if>
            <if test="dataFreq != null">#{dataFreq},</if>
            <if test="bizNote != null">#{bizNote},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="remark != null">#{remark},</if>
            SYSDATE
        </trim>
    </insert>

    <update id="updateGxExchangeBiz" parameterType="com.goldenwater.gx.domain.GxExchangeBiz">
        update gx_exchange_biz
        <set>
            <if test="bizCode != null and bizCode != ''">biz_code = #{bizCode},</if>
            <if test="bizName != null and bizName != ''">biz_name = #{bizName},</if>
            <if test="bizType != null and bizType != ''">biz_type = #{bizType},</if>
            <if test="bizUnit != null">biz_unit = #{bizUnit},</if>
            <if test="bizImplType != null">biz_impl_type = #{bizImplType},</if>
            <if test="bizImplUrl != null">biz_impl_url = #{bizImplUrl},</if>
            <if test="bizState != null">biz_state = #{bizState},</if>
            <if test="dataFreq != null">data_freq = #{dataFreq},</if>
            <if test="bizNote != null">biz_note = #{bizNote},</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_biz where del_flag = '0'
    </select>

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

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

</mapper>
