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

	<resultMap type="com.ym.mec.biz.dal.entity.EmployeeVisit" id="EmployeeVisit">
		<result column="id_" property="id" />
		<result column="employee_info_id_" property="employeeInfoId" />
		<result column="operator_id_" property="operatorId" />
		<result column="operator_name_" property="operatorName" />
		<result column="content_" property="content" />
		<result column="next_visit_date_" property="nextVisitDate" />
		<result column="create_time_" property="createTime" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>

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

	<!-- 全查询 -->
	<select id="findAll" resultMap="EmployeeVisit">
		SELECT * FROM employee_visit where tenant_id_ = #{tenantId}
		ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.EmployeeVisit"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO employee_visit
		(id_,employee_info_id_,operator_id_,content_,next_visit_date_,create_time_,tenant_id_)
		VALUES(#{id},#{employeeInfoId},#{operatorId},#{content},#{nextVisitDate},#{createTime},#{tenantId})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.EmployeeVisit">
		UPDATE employee_visit
		<set>
			<if test="operatorId != null">
				operator_id_ = #{operatorId},
			</if>
			<if test="nextVisitDate != null">
				next_visit_date_ = #{nextVisitDate},
			</if>
			<if test="employeeInfoId != null">
				employee_info_id_ = #{employeeInfoId},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="content != null">
				content_ = #{content},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM employee_visit WHERE id_ = #{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="EmployeeVisit" parameterType="map">
		SELECT * FROM employee_visit where tenant_id_ = #{tenantId} ORDER BY id_
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM employee_visit where tenant_id_ = #{tenantId}
	</select>
	
	<select id="queryByEmployeeInfoId" resultMap="EmployeeVisit">
		SELECT ev.*,u.real_name_ operator_name_ FROM employee_visit ev left join sys_user u on ev.operator_id_ = u.id_
		WHERE ev.employee_info_id_ = #{employeeInfoId} order by ev.id_ desc
	</select>
</mapper>
