<?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.archive.SalaryArchiveItemMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        <result column="id" property="id"/>
        <result column="salary_archive_id" property="salaryArchiveId"/>
        <result column="employee_id" property="employeeId"/>
        <result column="effective_time" property="effectiveTime"/>
        <result column="adjust_reason" property="adjustReason"/>
        <result column="salary_item_id" property="salaryItemId"/>
        <result column="item_value" property="itemValue"/>
        <result column="description" property="description"/>
        <result column="operator" property="operator"/>
        <result column="operate_time" property="operateTime"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.salary_archive_id
        , t.employee_id
        , t.effective_time
        , t.adjust_reason
        , t.salary_item_id
        , t.item_value
        , t.description
        , t.operator
        , t.operate_time
        , t.create_time
        , t.update_time
        , t.creator
        , t.delete_type
        , t.tenant_key
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_archive_item t
        WHERE delete_type = 0
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="salaryArchiveId != null">
            AND salary_archive_id = #{salaryArchiveId}
        </if>
        <if test="employeeId != null">
            AND employee_id = #{employeeId}
        </if>
        <if test="effectiveTime != null">
            AND effective_time = #{effectiveTime}
        </if>
        <if test="adjustReason != null">
            AND adjust_reason = #{adjustReason}
        </if>
        <if test="salaryItemId != null">
            AND salary_item_id = #{salaryItemId}
        </if>
        <if test="itemValue != null">
            AND item_value = #{itemValue}
        </if>
        <if test="description != null">
            AND description = #{description}
        </if>
        <if test="operator != null">
            AND operator = #{operator}
        </if>
        <if test="operateTime != null">
            AND operate_time = #{operateTime}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </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.salaryarchive.po.SalaryArchiveItemPO"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_salary_archive_item
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="salaryArchiveId != null">
                salary_archive_id,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="effectiveTime != null">
                effective_time,
            </if>
            <if test="adjustReason != null">
                adjust_reason,
            </if>
            <if test="salaryItemId != null">
                salary_item_id,
            </if>
            <if test="itemValue != null">
                item_value,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="operator != null">
                operator,
            </if>
            <if test="operateTime != null">
                operate_time,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="salaryArchiveId != null">
                #{salaryArchiveId},
            </if>
            <if test="employeeId != null">
                #{employeeId},
            </if>
            <if test="effectiveTime != null">
                #{effectiveTime},
            </if>
            <if test="adjustReason != null">
                #{adjustReason},
            </if>
            <if test="salaryItemId != null">
                #{salaryItemId},
            </if>
            <if test="itemValue != null">
                #{itemValue},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="operator != null">
                #{operator},
            </if>
            <if test="operateTime != null">
                #{operateTime},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO"
            databaseId="oracle"
    >
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            select hrsa_salary_archive_item_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_salary_archive_item
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="salaryArchiveId != null">
                salary_archive_id,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="effectiveTime != null">
                effective_time,
            </if>
            <if test="adjustReason != null">
                adjust_reason,
            </if>
            <if test="salaryItemId != null">
                salary_item_id,
            </if>
            <if test="itemValue != null">
                item_value,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="operator != null">
                operator,
            </if>
            <if test="operateTime != null">
                operate_time,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="salaryArchiveId != null">
                #{salaryArchiveId},
            </if>
            <if test="employeeId != null">
                #{employeeId},
            </if>
            <if test="effectiveTime != null">
                #{effectiveTime},
            </if>
            <if test="adjustReason != null">
                #{adjustReason},
            </if>
            <if test="salaryItemId != null">
                #{salaryItemId},
            </if>
            <if test="itemValue != null">
                #{itemValue},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="operator != null">
                #{operator},
            </if>
            <if test="operateTime != null">
                #{operateTime},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        UPDATE hrsa_salary_archive_item
        <set>
            salary_archive_id=#{salaryArchiveId},
            employee_id=#{employeeId},
            effective_time=#{effectiveTime},
            adjust_reason=#{adjustReason},
            salary_item_id=#{salaryItemId},
            item_value=#{itemValue},
            description=#{description},
            operator=#{operator},
            operate_time=#{operateTime},
            create_time=#{createTime},
            update_time=#{updateTime},
            creator=#{creator},
            delete_type=#{deleteType},
            tenant_key=#{tenantKey},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        UPDATE hrsa_salary_archive_item
        <set>
            <if test="salaryArchiveId != null">
                salary_archive_id=#{salaryArchiveId},
            </if>
            <if test="employeeId != null">
                employee_id=#{employeeId},
            </if>
            <if test="effectiveTime != null">
                effective_time=#{effectiveTime},
            </if>
            <if test="adjustReason != null">
                adjust_reason=#{adjustReason},
            </if>
            <if test="salaryItemId != null">
                salary_item_id=#{salaryItemId},
            </if>
            <if test="itemValue != null">
                item_value=#{itemValue},
            </if>
            <if test="description != null">
                description=#{description},
            </if>
            <if test="operator != null">
                operator=#{operator},
            </if>
            <if test="operateTime != null">
                operate_time=#{operateTime},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        UPDATE hrsa_salary_archive_item
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>


    <insert id="batchInsert">
        INSERT INTO hrsa_salary_archive_item (
        salary_archive_id,
        employee_id,
        effective_time,
        adjust_reason,
        salary_item_id,
        item_value,
        description,
        operator,
        operate_time,
        create_time,
        update_time,
        creator,
        tenant_key
        )
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (
            #{item.salaryArchiveId},
            #{item.employeeId},
            #{item.effectiveTime},
            #{item.adjustReason},
            #{item.salaryItemId},
            #{item.itemValue},
            #{item.description},
            #{item.operator},
            #{item.operateTime},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey}
            )
        </foreach>
    </insert>
    <insert id="batchInsert" databaseId="oracle">
        INSERT INTO hrsa_salary_archive_item (
        salary_archive_id,
        employee_id,
        effective_time,
        adjust_reason,
        salary_item_id,
        item_value,
        description,
        operator,
        operate_time,
        create_time,
        update_time,
        creator,
        tenant_key
        )

        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.salaryArchiveId,jdbcType=DOUBLE},
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.effectiveTime,jdbcType=DATE},
            #{item.adjustReason,jdbcType=VARCHAR},
            #{item.salaryItemId,jdbcType=DOUBLE},
            #{item.itemValue,jdbcType=VARCHAR},
            #{item.description,jdbcType=VARCHAR},
            #{item.operator,jdbcType=DOUBLE},
            #{item.operateTime,jdbcType=DATE},
            #{item.createTime,jdbcType=DATE},
            #{item.updateTime,jdbcType=DATE},
            #{item.creator,jdbcType=DOUBLE},
            #{item.tenantKey,jdbcType=VARCHAR}
            from dual
        </foreach>
    </insert>
    <insert id="batchInsert" databaseId="sqlserver">
        <foreach collection="collection" item="item" separator=";">
            INSERT INTO hrsa_salary_archive_item (
            salary_archive_id,
            employee_id,
            effective_time,
            adjust_reason,
            salary_item_id,
            item_value,
            description,
            operator,
            operate_time,
            create_time,
            update_time,
            creator,
            tenant_key
            )
            VALUES
            (
            #{item.salaryArchiveId},
            #{item.employeeId},
            #{item.effectiveTime},
            #{item.adjustReason},
            #{item.salaryItemId},
            #{item.itemValue},
            #{item.description},
            #{item.operator},
            #{item.operateTime},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey}
            )
        </foreach>
    </insert>

    <sql id="salaryArchiveItemColumn">
        id,
        salary_archive_id,
        employee_id,
        effective_time,
        adjust_reason,
        salary_item_id,
        item_value,
        description,
        operator,
        operate_time,
        create_time,
        update_time,
        creator,
        tenant_key
    </sql>


    <select id="salaryItemAdjustRecordList"
            resultType="com.engine.salary.entity.salaryarchive.dto.SalaryItemAdjustRecordListDTO">
        SELECT
        <include refid="salaryItemAdjustRecordColumn"/>
        FROM hrsa_salary_archive_item t1
        LEFT JOIN hrmresource o ON o.id = t1.operator
        LEFT JOIN hrsa_salary_item t2 ON t2.id = t1.salary_item_id
        WHERE
        t1.delete_type = 0
        <if test="salaryItemIds != null and salaryItemIds.size()>0">
            AND t1.salary_item_id IN
            <foreach collection="salaryItemIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.adjustItem != null and param.adjustItem != ''">
            AND t2.name like CONCAT('%',#{param.adjustItem},'%')
        </if>
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!--员工id,用于查询个人调薪记录-->
        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>
        <!-- 薪资档案id -->
        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>
        <if test="param.salaryArchiveIds != null and param.salaryArchiveIds.size()>0">
            AND t1.salary_archive_id IN
            <foreach collection="param.salaryArchiveIds" open="(" item="salaryArchiveId" separator="," close=")">
                #{salaryArchiveId}
            </foreach>
        </if>
        <!-- 调整原因 -->
        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>
        <!-- 生效日期 -->
        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>
        <!-- 操作日期 -->
        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN CONCAT(#{param.operateTime[0]},' 00:00:00') AND
            CONCAT(#{param.operateTime[1]},' 23:59:59'))
        </if>
        <!-- 操作人 -->
        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY t1.effective_time DESC,t1.id DESC
    </select>
    <select id="salaryItemAdjustRecordList"
            resultType="com.engine.salary.entity.salaryarchive.dto.SalaryItemAdjustRecordListDTO" databaseId="oracle">
        SELECT

        t1.id,
        t1.employee_id,
        t1.effective_time,
        t1.adjust_reason,
        t2.name AS adjust_item,
        t1.item_value AS adjust_after,
        o.lastname AS operator,
        t1.operate_time,
        t1.description,
        t1.salary_archive_id,
        t1.salary_item_id

        FROM hrsa_salary_archive_item t1
        LEFT JOIN hrmresource o ON o.id = t1.operator
        LEFT JOIN hrsa_salary_item t2 ON t2.id = t1.salary_item_id
        WHERE
        t1.delete_type = 0
        <if test="salaryItemIds != null and salaryItemIds.size()>0">
            AND t1.salary_item_id IN
            <foreach collection="salaryItemIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="param.adjustItem != null and param.adjustItem != ''">
            AND t2.name like '%'||#{param.adjustItem}||'%'
        </if>

        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>
        <if test="param.salaryArchiveIds != null and param.salaryArchiveIds.size()>0">
            AND t1.salary_archive_id IN
            <foreach collection="param.salaryArchiveIds" open="(" item="salaryArchiveId" separator="," close=")">
                #{salaryArchiveId}
            </foreach>
        </if>
        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>

        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>

        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN #{param.operateTime[0]}||' 00:00:00' AND #{param.operateTime[1]}||' 23:59:59' )
        </if>

        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.description != null and param.description != ''">
            AND t1.description like '%'||#{param.description}||'%'
        </if>

        ORDER BY t1.effective_time DESC,t1.id DESC
    </select>
    <select id="salaryItemAdjustRecordList"
            resultType="com.engine.salary.entity.salaryarchive.dto.SalaryItemAdjustRecordListDTO"
            databaseId="sqlserver">
        SELECT

        t1.id,
        t1.employee_id,
        t1.effective_time,
        t1.adjust_reason,
        t2.name AS adjust_item,
        t1.item_value AS adjust_after,
        o.lastname AS operator,
        t1.operate_time,
        t1.description,
        t1.salary_archive_id,
        t1.salary_item_id

        FROM hrsa_salary_archive_item t1
        LEFT JOIN hrmresource o ON o.id = t1.operator
        LEFT JOIN hrsa_salary_item t2 ON t2.id = t1.salary_item_id
        WHERE
        t1.delete_type = 0
        <if test="salaryItemIds != null and salaryItemIds.size()>0">
            AND t1.salary_item_id IN
            <foreach collection="salaryItemIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.adjustItem != null and param.adjustItem != ''">
            AND t2.name like '%'+#{param.adjustItem}+'%'
        </if>

        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>

        <if test="param.salaryArchiveIds != null and param.salaryArchiveIds.size()>0">
            AND t1.salary_archive_id IN
            <foreach collection="param.salaryArchiveIds" open="(" item="salaryArchiveId" separator="," close=")">
                #{salaryArchiveId}
            </foreach>
        </if>

        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>

        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>

        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN #{param.operateTime[0]}+' 00:00:00' AND #{param.operateTime[1]}+' 23:59:59' )
        </if>

        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY t1.effective_time DESC,t1.id DESC
    </select>

    <sql id="salaryItemAdjustRecordColumn">
        t1.id,
        t1.employee_id,
        t1.effective_time,
        t1.adjust_reason,
        t2.name AS adjust_item,
        t1.item_value AS adjust_after,
        o.lastname AS operator,
        t1.operate_time,
        t1.description,
        t1.salary_archive_id,
        t1.salary_item_id
    </sql>

    <sql id="paramSql">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!--员工id,用于查询个人调薪记录-->
        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>
        <!-- 薪资档案id -->
        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>
        <!-- 姓名 -->
        <if test="param.username != null and param.username != ''">
            AND e.lastname like CONCAT('%',#{param.username},'%')
        </if>
        <!-- 岗位 -->
        <if test="param.positionIds != null and param.positionIds.size()>0">
            AND e.jobtitle IN
            <foreach collection="param.positionIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 状态 -->
        <if test="param.userstatus != null and param.userstatus != ''">
            AND e.status = #{param.userstatus}
        </if>
        <!-- 部门 -->
        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 调整原因 -->
        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>
        <!-- 生效日期 -->
        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>
        <!-- 操作日期 -->
        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN CONCAT(#{param.operateTime[0]},' 00:00:00') AND
            CONCAT(#{param.operateTime[1]},' 23:59:59'))
        </if>
        <!-- 操作人 -->
        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 备注 -->
        <if test="param.description != null and param.description != ''">
            AND t1.description like CONCAT('%',#{param.description},'%')
        </if>
    </sql>
    <sql id="paramSql" databaseId="oracle">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>

        <if test="param.username != null and param.username != ''">
            AND e.lastname like '%'||#{param.username}||'%'
        </if>

        <if test="param.positionIds != null and param.positionIds.size()>0">
            AND e.jobtitle IN
            <foreach collection="param.positionIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.userstatus != null and param.userstatus != ''">
            AND e.status = #{param.userstatus}
        </if>

        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>

        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>

        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN #{param.operateTime[0]}||' 00:00:00' AND #{param.operateTime[1]}||' 23:59:59' )
        </if>

        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.description != null and param.description != ''">
            AND t1.description like '%'||#{param.description}||'%'
        </if>
    </sql>
    <sql id="paramSql" databaseId="sqlserver">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.employeeId != null">
            AND t1.employee_id = #{param.employeeId}
        </if>

        <if test="param.salaryArchiveId != null">
            AND t1.salary_archive_id = #{param.salaryArchiveId}
        </if>

        <if test="param.username != null and param.username != ''">
            AND e.lastname like '%'+#{param.username}+'%'
        </if>

        <if test="param.positionIds != null and param.positionIds.size()>0">
            AND e.jobtitle IN
            <foreach collection="param.positionIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.userstatus != null and param.userstatus != ''">
            AND e.status = #{param.userstatus}
        </if>

        <if test="param.departmentIds != null and param.departmentIds.size()>0">
            AND d.id IN
            <foreach collection="param.departmentIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.adjustReason != null and param.adjustReason != ''">
            AND t1.adjust_reason = #{param.adjustReason}
        </if>

        <if test="param.effectiveTime != null and param.effectiveTime.size() == 2">
            AND (t1.effective_time BETWEEN #{param.effectiveTime[0]} AND #{param.effectiveTime[1]})
        </if>

        <if test="param.operateTime != null and param.operateTime.size() == 2">
            AND (t1.operate_time BETWEEN #{param.operateTime[0]}+' 00:00:00' AND #{param.operateTime[1]}+' 23:59:59' )
        </if>

        <if test="param.operatorIds != null and param.operatorIds.size()>0">
            AND t1.operator IN
            <foreach collection="param.operatorIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.description != null and param.description != ''">
            AND t1.description like '%'+#{param.description}+'%'
        </if>
    </sql>


    <!-- 条件查询 -->
    <select id="listByParam" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_archive_item t
        WHERE delete_type = 0
        <if test="param.effectiveTime != null">
            AND t.effective_time &lt;= #{param.effectiveTime}
        </if>
        <if test="param.salaryItemIds != null and param.salaryItemIds.size()>0">
            AND t.salary_item_id IN
            <foreach collection="param.salaryItemIds" open="(" item="salaryItemId" separator="," close=")">
                #{salaryItemId}
            </foreach>
        </if>
        <if test="param.salaryArchivesIds != null and param.salaryArchivesIds.size()>0">
            AND t.salary_archive_id IN
            <foreach collection="param.salaryArchivesIds" open="(" item="salaryArchiveId" separator="," close=")">
                #{salaryArchiveId}
            </foreach>
        </if>
        <if test="param.employeeIds != null and param.employeeIds.size()>0">
            AND t.employee_id IN
            <foreach collection="param.employeeIds" open="(" item="employeeId" separator="," close=")">
                #{employeeId}
            </foreach>
        </if>
        ORDER BY t.effective_time DESC
    </select>

    <select id="getIneffectiveSalaryItems" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_archive_item t
        WHERE delete_type = 0
        <if test="param.effectiveTime != null">
            AND t.effective_time &gt; #{param.effectiveTime}
        </if>
        <if test="param.salaryItemIds != null and param.salaryItemIds.size()>0">
            AND (t.salary_item_id IN
            <!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
            <trim suffixOverrides=" OR t.salary_item_id IN()">
                <foreach collection="param.salaryItemIds " item="Id" index="index" open="(" close=")">
                    <if test="index != 0">
                        <choose>
                            <when test="index % 1000 == 999">) OR t.salary_item_id IN (</when>
                            <otherwise>,</otherwise>
                        </choose>
                    </if>
                    #{Id}
                </foreach>
            </trim>
            )
        </if>
        <if test="param.salaryArchiveId != null">
            AND t.salary_archive_id = #{param.salaryArchiveId}
        </if>
        <if test="param.salaryArchivesIds != null and param.salaryArchivesIds.size()>0">
            AND (t.salary_archive_id IN
            <!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
            <trim suffixOverrides=" OR t.salary_archive_id IN()">
                <foreach collection="param.salaryArchivesIds " item="Id" index="index" open="(" close=")">
                    <if test="index != 0">
                        <choose>
                            <when test="index % 1000 == 999">) OR t.salary_archive_id IN (</when>
                            <otherwise>,</otherwise>
                        </choose>
                    </if>
                    #{Id}
                </foreach>
            </trim>
            )
        </if>
        <if test="param.salaryItemId != null">
            AND t.salary_item_id = #{param.salaryItemId}
        </if>
        ORDER BY t.effective_time DESC
    </select>

    <select id="getEffectiveSalaryItems" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_archive_item t
        WHERE delete_type = 0
        <if test="param.effectiveTime != null">
            AND t.effective_time &lt;= #{param.effectiveTime}
        </if>
        <if test="param.salaryItemIds != null and param.salaryItemIds.size()>0">
            AND (t.salary_item_id IN
            <!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
            <trim suffixOverrides=" OR t.salary_item_id IN()">
                <foreach collection="param.salaryItemIds " item="Id" index="index" open="(" close=")">
                    <if test="index != 0">
                        <choose>
                            <when test="index % 1000 == 999">) OR t.salary_item_id IN (</when>
                            <otherwise>,</otherwise>
                        </choose>
                    </if>
                    #{Id}
                </foreach>
            </trim>
            )
        </if>
        <if test="param.salaryArchivesIds != null and param.salaryArchivesIds.size()>0">
            AND (t.salary_archive_id IN
            <!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
            <trim suffixOverrides=" OR t.salary_archive_id IN()">
                <foreach collection="param.salaryArchivesIds " item="Id" index="index" open="(" close=")">
                    <if test="index != 0">
                        <choose>
                            <when test="index % 1000 == 999">) OR t.salary_archive_id IN (</when>
                            <otherwise>,</otherwise>
                        </choose>
                    </if>
                    #{Id}
                </foreach>
            </trim>
            )
        </if>
        <if test="param.salaryArchiveId != null">
            AND t.salary_archive_id = #{param.salaryArchiveId}
        </if>
        ORDER BY t.effective_time DESC
    </select>

    <select id="listByArchiveIdAndEffectiveTime"
            resultType="com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_archive_item t
        WHERE delete_type = 0
        <if test="effectiveRange != null and effectiveRange.fromDate != null">
            AND t.effective_time <![CDATA[ >= ]]> #{effectiveRange.fromDate}
        </if>
        <if test="effectiveRange != null and effectiveRange.endDate != null">
            AND t.effective_time <![CDATA[ <= ]]> #{effectiveRange.endDate}
        </if>
        <if test="salaryArchivesIds != null and salaryArchivesIds.size()>0">
            AND t.salary_archive_id IN
            <foreach collection="salaryArchivesIds" open="(" item="salaryArchiveId" separator="," close=")">
                #{salaryArchiveId}
            </foreach>
        </if>

        ORDER BY t.effective_time DESC
    </select>


    <update id="deleteBatchIds">
        UPDATE hrsa_salary_archive_item
        SET delete_type = 1
        WHERE delete_type = 0
        AND (id IN
        <!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
        <trim suffixOverrides=" OR id IN()">
            <foreach collection="effectiveSalaryItemDels " item="Id" index="index" open="(" close=")">
                <if test="index != 0">
                    <choose>
                        <when test="index % 1000 == 999">) OR id IN (</when>
                        <otherwise>,</otherwise>
                    </choose>
                </if>
                #{Id}
            </foreach>
        </trim>
        )

    </update>

    <update id="deleteBySalaryArchiveId">
        UPDATE hrsa_salary_archive_item
        SET delete_type = 1
        WHERE delete_type = 0
        AND salary_archive_id IN
        <foreach collection="salaryArchiveIds" open="(" item="salaryArchiveId" separator="," close=")">
            #{salaryArchiveId}
        </foreach>
    </update>

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

    <update id="batchUpdate" parameterType="java.util.List">
        update hrsa_salary_archive_item
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="delete_type =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.deleteType!=null">
                        when id=#{item.id} then #{item.deleteType}
                    </if>
                </foreach>
            </trim>
            <trim prefix="item_value =case" suffix="end,">
                <foreach collection="collection" item="item" index="index">
                    <if test="item.itemValue!=null">
                        when id=#{item.id} then #{item.itemValue}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        id in
        <foreach collection="collection" item="item" index="index" separator="," open="(" close=")">
            #{item.id}
        </foreach>
    </update>






    <resultMap id="configResultMap" type="com.engine.salary.entity.salaryarchive.config.ArchiveFieldConfig">
        <result column="item_id" property="id"/>
        <result column="item_name" property="name"/>
        <result column="item_code" property="code"/>
        <result column="item_system_type" property="systemType"/>
        <result column="item_sys_salary_item_id" property="sysSalaryItemId"/>
        <result column="item_use_default" property="useDefault"/>
        <result column="item_use_in_employee_salary" property="useInEmployeeSalary"/>
        <result column="item_rounding_mode" property="roundingMode"/>
        <result column="item_pattern" property="pattern"/>
        <result column="item_value_type" property="valueType"/>
        <result column="item_formula_id" property="formulaId"/>
        <result column="item_description" property="description"/>
        <result column="item_can_edit" property="canEdit"/>
        <result column="item_data_type" property="dataType"/>
        <result column="item_shared_type" property="sharedType"/>
        <result column="item_tax_agent_ids" property="taxAgentIds"/>
        <result column="item_sorted_index" property="sortedIndex"/>
        <result column="item_hide_default" property="hideDefault"/>
        <result column="item_width" property="width"/>
        <result column="item_default_value" property="defaultValue"/>
    </resultMap>


    <sql id="itemColumns">
        item.id                      as     item_id
        ,item.name                        as     item_name
        , item.code                        as     item_code
        , item.system_type                as     item_system_type
        , item.sys_salary_item_id          as     item_sys_salary_item_id
        , item.use_default                 as     item_use_default
        , item.use_in_employee_salary      as     item_use_in_employee_salary
        , item.rounding_mode               as     item_rounding_mode
        , item.pattern                     as     item_pattern
        , item.value_type                  as     item_value_type
        , item.formula_id                  as     item_formula_id
        , item.description                 as     item_description
        , item.can_edit                    as     item_can_edit
        , item.can_delete                  as     item_can_delete
        , item.data_type                   as     item_data_type
        , item.shared_type                 as     item_shared_type
        , item.tax_agent_ids               as     item_tax_agent_ids
        , item.sorted_index                as     item_sorted_index
        , item.hide_default                as     item_hide_default
        , item.width                       as     item_width
        , item.default_value               as    item_default_value
    </sql>




</mapper>