<?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.xunhong.erp.turbo.biz.infrastructure.mapper.OrderSupplierMapper">
	<resultMap id="BaseResultMap"
			   type="com.xunhong.erp.turbo.biz.infrastructure.entity.OrderSupplierDO">
		<result property="orderSupplierId" column="order_supplier_id"/>
		<result property="orderId" column="order_id"/>
		<result property="supplierId" column="supplier_id"/>
		<result property="name" column="name"/>
		<result property="payeeName" column="payee_name"/>
		<result property="idCard" column="id_card"/>
		<result property="bankName" column="bank_name"/>
		<result property="bankCard" column="bank_card"/>
		<result property="phone" column="phone"/>
		<result property="wechatQr" column="wechat_qr"/>
		<result property="type" column="type"/>
		<result property="isLast" column="is_last"/>
		<result property="isPaper" column="is_paper"/>
		<result property="emptyWeight" column="empty_weight"/>
		<result property="totalWeight" column="total_weight"/>
		<result property="grossWeight" column="gross_weight"/>
		<result property="netWeight" column="net_weight"/>
		<result property="purchasePrice" column="purchase_price"/>
		<result property="packageUsage" column="package_usage"
				typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
		<result property="loadingMode" column="loading_mode"/>
		<result property="salePrice" column="sale_price"/>
		<result property="pricingMethod" column="pricing_method"/>
		<result property="invoiceAmount" column="invoice_amount"/>
		<result property="emptyWeightImg" column="empty_weight_img"/>
		<result property="totalWeightImg" column="total_Weight_img"/>
		<result property="invoiceImg" column="invoice_img"
				typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
		<result property="contractImg" column="contract_img"
				typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
		<result property="invoiceUpload" column="invoice_upload"/>
		<result property="contractUpload" column="contract_upload"/>
		<result property="productId" column="product_id"/>
		<result property="productName" column="product_name"/>
		<result property="costIds" column="cost_ids"
				typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
		<result property="costTemplate" column="cost_template"/>
		<result property="isDepositPaid" column="is_deposit_paid"/>
		<result property="depositAmount" column="deposit_amount"/>
		<result property="isPaid" column="is_paid"/>
		<result property="poState" column="po_state"/>
		<result property="createdAt" column="created_at"/>
		<result property="updatedAt" column="updated_at"/>
		<result property="isDelete" column="is_delete"/>
		<result property="version" column="version"/>
	</resultMap>

	<select id="selectPage"
			resultType="com.xunhong.erp.turbo.biz.infrastructure.entity.OrderSupplierDO"
			resultMap="BaseResultMap">
		SELECT
			os.*,
			po.state as po_state
		FROM order_supplier os
		LEFT JOIN order_vehicle ov ON os.order_id = ov.order_id AND ov.is_delete = 0
		LEFT JOIN `order` po ON os.order_id = po.order_id AND po.is_delete = 0
		<where>
			os.is_delete = 0
			<if test="query.deliveryTime != null and query.deliveryTime.size() == 2">
				AND ov.delivery_time BETWEEN #{query.deliveryTime[0]} AND #{query.deliveryTime[1]}
			</if>
			<if test="query.createdBy != null">
				AND po.created_by = #{query.createdBy}
			</if>
			<if test="query.type != null">
				AND os.type = #{query.type}
			</if>
			<if test="query.orderId != null">
				AND po.order_id = #{query.orderId}
			</if>
			<if test="query.poType != null">
				AND po.type = #{query.poType}
			</if>
			<if test="query.poStates != null and query.poStates.size() > 0">
				AND po.state IN
				<foreach collection="query.poStates" item="state" open="(" separator="," close=")">
					#{state.type}
				</foreach>
			</if>
			<if test="ew != null">
				<if test="ew.nonEmptyOfWhere">
					AND
				</if>
				${ew.sqlSegment}
			</if>
		</where>
	</select>
</mapper>
