🚚 重命名应收账单明细导出记录表

This commit is contained in:
caojia
2026-10-18 22:41:31 +08:00
parent 3cf85af180
commit a48b40c649
5 changed files with 118 additions and 14 deletions
@@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
export_by, export_by,
export_time, export_time,
remark remark
from ar_bill_export from ar_bill_detail_export
</sql> </sql>
<select id="selectByBillId" parameterType="long" resultMap="ArBillExportResult"> <select id="selectByBillId" parameterType="long" resultMap="ArBillExportResult">
@@ -68,7 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<insert id="insert" parameterType="ArBillExport" useGeneratedKeys="true" keyProperty="exportId"> <insert id="insert" parameterType="ArBillExport" useGeneratedKeys="true" keyProperty="exportId">
insert into ar_bill_export ( insert into ar_bill_detail_export (
ar_bill_id, file_name, file_type, template_id, template_code, template_version, ar_bill_id, file_name, file_type, template_id, template_code, template_version,
template_storage_type, template_storage_key, template_hash, storage_key, template_storage_type, template_storage_key, template_hash, storage_key,
file_size, file_hash, row_count, export_status, export_by, export_time, remark file_size, file_hash, row_count, export_status, export_by, export_time, remark
@@ -80,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert> </insert>
<update id="markSuccess" parameterType="ArBillExport"> <update id="markSuccess" parameterType="ArBillExport">
update ar_bill_export update ar_bill_detail_export
set storage_key = #{storageKey}, set storage_key = #{storageKey},
file_size = #{fileSize}, file_size = #{fileSize},
file_hash = #{fileHash}, file_hash = #{fileHash},
@@ -90,13 +90,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<update id="markFailed"> <update id="markFailed">
update ar_bill_export update ar_bill_detail_export
set export_status = 'FAILED', remark = #{remark} set export_status = 'FAILED', remark = #{remark}
where export_id = #{exportId} and export_status = 'PROCESSING' where export_id = #{exportId} and export_status = 'PROCESSING'
</update> </update>
<update id="markExpiredProcessingAsFailed"> <update id="markExpiredProcessingAsFailed">
update ar_bill_export update ar_bill_detail_export
set export_status = 'FAILED', remark = #{remark} set export_status = 'FAILED', remark = #{remark}
where export_status = 'PROCESSING' and export_time &lt; #{expiredBefore} where export_status = 'PROCESSING' and export_time &lt; #{expiredBefore}
</update> </update>
@@ -38,7 +38,7 @@
l.operation_source, l.request_id, l.trace_id, l.result, l.error_message, l.client_ip, l.create_time l.operation_source, l.request_id, l.trace_id, l.result, l.error_message, l.client_ip, l.create_time
from ar_bill_log l from ar_bill_log l
left join ar_bill b on b.ar_bill_id = l.ar_bill_id left join ar_bill b on b.ar_bill_id = l.ar_bill_id
left join ar_bill_export e on e.export_id = case when l.object_type = 'EXPORT' then cast(l.object_id as left join ar_bill_detail_export e on e.export_id = case when l.object_type = 'EXPORT' then cast(l.object_id as
unsigned) end unsigned) end
left join ar_balance_writeoff bw on bw.writeoff_id = case when l.object_type = 'BALANCE_WRITEOFF' then left join ar_balance_writeoff bw on bw.writeoff_id = case when l.object_type = 'BALANCE_WRITEOFF' then
cast(l.object_id as unsigned) end cast(l.object_id as unsigned) end
+1 -1
View File
@@ -2,7 +2,7 @@
新生成的应收账单导出 Excel 上传到 `lionqueen` Bucket。 新生成的应收账单导出 Excel 上传到 `lionqueen` Bucket。
生产路径为 `bms/prod/ar/bill/yyyy/MM/dd/<uuid>.xlsx`,本地、测试路径为 生产路径为 `bms/prod/ar/bill/yyyy/MM/dd/<uuid>.xlsx`,本地、测试路径为
`bms/test/ar/bill/yyyy/MM/dd/<uuid>.xlsx`。数据库 `ar_bill_export.storage_key` `bms/test/ar/bill/yyyy/MM/dd/<uuid>.xlsx`。数据库 `ar_bill_detail_export.storage_key`
保存包含完整对象路径的 `oss://lionqueen/...`,不需要数据库变更。 保存包含完整对象路径的 `oss://lionqueen/...`,不需要数据库变更。
生产环境启动需启用 `prod` Profile,可通过 `OSS_PATH_PREFIX` 覆盖目录前缀 生产环境启动需启用 `prod` Profile,可通过 `OSS_PATH_PREFIX` 覆盖目录前缀
(不以 `/` 开头或结尾)。同 Bucket 下的目录划分用于区分文件,权限隔离仍需配置 RAM 策略。 (不以 `/` 开头或结尾)。同 Bucket 下的目录划分用于区分文件,权限隔离仍需配置 RAM 策略。
@@ -0,0 +1,104 @@
-- 应收账单行级“导出明细”任务与文件元数据表改名,保留既有数据。
-- 脚本可重复执行;若新旧表同时存在,请先核对数据再手动合并,避免覆盖任一表。
SET @old_table_exists := (
SELECT COUNT(1) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_export'
);
SET @new_table_exists := (
SELECT COUNT(1) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
);
SET @sql := IF(@old_table_exists > 0 AND @new_table_exists = 0,
'RENAME TABLE `ar_bill_export` TO `ar_bill_detail_export`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 索引随表名统一;旧索引不存在或新索引已经存在时跳过。
SET @old_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_export_bill'
);
SET @new_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_detail_export_bill'
);
SET @sql := IF(@old_index_exists > 0 AND @new_index_exists = 0,
'ALTER TABLE `ar_bill_detail_export` RENAME INDEX `idx_ar_bill_export_bill` TO `idx_ar_bill_detail_export_bill`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @old_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_export_status'
);
SET @new_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_detail_export_status'
);
SET @sql := IF(@old_index_exists > 0 AND @new_index_exists = 0,
'ALTER TABLE `ar_bill_detail_export` RENAME INDEX `idx_ar_bill_export_status` TO `idx_ar_bill_detail_export_status`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @old_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_export_template'
);
SET @new_index_exists := (
SELECT COUNT(1) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND INDEX_NAME = 'idx_ar_bill_detail_export_template'
);
SET @sql := IF(@old_index_exists > 0 AND @new_index_exists = 0,
'ALTER TABLE `ar_bill_detail_export` RENAME INDEX `idx_ar_bill_export_template` TO `idx_ar_bill_detail_export_template`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- MySQL 没有外键重命名语法,通过同一 ALTER TABLE 替换约束名。
SET @old_constraint_exists := (
SELECT COUNT(1) FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND CONSTRAINT_NAME = 'fk_ar_bill_export_bill'
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
);
SET @new_constraint_exists := (
SELECT COUNT(1) FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail_export'
AND CONSTRAINT_NAME = 'fk_ar_bill_detail_export_bill'
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
);
SET @sql := IF(@old_constraint_exists > 0 AND @new_constraint_exists = 0,
'ALTER TABLE `ar_bill_detail_export` DROP FOREIGN KEY `fk_ar_bill_export_bill`, ADD CONSTRAINT `fk_ar_bill_detail_export_bill` FOREIGN KEY (`ar_bill_id`) REFERENCES `ar_bill` (`ar_bill_id`)',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
+7 -7
View File
@@ -172,9 +172,9 @@ CREATE TABLE `ar_bill_detail_fee` (
) ENGINE=InnoDB AUTO_INCREMENT=151 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单费用快照'; ) ENGINE=InnoDB AUTO_INCREMENT=151 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单费用快照';
-- ---------------------------- -- ----------------------------
-- 表结构:`ar_bill_export` -- 表结构:`ar_bill_detail_export`
-- ---------------------------- -- ----------------------------
CREATE TABLE `ar_bill_export` ( CREATE TABLE `ar_bill_detail_export` (
`export_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '导出ID', `export_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '导出ID',
`ar_bill_id` bigint(20) NOT NULL COMMENT '应收账单ID', `ar_bill_id` bigint(20) NOT NULL COMMENT '应收账单ID',
`file_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '下载展示名称', `file_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '下载展示名称',
@@ -194,11 +194,11 @@ CREATE TABLE `ar_bill_export` (
`export_time` datetime NOT NULL COMMENT '导出时间', `export_time` datetime NOT NULL COMMENT '导出时间',
`remark` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '失败原因或备注', `remark` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '失败原因或备注',
PRIMARY KEY (`export_id`), PRIMARY KEY (`export_id`),
KEY `idx_ar_bill_export_bill` (`ar_bill_id`,`export_time`), KEY `idx_ar_bill_detail_export_bill` (`ar_bill_id`,`export_time`),
KEY `idx_ar_bill_export_status` (`export_status`), KEY `idx_ar_bill_detail_export_status` (`export_status`),
KEY `idx_ar_bill_export_template` (`template_id`), KEY `idx_ar_bill_detail_export_template` (`template_id`),
CONSTRAINT `fk_ar_bill_export_bill` FOREIGN KEY (`ar_bill_id`) REFERENCES `ar_bill` (`ar_bill_id`) CONSTRAINT `fk_ar_bill_detail_export_bill` FOREIGN KEY (`ar_bill_id`) REFERENCES `ar_bill` (`ar_bill_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单导出文件元数据'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='应收账单明细导出任务和文件元数据';
-- ---------------------------- -- ----------------------------
-- 表结构:`ar_bill_generate_task` -- 表结构:`ar_bill_generate_task`