feat: 新增预算后端服务与差旅风险规则库
后端新增预算模型、端点和服务模块,支持预算 CRUD 和余额 查询,清理旧生成规则文件并替换为按严重等级分类的差旅风 险规则库,优化认证权限和报销单访问策略,新增财务规则目 录和演示数据构建脚本,前端预算中心增加对话框交互,完善 审计页面运行时模型和元数据展示,补充单元测试。
This commit is contained in:
@@ -13,44 +13,82 @@ export const DEFAULT_APP_VIEW_ORDER = [
|
||||
const ALWAYS_VISIBLE_VIEWS = new Set(['workbench', 'documents', 'policies'])
|
||||
const VIEW_ROLE_RULES = {
|
||||
overview: ['finance', 'executive'],
|
||||
budget: ['finance', 'executive'],
|
||||
audit: ['auditor', 'finance'],
|
||||
logs: ['manager'],
|
||||
employees: ['manager'],
|
||||
settings: ['manager']
|
||||
}
|
||||
budget: ['budget_monitor', 'executive'],
|
||||
audit: ['finance'],
|
||||
logs: ['manager'],
|
||||
employees: ['manager'],
|
||||
settings: ['manager']
|
||||
}
|
||||
const CLAIM_MANAGER_ROLE_CODES = new Set(['executive'])
|
||||
const CLAIM_RETURN_ROLE_CODES = new Set(['finance', 'executive', 'manager', 'approver'])
|
||||
const CLAIM_LEADER_APPROVAL_ROLE_CODES = new Set(['manager', 'approver'])
|
||||
|
||||
function normalizedRoleCodes(user) {
|
||||
if (!user) {
|
||||
return []
|
||||
}
|
||||
|
||||
return Array.isArray(user.roleCodes)
|
||||
? user.roleCodes.map((item) => String(item || '').trim().toLowerCase()).filter(Boolean)
|
||||
: []
|
||||
}
|
||||
|
||||
function normalizedRoleCodes(user) {
|
||||
if (!user) {
|
||||
return []
|
||||
}
|
||||
|
||||
return Array.isArray(user.roleCodes)
|
||||
? user.roleCodes
|
||||
.map((item) => normalizeRoleCode(item))
|
||||
.filter(Boolean)
|
||||
: []
|
||||
}
|
||||
|
||||
function normalizeRoleCode(value) {
|
||||
const roleCode = String(value || '').trim().toLowerCase()
|
||||
return roleCode === 'auditor' ? 'budget_monitor' : roleCode
|
||||
}
|
||||
|
||||
function hasPlatformAdminIdentity(user) {
|
||||
if (!user) {
|
||||
return false
|
||||
}
|
||||
|
||||
const username = String(user.username || user.account || '').trim().toLowerCase()
|
||||
const role = String(user.role || '').trim().toLowerCase()
|
||||
const roleCodes = normalizedRoleCodes(user)
|
||||
|
||||
return (
|
||||
Boolean(user.isAdmin)
|
||||
|| username === 'admin'
|
||||
|| role === 'admin'
|
||||
|| role === '管理员'
|
||||
|| role === '系统管理员'
|
||||
|| roleCodes.includes('admin')
|
||||
)
|
||||
}
|
||||
|
||||
export function isManagerUser(user) {
|
||||
return Boolean(user?.isAdmin) || normalizedRoleCodes(user).includes('manager')
|
||||
return hasPlatformAdminIdentity(user) || normalizedRoleCodes(user).includes('manager')
|
||||
}
|
||||
|
||||
export function isPlatformAdminUser(user) {
|
||||
return Boolean(user?.isAdmin)
|
||||
return hasPlatformAdminIdentity(user)
|
||||
}
|
||||
|
||||
export function isFinanceUser(user) {
|
||||
return normalizedRoleCodes(user).includes('finance')
|
||||
}
|
||||
|
||||
export function isExecutiveUser(user) {
|
||||
return normalizedRoleCodes(user).includes('executive')
|
||||
}
|
||||
|
||||
export function isExecutiveUser(user) {
|
||||
return normalizedRoleCodes(user).includes('executive')
|
||||
}
|
||||
|
||||
export function isBudgetMonitorUser(user) {
|
||||
return normalizedRoleCodes(user).includes('budget_monitor')
|
||||
}
|
||||
|
||||
export function canEditBudgetCenter(user) {
|
||||
return isPlatformAdminUser(user) || isExecutiveUser(user)
|
||||
}
|
||||
|
||||
export function canSwitchBudgetDepartments(user) {
|
||||
return isPlatformAdminUser(user) || isExecutiveUser(user)
|
||||
}
|
||||
|
||||
export function canManageExpenseClaims(user) {
|
||||
if (Boolean(user?.isAdmin)) {
|
||||
if (isPlatformAdminUser(user)) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -58,21 +96,21 @@ export function canManageExpenseClaims(user) {
|
||||
}
|
||||
|
||||
export function canDeleteArchivedExpenseClaims(user) {
|
||||
return Boolean(user?.isAdmin)
|
||||
return isPlatformAdminUser(user)
|
||||
}
|
||||
|
||||
export function canReturnExpenseClaims(user) {
|
||||
if (Boolean(user?.isAdmin)) {
|
||||
if (isPlatformAdminUser(user)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return normalizedRoleCodes(user).some((roleCode) => CLAIM_RETURN_ROLE_CODES.has(roleCode))
|
||||
}
|
||||
|
||||
export function canApproveLeaderExpenseClaims(user) {
|
||||
if (Boolean(user?.isAdmin)) {
|
||||
return true
|
||||
}
|
||||
export function canApproveLeaderExpenseClaims(user) {
|
||||
if (isPlatformAdminUser(user)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return normalizedRoleCodes(user).some((roleCode) => CLAIM_LEADER_APPROVAL_ROLE_CODES.has(roleCode))
|
||||
}
|
||||
@@ -86,6 +124,14 @@ export function canAccessAppView(user, viewId) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (viewId === 'budget') {
|
||||
if (isPlatformAdminUser(user)) {
|
||||
return true
|
||||
}
|
||||
const roleCodes = normalizedRoleCodes(user)
|
||||
return VIEW_ROLE_RULES.budget.some((roleCode) => roleCodes.includes(roleCode))
|
||||
}
|
||||
|
||||
if (isManagerUser(user)) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -119,16 +119,16 @@ export const BUDGET_CONTROL_ACTION_OPTIONS = ['正常', '提醒', '管控']
|
||||
export const BUDGET_YEAR_OPTIONS = ['2026', '2027', '2028']
|
||||
export const BUDGET_QUARTER_OPTIONS = ['Q1', 'Q2', 'Q3', 'Q4']
|
||||
export const BUDGET_EXPENSE_TYPE_OPTIONS = Object.freeze([
|
||||
{ value: 'travel', label: '差旅费' },
|
||||
{ value: 'travel', label: '差旅' },
|
||||
{ value: 'hotel', label: '住宿费' },
|
||||
{ value: 'transport', label: '交通费' },
|
||||
{ value: 'meal', label: '业务招待费' },
|
||||
{ value: 'meal', label: '招待费' },
|
||||
{ value: 'meeting', label: '会务费' },
|
||||
{ value: 'marketing', label: '市场推广费' },
|
||||
{ value: 'office', label: '办公用品费' },
|
||||
{ value: 'office', label: '办公用品' },
|
||||
{ value: 'training', label: '培训费' },
|
||||
{ value: 'software', label: '软件服务费' },
|
||||
{ value: 'communication', label: '通讯费' },
|
||||
{ value: 'communication', label: '通信' },
|
||||
{ value: 'welfare', label: '福利费' }
|
||||
])
|
||||
|
||||
@@ -139,6 +139,17 @@ const BUDGET_EXPENSE_TYPE_BY_CODE = Object.freeze(
|
||||
}, {})
|
||||
)
|
||||
|
||||
export const BUDGET_VISIBLE_EXPENSE_TYPE_CODES = Object.freeze([
|
||||
'travel',
|
||||
'communication',
|
||||
'meal',
|
||||
'office'
|
||||
])
|
||||
|
||||
export const BUDGET_VISIBLE_EXPENSE_TYPE_OPTIONS = Object.freeze(
|
||||
BUDGET_VISIBLE_EXPENSE_TYPE_CODES.map((code) => BUDGET_EXPENSE_TYPE_BY_CODE[code]).filter(Boolean)
|
||||
)
|
||||
|
||||
export function resolveBudgetExpenseTypeLabel(code, fallback = '') {
|
||||
return BUDGET_EXPENSE_TYPE_BY_CODE[String(code || '').trim()]?.label || fallback
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ const PROMPT_FIELD_LABELS = [
|
||||
]
|
||||
|
||||
export const APPLICATION_EXAMPLES = [
|
||||
'申请下周去北京做客户现场验收,差旅预算18000元',
|
||||
'申请下周去北京做客户现场验收,预计费用18000元',
|
||||
'申请上海产品发布会会务费32000元,需要场地和物料',
|
||||
'申请部门集中采购办公用品4800元,用于新员工入职'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user