<?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.ExtendGroupMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.extend.po.ExtendGroupPO">
        <result column="id" property="id"/>
        <result column="extend_type" property="extendType"/>
        <result column="group_name" property="groupName"/>
        <result column="show_order" property="showOrder"/>
        <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.pid
        , t.extend_type
        , t.group_name
        , t.is_system_default
        , t.creator
        , t.is_show
        , t.show_order
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>


    <select id="listByType" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        jcl_field_extendgroup t
        WHERE t.delete_type = 0
        <if test=" extendType != null and extendType != '' ">
            and extend_type = #{extendType}
        </if>
        order by show_order
    </select>
    <select id="getGroupNameById" resultType="java.lang.String">
        select group_name
        from jcl_field_extendgroup
        where id = #{id}
          and delete_type = 0
        order by show_order
    </select>
    <select id="listGroupByIds" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_field_extendgroup t
        WHERE t.delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        order by show_order
    </select>
    <select id="listGroupByPid" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_field_extendgroup t
        WHERE t.delete_type = 0
        and t.pid= #{pid}
        order by show_order
    </select>
    <select id="getGroupById" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_field_extendgroup t
        WHERE t.delete_type = 0
        and t.id= #{id}
        order by show_order
    </select>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.extend.po.ExtendGroupPO"
            keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_field_extendgroup
        <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="extendType != null ">
                extend_type,
            </if>
            <if test="groupName != null ">
                group_name,
            </if>
            <if test="pid != null ">
                pid,
            </if>
            <if test="isShow != null ">
                is_show,
            </if>
            <if test="showOrder != null ">
                show_order,
            </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="extendType != null ">
                #{extendType},
            </if>
            <if test="groupName != null ">
                #{groupName},
            </if>
            <if test="pid != null ">
                #{pid},
            </if>
            <if test="isShow != null ">
                #{isShow},
            </if>
            <if test="showOrder != null ">
                #{showOrder},
            </if>
            <if test="isSystemDefault != null ">
                #{isSystemDefault},
            </if>
        </trim>
    </insert>

    <update id="update">
        update jcl_field_extendgroup
        <set>
            group_name=#{name},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>

    <delete id="delete">
        update jcl_field_extendgroup
        <set>
            delete_type=1,
        </set>
        WHERE id = #{id} AND delete_type = 0
    </delete>

    <update id="updateNameAndOrder">
        update jcl_field_extendgroup
        <set>
            group_name=#{groupName},
            show_order=#{showOrder},
            is_show = #{isShow}
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>

    <delete id="batchDelete">
        UPDATE jcl_field_extendgroup
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>