<?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.UnifiedOrderGoodsMapperEx">



	<resultMap id="UnifiedOrderJoinGoodsDetailResultMap"
			   type="cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderJoinGoodsDetailVo">

		<result column="unified_order_id" property="unifiedOrderId" jdbcType="BIGINT"/>
		<result column="order_sn" property="orderSn" jdbcType="VARCHAR"/>
		<result column="order_sn_out_trade" property="orderSnOutTrade" jdbcType="VARCHAR"/>

		<!-- 弃用 改用定义 mark by linjinyu at 20220624 -->
		<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
		<result column="service_no" property="serviceNo" jdbcType="VARCHAR"/>

		<result column="project_id" property="projectId" jdbcType="BIGINT"/>
		<result column="project_name" property="projectName" jdbcType="VARCHAR"/>

		<result column="purchase_virt_id" property="purchaseVirtId" jdbcType="BIGINT"/>
		<result column="purchase_virt_name" property="purchaseVirtName" jdbcType="VARCHAR"/>

		<result column="purchase_user_id" property="purchaseUserId" jdbcType="BIGINT"/>
		<result column="purchase_user_name" property="purchaseUserName" jdbcType="VARCHAR"/>
		<result column="purchase_phone" property="purchasePhone" jdbcType="VARCHAR"/>

		<result column="sale_id" property="saleId" jdbcType="BIGINT"/>
		<result column="sale_name" property="saleName" jdbcType="VARCHAR"/>

		<result column="amount" property="amount" jdbcType="DECIMAL"/>
		<result column="cost_amount" property="costAmount" jdbcType="DECIMAL"/>
		<result column="transport_amount" property="transportAmount" jdbcType="DECIMAL"/>
		<result column="complet_state" property="completState" jdbcType="TINYINT"/>

		<result column="accounting_state_supplier" property="accountingStateSupplier" jdbcType="TINYINT"/>
		<result column="accounting_state_customer" property="accountingStateCustomer" jdbcType="TINYINT"/>

		<result column="pay_type" property="payType" jdbcType="TINYINT"/>
		<result column="pay_type_name" jdbcType="VARCHAR" property="payTypeName" />
		<result column="pay_state" property="payState" jdbcType="TINYINT"/>
		<result column="pay_state_name" jdbcType="VARCHAR" property="payStateName" />
		<result column="order_state" property="orderState" jdbcType="TINYINT"/>
		<result column="order_state_name" property="orderStateName" jdbcType="VARCHAR"/>

		<result column="settlement_type" property="settlementType" jdbcType="TINYINT"/>
		<result column="appraise_state" property="appraiseState" jdbcType="TINYINT"/>
		<result column="source_channel" property="sourceChannel" jdbcType="TINYINT"/>
		<result column="other_params" property="otherParams" jdbcType="VARCHAR"/>
		<result column="user_type" property="userType" jdbcType="VARCHAR"/>
		<result column="user_name" property="userName" jdbcType="VARCHAR"/>

		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>

		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="pay_time"     property="payTime"    jdbcType="TIMESTAMP"/>
		<result column="send_time"    property="sendTime"   jdbcType="TIMESTAMP"/>
		<result column="finish_time"  property="finishTime" jdbcType="TIMESTAMP"/>

		<result column="rec_user_name" property="recUserName" jdbcType="VARCHAR"/>
		<result column="rec_user_id" property="recUserId" jdbcType="BIGINT"/>
		<result column="rec_user_phone" property="recUserPhone" jdbcType="VARCHAR"/>
		<result column="rec_address" property="recAddress" jdbcType="VARCHAR"/>

		<result column="express_sn" jdbcType="VARCHAR" property="expressSn"/>
		<result column="express" jdbcType="VARCHAR" property="express"/>
		<result column="express_company" jdbcType="VARCHAR" property="expressCompany"/>

		<result column="invoice_status" property="invoiceStatus" jdbcType="TINYINT"/>
		<result column="invoice_number" property="invoiceNumber" jdbcType="VARCHAR"/>
		<result column="invoice_apply_sn" property="invoiceApplySn" jdbcType="VARCHAR"/>

		<result column="remarks" property="remarks" jdbcType="VARCHAR"/>

		<result column="unified_order_goods_id" property="unifiedOrderGoodsId" jdbcType="BIGINT"/>
		<result column="goods_id" property="goodsId" jdbcType="BIGINT"/>
		<result column="out_snapshot_order_goods_id" jdbcType="BIGINT" property="outSnapshotOrderGoodsId" />
		<result column="goods_name" property="goodsName" jdbcType="VARCHAR"/>
		<result column="goods_alias" jdbcType="VARCHAR" property="goodsAlias" />

		<result column="quantity" property="quantity" jdbcType="INTEGER"/>
		<result column="price" property="price" jdbcType="DECIMAL"/>
		<result column="cost_price" property="costPrice" jdbcType="DECIMAL"/>
		<result column="goods_amount" property="goodsAmount" jdbcType="DECIMAL"/>
		<result column="goods_cost_amount" property="goodsCostAmount" jdbcType="DECIMAL"/>

		<result column="direction" jdbcType="TINYINT" property="direction" />

		<result column="cate_id_lv1" property="cateIdLv1" jdbcType="BIGINT"/>
		<result column="cate_name_lv1" property="cateNameLv1" jdbcType="VARCHAR"/>
		<result column="cate_id_lv2" property="cateIdLv2" jdbcType="BIGINT"/>
		<result column="cate_name_lv2" property="cateNameLv2" jdbcType="VARCHAR"/>
		<result column="cate_id_lv3" property="cateIdLv3" jdbcType="BIGINT"/>
		<result column="cate_name_lv3" property="cateNameLv3" jdbcType="VARCHAR"/>
		<result column="self_option" jdbcType="VARCHAR" property="selfOption"/>
		<result column="unit" property="unit" jdbcType="VARCHAR"/>

		<result column="fiscal_code" jdbcType="VARCHAR" property="fiscalCode" />
		<result column="tax_code" jdbcType="VARCHAR" property="taxCode" />
		<result column="tax_rate" jdbcType="DECIMAL" property="taxRate" />
		<result column="merch_tax_id" jdbcType="BIGINT" property="merchTaxId" />
		<result column="merch_tax_code" jdbcType="VARCHAR" property="merchTaxCode" />
		<result column="merch_tax_rate" jdbcType="DECIMAL" property="merchTaxRate" />
		<result column="operation_tax_id" jdbcType="BIGINT" property="operationTaxId" />
		<result column="operation_tax_code" jdbcType="VARCHAR" property="operationTaxCode" />
		<result column="operation_tax_rate" jdbcType="DECIMAL" property="operationTaxRate" />

		<result column="goods_params" property="goodsParams" jdbcType="VARCHAR"/>


	</resultMap>

	<!-- 客户结算 - 未对账订单 - opt 导出表格 已核对 20200708 -->
	<select id="getUnifiedOrderJoinGoodsDetailVoList"
			resultMap="UnifiedOrderJoinGoodsDetailResultMap">
		SELECT
			uo.id as unified_order_id,
			uo.order_sn,
			uo.order_sn_out_trade,

		    <!-- 弃用 改用定义 mark by linjinyu at 20220624 -->
			uo.service_name,
			uo.service_no,

			uo.project_id,
			uo.project_name,

			uo.purchase_virt_id,
			uo.purchase_virt_name,

			uo.purchase_user_id,
			uo.purchase_user_name,
			uo.purchase_phone,

			uo.sale_id,
			uo.sale_name,

			uo.amount,
			uo.cost_amount,
			uo.transport_amount,
			uo.complet_state,
			uo.accounting_state_supplier,
			uo.accounting_state_customer,

			uo.pay_type,
			uo.pay_type_name,
			uo.pay_state,
			uo.pay_state_name,
			uo.order_state,
			uo.order_state_name,

			uo.settlement_type,
			uo.appraise_state,
			uo.source_channel,
			uo.other_params,
			uo.user_type,
			uo.user_name,


			uo.create_user_id,
			uo.update_user_id,

			uo.create_time,
			uo.update_time,
			uo.pay_time,
			uo.send_time,
			uo.finish_time,

			uo.rec_user_name,
			uo.rec_user_id,
			uo.rec_user_phone,
			uo.rec_address,

			uo.express_sn,
			uo.express,
			uo.express_company,


			uo.invoice_status,
			uo.invoice_number,
			uo.invoice_apply_sn,

			uo.remarks,

			uog.id as unified_order_goods_id,
			uog.goods_id,
			uog.out_snapshot_order_goods_id,
			uog.goods_name,
			uog.goods_alias,<!-- 已添加订单商品属性 -->

			uog.quantity,
			uog.price,
			uog.cost_price,
			uog.price * uog.quantity as goods_amount,
			uog.cost_price * uog.quantity as goods_cost_amount,

			uog.direction,

			uog.cate_id_lv1,
			uog.cate_name_lv1,
			uog.cate_id_lv2,
			uog.cate_name_lv2,
			uog.cate_id_lv3,
			uog.cate_name_lv3,
			uog.self_option,
			uog.unit,

			uog.fiscal_code,
			uog.tax_code,
			uog.tax_rate,
			uog.merch_tax_id,
			uog.merch_tax_code,
			uog.merch_tax_rate,
			uog.operation_tax_id,
			uog.operation_tax_code,
			uog.operation_tax_rate,

			uog.goods_params

		FROM
			unified_order uo
			LEFT JOIN unified_order_goods uog ON uo.order_sn = uog.order_sn
		<where>
			and uo.complet_state != 3
		<if test="completState != null and completState != '' ">
			and uo.complet_state = #{completState}
		</if>

		<if test="accountingStateCustomer != null and accountingStateCustomer != '' ">
			and uo.accounting_state_customer = #{accountingStateCustomer}
		</if>
		<if test="accountingStateSupplier != null and accountingStateSupplier != '' ">
			and uo.accounting_state_supplier = #{accountingStateSupplier}
		</if>

		<if test="amount != null and amount != '' ">
			and uo.amount = #{amount}
		</if>


		<if test="ids != null and ids !=''">
			and uo.id in
			<foreach collection="ids" index="index" item="id" open="(" close=")" separator=",">
				#{id}
			</foreach>
		</if>
		<if test="orderSn != null and orderSn != '' ">
			and uo.order_sn like CONCAT('%',#{orderSn},'%')
		</if>

		<if test="virtId != null and virtId != '' ">
			and uo.purchase_virt_id = #{virtId}
		</if>
		<if test="virtName != null and virtName != '' ">
			and uo.purchase_virt_name like CONCAT('%',#{virtName},'%')
		</if>

		<if test="supplierId != null and supplierId != '' ">
			and uo.sale_id = #{supplierId}
		</if>
		<if test="supplierName != null and supplierName != '' ">
			and uo.sale_name like CONCAT('%',#{supplierName},'%')
		</if>

		<if test="purchaseUserId != null and purchaseUserId != '' ">
			and uo.purchase_user_id = #{purchaseUserId}
		</if>
		<if test="purchaseUserName != null and purchaseUserName != '' ">
			and uo.purchase_user_name like CONCAT('%',#{purchaseUserName},'%')
		</if>

		<if test="serviceNo != null and serviceNo != '' ">
			and uo.service_no = #{serviceNo}
		</if>

		<if test="startTime != null and startTime != ''">
			and DATE_FORMAT(uo.create_time,'%Y-%m-%d') &gt;= #{startTime,jdbcType=VARCHAR}
		</if>
		<if test="endTime != null and endTime != ''">
			and DATE_FORMAT(uo.create_time,'%Y-%m-%d') &lt;= #{endTime,jdbcType=VARCHAR}
		</if>

		<if test="outVirtIds != null and outVirtIds != ''"><!-- 已修正 数据权限 by linjinyu at 2020090818 -->
			<!-- project_id -->
			and purchase_virt_id in
			<foreach collection="outVirtIds" index="index" item="pid" open="(" close=")" separator=",">
				#{pid}
			</foreach>
		</if>

		<if test="outServices != null and outServices != ''">
			and uo.service_no in
			(
				SELECT
					service_no
				from
					unified_service_group
				where
					group_code in
					<foreach collection="outServices" index="index" item="serviceno" open="(" close=")" separator=",">
						#{serviceno}
					</foreach>
			)
		</if>
		</where>
		order by uo.order_sn,uo.create_time
	</select>

	<select id="getSupplierStatementOfAccountDetailDimOrder2Goods"
			resultMap="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderMapperExSupplierDimGoods.UnifiedOrderJoinGoodsOfSupplierStatementOfAccountResultMap">
		SELECT
			uog.id as unified_order_goods_id,
			uo.id as unified_order_id,
			uog.order_sn,
			<!--
			uo.order_sn,
			-->

			uo.amount as order_amount,
			uo.cost_amount as order_cost_amount,
			uo.transport_amount as order_transport_amount,

			uo.purchase_virt_id,
			uo.purchase_virt_name,

			uo.purchase_user_id,
			uo.purchase_user_name,
			uo.purchase_phone,

			uo.express_sn,
			uo.express,
			uo.express_company,

			uo.order_state,
			uo.order_state_name,

			uo.sale_id,
			uo.sale_name,

			uo.pay_type,
			uo.pay_type_name,
			uo.pay_state,
			uo.pay_state_name,

		    <!-- 弃用 改用定义 mark by linjinyu at 20220624 -->
			uo.service_name,
			uo.service_no,

			uo.rec_user_name,
			uo.rec_user_id,
			uo.rec_user_phone,
			uo.rec_address,

			uo.create_time,
			uo.update_time,
			uo.pay_time,
			uo.send_time,
			uo.finish_time,

			uo.remarks,

			uog.goods_id,
			uog.out_snapshot_order_goods_id,
			uog.goods_name,
			uog.goods_alias,<!-- 已添加订单商品属性 -->

			uog.price,
			uog.cost_price,
			uog.quantity,
			uog.price * uog.quantity as goods_amount,
			uog.cost_price * uog.quantity as goods_cost_amount,

			uog.direction,

			uog.cate_id_lv1,
			uog.cate_name_lv1,
			uog.cate_id_lv2,
			uog.cate_name_lv2,
			uog.cate_id_lv3,
			uog.cate_name_lv3,
			uog.self_option,
			uog.unit,

			uog.fiscal_code,
			uog.tax_rate,
			uog.tax_code,
			uog.merch_tax_id,
			uog.merch_tax_code,
			uog.merch_tax_rate,
			uog.operation_tax_id,
			uog.operation_tax_code,
			uog.operation_tax_rate,

			uog.goods_params,

			<!-- 客户对账:1-已对账;2-未对账 -->
			uog.accounting_state_customer,
			<!-- 供应商对账:1-已对账;2-未对账 -->
			uog.accounting_state_supplier

			<!-- 发票申请状态 是否已申请 0-未申请;1-已申请;
			uog.invoice_apply_status,
			-->
			<!-- 开票状态 是否已登记开票 0-未登记;1-已登记;
			uog.invoice_make_status,
			 -->
			<!-- 回款状态 是否回款 0-未回款;1-已回款;
			uog.back_status,
			-->
		from
			unified_order_goods uog
			left join unified_order uo on uog.order_sn = uo.order_sn
		<where>
		<if test="accountingOrderSn != null and accountingOrderSn != ''">
			and uog.order_sn in (
				select
					order_sn
				from
					accounting_unified_supplier_order
				where
					accounting_order_sn =#{accountingOrderSn,jdbcType=VARCHAR}
			)
		</if>
		</where>
	</select>

	<delete id="deleteByOrderSn" parameterType="java.lang.String">
	delete from
  	 	unified_order_goods
	where
		order_sn = #{orderSn,jdbcType=VARCHAR}
	</delete>

	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderGoodsMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderGoodsMapper.Base_Column_List"/>
		from
			unified_order_goods
		<where>
		<if test="orderSn != null and orderSn != ''">
			and order_sn = #{orderSn,jdbcType=VARCHAR}
		</if>
		</where>
	</select>

	<select id="findByOrderSn" resultMap="cn.superdesk.uniorder.dao.mapper.base.UnifiedOrderGoodsMapper.BaseResultMap">
		SELECT
			*
		FROM
			unified_order_goods
		WHERE
			order_sn = #{orderSn}
	</select>

	<insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.base.UnifiedOrderGoods">

		<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into unified_order_goods
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="orderSn != null">
				order_sn,
			</if>
			<if test="goodsName != null">
				goods_name,
			</if>
			<if test="goodsAlias != null">
				goods_alias,
			</if>
			<if test="goodsId != null">
				goods_id,
			</if>
			<if test="outSnapshotOrderGoodsId != null">
				out_snapshot_order_goods_id,
			</if>
			<if test="goodsType != null">
				goods_type,
			</if>
			<if test="quantity != null">
				quantity,
			</if>
			<if test="unit != null">
				unit,
			</if>
			<if test="price != null">
				price,
			</if>
			<if test="costPrice != null">
				cost_price,
			</if>
			<if test="goodsParams != null">
				goods_params,
			</if>
			<if test="fiscalCode != null">
				fiscal_code,
			</if>
			<if test="taxCode != null">
				tax_code,
			</if>
			<if test="taxRate != null">
				tax_rate,
			</if>

			<if test="merchTaxId != null">
				merch_tax_id,
			</if>
			<if test="merchTaxCode != null">
				merch_tax_code,
			</if>
			<if test="merchTaxRate != null">
				merch_tax_rate,
			</if>
			<if test="operationTaxId != null">
				operation_tax_id,
			</if>
			<if test="operationTaxCode != null">
				operation_tax_code,
			</if>
			<if test="operationTaxRate != null">
				operation_tax_rate,
			</if>

			<if test="cateIdLv1 != null">
				cate_id_lv1,
			</if>
			<if test="cateNameLv1 != null">
				cate_name_lv1,
			</if>
			<if test="cateIdLv2 != null">
				cate_id_lv2,
			</if>
			<if test="cateNameLv2 != null">
				cate_name_lv2,
			</if>
			<if test="cateIdLv3 != null">
				cate_id_lv3,
			</if>
			<if test="cateNameLv3 != null">
				cate_name_lv3,
			</if>
			<if test="selfOption != null">
				self_option,
			</if>
			<if test="direction != null">
				direction,
			</if>
			<if test="goodsLockingCustomer != null">
				goods_locking_customer,
			</if>
			<if test="goodsLockingSupplier != null">
				goods_locking_supplier,
			</if>
			<if test="accountingStateCustomer != null">
				accounting_state_customer,
			</if>
			<if test="accountingStateSupplier != null">
				accounting_state_supplier,
			</if>
			<if test="backAccountStatus != null">
				back_account_status,
			</if>
			<if test="refundOrderSn != null">
				refund_order_sn,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="createUserId != null">
				create_user_id,
			</if>
			<if test="updateTime != null">
				update_time,
			</if>
			<if test="updateUserId != null">
				update_user_id,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id,jdbcType=BIGINT},
			</if>
			<if test="orderSn != null">
				#{orderSn,jdbcType=VARCHAR},
			</if>
			<if test="goodsName != null">
				#{goodsName,jdbcType=VARCHAR},
			</if>
			<if test="goodsAlias != null">
				#{goodsAlias,jdbcType=VARCHAR},
			</if>
			<if test="goodsId != null">
				#{goodsId,jdbcType=BIGINT},
			</if>
			<if test="outSnapshotOrderGoodsId != null">
				#{outSnapshotOrderGoodsId,jdbcType=BIGINT},
			</if>
			<if test="goodsType != null">
				#{goodsType,jdbcType=TINYINT},
			</if>
			<if test="quantity != null">
				#{quantity,jdbcType=INTEGER},
			</if>
			<if test="unit != null">
				#{unit,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				#{price,jdbcType=DECIMAL},
			</if>
			<if test="costPrice != null">
				#{costPrice,jdbcType=DECIMAL},
			</if>
			<if test="goodsParams != null">
				#{goodsParams,jdbcType=VARCHAR},
			</if>
			<if test="fiscalCode != null">
				#{fiscalCode,jdbcType=VARCHAR},
			</if>
			<if test="taxCode != null">
				#{taxCode,jdbcType=VARCHAR},
			</if>
			<if test="taxRate != null">
				#{taxRate,jdbcType=DECIMAL},
			</if>
			<if test="cateIdLv1 != null">
				#{cateIdLv1,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv1 != null">
				#{cateNameLv1,jdbcType=VARCHAR},
			</if>
			<if test="cateIdLv2 != null">
				#{cateIdLv2,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv2 != null">
				#{cateNameLv2,jdbcType=VARCHAR},
			</if>
			<if test="cateIdLv3 != null">
				#{cateIdLv3,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv3 != null">
				#{cateNameLv3,jdbcType=VARCHAR},
			</if>
			<if test="selfOption != null">
				#{selfOption,jdbcType=VARCHAR},
			</if>
			<if test="direction != null">
				#{direction,jdbcType=TINYINT},
			</if>
			<if test="goodsLockingCustomer != null">
				#{goodsLockingCustomer,jdbcType=TINYINT},
			</if>
			<if test="goodsLockingSupplier != null">
				#{goodsLockingSupplier,jdbcType=TINYINT},
			</if>
			<if test="accountingStateCustomer != null">
				#{accountingStateCustomer,jdbcType=TINYINT},
			</if>
			<if test="accountingStateSupplier != null">
				#{accountingStateSupplier,jdbcType=TINYINT},
			</if>
			<if test="backAccountStatus != null">
				#{backAccountStatus,jdbcType=TINYINT},
			</if>
			<if test="refundOrderSn != null">
				#{refundOrderSn,jdbcType=VARCHAR},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				#{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				#{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				#{updateUserId,jdbcType=BIGINT},
			</if>
		</trim>
	</insert>

	<insert id="insertSelectiveWithoutReturnId" parameterType="cn.superdesk.uniorder.dao.entity.base.UnifiedOrderGoods">
		insert into unified_order_goods
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="orderSn != null">
				order_sn,
			</if>
			<if test="goodsName != null">
				goods_name,
			</if>
			<if test="goodsAlias != null">
				goods_alias,
			</if>
			<if test="goodsId != null">
				goods_id,
			</if>
			<if test="outSnapshotOrderGoodsId != null">
				out_snapshot_order_goods_id,
			</if>
			<if test="goodsType != null">
				goods_type,
			</if>
			<if test="quantity != null">
				quantity,
			</if>
			<if test="unit != null">
				unit,
			</if>
			<if test="price != null">
				price,
			</if>
			<if test="costPrice != null">
				cost_price,
			</if>
			<if test="fiscalCode != null">
				fiscal_code,
			</if>
			<if test="taxCode != null">
				tax_code,
			</if>
			<if test="taxRate != null">
				tax_rate,
			</if>
			<if test="merchTaxId != null">
				merch_tax_id,
			</if>
			<if test="merchTaxCode != null">
				merch_tax_code,
			</if>
			<if test="merchTaxRate != null">
				merch_tax_rate,
			</if>
			<if test="operationTaxId != null">
				operation_tax_id,
			</if>
			<if test="operationTaxCode != null">
				operation_tax_code,
			</if>
			<if test="operationTaxRate != null">
				operation_tax_rate,
			</if>
			<if test="cateIdLv1 != null">
				cate_id_lv1,
			</if>
			<if test="cateNameLv1 != null">
				cate_name_lv1,
			</if>
			<if test="cateIdLv2 != null">
				cate_id_lv2,
			</if>
			<if test="cateNameLv2 != null">
				cate_name_lv2,
			</if>
			<if test="cateIdLv3 != null">
				cate_id_lv3,
			</if>
			<if test="cateNameLv3 != null">
				cate_name_lv3,
			</if>
			<if test="selfOption != null">
				self_option,
			</if>
			<if test="direction != null">
				direction,
			</if>
			<if test="goodsLockingCustomer != null">
				goods_locking_customer,
			</if>
			<if test="goodsLockingSupplier != null">
				goods_locking_supplier,
			</if>
			<if test="accountingStateCustomer != null">
				accounting_state_customer,
			</if>
			<if test="accountingStateSupplier != null">
				accounting_state_supplier,
			</if>
			<if test="backAccountStatus != null">
				back_account_status,
			</if>
			<if test="refundOrderSn != null">
				refund_order_sn,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="createUserId != null">
				create_user_id,
			</if>
			<if test="updateTime != null">
				update_time,
			</if>
			<if test="updateUserId != null">
				update_user_id,
			</if>
			<if test="goodsParams != null">
				goods_params,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id,jdbcType=BIGINT},
			</if>
			<if test="orderSn != null">
				#{orderSn,jdbcType=VARCHAR},
			</if>
			<if test="goodsName != null">
				#{goodsName,jdbcType=VARCHAR},
			</if>
			<if test="goodsAlias != null">
				#{goodsAlias,jdbcType=VARCHAR},
			</if>
			<if test="goodsId != null">
				#{goodsId,jdbcType=BIGINT},
			</if>
			<if test="outSnapshotOrderGoodsId != null">
				#{outSnapshotOrderGoodsId,jdbcType=BIGINT},
			</if>
			<if test="goodsType != null">
				#{goodsType,jdbcType=TINYINT},
			</if>
			<if test="quantity != null">
				#{quantity,jdbcType=INTEGER},
			</if>
			<if test="unit != null">
				#{unit,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				#{price,jdbcType=DECIMAL},
			</if>
			<if test="costPrice != null">
				#{costPrice,jdbcType=DECIMAL},
			</if>
			<if test="fiscalCode != null">
				#{fiscalCode,jdbcType=VARCHAR},
			</if>
			<if test="taxCode != null">
				#{taxCode,jdbcType=VARCHAR},
			</if>
			<if test="taxRate != null">
				#{taxRate,jdbcType=DECIMAL},
			</if>
			<if test="merchTaxId != null">
				#{merchTaxId,jdbcType=BIGINT},
			</if>
			<if test="merchTaxCode != null">
				#{merchTaxCode,jdbcType=VARCHAR},
			</if>
			<if test="merchTaxRate != null">
				#{merchTaxRate,jdbcType=DECIMAL},
			</if>
			<if test="operationTaxId != null">
				#{operationTaxId,jdbcType=BIGINT},
			</if>
			<if test="operationTaxCode != null">
				#{operationTaxCode,jdbcType=VARCHAR},
			</if>
			<if test="operationTaxRate != null">
				#{operationTaxRate,jdbcType=DECIMAL},
			</if>
			<if test="cateIdLv1 != null">
				#{cateIdLv1,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv1 != null">
				#{cateNameLv1,jdbcType=VARCHAR},
			</if>
			<if test="cateIdLv2 != null">
				#{cateIdLv2,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv2 != null">
				#{cateNameLv2,jdbcType=VARCHAR},
			</if>
			<if test="cateIdLv3 != null">
				#{cateIdLv3,jdbcType=BIGINT},
			</if>
			<if test="cateNameLv3 != null">
				#{cateNameLv3,jdbcType=VARCHAR},
			</if>
			<if test="selfOption != null">
				#{selfOption,jdbcType=VARCHAR},
			</if>
			<if test="direction != null">
				#{direction,jdbcType=TINYINT},
			</if>
			<if test="goodsLockingCustomer != null">
				#{goodsLockingCustomer,jdbcType=TINYINT},
			</if>
			<if test="goodsLockingSupplier != null">
				#{goodsLockingSupplier,jdbcType=TINYINT},
			</if>
			<if test="accountingStateCustomer != null">
				#{accountingStateCustomer,jdbcType=TINYINT},
			</if>
			<if test="accountingStateSupplier != null">
				#{accountingStateSupplier,jdbcType=TINYINT},
			</if>
			<if test="backAccountStatus != null">
				#{backAccountStatus,jdbcType=TINYINT},
			</if>
			<if test="refundOrderSn != null">
				#{refundOrderSn,jdbcType=VARCHAR},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				#{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				#{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				#{updateUserId,jdbcType=BIGINT},
			</if>
			<if test="goodsParams != null">
				#{goodsParams,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>

	<!-- cn.superdesk.uniorder.dao.entity.base.UnifiedOrderGoods -->
	<insert id="insertBatch" parameterType="java.util.List">
		<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into unified_order_goods (id,order_sn, goods_name, goods_alias,
		goods_id, out_snapshot_order_goods_id, goods_type, quantity, unit,
		price, cost_price, goods_params,
		fiscal_code, tax_code, tax_rate,

		merch_tax_id, merch_tax_code, merch_tax_rate,
		operation_tax_id, operation_tax_code, operation_tax_rate,

		cate_id_lv1, cate_name_lv1, cate_id_lv2,
		cate_name_lv2, cate_id_lv3, cate_name_lv3,
		self_option, direction,

		goods_locking_customer,
		goods_locking_supplier,
		accounting_state_customer,
		accounting_state_supplier,

		back_account_status,
		refund_order_sn, create_time, create_user_id,
		update_time, update_user_id)
		values
		<foreach collection="list" item="item" index="index" separator=",">
		(
		#{item.id,jdbcType=BIGINT},
		#{item.orderSn,jdbcType=VARCHAR},
		#{item.goodsName,jdbcType=VARCHAR},
		#{item.goodsAlias,jdbcType=VARCHAR},
		#{item.goodsId,jdbcType=BIGINT},
		#{item.outSnapshotOrderGoodsId,jdbcType=BIGINT},
		#{item.goodsType,jdbcType=TINYINT},
		#{item.quantity,jdbcType=INTEGER},
		#{item.unit,jdbcType=VARCHAR},
		#{item.price,jdbcType=DECIMAL},
		#{item.costPrice,jdbcType=DECIMAL},
		#{item.goodsParams,jdbcType=VARCHAR},
		#{item.fiscalCode,jdbcType=VARCHAR},
		#{item.taxCode,jdbcType=VARCHAR},
		#{item.taxRate,jdbcType=DECIMAL},

		#{item.merchTaxId,jdbcType=BIGINT},
		#{item.merchTaxCode,jdbcType=VARCHAR},
		#{item.merchTaxRate,jdbcType=DECIMAL},
		#{item.operationTaxId,jdbcType=BIGINT},
		#{item.operationTaxCode,jdbcType=VARCHAR},
		#{item.operationTaxRate,jdbcType=DECIMAL},

		#{item.cateIdLv1,jdbcType=BIGINT},
		#{item.cateNameLv1,jdbcType=VARCHAR},
		#{item.cateIdLv2,jdbcType=BIGINT},
		#{item.cateNameLv2,jdbcType=VARCHAR},
		#{item.cateIdLv3,jdbcType=BIGINT},
		#{item.cateNameLv3,jdbcType=VARCHAR},

		#{item.selfOption,jdbcType=VARCHAR},
		#{item.direction,jdbcType=TINYINT},

		#{item.goodsLockingCustomer,jdbcType=TINYINT},
		#{item.goodsLockingSupplier,jdbcType=TINYINT},

		#{item.accountingStateCustomer,jdbcType=TINYINT},
		#{item.accountingStateSupplier,jdbcType=TINYINT},

		#{item.backAccountStatus,jdbcType=TINYINT},
		#{item.refundOrderSn,jdbcType=VARCHAR},
		#{item.createTime,jdbcType=TIMESTAMP},
		#{item.createUserId,jdbcType=BIGINT},
		#{item.updateTime,jdbcType=TIMESTAMP},
		#{item.updateUserId,jdbcType=BIGINT}
		)
		</foreach>
	</insert>




	<!-- 可根据自己的需求，是否要使用 -->

	<resultMap id="pageQueryGenericParamResultMap"
			   type="cn.superdesk.uniorder.dto.vo.order.base.UnifiedOrderGoodsListItemVo">
		<id column="id" jdbcType="BIGINT" property="id"/>
	</resultMap>

	<select id="pageQueryGenericParam"
			resultMap="pageQueryGenericParamResultMap">

		SELECT
			uog.id
		FROM
			unified_order_goods uog
		<where>
			AND 1 = 1
			<include refid="conditionPart"></include>
		</where>
		<choose>
			<when test="orderByClause != null and orderByClause != '' ">
				order by ${orderByClause}
			</when>
			<otherwise>
				order by uog.create_time DESC
			</otherwise>
		</choose>

	</select>

	<sql id="conditionPart">

		<if test="unifiedOrderGoodsId != null and unifiedOrderGoodsId != '' ">
			and uog.id = #{unifiedOrderGoodsId}
		</if>
	</sql>


	<resultMap id="queryHeadGenericParamResultMap"
			   type="cn.superdesk.uniorder.dto.vo.order.base.UnifiedOrderGoodsDetailStatisticsVo">
		<result column="statistics_count" jdbcType="BIGINT" property="statisticsCount" />
	</resultMap>

	<select id="pageQueryHeadGenericParam"
			resultMap="queryHeadGenericParamResultMap">
		select
			COUNT(uog.id) AS statistics_count,
		from
		unified_order_goods uog
		<where>
			<include refid="conditionPart"></include>
		</where>
	</select>



</mapper>