优化
This commit is contained in:
@@ -79,6 +79,30 @@ export async function run(context) {
|
||||
`first=${createdStatementId || 'missing'}, replay=${statementId(replay) || 'missing'}`, OPTIONS)
|
||||
if (!createdStatementId) return
|
||||
|
||||
const permissionResponse = await context.request('GET', '/api/platform/v1/iam/authorization/permissions')
|
||||
const permissions = context.apiSuccess(MODULE, '客户详情财务账单查看权限链可用', permissionResponse, '', OPTIONS)
|
||||
const grantedPermissions = new Set(rows(permissions).map((item) => id(item?.permissionCode ?? item)))
|
||||
context.assert(MODULE, '财务账单列表查看权限已授予', permissionResponse,
|
||||
grantedPermissions.has('platform:finance:bill:view') || grantedPermissions.has('platform:finance:customer-statement:list'),
|
||||
`permissions=${[...grantedPermissions].filter((item) => item.includes('finance')).join(',')}`, OPTIONS)
|
||||
|
||||
const statementListResponse = await context.request('GET', `${BASE}/statements?customerId=${encodeURIComponent(customerId)}`)
|
||||
const statementList = context.apiSuccess(MODULE, '客户详情财务账单列表按客户过滤', statementListResponse,
|
||||
`customerId=${customerId}`, OPTIONS)
|
||||
const statementRows = rows(statementList)
|
||||
context.assert(MODULE, '财务账单列表仅返回本轮客户且包含新账单', statementListResponse,
|
||||
statementRows.length > 0 && statementRows.every((item) => id(item?.customerId) === customerId)
|
||||
&& statementRows.some((item) => statementId(item) === createdStatementId),
|
||||
`customerId=${customerId}, statementId=${createdStatementId}, rows=${statementRows.length}`, OPTIONS)
|
||||
|
||||
const statementDetailResponse = await context.request('GET', `${BASE}/reconciliation-statements/${encodeURIComponent(createdStatementId)}`)
|
||||
const statementDetail = context.apiSuccess(MODULE, '读取客户详情财务账单详情', statementDetailResponse,
|
||||
`statementId=${createdStatementId}`, OPTIONS)
|
||||
context.assert(MODULE, '财务账单详情客户与明细修订结构完整', statementDetailResponse,
|
||||
id(statementDetail?.customerId) === customerId && statementId(statementDetail) === createdStatementId
|
||||
&& Array.isArray(statementDetail?.lines) && Array.isArray(statementDetail?.revisions),
|
||||
`customerId=${id(statementDetail?.customerId) || 'missing'}, statementId=${statementId(statementDetail) || 'missing'}, lines=${Array.isArray(statementDetail?.lines)}, revisions=${Array.isArray(statementDetail?.revisions)}`, OPTIONS)
|
||||
|
||||
for (const action of ['SUBMIT', 'APPROVE', 'ISSUE']) {
|
||||
const actionResponse = await write(context, 'POST', `${BASE}/reconciliation-statements/${createdStatementId}/actions`,
|
||||
{ action, expectedVersion: Number(statement.version) }, `statement-${action.toLowerCase()}`)
|
||||
|
||||
Reference in New Issue
Block a user