<?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.yifu.cloud.plus.v1.yifu.archives.mapper.TProveRecordMapper">
    <resultMap id="tProveRecordMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TProveRecord">
        <id property="id" column="id"/>
        <result property="employeeInfo" column="employee_info"/>
        <result property="creatUser" column="creat_user"/>
        <result property="creatDate" column="creat_date"/>
        <result property="startMonth" column="start_month"/>
        <result property="endMonth" column="end_month"/>
        <result property="salary" column="salary"/>
        <result property="proveSalary" column="prove_salary"/>
        <result property="isInvalid" column="is_invalid"/>
        <result property="invalidReason" column="invalid_reason"/>
        <result property="no" column="no"/>
        <result property="purpose" column="purpose"/>
        <result property="sumType" column="sum_type"/>
        <result property="proveType" column="prove_type"/>
        <result property="number" column="number"/>
        <result property="unitName" column="unit_name"/>
        <result property="unitAddr" column="unit_addr"/>
        <result property="phone" column="phone"/>
        <result property="employeeIdCard" column="EMPLOYEE_ID_CARD"/>
        <result property="employeeName" column="EMPLOYEE_NAME"/>
        <result property="employeeSettleDepartName" column="EMPLOYEE_SETTLE_DEPART_NAME"/>
        <result property="creatUserName" column="CREAT_USER_NAME"/>
    </resultMap>
    <sql id="Base_Column_List">
             a.id,
             a.employee_info,
             a.creat_user,
             a.creat_date,
             a.start_month,
             a.end_month,
             a.salary,
             a.prove_salary,
             a.is_invalid,
             a.invalid_reason,
             a.no,
             a.purpose,
             a.sum_type,
             a.prove_type,
             a.number,
             a.unit_name,
             a.unit_addr,
             a.phone,
             a.EMPLOYEE_ID_CARD,
             a.EMPLOYEE_NAME,
             a.EMPLOYEE_SETTLE_DEPART_NAME,
             a.CREAT_USER_NAME

         </sql>
    <sql id="tProveRecord_where">
        <if test="tProveRecord != null">
			<if test="tProveRecord.idList != null and tProveRecord.idList.size>0">
				AND a.id in
				<foreach item="idStr" index="index" collection="tProveRecord.idList" open="(" separator="," close=")">
					#{idStr}
				</foreach>
			</if>
            <if test="tProveRecord.creatUser != null">
                AND a.creat_user = #{tProveRecord.creatUser}
            </if>
            <if test="tProveRecord.employeeIdCard != null and tProveRecord.employeeIdCard.trim() != ''">
                AND a.EMPLOYEE_ID_CARD like '%${tProveRecord.employeeIdCard}%'
            </if>
            <if test="tProveRecord.employeeName != null and tProveRecord.employeeName.trim() != ''">
                AND a.EMPLOYEE_NAME like '%${tProveRecord.employeeName}%'
            </if>
            <if test="tProveRecord.creatDate != null">
                AND a.creat_date = #{tProveRecord.creatDate}
            </if>
            <if test="tProveRecord.startMonth != null and tProveRecord.startMonth.trim() != ''">
                AND a.start_month = #{tProveRecord.startMonth}
            </if>
            <if test="tProveRecord.endMonth != null and tProveRecord.endMonth.trim() != ''">
                AND a.end_month = #{tProveRecord.endMonth}
            </if>
            <if test="tProveRecord.salary != null">
                AND a.salary = #{tProveRecord.salary}
            </if>
            <if test="tProveRecord.proveSalary != null">
                AND a.prove_salary = #{tProveRecord.proveSalary}
            </if>
            <if test="tProveRecord.isInvalid != null">
                AND a.is_invalid = #{tProveRecord.isInvalid}
            </if>
            <if test="tProveRecord.invalidReason != null and tProveRecord.invalidReason.trim() != ''">
                AND a.invalid_reason = #{tProveRecord.invalidReason}
            </if>
            <if test="tProveRecord.no != null and tProveRecord.no.trim() != ''">
                AND a.no = #{tProveRecord.no}
            </if>
            <if test="tProveRecord.purpose != null and tProveRecord.purpose.trim() != ''">
                AND a.purpose = #{tProveRecord.purpose}
            </if>
            <if test="tProveRecord.sumType != null">
                AND a.sum_type = #{tProveRecord.sumType}
            </if>
            <if test="tProveRecord.proveType != null">
                AND a.prove_type = #{tProveRecord.proveType}
            </if>
            <if test="tProveRecord.number != null">
                AND a.number = #{tProveRecord.number}
            </if>
            <if test="tProveRecord.unitName != null and tProveRecord.unitName.trim() != ''">
                AND a.unit_name = #{tProveRecord.unitName}
            </if>
            <if test="tProveRecord.unitAddr != null and tProveRecord.unitAddr.trim() != ''">
                AND a.unit_addr = #{tProveRecord.unitAddr}
            </if>
            <if test="tProveRecord.phone != null and tProveRecord.phone.trim() != ''">
                AND a.phone = #{tProveRecord.phone}
            </if>
        </if>
    </sql>
    <!--tProveRecord简单分页查询-->
    <select id="getTProveRecordPage" resultMap="tProveRecordMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_prove_record a
        <where>
            1=1
            <include refid="tProveRecord_where"/>
        </where>
		order by a.creat_date desc
    </select>

	<!--导出查条数-->
	<select id="getCountByExport" resultType="java.lang.Integer">
		SELECT
			count(1)
		FROM t_prove_record a
		<where>
			1=1
			<include refid="tProveRecord_where"/>
		</where>
	</select>

    <!--导出list-->
    <select id="getRecordInfoNoPage" resultMap="tProveRecordMap">
        SELECT
			a.id,
			a.creat_date,
			a.start_month,
			a.end_month,
			a.salary,
			a.prove_salary,
			if(a.is_invalid='0','否','是') as is_invalid,
			a.invalid_reason,
			a.no,
			a.purpose,
			if(a.sum_type='0','实发平均','应发平均') as sum_type,
			if(a.prove_type='0','正式员工证明','试用期员工证明') as prove_type,
			a.number,
			a.unit_name,
			a.unit_addr,
			a.phone,
			a.EMPLOYEE_ID_CARD,
			a.EMPLOYEE_NAME,
			a.EMPLOYEE_SETTLE_DEPART_NAME,
			a.CREAT_USER_NAME
        FROM t_prove_record a
        <where>
            1=1
            <include refid="tProveRecord_where"/>
        </where>
		order by a.creat_date desc
		<if test="tProveRecord != null">
			<if test="tProveRecord.limitStart != null">
				limit #{tProveRecord.limitStart},#{tProveRecord.limitEnd}
			</if>
		</if>
    </select>
    <select id="createNo" resultType="java.lang.Integer">
      select max(right(a.`no`,5))+1 from t_prove_record a where a.`no` like '${str}%'
    </select>
</mapper>
