<?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.resource.JclOrgCustomTemplateMapper">

    <resultMap id="BaseResultMap" type="com.engine.organization.entity.hrmresource.po.JclOrgCustomTemplatePO">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="basicFields" column="basic_fields" jdbcType="VARCHAR"/>
            <result property="personalFields" column="personal_fields" jdbcType="VARCHAR"/>
            <result property="workFields" column="work_fields" jdbcType="VARCHAR"/>
            <result property="isused" column="isused" jdbcType="INTEGER"/>
            <result property="creator" column="creator" jdbcType="INTEGER"/>
            <result property="createTime" column="create_time" jdbcType="DATE"/>
            <result property="updateTime" column="update_time" jdbcType="DATE"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,name,basic_fields,
        personal_fields,work_fields,isused,
        creator,create_time,update_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from jcl_org_custom_template
        where  id = #{id,jdbcType=INTEGER} 
    </select>
    <select id="listAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from jcl_org_custom_template order by id
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from jcl_org_custom_template
        where  id = #{id,jdbcType=INTEGER} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.engine.organization.entity.hrmresource.po.JclOrgCustomTemplatePO" useGeneratedKeys="true">
        insert into jcl_org_custom_template
        (name,basic_fields
        ,personal_fields,work_fields,isused
        ,creator,create_time,update_time
        )
        values (#{name,jdbcType=VARCHAR},#{basicFields,jdbcType=VARCHAR}
        ,#{personalFields,jdbcType=VARCHAR},#{workFields,jdbcType=VARCHAR},#{isused,jdbcType=INTEGER}
        ,#{creator,jdbcType=INTEGER},#{createTime,jdbcType=DATE},#{updateTime,jdbcType=DATE}
        )
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.engine.organization.entity.hrmresource.po.JclOrgCustomTemplatePO" useGeneratedKeys="true">
        insert into jcl_org_custom_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="name != null">name,</if>
                <if test="basicFields != null">basic_fields,</if>
                <if test="personalFields != null">personal_fields,</if>
                <if test="workFields != null">work_fields,</if>
                <if test="isused != null">isused,</if>
                <if test="creator != null">creator,</if>
                <if test="createTime != null">create_time,</if>
                <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="name != null">#{name,jdbcType=VARCHAR},</if>
                <if test="basicFields != null">#{basicFields,jdbcType=VARCHAR},</if>
                <if test="personalFields != null">#{personalFields,jdbcType=VARCHAR},</if>
                <if test="workFields != null">#{workFields,jdbcType=VARCHAR},</if>
                <if test="isused != null">#{isused,jdbcType=INTEGER},</if>
                <if test="creator != null">#{creator,jdbcType=INTEGER},</if>
                <if test="createTime != null">#{createTime,jdbcType=DATE},</if>
                <if test="updateTime != null">#{updateTime,jdbcType=DATE},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.engine.organization.entity.hrmresource.po.JclOrgCustomTemplatePO">
        update jcl_org_custom_template
        <set>
                <if test="name != null">
                    name = #{name,jdbcType=VARCHAR},
                </if>
                <if test="basicFields != null">
                    basic_fields = #{basicFields,jdbcType=VARCHAR},
                </if>
                <if test="personalFields != null">
                    personal_fields = #{personalFields,jdbcType=VARCHAR},
                </if>
                <if test="workFields != null">
                    work_fields = #{workFields,jdbcType=VARCHAR},
                </if>
                <if test="isused != null">
                    isused = #{isused,jdbcType=INTEGER},
                </if>
                <if test="creator != null">
                    creator = #{creator,jdbcType=INTEGER},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=DATE},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=DATE},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.engine.organization.entity.hrmresource.po.JclOrgCustomTemplatePO">
        update jcl_org_custom_template
        set 
            name =  #{name,jdbcType=VARCHAR},
            basic_fields =  #{basicFields,jdbcType=VARCHAR},
            personal_fields =  #{personalFields,jdbcType=VARCHAR},
            work_fields =  #{workFields,jdbcType=VARCHAR},
            isused =  #{isused,jdbcType=INTEGER},
            creator =  #{creator,jdbcType=INTEGER},
            create_time =  #{createTime,jdbcType=DATE},
            update_time =  #{updateTime,jdbcType=DATE}
        where   id = #{id,jdbcType=INTEGER} 
    </update>

    <select id="listAllId" resultType="java.lang.Long">
        select t.id from jcl_org_custom_template t
    </select>

    <delete id="deleteByIds">
        delete from jcl_org_custom_template where id in
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateUsed" parameterType="java.lang.String">
        update JCL_ORG_CUSTOM_TEMPLATE set isused = #{isused}
        <where>
            <if test="id !=null">
                id = #{id}
            </if>
            <if test="creator !=null">
                and creator = #{creator}
            </if>
        </where>
    </update>

    <select id="queryIsusedTemp" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from JCL_ORG_CUSTOM_TEMPLATE t where t.isused = #{isused} and t.creator = #{creator}
    </select>

</mapper>
