122 lines
5.2 KiB
XML
122 lines
5.2 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.rj.mapper.LbOrderRowMapper">
|
|
|
|
<!-- 复合主键 (tenant_id, id),按租户 + 订单 id upsert -->
|
|
<insert id="upsertBatch">
|
|
INSERT INTO lb_order_row (
|
|
id, old_id, tenant_id, data_type,
|
|
seller_id, seller_name, seller_phone,
|
|
buyer_id, buyer_name, buyer_phone,
|
|
order_sn, total_money,
|
|
pay_time, pay_img, status, is_resell, is_show,
|
|
consignee, phone, province, city, area, address,
|
|
merchandise_id, confirm_time, buy_time, created_at, updated_at,
|
|
today_total_money_sum, today_unresell_count, today_order_count, avg_amt
|
|
) VALUES
|
|
<foreach collection="list" item="item" separator=",">
|
|
(
|
|
#{item.id}, #{item.oldId}, #{item.tenantId}, #{item.dataType},
|
|
#{item.sellerId}, #{item.sellerName}, #{item.sellerPhone},
|
|
#{item.buyerId}, #{item.buyerName}, #{item.buyerPhone},
|
|
#{item.orderSn}, #{item.totalMoney},
|
|
#{item.payTime}, #{item.payImg}, #{item.status}, #{item.isResell}, #{item.isShow},
|
|
#{item.consignee}, #{item.phone}, #{item.province}, #{item.city}, #{item.area}, #{item.address},
|
|
#{item.merchandiseId}, #{item.confirmTime}, #{item.buyTime}, #{item.createdAt}, #{item.updatedAt},
|
|
#{item.todayTotalMoneySum}, #{item.todayUnresellCount}, #{item.todayOrderCount}, #{item.avgAmt}
|
|
)
|
|
</foreach>
|
|
ON DUPLICATE KEY UPDATE
|
|
old_id = VALUES(old_id),
|
|
tenant_id = VALUES(tenant_id),
|
|
data_type = VALUES(data_type),
|
|
seller_id = VALUES(seller_id),
|
|
seller_name = VALUES(seller_name),
|
|
seller_phone = VALUES(seller_phone),
|
|
buyer_id = VALUES(buyer_id),
|
|
buyer_name = VALUES(buyer_name),
|
|
buyer_phone = VALUES(buyer_phone),
|
|
order_sn = VALUES(order_sn),
|
|
total_money = VALUES(total_money),
|
|
pay_time = VALUES(pay_time),
|
|
pay_img = VALUES(pay_img),
|
|
status = VALUES(status),
|
|
is_resell = VALUES(is_resell),
|
|
is_show = VALUES(is_show),
|
|
consignee = VALUES(consignee),
|
|
phone = VALUES(phone),
|
|
province = VALUES(province),
|
|
city = VALUES(city),
|
|
area = VALUES(area),
|
|
address = VALUES(address),
|
|
merchandise_id = VALUES(merchandise_id),
|
|
confirm_time = VALUES(confirm_time),
|
|
buy_time = VALUES(buy_time),
|
|
created_at = VALUES(created_at),
|
|
updated_at = VALUES(updated_at),
|
|
today_total_money_sum = VALUES(today_total_money_sum),
|
|
today_unresell_count = VALUES(today_unresell_count),
|
|
today_order_count = VALUES(today_order_count),
|
|
avg_amt = VALUES(avg_amt)
|
|
</insert>
|
|
|
|
<select id="selectLatestPaidStatsByTenantId" resultType="com.rj.dto.LbBuyerTradeStats">
|
|
SELECT o.buyer_id AS buyerId,
|
|
o.pay_time AS payTime,
|
|
o.total_money AS totalMoney
|
|
FROM lb_order_row o
|
|
WHERE o.tenant_id = #{tenantId}
|
|
AND o.data_type = #{dataType}
|
|
AND o.buyer_id IS NOT NULL
|
|
AND o.pay_time IS NOT NULL
|
|
AND TRIM(o.pay_time) != ''
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM lb_order_row o2
|
|
WHERE o2.tenant_id = o.tenant_id
|
|
AND o2.data_type = o.data_type
|
|
AND o2.buyer_id = o.buyer_id
|
|
AND o2.pay_time IS NOT NULL
|
|
AND TRIM(o2.pay_time) != ''
|
|
AND (
|
|
o2.pay_time > o.pay_time
|
|
OR (o2.pay_time = o.pay_time AND o2.id > o.id)
|
|
)
|
|
)
|
|
</select>
|
|
|
|
<select id="selectSumTotalMoneyByBuyerIdsAndTimeRange" resultType="java.math.BigDecimal">
|
|
SELECT COALESCE(SUM(o.total_money), 0)
|
|
FROM lb_order_row o
|
|
WHERE o.tenant_id = #{tenantId}
|
|
AND o.buyer_id IN
|
|
<foreach collection="buyerIds" item="buyerId" open="(" separator="," close=")">
|
|
#{buyerId}
|
|
</foreach>
|
|
<if test="buyStartTime != null and buyStartTime != ''">
|
|
AND o.buy_time >= #{buyStartTime}
|
|
</if>
|
|
<if test="buyEndTime != null and buyEndTime != ''">
|
|
AND o.buy_time <= #{buyEndTime}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="selectSumTotalMoneyGroupByBuyerIds" resultType="map">
|
|
SELECT o.buyer_id AS buyerId, COALESCE(SUM(o.total_money), 0) AS totalMoney
|
|
FROM lb_order_row o
|
|
WHERE o.tenant_id = #{tenantId}
|
|
AND o.buyer_id IN
|
|
<foreach collection="buyerIds" item="buyerId" open="(" separator="," close=")">
|
|
#{buyerId}
|
|
</foreach>
|
|
<if test="buyStartTime != null and buyStartTime != ''">
|
|
AND o.buy_time >= #{buyStartTime}
|
|
</if>
|
|
<if test="buyEndTime != null and buyEndTime != ''">
|
|
AND o.buy_time <= #{buyEndTime}
|
|
</if>
|
|
GROUP BY o.buyer_id
|
|
</select>
|
|
|
|
</mapper>
|