<?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.TEmployeeRetirementMapper">

	<resultMap id="BaseResultMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeRetirement">
		<id property="id" column="ID" jdbcType="VARCHAR"/>
		<result property="empName" column="EMP_NAME" jdbcType="VARCHAR"/>
		<result property="empIdcard" column="EMP_IDCARD" jdbcType="VARCHAR"/>
		<result property="empPhone" column="EMP_PHONE" jdbcType="VARCHAR"/>
		<result property="empSex" column="EMP_SEX" jdbcType="VARCHAR"/>
		<result property="empAge" column="EMP_AGE" jdbcType="INTEGER"/>
		<result property="empNatrue" column="EMP_NATRUE" jdbcType="VARCHAR"/>
		<result property="fileProvince" column="FILE_PROVINCE" jdbcType="INTEGER"/>
		<result property="fileCity" column="FILE_CITY" jdbcType="INTEGER"/>
		<result property="fileTown" column="FILE_TOWN" jdbcType="INTEGER"/>
		<result property="socialProvince" column="SOCIAL_PROVINCE" jdbcType="INTEGER"/>
		<result property="socialCity" column="SOCIAL_CITY" jdbcType="INTEGER"/>
		<result property="socialTown" column="SOCIAL_TOWN" jdbcType="INTEGER"/>
		<result property="unitName" column="UNIT_NAME" jdbcType="VARCHAR"/>
		<result property="unitNo" column="UNIT_NO" jdbcType="VARCHAR"/>
		<result property="deptName" column="DEPT_NAME" jdbcType="VARCHAR"/>
		<result property="deptNo" column="DEPT_NO" jdbcType="VARCHAR"/>
		<result property="handleFlag" column="HANDLE_FLAG" jdbcType="INTEGER"/>
		<result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
		<result property="createName" column="CREATE_NAME" jdbcType="VARCHAR"/>
		<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
		<result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
		<result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
	</resultMap>

	<sql id="Base_Column_List">
		ID,EMP_NAME,EMP_IDCARD,
        EMP_PHONE,EMP_SEX,EMP_AGE,
        EMP_NATRUE,FILE_PROVINCE,FILE_CITY,
        FILE_TOWN,SOCIAL_PROVINCE,SOCIAL_CITY,
        SOCIAL_TOWN,UNIT_NAME,
        UNIT_NO,DEPT_NAME,DEPT_NO,HANDLE_FLAG,
        CREATE_BY,CREATE_NAME,CREATE_TIME,
        UPDATE_BY,UPDATE_TIME
	</sql>


	<sql id="tEmployeeRetirement_pageWhere">

		<if test="searchVo.empName != null and searchVo.empName.trim() != ''">
			AND a.EMP_NAME like concat('%',#{searchVo.empName},'%')
		</if>
		<if test="searchVo.empIdcard != null and searchVo.empIdcard.trim() != ''">
			AND a.EMP_IDCARD like concat('%',#{searchVo.empIdcard},'%')
		</if>
		<if test="searchVo.fileProvince != null">
			AND a.FILE_PROVINCE = #{searchVo.fileProvince}
		</if>
		<if test="searchVo.fileCity != null">
			AND a.FILE_CITY = #{searchVo.fileCity}
		</if>
		<if test="searchVo.fileTown != null">
			AND a.FILE_TOWN = #{searchVo.fileTown}
		</if>
		<if test="searchVo.socialProvince != null">
			AND a.SOCIAL_PROVINCE = #{searchVo.socialProvince}
		</if>
		<if test="searchVo.socialCity != null">
			AND a.SOCIAL_CITY = #{searchVo.socialCity}
		</if>
		<if test="searchVo.socialTown != null">
			AND a.SOCIAL_TOWN = #{searchVo.socialTown}
		</if>
		<if test="searchVo.unitName!= null">
			AND a.UNIT_NAME = #{searchVo.unitName}
		</if>
		<if test="searchVo.unitNo!= null and searchVo.unitNo!=''" >
			AND a.UNIT_NO = #{searchVo.unitNo}
		</if>
		<if test="searchVo.deptName!= null">
			AND a.DEPT_NAME like concat('%',#{searchVo.deptName},'%')
		</if>
		<if test="searchVo.deptNo!= null and searchVo.deptNo!=''">
			AND a.DEPT_NO =#{searchVo.deptNo}
		</if>
		<if test="searchVo.handleFlag!= null">
			AND a.HANDLE_FLAG =#{searchVo.handleFlag}
		</if>
		<if test="searchVo.empTypeList != null and searchVo.empTypeList.length>0">
			AND a.EMP_NATRUE IN
			<foreach collection="searchVo.empTypeList" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="searchVo.idList != null and searchVo.idList.length > 0">
			and  a.ID in
			<foreach collection="searchVo.idList" item="item" index="index" open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
	</sql>

	<sql id="tEmployeeRetirement_where">
		<if test="searchVo.empName != null and searchVo.empName.trim() != ''">
			AND a.EMP_NAME like concat('%',#{searchVo.empName},'%')
		</if>
		<if test="searchVo.empIdcard != null and searchVo.empIdcard.trim() != ''">
			AND a.EMP_IDCARD like concat('%',#{searchVo.empIdcard},'%')
		</if>
		<if test="searchVo.fileProvince != null">
			AND b.FILE_PROVINCE = #{searchVo.fileProvince}
		</if>
		<if test="searchVo.fileCity != null">
			AND b.FILE_CITY = #{searchVo.fileCity}
		</if>
		<if test="searchVo.fileTown != null">
			AND b.FILE_TOWN = #{searchVo.fileTown}
		</if>
		<if test="searchVo.socialProvince != null">
			AND a.SOCIAL_PROVINCE = #{searchVo.socialProvince}
		</if>
		<if test="searchVo.socialCity != null">
			AND a.SOCIAL_CITY = #{searchVo.socialCity}
		</if>
		<if test="searchVo.socialTown != null">
			AND a.SOCIAL_TOWN = #{searchVo.socialTown}
		</if>
		<if test="searchVo.unitName!= null">
			AND a.UNIT_NAME = #{searchVo.unitName}
		</if>
		<if test="searchVo.unitNo!= null">
			AND a.UNIT_NO = #{searchVo.unitNo}
		</if>
		<if test="searchVo.deptName!= null">
			AND a.DEPT_NAME like concat('%',#{searchVo.deptName},'%')
		</if>
		<if test="searchVo.deptNo!= null">
			AND a.DEPT_NO =#{searchVo.deptNo}
		</if>
		<if test="searchVo.handleFlag!= null">
			AND a.HANDLE_FLAG =#{searchVo.handleFlag}
		</if>
		<if test="searchVo.empTypeList != null and searchVo.empTypeList.length>0">
			AND a.EMP_NATRUE IN
			<foreach collection="searchVo.empTypeList" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
	</sql>
	<select id="getTEmployeeRetirementPage" resultMap="BaseResultMap">
		SELECT
		a.ID,a.EMP_NAME,a.EMP_IDCARD,
		a.EMP_PHONE,a.EMP_SEX,a.EMP_AGE,
		a.EMP_NATRUE,a.FILE_PROVINCE,a.FILE_CITY,
		a.FILE_TOWN,a.SOCIAL_PROVINCE,a.SOCIAL_CITY,
		a.SOCIAL_TOWN,a.UNIT_NAME,
		a.UNIT_NO,a.DEPT_NAME,a.DEPT_NO,a.HANDLE_FLAG,
		a.CREATE_BY,a.CREATE_NAME,a.CREATE_TIME,
		a.UPDATE_BY,a.UPDATE_TIME
		FROM t_employee_retirement a
		 LEFT JOIN t_cutsomer_data_permisson b ON b.SETTLE_DOMAIN_NO = a.DEPT_NO
		WHERE
		b.USER_ID = #{userId}
			<if test="searchVo.empName != null and searchVo.empName.trim() != ''">
				AND a.EMP_NAME like concat('%',#{searchVo.empName},'%')
			</if>
			<if test="searchVo.empIdcard != null and searchVo.empIdcard.trim() != ''">
				AND a.EMP_IDCARD like concat('%',#{searchVo.empIdcard},'%')
			</if>
			<if test="searchVo.fileProvince != null">
				AND a.FILE_PROVINCE = #{searchVo.fileProvince}
			</if>
			<if test="searchVo.fileCity != null">
				AND a.FILE_CITY = #{searchVo.fileCity}
			</if>
			<if test="searchVo.fileTown != null">
				AND a.FILE_TOWN = #{searchVo.fileTown}
			</if>
			<if test="searchVo.socialProvince != null">
				AND a.SOCIAL_PROVINCE = #{searchVo.socialProvince}
			</if>
			<if test="searchVo.socialCity != null">
				AND a.SOCIAL_CITY = #{searchVo.socialCity}
			</if>
			<if test="searchVo.socialTown != null">
				AND a.SOCIAL_TOWN = #{searchVo.socialTown}
			</if>
			<if test="searchVo.unitName!= null">
				AND a.UNIT_NAME = #{searchVo.unitName}
			</if>
			<if test="searchVo.unitNo!= null and searchVo.unitNo!=''" >
				AND a.UNIT_NO = #{searchVo.unitNo}
			</if>
			<if test="searchVo.deptName!= null">
				AND a.DEPT_NAME like concat('%',#{searchVo.deptName},'%')
			</if>
			<if test="searchVo.deptNo!= null and searchVo.deptNo!=''">
				AND a.DEPT_NO =#{searchVo.deptNo}
			</if>
			<if test="searchVo.handleFlag!= null">
				AND a.HANDLE_FLAG =#{searchVo.handleFlag}
			</if>
			<if test="searchVo.empTypeList != null and searchVo.empTypeList.length>0">
				AND a.EMP_NATRUE IN
				<foreach collection="searchVo.empTypeList" item="item" index="index" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="searchVo.idList != null and searchVo.idList.length > 0">
				and  a.ID in
				<foreach collection="searchVo.idList" item="item" index="index" open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
		ORDER BY
		field(a.HANDLE_FLAG,0,1) asc,
		CREATE_TIME asc
	</select>
	<select id="selectByEmpIdcard" resultType="Integer">
		SELECT count(*)
		FROM t_employee_retirement a
		where EMP_IDCARD=#{empIdCard}
             and DEPT_NO=#{deptNo}
	</select>
	<select id="getBirthday" parameterType="String" resultMap="BaseResultMap">
		SELECT a.EMP_NAME,
			   a.EMP_IDCARD,
			   b.EMP_SEX,
		       (substring(now(),1,4)-substring(a.EMP_IDCARD,7,4))-(substring(a.EMP_IDCARD,11,4)-date_format(now(),'%m%d')>0) EMP_AGE,
			   b.EMP_PHONE,
			   CASE
				   WHEN MAX(a.EMP_NATRUE)=3 THEN "3"
				   WHEN MIN(a.EMP_NATRUE)=0 THEN "0"
				   WHEN MIN(a.EMP_NATRUE)=1 THEN "1"
				   ELSE a.EMP_NATRUE END as EMP_NATRUE,
			   a.UNIT_NAME,
			   a.UNIT_NO,
			   a.DEPT_NAME,
			   a.DEPT_NO,
			   b.FILE_PROVINCE,
			   b.FILE_CITY,
			   b.FILE_TOWN,
			   a.SOCIAL_PROVINCE,
			   a.SOCIAL_CITY,
			   a.SOCIAL_TOWN,
			   b.EMP_BIRTHDAY
		FROM t_employee_project a
				 LEFT JOIN t_employee_info b ON a.EMP_IDCARD = b.EMP_IDCARD
		where ((datediff(#{oo}, b.EMP_BIRTHDAY) = 0 and b.EMP_SEX = '1')
			or (datediff(#{pp}, b.EMP_BIRTHDAY) = 0 and b.EMP_SEX = '2'))
		  and b.FILE_STATUS = 0 and a.EMP_NATRUE in ('0','1','3')
		   and a.PROJECT_STATUS = 0
		   and a.DELETE_FLAG=0
		GROUP BY a.EMP_IDCARD,
				 a.DEPT_NO
	</select>

	<update id="changeHandleFlagAll" parameterType="com.yifu.cloud.plus.v1.yifu.archives.vo.ChangeHandleFlagAllVo">
		update t_employee_retirement a
		set a.HANDLE_FLAG=#{changeHandleFlagAllVo.handleFlag}
		where a.ID in
		<foreach item="idStr" index="index" collection="changeHandleFlagAllVo.ids" open="(" separator="," close=")">
			#{idStr}
		</foreach>
	</update>

	<update id="changeHandleFlag" parameterType="com.yifu.cloud.plus.v1.yifu.archives.vo.ChangeHandleFlagVo">
		update t_employee_retirement a
		set a.HANDLE_FLAG=#{changeHandleFlagVo.handleFlag}
		where a.ID = #{changeHandleFlagVo.id}
	</update>
	<insert id="add">
		insert into t_employee_retirement (EMP_NAME)
			value (#{tEmployeeRetirement.empName})
	</insert>

	<select id="selectExportCount" resultType="java.lang.Long">
		SELECT
		count(1)
		from t_employee_retirement a
		<where>
			<include refid="tEmployeeRetirement_pageWhere"/>
		</where>
	</select>
	<select id="noPageDiy" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TEmployeeRetirementExportVo">
		SELECT a.ID,
		EMP_NAME,
		EMP_IDCARD,
	    EMP_PHONE,
		CASE WHEN a.EMP_SEX=1 THEN "男"
		WHEN a.EMP_SEX =2 THEN "女"
		ELSE "" END as "EMP_SEX",
		EMP_AGE,
		CASE WHEN a.EMP_NATRUE='0' THEN "外包"
		WHEN a.EMP_NATRUE='1' THEN "派遣"
		WHEN a.EMP_NATRUE='2' THEN "代理"
		WHEN a.EMP_NATRUE='3' THEN "内部员工"
		ELSE "" END as "EMP_NATRUE",
		FILE_PROVINCE,
		CASE WHEN a.HANDLE_FLAG=0 THEN "未处理"
		WHEN a.HANDLE_FLAG =1 THEN "已处理"
		ELSE "" END as "HANDLE_FLAG",
		       FILE_CITY, FILE_TOWN, SOCIAL_PROVINCE, SOCIAL_CITY, SOCIAL_TOWN,
		DEPT_NAME, UNIT_NAME, UNIT_NO, DEPT_NO
		FROM t_employee_retirement a
		LEFT JOIN t_cutsomer_data_permisson b ON b.SETTLE_DOMAIN_NO = a.DEPT_NO
		WHERE
		b.USER_ID = #{userId}
		<if test="searchVo.empName != null and searchVo.empName.trim() != ''">
			AND a.EMP_NAME like concat('%',#{searchVo.empName},'%')
		</if>
		<if test="searchVo.empIdcard != null and searchVo.empIdcard.trim() != ''">
			AND a.EMP_IDCARD like concat('%',#{searchVo.empIdcard},'%')
		</if>
		<if test="searchVo.fileProvince != null">
			AND a.FILE_PROVINCE = #{searchVo.fileProvince}
		</if>
		<if test="searchVo.fileCity != null">
			AND a.FILE_CITY = #{searchVo.fileCity}
		</if>
		<if test="searchVo.fileTown != null">
			AND a.FILE_TOWN = #{searchVo.fileTown}
		</if>
		<if test="searchVo.socialProvince != null">
			AND a.SOCIAL_PROVINCE = #{searchVo.socialProvince}
		</if>
		<if test="searchVo.socialCity != null">
			AND a.SOCIAL_CITY = #{searchVo.socialCity}
		</if>
		<if test="searchVo.socialTown != null">
			AND a.SOCIAL_TOWN = #{searchVo.socialTown}
		</if>
		<if test="searchVo.unitName!= null">
			AND a.UNIT_NAME = #{searchVo.unitName}
		</if>
		<if test="searchVo.unitNo!= null and searchVo.unitNo!=''" >
			AND a.UNIT_NO = #{searchVo.unitNo}
		</if>
		<if test="searchVo.deptName!= null">
			AND a.DEPT_NAME like concat('%',#{searchVo.deptName},'%')
		</if>
		<if test="searchVo.deptNo!= null and searchVo.deptNo!=''">
			AND a.DEPT_NO =#{searchVo.deptNo}
		</if>
		<if test="searchVo.handleFlag!= null">
			AND a.HANDLE_FLAG =#{searchVo.handleFlag}
		</if>
		<if test="searchVo.empTypeList != null and searchVo.empTypeList.length>0">
			AND a.EMP_NATRUE IN
			<foreach collection="searchVo.empTypeList" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="searchVo.idList != null and searchVo.idList.length > 0">
			and  a.ID in
			<foreach collection="searchVo.idList" item="item" index="index" open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
		ORDER BY
		field(a.HANDLE_FLAG,0,1) asc,
		a.CREATE_TIME asc
	</select>
	<!--tEmployeeInfo导出查询count改造 fxj 2022-11-03-->
	<select id="noPageCountDiy" resultType="java.lang.Integer">
		SELECT
		count(1)
		from t_employee_retirement a
		LEFT JOIN t_cutsomer_data_permisson b ON b.SETTLE_DOMAIN_NO = a.DEPT_NO
		WHERE
		b.USER_ID = #{userId}
		<if test="searchVo.empName != null and searchVo.empName.trim() != ''">
			AND a.EMP_NAME like concat('%',#{searchVo.empName},'%')
		</if>
		<if test="searchVo.empIdcard != null and searchVo.empIdcard.trim() != ''">
			AND a.EMP_IDCARD like concat('%',#{searchVo.empIdcard},'%')
		</if>
		<if test="searchVo.fileProvince != null">
			AND a.FILE_PROVINCE = #{searchVo.fileProvince}
		</if>
		<if test="searchVo.fileCity != null">
			AND a.FILE_CITY = #{searchVo.fileCity}
		</if>
		<if test="searchVo.fileTown != null">
			AND a.FILE_TOWN = #{searchVo.fileTown}
		</if>
		<if test="searchVo.socialProvince != null">
			AND a.SOCIAL_PROVINCE = #{searchVo.socialProvince}
		</if>
		<if test="searchVo.socialCity != null">
			AND a.SOCIAL_CITY = #{searchVo.socialCity}
		</if>
		<if test="searchVo.socialTown != null">
			AND a.SOCIAL_TOWN = #{searchVo.socialTown}
		</if>
		<if test="searchVo.unitName!= null">
			AND a.UNIT_NAME = #{searchVo.unitName}
		</if>
		<if test="searchVo.unitNo!= null and searchVo.unitNo!=''" >
			AND a.UNIT_NO = #{searchVo.unitNo}
		</if>
		<if test="searchVo.deptName!= null">
			AND a.DEPT_NAME like concat('%',#{searchVo.deptName},'%')
		</if>
		<if test="searchVo.deptNo!= null and searchVo.deptNo!=''">
			AND a.DEPT_NO =#{searchVo.deptNo}
		</if>
		<if test="searchVo.handleFlag!= null">
			AND a.HANDLE_FLAG =#{searchVo.handleFlag}
		</if>
		<if test="searchVo.empTypeList != null and searchVo.empTypeList.length>0">
			AND a.EMP_NATRUE IN
			<foreach collection="searchVo.empTypeList" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="searchVo.idList != null and searchVo.idList.length > 0">
			and  a.ID in
			<foreach collection="searchVo.idList" item="item" index="index" open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
		ORDER BY
		field(a.HANDLE_FLAG,0,1) asc,
		a.CREATE_TIME asc
	</select>
	<select id="selectByIdd" resultType="String">
		SELECT a.AREA_NAME
		from mvp_salary.sys_area a
		where id = #{id}
	</select>
</mapper>