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
43858bd5
Commit
43858bd5
authored
Apr 28, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/test_yh' into test
parents
920ed9f6
4383740e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
31 deletions
+111
-31
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/CommissionExpectedServiceImpl.java
+111
-31
No files found.
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/CommissionExpectedServiceImpl.java
View file @
43858bd5
...
...
@@ -150,11 +150,11 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
return
CommissionExpectedVOPage
;
}
/
/要返回CommissionExpectedNewVO分页记录,现在有一张预计来用表和一张保单来用表。两张表通过commission_expected_biz_id关联,现在要做查询合并两个表结果集,
//预计来用表和保单来用表是1对多的关系,现在想合并两个结果集合,预计来用的主记录在上面下面紧跟着保单来用记录。
//getCommissionExpectedVOPage是之前查询预计来用表记录的逻辑,pageByCommissionexpectedBizId是查询之前保单来用表的逻辑,可以参考这两个逻辑合并写到getCommissionExpectedVONewPage中
//返回记录里面 来佣类型:1-预计(预计来佣表记录) 2-实际(保单来佣表记录)
/
/
/
**
* 应收款管理列表查询
* @param commissionExpectedPage
* @return
*
/
@Override
public
Page
<
CommissionExpectedNewVO
>
getCommissionExpectedVONewPage
(
Page
<
CommissionExpected
>
commissionExpectedPage
)
{
List
<
CommissionExpected
>
commissionExpectedList
=
commissionExpectedPage
.
getRecords
();
...
...
@@ -167,18 +167,18 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
return
resultPage
;
}
//
1.
批量查询实际来佣记录(按预计来佣业务ID分组)
// 批量查询实际来佣记录(按预计来佣业务ID分组)
List
<
String
>
expectedBizIdList
=
commissionExpectedList
.
stream
()
.
map
(
CommissionExpected:
:
getCommissionExpectedBizId
)
.
collect
(
Collectors
.
toList
());
List
<
Commission
>
allCommissions
=
commissionService
.
lambdaQuery
()
.
in
(
Commission:
:
getCommissionExpectedBizId
,
expectedBizIdList
)
.
orderByAsc
(
Commission:
:
getCreateTime
)
// 按创建时间升序,保证从记录顺序
.
orderByAsc
(
Commission:
:
getCreateTime
)
.
list
();
Map
<
String
,
List
<
Commission
>>
commissionMap
=
allCommissions
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
Commission:
:
getCommissionExpectedBizId
));
//
2. 批量查询保单信息(用于填充产品名、保险公司名等
)
//
批量查询保单信息(Policy 和 PolicyFollow
)
Set
<
String
>
policyNoSet
=
new
HashSet
<>();
commissionExpectedList
.
forEach
(
e
->
policyNoSet
.
add
(
e
.
getPolicyNo
()));
allCommissions
.
forEach
(
c
->
policyNoSet
.
add
(
c
.
getPolicyNo
()));
...
...
@@ -200,19 +200,18 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
.
collect
(
Collectors
.
toMap
(
PolicyFollow:
:
getPolicyNo
,
Function
.
identity
(),
(
v1
,
v2
)
->
v1
));
}
//
3.
构建混合结果列表
// 构建混合结果列表
List
<
CommissionExpectedNewVO
>
mixedRecords
=
new
ArrayList
<>();
for
(
CommissionExpected
expected
:
commissionExpectedList
)
{
//
3.1 构建
主记录(预计来佣)
// 主记录(预计来佣)
CommissionExpectedNewVO
mainVo
=
buildMainVo
(
expected
,
policyMap
,
policyFollowMap
);
mixedRecords
.
add
(
mainVo
);
//
3.2 构建
从记录(实际来佣)
// 从记录(实际来佣)
List
<
Commission
>
commissions
=
commissionMap
.
getOrDefault
(
expected
.
getCommissionExpectedBizId
(),
Collections
.
emptyList
());
int
subIndex
=
1
;
for
(
Commission
commission
:
commissions
)
{
CommissionExpectedNewVO
subVo
=
buildSubVo
(
commission
,
policyMap
,
policyFollowMap
,
mainVo
);
// 编号:主编号-序号
subVo
.
setNo
(
mainVo
.
getNo
()
+
"-"
+
subIndex
);
subVo
.
setType
(
2
);
mixedRecords
.
add
(
subVo
);
...
...
@@ -221,11 +220,17 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
}
resultPage
.
setRecords
(
mixedRecords
);
// 回填对账公司名称(类似 enrichReceivableReportWithCompanyName)
enrichCommissionExpectedNewVOWithCompanyName
(
resultPage
);
return
resultPage
;
}
/**
* 构建主记录(预计来佣,type=1)
* 参考 getCommissionExpectedVOPage 的填充逻辑
* 当实佣率 >= 产品对应来佣率时,待入账金额设置为0
*/
private
CommissionExpectedNewVO
buildMainVo
(
CommissionExpected
expected
,
Map
<
String
,
Policy
>
policyMap
,
...
...
@@ -233,37 +238,56 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
CommissionExpectedNewVO
vo
=
new
CommissionExpectedNewVO
();
BeanUtils
.
copyProperties
(
expected
,
vo
);
vo
.
setType
(
1
);
// 主记录编号:
可使用应收账
款编号,若为空则用业务ID
// 主记录编号:
优先使用应收
款编号,若为空则用业务ID
vo
.
setNo
(
StringUtils
.
isNotBlank
(
expected
.
getReceivableNo
())
?
expected
.
getReceivableNo
()
:
expected
.
getCommissionExpectedBizId
());
// 填充保单相关
公共字段
// 填充保单相关
信息(与 getCommissionExpectedVOPage 一致)
Policy
policy
=
policyMap
.
get
(
expected
.
getPolicyNo
());
if
(
policy
!=
null
)
{
vo
.
setPremium
(
policy
.
getPaymentPremium
());
vo
.
setPolicyCurrency
(
policy
.
getCurrency
());
vo
.
setInsuranceCompany
(
policy
.
getInsuranceCompany
());
vo
.
setReconciliationCompany
(
policy
.
getReconciliationCompany
());
vo
.
setReconciliationCompany
(
policy
.
getReconciliationCompany
());
// 临时名称,后续通过公司服务回填
}
// 填充产品计划信息(优先使用 PolicyFollow 中的产品名称)
PolicyFollow
policyFollow
=
policyFollowMap
.
get
(
expected
.
getPolicyNo
());
if
(
policyFollow
!=
null
)
{
vo
.
setProductName
(
policyFollow
.
getProductName
());
vo
.
setProductLaunchBizId
(
policyFollow
.
getProductLaunchBizId
());
}
//
计算待入账比例/金额等
//
获取累计已入账金额、比例(来自预计来佣表)
BigDecimal
paidAmount
=
ObjectUtils
.
defaultIfNull
(
expected
.
getPaidAmount
(),
BigDecimal
.
ZERO
);
BigDecimal
paidRatio
=
ObjectUtils
.
defaultIfNull
(
expected
.
getPaidRatio
(),
BigDecimal
.
ZERO
);
if
(
expected
.
getCommissionRatio
()
!=
null
)
{
// 关联保单应收单(有预期来佣比例)
vo
.
setPaidRatio
(
paidRatio
);
vo
.
setPaidAmount
(
paidAmount
);
// 关键逻辑:累计实佣率是否已达标(实佣率 >= 产品来佣率)
if
(
paidRatio
.
compareTo
(
expected
.
getCommissionRatio
())
>=
0
)
{
// 已达标或超额,待入账金额/比例归零
vo
.
setPendingRatio
(
BigDecimal
.
ZERO
);
vo
.
setPendingAmount
(
BigDecimal
.
ZERO
);
}
else
{
// 未达标,正常计算待入账
vo
.
setPendingRatio
(
expected
.
getCommissionRatio
().
subtract
(
paidRatio
));
if
(
expected
.
getExpectedAmount
()
!=
null
)
{
vo
.
setPaidAmount
(
paidAmount
);
vo
.
setPendingAmount
(
expected
.
getExpectedAmount
().
subtract
(
paidAmount
));
}
}
}
else
{
// 非关联保单应收单(无来佣比例,直接按金额差计算)
vo
.
setPaidAmount
(
paidAmount
);
if
(
expected
.
getAmount
()
!=
null
)
{
vo
.
setPendingAmount
(
expected
.
getAmount
().
subtract
(
paidAmount
));
BigDecimal
pending
=
expected
.
getAmount
().
subtract
(
paidAmount
);
if
(
pending
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
// 已入账金额 >= 预计金额,待入账归零
vo
.
setPendingAmount
(
BigDecimal
.
ZERO
);
}
else
{
vo
.
setPendingAmount
(
pending
);
}
}
}
return
vo
;
...
...
@@ -271,48 +295,104 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
/**
* 构建从记录(实际来佣,type=2)
*
公共字段从主记录复制,实际特有字段使用 commission 数据覆盖
*
参考 getCommissionVOPage 的填充逻辑
*/
private
CommissionExpectedNewVO
buildSubVo
(
Commission
commission
,
Map
<
String
,
Policy
>
policyMap
,
Map
<
String
,
PolicyFollow
>
policyFollowMap
,
CommissionExpectedNewVO
mainVo
)
{
//
1. 从主记录复制所有公共字段(避免重复查询保单信息)
//
从主记录复制公共字段
CommissionExpectedNewVO
vo
=
new
CommissionExpectedNewVO
();
BeanUtils
.
copyProperties
(
mainVo
,
vo
,
"type"
,
"no"
,
"realReconciliationYearMonth"
,
"realCommissionDate"
,
"realExchangeRate"
,
"realAmount"
,
"realCurrentCommissionRatio"
,
"realUpdateTime"
,
"realUpdaterName"
);
// 2. 覆盖实际记录自己的业务字段(从 commission 获取)
// 检核年月、日期、汇率、金额、比例等
// 覆盖实际记录自己的字段
vo
.
setRealReconciliationYearMonth
(
commission
.
getReconciliationYearMonth
());
vo
.
setRealCommissionDate
(
commission
.
getCommissionDate
());
vo
.
setRealExchangeRate
(
commission
.
getExchangeRate
());
vo
.
setRealAmount
(
commission
.
getAmount
());
vo
.
setRealCurrentCommissionRatio
(
commission
.
getCurrentCommissionRatio
());
vo
.
setRealUpdateTime
(
commission
.
getUpdateTime
());
vo
.
setRealUpdaterName
(
commission
.
getUpdaterId
());
// 如有用户服务可查名称
vo
.
setRealUpdaterName
(
commission
.
getUpdaterId
());
//
同时覆盖公共字段中的金额、日期、汇率等,以便前端直接展示实际值
//
覆盖公共业务字段
vo
.
setAmount
(
commission
.
getAmount
());
vo
.
setCommissionDate
(
commission
.
getCommissionDate
());
// vo.setExchangeRate(commission.getExchangeRate());
// vo.setCurrentCommissionRatio(commission.getCurrentCommissionRatio()); // 实际入账比例
// 如果实际记录有更准确的期数、名称等,也一并覆盖(实际表中这些字段应与预计一致,但以防万一)
vo
.
setCommissionPeriod
(
commission
.
getCommissionPeriod
());
vo
.
setCommissionName
(
commission
.
getCommissionName
());
vo
.
setCommissionType
(
commission
.
getCommissionType
());
vo
.
setCurrency
(
commission
.
getCurrency
());
vo
.
setRemark
(
commission
.
getRemark
());
// 保单号以实际记录为准
vo
.
setPolicyNo
(
commission
.
getPolicyNo
());
// 3. 其他展示字段(产品名、保险公司等)已从主记录复制,无需额外处理
// 重新从 policyMap 获取保单信息以确保准确性
Policy
policy
=
policyMap
.
get
(
commission
.
getPolicyNo
());
if
(
policy
!=
null
)
{
vo
.
setPremium
(
policy
.
getPaymentPremium
());
vo
.
setPolicyCurrency
(
policy
.
getCurrency
());
vo
.
setInsuranceCompany
(
policy
.
getInsuranceCompany
());
vo
.
setReconciliationCompany
(
policy
.
getReconciliationCompany
());
}
PolicyFollow
policyFollow
=
policyFollowMap
.
get
(
commission
.
getPolicyNo
());
if
(
policyFollow
!=
null
)
{
vo
.
setProductName
(
policyFollow
.
getProductName
());
vo
.
setProductLaunchBizId
(
policyFollow
.
getProductLaunchBizId
());
}
return
vo
;
}
/**
* 为混合结果集回填对账公司名称(类似 enrichReceivableReportWithCompanyName)
*/
private
void
enrichCommissionExpectedNewVOWithCompanyName
(
Page
<
CommissionExpectedNewVO
>
page
)
{
if
(
page
==
null
||
CollectionUtils
.
isEmpty
(
page
.
getRecords
()))
{
return
;
}
// 收集所有非空的对账公司 bizId(去重)
List
<
String
>
bizIdList
=
page
.
getRecords
().
stream
()
.
map
(
CommissionExpectedNewVO:
:
getReconciliationCompanyBizId
)
.
filter
(
StringUtils:
:
isNotBlank
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
if
(
bizIdList
.
isEmpty
())
{
return
;
}
// 调用 Feign 批量查询对账公司信息
ApiInsuranceReconciliationCompanyPageRequest
request
=
new
ApiInsuranceReconciliationCompanyPageRequest
();
request
.
setReconciliationCompanyBizIdList
(
bizIdList
);
request
.
setPageNo
(
1
);
request
.
setPageSize
(
bizIdList
.
size
());
Result
result
=
companyFeignClient
.
page
(
request
);
List
<
ApiInsuranceReconciliationCompanyPageResponse
>
companyList
=
extractCompanyListFromResult
(
result
);
if
(
companyList
.
isEmpty
())
{
return
;
}
// 构建 bizId -> name 映射
Map
<
String
,
String
>
nameMap
=
companyList
.
stream
()
.
filter
(
c
->
StringUtils
.
isNotBlank
(
c
.
getReconciliationCompanyBizId
()))
.
collect
(
Collectors
.
toMap
(
ApiInsuranceReconciliationCompanyPageResponse:
:
getReconciliationCompanyBizId
,
ApiInsuranceReconciliationCompanyPageResponse:
:
getName
,
(
v1
,
v2
)
->
v1
));
// 回填名称
page
.
getRecords
().
forEach
(
vo
->
{
if
(
StringUtils
.
isNotBlank
(
vo
.
getReconciliationCompanyBizId
()))
{
String
name
=
nameMap
.
get
(
vo
.
getReconciliationCompanyBizId
());
if
(
StringUtils
.
isNotBlank
(
name
))
{
vo
.
setReconciliationCompany
(
name
);
}
}
});
}
private
void
enrichReceivableReportWithCompanyName
(
IPage
<
CommissionExpectedVO
>
page
)
{
if
(
page
==
null
||
CollectionUtils
.
isEmpty
(
page
.
getRecords
()))
{
return
;
...
...
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