<?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.keao.edu.user.dao.ExamLifecycleLogDao">
	
	<resultMap type="com.keao.edu.user.entity.ExamLifecycleLog" id="ExamLifecycleLog">
		<result column="id_" property="id" />
		<result column="examination_basic_id_" property="examinationBasicId" />
		<result column="event_name_" property="eventName" />
		<result column="operator_user_id_" property="operatorUserId" />
		<result column="memo_" property="memo" />
		<result column="create_time_" property="createTime" />
	</resultMap>

	<resultMap id="ExamLifecycleLogDto" type="com.keao.edu.user.dto.ExamLifecycleLogDto" extends="ExamLifecycleLog">
		<result column="real_name_" property="operatorName"/>
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="ExamLifecycleLog" >
		SELECT * FROM exam_lifecycle_log WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ExamLifecycleLog">
		SELECT * FROM exam_lifecycle_log ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.keao.edu.user.entity.ExamLifecycleLog" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO exam_lifecycle_log (id_,examination_basic_id_,event_name_,operator_user_id_,memo_,create_time_)
		VALUES(#{id},#{examinationBasicId},#{eventName},#{operatorUserId},#{memo},NOW())
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.keao.edu.user.entity.ExamLifecycleLog">
		UPDATE exam_lifecycle_log
		<set>
			<if test="examinationBasicId != null">
				examination_basic_id_ = #{examinationBasicId},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="memo != null">
				memo_ = #{memo},
			</if>
			<if test="operatorUserId != null">
				operator_user_id_ = #{operatorUserId},
			</if>
			<if test="eventName != null">
				event_name_ = #{eventName},
			</if>
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM exam_lifecycle_log WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ExamLifecycleLog" parameterType="map">
		SELECT * FROM exam_lifecycle_log ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM exam_lifecycle_log
	</select>

    <select id="findWithExam" resultMap="ExamLifecycleLogDto">
		SELECT elo.*,su.real_name_ FROM exam_lifecycle_log elo
		LEFT JOIN sys_user su ON  elo.operator_user_id_=su.id_
		WHERE examination_basic_id_=#{examId}
		ORDER BY id_ DESC
	</select>
</mapper>
