verce-vue-test 0.0.74 → 0.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,448 @@
1
+ import {
2
+ formatDate,
3
+ mockCurrentUser,
4
+ type BusinessType,
5
+ type ClientType,
6
+ type ForecastStatus,
7
+ type ForecastType,
8
+ type ForecastWay,
9
+ type ForeignExchangeType,
10
+ type ForeignPositionForecast,
11
+ type PaymentDirection,
12
+ type VerifyStatus,
13
+ } from './mock'
14
+ import { organizationOptions } from './options'
15
+ import type { ForecastEditorValue } from './editor'
16
+
17
+ const QUERY_TRAN_CODE = '/TAM/0001/140201001'
18
+ const AUTHORIZATION_TRAN_CODE = '/TAM/0001/120201006'
19
+ const apiBaseUrl = String(import.meta.env.VITE_API_BASE_URL || 'http://localhost:3011/oms').replace(/\/+$/, '')
20
+
21
+ export type ForeignPositionForecastQuery = {
22
+ valueDate: string
23
+ payDirection: '' | PaymentDirection
24
+ forecastStatuses: ForecastStatus[]
25
+ foreignExchangeType: '' | ForeignExchangeType
26
+ forecastWay: '' | ForecastWay
27
+ verifyStatuses: VerifyStatus[]
28
+ organizationName: string
29
+ clientName: string
30
+ businessType: '' | BusinessType
31
+ currencies: string[]
32
+ authirization: '' | '1' | '0'
33
+ ftuFilter: '' | '1' | '0'
34
+ minAmount: number | null
35
+ maxAmount: number | null
36
+ }
37
+
38
+ export type ForeignPositionForecastSort = {
39
+ amtOrder: '' | '1' | '2'
40
+ predOrder: '' | '1' | '2'
41
+ timeOrder: '' | '1' | '2'
42
+ }
43
+
44
+ type TamResultInfo = {
45
+ predRefNo?: string
46
+ predWay?: string
47
+ predStatus?: string
48
+ predType?: string
49
+ groundBranch?: string
50
+ payDirec?: string
51
+ bankAcct?: string
52
+ ccy?: string
53
+ predAmt?: string
54
+ tranDate?: string
55
+ verifyStatus?: string
56
+ verifyAmt?: string
57
+ tranType?: string
58
+ clientName?: string
59
+ clientAcct?: string
60
+ competName?: string
61
+ competAcct?: string
62
+ rcvBank?: string
63
+ rcvBankSc?: string
64
+ originalForeign?: string
65
+ predDate?: string
66
+ updateTime?: string
67
+ competAcctSc?: string
68
+ docbusinessno?: string
69
+ midBankSc?: string
70
+ predName?: string
71
+ predCode?: string
72
+ predDept?: string
73
+ phoneNo?: string
74
+ authorization?: string
75
+ remark?: string
76
+ }
77
+
78
+ type TamResponse = {
79
+ head?: {
80
+ retStatus?: string
81
+ retCode?: string
82
+ retMsg?: string
83
+ }
84
+ body?: {
85
+ totalPage?: string | number
86
+ totalCount?: string | number
87
+ resultInfos?: TamResultInfo[]
88
+ }
89
+ }
90
+
91
+ type ApiErrorResponse = {
92
+ error?: {
93
+ message?: string
94
+ }
95
+ }
96
+
97
+ type ForeignPositionForecastOperationResponse = {
98
+ success: boolean
99
+ message: string
100
+ resultList: ForeignPositionForecast[]
101
+ }
102
+
103
+ export type ForeignPositionForecastQueryResult = {
104
+ resultList: ForeignPositionForecast[]
105
+ totalCount: number
106
+ totalPage: number
107
+ }
108
+
109
+ export type ForeignPositionClient = {
110
+ id: string
111
+ name: string
112
+ account: string
113
+ }
114
+
115
+ function pad(value: number) {
116
+ return String(value).padStart(2, '0')
117
+ }
118
+
119
+ function compactDate(date: Date) {
120
+ return formatDate(date).replaceAll('-', '')
121
+ }
122
+
123
+ function compactTime(date: Date) {
124
+ return `${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
125
+ }
126
+
127
+ function createConsumerSeqNo(date: Date) {
128
+ return `${mockCurrentUser.userCode}${compactDate(date)}${compactTime(date)}${String(date.getMilliseconds()).padStart(3, '0')}`
129
+ }
130
+
131
+ function toProtocolStatusList(values: string[], prefix: 'PS' | 'VS') {
132
+ return values
133
+ .map((value) => value.replace(prefix, ''))
134
+ .map((value) => String(Number(value)))
135
+ .join(',')
136
+ }
137
+
138
+ function toNumber(value: unknown) {
139
+ const number = Number(String(value ?? '').replaceAll(',', ''))
140
+ return Number.isFinite(number) ? number : 0
141
+ }
142
+
143
+ function toForecastWay(value: string | undefined): ForecastWay {
144
+ return value === 'PW02' || value === 'PW03' ? value : 'PW01'
145
+ }
146
+
147
+ function toForecastStatus(value: string | undefined): ForecastStatus {
148
+ const number = Number(String(value || '').replace(/^PS/i, ''))
149
+ return number >= 1 && number <= 8
150
+ ? `PS${String(number).padStart(2, '0')}` as ForecastStatus
151
+ : 'PS01'
152
+ }
153
+
154
+ function toForecastType(value: string | undefined): ForecastType {
155
+ return value === 'PT02' || value === 'PT03' ? value : 'PT01'
156
+ }
157
+
158
+ function toVerifyStatus(value: string | undefined): VerifyStatus {
159
+ const number = Number(String(value || '').replace(/^VS/i, ''))
160
+ return number >= 1 && number <= 3
161
+ ? `VS${String(number).padStart(2, '0')}` as VerifyStatus
162
+ : 'VS01'
163
+ }
164
+
165
+ function toBusinessType(value: string | undefined): BusinessType {
166
+ return value === '11' || value === '12' || value === '13' ? value : '10'
167
+ }
168
+
169
+ function toForeignExchangeType(value: string | undefined): '' | ForeignExchangeType {
170
+ return value === '01' || value === '02' || value === '03' ? value : ''
171
+ }
172
+
173
+ function toFrontendRow(row: TamResultInfo): ForeignPositionForecast {
174
+ const organization = organizationOptions.find((option) => option.code === row.groundBranch)
175
+ const clientName = String(row.clientName || '')
176
+
177
+ return {
178
+ predRefNo: String(row.predRefNo || ''),
179
+ authirization: row.authorization === '1' ? '1' : '0',
180
+ filter: '',
181
+ predWay: toForecastWay(row.predWay),
182
+ predStatus: toForecastStatus(row.predStatus),
183
+ predType: toForecastType(row.predType),
184
+ groundBranch: organization?.value || String(row.groundBranch || ''),
185
+ groundBranchCode: String(row.groundBranch || organization?.code || ''),
186
+ payDirection: row.payDirec === 'O' ? 'O' : 'I',
187
+ bankAccount: String(row.bankAcct || ''),
188
+ paymentRoute: '01',
189
+ currency: String(row.ccy || ''),
190
+ predAmount: toNumber(row.predAmt),
191
+ valueDate: String(row.tranDate || '').slice(0, 10),
192
+ verifyStatus: toVerifyStatus(row.verifyStatus),
193
+ verifyAmount: toNumber(row.verifyAmt),
194
+ businessType: toBusinessType(row.tranType),
195
+ clientType: (clientName ? 'CT01' : '') as '' | ClientType,
196
+ clientId: '',
197
+ clientName,
198
+ clientAccount: String(row.clientAcct || ''),
199
+ counterpartyName: String(row.competName || ''),
200
+ counterpartyAccount: String(row.competAcct || ''),
201
+ receivingBank: String(row.rcvBank || ''),
202
+ receivingBankSwiftCode: String(row.rcvBankSc || ''),
203
+ foreignExchangeType: toForeignExchangeType(row.originalForeign),
204
+ counterpartySwiftCode: String(row.competAcctSc || ''),
205
+ documentBusinessNo: String(row.docbusinessno || ''),
206
+ intermediaryBankSwiftCode: String(row.midBankSc || ''),
207
+ purpose: '',
208
+ remark: String(row.remark || ''),
209
+ forecasterName: String(row.predName || ''),
210
+ forecasterCode: String(row.predCode || ''),
211
+ forecastDepartment: String(row.predDept || ''),
212
+ phoneNumber: String(row.phoneNo || ''),
213
+ forecastTime: String(row.predDate || ''),
214
+ approvalTime: String(row.updateTime || ''),
215
+ }
216
+ }
217
+
218
+ function getResponseMessage(payload: TamResponse, fallback: string) {
219
+ return payload.head?.retMsg || fallback
220
+ }
221
+
222
+ async function requestJson<T>(path: string, init: RequestInit = {}): Promise<T> {
223
+ const response = await fetch(`${apiBaseUrl}${path}`, {
224
+ ...init,
225
+ headers: {
226
+ 'Content-Type': 'application/json',
227
+ ...init.headers,
228
+ },
229
+ })
230
+
231
+ let payload: T | ApiErrorResponse
232
+ try {
233
+ payload = await response.json() as T | ApiErrorResponse
234
+ } catch {
235
+ throw new Error(`接口返回的不是有效 JSON(HTTP ${response.status})`)
236
+ }
237
+
238
+ if (!response.ok) {
239
+ const message = (payload as ApiErrorResponse).error?.message
240
+ throw new Error(message || `请求失败(HTTP ${response.status})`)
241
+ }
242
+
243
+ return payload as T
244
+ }
245
+
246
+ export function getForeignPositionForecast(predRefNo: string, signal?: AbortSignal) {
247
+ return requestJson<ForeignPositionForecast>(
248
+ `/foreign-position-forecasts/${encodeURIComponent(predRefNo)}`,
249
+ { signal },
250
+ )
251
+ }
252
+
253
+ export function searchForeignPositionClients(keyword: string, signal?: AbortSignal) {
254
+ return requestJson<ForeignPositionClient[]>(
255
+ `/clients/search?keyword=${encodeURIComponent(keyword.trim())}`,
256
+ { signal },
257
+ )
258
+ }
259
+
260
+ export function createForeignPositionForecast(value: ForecastEditorValue) {
261
+ return requestJson<ForeignPositionForecast>('/foreign-position-forecasts', {
262
+ method: 'POST',
263
+ body: JSON.stringify(value),
264
+ })
265
+ }
266
+
267
+ export function updateForeignPositionForecast(predRefNo: string, value: ForecastEditorValue) {
268
+ return requestJson<ForeignPositionForecast>(
269
+ `/foreign-position-forecasts/${encodeURIComponent(predRefNo)}`,
270
+ {
271
+ method: 'PATCH',
272
+ body: JSON.stringify(value),
273
+ },
274
+ )
275
+ }
276
+
277
+ export function deleteForeignPositionForecast(predRefNo: string) {
278
+ return requestJson<ForeignPositionForecast>(
279
+ `/foreign-position-forecasts/${encodeURIComponent(predRefNo)}`,
280
+ { method: 'DELETE' },
281
+ )
282
+ }
283
+
284
+ export function approveForeignPositionForecasts(predRefNos: string[], approved: boolean) {
285
+ return requestJson<ForeignPositionForecastOperationResponse>('/foreign-position-forecasts/approval', {
286
+ method: 'POST',
287
+ body: JSON.stringify({ predRefNos, approved }),
288
+ })
289
+ }
290
+
291
+ export async function updateForeignPositionForecastAuthorization(
292
+ predRefNo: string,
293
+ authorization: ForeignPositionForecast['authirization'],
294
+ pageIndex: number,
295
+ pageSize: number,
296
+ ) {
297
+ const now = new Date()
298
+ const request = {
299
+ appHead: {
300
+ fileName: '',
301
+ opType: '',
302
+ ip: '10.51.106.161',
303
+ },
304
+ head: {
305
+ branchId: mockCurrentUser.organizationCode,
306
+ consumerSeqNo: createConsumerSeqNo(now),
307
+ consumerId: 'TAM001',
308
+ tranCode: AUTHORIZATION_TRAN_CODE,
309
+ tranDate: compactDate(now),
310
+ tranTimestamp: compactTime(now),
311
+ pageSize,
312
+ pageIndex,
313
+ traceId: '',
314
+ spanId: '',
315
+ userId: mockCurrentUser.userCode,
316
+ versionId: '0001',
317
+ verifyUserId: '',
318
+ adminUserId: '',
319
+ apprUserId: '',
320
+ areaCode: '0000',
321
+ digitalSign: '',
322
+ fileFlag: 'N',
323
+ filePath: '',
324
+ isBatch: false,
325
+ },
326
+ body: {
327
+ authorization,
328
+ predRefNos: predRefNo,
329
+ },
330
+ }
331
+
332
+ const response = await fetch(`${apiBaseUrl}${AUTHORIZATION_TRAN_CODE}`, {
333
+ method: 'POST',
334
+ headers: { 'Content-Type': 'application/json' },
335
+ body: JSON.stringify(request),
336
+ })
337
+
338
+ let payload: TamResponse
339
+ try {
340
+ payload = await response.json() as TamResponse
341
+ } catch {
342
+ throw new Error('授权接口返回的不是有效 JSON')
343
+ }
344
+
345
+ const fallbackMessage = authorization === '1' ? '授权失败' : '取消授权失败'
346
+ if (!response.ok) {
347
+ throw new Error(getResponseMessage(payload, `${fallbackMessage}(HTTP ${response.status})`))
348
+ }
349
+ if (payload.head?.retStatus !== 'S' || payload.head?.retCode !== '00000') {
350
+ throw new Error(getResponseMessage(payload, fallbackMessage))
351
+ }
352
+
353
+ return getResponseMessage(payload, authorization === '1' ? '授权成功' : '取消授权成功')
354
+ }
355
+
356
+ export async function queryForeignPositionForecasts(
357
+ filters: ForeignPositionForecastQuery,
358
+ pageIndex: number,
359
+ pageSize: number,
360
+ sort: ForeignPositionForecastSort = {
361
+ amtOrder: '1',
362
+ predOrder: '',
363
+ timeOrder: '',
364
+ },
365
+ signal?: AbortSignal,
366
+ ): Promise<ForeignPositionForecastQueryResult> {
367
+ const now = new Date()
368
+ const request = {
369
+ appHead: {
370
+ fileName: '',
371
+ opType: '',
372
+ ip: '',
373
+ },
374
+ head: {
375
+ branchId: mockCurrentUser.organizationCode,
376
+ consumerSeqNo: createConsumerSeqNo(now),
377
+ consumerId: 'TAM001',
378
+ tranCode: QUERY_TRAN_CODE,
379
+ tranDate: compactDate(now),
380
+ tranTimestamp: compactTime(now),
381
+ pageSize,
382
+ pageIndex,
383
+ traceId: '',
384
+ spanId: '',
385
+ userId: mockCurrentUser.userCode,
386
+ versionId: '0001',
387
+ verifyUserId: '',
388
+ adminUserId: '',
389
+ apprUserId: '',
390
+ areaCode: '0000',
391
+ digitalSign: '',
392
+ fileFlag: 'N',
393
+ filePath: '',
394
+ isBatch: false,
395
+ },
396
+ body: {
397
+ orgName: filters.organizationName.trim(),
398
+ clientName: filters.clientName.trim(),
399
+ tranType: filters.businessType,
400
+ ccy: filters.currencies.join(','),
401
+ tranDate: filters.valueDate,
402
+ payDirec: filters.payDirection,
403
+ predStatus: toProtocolStatusList(filters.forecastStatuses, 'PS'),
404
+ originalForeign: filters.foreignExchangeType,
405
+ predWay: filters.forecastWay,
406
+ verifyStatus: toProtocolStatusList(filters.verifyStatuses, 'VS'),
407
+ startAmt: filters.minAmount === null ? '' : String(filters.minAmount),
408
+ endAmt: filters.maxAmount === null ? '' : String(filters.maxAmount),
409
+ filter: filters.ftuFilter,
410
+ authorization: filters.authirization,
411
+ amtOrder: sort.amtOrder,
412
+ predOrder: sort.predOrder,
413
+ timeOrder: sort.timeOrder,
414
+ },
415
+ }
416
+
417
+ const response = await fetch(`${apiBaseUrl}${QUERY_TRAN_CODE}`, {
418
+ method: 'POST',
419
+ headers: { 'Content-Type': 'application/json' },
420
+ body: JSON.stringify(request),
421
+ signal,
422
+ })
423
+
424
+ let payload: TamResponse
425
+ try {
426
+ payload = await response.json() as TamResponse
427
+ } catch {
428
+ throw new Error('外币头寸预报接口返回的不是有效 JSON')
429
+ }
430
+
431
+ if (!response.ok) throw new Error(getResponseMessage(payload, `查询失败(HTTP ${response.status})`))
432
+ if (payload.head?.retStatus !== 'S' || payload.head?.retCode !== '00000') {
433
+ throw new Error(getResponseMessage(payload, '外币头寸预报查询失败'))
434
+ }
435
+ const responseBody = payload.body
436
+ if (!responseBody || !Array.isArray(responseBody.resultInfos)) {
437
+ throw new Error('外币头寸预报接口返回结构不正确')
438
+ }
439
+
440
+ const totalCount = Number(responseBody.totalCount)
441
+ const totalPage = Number(responseBody.totalPage)
442
+
443
+ return {
444
+ resultList: responseBody.resultInfos.map(toFrontendRow),
445
+ totalCount: Number.isFinite(totalCount) ? totalCount : responseBody.resultInfos.length,
446
+ totalPage: Number.isFinite(totalPage) ? totalPage : 0,
447
+ }
448
+ }