RoomStockMapper.xml 4.5 KB
<?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.sibu.orderHelper.integral.web.dao.IMWebRoomStockDao">
	<resultMap id="roomStockBeanResponse" type="com.sibu.orderHelper.hotel.model.RoomStockBean">
		<result property="stockId" column="stock_id" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="roomId" column="room_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="price" column="price" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="number" column="number" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="integral" column="integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="ispayIntegral" column="ispay_integral" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="stockDate" column="stock_date" javaType="java.lang.String" jdbcType="VARCHAR"/>
		<result property="createTime" column="create_time" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
		<result property="isOpen" column="is_open" javaType="java.lang.Integer" jdbcType="VARCHAR"/>
		<result property="hotelId" column="hotel_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
	</resultMap>
	<!-- 返回房型库存 -->
	<resultMap type="com.sibu.orderHelper.integral.reponse.RoomStockResponse" id="roomStockResponse">
		<result property="stockId" column="stock_id" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="price" column="price" javaType="java.lang.Double" jdbcType="DECIMAL"/>
		<result property="number" column="number" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="integral" column="integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="ispayIntegral" column="ispay_integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="isOpen" column="is_open" javaType="java.lang.Integer" jdbcType="INTEGER"/>
		<result property="dayTime" column="dt" ></result>
		<result property="weekOfDay" column="wd" ></result>
	</resultMap>
	
	<!-- 返回当前时间房型后的库存信息 -->
	<select id="selectRoomStockList" resultMap="roomStockResponse" parameterType="java.util.Map">
		SELECT stock_id,price,number,integral,DATE_FORMAT(stock_date,'%y年%c月%d号')AS dt,DATE_FORMAT(stock_date,"%w") AS wd,is_open
		from room_stock where room_id =#{roomId} and stock_date >=(now()-1)
	</select>
	
	<insert id="save" parameterType="com.sibu.orderHelper.hotel.model.RoomStockBean">
		INSERT INTO room_stock (
			stock_id,room_id,price,number,integral,ispay_integral,stock_date,create_time,is_open,hotel_id
		) VALUES (
			#{stockId},#{roomId},#{price},#{number},#{integral},#{ispayIntegral},#{stockDate},#{createTime},#{isOpen},#{hotelId}
		)
		<!-- <selectKey resultType="java.lang.String" keyProperty="stockId">
			<![CDATA[SELECT last_insert_id() AS id ]]>
		</selectKey> -->
	</insert>
	<update id="update" parameterType="com.sibu.orderHelper.hotel.model.RoomStockBean">
		UPDATE room_stock
		<trim prefix="SET" suffixOverrides=",">
			<if test="null != price">
				price=#{price},
			</if>
			<if test="null != number">
				number=#{number},
			</if>
			<if test="null != integral">
				integral=#{integral},
			</if>
			<if test="null != ispayIntegral">
				ispay_integral=#{ispayIntegral},
			</if>
			<if test="null != isOpen">
				is_open=#{isOpen},
			</if>
		</trim>
		WHERE stock_id = #{stockId}
	</update>
	<delete id="delete" parameterType="java.lang.Integer">
		DELETE FROM room_stock WHERE id = #{stockId}
	</delete>
	<delete id="batchDelete" parameterType="java.util.List">
		DELETE FROM room_stock WHERE id in
		<foreach collection="list" item="item"  open="(" separator="," close=")">  
			#{item} 
		</foreach>
	</delete>
	<!-- 批量保存 -->
	<insert id="batchSaveStock" parameterType="java.util.List">
		INSERT INTO room_stock(
  			room_id,
  			price,
		    number,
		    integral,
		    ispay_integral,
		    stock_date,
		    is_open,
		    hotel_id,
		    create_time
			) values
			<foreach collection="list" item="stock" separator=",">
				(#{stock.roomId},#{stock.price},#{stock.number},#{stock.integral},#{stock.ispayIntegral},#{stock.stockDate},#{stock.isOpen},#{stock.hotelId},now())
			</foreach>
	</insert>
	<!-- 查询房间的最后一天的时间的 -->
	<select id="selectStock" parameterType="java.util.Map" resultType="java.lang.String">
		SELECT stock_date FROM room_stock WHERE room_id =#{roomId} ORDER BY stock_date DESC LIMIT 1
	</select>
</mapper>