add recycle

This commit is contained in:
Timi
2026-11-08 18:50:53 +08:00
parent 03a4d4a8ff
commit 74dd150469
40 changed files with 2326 additions and 9 deletions
@@ -7,7 +7,9 @@
(SELECT COUNT(*) FROM `gao_order_fulfillment_item` WHERE `product_id_snapshot` = #{productId}) +
(SELECT COUNT(*) FROM `gao_product_stock_record` WHERE `product_id_snapshot` = #{productId}) +
(SELECT COUNT(*) FROM `gao_package_config_item` WHERE `product_id_snapshot` = #{productId}) +
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `product_id_snapshot` = #{productId})
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `product_id_snapshot` = #{productId}) +
(SELECT COUNT(*) FROM `gao_recycle_item` WHERE `product_id` = #{productId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange` WHERE `product_id_snapshot` = #{productId} OR `source_product_id_snapshot` = #{productId})
</select>
<select id="countSkuReferences" resultType="int">
SELECT
@@ -16,7 +18,10 @@
(SELECT COUNT(*) FROM `gao_product_stock_record` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_package_config_item` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_point_redeem_sku` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `sku_id_snapshot` = #{skuId})
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `sku_id_snapshot` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_recycle_item` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange_rule` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange` WHERE `sku_id_snapshot` = #{skuId} OR `source_sku_id_snapshot` = #{skuId})
</select>
<select id="countUnitReferences" resultType="int">
SELECT
@@ -25,7 +30,13 @@
(SELECT COUNT(*) FROM `gao_product_stock_record` WHERE `sku_unit_id` = #{unitId}) +
(SELECT COUNT(*) FROM `gao_package_config_item` WHERE `sku_unit_id` = #{unitId}) +
(SELECT COUNT(*) FROM `gao_point_redeem_sku` WHERE `sku_unit_id` = #{unitId}) +
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `sku_unit_id_snapshot` = #{unitId})
(SELECT COUNT(*) FROM `gao_point_redemption` WHERE `sku_unit_id_snapshot` = #{unitId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange_rule` WHERE `sku_unit_id` = #{unitId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange` WHERE `sku_unit_id_snapshot` = #{unitId})
</select>
<select id="countRecycleReferences" resultType="int">
SELECT (SELECT COUNT(*) FROM `gao_recycle_exchange_rule` WHERE `sku_id` = #{skuId}) +
(SELECT COUNT(*) FROM `gao_recycle_exchange` WHERE `sku_id_snapshot` = #{skuId})
</select>
<select id="countMigrationPrecisionLoss" resultType="int">
SELECT COUNT(*) FROM (
@@ -0,0 +1,20 @@
<?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.imyeyu.api.modules.gao.mapper.GaoRecycleExchangeQueryMapper">
<sql id="conditions">
`store_id` = #{storeId}
<if test="customerId != null and customerId != ''">AND `customer_id` = #{customerId}</if>
<if test="recycleItemId != null and recycleItemId != ''">AND `recycle_item_id` = #{recycleItemId}</if>
<if test="skuId != null and skuId != ''">AND `sku_id_snapshot` = #{skuId}</if>
<if test="status != null">AND `status` = #{status}</if>
<if test="beginAt != null">AND `occurred_at` &gt;= #{beginAt}</if>
<if test="endAt != null">AND `occurred_at` &lt;= #{endAt}</if>
</sql>
<select id="count" resultType="long">
SELECT COUNT(*) FROM `gao_recycle_exchange` WHERE <include refid="conditions"/>
</select>
<select id="list" resultType="com.imyeyu.api.modules.gao.entity.GaoRecycleExchange">
SELECT * FROM `gao_recycle_exchange` WHERE <include refid="conditions"/>
ORDER BY `occurred_at` DESC, `created_at` DESC, `id` DESC LIMIT #{offset}, #{limit}
</select>
</mapper>
@@ -0,0 +1,44 @@
<?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.imyeyu.api.modules.gao.mapper.GaoRecycleStatMapper">
<select id="selectRecycleStats" resultType="com.imyeyu.api.modules.gao.vo.GaoRecycleStatView">
SELECT t.recycle_item_id AS recycleItemId, t.recycle_name AS recycleName,
t.recycle_unit AS recycleUnit, SUM(t.received) AS receivedQuantity,
SUM(t.returned) AS returnedQuantity, SUM(t.received - t.returned) AS netQuantity
FROM (
SELECT e.recycle_item_id, e.recycle_name_snapshot AS recycle_name,
e.recycle_unit_snapshot AS recycle_unit, e.recycle_quantity AS received, 0 AS returned
FROM gao_recycle_exchange e
WHERE e.store_id = #{storeId} AND e.occurred_at &gt;= #{startAt} AND e.occurred_at &lt; #{endAt}
UNION ALL
SELECT e.recycle_item_id, e.recycle_name_snapshot, e.recycle_unit_snapshot,
0, e.recycle_quantity
FROM gao_recycle_exchange_action a
JOIN gao_recycle_exchange e ON e.id = a.exchange_id AND e.store_id = a.store_id
WHERE a.store_id = #{storeId} AND a.action_type IN ('CANCEL', 'REVOKE')
AND a.recycle_returned = 1 AND a.occurred_at &gt;= #{startAt} AND a.occurred_at &lt; #{endAt}
) t
GROUP BY t.recycle_item_id, t.recycle_name, t.recycle_unit
</select>
<select id="selectExchangeStats" resultType="com.imyeyu.api.modules.gao.vo.GaoRecycleExchangeStatView">
SELECT t.sku_id AS skuId, t.sku_unit_id AS skuUnitId, t.product_name AS productName,
t.unit_name AS unit, SUM(t.created) AS createdQuantity,
SUM(t.verified) AS verifiedQuantity, SUM(t.revoked) AS revokedQuantity
FROM (
SELECT e.sku_id_snapshot AS sku_id, e.sku_unit_id_snapshot AS sku_unit_id,
e.product_name_snapshot AS product_name, e.unit_snapshot AS unit_name,
e.exchange_quantity AS created, 0 AS verified, 0 AS revoked
FROM gao_recycle_exchange e
WHERE e.store_id = #{storeId} AND e.occurred_at &gt;= #{startAt} AND e.occurred_at &lt; #{endAt}
UNION ALL
SELECT e.sku_id_snapshot, e.sku_unit_id_snapshot, e.product_name_snapshot, e.unit_snapshot,
0, CASE WHEN a.action_type = 'VERIFY' THEN e.exchange_quantity ELSE 0 END,
CASE WHEN a.action_type = 'REVOKE' THEN e.exchange_quantity ELSE 0 END
FROM gao_recycle_exchange_action a
JOIN gao_recycle_exchange e ON e.id = a.exchange_id AND e.store_id = a.store_id
WHERE a.store_id = #{storeId} AND a.action_type IN ('VERIFY', 'REVOKE')
AND a.occurred_at &gt;= #{startAt} AND a.occurred_at &lt; #{endAt}
) t
GROUP BY t.sku_id, t.sku_unit_id, t.product_name, t.unit_name
</select>
</mapper>