add gao product
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
CREATE TABLE IF NOT EXISTS `gao_product_category` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '所属门店 ID',
|
||||
`name` VARCHAR(64) NOT NULL COMMENT '分类名称',
|
||||
`sort` INT NOT NULL DEFAULT 0 COMMENT '排序值',
|
||||
`status` VARCHAR(32) NOT NULL COMMENT 'ACTIVE 启用,INACTIVE 停用',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
`deleted_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_gao_product_category_store_status` (`store_id`, `status`, `deleted_at`, `sort`, `name`)
|
||||
) COMMENT='GAO 产品分类';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_product` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '所属门店 ID',
|
||||
`category_id` VARCHAR(36) NULL COMMENT '产品分类 ID',
|
||||
`code` VARCHAR(64) NOT NULL COMMENT '门店内产品编码',
|
||||
`name` VARCHAR(128) NOT NULL COMMENT '产品名称',
|
||||
`product_type` VARCHAR(32) NOT NULL COMMENT 'SERVICE 服务,GOODS 实物,CONSUMABLE 消耗品',
|
||||
`base_unit` VARCHAR(32) NOT NULL COMMENT '基础库存单位',
|
||||
`stock_enabled` TINYINT(1) NOT NULL COMMENT 'true 为启用库存管理',
|
||||
`allow_decimal_quantity` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'true 为允许业务数量保留小数',
|
||||
`status` VARCHAR(32) NOT NULL COMMENT 'ACTIVE 启用,INACTIVE 停用',
|
||||
`sale_price` BIGINT NULL COMMENT '建议售价,单位分',
|
||||
`reference_cost` BIGINT NULL COMMENT '参考成本,单位分',
|
||||
`min_stock_quantity` DECIMAL(18,3) NULL COMMENT '最低库存,基础单位',
|
||||
`sort` INT NOT NULL DEFAULT 0 COMMENT '排序值',
|
||||
`remark` VARCHAR(255) NULL COMMENT '备注',
|
||||
`updated_by` VARCHAR(36) NOT NULL COMMENT '最后修改用户 ID',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
`deleted_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_product_store_code` (`store_id`, `code`),
|
||||
KEY `idx_gao_product_store_category` (`store_id`, `category_id`, `status`, `deleted_at`, `sort`, `name`)
|
||||
) COMMENT='GAO 产品';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_product_unit` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
`name` VARCHAR(32) NOT NULL COMMENT '单位名称',
|
||||
`conversion_to_base` DECIMAL(18,6) NOT NULL COMMENT '折算为基础单位的比例',
|
||||
`is_base` TINYINT(1) NOT NULL COMMENT 'true 为基础库存单位',
|
||||
`allow_purchase` TINYINT(1) NOT NULL COMMENT 'true 为允许采购入库',
|
||||
`allow_sale` TINYINT(1) NOT NULL COMMENT 'true 为允许销售或套餐配置',
|
||||
`sort` INT NOT NULL DEFAULT 0 COMMENT '排序值',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
`deleted_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_gao_product_unit_product` (`product_id`, `deleted_at`, `sort`)
|
||||
) COMMENT='GAO 产品单位';
|
||||
@@ -0,0 +1,46 @@
|
||||
CREATE TABLE IF NOT EXISTS `gao_product_stock` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
||||
`product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
`on_hand_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '实际库存,基础单位',
|
||||
`reserved_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '预占库存,基础单位',
|
||||
`updated_by` VARCHAR(36) NOT NULL COMMENT '最后操作人',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_product_stock_store_product` (`store_id`, `product_id`),
|
||||
KEY `idx_gao_product_stock_product` (`product_id`)
|
||||
) COMMENT='GAO 产品库存余额';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_stock_record` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
||||
`product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
`product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID',
|
||||
`product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照',
|
||||
`unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位快照',
|
||||
`conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照',
|
||||
`quantity` DECIMAL(18,3) NOT NULL COMMENT '业务数量',
|
||||
`base_quantity` DECIMAL(18,3) NOT NULL COMMENT '基础单位数量',
|
||||
`operation_type` VARCHAR(32) NOT NULL COMMENT '库存操作类型',
|
||||
`on_hand_delta` DECIMAL(18,3) NOT NULL COMMENT '实际库存增量',
|
||||
`reserved_delta` DECIMAL(18,3) NOT NULL COMMENT '预占库存增量',
|
||||
`on_hand_before` DECIMAL(18,3) NOT NULL COMMENT '操作前实际库存',
|
||||
`on_hand_after` DECIMAL(18,3) NOT NULL COMMENT '操作后实际库存',
|
||||
`reserved_before` DECIMAL(18,3) NOT NULL COMMENT '操作前预占库存',
|
||||
`reserved_after` DECIMAL(18,3) NOT NULL COMMENT '操作后预占库存',
|
||||
`biz_type` VARCHAR(32) NOT NULL COMMENT '来源业务类型',
|
||||
`biz_id` VARCHAR(36) NOT NULL COMMENT '来源业务 ID',
|
||||
`source_record_id` VARCHAR(36) NULL COMMENT '冲正来源流水 ID',
|
||||
`request_no` VARCHAR(128) NOT NULL COMMENT '幂等请求号',
|
||||
`operator_user_id` VARCHAR(36) NOT NULL COMMENT '操作人',
|
||||
`occurred_at` BIGINT NOT NULL COMMENT '发生时间',
|
||||
`reason` TEXT NULL COMMENT '原因',
|
||||
`remark` TEXT NULL COMMENT '备注',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_stock_record_request_product` (`store_id`, `request_no`, `operation_type`, `product_id`),
|
||||
UNIQUE KEY `uk_gao_stock_record_source` (`source_record_id`),
|
||||
KEY `idx_gao_stock_record_product_time` (`store_id`, `product_id`, `occurred_at`, `id`),
|
||||
KEY `idx_gao_stock_record_biz_time` (`store_id`, `biz_type`, `biz_id`, `occurred_at`, `id`)
|
||||
) COMMENT='GAO 库存变更流水';
|
||||
@@ -0,0 +1,61 @@
|
||||
ALTER TABLE `gao_store`
|
||||
ADD COLUMN `direct_product_sale_event_id` VARCHAR(36) NULL COMMENT '直接产品订单使用的消费事件 ID' AFTER `auto_closed_day`,
|
||||
ADD KEY `idx_gao_store_direct_product_sale_event` (`direct_product_sale_event_id`);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_sales_order` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
||||
`customer_id` VARCHAR(36) NOT NULL COMMENT '客户 ID',
|
||||
`order_no` VARCHAR(64) NOT NULL COMMENT '门店内订单号',
|
||||
`order_type` VARCHAR(32) NOT NULL COMMENT 'PACKAGE 套餐,DIRECT_PRODUCT 直接产品',
|
||||
`status` VARCHAR(32) NOT NULL COMMENT '订单状态',
|
||||
`payment_status` VARCHAR(32) NOT NULL COMMENT '付款状态',
|
||||
`refund_status` VARCHAR(32) NOT NULL COMMENT '退款状态',
|
||||
`sale_amount` BIGINT NOT NULL COMMENT '成交金额,单位分',
|
||||
`pending_paid_amount` BIGINT NOT NULL DEFAULT 0 COMMENT '待核销收款,单位分',
|
||||
`paid_amount` BIGINT NOT NULL DEFAULT 0 COMMENT '有效收款,单位分',
|
||||
`refunded_amount` BIGINT NOT NULL DEFAULT 0 COMMENT '有效退款,单位分',
|
||||
`source_event_record_id` VARCHAR(36) NULL COMMENT '来源事件记录 ID',
|
||||
`request_no` VARCHAR(128) NOT NULL COMMENT '创建订单幂等号',
|
||||
`purchased_at` BIGINT NOT NULL COMMENT '下单时间',
|
||||
`operator_user_id` VARCHAR(36) NOT NULL COMMENT '下单人',
|
||||
`cancelled_at` BIGINT NULL COMMENT '取消时间',
|
||||
`cancel_operator_user_id` VARCHAR(36) NULL COMMENT '取消人',
|
||||
`cancel_reason` TEXT NULL COMMENT '取消原因',
|
||||
`remark` TEXT NULL COMMENT '备注',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
`deleted_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_sales_order_store_no` (`store_id`, `order_no`),
|
||||
UNIQUE KEY `uk_gao_sales_order_store_request` (`store_id`, `request_no`),
|
||||
UNIQUE KEY `uk_gao_sales_order_source_event` (`source_event_record_id`),
|
||||
KEY `idx_gao_sales_order_customer` (`store_id`, `customer_id`, `status`, `deleted_at`, `purchased_at`),
|
||||
KEY `idx_gao_sales_order_payment` (`store_id`, `order_type`, `payment_status`, `refund_status`, `deleted_at`, `purchased_at`)
|
||||
) COMMENT='GAO 销售订单';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_sales_order_item` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`sales_order_id` VARCHAR(36) NOT NULL COMMENT '销售订单 ID',
|
||||
`product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
`product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID',
|
||||
`product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照',
|
||||
`unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位快照',
|
||||
`conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照',
|
||||
`quantity` DECIMAL(18,3) NOT NULL COMMENT '购买数量',
|
||||
`reserved_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '待履约数量',
|
||||
`fulfilled_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '已履约数量',
|
||||
`unit_price` BIGINT NOT NULL COMMENT '实际单价,单位分',
|
||||
`line_amount` BIGINT NOT NULL COMMENT '行金额,单位分',
|
||||
`sort` INT NOT NULL DEFAULT 0 COMMENT '排序值',
|
||||
`remark` VARCHAR(255) NULL COMMENT '备注',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
`deleted_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_sales_order_item_product_unit` (`sales_order_id`, `product_id`, `product_unit_id`),
|
||||
KEY `idx_gao_sales_order_item_order` (`sales_order_id`, `sort`, `created_at`)
|
||||
) COMMENT='GAO 直接产品订单明细';
|
||||
|
||||
ALTER TABLE `gao_fund_record`
|
||||
MODIFY COLUMN `biz_type` VARCHAR(32) NOT NULL COMMENT '业务类型,销售订单';
|
||||
@@ -0,0 +1,29 @@
|
||||
-- 套餐功能尚未上线,旧套餐记录无法可靠补齐产品主数据引用,清理不可兼容的旧数据
|
||||
DELETE FROM `gao_customer_package_item`;
|
||||
DELETE FROM `gao_customer_package`;
|
||||
DELETE FROM `gao_package_config_item`;
|
||||
UPDATE `gao_package_config`
|
||||
SET `status` = 'INACTIVE', `deleted_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `deleted_at` IS NULL;
|
||||
UPDATE `gao_event`
|
||||
SET `status` = 'DELETED', `deleted_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `biz_type` = 'PACKAGE_PURCHASE' AND `deleted_at` IS NULL;
|
||||
|
||||
ALTER TABLE `gao_package_config_item`
|
||||
ADD COLUMN IF NOT EXISTS `product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID' AFTER `package_config_id`,
|
||||
ADD COLUMN IF NOT EXISTS `product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID' AFTER `product_id`,
|
||||
ADD COLUMN IF NOT EXISTS `product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照' AFTER `product_unit_id`,
|
||||
ADD COLUMN IF NOT EXISTS `unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位快照' AFTER `product_name_snapshot`,
|
||||
ADD COLUMN IF NOT EXISTS `conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照' AFTER `unit_snapshot`,
|
||||
ADD KEY IF NOT EXISTS `idx_gao_package_config_item_product` (`product_id`, `product_unit_id`);
|
||||
|
||||
ALTER TABLE `gao_customer_package`
|
||||
ADD COLUMN IF NOT EXISTS `sales_order_id` VARCHAR(36) NOT NULL COMMENT '销售订单 ID' AFTER `id`,
|
||||
ADD UNIQUE KEY IF NOT EXISTS `uk_gao_customer_package_sales_order` (`sales_order_id`);
|
||||
|
||||
ALTER TABLE `gao_customer_package_item`
|
||||
ADD COLUMN IF NOT EXISTS `product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID' AFTER `customer_package_id`,
|
||||
ADD COLUMN IF NOT EXISTS `product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID' AFTER `product_id`,
|
||||
ADD COLUMN IF NOT EXISTS `conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照' AFTER `unit_snapshot`,
|
||||
ADD COLUMN IF NOT EXISTS `fulfilled_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '已履约数量' AFTER `reserved_quantity`,
|
||||
ADD KEY IF NOT EXISTS `idx_gao_customer_package_item_product` (`product_id`, `product_unit_id`);
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
CREATE TABLE IF NOT EXISTS `gao_order_fulfillment` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`sales_order_id` VARCHAR(36) NOT NULL COMMENT '销售订单 ID',
|
||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
||||
`customer_id` VARCHAR(36) NOT NULL COMMENT '客户 ID',
|
||||
`fulfillment_type` VARCHAR(32) NOT NULL COMMENT '履约类型',
|
||||
`status` VARCHAR(32) NOT NULL COMMENT '履约状态',
|
||||
`request_no` VARCHAR(128) NOT NULL COMMENT '履约幂等号',
|
||||
`operator_user_id` VARCHAR(36) NOT NULL COMMENT '提交人',
|
||||
`delivered_at` BIGINT NOT NULL COMMENT '实际履约时间',
|
||||
`verifier_user_id` VARCHAR(36) NULL COMMENT '核销或拒绝操作人',
|
||||
`verified_at` BIGINT NULL COMMENT '核销或拒绝时间',
|
||||
`source_fulfillment_id` VARCHAR(36) NULL COMMENT '冲正来源履约单 ID',
|
||||
`reason` TEXT NULL COMMENT '原因',
|
||||
`remark` TEXT NULL COMMENT '备注',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
`updated_at` BIGINT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_order_fulfillment_store_request` (`store_id`, `request_no`),
|
||||
UNIQUE KEY `uk_gao_order_fulfillment_source` (`source_fulfillment_id`),
|
||||
KEY `idx_gao_order_fulfillment_order` (`sales_order_id`, `created_at`),
|
||||
KEY `idx_gao_order_fulfillment_customer` (`store_id`, `customer_id`, `status`, `delivered_at`),
|
||||
KEY `idx_gao_order_fulfillment_status` (`store_id`, `status`, `delivered_at`)
|
||||
) COMMENT='GAO 统一履约单';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `gao_order_fulfillment_item` (
|
||||
`id` VARCHAR(36) NOT NULL,
|
||||
`fulfillment_id` VARCHAR(36) NOT NULL COMMENT '履约单 ID',
|
||||
`product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
`product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID',
|
||||
`source_order_item_id` VARCHAR(36) NULL COMMENT '直接订单明细 ID',
|
||||
`source_customer_package_item_id` VARCHAR(36) NULL COMMENT '客户套餐权益项 ID',
|
||||
`quantity` DECIMAL(18,3) NOT NULL COMMENT '本次履约数量',
|
||||
`base_quantity` DECIMAL(18,3) NOT NULL COMMENT '基础单位数量',
|
||||
`reserved_before` DECIMAL(18,3) NOT NULL COMMENT '操作前待履约数量',
|
||||
`reserved_after` DECIMAL(18,3) NOT NULL COMMENT '操作后待履约数量',
|
||||
`fulfilled_before` DECIMAL(18,3) NOT NULL COMMENT '操作前已履约数量',
|
||||
`fulfilled_after` DECIMAL(18,3) NOT NULL COMMENT '操作后已履约数量',
|
||||
`product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照',
|
||||
`unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位快照',
|
||||
`conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照',
|
||||
`created_at` BIGINT NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_gao_order_fulfillment_item_order` (`fulfillment_id`, `source_order_item_id`),
|
||||
UNIQUE KEY `uk_gao_order_fulfillment_item_package` (`fulfillment_id`, `source_customer_package_item_id`),
|
||||
KEY `idx_gao_order_fulfillment_item_fulfillment` (`fulfillment_id`, `created_at`),
|
||||
KEY `idx_gao_order_fulfillment_item_order_source` (`source_order_item_id`),
|
||||
KEY `idx_gao_order_fulfillment_item_package_source` (`source_customer_package_item_id`)
|
||||
) COMMENT='GAO 统一履约明细';
|
||||
@@ -0,0 +1,34 @@
|
||||
ALTER TABLE `gao_package_config_item`
|
||||
MODIFY COLUMN `product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
MODIFY COLUMN `product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID',
|
||||
MODIFY COLUMN `product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照',
|
||||
MODIFY COLUMN `unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位快照',
|
||||
MODIFY COLUMN `conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照',
|
||||
DROP COLUMN `product_name`,
|
||||
DROP COLUMN `unit`,
|
||||
ADD UNIQUE KEY `uk_gao_package_config_item_product_unit` (`package_config_id`, `product_id`, `product_unit_id`, `deleted_at`);
|
||||
|
||||
ALTER TABLE `gao_customer_package`
|
||||
MODIFY COLUMN `sales_order_id` VARCHAR(36) NOT NULL COMMENT '销售订单 ID',
|
||||
DROP INDEX `uk_gao_customer_package_purchase_event`,
|
||||
DROP INDEX `uk_gao_customer_package_request`,
|
||||
DROP INDEX `idx_gao_customer_package_payment`,
|
||||
DROP COLUMN `purchase_event_record_id`,
|
||||
DROP COLUMN `request_no`,
|
||||
DROP COLUMN `sale_amount`,
|
||||
DROP COLUMN `pending_paid_amount`,
|
||||
DROP COLUMN `paid_amount`,
|
||||
DROP COLUMN `refunded_amount`,
|
||||
DROP COLUMN `payment_status`,
|
||||
DROP COLUMN `refund_status`,
|
||||
DROP COLUMN `purchased_at`,
|
||||
DROP COLUMN `operator_user_id`;
|
||||
|
||||
ALTER TABLE `gao_customer_package_item`
|
||||
MODIFY COLUMN `product_id` VARCHAR(36) NOT NULL COMMENT '产品 ID',
|
||||
MODIFY COLUMN `product_unit_id` VARCHAR(36) NOT NULL COMMENT '产品单位 ID',
|
||||
MODIFY COLUMN `conversion_to_base_snapshot` DECIMAL(18,6) NOT NULL COMMENT '折算率快照',
|
||||
DROP COLUMN `delivered_quantity`;
|
||||
|
||||
DROP TABLE IF EXISTS `gao_package_delivery_item`;
|
||||
DROP TABLE IF EXISTS `gao_package_delivery`;
|
||||
@@ -27,13 +27,13 @@
|
||||
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} >= 0
|
||||
AND `reserved_quantity` + `delivered_quantity` + #{delta} <= `total_quantity`
|
||||
AND `reserved_quantity` + `fulfilled_quantity` + #{delta} <= `total_quantity`
|
||||
</update>
|
||||
<update id="updateDeliveredQuantity">
|
||||
<update id="updateFulfilledQuantity">
|
||||
UPDATE `gao_customer_package_item`
|
||||
SET `delivered_quantity` = `delivered_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
SET `fulfilled_quantity` = `fulfilled_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
AND `delivered_quantity` + #{delta} >= 0
|
||||
AND `reserved_quantity` + `delivered_quantity` + #{delta} <= `total_quantity`
|
||||
AND `fulfilled_quantity` + #{delta} >= 0
|
||||
AND `reserved_quantity` + `fulfilled_quantity` + #{delta} <= `total_quantity`
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
@@ -1,24 +1,14 @@
|
||||
<?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="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
|
||||
SELECT * FROM `gao_customer_package`
|
||||
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectByRequestNoAnyStore" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
|
||||
SELECT * FROM `gao_customer_package`
|
||||
WHERE `request_no` = #{requestNo}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<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="selectByPurchaseEventRecordId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
|
||||
<select id="selectBySalesOrderId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
|
||||
SELECT * FROM `gao_customer_package`
|
||||
WHERE `purchase_event_record_id` = #{purchaseEventRecordId}
|
||||
WHERE `sales_order_id` = #{salesOrderId} AND `deleted_at` IS NULL
|
||||
LIMIT 1
|
||||
</select>
|
||||
<sql id="queryWhere">
|
||||
@@ -26,10 +16,6 @@
|
||||
<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="paymentStatus != null">AND p.`payment_status` = #{paymentStatus}</if>
|
||||
<if test="refundStatus != null">AND p.`refund_status` = #{refundStatus}</if>
|
||||
<if test="beginAt != null">AND p.`purchased_at` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND p.`purchased_at` <= #{endAt}</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">
|
||||
@@ -44,19 +30,4 @@
|
||||
ORDER BY p.`purchased_at` DESC, p.`created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<update id="updatePendingPaidAmountDelta">
|
||||
UPDATE `gao_customer_package`
|
||||
SET `pending_paid_amount` = `pending_paid_amount` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL AND `pending_paid_amount` + #{delta} >= 0
|
||||
</update>
|
||||
<update id="updatePaidAmountDelta">
|
||||
UPDATE `gao_customer_package`
|
||||
SET `paid_amount` = `paid_amount` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL AND `paid_amount` + #{delta} >= 0
|
||||
</update>
|
||||
<update id="updateStatusIf">
|
||||
UPDATE `gao_customer_package`
|
||||
SET `status` = #{toStatus}, `cancelled_at` = #{cancelledAt}, `cancel_operator_user_id` = #{cancelOperatorUserId}, `cancel_reason` = #{cancelReason}, `refund_status` = #{refundStatus}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `status` = #{fromStatus} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
f.`deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND f.`store_id` = #{storeId}</if>
|
||||
<if test="customerPackageId != null and customerPackageId != ''">AND f.`biz_id` = #{customerPackageId}</if>
|
||||
<if test="salesOrderId != null and salesOrderId != ''">AND f.`biz_id` = #{salesOrderId}</if>
|
||||
<if test="customerId != null and customerId != ''">AND f.`customer_id` = #{customerId}</if>
|
||||
<if test="bizType != null">AND f.`biz_type` = #{bizType}</if>
|
||||
<if test="operationType != null">AND f.`operation_type` = #{operationType}</if>
|
||||
<if test="status != null">AND f.`status` = #{status}</if>
|
||||
<if test="beginAt != null">AND f.`occurred_at` >= #{beginAt}</if>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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.GaoOrderFulfillmentItemMapper">
|
||||
<select id="selectByFulfillmentId" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillmentItem">
|
||||
SELECT * FROM `gao_order_fulfillment_item`
|
||||
WHERE `fulfillment_id` = #{fulfillmentId}
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
<select id="selectByFulfillmentIdForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillmentItem">
|
||||
SELECT * FROM `gao_order_fulfillment_item`
|
||||
WHERE `fulfillment_id` = #{fulfillmentId}
|
||||
ORDER BY `created_at`
|
||||
FOR UPDATE
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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.GaoOrderFulfillmentMapper">
|
||||
<select id="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectById" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE `id` = #{id}
|
||||
</select>
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE `id` = #{id}
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<select id="selectBySalesOrderId" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE `sales_order_id` = #{salesOrderId}
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
<select id="selectBySourceFulfillmentId" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE `source_fulfillment_id` = #{sourceFulfillmentId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="countPendingBySalesOrderId" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_order_fulfillment`
|
||||
WHERE `sales_order_id` = #{salesOrderId} AND `status` IN ('WAITING_STOCK', 'PENDING')
|
||||
</select>
|
||||
<sql id="queryWhere">
|
||||
1 = 1
|
||||
<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` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND `delivered_at` <= #{endAt}</if>
|
||||
</sql>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_order_fulfillment` WHERE <include refid="queryWhere"/>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment">
|
||||
SELECT * FROM `gao_order_fulfillment`
|
||||
WHERE <include refid="queryWhere"/>
|
||||
ORDER BY `delivered_at` DESC, `created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<update id="updateStatus">
|
||||
UPDATE `gao_order_fulfillment`
|
||||
SET `status` = #{status}, `verifier_user_id` = #{verifierUserId}, `verified_at` = #{verifiedAt},
|
||||
`reason` = #{reason}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -1,20 +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.GaoPackageDeliveryItemMapper">
|
||||
<select id="selectByDeliveryId" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDeliveryItem">
|
||||
SELECT * FROM `gao_package_delivery_item`
|
||||
WHERE `delivery_id` = #{deliveryId} AND `deleted_at` IS NULL
|
||||
ORDER BY `created_at`, `id`
|
||||
</select>
|
||||
<select id="selectByDeliveryIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDeliveryItem">
|
||||
SELECT * FROM `gao_package_delivery_item`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<choose>
|
||||
<when test="deliveryIdList != null and !deliveryIdList.isEmpty()">
|
||||
AND `delivery_id` IN <foreach collection="deliveryIdList" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND FALSE</otherwise>
|
||||
</choose>
|
||||
ORDER BY `delivery_id`, `created_at`, `id`
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,55 +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.GaoPackageDeliveryMapper">
|
||||
<select id="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDelivery">
|
||||
SELECT * FROM `gao_package_delivery`
|
||||
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDelivery">
|
||||
SELECT * FROM `gao_package_delivery`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<select id="selectRevokeBySourceDeliveryId" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDelivery">
|
||||
SELECT * FROM `gao_package_delivery`
|
||||
WHERE `source_delivery_id` = #{sourceDeliveryId} AND `deleted_at` IS NULL
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="countPendingByCustomerPackageId" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_package_delivery`
|
||||
WHERE `customer_package_id` = #{customerPackageId} AND `status` = 'PENDING' AND `operation_type` = 'DELIVER' AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="countVerifiedByCustomerPackageId" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_package_delivery`
|
||||
WHERE `customer_package_id` = #{customerPackageId} AND `status` = 'VERIFIED' AND `operation_type` = 'DELIVER' AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectByCustomerPackageId" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDelivery">
|
||||
SELECT * FROM `gao_package_delivery`
|
||||
WHERE `customer_package_id` = #{customerPackageId} AND `deleted_at` IS NULL
|
||||
ORDER BY `delivered_at` DESC, `created_at` DESC
|
||||
</select>
|
||||
<sql id="queryWhere">
|
||||
d.`deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND d.`store_id` = #{storeId}</if>
|
||||
<if test="customerPackageId != null and customerPackageId != ''">AND d.`customer_package_id` = #{customerPackageId}</if>
|
||||
<if test="customerId != null and customerId != ''">AND d.`customer_id` = #{customerId}</if>
|
||||
<if test="status != null">AND d.`status` = #{status}</if>
|
||||
<if test="operationType != null">AND d.`operation_type` = #{operationType}</if>
|
||||
<if test="beginAt != null">AND d.`delivered_at` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND d.`delivered_at` <= #{endAt}</if>
|
||||
</sql>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_package_delivery` d WHERE <include refid="queryWhere"/>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPackageDelivery">
|
||||
SELECT d.* FROM `gao_package_delivery` d WHERE <include refid="queryWhere"/>
|
||||
ORDER BY d.`delivered_at` DESC, d.`created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<update id="updateStatusIf">
|
||||
UPDATE `gao_package_delivery`
|
||||
SET `status` = #{toStatus}, `verifier_user_id` = #{verifierUserId}, `verified_at` = #{verifiedAt}, `reason` = #{reason}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `status` = #{fromStatus} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.GaoProductCategoryMapper">
|
||||
<select id="selectById" resultType="com.imyeyu.api.modules.gao.entity.GaoProductCategory">
|
||||
SELECT * FROM `gao_product_category`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoProductCategory">
|
||||
SELECT * FROM `gao_product_category`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<if test="idList != null and !idList.isEmpty()">
|
||||
AND `id` IN
|
||||
<foreach collection="idList" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="idList == null or idList.isEmpty()">
|
||||
AND FALSE
|
||||
</if>
|
||||
</select>
|
||||
<update id="updateSort">
|
||||
UPDATE `gao_product_category`
|
||||
SET
|
||||
`sort` = CASE `id`
|
||||
<foreach collection="idList" item="id" index="sort" separator=" ">
|
||||
WHEN #{id} THEN #{sort}
|
||||
</foreach>
|
||||
END,
|
||||
`updated_at` = #{updatedAt}
|
||||
WHERE `deleted_at` IS NULL
|
||||
AND `id` IN
|
||||
<foreach collection="idList" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_product_category`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
|
||||
<if test="status != null">AND `status` = #{status}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND `name` LIKE CONCAT('%', #{keyword}, '%')</if>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProductCategory">
|
||||
SELECT * FROM `gao_product_category`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
|
||||
<if test="status != null">AND `status` = #{status}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND `name` LIKE CONCAT('%', #{keyword}, '%')</if>
|
||||
ORDER BY `sort`, `name`, `created_at`
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<select id="selectByStoreId" resultType="com.imyeyu.api.modules.gao.entity.GaoProductCategory">
|
||||
SELECT * FROM `gao_product_category`
|
||||
WHERE `store_id` = #{storeId} AND `deleted_at` IS NULL
|
||||
ORDER BY `sort`, `name`, `created_at`
|
||||
</select>
|
||||
<select id="selectByStoreIdAndName" resultType="com.imyeyu.api.modules.gao.entity.GaoProductCategory">
|
||||
SELECT * FROM `gao_product_category`
|
||||
WHERE `store_id` = #{storeId} AND `name` = #{name} AND `deleted_at` IS NULL
|
||||
<if test="excludeId != null">AND `id` != #{excludeId}</if>
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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.GaoProductMapper">
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_product`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
|
||||
<choose>
|
||||
<when test="categoryIdList != null and categoryIdList.size() > 0">
|
||||
AND `category_id` IN <foreach collection="categoryIdList" item="categoryIdItem" separator="," open="(" close=")">#{categoryIdItem}</foreach>
|
||||
</when>
|
||||
<when test="categoryId != null and categoryId != ''">AND `category_id` = #{categoryId}</when>
|
||||
</choose>
|
||||
<if test="status != null">AND `status` = #{status}</if>
|
||||
<if test="productType != null">AND `product_type` = #{productType}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%'))</if>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
|
||||
SELECT * FROM `gao_product`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
|
||||
<choose>
|
||||
<when test="categoryIdList != null and categoryIdList.size() > 0">
|
||||
AND `category_id` IN <foreach collection="categoryIdList" item="categoryIdItem" separator="," open="(" close=")">#{categoryIdItem}</foreach>
|
||||
</when>
|
||||
<when test="categoryId != null and categoryId != ''">AND `category_id` = #{categoryId}</when>
|
||||
</choose>
|
||||
<if test="status != null">AND `status` = #{status}</if>
|
||||
<if test="productType != null">AND `product_type` = #{productType}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%'))</if>
|
||||
ORDER BY `sort`, `name`, `code`, `created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<select id="selectByStoreIdAndCode" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
|
||||
SELECT * FROM `gao_product`
|
||||
WHERE `store_id` = #{storeId} AND `code` = #{code} AND `deleted_at` IS NULL
|
||||
<if test="excludeId != null">AND `id` != #{excludeId}</if>
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
|
||||
SELECT * FROM `gao_product`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
FOR UPDATE
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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.GaoProductStockMapper">
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStock">
|
||||
SELECT * FROM `gao_product_stock`
|
||||
WHERE `store_id` = #{storeId} AND `product_id` = #{productId}
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<select id="selectByStoreIdAndProductId" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStock">
|
||||
SELECT * FROM `gao_product_stock`
|
||||
WHERE `store_id` = #{storeId} AND `product_id` = #{productId}
|
||||
</select>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM `gao_product_stock` s
|
||||
INNER JOIN `gao_product` p ON p.`id` = s.`product_id` AND p.`deleted_at` IS NULL
|
||||
WHERE 1 = 1
|
||||
<if test="storeId != null and storeId != ''">AND s.`store_id` = #{storeId}</if>
|
||||
<if test="productId != null and productId != ''">AND s.`product_id` = #{productId}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%'))</if>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProductStock">
|
||||
SELECT s.*
|
||||
FROM `gao_product_stock` s
|
||||
INNER JOIN `gao_product` p ON p.`id` = s.`product_id` AND p.`deleted_at` IS NULL
|
||||
WHERE 1 = 1
|
||||
<if test="storeId != null and storeId != ''">AND s.`store_id` = #{storeId}</if>
|
||||
<if test="productId != null and productId != ''">AND s.`product_id` = #{productId}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND (p.`code` LIKE CONCAT('%', #{keyword}, '%') OR p.`name` LIKE CONCAT('%', #{keyword}, '%'))</if>
|
||||
ORDER BY p.`sort`, p.`name`, p.`code`
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<insert id="insertIgnore">
|
||||
INSERT IGNORE INTO `gao_product_stock`
|
||||
(`id`, `store_id`, `product_id`, `on_hand_quantity`, `reserved_quantity`, `updated_by`, `created_at`)
|
||||
VALUES
|
||||
(#{id}, #{storeId}, #{productId}, #{onHandQuantity}, #{reservedQuantity}, #{updatedBy}, #{createdAt})
|
||||
</insert>
|
||||
<update id="updateQuantity">
|
||||
UPDATE `gao_product_stock`
|
||||
SET `on_hand_quantity` = `on_hand_quantity` + #{onHandDelta},
|
||||
`reserved_quantity` = `reserved_quantity` + #{reservedDelta},
|
||||
`updated_by` = #{updatedBy},
|
||||
`updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id}
|
||||
AND `on_hand_quantity` + #{onHandDelta} >= 0
|
||||
AND `reserved_quantity` + #{reservedDelta} >= 0
|
||||
AND `reserved_quantity` + #{reservedDelta} <= `on_hand_quantity` + #{onHandDelta}
|
||||
</update>
|
||||
<update id="reserve">
|
||||
UPDATE `gao_product_stock`
|
||||
SET `reserved_quantity` = `reserved_quantity` + #{quantity}, `updated_by` = #{updatedBy}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `reserved_quantity` + #{quantity} <= `on_hand_quantity`
|
||||
</update>
|
||||
<update id="release">
|
||||
UPDATE `gao_product_stock`
|
||||
SET `reserved_quantity` = `reserved_quantity` - #{quantity}, `updated_by` = #{updatedBy}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `reserved_quantity` >= #{quantity}
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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.GaoProductUnitMapper">
|
||||
<resultMap id="unitResultMap" type="com.imyeyu.api.modules.gao.entity.GaoProductUnit">
|
||||
<id column="id" property="id"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="conversion_to_base" property="conversionToBase"/>
|
||||
<result column="is_base" property="isBase"/>
|
||||
<result column="allow_purchase" property="allowPurchase"/>
|
||||
<result column="allow_sale" property="allowSale"/>
|
||||
<result column="sort" property="sort"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
<result column="deleted_at" property="deletedAt"/>
|
||||
</resultMap>
|
||||
<select id="selectByProductId" resultMap="unitResultMap">
|
||||
SELECT * FROM `gao_product_unit`
|
||||
WHERE `product_id` = #{productId} AND `deleted_at` IS NULL
|
||||
ORDER BY `sort`, `created_at`
|
||||
</select>
|
||||
<select id="selectByProductIdList" resultMap="unitResultMap">
|
||||
SELECT * FROM `gao_product_unit`
|
||||
WHERE `deleted_at` IS NULL
|
||||
<choose>
|
||||
<when test="productIdList != null and !productIdList.isEmpty()">
|
||||
AND `product_id` IN <foreach collection="productIdList" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND FALSE</otherwise>
|
||||
</choose>
|
||||
ORDER BY `product_id`, `sort`, `created_at`
|
||||
</select>
|
||||
<select id="selectForUpdate" resultMap="unitResultMap">
|
||||
SELECT * FROM `gao_product_unit`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<update id="updateUnit">
|
||||
UPDATE `gao_product_unit`
|
||||
SET `name` = #{name}, `conversion_to_base` = #{conversionToBase}, `is_base` = #{isBase},
|
||||
`allow_purchase` = #{allowPurchase}, `allow_sale` = #{allowSale}, `sort` = #{sort},
|
||||
`updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `product_id` = #{productId} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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.GaoSalesOrderItemMapper">
|
||||
<select id="selectBySalesOrderId" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrderItem">
|
||||
SELECT * FROM `gao_sales_order_item`
|
||||
WHERE `sales_order_id` = #{salesOrderId} AND `deleted_at` IS NULL
|
||||
ORDER BY `sort`, `created_at`
|
||||
</select>
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrderItem">
|
||||
SELECT * FROM `gao_sales_order_item`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<update id="updateReservedQuantity">
|
||||
UPDATE `gao_sales_order_item`
|
||||
SET `reserved_quantity` = `reserved_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `reserved_quantity` + #{delta} >= 0
|
||||
AND `fulfilled_quantity` + `reserved_quantity` + #{delta} <= `quantity`
|
||||
</update>
|
||||
<update id="updateFulfilledQuantity">
|
||||
UPDATE `gao_sales_order_item`
|
||||
SET `fulfilled_quantity` = `fulfilled_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `fulfilled_quantity` + #{delta} >= 0
|
||||
AND `fulfilled_quantity` + #{delta} <= `quantity`
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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.GaoSalesOrderMapper">
|
||||
<select id="selectByRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrder">
|
||||
SELECT * FROM `gao_sales_order`
|
||||
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo} AND `deleted_at` IS NULL
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrder">
|
||||
SELECT * FROM `gao_sales_order`
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
FOR UPDATE
|
||||
</select>
|
||||
<sql id="queryWhere">
|
||||
o.`deleted_at` IS NULL
|
||||
<if test="storeId != null and storeId != ''">AND o.`store_id` = #{storeId}</if>
|
||||
<if test="customerId != null and customerId != ''">AND o.`customer_id` = #{customerId}</if>
|
||||
<if test="orderType != null">AND o.`order_type` = #{orderType}</if>
|
||||
<if test="status != null">AND o.`status` = #{status}</if>
|
||||
<if test="paymentStatus != null">AND o.`payment_status` = #{paymentStatus}</if>
|
||||
<if test="fulfilledButUnpaid != null and fulfilledButUnpaid">AND o.`status` = 'FULFILLED' AND o.`paid_amount` < o.`sale_amount`</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">AND (o.`order_no` LIKE CONCAT('%', #{keyword}, '%') OR c.`name` LIKE CONCAT('%', #{keyword}, '%') OR c.`code` LIKE CONCAT('%', #{keyword}, '%'))</if>
|
||||
<if test="beginAt != null">AND o.`purchased_at` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND o.`purchased_at` <= #{endAt}</if>
|
||||
</sql>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_sales_order` o LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id` WHERE <include refid="queryWhere"/>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoSalesOrder">
|
||||
SELECT o.* FROM `gao_sales_order` o LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id` WHERE <include refid="queryWhere"/>
|
||||
ORDER BY o.`purchased_at` DESC, o.`created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<update id="updatePayment">
|
||||
UPDATE `gao_sales_order`
|
||||
SET `pending_paid_amount` = #{pendingPaidAmount}, `paid_amount` = #{paidAmount}, `refunded_amount` = #{refundedAmount},
|
||||
`payment_status` = #{paymentStatus}, `refund_status` = #{refundStatus}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
<update id="cancelIf">
|
||||
UPDATE `gao_sales_order`
|
||||
SET `status` = #{toStatus}, `cancelled_at` = #{cancelledAt}, `cancel_operator_user_id` = #{cancelOperatorUserId},
|
||||
`cancel_reason` = #{cancelReason}, `refund_status` = #{refundStatus}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `status` = #{fromStatus} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
<update id="updateSourceEventRecordId">
|
||||
UPDATE `gao_sales_order`
|
||||
SET `source_event_record_id` = #{sourceEventRecordId}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `source_event_record_id` IS NULL AND `deleted_at` IS NULL
|
||||
</update>
|
||||
<update id="updateStatus">
|
||||
UPDATE `gao_sales_order`
|
||||
SET `status` = #{status}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
|
||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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`
|
||||
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`
|
||||
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`
|
||||
WHERE `biz_type` = #{bizType} AND `biz_id` = #{bizId} AND `product_id` = #{productId} AND `operation_type` = #{operationType}
|
||||
ORDER BY `occurred_at`, `id`
|
||||
LIMIT 1
|
||||
</select>
|
||||
<sql id="queryWhere">
|
||||
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="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>
|
||||
<if test="beginAt != null">AND r.`occurred_at` >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND r.`occurred_at` <= #{endAt}</if>
|
||||
</sql>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM `gao_stock_record` r 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"/>
|
||||
ORDER BY r.`occurred_at` DESC, r.`id` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user