<?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.fjs.scenic.mapper.order.OrderDetailsMapper">
	<resultMap id="BaseResultMap" type="com.fjs.scenic.entity.order.OrderDetails">
		<constructor>
			<arg column="order_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
			<arg column="goods_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
			<arg column="num" jdbcType="INTEGER" javaType="java.lang.Integer" />
			<arg column="price" jdbcType="INTEGER" javaType="java.lang.Integer" />
		</constructor>
	</resultMap>

	<insert id="insert" parameterType="com.fjs.scenic.entity.order.OrderDetails">
		insert into order_details
		(order_id, goods_id, num,
		price)
		values (#{orderId,jdbcType=INTEGER},
		#{goodsId,jdbcType=INTEGER},
		#{num,jdbcType=INTEGER},
		#{price,jdbcType=INTEGER})
	</insert>

	<update id="update" parameterType="com.fjs.scenic.entity.order.OrderDetails">
		update order_details
		<set>
			<if test="orderId != null">
				order_id = #{orderId,jdbcType=VARCHAR},
			</if>
			<if test="goodsId != null">
				goods_id = #{goodsId,jdbcType=VARCHAR},
			</if>
			<if test="num != null">
				num = #{num,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				price = #{price,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

	<delete id="delete" parameterType="com.fjs.scenic.entity.order.OrderDetails">
		delete from order_details where 1=1
		<if test="id != null"> and id = #{id}</if>
		<if test="orderId != null">
			and order_id = #{orderId,jdbcType=VARCHAR}
		</if>
		<if test="goodsId != null">
			and goods_id = #{goodsId,jdbcType=VARCHAR}
		</if>
		<if test="num != null">
			and num = #{num,jdbcType=VARCHAR}
		</if>
		<if test="price != null">
			and price = #{price,jdbcType=VARCHAR}
		</if>
	</delete>

	<select id="select" resultMap="BaseResultMap"
		parameterType="com.fjs.scenic.entity.order.OrderDetails">
		select * from order_details where 1 = 1
		<if test="id != null"> and id = #{id}</if>
		<if test="orderId != null">
			and order_id = #{orderId,jdbcType=VARCHAR}
		</if>
		<if test="goodsId != null">
			and goods_id = #{goodsId,jdbcType=VARCHAR}
		</if>
		<if test="num != null">
			and num = #{num,jdbcType=VARCHAR}
		</if>
		<if test="price != null">
			and price = #{price,jdbcType=VARCHAR}
		</if>
	</select>

	<select id="selectByParam" resultMap="BaseResultMap"
		parameterType="java.util.Map">
		select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> * </if>
		from order_details
		<if test="param != null and param != ''">where ${param}</if>
	</select>

	<delete id="deleteByParam" parameterType="java.util.Map">
		delete from order_details
		<if test="param != null and param != ''">where ${param}</if>
	</delete>

	<update id="updateByParam" parameterType="java.util.Map">
		<if test="param != null and param !=''">update order_details set ${param}</if>
	</update>
	
	<select id="getTicketNum" resultType="java.lang.Integer">
		SELECT SUM(num) num FROM order_details WHERE order_id=#{orderId}
	</select>
	
	
	<delete id="deleteByOrderId">
		delete from order_details where order_id=#{orderId}
	</delete>
	
	
</mapper>