账单bug修复,以及加入转单号功能
This commit is contained in:
@@ -76,6 +76,7 @@ CREATE TABLE IF NOT EXISTS ar_bill_detail (
|
||||
detail_no INT(11) NOT NULL COMMENT '账单内顺序号',
|
||||
order_no VARCHAR(64) NOT NULL COMMENT '订单号快照',
|
||||
tracking_no VARCHAR(64) DEFAULT NULL COMMENT '运单号快照',
|
||||
transfer_no VARCHAR(64) DEFAULT NULL COMMENT '转单号快照',
|
||||
receive_time DATETIME DEFAULT NULL COMMENT '收件或入库时间',
|
||||
product_code VARCHAR(50) NOT NULL COMMENT '产品代码快照',
|
||||
product_name VARCHAR(100) DEFAULT NULL COMMENT '产品名称快照',
|
||||
@@ -98,6 +99,7 @@ CREATE TABLE IF NOT EXISTS ar_bill_detail (
|
||||
UNIQUE KEY uk_ar_bill_detail_source (ar_bill_id, prc_order_bill_id),
|
||||
UNIQUE KEY uk_ar_bill_detail_no (ar_bill_id, detail_no),
|
||||
KEY idx_ar_bill_detail_source (prc_order_bill_id),
|
||||
KEY idx_ar_bill_detail_bill_transfer_no (ar_bill_id, transfer_no),
|
||||
CONSTRAINT fk_ar_bill_detail_bill FOREIGN KEY (ar_bill_id) REFERENCES ar_bill (ar_bill_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单订单快照';
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
-- 应收账单转单号快照迁移
|
||||
-- 适用于已经执行过 ar/ar_bill.sql 的存量数据库。
|
||||
-- 本脚本可重复执行,不删除账单明细,不覆盖已经存在的转单号快照。
|
||||
SET NAMES utf8mb4;
|
||||
SET @db_name := DATABASE();
|
||||
|
||||
-- 1. 账单明细保存生成账单时的转单号快照。
|
||||
SET @has_transfer_no := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db_name
|
||||
AND TABLE_NAME = 'ar_bill_detail'
|
||||
AND COLUMN_NAME = 'transfer_no'
|
||||
);
|
||||
SET @sql := IF(@has_transfer_no = 0,
|
||||
'ALTER TABLE ar_bill_detail ADD COLUMN transfer_no VARCHAR(64) DEFAULT NULL COMMENT ''转单号快照'' AFTER tracking_no',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 2. 详情按账单查询转单号时使用组合索引。
|
||||
SET @has_transfer_index := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @db_name
|
||||
AND TABLE_NAME = 'ar_bill_detail'
|
||||
AND INDEX_NAME = 'idx_ar_bill_detail_bill_transfer_no'
|
||||
);
|
||||
SET @sql := IF(@has_transfer_index = 0,
|
||||
'ALTER TABLE ar_bill_detail ADD KEY idx_ar_bill_detail_bill_transfer_no (ar_bill_id, transfer_no)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 3. 历史数据尽力回填,仅填充空值,不覆盖账单生成时已经保存的快照。
|
||||
-- 如果来源订单后续修改过转单号,回填值仅代表当前来源表值,不能视为严格历史值。
|
||||
UPDATE ar_bill_detail d
|
||||
JOIN prc_order_bill p ON p.bill_id = d.prc_order_bill_id
|
||||
SET d.transfer_no = p.transfer_no
|
||||
WHERE d.transfer_no IS NULL
|
||||
AND p.transfer_no IS NOT NULL;
|
||||
|
||||
-- 4. 执行后核验字段和回填数量。
|
||||
SELECT
|
||||
COUNT(*) AS detail_count,
|
||||
SUM(CASE WHEN transfer_no IS NOT NULL AND TRIM(transfer_no) <> '' THEN 1 ELSE 0 END) AS transfer_no_count
|
||||
FROM ar_bill_detail;
|
||||
@@ -0,0 +1,99 @@
|
||||
-- ================================================================
|
||||
-- BMS 应收账单导出模板恢复脚本
|
||||
--
|
||||
-- 用途:恢复应收账单导出功能使用的内置默认模板配置。
|
||||
-- 特点:
|
||||
-- 1. 可重复执行,不删除现有模板数据。
|
||||
-- 2. 模板表不存在时自动创建;模板记录已存在时不会重复插入。
|
||||
-- 3. storage_key 必须与后端 resources 下的模板路径一致。
|
||||
-- ================================================================
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 1. 创建导出模板表(表已存在时不会重复创建)
|
||||
CREATE TABLE IF NOT EXISTS ar_export_template (
|
||||
template_id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '导出模板ID',
|
||||
template_code VARCHAR(50) NOT NULL COMMENT '模板编码,例如 AR_CUSTOMER_BILL',
|
||||
template_name VARCHAR(100) NOT NULL COMMENT '模板名称',
|
||||
business_type VARCHAR(50) NOT NULL COMMENT '业务类型,例如 AR_BILL',
|
||||
template_version VARCHAR(50) NOT NULL COMMENT '模板版本,已启用版本不可覆盖',
|
||||
storage_type VARCHAR(20) NOT NULL DEFAULT 'CLASSPATH' COMMENT '存储类型:CLASSPATH=应用内置资源,FILE=服务器文件,OSS=对象存储,MINIO=MinIO对象存储',
|
||||
storage_key VARCHAR(500) NOT NULL COMMENT '模板文件存储Key或classpath资源路径',
|
||||
file_hash VARCHAR(128) DEFAULT NULL COMMENT '模板文件SHA-256校验值',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'ENABLED' COMMENT '状态:ENABLED=启用,DISABLED=停用',
|
||||
is_default CHAR(1) NOT NULL DEFAULT '0' COMMENT '是否默认模板:1是0否',
|
||||
effective_start DATE DEFAULT NULL COMMENT '生效开始日期',
|
||||
effective_end DATE DEFAULT NULL COMMENT '生效结束日期',
|
||||
remark VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
create_by VARCHAR(64) NOT NULL COMMENT '创建人',
|
||||
create_time DATETIME NOT NULL COMMENT '创建时间',
|
||||
update_by VARCHAR(64) DEFAULT NULL COMMENT '更新人',
|
||||
update_time DATETIME DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (template_id),
|
||||
UNIQUE KEY uk_ar_export_template_code_version (business_type, template_code, template_version),
|
||||
KEY idx_ar_export_template_default (business_type, status, is_default, effective_start, effective_end)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单导出模板管理';
|
||||
|
||||
-- 2. 恢复系统内置的应收账单默认模板
|
||||
-- 模板文件位置:
|
||||
-- bms-back/ruoyi-system/src/main/resources/templates/ar/ar_bill_template.xlsx
|
||||
INSERT INTO ar_export_template (
|
||||
template_code,
|
||||
template_name,
|
||||
business_type,
|
||||
template_version,
|
||||
storage_type,
|
||||
storage_key,
|
||||
file_hash,
|
||||
status,
|
||||
is_default,
|
||||
effective_start,
|
||||
effective_end,
|
||||
remark,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
)
|
||||
SELECT
|
||||
'AR_CUSTOMER_BILL',
|
||||
'应收账单默认模板',
|
||||
'AR_BILL',
|
||||
'1.0',
|
||||
'CLASSPATH',
|
||||
'templates/ar/ar_bill_template.xlsx',
|
||||
'735002ac3561e0579b724c0612a2c5ce2d6725bc7fd39c450b0aeff70911a45e',
|
||||
'ENABLED',
|
||||
'1',
|
||||
NULL,
|
||||
NULL,
|
||||
'系统内置默认模板',
|
||||
'system',
|
||||
NOW(),
|
||||
'system',
|
||||
NOW()
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM ar_export_template
|
||||
WHERE business_type = 'AR_BILL'
|
||||
AND template_code = 'AR_CUSTOMER_BILL'
|
||||
AND template_version = '1.0'
|
||||
);
|
||||
|
||||
-- 3. 执行后核验:应返回 1 条启用的默认模板记录
|
||||
SELECT
|
||||
template_id,
|
||||
template_code,
|
||||
template_name,
|
||||
business_type,
|
||||
template_version,
|
||||
storage_type,
|
||||
storage_key,
|
||||
status,
|
||||
is_default,
|
||||
file_hash
|
||||
FROM ar_export_template
|
||||
WHERE business_type = 'AR_BILL'
|
||||
AND template_code = 'AR_CUSTOMER_BILL'
|
||||
AND template_version = '1.0';
|
||||
Reference in New Issue
Block a user