fix: 为日计划调度增加排他领取

This commit is contained in:
zhouz
2026-08-14 14:51:13 +08:00
parent 5804c4613a
commit a9a2b868df
9 changed files with 289 additions and 19 deletions

View File

@@ -38,7 +38,9 @@ CREATE TABLE IF NOT EXISTS `lms_daily_plan` (
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`daily_plan_id`),
UNIQUE KEY `uk_plan_code_tenant` (`plan_code`, `tenant_id`),
UNIQUE KEY `uk_erp_order_code_tenant` (`erp_order_code`, `tenant_id`)
UNIQUE KEY `uk_erp_order_code_tenant` (`erp_order_code`, `tenant_id`),
KEY `idx_stocking_candidate` (`tenant_id`, `deleted`, `order_status`, `stocking_status`, `sort_seq`, `daily_plan_id`),
KEY `idx_sleeving_candidate` (`tenant_id`, `deleted`, `order_status`, `sleeving_status`, `sort_seq`, `daily_plan_id`)
) COMMENT='LMS日计划';
CREATE TABLE IF NOT EXISTS `lms_daily_plan_strategy` (
@@ -57,6 +59,30 @@ CREATE TABLE IF NOT EXISTS `lms_daily_plan_strategy` (
UNIQUE KEY `uk_strategy_type_tenant` (`strategy_type`, `tenant_id`)
) COMMENT='LMS日计划调度策略';
CREATE TABLE IF NOT EXISTS `lms_daily_plan_claim` (
`claim_id` bigint NOT NULL COMMENT '领取ID',
`claim_token` varchar(64) NOT NULL COMMENT '对外领取标识',
`daily_plan_id` bigint NOT NULL COMMENT '日计划ID',
`strategy_type` tinyint NOT NULL COMMENT '作业类型1备货2套管',
`claimed_qty` int NOT NULL COMMENT '本次预占数量',
`plan_version` int NOT NULL COMMENT '领取时日计划版本号',
`claim_status` tinyint NOT NULL DEFAULT 0 COMMENT '领取状态0执行中1已确认2已释放3已过期',
`active_flag` tinyint DEFAULT 1 COMMENT '有效领取唯一标记,终态置空',
`expire_time` datetime NOT NULL COMMENT '租约过期时间',
`confirmed_time` datetime DEFAULT NULL COMMENT '确认时间',
`operator` varchar(64) NOT NULL COMMENT '领取人/执行器',
`creator` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`claim_id`),
UNIQUE KEY `uk_claim_token_tenant` (`claim_token`, `tenant_id`),
UNIQUE KEY `uk_active_plan_type_tenant` (`daily_plan_id`, `strategy_type`, `active_flag`, `tenant_id`),
KEY `idx_claim_expire` (`tenant_id`, `claim_status`, `expire_time`)
) COMMENT='LMS日计划调度领取';
CREATE TABLE IF NOT EXISTS `lms_daily_plan_operation_log` (
`operation_log_id` bigint NOT NULL COMMENT '操作日志ID',
`daily_plan_id` bigint DEFAULT NULL COMMENT '日计划ID',
@@ -73,6 +99,24 @@ CREATE TABLE IF NOT EXISTS `lms_daily_plan_operation_log` (
PRIMARY KEY (`operation_log_id`)
) COMMENT='LMS日计划操作日志';
-- 兼容已执行过旧版脚本的数据库,幂等补充候选组合索引。
SET @lms_daily_plan_ddl = IF(
EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE()
AND table_name = 'lms_daily_plan' AND index_name = 'idx_stocking_candidate'),
'SELECT 1',
'ALTER TABLE lms_daily_plan ADD INDEX idx_stocking_candidate (tenant_id, deleted, order_status, stocking_status, sort_seq, daily_plan_id)');
PREPARE lms_daily_plan_stmt FROM @lms_daily_plan_ddl;
EXECUTE lms_daily_plan_stmt;
DEALLOCATE PREPARE lms_daily_plan_stmt;
SET @lms_daily_plan_ddl = IF(
EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE()
AND table_name = 'lms_daily_plan' AND index_name = 'idx_sleeving_candidate'),
'SELECT 1',
'ALTER TABLE lms_daily_plan ADD INDEX idx_sleeving_candidate (tenant_id, deleted, order_status, sleeving_status, sort_seq, daily_plan_id)');
PREPARE lms_daily_plan_stmt FROM @lms_daily_plan_ddl;
EXECUTE lms_daily_plan_stmt;
DEALLOCATE PREPARE lms_daily_plan_stmt;
-- 2093号段用于 LMS 日计划固定基础数据编码格式DP + yyyyMMdd + 4位日流水。
INSERT INTO base_code_rule
(id, rule_name, rule_code, segment_config, code_separator, letter_case, total_length,