<?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.qmth.jkserver.dao.ExamRoomDao">

    <delete id="deleteByExamCode">
        delete t from jk_exam_room t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
    </delete>

    <select id="findPlaceCodeAndPlaceNameAndCount" resultType="java.util.HashMap">
        SELECT t.place_code as placeCode,t.place_name as placeName,count(1) as count from jk_exam_room t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
        group by t.place_code,t.place_name
        order by t.place_code
    </select>

    <select id="findRoomCodeAndRoomNameAndCount" resultType="java.util.HashMap">
        SELECT t.room_code as roomCode,t.room_name as roomName,count(1) as count from jk_exam_room t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
        group by t.room_code,t.room_name
        order by t.room_code
    </select>

    <select id="listPage" resultType="com.qmth.jkserver.model.ExamRoom">
        SELECT t.* from jk_exam_room t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
            <if test="placeCode != null and placeCode != ''">
                and t.place_code = #{placeCode}
            </if>
            <if test="roomCode != null and roomCode != ''">
                and t.room_code = #{roomCode}
            </if>
            <if test="placeName != null and placeName != ''">
                and t.place_name like concat('%', #{placeName}, '%')
            </if>
            <if test="kjAlready != null and kjAlready != '' or kjAlready == 0">
                and t.kjAlready = #{kjAlready}
            </if>
        </where>
        order by t.place_code,t.room_code
    </select>

    <sql id="listPageByKwSql">
        SELECT t.* from jk_exam_room t
        <include refid="whereCommon" />
        order by t.place_code,t.room_code
    </sql>

    <sql id="whereCommon">
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
            <if test="placeCode != null and placeCode != ''">
                and t.place_code = #{placeCode}
            </if>
            <if test="placeName != null and placeName != ''">
                and t.place_name like concat('%', #{placeName}, '%')
            </if>
            <if test="kwKcAlready != null and kwKcAlready != '' or kwKcAlready == 0">
                and t.kw_kc_already = #{kwKcAlready}
            </if>
            <if test="kwPaperAlready != null and kwPaperAlready != '' or kwPaperAlready == 0">
                and t.kw_paper_already = #{kwPaperAlready}
            </if>
            <if test="kwUncolilingAlready != null and kwUncolilingAlready != '' or kwUncolilingAlready == 0">
                and t.kw_uncoliling_already = #{kwUncolilingAlready}
            </if>
        </where>
    </sql>

    <select id="listPageByKw" resultType="com.qmth.jkserver.model.ExamRoom">
       <include refid="listPageByKwSql" />
    </select>

    <select id="listPageCount" resultType="java.lang.Long">
        SELECT count(1) from jk_exam_room t
        <include refid="whereCommon" />
    </select>
</mapper>
