R35-2 审批通知补结构化摘要
这个提交包含在:
@@ -0,0 +1,212 @@
|
||||
const { formatDateOnly } = require("../leave");
|
||||
const { toMoneyString } = require("../../utils/workflow");
|
||||
|
||||
function normalizeWorkflowEntityType(entityType) {
|
||||
return entityType === "procurement" ? "purchase_request" : entityType;
|
||||
}
|
||||
|
||||
function formatAmount(value) {
|
||||
return toMoneyString(value) ?? "-";
|
||||
}
|
||||
|
||||
function formatRequestedDays(value) {
|
||||
const numeric = Number(value ?? 0);
|
||||
if (!Number.isFinite(numeric)) {
|
||||
return "-";
|
||||
}
|
||||
return Number.isInteger(numeric) ? String(numeric) : numeric.toFixed(1);
|
||||
}
|
||||
|
||||
function formatDateRange(startDate, endDate) {
|
||||
const start = startDate ? formatDateOnly(startDate) : null;
|
||||
const end = endDate ? formatDateOnly(endDate) : null;
|
||||
|
||||
if (start && end) {
|
||||
return start === end ? start : `${start} ~ ${end}`;
|
||||
}
|
||||
|
||||
return start ?? end ?? null;
|
||||
}
|
||||
|
||||
function buildReference(normalizedEntityType, entityRecord, entityId) {
|
||||
if (normalizedEntityType === "reimbursement") {
|
||||
return entityRecord?.form_number ?? entityId;
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "leave") {
|
||||
return formatDateRange(entityRecord?.start_date, entityRecord?.end_date) ?? entityId;
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "purchase_request") {
|
||||
return entityRecord?.request_no ?? entityId;
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "travel_request") {
|
||||
return entityRecord?.request_no ?? entityId;
|
||||
}
|
||||
|
||||
return entityId;
|
||||
}
|
||||
|
||||
function buildWorkflowEntityMeta(entityType, entityRecord, entityId) {
|
||||
const normalizedEntityType = normalizeWorkflowEntityType(entityType);
|
||||
|
||||
if (normalizedEntityType === "reimbursement") {
|
||||
return {
|
||||
entityType: normalizedEntityType,
|
||||
label: "报销单",
|
||||
reference: buildReference(normalizedEntityType, entityRecord, entityId),
|
||||
targetType: "reimbursement_form",
|
||||
detailPath: `/reimbursements/${entityId}`,
|
||||
summary: {
|
||||
applicantName: entityRecord?.owner?.name ?? null,
|
||||
amount: formatAmount(entityRecord?.total_amount),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "leave") {
|
||||
return {
|
||||
entityType: normalizedEntityType,
|
||||
label: "请假单",
|
||||
reference: buildReference(normalizedEntityType, entityRecord, entityId),
|
||||
targetType: "leave_request",
|
||||
detailPath: "/leave-requests",
|
||||
summary: {
|
||||
applicantName: entityRecord?.owner?.name ?? null,
|
||||
leaveTypeName: entityRecord?.leave_type?.name ?? null,
|
||||
requestedDays: formatRequestedDays(entityRecord?.requested_days),
|
||||
dateRange: formatDateRange(entityRecord?.start_date, entityRecord?.end_date) ?? "-",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "purchase_request") {
|
||||
return {
|
||||
entityType: normalizedEntityType,
|
||||
label: "采购申请",
|
||||
reference: buildReference(normalizedEntityType, entityRecord, entityId),
|
||||
targetType: "purchase_request",
|
||||
detailPath: "/purchase-requests",
|
||||
summary: {
|
||||
applicantName: entityRecord?.applicant?.name ?? null,
|
||||
amount: formatAmount(entityRecord?.total_amount),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (normalizedEntityType === "travel_request") {
|
||||
return {
|
||||
entityType: normalizedEntityType,
|
||||
label: "差旅申请",
|
||||
reference: buildReference(normalizedEntityType, entityRecord, entityId),
|
||||
targetType: "travel_request",
|
||||
detailPath: `/travel-requests?id=${entityId}`,
|
||||
summary: {
|
||||
applicantName: entityRecord?.applicant?.name ?? null,
|
||||
estimatedAmount: formatAmount(entityRecord?.estimated_amount),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
entityType: normalizedEntityType,
|
||||
label: "审批单",
|
||||
reference: entityId,
|
||||
targetType: normalizedEntityType,
|
||||
detailPath: `/workflow/tasks/${entityId}`,
|
||||
summary: {},
|
||||
};
|
||||
}
|
||||
|
||||
function buildSummaryLines(entityMeta) {
|
||||
if (entityMeta.entityType === "reimbursement") {
|
||||
return [
|
||||
`申请人:${entityMeta.summary.applicantName ?? "未知申请人"}`,
|
||||
`金额:${entityMeta.summary.amount ?? "-"}`,
|
||||
`单号:${entityMeta.reference}`,
|
||||
];
|
||||
}
|
||||
|
||||
if (entityMeta.entityType === "leave") {
|
||||
return [
|
||||
`申请人:${entityMeta.summary.applicantName ?? "未知申请人"}`,
|
||||
`假种:${entityMeta.summary.leaveTypeName ?? "请假"}`,
|
||||
`天数:${entityMeta.summary.requestedDays ?? "-"} 天`,
|
||||
`起止日期:${entityMeta.summary.dateRange ?? "-"}`,
|
||||
];
|
||||
}
|
||||
|
||||
if (entityMeta.entityType === "purchase_request") {
|
||||
return [
|
||||
`申请人:${entityMeta.summary.applicantName ?? "未知申请人"}`,
|
||||
`金额:${entityMeta.summary.amount ?? "-"}`,
|
||||
`单号:${entityMeta.reference}`,
|
||||
];
|
||||
}
|
||||
|
||||
if (entityMeta.entityType === "travel_request") {
|
||||
return [
|
||||
`申请人:${entityMeta.summary.applicantName ?? "未知申请人"}`,
|
||||
`预估金额:${entityMeta.summary.estimatedAmount ?? "-"}`,
|
||||
`单号:${entityMeta.reference}`,
|
||||
];
|
||||
}
|
||||
|
||||
return [`单据:${entityMeta.reference}`];
|
||||
}
|
||||
|
||||
function buildSubject(entityMeta) {
|
||||
return entityMeta.reference ? `${entityMeta.label} ${entityMeta.reference}` : entityMeta.label;
|
||||
}
|
||||
|
||||
function buildBody(entityMeta, resultLine) {
|
||||
return [...buildSummaryLines(entityMeta), resultLine].join("\n");
|
||||
}
|
||||
|
||||
function buildPendingTaskCopy(entityMeta, { transfer = false } = {}) {
|
||||
return {
|
||||
title: `【待办】${buildSubject(entityMeta)} ${transfer ? "转审待处理" : "待审批"}`,
|
||||
body: buildBody(
|
||||
entityMeta,
|
||||
transfer ? "动作:该审批已转审给你,请及时处理。" : "动作:请及时处理审批任务。",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function buildApprovedCopy(entityMeta) {
|
||||
return {
|
||||
title: `【已批准】${buildSubject(entityMeta)}`,
|
||||
body: buildBody(
|
||||
entityMeta,
|
||||
entityMeta.targetType === "reimbursement_form"
|
||||
? "结果:已审批通过,等待财务付款。"
|
||||
: "结果:已审批通过。",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function buildRejectedCopy(entityMeta, comment) {
|
||||
const safeComment = String(comment ?? "").trim() || "无";
|
||||
return {
|
||||
title: `【已驳回】${buildSubject(entityMeta)}`,
|
||||
body: buildBody(entityMeta, `结果:已驳回:${safeComment}`),
|
||||
};
|
||||
}
|
||||
|
||||
function buildReturnedCopy(entityMeta, comment) {
|
||||
const safeComment = String(comment ?? "").trim() || "无";
|
||||
return {
|
||||
title: `【已退回】${buildSubject(entityMeta)}`,
|
||||
body: buildBody(entityMeta, `结果:已退回:${safeComment}`),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildApprovedCopy,
|
||||
buildPendingTaskCopy,
|
||||
buildRejectedCopy,
|
||||
buildReturnedCopy,
|
||||
buildWorkflowEntityMeta,
|
||||
normalizeWorkflowEntityType,
|
||||
};
|
||||
在新工单中引用
屏蔽一个用户