<?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="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderReturnGoodsMapperEx">

	<resultMap id="ViewUnifiedOrderReturnResultMap" type="cn.superdesk.uniorder.dto.vo.unified.ViewUnifiedOrderReturn">
		<result column="id" property="id" jdbcType="BIGINT"/>
		<result column="goods_name" property="goodsName" jdbcType="VARCHAR"/>
		<result column="goods_alias" property="goodsAlias" jdbcType="VARCHAR"/>
		<result column="quantity" property="quantity" jdbcType="INTEGER"/>
		<result column="cost_price" property="costPrice" jdbcType="DECIMAL"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="order_return_id" property="orderReturnId" jdbcType="BIGINT"/>
		<result column="order_sn" property="orderSn" jdbcType="VARCHAR"/>
		<result column="return_sn" property="returnSn" jdbcType="VARCHAR"/>
		<result column="amount" property="amount" jdbcType="DECIMAL"/>
		<result column="transport_amount" property="transportAmount" jdbcType="DECIMAL"/>
		<result column="complet_state" property="completState" jdbcType="TINYINT"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="purchase_virt_name" property="purchaseVirtName" jdbcType="VARCHAR"/>
		<result column="sale_name" property="saleName" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findView" resultMap="ViewUnifiedOrderReturnResultMap">
		SELECT
			uorg.id AS id,
			uorg.return_sn AS return_sn,
			uorg.goods_name AS goods_name,
			uorg.goods_alias,
			uorg.goods_id AS goods_id,
			uorg.quantity AS quantity,
			uorg.cost_price AS cost_price,
			uorg.price AS price,

			uor.order_sn AS order_sn,
			uor.project_id AS project_id,
			uor.project_name AS project_name,
			uor.transport_amount AS transport_amount,
			uor.transport_amount_source AS transport_amount_source,
			uor.amount AS amount,
			uor.create_time AS create_time,
			uor.create_user_id AS create_user_id
		FROM
			unified_order_return_goods uorg
			LEFT JOIN unified_order_return uor ON uorg.return_sn = uor.return_sn
		<where>
		<if test="orderSn != null and orderSn != ''">
			and uor.order_sn = #{orderSn}
		</if>
		</where>
	</select>



	<select id="findByRefundOrderSn" resultMap="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderReturnGoodsMapper.BaseResultMap" parameterType="java.lang.String">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderReturnGoodsMapper.Base_Column_List"/>
		from
			unified_order_return_goods
		<where>
			<if test="refundOrderSn != null and refundOrderSn != ''">
			and return_sn = #{refundOrderSn,jdbcType=VARCHAR}
			</if>
		</where>
	</select>

	<select id="findByRefundOrderSnGoodsId" resultMap="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderReturnGoodsMapper.BaseResultMap" parameterType="java.lang.String">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderReturnGoodsMapper.Base_Column_List"/>
		from
		unified_order_return_goods
		<where>
			<if test="refundOrderSn != null and refundOrderSn != ''">
				and return_sn = #{refundOrderSn,jdbcType=VARCHAR}
			</if>
			<if test="goodsId != null">
				and goods_id = #{goodsId,jdbcType=BIGINT}
			</if>
		</where>
	</select>

</mapper>