实现 B-2a 报销审批内容工作台(reimbursement-approval-content-workbench)
这个提交包含在:
@@ -76,6 +76,95 @@ const WORKFLOW_OVERDUE_ACTION = "overdue_remind";
|
||||
const WORKFLOW_REMINDER_COOLDOWN_MS = 24 * 60 * 60 * 1000;
|
||||
const WORKFLOW_DEFAULT_DUE_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
const REIMBURSEMENT_SNAPSHOT_CONTROL_MODES = new Set(["warn", "block"]);
|
||||
|
||||
function projectReimbursementSubmissionSnapshot(contextData) {
|
||||
const source = contextData && typeof contextData === "object" && !Array.isArray(contextData)
|
||||
? contextData
|
||||
: {};
|
||||
const standardViolationsPresent = Object.prototype.hasOwnProperty.call(source, "standardViolations");
|
||||
const budgetCheckPresent = Object.prototype.hasOwnProperty.call(source, "budgetCheck") && source.budgetCheck != null;
|
||||
const budgetCheckRecordedPresent = Object.prototype.hasOwnProperty.call(source, "budgetCheckRecorded");
|
||||
const standardViolationsValid = Array.isArray(source.standardViolations) && source.standardViolations.every((item) => (
|
||||
item &&
|
||||
typeof item === "object" &&
|
||||
typeof item.itemId === "string" &&
|
||||
typeof item.expenseTypeId === "string" &&
|
||||
typeof item.expenseTypeName === "string" &&
|
||||
typeof item.amount === "string" &&
|
||||
typeof item.standardId === "string" &&
|
||||
typeof item.standardName === "string" &&
|
||||
typeof item.maxAmount === "string" &&
|
||||
["item", "day", "trip"].includes(item.perUnit) &&
|
||||
REIMBURSEMENT_SNAPSHOT_CONTROL_MODES.has(item.controlMode) &&
|
||||
["global", "department"].includes(item.scopeType) &&
|
||||
(item.scopeKey == null || typeof item.scopeKey === "string") &&
|
||||
typeof item.exceeded === "boolean" &&
|
||||
typeof item.exceededAmount === "string"
|
||||
));
|
||||
const standardViolations = standardViolationsValid
|
||||
? source.standardViolations.map((item) => ({
|
||||
itemId: item.itemId,
|
||||
expenseTypeId: item.expenseTypeId,
|
||||
expenseTypeName: item.expenseTypeName,
|
||||
amount: item.amount,
|
||||
standardId: item.standardId,
|
||||
standardName: item.standardName,
|
||||
maxAmount: item.maxAmount,
|
||||
perUnit: item.perUnit,
|
||||
controlMode: item.controlMode,
|
||||
scopeType: item.scopeType,
|
||||
scopeKey: item.scopeKey,
|
||||
exceeded: item.exceeded,
|
||||
exceededAmount: item.exceededAmount,
|
||||
}))
|
||||
: [];
|
||||
|
||||
let budgetCheck = null;
|
||||
if (budgetCheckPresent) {
|
||||
const candidate = source.budgetCheck;
|
||||
const usagePercent = Number(candidate?.usagePercent);
|
||||
if (
|
||||
candidate &&
|
||||
typeof candidate === "object" &&
|
||||
!Array.isArray(candidate) &&
|
||||
typeof candidate.budgetId === "string" &&
|
||||
typeof candidate.budgetCode === "string" &&
|
||||
REIMBURSEMENT_SNAPSHOT_CONTROL_MODES.has(candidate.controlMode) &&
|
||||
Number.isFinite(usagePercent) &&
|
||||
typeof candidate.exceededThreshold === "boolean" &&
|
||||
typeof candidate.exceededBudget === "boolean"
|
||||
) {
|
||||
budgetCheck = {
|
||||
budgetId: candidate.budgetId,
|
||||
budgetCode: candidate.budgetCode,
|
||||
controlMode: candidate.controlMode,
|
||||
usagePercent,
|
||||
exceededThreshold: candidate.exceededThreshold,
|
||||
exceededBudget: candidate.exceededBudget,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const parseStatus =
|
||||
(standardViolationsPresent && !standardViolationsValid) ||
|
||||
(budgetCheckPresent && !budgetCheck) ||
|
||||
(budgetCheckRecordedPresent && source.budgetCheckRecorded !== true)
|
||||
? "invalid"
|
||||
: "ready";
|
||||
|
||||
return {
|
||||
standardViolations,
|
||||
budgetCheck,
|
||||
budgetCheckStatus: budgetCheck
|
||||
? "available"
|
||||
: source.budgetCheckRecorded === true
|
||||
? "not_applicable"
|
||||
: "missing",
|
||||
parseStatus,
|
||||
};
|
||||
}
|
||||
|
||||
const APPROVER_LIST_QUERY_SCHEMA = z.object({
|
||||
keyword: z.string().trim().max(100).optional(),
|
||||
page: z.coerce.number().int().min(1).optional(),
|
||||
@@ -2429,6 +2518,9 @@ async function workflowRoutes(fastify) {
|
||||
},
|
||||
},
|
||||
});
|
||||
const reimbursementSubmissionSnapshot = task.workflow_instance?.entity_type === "reimbursement"
|
||||
? projectReimbursementSubmissionSnapshot(task.workflow_instance.context_data)
|
||||
: null;
|
||||
|
||||
return sendData(reply, request, {
|
||||
task: {
|
||||
@@ -2451,9 +2543,10 @@ async function workflowRoutes(fastify) {
|
||||
currentStatus: task.workflow_instance.current_status,
|
||||
currentStepId: task.workflow_instance.current_step_id,
|
||||
contextData: {
|
||||
standardViolations: Array.isArray(task.workflow_instance.context_data?.standardViolations)
|
||||
? task.workflow_instance.context_data.standardViolations
|
||||
: [],
|
||||
standardViolations: reimbursementSubmissionSnapshot?.standardViolations ?? [],
|
||||
budgetCheck: reimbursementSubmissionSnapshot?.budgetCheck ?? null,
|
||||
budgetCheckStatus: reimbursementSubmissionSnapshot?.budgetCheckStatus ?? "missing",
|
||||
parseStatus: reimbursementSubmissionSnapshot?.parseStatus ?? "ready",
|
||||
},
|
||||
startedAt: isoOrNull(task.workflow_instance.started_at),
|
||||
completedAt: isoOrNull(task.workflow_instance.completed_at),
|
||||
|
||||
在新工单中引用
屏蔽一个用户