<?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.willalp.salary.mapper.HsSalarySlipMapper">

    <resultMap type="com.willalp.salary.domain.HsSalarySlip" id="HsSalarySlipResult">
        <result property="id" column="id"/>
        <result property="source" column="source"/>
        <result property="userCode" column="user_code"/>
        <result property="userWorkNum" column="user_work_num"/>
        <result property="userName" column="user_name"/>
        <result property="payDate" column="pay_date"/>
        <result property="salary" column="salary"/>
        <result property="fsalary" column="fsalary"/>
        <result property="paySlipStatus" column="pay_slip_status"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsSalarySlipVo">
        select id,
               source,
               user_code,
               user_work_num,
               user_name,
               pay_date,
               salary,
               fsalary,
               pay_slip_status,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_salary_slip
    </sql>
    <update id="updateAllPushStatus">
        update hs_salary_slip
        set pay_slip_status = '2'
        WHERE is_delete = 0
    </update>

    <select id="selectHsSalarySlipList" parameterType="HsSalarySlip" resultMap="HsSalarySlipResult">
        <include refid="selectHsSalarySlipVo"/>
        <where>
            is_delete = 0 AND source = #{source}
            <if test="userCode != null  and userCode != ''">
                and user_code like concat('%', #{userCode}, '%')
            </if>
            <if test="userWorkNum != null  and userWorkNum != ''">
                and user_work_num like concat('%', #{userWorkNum}, '%')
            </if>
            <if test="userName != null  and userName != ''">
                and user_name like concat('%', #{userName}, '%')
            </if>
            <if test="payDate != null and payDate != ''">
                and pay_date = #{pay_date}
            </if>
            <if test="salary != null ">
                and salary = #{salary}
            </if>
            <if test="fsalary != null ">
                and fsalary = #{fsalary}
            </if>
            <if test="paySlipStatus != null  and paySlipStatus != ''">
                and pay_slip_status = #{paySlipStatus}
            </if>
            <if test="isDelete != null ">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>
    <select id="excelList" resultType="com.willalp.salary.domain.HsSalarySlip">
        SELECT id,
               source,
               pay_date
        FROM hs_salary_slip
        GROUP BY source
    </select>
</mapper>
