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

    <resultMap type="DmsNewWenming" id="DmsNewWenmingResult">
        <result property="id"    column="id"    />
        <result property="dormitoryId"    column="dormitory_id"    />
        <result property="makeTime"    column="make_time"    />
        <result property="makeType"    column="make_type"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <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="delFlag"    column="del_flag"    />
    </resultMap>

<!--    <sql id="selectDmsNewWenmingVo">-->
<!--        select id, dormitory_id, make_time, make_type, status, remark, create_by, create_time, update_by, update_time, del_flag from dms_new_wenming-->
<!--    </sql>-->

<!--    <select id="selectDmsNewWenmingList" parameterType="DmsNewWenming" resultMap="DmsNewWenmingResult">-->
<!--        <include refid="selectDmsNewWenmingVo"/>-->
<!--        <where>-->
<!--            <if test="dormitoryId != null "> and dormitory_id = #{dormitoryId}</if>-->
<!--            <if test="makeTime != null "> and make_time = #{makeTime}</if>-->
<!--            <if test="makeType != null  and makeType != ''"> and make_type = #{makeType}</if>-->
<!--            <if test="status != null "> and status = #{status}</if>-->
<!--        </where>-->
<!--    </select>-->
    <sql id="selectDmsNewWenmingVo">
        select id,term_name,dept_name,class_name,room_no,ranking from dms_new_wenming
    </sql>

    <select id="selectDmsNewWenmingList" parameterType="DmsNewWenming" resultMap="DmsNewWenmingResult">
        <include refid="selectDmsNewWenmingVo"/>
        <where>
            <if test="termName != null and termName!='' "> and term_name = #{termName}</if>
            <if test="deptName != null and deptName!='' "> and dept_name = #{deptName}</if>
            <if test="className != null  and className != ''"> and class_name = #{className}</if>
            <if test="roomNo != null and roomNo!='' "> and room_no = #{roomNo}</if>
            <if test="ranking != null and ranking!='' "> and ranking = #{ranking}</if>
        </where>
    </select>

    <select id="selectDmsNewWenmingById" parameterType="Long" resultMap="DmsNewWenmingResult">
        <include refid="selectDmsNewWenmingVo"/>
        where id = #{id}
    </select>

    <insert id="insertDmsNewWenming" parameterType="DmsNewWenming" useGeneratedKeys="true" keyProperty="id">
        insert into dms_new_wenming
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dormitoryId != null">dormitory_id,</if>
            <if test="makeTime != null">make_time,</if>
            <if test="makeType != null">make_type,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="className != null">class_name,</if>
            <if test="termName != null">termName,</if>
            <if test="ranking != null">ranking,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dormitoryId != null">#{dormitoryId},</if>
            <if test="makeTime != null">#{makeTime},</if>
            <if test="makeType != null">#{makeType},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="deptName != null">{deptName},</if>
            <if test="className != null">{className},</if>
            <if test="termName != null">{termName},</if>
            <if test="ranking != null">{ranking},</if>
         </trim>
    </insert>

    <update id="updateDmsNewWenming" parameterType="DmsNewWenming">
        update dms_new_wenming
        <trim prefix="SET" suffixOverrides=",">
            <if test="dormitoryId != null">dormitory_id = #{dormitoryId},</if>
            <if test="makeTime != null">make_time = #{makeTime},</if>
            <if test="makeType != null">make_type = #{makeType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="termName != null">term_name = #{termName},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="ranking != null">ranking = #{ranking},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsNewWenmingById" parameterType="Long">
        delete from dms_new_wenming where id = #{id}
    </delete>

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

    <select id="listView" parameterType="DmsSearch" resultType="DomInfo">
        select a.make_time,a.id,a.dormitory_id,a.dept_name,a.class_name,a.term_name,a.room_no,a.ranking
--         concat(b.campus_name,' ',b.park_name,' ',b.building_name,' ',b.floor,'层 ',b.room_no) as room_no
        from dms_new_wenming as a
        left join view_dorm_info as b on a.dormitory_id = b.id
        <where>
            <if test="termName != null  and termName != ''"> and term_name like concat('%', #{termName}, '%')</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="ranking != null  and ranking != ''"> and ranking like concat('%', #{ranking}, '%')</if>
            <if test="roomNo != null  and roomNo != ''"> and a.room_no like concat('%', #{roomNo}, '%')</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
        </where>
        ORDER BY a.ranking asc
    </select>


</mapper>
