<?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.ruoyi.system.mapper.StudentMindOldMapper">
    
    <resultMap type="StudentMindOld" id="StudentMindOldResult">
        <result property="mindId"    column="mind_id"    />
        <result property="studentId"    column="student_id"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="age"    column="age"    />
        <result property="school"    column="school"    />
        <result property="studentNumber"    column="student_number"    />
        <result property="idCard"    column="id_card"    />
        <result property="mind"    column="mind"    />
        <result property="psychologicalDescription"    column="psychological_description"    />

        <result property="createType"    column="create_type"    />

        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectStudentMindOldVo">
        select mind_id, student_id, name, sex, age, school, student_number, id_card, mind, psychological_description,create_type, create_by, create_time, update_by, update_time, remark from student_mind_old
    </sql>

    <select id="selectStudentMindOldList" parameterType="StudentMindOld" resultMap="StudentMindOldResult">
        <include refid="selectStudentMindOldVo"/>
        <where>  
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="age != null  and age != ''"> and age = #{age}</if>
            <if test="school != null  and school != ''"> and school = #{school}</if>
            <if test="studentNumber != null  and studentNumber != ''"> and student_number = #{studentNumber}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="mind != null  and mind != ''"> and mind = #{mind}</if>
            <if test="psychologicalDescription != null  and psychologicalDescription != ''"> and psychological_description = #{psychologicalDescription}</if>
            <if test="createType != null and createType != ''"> and create_type = #{createType}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectStudentMindOldByMindId" parameterType="Long" resultMap="StudentMindOldResult">
        <include refid="selectStudentMindOldVo"/>
        where mind_id = #{mindId}
    </select>
        
    <insert id="insertStudentMindOld" parameterType="StudentMindOld" useGeneratedKeys="true" keyProperty="mindId">
        insert into student_mind_old
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="studentId != null">student_id,</if>
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="age != null">age,</if>
            <if test="school != null">school,</if>
            <if test="studentNumber != null">student_number,</if>
            <if test="idCard != null">id_card,</if>
            <if test="mind != null">mind,</if>
            <if test="psychologicalDescription != null">psychological_description,</if>
            <if test="createType != null">create_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="studentId != null">#{studentId},</if>
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="age != null">#{age},</if>
            <if test="school != null">#{school},</if>
            <if test="studentNumber != null">#{studentNumber},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="mind != null">#{mind},</if>
            <if test="psychologicalDescription != null">#{psychologicalDescription},</if>
            <if test="createType != null"> #{createType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateStudentMindOld" parameterType="StudentMindOld">
        update student_mind_old
        <trim prefix="SET" suffixOverrides=",">
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="age != null">age = #{age},</if>
            <if test="school != null">school = #{school},</if>
            <if test="studentNumber != null">student_number = #{studentNumber},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="mind != null">mind = #{mind},</if>
            <if test="psychologicalDescription != null">psychological_description = #{psychologicalDescription},</if>
            <if test="createType != null">create_type = #{createType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where mind_id = #{mindId}
    </update>

    <delete id="deleteStudentMindOldByMindId" parameterType="Long">
        delete from student_mind_old where mind_id = #{mindId}
    </delete>

    <delete id="deleteStudentMindOldByMindIds" parameterType="String">
        delete from student_mind_old where mind_id in 
        <foreach item="mindId" collection="array" open="(" separator="," close=")">
            #{mindId}
        </foreach>
    </delete>
</mapper>