<?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.salary.mapper.setting.PageListTemplateMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.setting.po.PageListTemplatePO">
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="id" property="id"/>
        <result column="limit_ids" property="limitIds" typeHandler="com.engine.salary.handle.LongListTypeHandler"/>
        <result column="name" property="name"/>
        <result column="page" property="page"/>
        <result column="setting" property="setting" typeHandler="com.engine.salary.handle.SalaryListTypeHandler"/>
        <result column="shared_type" property="sharedType"/>
        <result column="system_type" property="systemType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
        <result column="file_id" property="fileId"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        create_time
        , t.creator
        , t.delete_type
        , t.id
        , t.limit_ids
        , t.name
        , t.page
        , t.setting
        , t.shared_type
        , t.system_type
        , t.tenant_key
        , t.update_time
        , t.file_id
    </sql>

    <!-- 查询全部 -->
    <select id="listAll" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_page_list_template t
        WHERE delete_type = 0
    </select>

    <!-- 根据主键获取单条记录 -->
    <select id="getById" resultMap="BaseResultMap" parameterType="Long">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_page_list_template t
        WHERE id = #{id} AND delete_type = 0
    </select>

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.setting.po.PageListTemplatePO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_page_list_template t
        WHERE delete_type = 0
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="name != null">
            AND name = #{name}
        </if>
        <if test="page != null">
            AND page = #{page}
        </if>
        <if test="fileId != null">
            AND file_id = #{fileId}
        </if>
        <if test="setting != null">
            AND setting = #{setting}
        </if>
        <if test="sharedType != null">
            AND shared_type = #{sharedType}
        </if>
        <if test="systemType != null">
            AND system_type = #{systemType}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>


    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.setting.po.PageListTemplatePO">
        INSERT INTO hrsa_page_list_template
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="limitIds != null">
                limit_ids,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="page != null">
                page,
            </if>
            <if test="setting != null">
                setting,
            </if>
            <if test="sharedType != null">
                shared_type,
            </if>
            <if test="systemType != null">
                system_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="fileId != null">
                file_id,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="limitIds != null">
                #{limitIds, jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="page != null">
                #{page},
            </if>
            <if test="setting != null">
                #{setting , jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            </if>
            <if test="sharedType != null">
                #{sharedType},
            </if>
            <if test="systemType != null">
                #{systemType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="fileId != null">
                #{fileId},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.setting.po.PageListTemplatePO">
        UPDATE hrsa_page_list_template
        <set>
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            limit_ids=#{limitIds, jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            name=#{name},
            page=#{page},
            setting=#{setting, jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            shared_type=#{sharedType},
            system_type=#{systemType},
            tenant_key=#{tenantKey},
            update_time=#{updateTime},
            file_id=#{fileId},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.setting.po.PageListTemplatePO">
        UPDATE hrsa_page_list_template
        <set>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="limitIds != null">
                limit_ids=#{limitIds, jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            </if>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="page != null">
                page=#{page},
            </if>
            <if test="setting != null">
                setting=#{setting, jdbcType=ARRAY, typeHandler=com.engine.salary.handle.SalaryListTypeHandler},
            </if>
            <if test="sharedType != null">
                shared_type=#{sharedType},
            </if>
            <if test="systemType != null">
                system_type=#{systemType},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            file_id=#{fileId},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete">
        UPDATE hrsa_page_list_template
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

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


</mapper>