Commit 348cf714 authored by fangxinjiang's avatar fangxinjiang

代码优化-fxj

parent 79a48d60
......@@ -96,18 +96,44 @@ public class TInsuranceWarnServiceImpl extends ServiceImpl<TInsuranceWarnMapper,
log.error("商险不购买提醒初始化停用客服异常:",e);
}
//处理已经离职数据,分批请求,每次请求1000条数据,返回在职人员信息
R<Set<String>> onlineSet;
R<Set<String>> onlineSetTemp = new R<>();
if (list.size() <= 1000){
if (list.size() <= 2000){
onlineSetTemp = archivesDaprUtil.getEmpOnlineMap(list.stream().map(TInsuranceAlert::getEmpIdcardNo).collect(Collectors.toList()));
}else {
for (int i = 0; i < list.size(); i++) {
if (i % 1000 == 0) {
onlineSet = archivesDaprUtil.getEmpOnlineMap(list.stream().map(TInsuranceAlert::getEmpIdcardNo).collect(Collectors.toList()));
if (null != onlineSet && Common.isNotNull(onlineSet.getData())) {
onlineSetTemp.getData().addAll(onlineSet.getData());
// 提前提取身份证号列表,避免重复 stream 操作
List<String> idCardNoList = list.stream()
.map(TInsuranceAlert::getEmpIdcardNo)
.collect(Collectors.toList());
int batchSize = 2000;
int totalSize = idCardNoList.size();
// 初始化 onlineSetTemp,防止 NullPointerException
if (onlineSetTemp == null) {
onlineSetTemp = new R<>(); // 替换为实际类型
}
R<Set<String>> onlineSet;
Set<String> temp = new HashSet<>();
for (int i = 0; i < totalSize; i++) {
if (i % batchSize == 0) {
// 计算当前批次的结束索引
int end = Math.min(i + batchSize, totalSize);
// 获取当前批次的数据
List<String> subList = idCardNoList.subList(i, end);
// 调用接口获取在职人员信息
onlineSet = archivesDaprUtil.getEmpOnlineMap(subList);
// 判空处理
if (onlineSet != null && onlineSet.getData() != null && Common.isNotNull(onlineSet.getData())) {
temp.addAll(onlineSet.getData());
}
}
}
if (temp != null){
onlineSetTemp.setData(temp);
}
}
//如果不存在离职人员直接走生成逻辑
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment