<?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.StudentInfoMapper">
    
    <resultMap type="StudentInfo" id="StudentInfoResult">
        <result property="id"    column="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="height"    column="height"    />
        <result property="weight"    column="weight"    />
        <result property="bloodType"    column="blood_type"    />
        <result property="politicalStatus"    column="political_status"    />
        <result property="identificationPhoto"    column="identification_photo"    />
        <result property="entrancePermit"    column="entrance_permit"    />
        <result property="fatherName"    column="father_name"    />
        <result property="fatherTelephone"    column="father_telephone"    />
        <result property="motherName"    column="mother_name"    />
        <result property="motherTelephone"    column="mother_telephone"    />
        <result property="address"    column="address"    />
        <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"    />

        <result property="isNearsightedness"    column="is_nearsightedness"    />
        <result property="degreeMyopia"    column="degree_myopia"    />
        <result property="health"    column="health"    />
        <result property="mind"    column="mind"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />

        <result property="classId"    column="classId"    />

    </resultMap>

    <sql id="selectStudentInfoVo">
        select id, student_id, name, sex, age, school, student_number, id_card, height, weight, blood_type, political_status, identification_photo,
               entrance_permit, father_name, father_telephone, mother_name, mother_telephone, address, create_by, create_time, update_by, update_time,
               remark,is_nearsightedness,degree_myopia,health,mind,longitude,latitude from student_info
    </sql>

    <select id="selectStudentInfoList" parameterType="StudentInfo" resultMap="StudentInfoResult">
        select s.id, s.student_id, s.name, s.sex, s.age, s.school, s.student_number, s.id_card, s.height, s.weight, s.blood_type, s.political_status, s.identification_photo,
        s.entrance_permit, s.father_name, s.father_telephone, s.mother_name, s.mother_telephone, s.address, s.create_by, s.create_time, s.update_by, s.update_time, s.remark,
        s.is_nearsightedness,s.degree_myopia,s.health,mind,s.longitude,s.latitude
        from student_info s
        left join formal_parents_student f on s.student_id = f.id
        <where>  
            <if test="studentId != null "> and s.student_id = #{studentId}</if>
            <if test="name != null  and name != ''"> and s.name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and s.sex = #{sex}</if>
            <if test="age != null  and age != ''"> and s.age = #{age}</if>
            <if test="school != null  and school != ''"> and s.school = #{school}</if>
            <if test="studentNumber != null  and studentNumber != ''"> and s.student_number = #{studentNumber}</if>
            <if test="idCard != null  and idCard != ''"> and s.id_card = #{idCard}</if>
            <if test="height != null  and height != ''"> and s.height = #{height}</if>
            <if test="weight != null  and weight != ''"> and s.weight = #{weight}</if>
            <if test="bloodType != null  and bloodType != ''"> and s.blood_type = #{bloodType}</if>
            <if test="politicalStatus != null  and politicalStatus != ''"> and s.political_status = #{politicalStatus}</if>
            <if test="identificationPhoto != null  and identificationPhoto != ''"> and s.identification_photo = #{identificationPhoto}</if>
            <if test="entrancePermit != null  and entrancePermit != ''"> and s.entrance_permit = #{entrancePermit}</if>
            <if test="fatherName != null  and fatherName != ''"> and s.father_name like concat('%', #{fatherName}, '%')</if>
            <if test="fatherTelephone != null  and fatherTelephone != ''"> and s.father_telephone = #{fatherTelephone}</if>
            <if test="motherName != null  and motherName != ''"> and s.mother_name like concat('%', #{motherName}, '%')</if>
            <if test="motherTelephone != null  and motherTelephone != ''"> and s.mother_telephone = #{motherTelephone}</if>
            <if test="address != null  and address != ''"> and s.address = #{address}</if>
            <if test="classId != null "> and f.class_id = #{classId}</if>
        </where>
    </select>
    
    <select id="selectStudentInfoById" parameterType="Long" resultMap="StudentInfoResult">
        <include refid="selectStudentInfoVo"/>
        where id = #{id}
    </select>


    <insert id="insertStudentInfo" parameterType="StudentInfo" useGeneratedKeys="true" keyProperty="id">
        insert into student_info
        <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="height != null">height,</if>
            <if test="weight != null">weight,</if>
            <if test="bloodType != null">blood_type,</if>
            <if test="politicalStatus != null">political_status,</if>
            <if test="identificationPhoto != null">identification_photo,</if>
            <if test="entrancePermit != null">entrance_permit,</if>
            <if test="fatherName != null">father_name,</if>
            <if test="fatherTelephone != null">father_telephone,</if>
            <if test="motherName != null">mother_name,</if>
            <if test="motherTelephone != null">mother_telephone,</if>
            <if test="address != null">address,</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>

            <if test="isNearsightedness != null">is_nearsightedness,</if>
            <if test="degreeMyopia != null">degree_myopia,</if>
            <if test="health != null">health,</if>
            <if test="mind != null">mind,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</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="height != null">#{height},</if>
            <if test="weight != null">#{weight},</if>
            <if test="bloodType != null">#{bloodType},</if>
            <if test="politicalStatus != null">#{politicalStatus},</if>
            <if test="identificationPhoto != null">#{identificationPhoto},</if>
            <if test="entrancePermit != null">#{entrancePermit},</if>
            <if test="fatherName != null">#{fatherName},</if>
            <if test="fatherTelephone != null">#{fatherTelephone},</if>
            <if test="motherName != null">#{motherName},</if>
            <if test="motherTelephone != null">#{motherTelephone},</if>
            <if test="address != null">#{address},</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>

            <if test="isNearsightedness != null">#{isNearsightedness},</if>
            <if test="degreeMyopia != null">#{degreeMyopia},</if>
            <if test="health != null">#{health},</if>
            <if test="mind != null">#{mind},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>

         </trim>
    </insert>

    <update id="updateStudentInfo" parameterType="StudentInfo">
        update student_info
        <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="height != null">height = #{height},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="bloodType != null">blood_type = #{bloodType},</if>
            <if test="politicalStatus != null">political_status = #{politicalStatus},</if>
            <if test="identificationPhoto != null">identification_photo = #{identificationPhoto},</if>
            <if test="entrancePermit != null">entrance_permit = #{entrancePermit},</if>
            <if test="fatherName != null">father_name = #{fatherName},</if>
            <if test="fatherTelephone != null">father_telephone = #{fatherTelephone},</if>
            <if test="motherName != null">mother_name = #{motherName},</if>
            <if test="motherTelephone != null">mother_telephone = #{motherTelephone},</if>
            <if test="address != null">address = #{address},</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>

            <if test="isNearsightedness != null">is_nearsightedness= #{isNearsightedness},</if>
            <if test="degreeMyopia != null">degree_myopia= #{degreeMyopia},</if>
            <if test="health != null">health= #{health},</if>
            <if test="mind != null">mind= #{mind},</if>
            <if test="longitude != null">longitude= #{longitude},</if>
            <if test="latitude != null">latitude= #{latitude},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStudentInfoById" parameterType="Long">
        delete from student_info where id = #{id}
    </delete>

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