<?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.DmsDormitoryCheckMapper">

    <resultMap type="DmsDormitoryCheck" id="DmsDormitoryCheckResult">
        <result property="checkId"    column="check_id"    />
        <result property="dormitoryId"    column="dormitory_id"    />
        <result property="dormitoryNumber"    column="dormitory_number"    />
        <result property="checkImage"    column="check_image"    />
        <result property="checkResult"    column="check_result"    />
        <result property="remark"    column="remark"    />
        <result property="checkDate"    column="check_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsDormitoryCheckVo">
        select check_id,dormitory_id, dormitory_number, check_image, check_result, remark, check_date, create_by, create_time, update_by, update_time from dms_dormitory_check
    </sql>

    <select id="selectDmsDormitoryCheckList" parameterType="DmsDormitoryCheck" resultMap="DmsDormitoryCheckResult">
        <include refid="selectDmsDormitoryCheckVo"/>
        <where>
            <if test="dormitoryNumber != null  and dormitoryNumber != ''"> and dormitory_number = #{dormitoryNumber}</if>
            <if test="checkImage != null  and checkImage != ''"> and check_image = #{checkImage}</if>
            <if test="checkResult != null  and checkResult != ''"> and check_result = #{checkResult}</if>
            <if test="checkDate != null "> and check_date = #{checkDate}</if>
        </where>
    </select>

    <select id="selectDmsDormitoryCheckByCheckId" parameterType="Long" resultMap="DmsDormitoryCheckResult">
        <include refid="selectDmsDormitoryCheckVo"/>
        where check_id = #{checkId}
    </select>

    <insert id="insertDmsDormitoryCheck" parameterType="DmsDormitoryCheck" useGeneratedKeys="true" keyProperty="checkId">
        insert into dms_dormitory_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dormitoryNumber != null and dormitoryNumber != ''">dormitory_number,</if>
            <if test="dormitoryId != null">dormitory_id,</if>
            <if test="checkImage != null and checkImage != ''">check_image,</if>
            <if test="checkResult != null and checkResult != ''">check_result,</if>
            <if test="remark != null">remark,</if>
            <if test="checkDate != null">check_date,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dormitoryNumber != null and dormitoryNumber != ''">#{dormitoryNumber},</if>
            <if test="dormitoryId != null">#{dormitoryId},</if>
            <if test="checkImage != null and checkImage != ''">#{checkImage},</if>
            <if test="checkResult != null and checkResult != ''">#{checkResult},</if>
            <if test="remark != null">#{remark},</if>
            <if test="checkDate != null">#{checkDate},</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>
        </trim>
    </insert>

    <update id="updateDmsDormitoryCheck" parameterType="DmsDormitoryCheck">
        update dms_dormitory_check
        <trim prefix="SET" suffixOverrides=",">
            <if test="dormitoryNumber != null and dormitoryNumber != ''">dormitory_number = #{dormitoryNumber},</if>
            <if test="checkImage != null and checkImage != ''">check_image = #{checkImage},</if>
            <if test="checkResult != null and checkResult != ''">check_result = #{checkResult},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="dormitoryId != null">dormitory_id = #{dormitoryId},</if>
            <if test="checkDate != null">check_date = #{checkDate},</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>
        </trim>
        where check_id = #{checkId}
    </update>

    <delete id="deleteDmsDormitoryCheckByCheckId" parameterType="Long">
        delete from dms_dormitory_check where check_id = #{checkId}
    </delete>

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

    <select id="listDorm" parameterType="DmsSearch" resultType="Map">
        select
        a.id,
        a.park_name,
        a.building_name,
        a.room_no,
        CONCAT(a.park_name, a.building_name, a.room_no) as dorm_name
        from view_dorm_info as a
        <where>
            <if test="parkName != null  and parkName != ''">
                and a.park_name like concat('%',#{parkName},'%')
            </if>
            <if test="buildingName != null  and buildingName != ''">
                and a.building_name like concat('%',#{buildingName},'%')
            </if>
            <if test="roomNo != null  and roomNo != ''">
                and a.room_no = #{roomNo}
            </if>
            <if test="dormitoryId != null">
                and a.id = #{dormitoryId}
            </if>
        </where>
        order by a.id asc
    </select>


</mapper>
