Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-csf
Commits
dcc902b4
Commit
dcc902b4
authored
Jan 14, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
3dd03e29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
63 deletions
+71
-63
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiPremiumReconciliationServiceImpl.java
+71
-63
No files found.
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiPremiumReconciliationServiceImpl.java
View file @
dcc902b4
...
...
@@ -43,9 +43,11 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Slf4j
@Service
...
...
@@ -193,7 +195,8 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
// 首先收集所有需要转换的请求
List
<
ApiExchangeRateConvertRequest
>
convertRequests
=
new
ArrayList
<>();
Map
<
String
,
ConvertInfo
>
convertInfoMap
=
new
HashMap
<>();
// 改为使用列表保存转换信息,按顺序匹配
List
<
ConvertInfo
>
convertInfoList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
List
<
ApiPremiumRemittanceDto
>>
entry
:
reconciliationRemittanceMap
.
entrySet
())
{
String
reconciliationBizId
=
entry
.
getKey
();
...
...
@@ -216,6 +219,7 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
// 初始化总金额
BigDecimal
totalAmount
=
BigDecimal
.
ZERO
;
String
paymentCurrency
=
policyCurrency
;
// 首先处理相同币种的汇款记录
int
sameCurrencyCount
=
0
;
...
...
@@ -263,7 +267,7 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
}
}
// 生成唯一请求ID
// 生成唯一请求ID
- 但汇率服务可能不返回,所以我们主要依赖顺序匹配
String
requestId
=
reconciliationBizId
+
"_"
+
(
StringUtils
.
isNotBlank
(
remittanceDto
.
getPremiumRemittanceBizId
())
?
remittanceDto
.
getPremiumRemittanceBizId
()
:
UUID
.
randomUUID
().
toString
());
...
...
@@ -271,13 +275,14 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
convertRequests
.
add
(
convertRequest
);
// 保存转换信息
// 保存转换信息
到列表(按顺序)
ConvertInfo
info
=
new
ConvertInfo
();
info
.
reconciliationBizId
=
reconciliationBizId
;
info
.
originalAmount
=
amount
;
info
.
originalCurrency
=
remittanceCurrency
;
info
.
targetCurrency
=
policyCurrency
;
convertInfoMap
.
put
(
requestId
,
info
);
info
.
requestId
=
requestId
;
// 保存requestId,如果汇率服务返回则使用
convertInfoList
.
add
(
info
);
}
log
.
debug
(
"需要转换的汇款记录数: {}"
,
convertCount
);
...
...
@@ -285,7 +290,7 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
// 先保存相同币种的累计金额
totalAmount
=
totalAmount
.
setScale
(
2
,
RoundingMode
.
HALF_EVEN
);
totalPaymentAmounts
.
put
(
reconciliationBizId
,
totalAmount
);
paymentCurrencies
.
put
(
reconciliationBizId
,
p
olicy
Currency
);
paymentCurrencies
.
put
(
reconciliationBizId
,
p
ayment
Currency
);
log
.
info
(
"对账记录 {} 初始总金额: {} {}"
,
reconciliationBizId
,
totalAmount
,
policyCurrency
);
}
...
...
@@ -300,6 +305,7 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
for
(
int
i
=
0
;
i
<
convertRequests
.
size
();
i
+=
batchSize
)
{
int
end
=
Math
.
min
(
convertRequests
.
size
(),
i
+
batchSize
);
List
<
ApiExchangeRateConvertRequest
>
batch
=
convertRequests
.
subList
(
i
,
end
);
List
<
ConvertInfo
>
batchConvertInfos
=
convertInfoList
.
subList
(
i
,
end
);
log
.
info
(
"发送第 {} 批汇率转换请求,共 {} 条"
,
i
/
batchSize
+
1
,
batch
.
size
());
...
...
@@ -311,10 +317,35 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
log
.
info
(
"收到第 {} 批汇率转换响应,共 {} 条"
,
i
/
batchSize
+
1
,
batchResult
.
getData
().
size
());
// 处理转换结果
for
(
ApiExchangeRateConvertResponse
convertResponse
:
batchResult
.
getData
())
{
String
requestId
=
convertResponse
.
getRequestId
();
ConvertInfo
info
=
convertInfoMap
.
get
(
requestId
);
// 处理转换结果 - 使用顺序匹配
List
<
ApiExchangeRateConvertResponse
>
responses
=
batchResult
.
getData
();
// 确保响应数量与请求数量一致
if
(
responses
.
size
()
!=
batch
.
size
())
{
log
.
warn
(
"汇率转换响应数量({})与请求数量({})不一致,可能无法正确匹配"
,
responses
.
size
(),
batch
.
size
());
}
// 处理每个转换结果
for
(
int
j
=
0
;
j
<
Math
.
min
(
responses
.
size
(),
batch
.
size
());
j
++)
{
ApiExchangeRateConvertResponse
convertResponse
=
responses
.
get
(
j
);
ConvertInfo
info
=
null
;
// 首先尝试通过requestId匹配
if
(
StringUtils
.
isNotBlank
(
convertResponse
.
getRequestId
()))
{
// 如果汇率服务返回了requestId,则从整个列表中查找
for
(
ConvertInfo
ci
:
convertInfoList
)
{
if
(
convertResponse
.
getRequestId
().
equals
(
ci
.
requestId
))
{
info
=
ci
;
break
;
}
}
}
// 如果通过requestId没有找到,则使用顺序匹配
if
(
info
==
null
&&
j
<
batchConvertInfos
.
size
())
{
info
=
batchConvertInfos
.
get
(
j
);
}
if
(
info
!=
null
&&
convertResponse
.
getConvertedAmount
()
!=
null
)
{
BigDecimal
currentTotal
=
totalPaymentAmounts
.
getOrDefault
(
info
.
reconciliationBizId
,
BigDecimal
.
ZERO
);
...
...
@@ -332,8 +363,32 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
log
.
debug
(
"对账记录 {} 累加后总金额: {} (之前: {} + 转换: {})"
,
info
.
reconciliationBizId
,
newTotal
,
currentTotal
,
convertedAmount
);
}
else
{
log
.
warn
(
"转换结果缺少必要信息: requestId={}, info={}, convertedAmount={}"
,
requestId
,
info
,
convertResponse
.
getConvertedAmount
());
log
.
warn
(
"转换结果缺少必要信息或无法匹配: requestId={}, info={}, convertedAmount={}"
,
convertResponse
.
getRequestId
(),
info
,
convertResponse
.
getConvertedAmount
());
// 尝试通过其他方式匹配
if
(
convertResponse
.
getOriginalAmount
()
!=
null
&&
StringUtils
.
isNotBlank
(
convertResponse
.
getOriginalCurrency
())
&&
StringUtils
.
isNotBlank
(
convertResponse
.
getTargetCurrency
()))
{
// 通过金额、原币种和目标币种匹配
for
(
ConvertInfo
ci
:
convertInfoList
)
{
if
(
convertResponse
.
getOriginalAmount
().
compareTo
(
ci
.
originalAmount
)
==
0
&&
convertResponse
.
getOriginalCurrency
().
equalsIgnoreCase
(
ci
.
originalCurrency
)
&&
convertResponse
.
getTargetCurrency
().
equalsIgnoreCase
(
ci
.
targetCurrency
))
{
info
=
ci
;
BigDecimal
convertedAmount
=
convertResponse
.
getConvertedAmount
();
if
(
convertedAmount
!=
null
)
{
BigDecimal
currentTotal
=
totalPaymentAmounts
.
getOrDefault
(
info
.
reconciliationBizId
,
BigDecimal
.
ZERO
);
convertedAmount
=
convertedAmount
.
setScale
(
2
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
newTotal
=
currentTotal
.
add
(
convertedAmount
);
totalPaymentAmounts
.
put
(
info
.
reconciliationBizId
,
newTotal
);
log
.
info
(
"通过金额和币种匹配成功: 对账记录={}, 累加金额={}"
,
info
.
reconciliationBizId
,
convertedAmount
);
}
break
;
}
}
}
}
}
}
else
{
...
...
@@ -356,9 +411,9 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
BigDecimal
totalAmount
=
totalPaymentAmounts
.
get
(
reconciliationBizId
);
String
paymentCurrency
=
paymentCurrencies
.
get
(
reconciliationBizId
);
log
.
info
(
"更新对账记录 {}: 付款金额={} {}, 原paymentAmount={} {}"
,
log
.
info
(
"更新对账记录 {}: 付款金额={} {}, 原paymentAmount={} {}
, 原paymentCurrency={}
"
,
reconciliationBizId
,
totalAmount
,
paymentCurrency
,
item
.
getPaymentAmount
(),
item
.
getPaymentCurrency
());
item
.
getPaymentAmount
(),
item
.
getPaymentCurrency
()
,
item
.
getPaymentCurrency
()
);
item
.
setPaymentAmount
(
totalAmount
);
...
...
@@ -383,57 +438,9 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
BigDecimal
originalAmount
;
String
originalCurrency
;
String
targetCurrency
;
String
requestId
;
// 添加requestId字段
}
// 内部类,用于保存转换请求信息
private
static
class
ConvertRequestInfo
{
private
String
reconciliationBizId
;
private
String
remittanceBizId
;
private
BigDecimal
originalAmount
;
private
String
originalCurrency
;
private
String
targetCurrency
;
// getters and setters
public
String
getReconciliationBizId
()
{
return
reconciliationBizId
;
}
public
void
setReconciliationBizId
(
String
reconciliationBizId
)
{
this
.
reconciliationBizId
=
reconciliationBizId
;
}
public
String
getRemittanceBizId
()
{
return
remittanceBizId
;
}
public
void
setRemittanceBizId
(
String
remittanceBizId
)
{
this
.
remittanceBizId
=
remittanceBizId
;
}
public
BigDecimal
getOriginalAmount
()
{
return
originalAmount
;
}
public
void
setOriginalAmount
(
BigDecimal
originalAmount
)
{
this
.
originalAmount
=
originalAmount
;
}
public
String
getOriginalCurrency
()
{
return
originalCurrency
;
}
public
void
setOriginalCurrency
(
String
originalCurrency
)
{
this
.
originalCurrency
=
originalCurrency
;
}
public
String
getTargetCurrency
()
{
return
targetCurrency
;
}
public
void
setTargetCurrency
(
String
targetCurrency
)
{
this
.
targetCurrency
=
targetCurrency
;
}
}
/**
* 获取缴费方式字典数据
*/
...
...
@@ -941,4 +948,4 @@ public class ApiPremiumReconciliationServiceImpl implements ApiPremiumReconcilia
return
Result
.
success
(
premiumReconciliation
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment