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.
- package/.feisuan/rules/project_rule.md +122 -0
- package/env.d.ts +14 -0
- package/package.json +1 -1
- package/src/App.vue +117 -11
- package/src/router/index.ts +10 -0
- package/src/views/ForecastInfo/components/FlowInfoPanel.vue +1 -3
- package/src/views/ForecastInfo/components/ForecastInfoPanel.vue +0 -2
- package/src/views/ForecastInfo/store.ts +2 -2
- package/src/views/RmbPositionEstimationView.vue +990 -0
- package/src/views/foreign-currency-position-forecast/api.ts +448 -0
- package/src/views/foreign-currency-position-forecast/components/ForeignPositionForecastEditor.vue +1013 -0
- package/src/views/foreign-currency-position-forecast/editor.ts +32 -0
- package/src/views/foreign-currency-position-forecast/index.vue +1147 -0
- package/src/views/foreign-currency-position-forecast/mock.ts +70 -0
- package/src/views/foreign-currency-position-forecast/options.ts +94 -0
- package/src/views/foreign-currency-position-forecast/store.ts +129 -0
- package/src/views/rmb-position-estimation/api.ts +221 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type ForecastWay = 'PW01' | 'PW02' | 'PW03'
|
|
2
|
+
export type ForecastStatus = 'PS01' | 'PS02' | 'PS03' | 'PS04' | 'PS05' | 'PS06' | 'PS07' | 'PS08'
|
|
3
|
+
export type ForecastType = 'PT01' | 'PT02' | 'PT03'
|
|
4
|
+
export type PaymentDirection = 'I' | 'O'
|
|
5
|
+
export type VerifyStatus = 'VS01' | 'VS02' | 'VS03'
|
|
6
|
+
export type BusinessType = '10' | '11' | '12' | '13'
|
|
7
|
+
export type ForeignExchangeType = '01' | '02' | '03'
|
|
8
|
+
export type ClientType = 'CT01' | 'CT02'
|
|
9
|
+
export type PaymentRoute = '01' | '02' | '03'
|
|
10
|
+
export type UserRole = '006' | '007' | '008'
|
|
11
|
+
|
|
12
|
+
export type ForeignPositionForecast = {
|
|
13
|
+
predRefNo: string
|
|
14
|
+
/** 页面沿用既有拼写:1 已授权,0 未授权。 */
|
|
15
|
+
authirization: '1' | '0'
|
|
16
|
+
/** FTU 标识:1 是,空字符串为否。 */
|
|
17
|
+
filter: '1' | ''
|
|
18
|
+
predWay: ForecastWay
|
|
19
|
+
predStatus: ForecastStatus
|
|
20
|
+
predType: ForecastType
|
|
21
|
+
groundBranch: string
|
|
22
|
+
groundBranchCode: string
|
|
23
|
+
payDirection: PaymentDirection
|
|
24
|
+
bankAccount: string
|
|
25
|
+
paymentRoute: PaymentRoute
|
|
26
|
+
currency: string
|
|
27
|
+
predAmount: number
|
|
28
|
+
valueDate: string
|
|
29
|
+
verifyStatus: VerifyStatus
|
|
30
|
+
verifyAmount: number
|
|
31
|
+
businessType: BusinessType
|
|
32
|
+
clientType: '' | ClientType
|
|
33
|
+
clientId: string
|
|
34
|
+
clientName: string
|
|
35
|
+
clientAccount: string
|
|
36
|
+
counterpartyName: string
|
|
37
|
+
counterpartyAccount: string
|
|
38
|
+
receivingBank: string
|
|
39
|
+
receivingBankSwiftCode: string
|
|
40
|
+
foreignExchangeType: '' | ForeignExchangeType
|
|
41
|
+
counterpartySwiftCode: string
|
|
42
|
+
documentBusinessNo: string
|
|
43
|
+
intermediaryBankSwiftCode: string
|
|
44
|
+
purpose: string
|
|
45
|
+
remark: string
|
|
46
|
+
forecasterName: string
|
|
47
|
+
forecasterCode: string
|
|
48
|
+
forecastDepartment: string
|
|
49
|
+
phoneNumber: string
|
|
50
|
+
forecastTime: string
|
|
51
|
+
approvalTime: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const mockCurrentUser = {
|
|
55
|
+
role: '006' as UserRole,
|
|
56
|
+
userCode: 'HQ00601',
|
|
57
|
+
userName: '总行头寸管理员',
|
|
58
|
+
department: '总行金融市场部',
|
|
59
|
+
phoneNumber: '010-66590001',
|
|
60
|
+
organizationCode: 'HQ001',
|
|
61
|
+
approvalAmountBoundary: 30_000_000,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function pad(value: number) {
|
|
65
|
+
return String(value).padStart(2, '0')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function formatDate(date: Date) {
|
|
69
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
|
70
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type SelectOption = {
|
|
2
|
+
value: string
|
|
3
|
+
label: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const forecastWayOptions = [
|
|
7
|
+
{ value: 'PW01', label: '新增预报' },
|
|
8
|
+
{ value: 'PW02', label: '到期预报' },
|
|
9
|
+
{ value: 'PW03', label: '其他预报' },
|
|
10
|
+
] satisfies SelectOption[]
|
|
11
|
+
|
|
12
|
+
export const forecastStatusOptions = [
|
|
13
|
+
{ value: 'PS01', label: '待分行确认' },
|
|
14
|
+
{ value: 'PS02', label: '待总行确认' },
|
|
15
|
+
{ value: 'PS03', label: '已确认' },
|
|
16
|
+
{ value: 'PS04', label: '分行拒绝' },
|
|
17
|
+
{ value: 'PS05', label: '已删除' },
|
|
18
|
+
{ value: 'PS06', label: '待分行确认删除' },
|
|
19
|
+
{ value: 'PS07', label: '待总行确认删除' },
|
|
20
|
+
{ value: 'PS08', label: '总行拒绝' },
|
|
21
|
+
] satisfies SelectOption[]
|
|
22
|
+
|
|
23
|
+
export const forecastTypeOptions = [
|
|
24
|
+
{ value: 'PT01', label: '提前预报' },
|
|
25
|
+
{ value: 'PT02', label: '当日预报' },
|
|
26
|
+
{ value: 'PT03', label: '当日补报' },
|
|
27
|
+
] satisfies SelectOption[]
|
|
28
|
+
|
|
29
|
+
export const payDirectionOptions = [
|
|
30
|
+
{ value: 'I', label: '收入' },
|
|
31
|
+
{ value: 'O', label: '支出' },
|
|
32
|
+
] satisfies SelectOption[]
|
|
33
|
+
|
|
34
|
+
export const verifyStatusOptions = [
|
|
35
|
+
{ value: 'VS01', label: '未核销' },
|
|
36
|
+
{ value: 'VS02', label: '部分核销' },
|
|
37
|
+
{ value: 'VS03', label: '已核销' },
|
|
38
|
+
] satisfies SelectOption[]
|
|
39
|
+
|
|
40
|
+
export const businessTypeOptions = [
|
|
41
|
+
{ value: '10', label: '普通汇款' },
|
|
42
|
+
{ value: '11', label: '单证业务' },
|
|
43
|
+
{ value: '12', label: '同业/其他业务' },
|
|
44
|
+
{ value: '13', label: '资金调拨' },
|
|
45
|
+
] satisfies SelectOption[]
|
|
46
|
+
|
|
47
|
+
export const foreignExchangeTypeOptions = [
|
|
48
|
+
{ value: '01', label: '结汇' },
|
|
49
|
+
{ value: '02', label: '购汇' },
|
|
50
|
+
{ value: '03', label: '现汇' },
|
|
51
|
+
] satisfies SelectOption[]
|
|
52
|
+
|
|
53
|
+
export const authirizationOptions = [
|
|
54
|
+
{ value: '1', label: '已授权' },
|
|
55
|
+
{ value: '0', label: '未授权' },
|
|
56
|
+
] satisfies SelectOption[]
|
|
57
|
+
|
|
58
|
+
export const ftuFilterOptions = [
|
|
59
|
+
{ value: '1', label: '是' },
|
|
60
|
+
{ value: '0', label: '否' },
|
|
61
|
+
] satisfies SelectOption[]
|
|
62
|
+
|
|
63
|
+
export const currencyOptions = [
|
|
64
|
+
{ value: 'USD', label: 'USD 美元' },
|
|
65
|
+
{ value: 'EUR', label: 'EUR 欧元' },
|
|
66
|
+
{ value: 'HKD', label: 'HKD 港币' },
|
|
67
|
+
{ value: 'JPY', label: 'JPY 日元' },
|
|
68
|
+
{ value: 'GBP', label: 'GBP 英镑' },
|
|
69
|
+
{ value: 'SGD', label: 'SGD 新加坡元' },
|
|
70
|
+
{ value: 'AUD', label: 'AUD 澳元' },
|
|
71
|
+
{ value: 'CAD', label: 'CAD 加拿大元' },
|
|
72
|
+
{ value: 'CHF', label: 'CHF 瑞士法郎' },
|
|
73
|
+
] satisfies SelectOption[]
|
|
74
|
+
|
|
75
|
+
export const clientTypeOptions = [
|
|
76
|
+
{ value: 'CT01', label: '对公客户' },
|
|
77
|
+
{ value: 'CT02', label: '个人客户' },
|
|
78
|
+
] satisfies SelectOption[]
|
|
79
|
+
|
|
80
|
+
export const paymentRouteOptions = [
|
|
81
|
+
{ value: '01', label: '直汇' },
|
|
82
|
+
{ value: '02', label: '转汇' },
|
|
83
|
+
{ value: '03', label: '内部划转' },
|
|
84
|
+
] satisfies SelectOption[]
|
|
85
|
+
|
|
86
|
+
export const organizationOptions = [
|
|
87
|
+
{ value: '总行金融市场部', label: '总行金融市场部', code: 'HQ001' },
|
|
88
|
+
{ value: '北京分行营业部', label: '北京分行营业部', code: 'BJ001' },
|
|
89
|
+
{ value: '上海浦东分行', label: '上海浦东分行', code: 'SH001' },
|
|
90
|
+
{ value: '深圳前海分行', label: '深圳前海分行', code: 'SZ001' },
|
|
91
|
+
{ value: '广州天河支行', label: '广州天河支行', code: 'GZ001' },
|
|
92
|
+
{ value: '杭州分行营业部', label: '杭州分行营业部', code: 'HZ001' },
|
|
93
|
+
{ value: '成都高新分行', label: '成都高新分行', code: 'CD001' },
|
|
94
|
+
]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { computed, reactive, ref } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import type { ForeignPositionForecastQuery } from './api'
|
|
4
|
+
import type { ForecastEditorMode } from './editor'
|
|
5
|
+
import type { ForeignPositionForecast } from './mock'
|
|
6
|
+
|
|
7
|
+
export type FilterState = ForeignPositionForecastQuery
|
|
8
|
+
export type ApprovalAction = 'approve' | 'reject' | null
|
|
9
|
+
export type PageMode = 'list' | 'editor'
|
|
10
|
+
|
|
11
|
+
export function createEmptyFilters(): FilterState {
|
|
12
|
+
return {
|
|
13
|
+
valueDate: '',
|
|
14
|
+
payDirection: '',
|
|
15
|
+
forecastStatuses: [],
|
|
16
|
+
foreignExchangeType: '',
|
|
17
|
+
forecastWay: '',
|
|
18
|
+
verifyStatuses: [],
|
|
19
|
+
organizationName: '',
|
|
20
|
+
clientName: '',
|
|
21
|
+
businessType: '',
|
|
22
|
+
currencies: [],
|
|
23
|
+
authirization: '',
|
|
24
|
+
ftuFilter: '',
|
|
25
|
+
minAmount: null,
|
|
26
|
+
maxAmount: null,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cloneFilters(filters: FilterState): FilterState {
|
|
31
|
+
return {
|
|
32
|
+
...filters,
|
|
33
|
+
forecastStatuses: [...filters.forecastStatuses],
|
|
34
|
+
verifyStatuses: [...filters.verifyStatuses],
|
|
35
|
+
currencies: [...filters.currencies],
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const useForeignPositionForecastStore = defineStore(
|
|
40
|
+
'foreign-currency-position-forecast',
|
|
41
|
+
() => {
|
|
42
|
+
const filterForm = reactive<FilterState>(createEmptyFilters())
|
|
43
|
+
const appliedFilters = ref<FilterState>(createEmptyFilters())
|
|
44
|
+
const successfulFilters = ref<FilterState>(createEmptyFilters())
|
|
45
|
+
const allRows = ref<ForeignPositionForecast[]>([])
|
|
46
|
+
const totalCount = ref(0)
|
|
47
|
+
const selectedRows = ref<ForeignPositionForecast[]>([])
|
|
48
|
+
const selectionResetKey = ref(0)
|
|
49
|
+
const isLoading = ref(false)
|
|
50
|
+
const isQuerying = ref(false)
|
|
51
|
+
const filterCollapsed = ref(true)
|
|
52
|
+
const currentPage = ref(1)
|
|
53
|
+
const pageSize = ref(25)
|
|
54
|
+
const successfulPage = ref(1)
|
|
55
|
+
const successfulPageSize = ref(25)
|
|
56
|
+
|
|
57
|
+
const pageMode = ref<PageMode>('list')
|
|
58
|
+
const editorMode = ref<ForecastEditorMode>('add')
|
|
59
|
+
const editorRecord = ref<ForeignPositionForecast | null>(null)
|
|
60
|
+
const isSaving = ref(false)
|
|
61
|
+
const approvalAction = ref<ApprovalAction>(null)
|
|
62
|
+
|
|
63
|
+
const selectedCurrencyCount = computed(
|
|
64
|
+
() => new Set(selectedRows.value.map((row) => row.currency)).size,
|
|
65
|
+
)
|
|
66
|
+
const hasMixedCurrencySelection = computed(
|
|
67
|
+
() => selectedRows.value.length > 1 && selectedCurrencyCount.value > 1,
|
|
68
|
+
)
|
|
69
|
+
const amountSummary = computed(() => {
|
|
70
|
+
if (selectedRows.value.length === 0 || selectedCurrencyCount.value !== 1) return null
|
|
71
|
+
|
|
72
|
+
const rows = selectedRows.value
|
|
73
|
+
const currency = rows[0]?.currency ?? ''
|
|
74
|
+
const income = rows
|
|
75
|
+
.filter((row) => row.payDirection === 'I')
|
|
76
|
+
.reduce((sum, row) => sum + row.predAmount, 0) / 10_000
|
|
77
|
+
const expense = rows
|
|
78
|
+
.filter((row) => row.payDirection === 'O')
|
|
79
|
+
.reduce((sum, row) => sum + row.predAmount, 0) / 10_000
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
currency,
|
|
83
|
+
source: `已选 ${rows.length} 笔`,
|
|
84
|
+
income,
|
|
85
|
+
expense,
|
|
86
|
+
net: income - expense,
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
const tableHeight = computed(() => (
|
|
90
|
+
filterCollapsed.value ? 'calc(100vh - 330px)' : 'calc(100vh - 430px)'
|
|
91
|
+
))
|
|
92
|
+
|
|
93
|
+
function clearTableSelection() {
|
|
94
|
+
selectedRows.value = []
|
|
95
|
+
selectionResetKey.value += 1
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function resetFilterForm() {
|
|
99
|
+
Object.assign(filterForm, createEmptyFilters())
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
filterForm,
|
|
104
|
+
appliedFilters,
|
|
105
|
+
successfulFilters,
|
|
106
|
+
allRows,
|
|
107
|
+
totalCount,
|
|
108
|
+
selectedRows,
|
|
109
|
+
selectionResetKey,
|
|
110
|
+
isLoading,
|
|
111
|
+
isQuerying,
|
|
112
|
+
filterCollapsed,
|
|
113
|
+
currentPage,
|
|
114
|
+
pageSize,
|
|
115
|
+
successfulPage,
|
|
116
|
+
successfulPageSize,
|
|
117
|
+
pageMode,
|
|
118
|
+
editorMode,
|
|
119
|
+
editorRecord,
|
|
120
|
+
isSaving,
|
|
121
|
+
approvalAction,
|
|
122
|
+
hasMixedCurrencySelection,
|
|
123
|
+
amountSummary,
|
|
124
|
+
tableHeight,
|
|
125
|
+
clearTableSelection,
|
|
126
|
+
resetFilterForm,
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { mockCurrentUser } from '../foreign-currency-position-forecast/mock'
|
|
2
|
+
|
|
3
|
+
const TRAN_CODE = '/TAM/0001/140103006'
|
|
4
|
+
const apiBaseUrl = String(import.meta.env.VITE_API_BASE_URL || 'http://localhost:3011/oms').replace(/\/+$/, '')
|
|
5
|
+
const tamBranchId = String(import.meta.env.VITE_TAM_BRANCH_ID || mockCurrentUser.organizationCode)
|
|
6
|
+
const tamUserId = String(import.meta.env.VITE_TAM_USER_ID || mockCurrentUser.userCode)
|
|
7
|
+
const tamClientIp = String(import.meta.env.VITE_TAM_CLIENT_IP || '')
|
|
8
|
+
|
|
9
|
+
export const rmbPositionAmountFields = [
|
|
10
|
+
'hgPredAmtIn',
|
|
11
|
+
'hgPredAmtOut',
|
|
12
|
+
'hgPredAmtNet',
|
|
13
|
+
'hgUnverifyAmtIn',
|
|
14
|
+
'hgUnverifyAmtOut',
|
|
15
|
+
'hgUnverifyAmtNet',
|
|
16
|
+
'zqPredAmtIn',
|
|
17
|
+
'zqPredAmtOut',
|
|
18
|
+
'zqPredAmtNet',
|
|
19
|
+
'zqUnverifyAmtIn',
|
|
20
|
+
'zqUnverifyAmtOut',
|
|
21
|
+
'zqUnverifyAmtNet',
|
|
22
|
+
'pjPredAmtIn',
|
|
23
|
+
'pjPredAmtOut',
|
|
24
|
+
'pjPredAmtNet',
|
|
25
|
+
'pjUnverifyAmtIn',
|
|
26
|
+
'pjUnverifyAmtOut',
|
|
27
|
+
'pjUnverifyAmtNet',
|
|
28
|
+
'tgPredAmtIn',
|
|
29
|
+
'tgPredAmtOut',
|
|
30
|
+
'tgPredAmtNet',
|
|
31
|
+
'tgUnverifyAmtIn',
|
|
32
|
+
'tgUnverifyAmtOut',
|
|
33
|
+
'tgUnverifyAmtNet',
|
|
34
|
+
'tyPredAmtIn',
|
|
35
|
+
'tyPredAmtOut',
|
|
36
|
+
'tyPredAmtNet',
|
|
37
|
+
'tyUnverifyAmtIn',
|
|
38
|
+
'tyUnverifyAmtOut',
|
|
39
|
+
'tyUnverifyAmtNet',
|
|
40
|
+
'fzhPredAmtIn',
|
|
41
|
+
'fzhPredAmtOut',
|
|
42
|
+
'fzhPredAmtNet',
|
|
43
|
+
'fzhUnverifyAmtIn',
|
|
44
|
+
'fzhUnverifyAmtOut',
|
|
45
|
+
'fzhUnverifyAmtNet',
|
|
46
|
+
'lcPredAmtIn',
|
|
47
|
+
'lcPredAmtOut',
|
|
48
|
+
'lcPredAmtNet',
|
|
49
|
+
'lcUnverifyAmtIn',
|
|
50
|
+
'lcUnverifyAmtOut',
|
|
51
|
+
'lcUnverifyAmtNet',
|
|
52
|
+
'qtPredAmtIn',
|
|
53
|
+
'qtPredAmtOut',
|
|
54
|
+
'qtPredAmtNet',
|
|
55
|
+
'qtUnverifyAmtIn',
|
|
56
|
+
'qtUnverifyAmtOut',
|
|
57
|
+
'qtUnverifyAmtNet',
|
|
58
|
+
'xjAmtIn',
|
|
59
|
+
'xjAmtOut',
|
|
60
|
+
'xjAmtNet',
|
|
61
|
+
'unVerifyAmtIn1',
|
|
62
|
+
'unVerifyAmtOut1',
|
|
63
|
+
'unVerifyAmtNet1',
|
|
64
|
+
'unVerifyAmtIn',
|
|
65
|
+
'unVerifyAmtOut',
|
|
66
|
+
'unVerifyAmtNet',
|
|
67
|
+
'zjPredAmtIn',
|
|
68
|
+
'zjPredAmtOut',
|
|
69
|
+
'zjPredAmtNet',
|
|
70
|
+
'zjUnverifyAmtIn',
|
|
71
|
+
'zjUnverifyAmtOut',
|
|
72
|
+
'zjUnverifyAmtNet',
|
|
73
|
+
] as const
|
|
74
|
+
|
|
75
|
+
export type RmbPositionAmountField = typeof rmbPositionAmountFields[number]
|
|
76
|
+
export type ProtocolAmount = number | '0'
|
|
77
|
+
|
|
78
|
+
export type RmbPositionEstimationRequestBody = {
|
|
79
|
+
overAmt: ProtocolAmount
|
|
80
|
+
tranDate: string
|
|
81
|
+
fzAmtIn: ProtocolAmount
|
|
82
|
+
fzAmtOut: ProtocolAmount
|
|
83
|
+
fzAmtRmk: string
|
|
84
|
+
bepsAmtIn: ProtocolAmount
|
|
85
|
+
bepsAmtOut: ProtocolAmount
|
|
86
|
+
bepsAmtRmk: string
|
|
87
|
+
othAmtIn: ProtocolAmount
|
|
88
|
+
othAmtOut: ProtocolAmount
|
|
89
|
+
othAmtRmk: string
|
|
90
|
+
ysAmtIn: ProtocolAmount
|
|
91
|
+
ysAmtOut: ProtocolAmount
|
|
92
|
+
ysAmtRmk: string
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type RmbPositionEstimationResponseBody = {
|
|
96
|
+
fileName: string
|
|
97
|
+
} & Record<RmbPositionAmountField, string>
|
|
98
|
+
|
|
99
|
+
type TamResponse = {
|
|
100
|
+
head?: {
|
|
101
|
+
retStatus?: string
|
|
102
|
+
retCode?: string
|
|
103
|
+
retMsg?: string
|
|
104
|
+
}
|
|
105
|
+
body?: Record<string, unknown>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type RequestOptions = {
|
|
109
|
+
signal?: AbortSignal
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function pad(value: number) {
|
|
113
|
+
return String(value).padStart(2, '0')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function compactDate(date: Date) {
|
|
117
|
+
return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function compactTime(date: Date) {
|
|
121
|
+
return `${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createConsumerSeqNo(date: Date) {
|
|
125
|
+
return `${tamUserId}${compactDate(date)}${compactTime(date)}${String(date.getMilliseconds()).padStart(3, '0')}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getResponseMessage(payload: TamResponse, fallback: string) {
|
|
129
|
+
return payload.head?.retMsg || fallback
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function normalizeResponseBody(
|
|
133
|
+
source: Record<string, unknown>,
|
|
134
|
+
): RmbPositionEstimationResponseBody {
|
|
135
|
+
const result = {
|
|
136
|
+
fileName: String(source.fileName ?? ''),
|
|
137
|
+
} as RmbPositionEstimationResponseBody
|
|
138
|
+
|
|
139
|
+
rmbPositionAmountFields.forEach((field) => {
|
|
140
|
+
if (!Object.hasOwn(source, field)) {
|
|
141
|
+
throw new Error(`人民币头寸匡算接口缺少返回字段:${field}`)
|
|
142
|
+
}
|
|
143
|
+
const value = String(source[field] ?? '').trim()
|
|
144
|
+
if (!/^-?(?:\d+(?:\.\d+)?|\.\d+)$/.test(value)) {
|
|
145
|
+
throw new Error(`人民币头寸匡算接口金额字段格式不正确:${field}`)
|
|
146
|
+
}
|
|
147
|
+
result[field] = value
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return result
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function requestRmbPositionEstimation(
|
|
154
|
+
body: RmbPositionEstimationRequestBody,
|
|
155
|
+
options: RequestOptions = {},
|
|
156
|
+
) {
|
|
157
|
+
const now = new Date()
|
|
158
|
+
const request = {
|
|
159
|
+
appHead: {
|
|
160
|
+
fileName: '',
|
|
161
|
+
opType: '',
|
|
162
|
+
ip: tamClientIp,
|
|
163
|
+
},
|
|
164
|
+
head: {
|
|
165
|
+
branchId: tamBranchId,
|
|
166
|
+
consumerSeqNo: createConsumerSeqNo(now),
|
|
167
|
+
consumerId: 'TAM001',
|
|
168
|
+
tranCode: TRAN_CODE,
|
|
169
|
+
tranDate: compactDate(now),
|
|
170
|
+
tranTimestamp: compactTime(now),
|
|
171
|
+
pageSize: '10',
|
|
172
|
+
pageIndex: '1',
|
|
173
|
+
traceId: '',
|
|
174
|
+
spanId: '',
|
|
175
|
+
userId: tamUserId,
|
|
176
|
+
versionId: '0001',
|
|
177
|
+
verifyUserId: '',
|
|
178
|
+
adminUserId: '',
|
|
179
|
+
apprUserId: '',
|
|
180
|
+
areaCode: '0000',
|
|
181
|
+
digitalSign: '',
|
|
182
|
+
fileFlag: 'N',
|
|
183
|
+
filePath: '',
|
|
184
|
+
isBatch: false,
|
|
185
|
+
},
|
|
186
|
+
body,
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const response = await fetch(`${apiBaseUrl}${TRAN_CODE}`, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
headers: { 'Content-Type': 'application/json' },
|
|
192
|
+
body: JSON.stringify(request),
|
|
193
|
+
signal: options.signal,
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
let payload: TamResponse
|
|
197
|
+
try {
|
|
198
|
+
payload = await response.json() as TamResponse
|
|
199
|
+
} catch {
|
|
200
|
+
throw new Error(`人民币头寸匡算接口返回的不是有效 JSON(HTTP ${response.status})`)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
204
|
+
throw new Error('人民币头寸匡算接口返回结构不正确')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!response.ok) {
|
|
208
|
+
throw new Error(getResponseMessage(payload, `人民币头寸匡算请求失败(HTTP ${response.status})`))
|
|
209
|
+
}
|
|
210
|
+
if (payload.head?.retStatus !== 'S' || payload.head?.retCode !== '00000') {
|
|
211
|
+
throw new Error(getResponseMessage(payload, '人民币头寸匡算失败'))
|
|
212
|
+
}
|
|
213
|
+
if (!payload.body || typeof payload.body !== 'object' || Array.isArray(payload.body)) {
|
|
214
|
+
throw new Error('人民币头寸匡算接口返回结构不正确')
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
body: normalizeResponseBody(payload.body),
|
|
219
|
+
message: getResponseMessage(payload, '交易成功'),
|
|
220
|
+
}
|
|
221
|
+
}
|