feat(expenses): add authoritative pre-review workflow
This commit is contained in:
@@ -187,6 +187,12 @@ function sanitizeHeaders(headers) {
|
||||
function buildApiResponseError(response, payload, { auth, handleUnauthorized }) {
|
||||
const error = new Error(resolveErrorMessage(payload))
|
||||
error.status = response.status
|
||||
error.payload = payload
|
||||
error.detail = payload?.detail
|
||||
if (payload?.detail && typeof payload.detail === 'object') {
|
||||
error.code = String(payload.detail.code || '').trim()
|
||||
error.review = payload.detail.review || null
|
||||
}
|
||||
if (response.status === 401 && auth && handleUnauthorized && readAuthAccessToken()) {
|
||||
error.code = 'AUTH_SESSION_EXPIRED'
|
||||
notifyAuthSessionExpired()
|
||||
|
||||
@@ -224,10 +224,26 @@ export function updateExpenseClaimItem(claimId, itemId, payload) {
|
||||
})
|
||||
}
|
||||
|
||||
export function submitExpenseClaim(claimId) {
|
||||
function createPreReviewRequestId() {
|
||||
if (typeof globalThis.crypto?.randomUUID === 'function') {
|
||||
return `pre-review:${globalThis.crypto.randomUUID()}`
|
||||
}
|
||||
return `pre-review:${Date.now()}:${Math.random().toString(16).slice(2)}`
|
||||
}
|
||||
|
||||
export function preReviewExpenseClaim(claimId, requestId = '') {
|
||||
const normalizedRequestId = String(requestId || '').trim() || createPreReviewRequestId()
|
||||
return apiRequest(`/reimbursements/claims/${encodeURIComponent(String(claimId || '').trim())}/pre-review`, {
|
||||
method: 'POST',
|
||||
headers: { 'X-Request-ID': normalizedRequestId },
|
||||
body: JSON.stringify({})
|
||||
})
|
||||
}
|
||||
|
||||
export function submitExpenseClaim(claimId, payload = {}) {
|
||||
return apiRequest(`/reimbursements/claims/${encodeURIComponent(String(claimId || '').trim())}/submit`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({})
|
||||
body: JSON.stringify(payload || {})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ const EVENT_PRESENTATION = {
|
||||
application_returned: { label: '费用申请被退回', icon: 'mdi mdi-arrow-u-left-top', tone: 'warning' },
|
||||
claim_returned: { label: '报销单被退回', icon: 'mdi mdi-arrow-u-left-top', tone: 'warning' },
|
||||
reimbursement_draft_generated: { label: '报销草稿已自动生成', icon: 'mdi mdi-robot-outline', tone: 'success' },
|
||||
receipt_received: { label: '票据已进入费用事件', icon: 'mdi mdi-receipt-text-plus-outline', tone: 'info' },
|
||||
attachment_associated: { label: '票据已归集到报销草稿', icon: 'mdi mdi-file-link-outline', tone: 'success' },
|
||||
application_pre_review_completed: { label: '费用申请 AI 预审已完成', icon: 'mdi mdi-shield-search-outline', tone: 'success' },
|
||||
claim_pre_review_completed: { label: '报销单 AI 预审已完成', icon: 'mdi mdi-shield-search-outline', tone: 'success' },
|
||||
payment_completed: { label: '付款已完成', icon: 'mdi mdi-cash-check', tone: 'success' },
|
||||
application_archived: { label: '费用申请已归档', icon: 'mdi mdi-archive-check-outline', tone: 'success' }
|
||||
}
|
||||
@@ -125,6 +129,32 @@ function buildEventSummary(eventType, payload) {
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType === 'receipt_received') {
|
||||
const fileName = compactText(readField(payload, 'file_name', 'fileName'))
|
||||
return fileName
|
||||
? `${fileName} 已进入费用事件并完成票据识别。`
|
||||
: '票据已进入费用事件并完成识别。'
|
||||
}
|
||||
|
||||
if (eventType === 'attachment_associated') {
|
||||
const claimNo = compactText(readField(payload, 'claim_no', 'claimNo'))
|
||||
return claimNo
|
||||
? `票据已自动归集到报销草稿 ${claimNo}。`
|
||||
: '票据已自动归集到当前报销草稿。'
|
||||
}
|
||||
|
||||
if (['application_pre_review_completed', 'claim_pre_review_completed'].includes(eventType)) {
|
||||
const message = compactText(payload?.message)
|
||||
if (message) {
|
||||
return message
|
||||
}
|
||||
const passed = readField(payload, 'passed', 'passed')
|
||||
const blockingCount = Number(readField(payload, 'blocking_risk_count', 'blockingRiskCount') || 0)
|
||||
return passed === false
|
||||
? `AI 预审发现 ${blockingCount} 条重大风险,请处理后重新预审。`
|
||||
: 'AI 预审已通过,可以继续提交审批。'
|
||||
}
|
||||
|
||||
if (eventType === 'application_archived') {
|
||||
const reimbursementClaimNo = compactText(readField(payload, 'reimbursement_claim_no', 'reimbursementClaimNo'))
|
||||
if (reimbursementClaimNo) {
|
||||
@@ -175,13 +205,17 @@ function normalizeEvent(event, index) {
|
||||
const occurredAt = readField(event, 'occurred_at', 'occurredAt')
|
||||
const timestamp = new Date(occurredAt || '').getTime()
|
||||
const payload = readField(event, 'payload_json', 'payloadJson') || {}
|
||||
const isFailedPreReview = (
|
||||
['application_pre_review_completed', 'claim_pre_review_completed'].includes(eventType)
|
||||
&& readField(payload, 'passed', 'passed') === false
|
||||
)
|
||||
|
||||
return {
|
||||
id: compactText(event?.id) || `${eventType || 'event'}-${index}`,
|
||||
eventType,
|
||||
label: presentation.label,
|
||||
icon: presentation.icon,
|
||||
tone: presentation.tone,
|
||||
tone: isFailedPreReview ? 'warning' : presentation.tone,
|
||||
summary: buildEventSummary(eventType, payload),
|
||||
actorLabel: eventType === 'historical_claim_imported' ? '系统' : resolveActorLabel(event),
|
||||
occurredAt: compactText(occurredAt),
|
||||
|
||||
13
web/src/views/scripts/travelRequestDetailPreReview.js
Normal file
13
web/src/views/scripts/travelRequestDetailPreReview.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export function mapPreReviewFindingsToRiskFlags(preReview = {}) {
|
||||
const findings = Array.isArray(preReview?.findings) ? preReview.findings : []
|
||||
return findings.map((finding) => ({
|
||||
...finding,
|
||||
source: String(finding?.source || 'pre_review_finding').trim() || 'pre_review_finding',
|
||||
label: finding?.message || '提交前预审风险',
|
||||
business_stage: String(
|
||||
finding?.business_stage || finding?.businessStage || 'reimbursement'
|
||||
).trim() || 'reimbursement',
|
||||
risk_domain: finding?.risk_domain || finding?.riskDomain || '',
|
||||
visibility_scope: finding?.visibility_scope || finding?.visibilityScope || ''
|
||||
}))
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { computed, nextTick, ref, watch } from 'vue'
|
||||
import {
|
||||
acceptExpenseClaimStandardAdjustment,
|
||||
calculateTravelReimbursement,
|
||||
preReviewExpenseClaim,
|
||||
submitExpenseClaim,
|
||||
updateExpenseClaim
|
||||
} from '../../services/reimbursements.js'
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
normalizeRiskTone,
|
||||
resolveRiskTags
|
||||
} from './travelRequestDetailInsights.js'
|
||||
import { mapPreReviewFindingsToRiskFlags } from './travelRequestDetailPreReview.js'
|
||||
import {
|
||||
buildCurrentStandardAdjustmentMap,
|
||||
buildStandardAdjustmentPayload as buildStandardAdjustmentPayloadModel,
|
||||
@@ -139,11 +141,16 @@ export function useTravelRequestDetailRiskSubmit({
|
||||
}
|
||||
|
||||
function applyClaimRiskFlagsPayload(payload) {
|
||||
const flags = Array.isArray(payload?.claim_risk_flags)
|
||||
? payload.claim_risk_flags
|
||||
: Array.isArray(payload?.claimRiskFlags)
|
||||
? payload.claimRiskFlags
|
||||
const flags = [
|
||||
payload?.claim_risk_flags,
|
||||
payload?.claimRiskFlags,
|
||||
payload?.risk_flags_json,
|
||||
payload?.riskFlags
|
||||
].find(Array.isArray) || (
|
||||
Array.isArray(payload?.pre_review?.findings)
|
||||
? mapPreReviewFindingsToRiskFlags(payload.pre_review)
|
||||
: null
|
||||
)
|
||||
if (!flags) {
|
||||
return
|
||||
}
|
||||
@@ -657,7 +664,24 @@ export function useTravelRequestDetailRiskSubmit({
|
||||
|
||||
async function runSubmitRequest(claimId, documentNo, isApplication, taskSeq) {
|
||||
try {
|
||||
const payload = await submitExpenseClaim(claimId)
|
||||
const reviewedClaim = await preReviewExpenseClaim(claimId)
|
||||
if (taskSeq !== submitTaskSeq || String(request.value?.claimId || '').trim() !== claimId) {
|
||||
return
|
||||
}
|
||||
applyClaimRiskFlagsPayload(reviewedClaim)
|
||||
const preReview = reviewedClaim?.pre_review || reviewedClaim?.preReview || null
|
||||
if (String(preReview?.decision || '').trim() === 'needs_fix') {
|
||||
toast(preReview?.message || '自动检测发现需要先整改的风险,请处理后重新提交。')
|
||||
emit('request-updated', { claimId })
|
||||
return
|
||||
}
|
||||
|
||||
const payload = await submitExpenseClaim(claimId, {
|
||||
pre_review_id: String(preReview?.review_id || preReview?.reviewId || '').trim() || null,
|
||||
input_fingerprint: String(
|
||||
preReview?.input_fingerprint || preReview?.inputFingerprint || ''
|
||||
).trim() || null
|
||||
})
|
||||
if (taskSeq !== submitTaskSeq || String(request.value?.claimId || '').trim() !== claimId) {
|
||||
return
|
||||
}
|
||||
@@ -678,6 +702,12 @@ export function useTravelRequestDetailRiskSubmit({
|
||||
emit('request-updated', { claimId })
|
||||
} catch (error) {
|
||||
if (taskSeq === submitTaskSeq) {
|
||||
if (['PRE_REVIEW_NEEDS_FIX', 'PRE_REVIEW_CHANGED'].includes(error?.code)) {
|
||||
applyClaimRiskFlagsPayload({ pre_review: error?.review })
|
||||
toast(error?.review?.message || error?.message || '自动检测发现需要先整改的风险。')
|
||||
emit('request-updated', { claimId })
|
||||
return
|
||||
}
|
||||
toast(error?.message || '提交审批失败,请稍后重试。')
|
||||
}
|
||||
} finally {
|
||||
@@ -693,7 +723,6 @@ export function useTravelRequestDetailRiskSubmit({
|
||||
submitTaskSeq += 1
|
||||
submitBusy.value = false
|
||||
}
|
||||
|
||||
function disposeRiskSubmit() {
|
||||
resetSubmitWorkState()
|
||||
if (highlightedRiskCardTimer) {
|
||||
|
||||
Reference in New Issue
Block a user