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
f8d82c99
Commit
f8d82c99
authored
Nov 27, 2025
by
jianan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新单跟进112
parent
a8574718
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
18 deletions
+85
-18
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/CommissionServiceImpl.java
+85
-18
No files found.
yd-csf-service/src/main/java/com/yd/csf/service/service/impl/CommissionServiceImpl.java
View file @
f8d82c99
...
@@ -33,6 +33,7 @@ import javax.annotation.Resource;
...
@@ -33,6 +33,7 @@ import javax.annotation.Resource;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.math.RoundingMode
;
import
java.util.*
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -237,6 +238,11 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
...
@@ -237,6 +238,11 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
}
}
}
}
// 构建保单号+期次的复合键集合
Set
<
String
>
commissionPolicyPeriodKeys
=
commissionList
.
stream
()
.
map
(
commission
->
buildPolicyPeriodKey
(
commission
.
getPolicyNo
(),
commission
.
getCommissionPeriod
()))
.
collect
(
Collectors
.
toSet
());
// 3. 根据保单号查询所有发佣记录
// 3. 根据保单号查询所有发佣记录
List
<
Fortune
>
fortuneList
=
fortuneService
.
list
(
new
QueryWrapper
<
Fortune
>().
in
(
"policy_no"
,
policyNoSet
));
List
<
Fortune
>
fortuneList
=
fortuneService
.
list
(
new
QueryWrapper
<
Fortune
>().
in
(
"policy_no"
,
policyNoSet
));
...
@@ -248,11 +254,10 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
...
@@ -248,11 +254,10 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
}
}
}
}
// 5. 筛
出来佣对应的预计发佣记录
// 5. 筛
选匹配的预计发佣记录(优化性能)
List
<
ExpectedFortune
>
filteredExpectedFortuneList
=
expectedFortuneList
.
stream
()
List
<
ExpectedFortune
>
filteredExpectedFortuneList
=
expectedFortuneList
.
stream
()
.
filter
(
expectedFortune
->
commissionList
.
stream
()
.
filter
(
expectedFortune
->
commissionPolicyPeriodKeys
.
contains
(
.
anyMatch
(
commission
->
StringUtils
.
equals
(
commission
.
getPolicyNo
(),
expectedFortune
.
getPolicyNo
())
buildPolicyPeriodKey
(
expectedFortune
.
getPolicyNo
(),
expectedFortune
.
getFortunePeriod
())))
&&
commission
.
getCommissionPeriod
().
equals
(
expectedFortune
.
getFortunePeriod
())))
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
// 6.删除旧的发佣记录
// 6.删除旧的发佣记录
...
@@ -265,31 +270,93 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
...
@@ -265,31 +270,93 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
List
<
Fortune
>
policyPaidFortuneList
=
fortuneService
.
list
(
fortuneQueryWrapper
);
List
<
Fortune
>
policyPaidFortuneList
=
fortuneService
.
list
(
fortuneQueryWrapper
);
// 7.2 构建实际的初始发佣记录
// 7.2 构建实际的初始发佣记录
List
<
Fortune
>
newFortuneList
=
new
ArrayList
<>();
List
<
Fortune
>
newFortuneList
=
buildNewFortunes
(
filteredExpectedFortuneList
,
commissionList
,
policyPaidFortuneList
);
for
(
ExpectedFortune
expectedFortune
:
filteredExpectedFortuneList
)
{
// List<Fortune> newFortuneList = new ArrayList<>();
// for (ExpectedFortune expectedFortune : filteredExpectedFortuneList) {
// Fortune fortune = new Fortune();
// BeanUtils.copyProperties(expectedFortune, fortune);
//
// fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
// fortune.setStatus(FortuneStatusEnum.WAIT.getItemValue());
// // 关联来佣业务ID
// matchCommission(fortune, commissionList);
// // 扣减已发薪资
// calculateCurrentFortune(fortune, policyPaidFortuneList);
//
// fortune.setCreateTime(new Date());
// fortune.setUpdateTime(new Date());
//
// newFortuneList.add(fortune);
// }
// 10. 保存发佣记录
saveNewFortunes
(
newFortuneList
);
return
true
;
}
/**
* 保存新的发佣记录
*/
private
void
saveNewFortunes
(
List
<
Fortune
>
newFortuneList
)
{
if
(
CollectionUtils
.
isEmpty
(
newFortuneList
))
{
throw
new
BusinessException
(
ResultCode
.
FAIL
.
getCode
(),
"没有可保存的发佣记录"
);
}
boolean
saveSuccess
=
fortuneService
.
saveBatch
(
newFortuneList
);
if
(!
saveSuccess
)
{
throw
new
BusinessException
(
ResultCode
.
FAIL
.
getCode
(),
"保存发佣记录失败"
);
}
}
/**
* 构建新的发佣记录
*/
private
List
<
Fortune
>
buildNewFortunes
(
List
<
ExpectedFortune
>
filteredExpectedFortuneList
,
List
<
Commission
>
commissionList
,
List
<
Fortune
>
policyPaidFortuneList
)
{
// 构建来佣记录映射,用于快速查找
Map
<
String
,
Commission
>
commissionByPolicyPeriod
=
commissionList
.
stream
()
.
collect
(
Collectors
.
toMap
(
commission
->
buildPolicyPeriodKey
(
commission
.
getPolicyNo
(),
commission
.
getCommissionPeriod
()),
Function
.
identity
()
));
Date
now
=
new
Date
();
return
filteredExpectedFortuneList
.
stream
()
.
map
(
expectedFortune
->
{
Fortune
fortune
=
new
Fortune
();
Fortune
fortune
=
new
Fortune
();
BeanUtils
.
copyProperties
(
expectedFortune
,
fortune
);
BeanUtils
.
copyProperties
(
expectedFortune
,
fortune
);
fortune
.
setFortuneBizId
(
RandomStringGenerator
.
generateBizId16
(
CommonEnum
.
UID_TYPE_FORTUNE
.
getCode
()));
fortune
.
setFortuneBizId
(
RandomStringGenerator
.
generateBizId16
(
CommonEnum
.
UID_TYPE_FORTUNE
.
getCode
()));
fortune
.
setStatus
(
FortuneStatusEnum
.
WAIT
.
getItemValue
());
fortune
.
setStatus
(
FortuneStatusEnum
.
WAIT
.
getItemValue
());
// 关联来佣业务ID
// 关联来佣业务ID
matchCommission
(
fortune
,
commissionList
);
String
key
=
buildPolicyPeriodKey
(
expectedFortune
.
getPolicyNo
(),
expectedFortune
.
getFortunePeriod
());
Commission
matchedCommission
=
commissionByPolicyPeriod
.
get
(
key
);
if
(
matchedCommission
!=
null
)
{
fortune
.
setCommissionBizId
(
matchedCommission
.
getCommissionBizId
());
}
else
{
fortune
.
setStatus
(
FortuneStatusEnum
.
MATCH_FAIL
.
getItemValue
());
fortune
.
setRemark
(
"未找到当前预计发佣对应的来佣"
);
}
// 扣减已发薪资
// 扣减已发薪资
calculateCurrentFortune
(
fortune
,
policyPaidFortuneList
);
calculateCurrentFortune
(
fortune
,
policyPaidFortuneList
);
fortune
.
setCreateTime
(
new
Date
()
);
fortune
.
setCreateTime
(
now
);
fortune
.
setUpdateTime
(
new
Date
()
);
fortune
.
setUpdateTime
(
now
);
newFortuneList
.
add
(
fortune
);
return
fortune
;
}
})
// 8. 保存发佣记录
.
collect
(
Collectors
.
toList
());
if
(
CollUtil
.
isNotEmpty
(
newFortuneList
))
{
boolean
saveSuccess
=
fortuneService
.
saveBatch
(
newFortuneList
);
if
(!
saveSuccess
)
{
throw
new
BusinessException
(
ResultCode
.
FAIL
.
getCode
(),
"保存发佣记录失败"
);
}
}
}
return
true
;
/**
* 构建保单号+期次的唯一键
*/
private
String
buildPolicyPeriodKey
(
String
policyNo
,
Object
period
)
{
return
(
policyNo
==
null
?
""
:
policyNo
)
+
"|"
+
(
period
==
null
?
""
:
period
.
toString
());
}
}
private
void
calculateCurrentFortune
(
Fortune
fortune
,
List
<
Fortune
>
policyPaidFortuneList
)
{
private
void
calculateCurrentFortune
(
Fortune
fortune
,
List
<
Fortune
>
policyPaidFortuneList
)
{
...
...
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