Files
ruoyi-java/ruoyi-system/src/main/resources/mapper/jarvis/JDOrderMapper.xml
T
2026-09-30 15:02:12 +08:00

437 lines
26 KiB
XML

<?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.ruoyi.jarvis.mapper.JDOrderMapper">
<resultMap id="JDOrderResult" type="JDOrder">
<result property="id" column="id"/>
<result property="remark" column="remark"/>
<result property="distributionMark" column="distribution_mark"/>
<result property="modelNumber" column="model_number"/>
<result property="modelShop" column="model_shop"/>
<result property="link" column="link"/>
<result property="paymentAmount" column="payment_amount"/>
<result property="rebateAmount" column="rebate_amount"/>
<result property="address" column="address"/>
<result property="logisticsLink" column="logistics_link"/>
<result property="waybillNo" column="waybill_no"/>
<result property="tencentDocPushed" column="tencent_doc_pushed"/>
<result property="tencentDocPushTime" column="tencent_doc_push_time"/>
<result property="orderId" column="order_id"/>
<result property="buyer" column="buyer"/>
<result property="orderTime" column="order_time"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="status" column="status"/>
<result property="isCountEnabled" column="is_count_enabled"/>
<result property="thirdPartyOrderNo" column="third_party_order_no"/>
<result property="jingfenActualPrice" column="jingfen_actual_price"/>
<result property="isRefunded" column="is_refunded"/>
<result property="refundDate" column="refund_date"/>
<result property="isRefundReceived" column="is_refund_received"/>
<result property="refundReceivedDate" column="refund_received_date"/>
<result property="isRebateReceived" column="is_rebate_received"/>
<result property="rebateReceivedDate" column="rebate_received_date"/>
<result property="isPriceProtected" column="is_price_protected"/>
<result property="priceProtectedDate" column="price_protected_date"/>
<result property="isInvoiceOpened" column="is_invoice_opened"/>
<result property="invoiceOpenedDate" column="invoice_opened_date"/>
<result property="isReviewPosted" column="is_review_posted"/>
<result property="reviewPostedDate" column="review_posted_date"/>
<result property="rebateRemarkJson" column="rebate_remark_json"/>
<result property="rebateRemarkHasAbnormal" column="rebate_remark_has_abnormal"/>
<result property="sellingPriceType" column="selling_price_type"/>
<result property="sellingPrice" column="selling_price"/>
<result property="profit" column="profit"/>
<result property="sellingPriceManual" column="selling_price_manual"/>
<result property="profitManual" column="profit_manual"/>
<result property="extraCost" column="extra_cost"/>
</resultMap>
<sql id="selectJDOrderBase">
select id, remark, distribution_mark, model_number, model_shop, link, payment_amount, rebate_amount,
address, logistics_link, waybill_no, order_id, buyer, order_time, create_time, update_time, status, is_count_enabled, third_party_order_no, jingfen_actual_price,
is_refunded, refund_date, is_refund_received, refund_received_date, is_rebate_received, rebate_received_date,
is_price_protected, price_protected_date, is_invoice_opened, invoice_opened_date, is_review_posted, review_posted_date,
rebate_remark_json, rebate_remark_has_abnormal,
selling_price_type, selling_price, profit, selling_price_manual, profit_manual, extra_cost
from jd_order
</sql>
<select id="selectJDOrderList" parameterType="JDOrder" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
<where>
<if test="remark != null and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
<if test="params.orderSearch != null and params.orderSearch != ''">
and (
order_id like concat('%', #{params.orderSearch}, '%')
or third_party_order_no like concat('%', #{params.orderSearch}, '%')
or distribution_mark like concat('%', #{params.orderSearch}, '%')
or waybill_no like concat('%', #{params.orderSearch}, '%')
)
</if>
<if test="params.mobileQuickSearch != null and params.mobileQuickSearch != ''">
and (
remark like concat('%', #{params.mobileQuickSearch}, '%')
or order_id like concat('%', #{params.mobileQuickSearch}, '%')
or third_party_order_no like concat('%', #{params.mobileQuickSearch}, '%')
or distribution_mark like concat('%', #{params.mobileQuickSearch}, '%')
or waybill_no like concat('%', #{params.mobileQuickSearch}, '%')
or buyer like concat('%', #{params.mobileQuickSearch}, '%')
or address like concat('%', #{params.mobileQuickSearch}, '%')
)
</if>
<if test="params.quickRecordSearch != null and params.quickRecordSearch != ''">
and (
model_number like concat('%', #{params.quickRecordSearch}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{params.quickRecordSearch}, '%')
or address like concat('%', #{params.quickRecordSearch}, '%')
or buyer like concat('%', #{params.quickRecordSearch}, '%')
or order_id like concat('%', #{params.quickRecordSearch}, '%')
or third_party_order_no like concat('%', #{params.quickRecordSearch}, '%')
or distribution_mark like concat('%', #{params.quickRecordSearch}, '%')
or waybill_no like concat('%', #{params.quickRecordSearch}, '%')
or logistics_link like concat('%', #{params.quickRecordSearch}, '%')
)
</if>
<if test="distributionMark != null and distributionMark != ''"> and distribution_mark = #{distributionMark}</if>
<if test="modelNumber != null and modelNumber != ''">
and (
model_number like concat('%', #{modelNumber}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{modelNumber}, '%')
)
</if>
<if test="modelShop != null and modelShop != ''"> and model_shop = #{modelShop}</if>
<if test="params.modelNumberExcludeList != null and params.modelNumberExcludeList.size() > 0">
<foreach collection="params.modelNumberExcludeList" item="ex">
and (model_number is null or model_number not like concat('%', #{ex}, '%'))
</foreach>
</if>
<if test="link != null and link != ''"> and link like concat('%', #{link}, '%')</if>
<if test="paymentAmount != null"> and payment_amount = #{paymentAmount}</if>
<if test="rebateAmount != null"> and rebate_amount = #{rebateAmount}</if>
<if test="address != null and address != ''"> and address like concat('%', #{address}, '%')</if>
<if test="logisticsLink != null and logisticsLink != ''"> and logistics_link like concat('%', #{logisticsLink}, '%')</if>
<if test="waybillNo != null and waybillNo != ''"> and waybill_no like concat('%', #{waybillNo}, '%')</if>
<if test="buyer != null and buyer != ''"> and buyer like concat('%', #{buyer}, '%')</if>
<if test="orderTime != null"> and order_time = #{orderTime}</if>
<if test="status != null and status != ''"> and status like concat('%', #{status}, '%')</if>
<if test="isRefunded != null"> and is_refunded = #{isRefunded}</if>
<if test="isRefundReceived != null"> and is_refund_received = #{isRefundReceived}</if>
<if test="isRebateReceived != null"> and is_rebate_received = #{isRebateReceived}</if>
<if test="isPriceProtected != null"> and is_price_protected = #{isPriceProtected}</if>
<if test="isInvoiceOpened != null"> and is_invoice_opened = #{isInvoiceOpened}</if>
<if test="isReviewPosted != null"> and is_review_posted = #{isReviewPosted}</if>
<if test="rebateRemarkHasAbnormal != null"> and rebate_remark_has_abnormal = #{rebateRemarkHasAbnormal}</if>
<if test="params.hasRebateRemark != null and params.hasRebateRemark == true">
and rebate_remark_json is not null and char_length(trim(rebate_remark_json)) &gt; 2
</if>
<if test="params.rebateWithoutUploadLink != null and params.rebateWithoutUploadLink == true">
and (
rebate_remark_json is null
or char_length(trim(rebate_remark_json)) &lt;= 2
or rebate_remark_json not like '%"uploadRecordId"%'
)
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date(order_time) &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date(order_time) &lt;= #{params.endTime}
</if>
</where>
order by remark asc, create_time desc, id desc
</select>
<select id="selectJDOrderListWithSort" parameterType="JDOrder" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
<where>
<if test="remark != null and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
<if test="params.orderSearch != null and params.orderSearch != ''">
and (
order_id like concat('%', #{params.orderSearch}, '%')
or third_party_order_no like concat('%', #{params.orderSearch}, '%')
or distribution_mark like concat('%', #{params.orderSearch}, '%')
or waybill_no like concat('%', #{params.orderSearch}, '%')
)
</if>
<if test="params.mobileQuickSearch != null and params.mobileQuickSearch != ''">
and (
remark like concat('%', #{params.mobileQuickSearch}, '%')
or order_id like concat('%', #{params.mobileQuickSearch}, '%')
or third_party_order_no like concat('%', #{params.mobileQuickSearch}, '%')
or distribution_mark like concat('%', #{params.mobileQuickSearch}, '%')
or waybill_no like concat('%', #{params.mobileQuickSearch}, '%')
or buyer like concat('%', #{params.mobileQuickSearch}, '%')
or address like concat('%', #{params.mobileQuickSearch}, '%')
)
</if>
<if test="params.quickRecordSearch != null and params.quickRecordSearch != ''">
and (
model_number like concat('%', #{params.quickRecordSearch}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{params.quickRecordSearch}, '%')
or address like concat('%', #{params.quickRecordSearch}, '%')
or buyer like concat('%', #{params.quickRecordSearch}, '%')
or order_id like concat('%', #{params.quickRecordSearch}, '%')
or third_party_order_no like concat('%', #{params.quickRecordSearch}, '%')
or distribution_mark like concat('%', #{params.quickRecordSearch}, '%')
or waybill_no like concat('%', #{params.quickRecordSearch}, '%')
or logistics_link like concat('%', #{params.quickRecordSearch}, '%')
)
</if>
<if test="distributionMark != null and distributionMark != ''"> and distribution_mark = #{distributionMark}</if>
<if test="modelNumber != null and modelNumber != ''">
and (
model_number like concat('%', #{modelNumber}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{modelNumber}, '%')
)
</if>
<if test="modelShop != null and modelShop != ''"> and model_shop = #{modelShop}</if>
<if test="params.modelNumberExcludeList != null and params.modelNumberExcludeList.size() > 0">
<foreach collection="params.modelNumberExcludeList" item="ex">
and (model_number is null or model_number not like concat('%', #{ex}, '%'))
</foreach>
</if>
<if test="link != null and link != ''"> and link like concat('%', #{link}, '%')</if>
<if test="paymentAmount != null"> and payment_amount = #{paymentAmount}</if>
<if test="rebateAmount != null"> and rebate_amount = #{rebateAmount}</if>
<if test="address != null and address != ''"> and address like concat('%', #{address}, '%')</if>
<if test="logisticsLink != null and logisticsLink != ''"> and logistics_link like concat('%', #{logisticsLink}, '%')</if>
<if test="waybillNo != null and waybillNo != ''"> and waybill_no like concat('%', #{waybillNo}, '%')</if>
<if test="buyer != null and buyer != ''"> and buyer like concat('%', #{buyer}, '%')</if>
<if test="orderTime != null"> and order_time = #{orderTime}</if>
<if test="status != null and status != ''"> and status like concat('%', #{status}, '%')</if>
<if test="isRefunded != null"> and is_refunded = #{isRefunded}</if>
<if test="isRefundReceived != null"> and is_refund_received = #{isRefundReceived}</if>
<if test="isRebateReceived != null"> and is_rebate_received = #{isRebateReceived}</if>
<if test="isPriceProtected != null"> and is_price_protected = #{isPriceProtected}</if>
<if test="isInvoiceOpened != null"> and is_invoice_opened = #{isInvoiceOpened}</if>
<if test="isReviewPosted != null"> and is_review_posted = #{isReviewPosted}</if>
<if test="rebateRemarkHasAbnormal != null"> and rebate_remark_has_abnormal = #{rebateRemarkHasAbnormal}</if>
<if test="params.hasRebateRemark != null and params.hasRebateRemark == true">
and rebate_remark_json is not null and char_length(trim(rebate_remark_json)) &gt; 2
</if>
<if test="params.rebateWithoutUploadLink != null and params.rebateWithoutUploadLink == true">
and (
rebate_remark_json is null
or char_length(trim(rebate_remark_json)) &lt;= 2
or rebate_remark_json not like '%"uploadRecordId"%'
)
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date(order_time) &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date(order_time) &lt;= #{params.endTime}
</if>
</where>
<choose>
<when test="params.orderBy != null and params.orderBy != ''">
order by ${params.orderBy}
<if test="params.isAsc != null and params.isAsc == 'asc'">asc</if>
<if test="params.isAsc == null or params.isAsc == 'desc'">desc</if>
</when>
<otherwise>
order by remark asc, create_time desc, id desc
</otherwise>
</choose>
</select>
<select id="selectJDOrderById" parameterType="long" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where id = #{id}
</select>
<insert id="insertJDOrder" parameterType="JDOrder" useGeneratedKeys="true" keyProperty="id">
insert into jd_order (
remark, distribution_mark, model_number, model_shop, link,
payment_amount, rebate_amount, address, logistics_link, waybill_no,
tencent_doc_pushed, tencent_doc_push_time,
order_id, buyer, order_time, create_time, update_time, status, is_count_enabled, third_party_order_no, jingfen_actual_price,
is_refunded, refund_date, is_refund_received, refund_received_date, is_rebate_received, rebate_received_date,
is_price_protected, price_protected_date, is_invoice_opened, invoice_opened_date, is_review_posted, review_posted_date,
selling_price_type, selling_price, profit, selling_price_manual, profit_manual, extra_cost
) values (
#{remark}, #{distributionMark}, #{modelNumber}, #{modelShop}, #{link},
#{paymentAmount}, #{rebateAmount}, #{address}, #{logisticsLink}, #{waybillNo},
0, null,
#{orderId}, #{buyer}, #{orderTime}, now(), now(), #{status}, #{isCountEnabled}, #{thirdPartyOrderNo}, #{jingfenActualPrice},
#{isRefunded}, #{refundDate}, #{isRefundReceived}, #{refundReceivedDate}, #{isRebateReceived}, #{rebateReceivedDate},
#{isPriceProtected}, #{priceProtectedDate}, #{isInvoiceOpened}, #{invoiceOpenedDate}, #{isReviewPosted}, #{reviewPostedDate},
#{sellingPriceType}, #{sellingPrice}, #{profit}, #{sellingPriceManual}, #{profitManual}, #{extraCost,jdbcType=DOUBLE}
)
</insert>
<update id="updateJDOrder" parameterType="JDOrder">
update jd_order
<set>
<if test="remark != null"> remark = #{remark},</if>
<if test="distributionMark != null"> distribution_mark = #{distributionMark},</if>
<if test="modelNumber != null"> model_number = #{modelNumber},</if>
<if test="modelShop != null"> model_shop = #{modelShop},</if>
<if test="link != null"> link = #{link},</if>
<if test="paymentAmount != null"> payment_amount = #{paymentAmount},</if>
<if test="rebateAmount != null"> rebate_amount = #{rebateAmount},</if>
<if test="address != null"> address = #{address},</if>
<if test="logisticsLink != null"> logistics_link = #{logisticsLink},</if>
<if test="waybillNo != null"> waybill_no = #{waybillNo},</if>
<if test="tencentDocPushed != null"> tencent_doc_pushed = #{tencentDocPushed},</if>
<if test="tencentDocPushTime != null"> tencent_doc_push_time = #{tencentDocPushTime},</if>
<if test="orderId != null"> order_id = #{orderId},</if>
<if test="buyer != null"> buyer = #{buyer},</if>
<if test="orderTime != null"> order_time = #{orderTime},</if>
<if test="status != null"> status = #{status},</if>
<if test="isCountEnabled != null"> is_count_enabled = #{isCountEnabled},</if>
<if test="thirdPartyOrderNo != null"> third_party_order_no = #{thirdPartyOrderNo},</if>
<if test="jingfenActualPrice != null"> jingfen_actual_price = #{jingfenActualPrice},</if>
<if test="isRefunded != null"> is_refunded = #{isRefunded},</if>
<if test="refundDate != null"> refund_date = #{refundDate},</if>
<if test="isRefundReceived != null"> is_refund_received = #{isRefundReceived},</if>
<if test="refundReceivedDate != null"> refund_received_date = #{refundReceivedDate},</if>
<if test="isRebateReceived != null"> is_rebate_received = #{isRebateReceived},</if>
<if test="rebateReceivedDate != null"> rebate_received_date = #{rebateReceivedDate},</if>
<if test="isPriceProtected != null"> is_price_protected = #{isPriceProtected},</if>
<if test="priceProtectedDate != null"> price_protected_date = #{priceProtectedDate},</if>
<if test="isInvoiceOpened != null"> is_invoice_opened = #{isInvoiceOpened},</if>
<if test="invoiceOpenedDate != null"> invoice_opened_date = #{invoiceOpenedDate},</if>
<if test="isReviewPosted != null"> is_review_posted = #{isReviewPosted},</if>
<if test="reviewPostedDate != null"> review_posted_date = #{reviewPostedDate},</if>
<if test="rebateRemarkJson != null"> rebate_remark_json = #{rebateRemarkJson},</if>
<if test="rebateRemarkHasAbnormal != null"> rebate_remark_has_abnormal = #{rebateRemarkHasAbnormal},</if>
<!-- extra_cost:随列表保存一并写入 applyProfitFields,避免仅写了 profit 却未持久化额外成本 -->
<if test="params != null and params.applyProfitFields != null and params.applyProfitFields == true">
selling_price_type = #{sellingPriceType,jdbcType=VARCHAR},
selling_price = #{sellingPrice,jdbcType=DOUBLE},
profit = #{profit,jdbcType=DOUBLE},
selling_price_manual = #{sellingPriceManual,jdbcType=INTEGER},
profit_manual = #{profitManual,jdbcType=INTEGER},
extra_cost = COALESCE(#{extraCost,jdbcType=DOUBLE}, 0),
</if>
update_time = now()
</set>
where id = #{id}
</update>
<select id="selectJDOrderByRemark" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where remark = #{remark}
limit 1
</select>
<select id="selectJDOrderListByAddress" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where address = #{address}
order by order_time desc
</select>
<select id="selectJDOrderByOrderId" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where order_id = #{orderId}
order by order_time desc
limit 1
</select>
<select id="selectLatestJDOrdersByOrderIds" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where id in (
select max(id) from jd_order
where order_id in
<foreach collection="orderIds" item="oid" open="(" separator="," close=")">
#{oid}
</foreach>
group by order_id
)
</select>
<select id="selectJDOrderByLogisticsLink" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where logistics_link = #{logisticsLink}
order by order_time desc
limit 1
</select>
<select id="selectJDOrderByWaybillNo" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where waybill_no = #{waybillNo}
order by order_time desc
limit 1
</select>
<select id="selectJDOrderByThirdPartyOrderNo" parameterType="string" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where third_party_order_no = #{thirdPartyOrderNo}
limit 1
</select>
<select id="selectOrderIdsByRebateRemarkUploadRecordId" parameterType="long" resultType="long">
select id from jd_order
where rebate_remark_json is not null
and char_length(trim(rebate_remark_json)) &gt; 2
and (
rebate_remark_json like concat('%"uploadRecordId":', #{uploadRecordId}, ',%')
or rebate_remark_json like concat('%"uploadRecordId":', #{uploadRecordId}, '}%')
)
</select>
<delete id="deleteJDOrderByIds" parameterType="long">
delete from jd_order where id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectJDOrderListByDistributionMarkFOrPDD" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
<where>
(distribution_mark = 'F' OR distribution_mark LIKE 'F-%' OR distribution_mark = 'PDD' OR distribution_mark = 'H' OR distribution_mark = 'W' OR distribution_mark = 'PDD-W')
AND logistics_link IS NOT NULL
AND logistics_link != ''
AND create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
</where>
ORDER BY create_time DESC
</select>
<resultMap id="QuickRecordModelOptionResult" type="com.ruoyi.jarvis.domain.dto.QuickRecordModelOption">
<result property="modelNumber" column="model_number"/>
<result property="modelShop" column="model_shop"/>
<result property="lastPaymentAmount" column="last_payment_amount"/>
<result property="lastRebateAmount" column="last_rebate_amount"/>
</resultMap>
<select id="selectQuickRecordModelOptions" resultMap="QuickRecordModelOptionResult">
select o.model_number as model_number,
o.model_shop as model_shop,
o.payment_amount as last_payment_amount,
o.rebate_amount as last_rebate_amount
from jd_order o
inner join (
select trim(IFNULL(model_number, '')) as m,
trim(IFNULL(model_shop, '')) as s,
max(id) as mid
from jd_order
where model_number is not null and trim(model_number) != ''
group by trim(IFNULL(model_number, '')), trim(IFNULL(model_shop, ''))
) t on trim(IFNULL(o.model_number, '')) = t.m
and trim(IFNULL(o.model_shop, '')) = t.s
and o.id = t.mid
order by o.id desc
</select>
<select id="selectOrdersPendingModelShopMigration" resultMap="JDOrderResult">
<include refid="selectJDOrderBase"/>
where model_number is not null
and trim(model_number) != ''
order by id asc
</select>
<update id="updateModelShopFields">
update jd_order
set model_number = #{modelNumber},
model_shop = #{modelShop},
update_time = now()
where id = #{id}
</update>
</mapper>