update customer package

This commit is contained in:
Timi
2026-09-06 15:49:57 +08:00
parent f3166f0413
commit db2fca5715
25 changed files with 394 additions and 608 deletions
@@ -0,0 +1,38 @@
ALTER TABLE `gao_sales_order_item`
ADD COLUMN `item_type` VARCHAR(32) NOT NULL DEFAULT 'DIRECT_PRODUCT' COMMENT 'DIRECT_PRODUCT 直接产品,PACKAGE_ENTITLEMENT 套餐权益' AFTER `sales_order_id`,
MODIFY COLUMN `unit_price` BIGINT NULL COMMENT '实际单价,套餐权益为空',
MODIFY COLUMN `line_amount` BIGINT NULL COMMENT '行金额,套餐权益为空';
ALTER TABLE `gao_order_fulfillment_item`
DROP KEY `uk_gao_order_fulfillment_item_package`,
DROP KEY `idx_gao_order_fulfillment_item_package_source`,
MODIFY COLUMN `source_order_item_id` VARCHAR(36) NOT NULL COMMENT '来源销售订单项 ID',
DROP COLUMN `source_customer_package_item_id`;
ALTER TABLE `gao_order_fulfillment`
DROP COLUMN `fulfillment_type`;
ALTER TABLE `gao_customer_package`
DROP KEY `idx_gao_customer_package_customer`,
DROP COLUMN `status`,
DROP COLUMN `cancelled_at`,
DROP COLUMN `cancel_operator_user_id`,
DROP COLUMN `cancel_reason`;
DROP TABLE IF EXISTS `gao_customer_package_item`;
DELETE role_permission
FROM `role_permission` role_permission
INNER JOIN `permission` permission ON permission.`id` = role_permission.`permission_id`
WHERE permission.`module_code` = 'GAO'
AND permission.`code` IN ('PACKAGE_DELIVERY:CREATE', 'PACKAGE_DELIVERY:READ', 'PACKAGE_DELIVERY:VERIFY', 'PACKAGE_DELIVERY:REVOKE');
DELETE role_permission_delegation
FROM `role_permission_delegation` role_permission_delegation
INNER JOIN `permission` permission ON permission.`id` = role_permission_delegation.`permission_id`
WHERE permission.`module_code` = 'GAO'
AND permission.`code` IN ('PACKAGE_DELIVERY:CREATE', 'PACKAGE_DELIVERY:READ', 'PACKAGE_DELIVERY:VERIFY', 'PACKAGE_DELIVERY:REVOKE');
DELETE FROM `permission`
WHERE `module_code` = 'GAO'
AND `code` IN ('PACKAGE_DELIVERY:CREATE', 'PACKAGE_DELIVERY:READ', 'PACKAGE_DELIVERY:VERIFY', 'PACKAGE_DELIVERY:REVOKE');
@@ -1,39 +0,0 @@
<?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.GaoCustomerPackageItemMapper">
<select id="selectByCustomerPackageId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `customer_package_id` = #{customerPackageId} AND `deleted_at` IS NULL
ORDER BY `sort`, `created_at`
</select>
<select id="selectByCustomerPackageIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `deleted_at` IS NULL
<choose>
<when test="customerPackageIdList != null and !customerPackageIdList.isEmpty()">
AND `customer_package_id` IN <foreach collection="customerPackageIdList" item="id" open="(" separator="," close=")">#{id}</foreach>
</when>
<otherwise>AND FALSE</otherwise>
</choose>
ORDER BY `customer_package_id`, `sort`, `created_at`
</select>
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `id` = #{id} AND `deleted_at` IS NULL
FOR UPDATE
</select>
<update id="updateReservedQuantity">
UPDATE `gao_customer_package_item`
SET `reserved_quantity` = `reserved_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
WHERE `id` = #{id} AND `deleted_at` IS NULL
AND `reserved_quantity` + #{delta} &gt;= 0
AND `reserved_quantity` + `fulfilled_quantity` + #{delta} &lt;= `total_quantity`
</update>
<update id="updateFulfilledQuantity">
UPDATE `gao_customer_package_item`
SET `fulfilled_quantity` = `fulfilled_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
WHERE `id` = #{id} AND `deleted_at` IS NULL
AND `fulfilled_quantity` + #{delta} &gt;= 0
AND `reserved_quantity` + `fulfilled_quantity` + #{delta} &lt;= `total_quantity`
</update>
</mapper>
@@ -1,11 +1,6 @@
<?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.GaoCustomerPackageMapper">
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
SELECT * FROM `gao_customer_package`
WHERE `id` = #{id} AND `deleted_at` IS NULL
FOR UPDATE
</select>
<select id="selectBySalesOrderId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
SELECT * FROM `gao_customer_package`
WHERE `sales_order_id` = #{salesOrderId} AND `deleted_at` IS NULL
@@ -15,18 +10,19 @@
p.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if>
<if test="customerId != null and customerId != ''">AND p.`customer_id` = #{customerId}</if>
<if test="status != null">AND p.`status` = #{status}</if>
<if test="status != null">AND o.`status` = #{status}</if>
<if test="keyword != null and keyword.trim() != ''">AND (p.`package_name_snapshot` LIKE CONCAT('%', #{keyword}, '%') OR c.`name` LIKE CONCAT('%', #{keyword}, '%') OR c.`code` LIKE CONCAT('%', #{keyword}, '%'))</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1) FROM `gao_customer_package` p
LEFT JOIN `gao_customer` c ON c.`id` = p.`customer_id`
INNER JOIN `gao_sales_order` o ON o.`id` = p.`sales_order_id` AND o.`store_id` = p.`store_id` AND o.`deleted_at` IS NULL
WHERE <include refid="queryWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
SELECT p.* FROM `gao_customer_package` p
LEFT JOIN `gao_customer` c ON c.`id` = p.`customer_id`
LEFT JOIN `gao_sales_order` o ON o.`id` = p.`sales_order_id` AND o.`store_id` = p.`store_id` AND o.`deleted_at` IS NULL
INNER JOIN `gao_sales_order` o ON o.`id` = p.`sales_order_id` AND o.`store_id` = p.`store_id` AND o.`deleted_at` IS NULL
WHERE <include refid="queryWhere"/>
ORDER BY o.`purchased_at` DESC, p.`created_at` DESC
LIMIT #{offset}, #{limit}
@@ -34,7 +34,6 @@
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
<if test="salesOrderId != null and salesOrderId != ''">AND `sales_order_id` = #{salesOrderId}</if>
<if test="customerId != null and customerId != ''">AND `customer_id` = #{customerId}</if>
<if test="fulfillmentType != null">AND `fulfillment_type` = #{fulfillmentType}</if>
<if test="status != null">AND `status` = #{status}</if>
<if test="beginAt != null">AND `delivered_at` &gt;= #{beginAt}</if>
<if test="endAt != null">AND `delivered_at` &lt;= #{endAt}</if>
@@ -11,6 +11,14 @@
WHERE `id` = #{id} AND `deleted_at` IS NULL
FOR UPDATE
</select>
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrder">
SELECT * FROM `gao_sales_order`
WHERE `id` IN
<foreach collection="idList" item="id" separator="," open="(" close=")">
#{id}
</foreach>
AND `deleted_at` IS NULL
</select>
<sql id="queryWhere">
o.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND o.`store_id` = #{storeId}</if>