feat(mobile-oa-h5): add helpers to auto-submit dfj presign transfers on save
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b217ffcdca
commit
ee95036666
2 files changed
+83
-1
No files matched your search
@@ -145,3 +145,39 @@ export function buildPresignOrderPayload(form = {}, { includeTransfers = true }
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
export function collectDfjTransferIds(transfers) {
|
||||
const rows = Array.isArray(transfers) ? transfers : []
|
||||
return rows
|
||||
.filter((row) => {
|
||||
const id = String(row?.id || '').trim()
|
||||
const status = String(row?.payStatus || 'dfj').trim() || 'dfj'
|
||||
return Boolean(id) && status === 'dfj'
|
||||
})
|
||||
.map((row) => String(row.id).trim())
|
||||
}
|
||||
|
||||
export function formatAutoSubmitFinanceFailureMessage(failures) {
|
||||
const list = Array.isArray(failures) ? failures.filter(Boolean) : []
|
||||
if (!list.length) return ''
|
||||
const reasons = list
|
||||
.map((item) => String(item?.message || item || '提交失败').trim())
|
||||
.filter(Boolean)
|
||||
return `订单已保存,但有 ${list.length} 笔提交财务确认失败:${reasons.join(';')}`
|
||||
}
|
||||
|
||||
export async function submitDfjTransfersOnSave(transfers, submitOne) {
|
||||
const ids = collectDfjTransferIds(transfers)
|
||||
const failures = []
|
||||
for (const id of ids) {
|
||||
try {
|
||||
await submitOne(id)
|
||||
} catch (error) {
|
||||
failures.push({
|
||||
id,
|
||||
message: String(error?.message || error || '提交失败').trim() || '提交失败'
|
||||
})
|
||||
}
|
||||
}
|
||||
return failures
|
||||
}
|
||||
@@ -5,10 +5,13 @@ import {
|
||||
buildPresignOrderPayload,
|
||||
buildPresignTransferPayload,
|
||||
changePresignRegion,
|
||||
collectDfjTransferIds,
|
||||
createPresignForm,
|
||||
formatAutoSubmitFinanceFailureMessage,
|
||||
isPresignLocked,
|
||||
isPresignTransferLocked,
|
||||
mergePersistedTransfer
|
||||
mergePersistedTransfer,
|
||||
submitDfjTransfersOnSave
|
||||
} from './presign-form-state.js'
|
||||
|
||||
test('creates every Web-writable field with mobile defaults', () => {
|
||||
@@ -215,3 +218,46 @@ test('an explicit empty attachment array deletes every transfer attachment', ()
|
||||
transferAttachments: 'fallback.pdf'
|
||||
}).transferAttachments, 'fallback.pdf')
|
||||
})
|
||||
|
||||
test('collectDfjTransferIds only returns paid transfers with server ids', () => {
|
||||
assert.deepEqual(
|
||||
collectDfjTransferIds([
|
||||
{ id: 't1', payStatus: 'dfj' },
|
||||
{ id: 't2', payStatus: 'jfqrz' },
|
||||
{ id: '', payStatus: 'dfj' },
|
||||
{ payStatus: 'dfj' },
|
||||
{ id: 't3', payStatus: 'dfj' },
|
||||
{ id: ' t4 ', payStatus: 'dfj' }
|
||||
]),
|
||||
['t1', 't3', 't4']
|
||||
)
|
||||
assert.deepEqual(collectDfjTransferIds(null), [])
|
||||
})
|
||||
|
||||
test('formatAutoSubmitFinanceFailureMessage summarizes count and reasons', () => {
|
||||
assert.equal(formatAutoSubmitFinanceFailureMessage([]), '')
|
||||
assert.equal(
|
||||
formatAutoSubmitFinanceFailureMessage([
|
||||
{ id: 't1', message: '请选择转账方式' },
|
||||
{ id: 't2', message: '请填写转账金额' }
|
||||
]),
|
||||
'订单已保存,但有 2 笔提交财务确认失败:请选择转账方式;请填写转账金额'
|
||||
)
|
||||
})
|
||||
|
||||
test('submitDfjTransfersOnSave submits only dfj ids and continues after failures', async () => {
|
||||
const calls = []
|
||||
const failures = await submitDfjTransfersOnSave(
|
||||
[
|
||||
{ id: 'ok', payStatus: 'dfj' },
|
||||
{ id: 'skip', payStatus: 'yjf' },
|
||||
{ id: 'bad', payStatus: 'dfj' }
|
||||
],
|
||||
async (id) => {
|
||||
calls.push(id)
|
||||
if (id === 'bad') throw new Error('请填写转账金额')
|
||||
}
|
||||
)
|
||||
assert.deepEqual(calls, ['ok', 'bad'])
|
||||
assert.deepEqual(failures, [{ id: 'bad', message: '请填写转账金额' }])
|
||||
})
|
||||
Reference in new issue
Block a user