<?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.itheima.dao.StudentCleanDao" >

    <!--分页查询-->
    <select id="getStudentCleanList" parameterType="StudentClean" resultType="StudentClean">
        select *from d_stgrade
        <where>
            <if test="s_studentid!=null and s_studentid!=0">
                and  s_studentid like  '%${s_studentid}%'
            </if>
            <if test="s_name !=null and s_name !=''">
                and  s_name like  '%${s_name}%'
            </if>
            <if test="s_dormitoryid!=null and s_dormitoryid!=0">
                and  s_dormitoryid like  '%${s_dormitoryid}%'
            </if>
        </where>
        ORDER BY  g_id asc
        limit #{currentPage},#{pageSize}
    </select>

    <!--查询数据总数-->
    <select id="totalCount"  resultType="Integer">
        select count(g_id) from d_stgrade
        <where>
            <if test="s_studentid!=null and s_studentid!=0">
                and  s_studentid like  '%${s_studentid}%'
            </if>
            <if test="s_name !=null and s_name !=''">
                and  s_name like  '%${s_name}%'
            </if>
            <if test="s_dormitoryid!=null and s_dormitoryid!=0">
                and  s_dormitoryid like  '%${s_dormitoryid}%'
            </if>
        </where>
    </select>

    <!--添加宿舍卫生信息-->
    <insert id="addStudentClean" parameterType="StudentClean" keyProperty="g_id" useGeneratedKeys="true">
        insert into d_stgrade (s_studentid,s_name,s_grade,s_classid,s_dormitoryid,create_time,update_time)
        values(#{s_studentid},#{s_name},#{s_grade},#{s_classid},#{s_dormitoryid},now(),now())
    </insert>

    <!--通过id删除宿舍卫生信息-->
    <delete id="deleteStudentClean" parameterType="Integer" >
        delete from d_stgrade where g_id=#{g_id}
    </delete>

    <select id="findStudentCleanById"  parameterType="Integer" resultType="StudentClean" >
        select * from d_stgrade where g_id=#{g_id}
    </select>

    <select id="getAll" resultType="StudentClean">
        select * from d_stgrade;
    </select>

    <!--修改宿舍卫生信息-->
    <update id="updateStudentClean" parameterType="StudentClean">
        update d_stgrade
        <set>
            <if test="s_studentid!=null and s_studentid!=0">
                s_studentid=#{s_studentid},
            </if>
            <if test="s_name !=null and s_name !=''">
                s_name=#{s_name},
            </if>
            <if test="s_grade!=null and s_grade!=0">
                s_grade=#{s_grade},
            </if>
            <if test="s_classid!=null and s_classid!=0">
                s_classid=#{s_classid},
            </if>
            <if test="s_dormitoryid!=null and s_dormitoryid!=0">
                s_dormitoryid=#{s_dormitoryid},
            </if>
            <if test="update_time != null" >
                update_time = now(),
            </if>
        </set>
        where g_id = #{g_id}
    </update>

    <!--宿舍卫生信息查询信息-->
    <resultMap type="com.itheima.po.StudentClean" id="cardAndInfo2">
        <id property="g_id" column="g_id"/>
        <result property="s_studentid" column="s_studentid" />
        <result property="s_name" column="s_name" />
        <result property="s_grade" column="s_grade" />
        <result property="s_classid" column="s_classid" />
        <result property="s_dormitoryid" column="s_dormitoryid" />
    </resultMap>


</mapper>
