<?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.kakarote.hrm.mapper.HrmSalaryArchivesMapper">

    <select id="querySalaryArchivesList" resultType="com.kakarote.hrm.entity.VO.QuerySalaryArchivesListVO">
        select a.employee_id,
        a.employee_name,
        a.job_number,
        a.dept_id,
        b.name as deptName,
        a.post,
        a.status,
        date_format(a.entry_time, '%Y-%m-%d') as entry_time,
        date_format(a.become_time, '%Y-%m-%d') as become_time,
        c.change_reason,
        ifnull(c.change_type,0) as change_type,
        date_format(c.change_data, '%Y-%m-%d') as change_data,
        sum(d.value) as total
        from wk_hrm_employee a
        left join wk_hrm_dept b on a.dept_id = b.dept_id
        left join wk_hrm_salary_archives c on a.employee_id = c.employee_id
        left join wk_hrm_salary_archives_option d on a.employee_id = d.employee_id and if(a.status != 2,d.is_pro
        =0,d.is_pro = 1)
        where a.is_del = 0
        <choose>
            <when test="employeeIds != null and employeeIds.size >0">
                and a.employee_id in
                <foreach collection="employeeIds" index="index" item="employeeId" open="(" close=")" separator=",">
                    #{employeeId}
                </foreach>
            </when>
            <when test="employeeIds != null and employeeIds.size == 0">
                and 1=2
            </when>
        </choose>
        <if test="data.search != null and data.search != ''">
            and (a.employee_name like concat('%',#{data.search},'%') or a.job_number like
            concat('%',#{data.search},'%'))
        </if>
        <if test="data.deptId != null and data.deptId != ''">
            and a.dept_id = #{data.deptId}
        </if>
        <if test="data.post != null and data.post != ''">
            and a.post = #{data.post}
        </if>
        <if test="data.status != null and data.status != '' and data.status != 11 and data.status != 12 and data.status != 13 and data.status != 14 and data.status != 15">
            and a.status = #{data.status} and a.entry_status in (1,3)
        </if>
        <if test="data.status == '11'">
            and a.entry_status in (1,3)
        </if>
        <if test="data.status == '12'">
            and a.status in (1,2) and a.entry_status in (1,3)
        </if>
        <if test="data.status == '13'">
            and a.entry_status = 2
        </if>
        <if test="data.status == '14'">
            and a.entry_status = 3
        </if>
        <if test="data.status == '15'">
            and a.entry_status = 4
        </if>
        <if test="data.changeType != null and data.changeType != ''">
            <choose>
                <when test="data.changeType == 0">
                    and (c.change_type is null or c.change_type = 0)
                </when>
                <otherwise>
                    and c.change_type = #{data.changeType}
                </otherwise>
            </choose>
        </if>
        group by a.employee_id
    </select>
    <select id="queryChangeRecordList" resultType="com.kakarote.hrm.entity.VO.QueryChangeRecordListVO">
        select id
             , employee_id
             , record_type
             , change_reason
             , date_format(enable_date, '%Y-%m-%d') as enable_date
             , status
             , before_total
             , after_total
             , remarks
        from wk_hrm_salary_change_record
        where employee_id = #{employeeId}
        order by create_time desc
    </select>
    <select id="queryBatchChangeOption" resultType="com.kakarote.hrm.entity.VO.ChangeSalaryOptionVO">
        select code, name
        from wk_hrm_salary_option
        where parent_code = 10
    </select>
    <select id="queryFixSalaryExcelExportOption" resultType="com.kakarote.hrm.entity.DTO.ExcelTemplateOption">
        select code, parent_code, name
        from wk_hrm_salary_option
        where code between 10 and 90
           or parent_code between 10 and 90
    </select>
    <select id="queryChangeSalaryExcelExportOption"
            resultType="com.kakarote.hrm.entity.DTO.ExcelTemplateOption">
        select code, parent_code, name
        from wk_hrm_salary_option
        where parent_code between 10 and 90
    </select>
</mapper>
