<?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.fuxi.ws.data.dao.WReturndtlMapper">
	<resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WReturndtl">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		<id column="ReturnID" jdbcType="BIGINT" property="returnid" />
		<id column="GoodsID" jdbcType="VARCHAR" property="goodsid" />
		<id column="ColorID" jdbcType="VARCHAR" property="colorid" />
		<id column="SizeID" jdbcType="VARCHAR" property="sizeid" />
		<result column="Quantity" jdbcType="INTEGER" property="quantity" />
		<result column="UnitPrice" jdbcType="DECIMAL" property="unitprice" />
		<result column="Amount" jdbcType="DECIMAL" property="amount" />
		<result column="SendTimes" jdbcType="DECIMAL" property="sendtimes" />
		<result column="SendPoint" jdbcType="INTEGER" property="sendpoint" />
		<result column="AllotSales" jdbcType="DECIMAL" property="allotsales" />
		<result column="Integral" jdbcType="INTEGER" property="integral" />
	</resultMap>
	<sql id="Example_Where_Clause">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		<where>
			<foreach collection="oredCriteria" item="criteria" separator="or">
				<if test="criteria.valid">
					<trim prefix="(" prefixOverrides="and" suffix=")">
						<foreach collection="criteria.criteria" item="criterion">
							<choose>
								<when test="criterion.noValue">
									and ${criterion.condition}
								</when>
								<when test="criterion.singleValue">
									and ${criterion.condition} #{criterion.value}
								</when>
								<when test="criterion.betweenValue">
									and ${criterion.condition} #{criterion.value} and
									#{criterion.secondValue}
								</when>
								<when test="criterion.listValue">
									and ${criterion.condition}
									<foreach close=")" collection="criterion.value" item="listItem"
										open="(" separator=",">
										#{listItem}
									</foreach>
								</when>
							</choose>
						</foreach>
					</trim>
				</if>
			</foreach>
		</where>
	</sql>
	<sql id="Base_Column_List">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		ReturnID, GoodsID, ColorID, SizeID, Quantity, UnitPrice, Amount,
		SendTimes, SendPoint,
		AllotSales, Integral
	</sql>
	<select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WReturndtlExample"
		resultMap="BaseResultMap">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		select
		<if test="distinct">
			distinct
		</if>
		'false' as QUERYID,
		<include refid="Base_Column_List" />
		from W_ReturnDtl
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
		<if test="orderByClause != null">
			order by ${orderByClause}
		</if>
	</select>
	<select id="selectByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WReturndtlKey"
		resultMap="BaseResultMap">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		select
		<include refid="Base_Column_List" />
		from W_ReturnDtl
		where ReturnID = #{returnid,jdbcType=BIGINT}
		and GoodsID = #{goodsid,jdbcType=VARCHAR}
		and ColorID = #{colorid,jdbcType=VARCHAR}
		and SizeID = #{sizeid,jdbcType=VARCHAR}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WReturndtlKey">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		delete from W_ReturnDtl
		where ReturnID = #{returnid,jdbcType=BIGINT}
		and GoodsID = #{goodsid,jdbcType=VARCHAR}
		and ColorID = #{colorid,jdbcType=VARCHAR}
		and SizeID = #{sizeid,jdbcType=VARCHAR}
	</delete>
	<insert id="insert" parameterType="com.fuxi.ws.data.entity.WReturndtl">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		insert into W_ReturnDtl (ReturnID, GoodsID, ColorID,
		SizeID, Quantity, UnitPrice,
		Amount, SendTimes, SendPoint,
		AllotSales, Integral)
		values (#{returnid,jdbcType=BIGINT}, #{goodsid,jdbcType=VARCHAR},
		#{colorid,jdbcType=VARCHAR},
		#{sizeid,jdbcType=VARCHAR}, #{quantity,jdbcType=INTEGER}, #{unitprice,jdbcType=DECIMAL},
		#{amount,jdbcType=DECIMAL}, #{sendtimes,jdbcType=DECIMAL},
		#{sendpoint,jdbcType=INTEGER},
		#{allotsales,jdbcType=DECIMAL}, #{integral,jdbcType=INTEGER})
	</insert>
	<insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WReturndtl">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		insert into W_ReturnDtl
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="returnid != null">
				ReturnID,
			</if>
			<if test="goodsid != null">
				GoodsID,
			</if>
			<if test="colorid != null">
				ColorID,
			</if>
			<if test="sizeid != null">
				SizeID,
			</if>
			<if test="quantity != null">
				Quantity,
			</if>
			<if test="unitprice != null">
				UnitPrice,
			</if>
			<if test="amount != null">
				Amount,
			</if>
			<if test="sendtimes != null">
				SendTimes,
			</if>
			<if test="sendpoint != null">
				SendPoint,
			</if>
			<if test="allotsales != null">
				AllotSales,
			</if>
			<if test="integral != null">
				Integral,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="returnid != null">
				#{returnid,jdbcType=BIGINT},
			</if>
			<if test="goodsid != null">
				#{goodsid,jdbcType=VARCHAR},
			</if>
			<if test="colorid != null">
				#{colorid,jdbcType=VARCHAR},
			</if>
			<if test="sizeid != null">
				#{sizeid,jdbcType=VARCHAR},
			</if>
			<if test="quantity != null">
				#{quantity,jdbcType=INTEGER},
			</if>
			<if test="unitprice != null">
				#{unitprice,jdbcType=DECIMAL},
			</if>
			<if test="amount != null">
				#{amount,jdbcType=DECIMAL},
			</if>
			<if test="sendtimes != null">
				#{sendtimes,jdbcType=DECIMAL},
			</if>
			<if test="sendpoint != null">
				#{sendpoint,jdbcType=INTEGER},
			</if>
			<if test="allotsales != null">
				#{allotsales,jdbcType=DECIMAL},
			</if>
			<if test="integral != null">
				#{integral,jdbcType=INTEGER},
			</if>
		</trim>
	</insert>
	<select id="countByExample" parameterType="com.fuxi.ws.data.entity.WReturndtlExample"
		resultType="java.lang.Integer">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		select count(*) from W_ReturnDtl
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
	</select>
	<update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WReturndtl">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		update W_ReturnDtl
		<set>
			<if test="quantity != null">
				Quantity = #{quantity,jdbcType=INTEGER},
			</if>
			<if test="unitprice != null">
				UnitPrice = #{unitprice,jdbcType=DECIMAL},
			</if>
			<if test="amount != null">
				Amount = #{amount,jdbcType=DECIMAL},
			</if>
			<if test="sendtimes != null">
				SendTimes = #{sendtimes,jdbcType=DECIMAL},
			</if>
			<if test="sendpoint != null">
				SendPoint = #{sendpoint,jdbcType=INTEGER},
			</if>
			<if test="allotsales != null">
				AllotSales = #{allotsales,jdbcType=DECIMAL},
			</if>
			<if test="integral != null">
				Integral = #{integral,jdbcType=INTEGER},
			</if>
		</set>
		where ReturnID = #{returnid,jdbcType=BIGINT}
		and GoodsID = #{goodsid,jdbcType=VARCHAR}
		and ColorID = #{colorid,jdbcType=VARCHAR}
		and SizeID = #{sizeid,jdbcType=VARCHAR}
	</update>
	<update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WReturndtl">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Tue Dec 06 
			15:01:07 CST 2016. -->
		update W_ReturnDtl
		set Quantity = #{quantity,jdbcType=INTEGER},
		UnitPrice = #{unitprice,jdbcType=DECIMAL},
		Amount = #{amount,jdbcType=DECIMAL},
		SendTimes = #{sendtimes,jdbcType=DECIMAL},
		SendPoint = #{sendpoint,jdbcType=INTEGER},
		AllotSales = #{allotsales,jdbcType=DECIMAL},
		Integral = #{integral,jdbcType=INTEGER}
		where ReturnID = #{returnid,jdbcType=BIGINT}
		and GoodsID = #{goodsid,jdbcType=VARCHAR}
		and ColorID = #{colorid,jdbcType=VARCHAR}
		and SizeID = #{sizeid,jdbcType=VARCHAR}
	</update>

	<select id="getReturnDtl" resultType="java.util.LinkedHashMap">
		select
		a.Quantity,a.UnitPrice,b.GoodsID,b.GoodName,b.ImgPath,c.Color,d.Size,b.ViewColor,b.ViewSize,e.PointOrder,a.Integral
		from W_Return t
		join EShopOrder e on t.EShopOrderID=e.EShopOrderID
		join W_ReturnDtl a on t.ReturnID=a.ReturnID
		join W_Goods b on a.GoodsID=b.GoodsID
		join Color c on
		a.ColorID=c.ColorID
		join Size d on a.SizeID=d.SizeID
		where a.ReturnID=#{
		returnid }
	</select>

	<!--每张退货单每个商品总数量、总金额 -->
	<select id="getreturndtlbygoods" resultType="java.util.LinkedHashMap">
		select
		rd.ReturnID,rd.GoodsID,r.EShopOrderID,SUM(rd.Quantity) as
		Quantity,SUM(rd.Amount) as Amount
		from W_ReturnDtl as rd
		inner join
		W_Return as r on rd.ReturnID=r.ReturnID
		where rd.ReturnID=#{returnid}
		group by
		rd.ReturnID,rd.GoodsID,r.EShopOrderID
	</select>

	<select id="getreturn" parameterType="java.util.HashMap"
		resultType="java.util.LinkedHashMap">
		select
		rd.ReturnID,rd.GoodsID,wg.Code,wg.GoodName,rd.ColorID,c.Color,rd.SizeID,s.Size,rd.Quantity,
		rd.UnitPrice,rd.Amount
		from W_ReturnDtl as rd
		inner join W_Return as r
		on r.ReturnID=rd.ReturnID
		left join W_Goods as wg on rd.GoodsID=wg.GoodsID
		left join Color as c
		on rd.ColorID=c.ColorID
		left join Size as s on rd.SizeID=s.SizeID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
		order by rd.ReturnID desc
	</select>

	<select id="getReturnGBGoods" resultType="java.util.LinkedHashMap">
		select
		returnid,GoodsID,SUM(Amount) as
		AmountSum,SUM(Quantity) as Quantity
		from w_returndtl
		where returnid=#{ returnid }
		group by returnid,GoodsID
	</select>
</mapper>