rename GaoStockRecord to GaoProductStockRecord

This commit is contained in:
Timi
2026-09-04 10:37:43 +08:00
parent 913dc3d278
commit df16ac3c8e
23 changed files with 377 additions and 197 deletions
@@ -0,0 +1,2 @@
ALTER TABLE `gao_product`
DROP COLUMN `base_unit`;
@@ -0,0 +1,2 @@
ALTER TABLE `gao_product`
DROP COLUMN `reference_cost`;
@@ -0,0 +1,12 @@
RENAME TABLE `gao_stock_record` TO `gao_product_stock_record`;
ALTER TABLE `gao_product_stock_record`
DROP KEY `uk_gao_stock_record_request_product`,
DROP KEY `uk_gao_stock_record_source`,
DROP KEY `idx_gao_stock_record_product_time`,
DROP KEY `idx_gao_stock_record_biz_time`,
DROP COLUMN `reason`,
ADD UNIQUE KEY `uk_gao_product_stock_record_request_product` (`store_id`, `request_no`, `operation_type`, `product_id`),
ADD UNIQUE KEY `uk_gao_product_stock_record_source` (`source_record_id`),
ADD KEY `idx_gao_product_stock_record_product_time` (`store_id`, `product_id`, `occurred_at`, `id`),
ADD KEY `idx_gao_product_stock_record_biz_time` (`store_id`, `biz_type`, `biz_id`, `occurred_at`, `id`);
@@ -1,18 +1,28 @@
<?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.GaoStockRecordMapper">
<select id="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoStockRecord">
SELECT * FROM `gao_stock_record`
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoProductStockRecordMapper">
<select id="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT * FROM `gao_product_stock_record`
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo}
ORDER BY `product_id`, `id`
</select>
<select id="selectByBiz" resultType="com.imyeyu.api.modules.gao.entity.GaoStockRecord">
SELECT * FROM `gao_stock_record`
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT * FROM `gao_product_stock_record`
WHERE `id` = #{id}
FOR UPDATE
</select>
<select id="selectRevokeBySourceRecordId" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT * FROM `gao_product_stock_record`
WHERE `source_record_id` = #{sourceRecordId}
LIMIT 1
</select>
<select id="selectByBiz" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT * FROM `gao_product_stock_record`
WHERE `biz_type` = #{bizType} AND `biz_id` = #{bizId}
ORDER BY `occurred_at`, `id`
</select>
<select id="selectByBizProduct" resultType="com.imyeyu.api.modules.gao.entity.GaoStockRecord">
SELECT * FROM `gao_stock_record`
<select id="selectByBizProduct" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT * FROM `gao_product_stock_record`
WHERE `biz_type` = #{bizType} AND `biz_id` = #{bizId} AND `product_id` = #{productId} AND `operation_type` = #{operationType}
ORDER BY `occurred_at`, `id`
LIMIT 1
@@ -21,6 +31,7 @@
1 = 1
<if test="storeId != null and storeId != ''">AND r.`store_id` = #{storeId}</if>
<if test="productId != null and productId != ''">AND r.`product_id` = #{productId}</if>
<if test="keyword != null and keyword.trim() != ''">AND (r.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%') OR p.`code` LIKE CONCAT('%', #{keyword}, '%'))</if>
<if test="bizType != null">AND r.`biz_type` = #{bizType}</if>
<if test="bizId != null and bizId != ''">AND r.`biz_id` = #{bizId}</if>
<if test="operationType != null">AND r.`operation_type` = #{operationType}</if>
@@ -28,10 +39,10 @@
<if test="endAt != null">AND r.`occurred_at` &lt;= #{endAt}</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1) FROM `gao_stock_record` r WHERE <include refid="queryWhere"/>
SELECT COUNT(1) FROM `gao_product_stock_record` r LEFT JOIN `gao_product` p ON p.`id` = r.`product_id` AND p.`store_id` = r.`store_id` WHERE <include refid="queryWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoStockRecord">
SELECT r.* FROM `gao_stock_record` r WHERE <include refid="queryWhere"/>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStockRecord">
SELECT r.* FROM `gao_product_stock_record` r LEFT JOIN `gao_product` p ON p.`id` = r.`product_id` AND p.`store_id` = r.`store_id` WHERE <include refid="queryWhere"/>
ORDER BY r.`occurred_at` DESC, r.`id` DESC
LIMIT #{offset}, #{limit}
</select>