ASSET1 统一电子资产与固定资产台账

这个提交包含在:
2026-05-22 22:04:41 +08:00
父节点 c2a3c7a84b
当前提交 9090046a97
共修改 18 个文件,包含 1457 行新增和 199 行删除
+26 -10
查看文件
@@ -65,10 +65,10 @@ const DOCUMENT_TYPE_CONFIG = {
defaultCategoryCode: "ASSET_CARD_DEFAULT",
preferLegacySequence: false,
fallback: {
prefix: "ZC",
dateFormat: "YYYYMMDD",
prefix: "FA",
dateFormat: "YYYY",
separator: "-",
numberLength: 4,
numberLength: 6,
resetPeriod: "yearly",
},
},
@@ -151,6 +151,7 @@ function buildConfigFromFallback(documentType) {
function buildConfigFromCategory(documentType, category, sequenceRecord) {
const fallback = DOCUMENT_TYPE_CONFIG[documentType].fallback;
const mappedSequence = mapSequenceRecord(sequenceRecord);
const shouldPreferFallbackDateFormat = documentType === "asset_card";
return {
exists: Boolean(sequenceRecord),
@@ -158,7 +159,7 @@ function buildConfigFromCategory(documentType, category, sequenceRecord) {
documentType,
documentCategoryCode: category.code,
prefix: category.sequence_prefix,
dateFormat: mappedSequence?.dateFormat ?? fallback.dateFormat,
dateFormat: shouldPreferFallbackDateFormat ? fallback.dateFormat : mappedSequence?.dateFormat ?? fallback.dateFormat,
separator: mappedSequence?.separator ?? fallback.separator,
numberLength: category.number_length,
resetPeriod: category.reset_period,
@@ -249,12 +250,13 @@ async function findDocumentCategory(prisma, { documentType, documentCategoryCode
});
}
async function resolveDocumentSequenceConfig(prisma, { documentType, documentCategoryCode = null } = {}) {
async function resolveDocumentSequenceConfig(prisma, { documentType, documentCategoryCode = null, sequenceKey = null } = {}) {
const normalizedDocumentType = normalizeDocumentType(documentType);
const documentTypeConfig = DOCUMENT_TYPE_CONFIG[normalizedDocumentType];
const resolvedSequenceKey = sequenceKey || normalizedDocumentType;
const sequenceRecord = await prisma.documentSequence.findUnique({
where: { document_type: normalizedDocumentType },
where: { document_type: resolvedSequenceKey },
select: {
document_type: true,
prefix: true,
@@ -299,24 +301,37 @@ async function resolveDocumentSequenceConfig(prisma, { documentType, documentCat
return buildConfigFromFallback(normalizedDocumentType);
}
function formatDatePart(dateFormat, timeZone) {
const compact = compactDateString(timeZone);
if (dateFormat === "YYYY") {
return compact.slice(0, 4);
}
if (dateFormat === "YYYYMM") {
return compact.slice(0, 6);
}
return compact;
}
function formatDocumentNumber(sequenceConfig, timeZone) {
const datePart = compactDateString(timeZone);
const datePart = formatDatePart(sequenceConfig.dateFormat, timeZone);
const serial = String(sequenceConfig.current_number).padStart(sequenceConfig.number_length, "0");
return `${sequenceConfig.prefix}${sequenceConfig.separator}${datePart}${sequenceConfig.separator}${serial}`;
}
async function issueDocumentNumber(
tx,
{ documentType, documentCategoryCode = null, actorId = null, timeZone = "Asia/Shanghai" } = {},
{ documentType, documentCategoryCode = null, sequenceKey = null, actorId = null, timeZone = "Asia/Shanghai" } = {},
) {
const normalizedDocumentType = normalizeDocumentType(documentType);
const resolvedSequenceKey = sequenceKey || normalizedDocumentType;
const config = await resolveDocumentSequenceConfig(tx, {
documentType: normalizedDocumentType,
documentCategoryCode,
sequenceKey: resolvedSequenceKey,
});
const sequenceRecord = await tx.documentSequence.upsert({
where: { document_type: normalizedDocumentType },
where: { document_type: resolvedSequenceKey },
update: {
prefix: config.prefix,
date_format: config.dateFormat,
@@ -327,7 +342,7 @@ async function issueDocumentNumber(
updated_by: actorId,
},
create: {
document_type: normalizedDocumentType,
document_type: resolvedSequenceKey,
prefix: config.prefix,
date_format: config.dateFormat,
separator: config.separator,
@@ -356,6 +371,7 @@ async function issueDocumentNumber(
{
prefix: mappedSequence.prefix,
separator: mappedSequence.separator,
dateFormat: mappedSequence.dateFormat,
number_length: mappedSequence.numberLength,
current_number: mappedSequence.currentNumber,
},