<?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.ym.mec.biz.dal.dao.EmployeeInfoDao">

	<resultMap type="com.ym.mec.biz.dal.entity.EmployeeInfo" id="EmployeeInfo">
		<result column="id_" property="id" />
		<result column="real_name_" property="realName" />
		<result column="mobile_no_" property="mobileNo" />
		<result column="wechat_no_" property="wechatNo" />
		<result column="id_card_" property="idCard" />
		<result column="age_" property="age" />
		<result column="gender_" property="gender" />
		<result column="birthdate_" property="birthdate" />
		<result column="emergency_contact_name_" property="emergencyContactName" />
		<result column="emergency_contact_relation_" property="emergencyContactRelation" />
		<result column="emergency_contact_phone_" property="emergencyContactPhone" />
		<result column="live_city_" property="liveCity" />
		<result column="intention_city_" property="intentionCity" />
		<result column="educational_background_" property="educationalBackground" />
		<result column="subject_id_list_" property="subjectIdList" />
		<result column="assessment_result_" property="assessmentResult" />
		<result column="other_comment_" property="otherComment" />
		<result column="entry_date_" property="entryDate" />
		<result column="position_" property="position" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="is_probation_period_" property="isProbationPeriod" />
		<result column="bank_card_no_" property="bankCardNo" />
		<result column="bank_address_" property="bankAddress" />
		<result column="resignation_date_" property="resignationDate" />
		<result column="organ_id_" property="organId" />
		<result column="operator_id_" property="operatorId" />
		<result column="source_from_" property="sourceFrom" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="organName" property="organName" />
		<result column="subjectName" property="subjectName" />
		<result column="operatorName" property="operatorName" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="EmployeeInfo">
		SELECT * FROM
		employee_info WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="EmployeeInfo">
		SELECT * FROM employee_info ORDER
		BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.EmployeeInfo"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO employee_info
		(id_,real_name_,mobile_no_,wechat_no_,id_card_,age_,gender_,birthdate_,emergency_contact_name_,emergency_contact_relation_,emergency_contact_phone_,live_city_,intention_city_,educational_background_,subject_id_list_,assessment_result_,other_comment_,entry_date_,organ_id_,position_,status_,is_probation_period_,bank_card_no_,bank_address_,resignation_date_,operator_id_,source_from_,create_time_,update_time_)
		VALUES(#{id},#{realName},#{mobileNo},#{wechatNo},#{idCard},#{age},#{gender},#{birthdate},#{emergencyContactName},#{emergencyContactRelation},#{emergencyContactPhone},#{liveCity},#{intentionCity},#{educationalBackground},#{subjectIdList},#{assessmentResult},#{otherComment},#{entryDate},#{organId},#{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isProbationPeriod},#{bankCardNo},#{bankAddress},#{resignationDate},#{operatorId},#{sourceFrom},#{createTime},#{updateTime})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.EmployeeInfo">
		UPDATE employee_info
		<set>
			<if test="isProbationPeriod != null">
				is_probation_period_ = #{isProbationPeriod},
			</if>
			<if test="subjectIdList != null">
				subject_id_list_ = #{subjectIdList},
			</if>
				gender_ = #{gender},
				entry_date_ = #{entryDate},
				other_comment_ = #{otherComment},
			<if test="status != null">
				status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
				educational_background_ = #{educationalBackground},
				emergency_contact_phone_ = #{emergencyContactPhone},
				resignation_date_ = #{resignationDate},
				position_ = #{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			<if test="updateTime != null">
				update_time_ = #{updateTime},
			</if>
				emergency_contact_relation_ = #{emergencyContactRelation},
			<if test="id != null">
				id_ = #{id},
			</if>
				bank_card_no_ = #{bankCardNo},
				real_name_ = #{realName},
				id_card_ = #{idCard},
				age_ = #{age},
				live_city_ = #{liveCity},
				intention_city_ = #{intentionCity},
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
				wechat_no_ = #{wechatNo},
				assessment_result_ = #{assessmentResult},
				mobile_no_ = #{mobileNo},
				emergency_contact_name_ = #{emergencyContactName},
				birthdate_ = #{birthdate},
				bank_address_ = #{bankAddress},
			<if test="organId != null">
				organ_id_ = #{organId},
			</if>
			<if test="operatorId != null">
				operator_id_ = #{operatorId},
			</if>
				source_from_ = #{sourceFrom}
		</set>
		WHERE id_ = #{id}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM employee_info WHERE id_ = #{id}
	</delete>
	
	<sql id="queryPageMap">
		<where>
			<if test="organId != null">
            	AND ei.organ_id_ = #{organId}
	        </if>
	        <if test="userNameOrIdOrMobile != null">
	            AND (ei.real_name_ LIKE CONCAT('%',#{userNameOrIdOrMobile},'%') OR ei.mobile_no_ LIKE CONCAT('%',#{userNameOrIdOrMobile},'%') OR ei.id_ = #{userNameOrIdOrMobile})
	        </if>
	        <if test="subjectId != null">
	            AND find_in_set(#{subjectId},ei.subject_id_list_)
	        </if>
	        <if test="sourceFrom != null">
	            AND ei.source_from_ = #{sourceFrom}
	        </if>
	        <if test="position != null">
	            AND ei.position_ = #{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
	        </if>
	        <if test="status != null">
	            AND ei.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
	        </if>
	        <if test="startDate != null">
	            AND ei.update_time_ &gt;= #{startDate}
	        </if>
	        <if test="endDate != null">
	            AND ei.update_time_ &lt;= #{endDate}
	        </if>
	        <if test="operator != null">
	            AND (ei.operator_id_ like concat('%',#{operator},'%') or u.real_name_ like concat('%',#{operator},'%'))
	        </if>
		</where>
    </sql>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="EmployeeInfo" parameterType="map">
		SELECT o.name_ organName,group_concat(s.name_) subjectName,u.real_name_ operatorName,ei.* FROM employee_info ei
		left join subject s on find_in_set(s.id_,ei.subject_id_list_)
		left join organization o on o.id_ = ei.organ_id_
		left join sys_user u on u.id_ = ei.operator_id_
        <include refid="queryPageMap"/>
        GROUP BY ei.id_
		ORDER BY ei.update_time_ desc
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(ei.id_) FROM employee_info ei
		left join sys_user u on u.id_ = ei.operator_id_
        <include refid="queryPageMap"/>
	</select>
</mapper>
