<?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.engine.organization.mapper.extend.ExtendTitleMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.extend.po.ExtendTitlePO">
        <result column="id" property="id"/>
        <result column="group_id" property="groupId"/>
        <result column="title" property="title"/>
        <result column="show_order" property="showOrder"/>
        <result column="is_show" property="isShow"/>
        <result column="is_system_default" property="isSystemDefault"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.group_id
        , t.title
        , t.show_order
        , t.is_show
        , t.is_system_default
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>
    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.extend.po.ExtendTitlePO"
            keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_field_extendtitle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>

            <if test="groupId != null ">
                group_id,
            </if>
            <if test="title != null ">
                title,
            </if>
            <if test="showOrder != null ">
                show_order,
            </if>
            <if test="isShow != null ">
                is_show,
            </if>
            <if test="isSystemDefault != null ">
                is_system_default,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="groupId != null ">
                #{groupId},
            </if>
            <if test="title != null ">
                #{title},
            </if>

            <if test="showOrder != null ">
                #{showOrder},
            </if>
            <if test="isShow != null ">
                #{isShow},
            </if>
            <if test="isSystemDefault != null ">
                #{isSystemDefault},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.extend.po.ExtendTitlePO"
            databaseId="oracle">

        <selectKey keyProperty="id" resultType="long" order="AFTER">
            select JCL_FIELD_TITLE_ID.currval from dual
        </selectKey>

        INSERT INTO jcl_field_extendtitle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>

            <if test="groupId != null ">
                group_id,
            </if>
            <if test="title != null ">
                title,
            </if>
            <if test="showOrder != null ">
                show_order,
            </if>
            <if test="isShow != null ">
                is_show,
            </if>
            <if test="isSystemDefault != null ">
                is_system_default,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="groupId != null ">
                #{groupId},
            </if>
            <if test="title != null ">
                #{title},
            </if>

            <if test="showOrder != null ">
                #{showOrder},
            </if>
            <if test="isShow != null ">
                #{isShow},
            </if>
            <if test="isSystemDefault != null ">
                #{isSystemDefault},
            </if>
        </trim>
    </insert>

    <update id="updateExtendTitle" parameterType="com.engine.organization.entity.extend.po.ExtendTitlePO">
        update jcl_field_extendtitle
        <set>
            update_time=#{updateTime},
            group_id=#{groupId},
            title=#{title},
            show_order=#{showOrder},
            is_show=#{isShow},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>
    <delete id="deleteExtendTitleByIds">
        UPDATE jcl_field_extendtitle
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getTitlesByGroupID" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        jcl_field_extendtitle t
        WHERE t.delete_type = 0
        <if test=" groupId != null ">
            and group_id = #{groupId}
        </if>
        <if test=" isShow !=null">
            and is_show = #{isShow}
        </if>
        order by show_order
    </select>

    <select id="getTitlesByIds" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        jcl_field_extendtitle t
        WHERE t.delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        and is_show = '1'
        order by show_order
    </select>


</mapper>