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

  <resultMap id="tElecEmployeeInfoMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TElecEmployeeInfo">
    <id property="id" column="ID"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="empNo" column="EMP_NO"/>
    <result property="unitName" column="UNIT_NAME"/>
    <result property="deptName" column="DEPT_NAME"/>
    <result property="deptNo" column="DEPT_NO"/>
    <result property="dataType" column="DATA_TYPE"/>
    <result property="deleteFlag" column="DELETE_FLAG"/>
    <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"/>
  </resultMap>

	<sql id="Base_Column_List">
		a.ID,
		a.EMP_NAME,
		a.EMP_IDCARD,
		a.DATA_TYPE,
		a.DELETE_FLAG,
		a.UPDATE_BY,
		a.CREATE_BY,
		a.CREATE_NAME,
		a.CREATE_TIME,
		a.UPDATE_TIME
	</sql>

	<sql id="tElecEmployeeInfo_where">
	<if test="tElecEmployeeInfo != null">
		<if test="tElecEmployeeInfo.id != null and tElecEmployeeInfo.id.trim() != ''">
			AND a.ID = #{tElecEmployeeInfo.id}
		</if>
		<if test="tElecEmployeeInfo.empName != null and tElecEmployeeInfo.empName.trim() != ''">
			AND a.EMP_NAME = #{tElecEmployeeInfo.empName}
		</if>
		<if test="tElecEmployeeInfo.empIdcard != null and tElecEmployeeInfo.empIdcard.trim() != ''">
			AND a.EMP_IDCARD = #{tElecEmployeeInfo.empIdcard}
		</if>
		<if test="tElecEmployeeInfo.dataType != null and tElecEmployeeInfo.dataType.trim() != ''">
			AND a.DATA_TYPE = #{tElecEmployeeInfo.dataType}
		</if>
		<if test="tElecEmployeeInfo.createBy != null and tElecEmployeeInfo.createBy.trim() != ''">
			AND a.CREATE_BY = #{tElecEmployeeInfo.createBy}
		</if>
		<if test="tElecEmployeeInfo.createName != null and tElecEmployeeInfo.createName.trim() != ''">
			AND a.CREATE_NAME = #{tElecEmployeeInfo.createName}
		</if>
		<if test="tElecEmployeeInfo.createTime != null">
			AND a.CREATE_TIME = #{tElecEmployeeInfo.createTime}
		</if>
		<if test="tElecEmployeeInfo.updateBy != null and tElecEmployeeInfo.updateBy.trim() != ''">
			AND a.UPDATE_BY = #{tElecEmployeeInfo.updateBy}
		</if>
		<if test="tElecEmployeeInfo.updateTime != null">
			AND a.UPDATE_TIME = #{tElecEmployeeInfo.updateTime}
		</if>
	</if>
	</sql>

	<!--tElecEmployeeInfo简单分页查询-->
	<select id="getTElecEmployeeInfoPage" resultMap="tElecEmployeeInfoMap">
		SELECT * from (
			SELECT
			<include refid="Base_Column_List"/>,GROUP_CONCAT(distinct c.DEPT_NAME) as DEPT_NAME,GROUP_CONCAT(distinct c.UNIT_NAME) as UNIT_NAME,GROUP_CONCAT(distinct c.DEPT_NO) as DEPT_NO,GROUP_CONCAT(distinct c.EMP_NO) as EMP_NO
			FROM t_elec_employee_info a
			left join t_employee_info b on a.EMP_IDCARD = b.EMP_IDCARD
			left join t_employee_project c on a.EMP_IDCARD = c.EMP_IDCARD AND c.DELETE_FLAG = '0' AND c.PROJECT_STATUS = '0'
			WHERE a.DELETE_FLAG = '0'
				<include refid="tElecEmployeeInfo_where"/>
			GROUP BY a.EMP_IDCARD,a.CREATE_TIME,a.DATA_TYPE
			ORDER BY a.CREATE_TIME desc
		) b
		where 1=1
		<if test="tElecEmployeeInfo.unitName != null and tElecEmployeeInfo.unitName.trim() != ''">
			AND b.UNIT_NAME like concat('%',#{tElecEmployeeInfo.unitName},'%')
		</if>
		<if test="tElecEmployeeInfo.deptName != null and tElecEmployeeInfo.deptName.trim() != ''">
			AND b.DEPT_NAME like concat('%',#{tElecEmployeeInfo.deptName},'%')
		</if>
		<if test="tElecEmployeeInfo.deptNo != null and tElecEmployeeInfo.deptNo.trim() != ''">
			AND b.DEPT_NO like concat('%',#{tElecEmployeeInfo.deptNo},'%')
		</if>
		<if test="tElecEmployeeInfo.empNo != null and tElecEmployeeInfo.empNo.trim() != ''">
			AND b.EMP_NO like concat('%',#{tElecEmployeeInfo.empNo},'%')
		</if>
	</select>
</mapper>
