<?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.srs.dormitory.mapper.DmsCheckLogMapper">

    <resultMap type="DmsCheckLog" id="DmsCheckLogResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="checkId"    column="check_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectDmsCheckLogVo">
        select id, stu_no, check_id, create_time from dms_check_log
    </sql>

    <select id="selectDmsCheckLogList" parameterType="DmsCheckLog" resultMap="DmsCheckLogResult">
        <include refid="selectDmsCheckLogVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="checkId != null "> and check_id = #{checkId}</if>
        </where>
    </select>

    <select id="selectDmsCheckLogById" parameterType="Long" resultMap="DmsCheckLogResult">
        <include refid="selectDmsCheckLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertDmsCheckLog" parameterType="DmsCheckLog" useGeneratedKeys="true" keyProperty="id">
        insert into dms_check_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="checkId != null">check_id,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="checkId != null">#{checkId},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateDmsCheckLog" parameterType="DmsCheckLog">
        update dms_check_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="checkId != null">check_id = #{checkId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsCheckLogById" parameterType="Long">
        delete from dms_check_log where id = #{id}
    </delete>

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


    <select id="listView" resultType="DmsCheckLog" parameterType="DmsCheckLog">
        select a.*,b.check_image,b.check_result,b.remark,b.check_date,c.park_name,c.building_name,c.room_no,d.stu_name,d.class_name,d.dept_name
        from dms_check_log as a
                 left join dms_dormitory_check as b on a.check_id = b.check_id
                 left join view_dorm_info as c on b.dormitory_id = c.id
                 left join view_stu_info as d on a.stu_no = d.stu_no
        <where>
            <if test="stuNo != null  and stuNo != ''"> and a.stu_no = #{stuNo}</if>
            <if test="checkId != null "> and a.check_id = #{checkId}</if>
            <if test="deptName != null  and deptName != ''"> and d.dept_name like concat('%',#{deptName},'%')</if>
            <if test="parkName != null  and parkName != ''"> and c.park_name like concat('%',#{parkName},'%')</if>
            <if test="className != null  and className != ''"> and d.class_name like concat('%',#{className},'%')</if>
            <if test="stuName != null  and stuName != ''"> and d.stu_name like concat('%',#{stuName},'%')</if>
            <if test="buildingName != null  and buildingName != ''"> and c.building_name like concat('%',#{buildingName},'%')</if>
            <if test="roomNo != null  and roomNo != ''"> and c.room_no = #{roomNo}</if>
            <if test="tNo != null  and tNo != ''"> and d.t_no = #{tNo}</if>
        </where>
        order by a.id desc
    </select>


</mapper>