<?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.comprehensive.mapper.CphDormitoryGoodMapper">
	
	<resultMap type="com.srs.comprehensive.domain.Vo.CphDormitoryGoodStuYear" id="CphDormitoryGoodStuYearResult">
		<result property="id" column="id"/>
		<result property="rank" column="rank"/>
		<result property="createBy" column="create_by"/>
		<result property="updateBy" column="update_by"/>
		<result property="status" column="status"/>
		<result property="buildingNo" column="building_no"/>
		<result property="floorNo" column="floor_no"/>
		<result property="roomNo" column="room_no"/>
		<result property="stuYearName" column="stu_year_name"/>
		<result property="number" column="number"/>
	</resultMap>
	
	<sql id="selectCphDormitoryGoodVo">
		select c.id,
		       c.create_by,
		       c.update_by,
		       c.rank,
		       c.status,
		       d.building_no,
		       d.floor_no,
		       d.room_no,
		       s.stu_year_name,
		       c.number
		from cph_dormitory_good c
			     join srs_dormitory d on c.dormitory_id = d.id
			     join srs_stu_year s on c.year_id = s.id
	</sql>
	
	<select id="selectCphDormitoryGoodList" parameterType="com.srs.comprehensive.domain.Vo.CphDormitoryGoodStuYear"
	        resultMap="CphDormitoryGoodStuYearResult">
		<include refid="selectCphDormitoryGoodVo"/>
		<where>
			<if test="dormitoryId != null ">and c.dormitory_id = #{dormitoryId}</if>
			<if test="yearId != null ">and c.year_id = #{yearId}</if>
			<if test="status != null ">and c.status = #{status}</if>
			<if test="number != null and number != ''">and c.number = #{number}</if>
		</where>
	</select>
	
	
	<select id="selectCphDormitoryGoodById" parameterType="Long" resultMap="CphDormitoryGoodStuYearResult">
		<include refid="selectCphDormitoryGoodVo"/>
		where c.id = #{id}
	</select>
	
	
	<insert id="insertCphDormitoryGood" parameterType="CphDormitoryGood" useGeneratedKeys="true" keyProperty="id">
		insert into cph_dormitory_good
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="dormitoryId != null">dormitory_id,</if>
			<if test="yearId != null">year_id,</if>
			<if test="createBy != null and createBy != ''">create_by,</if>
			<if test="updateBy != null and updateBy != ''">update_by,</if>
			<if test="rank != null and rank != ''">`rank`,</if>
			<if test="status != null">status,</if>
			<if test="number != null and number != ''">number,</if>
			<if test="createTime != null">create_time,</if>
			<if test="updateTime != null">update_time,</if>
			<if test="delFlag != null and delFlag != ''">del_flag,</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="dormitoryId != null">#{dormitoryId},</if>
			<if test="yearId != null">#{yearId},</if>
			<if test="createBy != null and createBy != ''">#{createBy},</if>
			<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
			<if test="rank != null and rank != ''">#{rank},</if>
			<if test="status != null">#{status},</if>
			<if test="number != null and number != ''">#{number},</if>
			<if test="createTime != null">#{createTime},</if>
			<if test="updateTime != null">#{updateTime},</if>
			<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
		</trim>
	</insert>
	
	<update id="updateCphDormitoryGood" parameterType="CphDormitoryGood">
		update cph_dormitory_good
		<trim prefix="SET" suffixOverrides=",">
			<if test="dormitoryId != null">dormitory_id = #{dormitoryId},</if>
			<if test="yearId != null">year_id = #{yearId},</if>
			<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
			<if test="rank != null and rank != ''">`rank`= #{rank},</if>
			<if test="status != null">status = #{status},</if>
			<if test="number != null and number != ''">number = #{number},</if>
			<if test="createTime != null">create_time = #{createTime},</if>
			<if test="updateTime != null">update_time = #{updateTime},</if>
			<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
		</trim>
		where id = #{id}
	</update>
	
	<delete id="deleteCphDormitoryGoodById" parameterType="Long">
		delete
		from cph_dormitory_good
		where id = #{id}
	</delete>
	
	<delete id="deleteCphDormitoryGoodByIds" parameterType="String">
		delete from cph_dormitory_good where id in
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>
</mapper>