提交
This commit is contained in:
1 parent
13e4c9530a
commit
575e63e7e8
62 files changed
+28759
-9636
No files matched your search
@@ -0,0 +1,125 @@
|
||||
-- ============================================================
|
||||
-- 渠道服务订单:多次操作流水模型迁移
|
||||
-- Date: 2026-05-24
|
||||
-- ============================================================
|
||||
|
||||
-- 1. 新增操作流水表
|
||||
DROP TABLE IF EXISTS `biz_channel_service_order_txn`;
|
||||
CREATE TABLE `biz_channel_service_order_txn` (
|
||||
`id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主键ID',
|
||||
`service_order_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '关联订单ID',
|
||||
`txn_type` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'recharge/refund/purchase/unsubscribe',
|
||||
`amount` decimal(18,2) DEFAULT NULL COMMENT '本次操作金额',
|
||||
`txn_status` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'dsx' COMMENT 'dsx待生效 dqr待财务确认 yqr已确认 yzf已作废',
|
||||
`products_json` text COLLATE utf8mb4_unicode_ci COMMENT '产品明细JSON(purchase/unsubscribe类型)',
|
||||
`remark` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '备注',
|
||||
`finance_submit_by` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '发起确认人ID',
|
||||
`finance_submit_time` datetime DEFAULT NULL COMMENT '发起确认时间',
|
||||
`finance_submit_remark` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '发起确认备注',
|
||||
`finance_submit_attachments` text COLLATE utf8mb4_unicode_ci COMMENT '发起确认附件',
|
||||
`finance_confirm_time` datetime DEFAULT NULL COMMENT '财务确认时间',
|
||||
`finance_confirm_attachments` text COLLATE utf8mb4_unicode_ci COMMENT '财务确认附件',
|
||||
`finance_remark` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '财务确认备注',
|
||||
`balance_before` decimal(18,2) DEFAULT NULL COMMENT '操作前余额(yfk类型)',
|
||||
`balance_after` decimal(18,2) DEFAULT NULL COMMENT '操作后余额(yfk类型)',
|
||||
`tenant_no` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'zkxw' COMMENT '租户编号',
|
||||
`order_num` int(11) DEFAULT NULL COMMENT '排序号',
|
||||
`create_by` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '创建人id',
|
||||
`create_dept_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '创建人部门ID',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_by` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '更新人id',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`del_flag` tinyint(4) NOT NULL DEFAULT '0' COMMENT '删除标记',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_txn_order` (`service_order_id`, `del_flag`),
|
||||
KEY `idx_txn_status` (`txn_status`, `tenant_no`, `del_flag`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='渠道服务订单操作流水';
|
||||
|
||||
-- 2. 订单主表新增汇总字段
|
||||
ALTER TABLE `biz_channel_service_order`
|
||||
ADD COLUMN `total_recharge_amount` decimal(18,2) NOT NULL DEFAULT 0.00 COMMENT '累计充值总额' AFTER `channel_agreement_id`,
|
||||
ADD COLUMN `total_refund_amount` decimal(18,2) NOT NULL DEFAULT 0.00 COMMENT '累计退款总额' AFTER `total_recharge_amount`,
|
||||
ADD COLUMN `current_balance` decimal(18,2) NOT NULL DEFAULT 0.00 COMMENT '当前余额' AFTER `total_refund_amount`;
|
||||
|
||||
-- 3. 产品持仓表新增字段
|
||||
ALTER TABLE `biz_channel_service_order_product`
|
||||
ADD COLUMN `total_buy_qty` decimal(18,4) NOT NULL DEFAULT 0.0000 COMMENT '累计购买数量' AFTER `buy_amount`,
|
||||
ADD COLUMN `total_unsubscribe_qty` decimal(18,4) NOT NULL DEFAULT 0.0000 COMMENT '累计退订数量' AFTER `total_buy_qty`,
|
||||
ADD COLUMN `current_qty` decimal(18,4) NOT NULL DEFAULT 0.0000 COMMENT '当前持有数量' AFTER `total_unsubscribe_qty`,
|
||||
ADD COLUMN `total_unsubscribe_amount` decimal(18,2) NOT NULL DEFAULT 0.00 COMMENT '累计退订金额' AFTER `current_qty`;
|
||||
|
||||
-- ============================================================
|
||||
-- 以下为数据迁移(可选执行,用于保留历史数据)
|
||||
-- ============================================================
|
||||
|
||||
-- 4. 迁移现有充值记录到流水表
|
||||
INSERT INTO `biz_channel_service_order_txn` (
|
||||
`id`, `service_order_id`, `txn_type`, `amount`, `txn_status`,
|
||||
`remark`,
|
||||
`finance_submit_by`, `finance_submit_time`, `finance_submit_remark`, `finance_submit_attachments`,
|
||||
`finance_confirm_time`, `finance_confirm_attachments`, `finance_remark`,
|
||||
`balance_before`, `balance_after`,
|
||||
`tenant_no`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`
|
||||
)
|
||||
SELECT
|
||||
REPLACE(UUID(),'-','') AS `id`,
|
||||
o.`id` AS `service_order_id`,
|
||||
'recharge' AS `txn_type`,
|
||||
o.`prepay_amount` AS `amount`,
|
||||
CASE
|
||||
WHEN o.`finance_confirm_time` IS NOT NULL THEN 'yqr'
|
||||
WHEN o.`finance_submit_time` IS NOT NULL THEN 'dqr'
|
||||
ELSE 'dsx'
|
||||
END AS `txn_status`,
|
||||
o.`remark`,
|
||||
o.`finance_submit_by`, o.`finance_submit_time`, o.`finance_submit_remark`, o.`finance_submit_attachments`,
|
||||
o.`finance_confirm_time`, o.`finance_confirm_attachments`, o.`finance_remark`,
|
||||
o.`balance_before`, o.`balance_after`,
|
||||
o.`tenant_no`, o.`create_by`, o.`create_dept_id`, o.`create_time`, o.`update_by`, o.`update_time`, o.`del_flag`
|
||||
FROM `biz_channel_service_order` o
|
||||
WHERE o.`order_type` = 'yfk' AND (o.`finance_submit_time` IS NOT NULL OR o.`prepay_amount` IS NOT NULL);
|
||||
|
||||
-- 5. 迁移退款记录到流水表
|
||||
INSERT INTO `biz_channel_service_order_txn` (
|
||||
`id`, `service_order_id`, `txn_type`, `amount`, `txn_status`,
|
||||
`remark`,
|
||||
`finance_submit_by`, `finance_submit_time`, `finance_submit_remark`, `finance_submit_attachments`,
|
||||
`finance_confirm_time`, `finance_confirm_attachments`, `finance_remark`,
|
||||
`tenant_no`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`
|
||||
)
|
||||
SELECT
|
||||
REPLACE(UUID(),'-','') AS `id`,
|
||||
o.`id` AS `service_order_id`,
|
||||
'refund' AS `txn_type`,
|
||||
o.`refund_amount` AS `amount`,
|
||||
CASE
|
||||
WHEN o.`refund_finance_confirm_time` IS NOT NULL THEN 'yqr'
|
||||
ELSE 'dqr'
|
||||
END AS `txn_status`,
|
||||
o.`refund_remark` AS `remark`,
|
||||
o.`refund_apply_by` AS `finance_submit_by`,
|
||||
o.`refund_apply_time` AS `finance_submit_time`,
|
||||
o.`refund_remark` AS `finance_submit_remark`,
|
||||
o.`refund_attachments` AS `finance_submit_attachments`,
|
||||
o.`refund_finance_confirm_time` AS `finance_confirm_time`,
|
||||
o.`refund_finance_confirm_attachments` AS `finance_confirm_attachments`,
|
||||
o.`refund_finance_remark` AS `finance_remark`,
|
||||
o.`tenant_no`, o.`refund_apply_by` AS `create_by`, o.`create_dept_id`,
|
||||
COALESCE(o.`refund_apply_time`, o.`update_time`) AS `create_time`,
|
||||
o.`update_by`, o.`update_time`, o.`del_flag`
|
||||
FROM `biz_channel_service_order` o
|
||||
WHERE o.`refund_amount` IS NOT NULL AND o.`refund_amount` > 0;
|
||||
|
||||
-- 6. 回填主表汇总字段(yfk类型)
|
||||
UPDATE `biz_channel_service_order` o
|
||||
SET
|
||||
`total_recharge_amount` = COALESCE(o.`prepay_amount`, 0),
|
||||
`total_refund_amount` = COALESCE(o.`refund_amount`, 0),
|
||||
`current_balance` = COALESCE(o.`prepay_amount`, 0) - COALESCE(o.`refund_amount`, 0)
|
||||
WHERE o.`order_type` = 'yfk' AND o.`prepay_amount` IS NOT NULL;
|
||||
|
||||
-- 7. 回填产品持仓表的累计字段
|
||||
UPDATE `biz_channel_service_order_product` p
|
||||
SET
|
||||
`total_buy_qty` = COALESCE(p.`buy_qty`, 0),
|
||||
`current_qty` = COALESCE(p.`buy_qty`, 0);
|
||||
@@ -1,59 +0,0 @@
|
||||
-- ============================================================
|
||||
-- 工单表合并迁移:biz_temp_* → 主表 + work_order_type
|
||||
-- Date: 2026-05-24
|
||||
-- 执行顺序:先本脚本,再 work_order_unification_phase1.sql
|
||||
-- 适用:仍保留 biz_temp_qc_work_order / biz_temp_production_work_order 的旧库
|
||||
-- ============================================================
|
||||
|
||||
-- 1. biz_qc_work_order: 加 work_order_type(若已存在则跳过,需 MySQL 8+ 或手动检查)
|
||||
-- ALTER TABLE biz_qc_work_order
|
||||
-- ADD COLUMN work_order_type VARCHAR(20) NOT NULL DEFAULT 'inbound'
|
||||
-- COMMENT '工单类型: inbound=入库, temporary=临时' AFTER work_order_no;
|
||||
|
||||
-- 2. reception 关联字段改为可空(临时工单不需要)
|
||||
-- ALTER TABLE biz_qc_work_order
|
||||
-- MODIFY COLUMN reception_id VARCHAR(64) NULL,
|
||||
-- MODIFY COLUMN protocol_sample_id VARCHAR(64) NULL,
|
||||
-- MODIFY COLUMN collection_protocol_id VARCHAR(64) NULL,
|
||||
-- MODIFY COLUMN reception_source VARCHAR(20) NULL DEFAULT 'cell_storage';
|
||||
|
||||
-- 3. 迁移临时质检工单(按 id 去重,避免重复执行)
|
||||
INSERT INTO biz_qc_work_order (
|
||||
id, work_order_no, work_order_type, work_order_status,
|
||||
has_lab, has_third_party, third_party_fee_total,
|
||||
configured_time, configured_by,
|
||||
tenant_no, order_num, remark,
|
||||
create_by, create_dept_id, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
SELECT
|
||||
t.id, t.work_order_no, 'temporary', t.work_order_status,
|
||||
t.has_lab, t.has_third_party, t.third_party_fee_total,
|
||||
t.configured_time, t.configured_by,
|
||||
t.tenant_no, t.order_num, t.remark,
|
||||
t.create_by, t.create_dept_id, t.create_time, t.update_by, t.update_time, t.del_flag
|
||||
FROM biz_temp_qc_work_order t
|
||||
WHERE NOT EXISTS (SELECT 1 FROM biz_qc_work_order m WHERE m.id = t.id);
|
||||
|
||||
-- 4. biz_production_work_order: 加 work_order_type / configured_time / configured_by(若未加请手动 ALTER)
|
||||
-- ALTER TABLE biz_production_work_order ADD COLUMN work_order_type ...
|
||||
-- ALTER TABLE biz_production_work_order ADD COLUMN configured_time DATETIME NULL ...
|
||||
-- ALTER TABLE biz_production_work_order ADD COLUMN configured_by VARCHAR(64) NULL ...
|
||||
|
||||
-- 5. 迁移临时生产工单
|
||||
INSERT INTO biz_production_work_order (
|
||||
id, work_order_no, work_order_type, work_order_status,
|
||||
configured_time, configured_by,
|
||||
tenant_no, order_num, remark,
|
||||
create_by, create_dept_id, create_time, update_by, update_time, del_flag
|
||||
)
|
||||
SELECT
|
||||
t.id, t.work_order_no, 'temporary', t.work_order_status,
|
||||
t.configured_time, t.configured_by,
|
||||
t.tenant_no, t.order_num, t.remark,
|
||||
t.create_by, t.create_dept_id, t.create_time, t.update_by, t.update_time, t.del_flag
|
||||
FROM biz_temp_production_work_order t
|
||||
WHERE NOT EXISTS (SELECT 1 FROM biz_production_work_order m WHERE m.id = t.id);
|
||||
|
||||
-- 6. 删除临时表(确认迁移成功后执行)
|
||||
DROP TABLE IF EXISTS biz_temp_qc_work_order;
|
||||
DROP TABLE IF EXISTS biz_temp_production_work_order;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- 生产任务:生产结论(cg=成功 sb=失败)
|
||||
ALTER TABLE biz_production_task
|
||||
ADD COLUMN conclusion VARCHAR(16) NULL
|
||||
COMMENT '生产结论 cg=成功 sb=失败'
|
||||
AFTER completed_time;
|
||||
@@ -1,7 +0,0 @@
|
||||
-- ============================================================
|
||||
-- 临时质检工单关联细胞产品(质检对象)
|
||||
-- Date: 2026-05-24
|
||||
-- ============================================================
|
||||
|
||||
ALTER TABLE biz_qc_work_order
|
||||
ADD COLUMN cell_product_id VARCHAR(64) DEFAULT NULL COMMENT '质检对象-细胞产品ID' AFTER qc_biz_type;
|
||||
@@ -1,47 +0,0 @@
|
||||
-- ============================================================
|
||||
-- 工单融合 Phase 1:菜单收口 + 数据修正 + 删除废弃临时表
|
||||
-- Date: 2026-05-24
|
||||
--
|
||||
-- 执行顺序:
|
||||
-- 1) 若库中仍有 biz_temp_* 表 → 先执行 merge_work_order_tables.sql
|
||||
-- 2) 再执行本脚本
|
||||
--
|
||||
-- 说明:zkxw.sql 全量基线已无 biz_temp_* 表;本脚本 DROP 用于清理历史库残留。
|
||||
-- ============================================================
|
||||
|
||||
-- 1. 菜单重命名与软删临时工单菜单
|
||||
UPDATE sys_menu SET menu_name = '质检工单', update_time = NOW()
|
||||
WHERE id = '70000000000000000000000000000007' AND del_flag = 0;
|
||||
|
||||
UPDATE sys_menu SET menu_name = '生产工单', update_time = NOW()
|
||||
WHERE id = '90000000000000000000000000000011' AND del_flag = 0;
|
||||
|
||||
UPDATE sys_menu SET del_flag = 1, update_time = NOW()
|
||||
WHERE id IN (
|
||||
'70000000000000000000000000000012',
|
||||
'90000000000000000000000000000110'
|
||||
) AND del_flag = 0;
|
||||
|
||||
-- 2. 临时工单 reception_id 空串修正为 NULL(避免 uk_qc_wo_reception 冲突)
|
||||
UPDATE biz_qc_work_order
|
||||
SET reception_id = NULL,
|
||||
protocol_sample_id = NULL,
|
||||
collection_protocol_id = NULL,
|
||||
update_time = NOW()
|
||||
WHERE work_order_type = 'temporary'
|
||||
AND del_flag = 0
|
||||
AND (reception_id = '' OR reception_id IS NULL);
|
||||
|
||||
UPDATE biz_production_work_order
|
||||
SET reception_id = NULL,
|
||||
protocol_sample_id = NULL,
|
||||
collection_protocol_id = NULL,
|
||||
update_time = NOW()
|
||||
WHERE work_order_type = 'temporary'
|
||||
AND del_flag = 0
|
||||
AND (reception_id = '' OR reception_id IS NULL);
|
||||
|
||||
-- 3. 删除已废弃的临时工单表(ORM/代码已不再使用)
|
||||
-- 若表内仍有未迁移数据,请先执行 merge_work_order_tables.sql 再 DROP
|
||||
DROP TABLE IF EXISTS biz_temp_qc_work_order;
|
||||
DROP TABLE IF EXISTS biz_temp_production_work_order;
|
||||
+270
-82
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user