<?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.aucma.base.mapper.BaseCustomDataMapper">

    <resultMap type="BaseCustomData" id="BaseCustomDataResult">
        <result property="objId" column="obj_id"/>
        <result property="customType" column="custom_type"/>
        <result property="customFunction" column="custom_function"/>
        <result property="customCode" column="custom_code"/>
        <result property="customData" column="custom_data"/>
        <result property="customSort" column="custom_sort"/>
        <result property="remark" column="remark"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
    </resultMap>

    <sql id="selectBaseCustomDataVo">
        select obj_id,
               custom_type,
               custom_function,
               custom_code,
               custom_data,
               custom_sort,
               remark,
               is_flag,
               created_by,
               created_time,
               updated_by,
               updated_time
        from base_custom_data
    </sql>

    <select id="selectBaseCustomDataList" parameterType="BaseCustomData" resultMap="BaseCustomDataResult">
        <include refid="selectBaseCustomDataVo"/>
        <where>
            <if test="customType != null ">and custom_type = #{customType}</if>
            <if test="customFunction != null  and customFunction != ''">and custom_function like concat(concat('%',
                #{customFunction}), '%')</if>
            <if test="customCode != null  and customCode != ''">and custom_code like concat(concat('%',
                #{customCode}), '%')</if>
            <if test="customData != null  and customData != ''">and custom_data = #{customData}</if>
            <if test="customSort != null ">and custom_sort = #{customSort}</if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="createdTime != null ">and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
        </where>
        order by custom_type,custom_sort
    </select>

    <select id="selectBaseCustomDataByObjId" parameterType="Long" resultMap="BaseCustomDataResult">
        <include refid="selectBaseCustomDataVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBaseCustomData" parameterType="BaseCustomData">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_base_custom_data.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into base_custom_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="customType != null">custom_type,</if>
            <if test="customFunction != null">custom_function,</if>
            <if test="customCode != null">custom_code,</if>
            <if test="customData != null">custom_data,</if>
            <if test="customSort != null">custom_sort,</if>
            <if test="remark != null">remark,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="customType != null">#{customType},</if>
            <if test="customFunction != null">#{customFunction},</if>
            <if test="customCode != null">#{customCode},</if>
            <if test="customData != null">#{customData},</if>
            <if test="customSort != null">#{customSort},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateBaseCustomData" parameterType="BaseCustomData">
        update base_custom_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="customType != null">custom_type = #{customType},</if>
            <if test="customFunction != null">custom_function = #{customFunction},</if>
            <if test="customCode != null">custom_code = #{customCode},</if>
            <if test="customData != null">custom_data = #{customData},</if>
            <if test="customSort != null">custom_sort = #{customSort},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBaseCustomDataByObjId" parameterType="Long">
        delete
        from base_custom_data
        where obj_id = #{objId}
    </delete>

    <delete id="deleteBaseCustomDataByObjIds" parameterType="String">
        delete from base_custom_data where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>