<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!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.TPreEmpMainMapper">

  <resultMap id="tPreEmpMainMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TPreEmpMain">
    <id property="id" column="ID"/>
    <result property="status" column="STATUS"/>
    <result property="empId" column="EMP_ID"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="empPhone" column="EMP_PHONE"/>
    <result property="empWx" column="EMP_WX"/>
    <result property="unitId" column="UNIT_ID"/>
    <result property="unitName" column="UNIT_NAME"/>
    <result property="unitNo" column="UNIT_NO"/>
    <result property="deptId" column="DEPT_ID"/>
    <result property="deptName" column="DEPT_NAME"/>
    <result property="deptNo" column="DEPT_NO"/>
    <result property="businessPrimaryType" column="BUSINESS_PRIMARY_TYPE"/>
    <result property="businessSecondType" column="BUSINESS_SECOND_TYPE"/>
    <result property="businessThirdType" column="BUSINESS_THIRD_TYPE"/>
    <result property="businessType" column="BUSINESS_TYPE"/>
    <result property="empNatrue" column="EMP_NATRUE"/>
    <result property="auditId" column="AUDIT_ID"/>
    <result property="auditName" column="AUDIT_NAME"/>
    <result property="auditTime" column="AUDIT_TIME"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="createName" column="CREATE_NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateTime" column="UPDATE_TIME"/>
    <result property="settleDomain" column="SETTLE_DOMAIN"/>
    <result property="declarationId" column="DECLARATION_ID"/>
    <result property="sourType" column="SOUR_TYPE"/>
    <result property="isSimple" column="IS_SIMPLE"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.STATUS,
                a.EMP_ID,
                a.EMP_NAME,
                a.EMP_IDCARD,
                a.EMP_PHONE,
                a.EMP_WX,
                a.UNIT_ID,
                a.UNIT_NAME,
                a.UNIT_NO,
                a.DEPT_ID,
                a.DEPT_NAME,
                a.DEPT_NO,
                a.BUSINESS_PRIMARY_TYPE,
                a.BUSINESS_SECOND_TYPE,
                a.BUSINESS_THIRD_TYPE,
                concat(a.BUSINESS_PRIMARY_TYPE,'-',ifnull(a.BUSINESS_SECOND_TYPE,''),'-',ifnull(a.BUSINESS_THIRD_TYPE,'')) BUSINESS_TYPE,
                a.EMP_NATRUE,
                a.AUDIT_ID,
                if(a.STATUS in ('3','4'),a.AUDIT_NAME,'') AUDIT_NAME,
                if(a.STATUS in ('3','4'),a.AUDIT_TIME,null) AUDIT_TIME,
                a.CREATE_BY,
                a.UPDATE_BY,
                a.CREATE_NAME,
                a.CREATE_TIME,
                a.UPDATE_TIME,
                a.SETTLE_DOMAIN,
                a.DECLARATION_ID,
                a.SOUR_TYPE,
                a.IS_SIMPLE
    </sql>
    <sql id="tPreEmpMain_where">
        <if test="tPreEmpMain != null">
			<if test="tPreEmpMain.statusList != null and tPreEmpMain.statusList.length>0">
				AND a.STATUS IN
				<foreach collection="tPreEmpMain.statusList" item="item" index="index" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
                    <if test="tPreEmpMain.id != null and tPreEmpMain.id.trim() != ''">
                        AND a.ID = #{tPreEmpMain.id}
                    </if>
					<if test="tPreEmpMain.ids != null and tPreEmpMain.ids.length > 0">
						AND a.ID in
						<foreach item="idStr" index="index" collection="tPreEmpMain.ids" open="(" separator="," close=")">
							#{idStr}
						</foreach>
					</if>
                    <if test="tPreEmpMain.status != null and tPreEmpMain.status.trim() != ''">
                        AND a.STATUS = #{tPreEmpMain.status}
                    </if>

					<if test="tPreEmpMain.statusArray != null and tPreEmpMain.statusArray.length > 0">
						AND a.STATUS in
						<foreach item="idStr" index="index" collection="tPreEmpMain.statusArray" open="(" separator="," close=")">
							#{idStr}
						</foreach>
					</if>
                    <if test="tPreEmpMain.empId != null and tPreEmpMain.empId.trim() != ''">
                        AND a.EMP_ID = #{tPreEmpMain.empId}
                    </if>
                    <if test="tPreEmpMain.empName != null and tPreEmpMain.empName.trim() != ''">
                        AND a.EMP_NAME like concat('%',#{tPreEmpMain.empName},'%')
                    </if>
                    <if test="tPreEmpMain.empIdcard != null and tPreEmpMain.empIdcard.trim() != ''">
                        AND a.EMP_IDCARD like concat('%',#{tPreEmpMain.empIdcard},'%')
                    </if>
                    <if test="tPreEmpMain.empPhone != null and tPreEmpMain.empPhone.trim() != ''">
                        AND a.EMP_PHONE = #{tPreEmpMain.empPhone}
                    </if>
                    <if test="tPreEmpMain.empWx != null and tPreEmpMain.empWx.trim() != ''">
                        AND a.EMP_WX = #{tPreEmpMain.empWx}
                    </if>
                    <if test="tPreEmpMain.unitId != null and tPreEmpMain.unitId.trim() != ''">
                        AND a.UNIT_ID = #{tPreEmpMain.unitId}
                    </if>
                    <if test="tPreEmpMain.unitName != null and tPreEmpMain.unitName.trim() != ''">
                        AND a.UNIT_NAME like concat('%',#{tPreEmpMain.unitName},'%')
                    </if>
                    <if test="tPreEmpMain.unitNo != null and tPreEmpMain.unitNo.trim() != ''">
                        AND a.UNIT_NO = #{tPreEmpMain.unitNo}
                    </if>
                    <if test="tPreEmpMain.deptId != null and tPreEmpMain.deptId.trim() != ''">
                        AND a.DEPT_ID = #{tPreEmpMain.deptId}
                    </if>
                    <if test="tPreEmpMain.deptName != null and tPreEmpMain.deptName.trim() != ''">
                        AND a.DEPT_NAME like concat('%',#{tPreEmpMain.deptName},'%')
                    </if>
                    <if test="tPreEmpMain.deptNo != null and tPreEmpMain.deptNo.trim() != ''">
                        AND a.DEPT_NO = #{tPreEmpMain.deptNo}
                    </if>
                    <if test="tPreEmpMain.businessPrimaryType != null and tPreEmpMain.businessPrimaryType.trim() != ''">
                        AND a.BUSINESS_PRIMARY_TYPE like concat('%',#{tPreEmpMain.businessPrimaryType},'%')
                    </if>
                    <if test="tPreEmpMain.businessSecondType != null and tPreEmpMain.businessSecondType.trim() != ''">
                        AND a.BUSINESS_SECOND_TYPE like concat('%',#{tPreEmpMain.businessSecondType},'%')
                    </if>
                    <if test="tPreEmpMain.businessThirdType != null and tPreEmpMain.businessThirdType.trim() != ''">
                        AND a.BUSINESS_THIRD_TYPE like concat('%',#{tPreEmpMain.businessThirdType},'%')
                    </if>
                    <if test="tPreEmpMain.empNatrue != null and tPreEmpMain.empNatrue.trim() != ''">
                        AND a.EMP_NATRUE = #{tPreEmpMain.empNatrue}
                    </if>
					<if test="tPreEmpMain.empNatureArray != null and tPreEmpMain.empNatureArray.length > 0">
						AND a.EMP_NATRUE in
						<foreach item="idStr" index="index" collection="tPreEmpMain.empNatureArray" open="(" separator="," close=")">
							#{idStr}
						</foreach>
					</if>
                    <if test="tPreEmpMain.auditId != null and tPreEmpMain.auditId.trim() != ''">
                        AND a.AUDIT_ID = #{tPreEmpMain.auditId}
                    </if>
                    <if test="tPreEmpMain.auditName != null and tPreEmpMain.auditName.trim() != ''">
                        AND a.AUDIT_NAME = #{tPreEmpMain.auditName}
                    </if>
                    <if test="tPreEmpMain.auditTime != null">
                        AND a.AUDIT_TIME = #{tPreEmpMain.auditTime}
                    </if>
                    <if test="tPreEmpMain.createBy != null and tPreEmpMain.createBy.trim() != ''">
                        AND a.CREATE_BY = #{tPreEmpMain.createBy}
                    </if>
                    <if test="tPreEmpMain.updateBy != null and tPreEmpMain.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{tPreEmpMain.updateBy}
                    </if>
                    <if test="tPreEmpMain.createName != null and tPreEmpMain.createName.trim() != ''">
                        AND a.CREATE_NAME = #{tPreEmpMain.createName}
                    </if>
                    <if test="tPreEmpMain.createTime != null">
                        AND a.CREATE_TIME = #{tPreEmpMain.createTime}
                    </if>
                    <if test="tPreEmpMain.updateTime != null">
                        AND a.UPDATE_TIME = #{tPreEmpMain.updateTime}
                    </if>
                    <if test="tPreEmpMain.settleDomain != null and tPreEmpMain.settleDomain.trim() != ''">
                        AND a.SETTLE_DOMAIN = #{tPreEmpMain.settleDomain}
                    </if>
                    <if test="tPreEmpMain.createTimeStart != null">
                        AND a.CREATE_TIME >= #{tPreEmpMain.createTimeStart}
                    </if>
                    <if test="tPreEmpMain.createTimeEnd != null">
                        AND a.CREATE_TIME <![CDATA[ <= ]]> #{tPreEmpMain.createTimeEnd}
                    </if>
        </if>
    </sql>
    <!--tPreEmpMain简单分页查询-->
    <select id="getTPreEmpMainPage" resultMap="tPreEmpMainMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_pre_emp_main a
        <where>
            a.STATUS != '5'
            <include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
        </where>
		order by a.create_time desc
    </select>

    <select id="getTPreEmpMainCount" resultType="java.lang.Integer">
        SELECT
        	count(1)
        FROM t_pre_emp_main a
        <where>
            a.STATUS != '5'
            <include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
        </where>
    </select>

	<!--list-->
	<select id="getTPreEmpMainList" resultMap="tPreEmpMainMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_pre_emp_main a
		<where>
			a.STATUS != '5'
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.limitStart != null">
					limit #{tPreEmpMain.limitStart},#{tPreEmpMain.limitEnd}
				</if>
			</if>
		</where>
	</select>

    <select id="getTPreEmpMainAllCount" resultType="java.lang.Integer">
        SELECT
        	count(1)
        FROM t_pre_emp_main a
        <where>
            a.STATUS != '5'
            <include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
        </where>
    </select>

	<!--list-->
	<select id="getTPreEmpMainAllList" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
			a.id mainId,case a.STATUS when '0' then '草稿' when '1' then '待完善' when '2' then '待审核' when '3' then '审核不通过' when '4' then '审核通过' else '-' end field1
			,DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') field2,if(a.STATUS in ('3','4'),a.AUDIT_NAME,'') field64,if(a.STATUS in ('3','4'),DATE_FORMAT(a.AUDIT_TIME,'%Y-%m-%d %H:%i:%s'),'') field65
		     ,e.EMP_CODE field3,a.emp_Natrue field4,a.emp_name field5,a.emp_idcard field6
			,if(e.EMP_SEX='2','女',if(e.EMP_SEX='1','男','-')) field7
			,if(e.VALIDITY_END is null,'-',if(e.VALIDITY_END > '2999-12-30','长期','固定')) field8	,e.VALIDITY_START field9
			,if(e.VALIDITY_END > '2999-12-30','长期',e.VALIDITY_END) field10,e.EMP_BIRTHDAY field11,e.EMP_AGE field12	,e.EMP_MARRI_STATUS field13,e.EMP_NATIONAL field14
			,e.POLITICAL_STATUS field15,e.EMP_PHONE field16,e.EMP_EMAIL field17
			,e.ID_PROVINCE field18,e.ID_CITY field69,e.ID_TOWN field70,e.EMP_REGIS_TYPE field19
			,e.FILE_PROVINCE field20,e.FILE_CITY field71,e.FILE_TOWN field72,if(e.status=0,'草稿','已审核') field21,
			e.CONTACT_PROVINCE as "field66", e.CONTACT_CITY as "field67", e.CONTACT_TOWN as "field68"
		     ,e.CONTACT_ADDRESS field22,p.UNIT_NAME field23,p.DEPT_NAME field24
			,concat(p.BUSINESS_PRIMARY_TYPE,'-',ifnull(p.BUSINESS_SECOND_TYPE,''),'-',ifnull(p.BUSINESS_THIRD_TYPE,'')) field25
			,p.CONTRACT_TYPE field26	,p.WORKING_HOURS field27,p.POST field28,p.ENJOIN_DATE field29
			,p.TRY_PERIOD field30,p.EMP_LABEL field31
			,ec.EMP_NAME field32,ec.RELATION_TYPE field33,ec.ADDRESS field34,ec.TEL field35
			,ee.SCHOOL field36,ee.MAJOR field37,ee.EDUCATION_NAME field38,if(e.IS_COLLEGE=0,'否','是') field39
			,e.HIGN_EDUCATION field40	,ee.ENTRY_DATE field41,ee.GRADUTION_DATE field42
			,if(e.FIRST_WORK_FLAG is null,'',if(e.FIRST_WORK_FLAG=0,'是','否')) field43
			,if(e.HAVE_QUALIFICATION is null,'',if(e.HAVE_QUALIFICATION=0,'是','否')) field51
			,if(ed.INJURY_IDENTIFICATION=0,'是','否') field54,if(ed.OCCUPATIONAL_DISEASE_FLAG=0,'是','否') field55	,ed.OCCUPATIONAL_DISEASE field56
			,if(ed.INFECTIOUS_DISEASE_FLAG=0,'是','否') field57	,ed.INFECTIOUS_NAME field58	,if(ed.DISABILITY_FLAG=0,'是','否') field59
			,ed.DISABILITY_NAME field60,ed.DISABILITY_LEVEL field61,if(ed.OTHER_FLAG=0,'是','否') field62,eb.REMARK field63
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_employee_project p on a.id=p.PRE_MAIN_ID
		left join t_pre_emp_contact_info ec on a.id=ec.PRE_MAIN_ID
		left join t_pre_emp_education ee on a.id=ee.PRE_MAIN_ID
		left join t_pre_emp_disability_info ed on a.id=ed.PRE_MAIN_ID
		left join t_pre_emp_bad_record eb on a.id=eb.PRE_MAIN_ID
		<where>
			a.STATUS != '5'
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.limitStart != null">
					limit #{tPreEmpMain.limitStart},#{tPreEmpMain.limitEnd}
				</if>
			</if>
		</where>
	</select>

	<select id="getTPreEmpMainAllListByWork" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		ee.PRE_MAIN_ID mainId,ee.WORK_UNIT field44,ee.WORK_JOB field45,ee.START_DATE field46,ee.END_DATE field47
		from t_pre_emp_work_recording ee
		where ee.PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
		ORDER BY ee.create_time desc
	</select>

	<select id="getTPreEmpMainAllListByFamily" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		ee.PRE_MAIN_ID mainId,ee.FAMILY_NAME field48,ee.RELATIONSHIP_SELF field49,ee.CONTRACT_TEL field50
		FROM t_pre_emp_family ee
		where ee.PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
		ORDER BY ee.create_time desc
	</select>

	<select id="getTPreEmpMainAllListByProfessional" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		ee.PRE_MAIN_ID mainId,ee.DECLARE_YEAR field52,ee.QUALIFICATION_TYPE field53
		FROM t_pre_emp_professional_qualification ee
		where ee.PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
		ORDER BY ee.create_time desc
	</select>

	<!-- 数量 -->
	<select id="getTEmpMainAllCountOneWork" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_work_recording ew on a.id=ew.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ew.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_work_recording a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ew.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
	</select>

	<!--导出统计list1主要工作经历-->
	<select id="getTEmpMainAllListOneWork" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		e.emp_idcard field6
		,if(e.FIRST_WORK_FLAG is null,'',if(e.FIRST_WORK_FLAG=0,'是','否')) field43,ew.WORK_UNIT field44,ew.WORK_JOB field45,ew.START_DATE field46,ew.END_DATE field47
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_work_recording ew on a.id=ew.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ew.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_work_recording a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ew.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
		ORDER BY a.emp_idcard DESC
		<if test="tPreEmpMain != null">
			<if test="tPreEmpMain.limitStart != null">
				limit #{tPreEmpMain.limitStart},#{tPreEmpMain.limitEnd}
			</if>
		</if>
	</select>

	<!-- 数量 -->
	<select id="getTEmpMainAllCountTwoFamily" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_family ef on a.id=ef.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ef.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_family a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ef.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
	</select>
	<!--导出统计list2主要家庭成员信息-->
	<select id="getTEmpMainAllListTwoFamily" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		e.emp_idcard field6
		,ef.FAMILY_NAME field48,ef.RELATIONSHIP_SELF field49,ef.CONTRACT_TEL field50
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_family ef on a.id=ef.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ef.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_family a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ef.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
		ORDER BY a.emp_idcard DESC
		<if test="tPreEmpMain != null">
			<if test="tPreEmpMain.limitStart != null">
				limit #{tPreEmpMain.limitStart},#{tPreEmpMain.limitEnd}
			</if>
		</if>
	</select>

	<!-- 数量 -->
	<select id="getTEmpMainAllCountThreeProfessional" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_professional_qualification ep on a.id=ep.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ep.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_professional_qualification a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ep.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
	</select>
	<!--导出统计list3职业资格信息-->
	<select id="getTEmpMainAllListThreeProfessional" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.TPreMainExportAllVO">
		SELECT
		e.emp_idcard field6
		,if(e.HAVE_QUALIFICATION is null,'',if(e.HAVE_QUALIFICATION=0,'是','否')) field51,ep.DECLARE_YEAR field52,ep.QUALIFICATION_TYPE field53
		FROM t_pre_emp_main a
		left join t_pre_employee_info e on a.id=e.PRE_MAIN_ID
		left join t_pre_emp_professional_qualification ep on a.id=ep.PRE_MAIN_ID
		<where>
			a.STATUS != '5' and ep.id is not null and EXISTS (
			select 1 from (select a.EMP_IDCARD from t_pre_emp_professional_qualification a left join t_pre_emp_main p on a.PRE_MAIN_ID=p.id where p.STATUS != '5' and p.id is not null GROUP BY a.EMP_IDCARD HAVING count(1)>1) ea where ea.EMP_IDCARD=ep.EMP_IDCARD
			)
			<include refid="tPreEmpMain_where"/>
			<if test="tPreEmpMain != null">
				<if test="tPreEmpMain.authSql != null and tPreEmpMain.authSql.trim() != ''">
					${tPreEmpMain.authSql}
				</if>
			</if>
		</where>
		ORDER BY a.emp_idcard DESC
		<if test="tPreEmpMain != null">
			<if test="tPreEmpMain.limitStart != null">
				limit #{tPreEmpMain.limitStart},#{tPreEmpMain.limitEnd}
			</if>
		</if>
	</select>
	

    <!--tPreEmpMain简单分页查询-->
    <select id="getTPreEmpMainByCardAndDept" resultMap="tPreEmpMainMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_pre_emp_main a
        where  a.EMP_IDCARD = #{empIdCard} AND a.DEPT_ID = #{deptId} and a.STATUS != '4'
		limit 1
    </select>

	<!-- 导入预入职时，查询所有身份证的预入职使用的，查出来删除附属信息 -->
    <select id="getTPreEmpMainListByCardAndDept" resultType="java.lang.String">
        SELECT
			a.ID
        FROM t_pre_emp_main a
        where a.DEPT_ID = #{deptId} AND a.EMP_IDCARD in
		<foreach collection="empIdCardList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
    </select>

    <!--tPreEmpMain简单分页查询-->
    <select id="getTPreEmpMainByCardAndDeptNo" resultMap="tPreEmpMainMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_pre_emp_main a
        where  a.EMP_IDCARD = #{empIdCard} AND a.DEPT_NO = #{deptNo}
		limit 1
    </select>

	<delete id="deleteBadByMainId">
		delete from t_pre_emp_bad_record where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteContactByMainId">
		delete from t_pre_emp_contact_info where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteDisabilityByMainId">
		delete from t_pre_emp_disability_info where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteEducationByMainId">
		delete from t_pre_emp_education where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteFamilyByMainId">
		delete from t_pre_emp_family where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteEmployeeByMainId">
		delete from t_pre_employee_info where PRE_MAIN_ID = #{preMainId}
	</delete>
	<delete id="deleteProjectByMainId">
		delete from t_pre_employee_project where PRE_MAIN_ID = #{preMainId}
	</delete>
	
	
	<delete id="deleteBadByMainIdList">
		delete from t_pre_emp_bad_record where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteContactByMainIdList">
		delete from t_pre_emp_contact_info where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteDisabilityByMainIdList">
		delete from t_pre_emp_disability_info where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteEducationByMainIdList">
		delete from t_pre_emp_education where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteFamilyByMainIdList">
		delete from t_pre_emp_family where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteEmployeeByMainIdList">
		delete from t_pre_employee_info where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteProjectByMainIdList">
		delete from t_pre_employee_project where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>

	<delete id="deleteWorkRecordingByMainIdList">
		delete from t_pre_emp_work_recording where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteProfessionalByMainIdList">
		delete from t_pre_emp_professional_qualification where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteOtherFileByMainIdList">
		delete from t_pre_emp_other_file where PRE_MAIN_ID in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deleteAttaByDomainIdList">
		delete from t_atta_info where domain_id in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>
	<delete id="deletePreMainIdList">
		delete from t_pre_emp_main where id in
		<foreach collection="preMainIdList" item="ids" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</delete>

</mapper>
