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

	<resultMap id="tEmployeeContrctInfoMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeContractInfo">
		<id property="id" column="ID"/>
		<result property="empNo" column="EMP_NO"/>
		<result property="empId" column="EMP_ID"/>
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="contractName" column="CONTRACT_NAME"/>
		<result property="contractType" column="CONTRACT_TYPE"/>
		<result property="contractEnd" column="CONTRACT_END"/>
		<result property="subjectDepart" column="SUBJECT_DEPART"/>
		<result property="subjectUnit" column="SUBJECT_UNIT"/>
		<result property="situation" column="SITUATION"/>
		<result property="contractTerm" column="CONTRACT_TERM"/>
		<result property="contractNo" column="CONTRACT_NO"/>
		<result property="remark" column="REMARK"/>
		<result property="isObsolete" column="IS_OBSOLETE"/>
		<result property="isFile" column="IS_FILE"/>
		<result property="oldId" column="OLD_ID"/>
		<result property="enjoinDate" column="ENJOIN_DATE"/>
		<result property="post" column="POST"/>
		<result property="workingHours" column="WORKING_HOURS"/>
		<result property="fileCabinetNo" column="FILE_CABINET_NO"/>
		<result property="settleDomain" column="SETTLE_DOMAIN"/>
		<result property="inUse" column="IN_USE"/>
		<result property="obsoleteReason" column="OBSOLETE_REASON"/>
		<result property="customerId" column="CUSTOMER_ID"/>
		<result property="fileProvince" column="FILE_PROVINCE"/>
		<result property="fileCity" column="FILE_CITY"/>
		<result property="fileTown" column="FILE_TOWN"/>
		<result property="workingStatusSub" column="WORKING_STATUS_SUB"/>
		<result property="workFlag" column="WORK_FLAG"/>
		<result property="periodStart" column="PERIOD_START"/>
		<result property="periodEnd" column="PERIOD_END"/>
		<result property="periodSalaryPerMonth" column="PERIOD_SALARY_PER_MONTH"/>
		<result property="salaryType" column="SALARY_TYPE"/>
		<result property="salaryStandardPerHour" column="SALARY_STANDARD_PER_HOUR"/>
		<result property="salaryStandardPerPiece" column="SALARY_STANDARD_PER_PIECE"/>
		<result property="dispatchFlag" column="DISPATCH_FLAG"/>
		<result property="warnEmailUserId" column="WARN_EMAIL_USER_ID"/>
		<result property="fddFlag" column="FDD_FLAG"/>
		<result property="isSign" column="IS_SIGN"/>
		<result property="createName" column="CREATE_NAME"/>
		<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="unitNo" column="UNIT_NO"/>
		<result property="deptNo" column="DEPT_NO"/>
		<result property="applyNo" column="APPLY_NO"/>
		<result property="auditStatus" column="AUDIT_STATUS"/>
		<result property="deleteFlag" column="DELETE_FLAG"/>
		<result property="empNatrue" column="EMP_NATRUE"/>
		<result property="contractParty" column="CONTRACT_PARTY"/>
		<result property="contractSubName" column="CONTRACT_SUB_NAME"/>
		<result property="reason" column="REASON"/>
		<result property="auditTimeLast" column="AUDIT_TIME_LAST"/>

		<result property="type" column="TYPE"/>
		<result property="leaveDate" column="LEAVE_DATE"/>
		<result property="reduceReason" column="REDUCE_REASON"/>
		<result property="changeContractAndEmployee" column="CHANGE_CONTRACT_AND_EMPLOYEE"/>
		<result property="tryPeriod" column="TRY_PERIOD"/>

	</resultMap>
	<!-- 合同审核导出 -->
	<resultMap id="empContractExportAuditMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeContractExportAuditVO">
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="contractName" column="CONTRACT_NAME"/>
		<result property="contractType" column="CONTRACT_TYPE"/>
		<result property="contractEnd" column="CONTRACT_END"/>
		<result property="subjectDepart" column="SUBJECT_DEPART"/>
		<result property="subjectUnit" column="SUBJECT_UNIT"/>
		<result property="situation" column="SITUATION"/>
		<result property="workingHours" column="WORKING_HOURS"/>
		<result property="createName" column="CREATE_NAME"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="contractSubName" column="CONTRACT_SUB_NAME"/>
		<result property="reason" column="REASON"/>
		<result property="contractNo" column="CONTRACT_NO"/>
		<result property="type" column="TYPE"/>
		<result property="leaveDate" column="LEAVE_DATE"/>
		<result property="reduceReason" column="REDUCE_REASON"/>
	</resultMap>
	<!-- 合同导出 -->
	<resultMap id="tEmployeeContrctInfoExportMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeContractExportVO">
		<result property="applyNo" column="APPLY_NO"/>
		<result property="empNo" column="EMP_NO"/>
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="contractStart" column="CONTRACT_START"/>
		<result property="contractEnd" column="CONTRACT_END"/>
		<result property="fileProvince" column="FILE_PROVINCE"/>
		<result property="fileCity" column="FILE_CITY"/>
		<result property="fileTown" column="FILE_TOWN"/>
		<result property="subjectDepart" column="SUBJECT_DEPART"/>
		<result property="deptNo" column="DEPT_NO"/>
		<result property="empNatrue" column="EMP_NATRUE"/>
		<result property="contractName" column="CONTRACT_NAME"/>
		<result property="contractSubName" column="CONTRACT_SUB_NAME"/>
		<result property="situation" column="SITUATION"/>
		<result property="contractType" column="CONTRACT_TYPE"/>
		<result property="contractParty" column="CONTRACT_PARTY"/>
		<result property="subjectUnit" column="SUBJECT_UNIT"/>
		<result property="auditStatus" column="AUDIT_STATUS"/>
		<result property="inUse" column="IN_USE"/>
		<result property="files" column="FILES"/>
		<result property="isFile" column="IS_FILE"/>
		<result property="createName" column="CREATE_NAME"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="createNum" column="CREATE_NUM"/>
		<result property="startDate" column="START_DATE"/>
		<result property="endDate" column="END_DATE"/>
		<result property="history" column="HISTORY"/>
		<result property="type" column="TYPE"/>
		<result property="contractNo" column="CONTRACT_NO"/>
		<result property="workingHours" column="WORKING_HOURS"/>
		<result property="post" column="POST"/>
		<result property="remark" column="REMARK"/>
		<result property="memo" column="MEMO"/>
		<result property="tryPeriod" column="TRY_PERIOD"/>
	</resultMap>

	<sql id="Base_Column_List">
		a.ID,
		a.EMP_NO,
		a.EMP_ID,
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.CONTRACT_NAME,
		a.CONTRACT_TYPE,
		a.CONTRACT_START,
		a.CONTRACT_END,
		a.SUBJECT_DEPART,
		a.SUBJECT_UNIT,
		a.SITUATION,
		a.CONTRACT_TERM,
		a.CONTRACT_NO,
		a.REMARK,
		a.IS_OBSOLETE,
		a.IS_FILE,
		a.OLD_ID,
		a.ENJOIN_DATE,
		a.POST,
		a.WORKING_HOURS,
		a.FILE_CABINET_NO,
		a.SETTLE_DOMAIN,
		a.IN_USE,
		a.OBSOLETE_REASON,
		a.CUSTOMER_ID,
		a.FILE_PROVINCE,
		a.FILE_CITY,
		a.FILE_TOWN,
		a.WORKING_STATUS_SUB,
		a.WORK_FLAG,
		a.PERIOD_START,
		a.PERIOD_END,
		a.PERIOD_SALARY_PER_MONTH,
		a.SALARY_TYPE,
		a.SALARY_STANDARD_PER_HOUR,
		a.SALARY_STANDARD_PER_PIECE,
		a.DISPATCH_FLAG,
		a.WARN_EMAIL_USER_ID,
		a.FDD_FLAG,
		a.IS_SIGN,
		a.CREATE_BY,
		a.CREATE_NAME,
		a.CREATE_TIME,
		a.UPDATE_BY,
		a.UPDATE_TIME,
		a.UNIT_NO,
		a.DEPT_NO,
		a.AUDIT_STATUS,
		a.APPLY_NO,
		a.DELETE_FLAG,
		a.EMP_NATRUE,
		a.CONTRACT_PARTY,
		a.CONTRACT_SUB_NAME,
		a.REASON,
		a.AUDIT_TIME_LAST,
		a.TYPE,
		a.LEAVE_DATE,
		a.AUDIT_USER_NAME,
		a.REDUCE_REASON,
		a.type,
		a.TRY_PERIOD

	</sql>

	<!-- 导出 -->
	<sql id="Base_Export_Column_List">
		a.APPLY_NO,
		a.EMP_NO,
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.AUDIT_USER_NAME,
		a.CONTRACT_START,
		a.CONTRACT_END,
		a.FILE_PROVINCE,
		a.FILE_CITY,
		a.FILE_TOWN,
		a.SUBJECT_DEPART,
		a.DEPT_NO,
		a.EMP_NATRUE,
		a.CONTRACT_NAME,
		a.CONTRACT_SUB_NAME,
		a.SITUATION,
		a.CONTRACT_TYPE,
		a.CONTRACT_PARTY,
		a.SUBJECT_UNIT,
		a.AUDIT_STATUS,
		b.REMARK,
		a.IN_USE,
		if(a.IS_FILE = 0,'有附件','无附件') FILES,
		a.IS_FILE,
		a.CREATE_NAME,
		a.CREATE_TIME

	</sql>
	<sql id="tEmployeeContractInfo_where">
		<if test="tEmployeeContractInfo != null">
			<if test="tEmployeeContractInfo.idList != null">
				AND a.id in
				<foreach item="idStr" index="index" collection="tEmployeeContractInfo.idList" open="(" separator="," close=")">
					#{idStr}
				</foreach>
			</if>
			<if test="tEmployeeContractInfo.auditUserName != null and tEmployeeContractInfo.auditUserName.trim() != ''">
				AND a.AUDIT_USER_NAME like  concat('%',#{tEmployeeContractInfo.auditUserName},'%')
			</if>
			<if test="tEmployeeContractInfo.id != null and tEmployeeContractInfo.id.trim() != ''">
				AND a.ID = #{tEmployeeContractInfo.id}
			</if>
			<if test="tEmployeeContractInfo.type != null and tEmployeeContractInfo.type.trim() != ''">
				AND a.type = #{tEmployeeContractInfo.type}
			</if>
			<if test="tEmployeeContractInfo.empNo != null and tEmployeeContractInfo.empNo.trim() != ''">
				AND a.EMP_NO = #{tEmployeeContractInfo.empNo}
			</if>
			<if test="tEmployeeContractInfo.empId != null and tEmployeeContractInfo.empId.trim() != ''">
				AND a.EMP_ID = #{tEmployeeContractInfo.empId}
			</if>
			<if test="tEmployeeContractInfo.empName != null and tEmployeeContractInfo.empName.trim() != ''">
				AND a.EMP_NAME like concat('%',#{tEmployeeContractInfo.empName},'%')
			</if>
			<if test="tEmployeeContractInfo.empIdcard != null and tEmployeeContractInfo.empIdcard.trim() != ''">
				AND a.EMP_IDCARD like concat('%',#{tEmployeeContractInfo.empIdcard},'%')
			</if>
			<if test="tEmployeeContractInfo.contractName != null and tEmployeeContractInfo.contractName.trim() != ''">
				AND a.CONTRACT_NAME = #{tEmployeeContractInfo.contractName}
			</if>
			<if test="tEmployeeContractInfo.contractType != null and tEmployeeContractInfo.contractType.trim() != ''">
				AND a.CONTRACT_TYPE = #{tEmployeeContractInfo.contractType}
			</if>
			<if test="tEmployeeContractInfo.contractStart != null">
				AND a.CONTRACT_START = #{tEmployeeContractInfo.contractStart}
			</if>
			<if test="tEmployeeContractInfo.contractEnd != null">
				AND a.CONTRACT_END = #{tEmployeeContractInfo.contractEnd}
			</if>
			<if test="tEmployeeContractInfo.subjectDepart != null and tEmployeeContractInfo.subjectDepart.trim() != ''">
				AND a.SUBJECT_DEPART like concat('%',#{tEmployeeContractInfo.subjectDepart},'%')
			</if>
			<if test="tEmployeeContractInfo.subjectUnit != null and tEmployeeContractInfo.subjectUnit.trim() != ''">
				AND a.SUBJECT_UNIT like concat('%',#{tEmployeeContractInfo.subjectUnit},'%')
			</if>
			<if test="tEmployeeContractInfo.situation != null and tEmployeeContractInfo.situation.trim() != ''">
				AND a.SITUATION = #{tEmployeeContractInfo.situation}
			</if>
			<if test="tEmployeeContractInfo.isFilePage != null">
				AND a.SITUATION != '作废' AND a.SITUATION != '终止'
			</if>
			<if test="tEmployeeContractInfo.contractTerm != null">
				AND a.CONTRACT_TERM = #{tEmployeeContractInfo.contractTerm}
			</if>
			<if test="tEmployeeContractInfo.contractNo != null and tEmployeeContractInfo.contractNo.trim() != ''">
				AND a.CONTRACT_NO = #{tEmployeeContractInfo.contractNo}
			</if>
			<if test="tEmployeeContractInfo.remark != null and tEmployeeContractInfo.remark.trim() != ''">
				AND a.REMARK = #{tEmployeeContractInfo.remark}
			</if>
			<if test="tEmployeeContractInfo.isObsolete != null and tEmployeeContractInfo.isObsolete.trim() != ''">
				AND a.IS_OBSOLETE = #{tEmployeeContractInfo.isObsolete}
			</if>
			<if test="tEmployeeContractInfo.isFile != null and tEmployeeContractInfo.isFile.trim() != ''">
				AND a.IS_FILE = #{tEmployeeContractInfo.isFile}
			</if>
			<if test="tEmployeeContractInfo.isAtta != null and tEmployeeContractInfo.isAtta.trim() != ''">
				AND a.IS_FILE = #{tEmployeeContractInfo.isAtta}
			</if>
			<if test="tEmployeeContractInfo.oldId != null">
				AND a.OLD_ID = #{tEmployeeContractInfo.oldId}
			</if>
			<if test="tEmployeeContractInfo.enjoinDate != null">
				AND a.ENJOIN_DATE = #{tEmployeeContractInfo.enjoinDate}
			</if>
			<if test="tEmployeeContractInfo.post != null and tEmployeeContractInfo.post.trim() != ''">
				AND a.POST = #{tEmployeeContractInfo.post}
			</if>
			<if test="tEmployeeContractInfo.workingHours != null and tEmployeeContractInfo.workingHours.trim() != ''">
				AND a.WORKING_HOURS = #{tEmployeeContractInfo.workingHours}
			</if>
			<if test="tEmployeeContractInfo.fileCabinetNo != null and tEmployeeContractInfo.fileCabinetNo.trim() != ''">
				AND a.FILE_CABINET_NO = #{tEmployeeContractInfo.fileCabinetNo}
			</if>
			<if test="tEmployeeContractInfo.settleDomain != null and tEmployeeContractInfo.settleDomain.trim() != ''">
				AND a.SETTLE_DOMAIN = #{tEmployeeContractInfo.settleDomain}
			</if>
			<if test="tEmployeeContractInfo.inUse != null and tEmployeeContractInfo.inUse.trim() != ''">
				AND a.IN_USE = #{tEmployeeContractInfo.inUse}
			</if>
			<if test="tEmployeeContractInfo.obsoleteReason != null and tEmployeeContractInfo.obsoleteReason.trim() != ''">
				AND a.OBSOLETE_REASON = #{tEmployeeContractInfo.obsoleteReason}
			</if>
			<if test="tEmployeeContractInfo.customerId != null and tEmployeeContractInfo.customerId.trim() != ''">
				AND a.CUSTOMER_ID = #{tEmployeeContractInfo.customerId}
			</if>
			<if test="tEmployeeContractInfo.fileProvince != null">
				AND a.FILE_PROVINCE = #{tEmployeeContractInfo.fileProvince}
			</if>
			<if test="tEmployeeContractInfo.fileCity != null">
				AND a.FILE_CITY = #{tEmployeeContractInfo.fileCity}
			</if>
			<if test="tEmployeeContractInfo.fileTown != null">
				AND a.FILE_TOWN = #{tEmployeeContractInfo.fileTown}
			</if>
			<if test="tEmployeeContractInfo.workingStatusSub != null and tEmployeeContractInfo.workingStatusSub.trim() != ''">
				AND a.WORKING_STATUS_SUB = #{tEmployeeContractInfo.workingStatusSub}
			</if>
			<if test="tEmployeeContractInfo.workFlag != null and tEmployeeContractInfo.workFlag.trim() != ''">
				AND a.WORK_FLAG = #{tEmployeeContractInfo.workFlag}
			</if>
			<if test="tEmployeeContractInfo.periodStart != null">
				AND a.PERIOD_START = #{tEmployeeContractInfo.periodStart}
			</if>
			<if test="tEmployeeContractInfo.periodEnd != null">
				AND a.PERIOD_END = #{tEmployeeContractInfo.periodEnd}
			</if>
			<if test="tEmployeeContractInfo.periodSalaryPerMonth != null">
				AND a.PERIOD_SALARY_PER_MONTH = #{tEmployeeContractInfo.periodSalaryPerMonth}
			</if>
			<if test="tEmployeeContractInfo.salaryType != null and tEmployeeContractInfo.salaryType.trim() != ''">
				AND a.SALARY_TYPE = #{tEmployeeContractInfo.salaryType}
			</if>
			<if test="tEmployeeContractInfo.salaryStandardPerHour != null">
				AND a.SALARY_STANDARD_PER_HOUR = #{tEmployeeContractInfo.salaryStandardPerHour}
			</if>
			<if test="tEmployeeContractInfo.salaryStandardPerPiece != null">
				AND a.SALARY_STANDARD_PER_PIECE = #{tEmployeeContractInfo.salaryStandardPerPiece}
			</if>
			<if test="tEmployeeContractInfo.dispatchFlag != null and tEmployeeContractInfo.dispatchFlag.trim() != ''">
				AND a.DISPATCH_FLAG = #{tEmployeeContractInfo.dispatchFlag}
			</if>
			<if test="tEmployeeContractInfo.warnEmailUserId != null and tEmployeeContractInfo.warnEmailUserId.trim() != ''">
				AND a.WARN_EMAIL_USER_ID = #{tEmployeeContractInfo.warnEmailUserId}
			</if>
			<if test="tEmployeeContractInfo.fddFlag != null and tEmployeeContractInfo.fddFlag.trim() != ''">
				AND a.FDD_FLAG = #{tEmployeeContractInfo.fddFlag}
			</if>
			<if test="tEmployeeContractInfo.isSign != null">
				AND a.IS_SIGN = #{tEmployeeContractInfo.isSign}
			</if>
			<if test="tEmployeeContractInfo.createBy != null and tEmployeeContractInfo.createBy.trim() != ''">
				AND a.CREATE_BY = #{tEmployeeContractInfo.createBy}
			</if>
			<if test="tEmployeeContractInfo.createName != null and tEmployeeContractInfo.createName.trim() != ''">
				AND a.CREATE_NAME like concat('%',#{tEmployeeContractInfo.createName},'%')
			</if>
			<if test="tEmployeeContractInfo.updateBy != null and tEmployeeContractInfo.updateBy.trim() != ''">
				AND a.UPDATE_BY = #{tEmployeeContractInfo.updateBy}
			</if>
			<if test="tEmployeeContractInfo.updateTime != null">
				AND a.UPDATE_TIME = #{tEmployeeContractInfo.updateTime}
			</if>

			<if test="tEmployeeContractInfo.unitNo != null and tEmployeeContractInfo.unitNo.trim() != ''">
				AND a.UNIT_NO = #{tEmployeeContractInfo.unitNo}
			</if>

			<if test="tEmployeeContractInfo.deptNo != null and tEmployeeContractInfo.deptNo.trim() != ''">
				AND a.DEPT_NO = #{tEmployeeContractInfo.deptNo}
			</if>
			<if test="tEmployeeContractInfo.applyNo != null and tEmployeeContractInfo.applyNo.trim() != ''">
				AND a.APPLY_NO = #{tEmployeeContractInfo.applyNo}
			</if>
			<if test="tEmployeeContractInfo.auditStatus != null">
				AND a.AUDIT_STATUS = #{tEmployeeContractInfo.auditStatus}
			</if>
			<if test="tEmployeeContractInfo.empNatrue != null and tEmployeeContractInfo.empNatrue.trim() != ''">
				AND a.EMP_NATRUE = #{tEmployeeContractInfo.empNatrue}
			</if>
			<if test="tEmployeeContractInfo.contractParty != null and tEmployeeContractInfo.contractParty.trim() != ''">
				AND a.CONTRACT_PARTY like concat('%',#{tEmployeeContractInfo.contractParty},'%')
			</if>
			<if test="tEmployeeContractInfo.contractSubName != null and tEmployeeContractInfo.contractSubName.trim() != ''">
				AND a.CONTRACT_SUB_NAME = #{tEmployeeContractInfo.contractSubName}
			</if>

			<if test="tEmployeeContractInfo.createTimeStart != null and tEmployeeContractInfo.createTimeStart.trim() != ''">
				AND a.CREATE_TIME >= #{tEmployeeContractInfo.createTimeStart}
			</if>
			<if test="tEmployeeContractInfo.createTimeEnd != null and tEmployeeContractInfo.createTimeEnd.trim() != ''">
				AND a.CREATE_TIME <![CDATA[ <= ]]> #{tEmployeeContractInfo.createTimeEnd}
			</if>

		</if>
	</sql>
	<!--tEmployeeContractInfo简单分页查询-->
	<select id="getTEmployeeContractInfoPage" resultMap="tEmployeeContrctInfoMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM t_employee_contract_info a
		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
		order by a.APPLY_NO desc
	</select>

	<!--list-->
	<select id="getTEmployeeContractList" resultMap="tEmployeeContrctInfoMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM t_employee_contract_info a
		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
		</where>
		order by a.APPLY_NO desc
	</select>

	<!--导出合同数量查询-->
	<select id="selectCountContractExport" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_employee_contract_info a
		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
	</select>

	<!--导出-->
	<select id="getTEmployeeContractExport" resultMap="tEmployeeContrctInfoExportMap">
		SELECT
		a.APPLY_NO,
		a.EMP_NO,
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.CONTRACT_START,
		a.CONTRACT_END,
		a.AUDIT_USER_NAME,
		a1.AREA_NAME as "FILE_PROVINCE",
		a2.AREA_NAME as "FILE_CITY",
		a3.AREA_NAME as "FILE_TOWN",
		a.SUBJECT_DEPART,
		a.DEPT_NO,
		a.EMP_NATRUE,
		a.CONTRACT_NAME,
		a.CONTRACT_SUB_NAME,
		a.SITUATION,
		a.CONTRACT_TYPE,
		a.CONTRACT_PARTY,
		a.SUBJECT_UNIT,
		CASE WHEN a.AUDIT_STATUS=0 THEN "待提交"
		WHEN a.AUDIT_STATUS =1 THEN "待审核"
		WHEN a.AUDIT_STATUS =2 THEN "审核通过"
		WHEN a.AUDIT_STATUS =3 THEN "审核不通过"
		ELSE a.AUDIT_STATUS END as "AUDIT_STATUS",
		if(a.IN_USE = 0,'可用','不可用') IN_USE,
		if(a.IS_FILE = 0,'有附件','无附件') FILES,
		if(a.IS_FILE = 0,'已归档','未归档') IS_FILE,
		a.CREATE_NAME,
		a.CONTRACT_NO,
		a.POST,
		CASE WHEN a.WORKING_HOURS=1 THEN "标准工时"
		WHEN a.WORKING_HOURS =2 THEN "综合工时"
		WHEN a.WORKING_HOURS =3 THEN "不定时工时制"
		ELSE a.WORKING_HOURS END as "WORKING_HOURS",
		CASE WHEN a.type=0 THEN "派增-社保派单"
		WHEN a.type =1 THEN "派增-无社保新签"
		WHEN a.type =2 THEN "派增-续签"
		WHEN a.type =3 THEN "派减-作废"
		WHEN a.type =4 THEN "派减-终止"
		ELSE a.type END as "type",
		b.REMARK,
		a.REMARK as memo,
		a.CREATE_TIME,
		a.TRY_PERIOD
		FROM t_employee_contract_info a
		LEFT JOIN sys_area a1 on a1.id=a.FILE_PROVINCE
		LEFT JOIN sys_area a2 on a2.id=a.FILE_CITY
		LEFT JOIN sys_area a3 on a3.id=a.FILE_TOWN
		left join (select REMARK,LINK_ID from t_employee_contract_audit where ROOT_NAME='合同审核') b on a.ID=b.LINK_ID
		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
		GROUP BY a.id
		order by a.APPLY_NO desc
		limit #{tEmployeeContractInfo.limitStart},#{tEmployeeContractInfo.limitEnd}
	</select>

	<!--导出历史合并合同数量查询-->
	<select id="selectCountHistoryContractExport" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_employee_contract_info a
		<where>
			a.DELETE_FLAG = 0 and a.AUDIT_TIME_LAST is not null and a.SITUATION != '作废' and a.SITUATION != '终止'
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
	</select>

	<!--导出历史合并-->
	<select id="getTEmployeeContractExportHistory" resultMap="tEmployeeContrctInfoExportMap">
		SELECT
			a.APPLY_NO,
			a.EMP_NO,
			a.EMP_NAME,
			a.EMP_IDCARD,
			a.CONTRACT_START,
			a.CONTRACT_END,
			a1.AREA_NAME as "FILE_PROVINCE",
			a2.AREA_NAME as "FILE_CITY",
			a3.AREA_NAME as "FILE_TOWN",
			a.SUBJECT_DEPART,
			a.DEPT_NO,
			a.EMP_NATRUE,
			a.CONTRACT_NAME,
			a.CONTRACT_SUB_NAME,
			a.SITUATION,
			a.CONTRACT_TYPE,
			a.CONTRACT_PARTY,
			a.SUBJECT_UNIT,
			CASE WHEN a.AUDIT_STATUS=0 THEN "待提交"
			WHEN a.AUDIT_STATUS =1 THEN "待审核"
			WHEN a.AUDIT_STATUS =2 THEN "审核通过"
			WHEN a.AUDIT_STATUS =3 THEN "审核不通过"
			ELSE a.AUDIT_STATUS END as "AUDIT_STATUS",
			if(a.IN_USE = 0,'可用','不可用') IN_USE,
			if(a.IS_FILE = 0,'有附件','无附件') FILES,
			if(a.IS_FILE = 0,'已归档','未归档') IS_FILE,
			max(a.CONTRACT_NO) CONTRACT_NO,
			max(a.POST) POST,
			CASE WHEN max(a.WORKING_HOURS)=1 THEN "标准工时"
			WHEN max(a.WORKING_HOURS) =2 THEN "综合工时"
			WHEN max(a.WORKING_HOURS) =3 THEN "不定时工时制"
			ELSE max(a.WORKING_HOURS) END as "WORKING_HOURS",
			a.CREATE_NAME,
			CASE WHEN a.type=0 THEN "派增-社保派单"
			WHEN a.type =1 THEN "派增-无社保新签"
			WHEN a.type =2 THEN "派增-续签"
			WHEN a.type =3 THEN "派减-作废"
			WHEN a.type =4 THEN "派减-终止"
			ELSE a.type END as "type",
			a.CREATE_TIME,
			count(1) CREATE_NUM,
			min(a.CONTRACT_START) START_DATE,
			max(a.CONTRACT_END) END_DATE,
			GROUP_CONCAT(concat(a.CONTRACT_START,'~',ifnull(a.CONTRACT_END,'')) ORDER BY a.CONTRACT_START asc) HISTORY,
			a.TRY_PERIOD
		FROM t_employee_contract_info a
		LEFT JOIN sys_area a1 on a1.id=a.FILE_PROVINCE
		LEFT JOIN sys_area a2 on a2.id=a.FILE_CITY
		LEFT JOIN sys_area a3 on a3.id=a.FILE_TOWN
		<where>
			a.DELETE_FLAG = 0 and a.AUDIT_TIME_LAST is not null and a.SITUATION != '作废' and a.SITUATION != '终止'
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
		GROUP BY a.EMP_IDCARD,a.SETTLE_DOMAIN
		order by a.APPLY_NO desc
		limit #{tEmployeeContractInfo.limitStart},#{tEmployeeContractInfo.limitEnd}
	</select>

	<!--tEmployeeContractInfo简单分页查询-->
	<select id="getOneContractByApplyNo" resultMap="tEmployeeContrctInfoMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM t_employee_contract_info a
		where a.DELETE_FLAG = 0 and a.APPLY_NO = #{applyNo}
		limit 1
	</select>

	<!-- 根据员工ID更新合同在用状态 -->
	<update id="updateInUseStatusById">
		update t_employee_contract_info
		set IN_USE = #{status}
		where EMP_ID = #{empId} and DEPT_NO = #{deptNo} and ID != #{id}
	</update>

	<!-- 获取当日最大的编码 -->
	<select id="getMaxContractCode" resultType="java.lang.String">
		SELECT ifnull(max(right(e.APPLY_NO,4)),0) APPLY_NO FROM t_employee_contract_info e where e.DELETE_FLAG = 0 and e.CREATE_TIME>DATE_FORMAT(now(),'%Y-%m-%d')
	</select>

	<!-- 根据编码获取数据 -->
	<select id="getContractByApplyNo" resultType="java.lang.String">
		SELECT e.id FROM t_employee_contract_info e where e.APPLY_NO = #{applyNo}
	</select>


	<!--tEmployeeContractInfo简单分页查询审核导出fxj-2022-11-04-->
	<select id="noPageDiy" resultMap="empContractExportAuditMap">
		SELECT
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.CONTRACT_NAME,
		a.CONTRACT_TYPE,
		a.CONTRACT_START,
		a.CONTRACT_END,
		a.SUBJECT_DEPART,
		a.SUBJECT_UNIT,
		a.SITUATION,
		a.WORKING_HOURS,
		a.CREATE_NAME,
		a.CREATE_TIME,
		a.CONTRACT_SUB_NAME,
		a.REASON,
		a.TYPE,
		a.LEAVE_DATE,
		a.CONTRACT_NO,
		a.REDUCE_REASON,
		a.REMARK
		FROM t_employee_contract_info a
		left join (select REMARK,LINK_ID from t_employee_contract_audit where ROOT_NAME='合同审核') b on a.ID=b.LINK_ID

		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
		order by a.APPLY_NO desc
		<if test="tEmployeeContractInfo != null">
			<if test="tEmployeeContractInfo.limitStart != null">
				limit #{tEmployeeContractInfo.limitStart},#{tEmployeeContractInfo.limitEnd}
			</if>
		</if>
	</select>
	<!--tEmployeeContractInfo简单分页查询审核导出fxj-2022-11-04-->
	<select id="noPageCountDiy" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_employee_contract_info a
		<where>
			a.DELETE_FLAG = 0
			<include refid="tEmployeeContractInfo_where"/>
			<if test="tEmployeeContractInfo.authSql != null and tEmployeeContractInfo.authSql.trim() != ''">
				${tEmployeeContractInfo.authSql}
			</if>
		</where>
	</select>


	<!--*********************************B端合同列表开始2020-08-27**************************************-->
	<resultMap id="tEmpContractInfoBusinessMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.EmpContractBusinessPageVo">
		<id property="id" column="ID"/>
		<result property="empNo" column="EMP_NO"/>
		<result property="empId" column="EMP_ID"/>
		<result property="empName" column="EMP_NAME"/>
		<result property="empIdcard" column="EMP_IDCARD"/>
		<result property="contractName" column="CONTRACT_NAME"/>
		<result property="contractType" column="CONTRACT_TYPE"/>
		<result property="contractStart" column="CONTRACT_START"/>
		<result property="contractEnd" column="CONTRACT_END"/>
		<result property="situation" column="SITUATION"/>
		<result property="isObsolete" column="IS_OBSOLETE"/>
		<result property="settleDomain" column="SETTLE_DOMAIN"/>
		<result property="inUse" column="IN_USE"/>
	</resultMap>

	<!--B端合同列表简单分页查询-->
	<select id="getContractBusinessPage" resultMap="tEmpContractInfoBusinessMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM t_employee_contract_info a
		LEFT JOIN t_employee_contract_info b on a.EMP_ID=b.EMP_ID and b.CREATE_TIME >a.CREATE_TIME
		<where>
			b.id is NULL
			<if test="tEmployeeContractInfo != null">
				<if test="tEmployeeContractInfo.empName != null and tEmployeeContractInfo.empName.trim() != ''">
					AND a.EMP_NAME like CONCAT('%',#{tEmployeeContractInfo.empName},'%')
				</if>
				<if test="tEmployeeContractInfo.situation != null and tEmployeeContractInfo.situation != ''">
					AND a.SITUATION = #{tEmployeeContractInfo.situation}
				</if>
				<if test="tEmployeeContractInfo.isObsolete != null and tEmployeeContractInfo.isObsolete.trim() != ''">
					AND a.IS_OBSOLETE = #{tEmployeeContractInfo.isObsolete}
				</if>
				<if test="tEmployeeContractInfo.settleDomain != null and tEmployeeContractInfo.settleDomain != ''">
					AND a.SETTLE_DOMAIN = #{tEmployeeContractInfo.settleDomain}
				</if>
				<if test="tEmployeeContractInfo.inUse != null and tEmployeeContractInfo.inUse.trim() != ''">
					AND a.IN_USE = #{tEmployeeContractInfo.inUse}
				</if>
			</if>
			<if test="settleDomainIds != null and settleDomainIds.size >0">
				AND a.SETTLE_DOMAIN in
				<foreach item="item" index="index" collection="settleDomainIds" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="flag != null  and flag == 0">
				AND a.CONTRACT_END <![CDATA[<]]> ADDDATE(current_date,INTERVAL 3 month) AND a.CONTRACT_END <![CDATA[>]]> now()
				AND a.IN_USE = '0'
			</if>
		</where>
		order by a.EMP_ID,a.CONTRACT_START DESC
	</select>

	<select id="getContractBusinessAlertCount" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_employee_contract_info a
		LEFT JOIN t_employee_contract_info b on a.EMP_ID=b.EMP_ID and b.CREATE_TIME >a.CREATE_TIME
		<where>
			b.id is NULL
			<if test="tEmployeeContractInfo != null">
				<if test="tEmployeeContractInfo.empName != null and tEmployeeContractInfo.empName.trim() != ''">
					AND a.EMP_NAME like CONCAT(#{tEmployeeContractInfo.empName},'%')
				</if>
				<if test="tEmployeeContractInfo.situation != null and tEmployeeContractInfo.situation != ''">
					AND a.SITUATION = #{tEmployeeContractInfo.situation}
				</if>
				<if test="tEmployeeContractInfo.isObsolete != null and tEmployeeContractInfo.isObsolete.trim() != ''">
					AND a.IS_OBSOLETE = #{tEmployeeContractInfo.isObsolete}
				</if>
				<if test="tEmployeeContractInfo.settleDomain != null and tEmployeeContractInfo.settleDomain != ''">
					AND a.SETTLE_DOMAIN = #{tEmployeeContractInfo.settleDomain}
				</if>
				<if test="tEmployeeContractInfo.inUse != null and tEmployeeContractInfo.inUse.trim() != ''">
					AND a.IN_USE = #{tEmployeeContractInfo.inUse}
				</if>
			</if>
			<if test="settleDomainIds != null and settleDomainIds.size >0">
				AND a.SETTLE_DOMAIN in
				<foreach item="item" index="index" collection="settleDomainIds" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="alertMonth != null">
				AND a.CONTRACT_END <![CDATA[<]]> ADDDATE(current_date,INTERVAL #{alertMonth} month) AND a.CONTRACT_END <![CDATA[>]]> now()
			</if>
		</where>
	</select>

	<!--获取最新合同，通过员工身份证-->
	<select id="getOtherContractBusinessInfo" resultMap="tEmpContractInfoBusinessMap">
		SELECT
			a.ID,
			a.EMP_NO,
			a.EMP_ID,
			a.EMP_NAME,
			a.EMP_IDCARD,
			a.CONTRACT_NAME,
			a.CONTRACT_TYPE,
			a.CONTRACT_START,
			a.CONTRACT_END,
			a.SITUATION,
			a.IS_OBSOLETE,
			a.SETTLE_DOMAIN,
			a.IN_USE
		FROM t_employee_contract_info a
		where
		IS_OBSOLETE = '0'
		<if test="empId != null">
			AND a.EMP_ID = #{empId}
		</if>
		<if test="contractId != null">
			AND a.id !=  #{contractId}
		</if>
		ORDER BY a.CREATE_TIME  DESC
	</select>
	<!-- 根据员工ID更新合同在用状态 -->
	<update id="updateContractChange">
		update t_employee_contract_info a,t_settle_domain b
		set a.DEPT_NO=b.DEPART_NO,
		    a.SETTLE_DOMAIN=b.id,
		    a.UNIT_NO=b.CUSTOMER_NO,
		    a.CUSTOMER_ID=b.CUSTOMER_ID,
		    a.SUBJECT_DEPART=b.DEPART_NAME,
		    a.SUBJECT_UNIT=b.CUSTOMER_NAME
		where a.EMP_IDCARD = #{idCard} and a.DEPT_NO = #{oldDeptNo}  and b.DEPART_NO= #{deptNo}  and b.DELETE_FLAG='0';
	</update>

	<update id="updateContractEnd">
		update t_employee_contract_info a
		set a.CONTRACT_END=#{tEmployeeContractInfo.contractEnd}
		where a.ID=#{tEmployeeContractInfo.id}
	</update>
	<select id="getContractByEmpIdCardAndDeptId" resultType="java.lang.String">
		select
		       e.CONTRACT_START
		from t_employee_contract_info e
		where e.EMP_IDCARD = #{empIdCard} and e.SETTLE_DOMAIN = #{deptId}
			  and e.DELETE_FLAG = '0'
			  AND (
					( e.AUDIT_STATUS = '2' AND e.IN_USE = '0' )
					OR
					( e.AUDIT_STATUS = '1' AND e.IN_USE = '1' )
			  )
		limit 1
	</select>
</mapper>
