<?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.StudentBasicInfoDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.StudentBasicInfo" id="StudentBasicInfo">
		<result column="user_id_" property="userId" />
		<result column="user_name_" property="userName" />
		<result column="phone_" property="phone" />
		<result column="subject_id_" property="subjectId" />
		<result column="subject_name_" property="subjectName" />
		<result column="grade_" property="grade" />
		<result column="organ_id_" property="organId" />
		<result column="organ_name_" property="organName" />
		<result column="cooperation_organ_id_" property="cooperationOrganId" />
		<result column="cooperation_organ_name_" property="cooperationOrganName" />
		<result column="subject_teacher_id_" property="subjectTeacherId" />
		<result column="subject_teacher_name_" property="subjectTeacherName" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="StudentBasicInfo" >
		SELECT * FROM student_basic_info WHERE user_id_ = #{userId} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="StudentBasicInfo">
		SELECT * FROM student_basic_info ORDER BY user_id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentBasicInfo" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO student_basic_info (user_id_,user_name_,phone_,subject_id_,subject_name_,grade_,organ_id_,organ_name_,cooperation_organ_id_,cooperation_organ_name_,subject_teacher_id_,subject_teacher_name_) VALUES(#{userId},#{userName},#{phone},#{subjectId},#{subjectName},#{grade},#{organId},#{organName},#{cooperationOrganId},#{cooperationOrganName},#{subjectTeacherId},#{subjectTeacherName})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentBasicInfo">
		UPDATE student_basic_info <set>
			<if test="subjectId != null">
			subject_id_ = #{subjectId},
			</if>
			<if test="subjectName != null">
			subject_name_ = #{subjectName},
			</if>
			<if test="userId != null">
			user_id_ = #{userId},
			</if>
			<if test="organId != null">
			organ_id_ = #{organId},
			</if>
			<if test="subjectTeacherId != null">
			subject_teacher_id_ = #{subjectTeacherId},
			</if>
			<if test="userName != null">
			user_name_ = #{userName},
			</if>
			<if test="cooperationOrganId != null">
			cooperation_organ_id_ = #{cooperationOrganId},
			</if>
			<if test="organName != null">
			organ_name_ = #{organName},
			</if>
			<if test="phone != null">
			phone_ = #{phone},
			</if>
			<if test="cooperationOrganName != null">
			cooperation_organ_name_ = #{cooperationOrganName},
			</if>
			<if test="grade != null">
			grade_ = #{grade},
			</if>
			<if test="subjectTeacherName != null">
			subject_teacher_name_ = #{subjectTeacherName},
			</if>
		</set> WHERE user_id_ = #{userId}
	</update>

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

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="StudentBasicInfo" parameterType="map">
		SELECT * FROM student_basic_info ORDER BY user_id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM student_basic_info
	</select>
    <select id="getMaxId" resultType="java.lang.Integer">
		SELECT MAX(id_) FROM student_basic_info
	</select>
	<update id="updateSubjectTeacher">
		SELECT updateSubjectTeacher()
	</update>
</mapper>
