86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import type { AuditSubjectResourceType } from '@/types/api'
|
|
import type { AuditFinanceField, AuditInvestigationTarget } from '@/components/business/audit/types'
|
|
|
|
interface AuditResourceRouteOptions {
|
|
userType?: number
|
|
resourceType: AuditSubjectResourceType | string
|
|
internalId?: string | number | null
|
|
businessIdentifier?: string | null
|
|
}
|
|
|
|
interface AuditReferenceOptions {
|
|
currentId?: string | null
|
|
fidelity?: boolean | null
|
|
}
|
|
|
|
/** 仅保留非空、可靠且不会回到当前目标的显式调查引用。 */
|
|
export function resolveInvestigationReference(
|
|
value?: string | null,
|
|
options: AuditReferenceOptions = {}
|
|
): string | null {
|
|
if (options.fidelity === false) return null
|
|
const normalizedValue = value?.trim()
|
|
if (!normalizedValue || normalizedValue === options.currentId?.trim()) return null
|
|
return normalizedValue
|
|
}
|
|
|
|
/** 根据当前主体选择平台内部 ID 或主体安全业务标识。 */
|
|
export function resolveAuditResourceTarget(
|
|
options: AuditResourceRouteOptions
|
|
): AuditInvestigationTarget | null {
|
|
const { userType, resourceType, internalId, businessIdentifier } = options
|
|
const normalizedBusinessIdentifier = businessIdentifier?.trim()
|
|
if (userType === 3) {
|
|
if (
|
|
!normalizedBusinessIdentifier ||
|
|
![
|
|
'iot_card',
|
|
'device',
|
|
'asset_allocation_record',
|
|
'exchange_order',
|
|
'shop',
|
|
'enterprise'
|
|
].includes(resourceType)
|
|
)
|
|
return null
|
|
return {
|
|
mode: 'agent',
|
|
resourceType: resourceType as AuditSubjectResourceType,
|
|
id: normalizedBusinessIdentifier
|
|
}
|
|
}
|
|
if (userType === 4) {
|
|
if (!normalizedBusinessIdentifier || !['iot_card', 'device'].includes(resourceType)) return null
|
|
return {
|
|
mode: 'enterprise',
|
|
resourceType: resourceType as AuditSubjectResourceType,
|
|
id: normalizedBusinessIdentifier
|
|
}
|
|
}
|
|
if (
|
|
internalId === undefined ||
|
|
internalId === null ||
|
|
internalId === '' ||
|
|
(typeof internalId === 'string' && !internalId.trim()) ||
|
|
(typeof internalId === 'number' && (!Number.isFinite(internalId) || internalId <= 0))
|
|
)
|
|
return null
|
|
return { mode: 'resource', resourceType, id: String(internalId).trim() }
|
|
}
|
|
|
|
export function resolveFinanceAuditTarget(
|
|
field: AuditFinanceField,
|
|
value?: string | number | null
|
|
): AuditInvestigationTarget | null {
|
|
const normalizedValue = typeof value === 'string' ? value.trim() : value
|
|
if (
|
|
normalizedValue === undefined ||
|
|
normalizedValue === null ||
|
|
normalizedValue === '' ||
|
|
(typeof normalizedValue === 'number' &&
|
|
(!Number.isFinite(normalizedValue) || normalizedValue <= 0))
|
|
)
|
|
return null
|
|
return { mode: 'finance', field, value: normalizedValue }
|
|
}
|