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

	<resultMap id="tEmployeeContractAreaResMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeContractAreaRes">
		<id property="id" column="ID"/>
		<result property="userId" column="USER_ID"/>
		<result property="fileProvince" column="FILE_PROVINCE"/>
		<result property="fileCity" column="FILE_CITY"/>
		<result property="fileTown" column="FILE_TOWN"/>
		<result property="userName" column="USER_NAME"/>
		<result property="status" column="STATUS"/>
		<result property="organName" column="ORGAN_NAME"/>
	</resultMap>
	<resultMap id="empContractAreaResExportMap" type="com.yifu.cloud.plus.v1.yifu.archives.vo.TEmpContractAreaExportVo">
		<result property="fileProvince" column="FILE_PROVINCE"/>
		<result property="fileCity" column="FILE_CITY"/>
		<result property="fileTown" column="FILE_TOWN"/>
		<result property="userName" column="USER_NAME"/>
		<result property="status" column="STATUS"/>
		<result property="organName" column="ORGAN_NAME"/>
	</resultMap>
	<sql id="Base_Column_List">
		a.ID,
		a.USER_ID,
		a.FILE_PROVINCE,
		a.FILE_CITY,
		a.FILE_TOWN,a.USER_NAME,a.STATUS,a.ORGAN_NAME
	</sql>
	<sql id="tEmployeeContractAreaRes_where">
		<if test="tEmployeeContractAreaRes != null">
			<if test="tEmployeeContractAreaRes.id != null and tEmployeeContractAreaRes.id.trim() != ''">
				AND a.ID = #{tEmployeeContractAreaRes.id}
			</if>
			<if test="tEmployeeContractAreaRes.userId != null and tEmployeeContractAreaRes.userId.trim() != ''">
				AND a.USER_ID = #{tEmployeeContractAreaRes.userId}
			</if>
			<if test="tEmployeeContractAreaRes.fileProvince != null">
				AND a.FILE_PROVINCE = #{tEmployeeContractAreaRes.fileProvince}
			</if>
			<if test="tEmployeeContractAreaRes.fileCity != null">
				AND a.FILE_CITY = #{tEmployeeContractAreaRes.fileCity}
			</if>
			<if test="tEmployeeContractAreaRes.fileTown != null">
				AND a.FILE_TOWN = #{tEmployeeContractAreaRes.fileTown}
			</if>
			<if test="tEmployeeContractAreaRes.status!= null">
				AND a.status like CONCAT(#{tEmployeeContractAreaRes.status},'%')
			</if>
			<if test="tEmployeeContractAreaRes.userName != null">
				AND a.USER_NAME like CONCAT('%',#{tEmployeeContractAreaRes.userName},'%')
			</if>
			<if test="tEmployeeContractAreaRes.organName != null">
				AND a.ORGAN_NAME like CONCAT('%',#{tEmployeeContractAreaRes.organName},'%')
			</if>
		</if>
	</sql>
	<!--tEmployeeContractAreaRes简单分页查询-->
	<select id="getTEmployeeContractAreaResPage" resultMap="tEmployeeContractAreaResMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_employee_contract_area_res a
		<where>
			1=1
			<include refid="tEmployeeContractAreaRes_where"/>
			order by a.CREATE_TIME desc
		</where>
	</select>

	<select id="noPageDiy" resultMap="empContractAreaResExportMap">
		SELECT
		a.FILE_PROVINCE,
		a.FILE_CITY,
		a.FILE_TOWN,a.USER_NAME,a.STATUS,a.ORGAN_NAME
		FROM t_employee_contract_area_res a
		<where>
			1=1
			<include refid="export_where"/>
			<if test="tEmployeeContractAreaRes != null">
				<if test="tEmployeeContractAreaRes.authSql != null and tEmployeeContractAreaRes.authSql.trim() != ''">
					${tEmployeeContractAreaRes.authSql}
				</if>
				<if test="tEmployeeContractAreaRes.limitStart != null">
					limit #{tEmployeeContractAreaRes.limitStart},#{tEmployeeContractAreaRes.limitEnd}
				</if>
			</if>
		</where>
	</select>
	<select id="noPageCountDiy"  resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_employee_contract_area_res a
		<where>
			1=1
			<include refid="export_where"/>
			<if test="tEmployeeContractAreaRes.authSql != null and tEmployeeContractAreaRes.authSql.trim() != ''">
				${tEmployeeContractAreaRes.authSql}
			</if>
		</where>
	</select>
	<sql id="export_where">
		<include refid="tEmployeeContractAreaRes_where"/>
		<if test="idsStr != null and idsStr.size > 0">
			AND a.ID in
			<foreach item="items" index="index" collection="idsStr" open="(" separator="," close=")">
				#{items}
			</foreach>
		</if>
		<!--数据权限判断-->
		<if test="settleDomainIds != null">
			<if test="settleDomainIds.size() > 0">
				and a.SETTLE_DOMAIN_ID in
				<foreach collection="settleDomainIds" item="param" index="index" open="(" close=")" separator=",">
					#{param}
				</foreach>
			</if>
			<if test="settleDomainIds.size() == 0">
				and 1=2
			</if>
		</if>
		<if test="settleDomainIds == null">
			and 1=1
		</if>
		<if test='sql != null and sql != ""'>
			and <![CDATA[sql]]>
		</if>
	</sql>
</mapper>
