|
|
@@ -7,6 +7,7 @@ import cn.com.taiji.core.entity.user.AccountInfo; |
|
|
|
import cn.com.taiji.core.entity.user.Staff; |
|
|
|
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo; |
|
|
|
import cn.com.taiji.core.repo.jpa.user.StaffRepo; |
|
|
|
import cn.com.taiji.userw.model.MyFinals; |
|
|
|
import cn.com.taiji.userw.model.excel.StaffRegisterData; |
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
@@ -29,6 +30,7 @@ public class StaffRegisterDataListener implements ReadListener<StaffRegisterData |
|
|
|
private Set<StaffRegisterData> errors = new HashSet<>(); |
|
|
|
private List<StaffRegisterData> result = new ArrayList<>(); |
|
|
|
private String opneId; |
|
|
|
private String agencyId; |
|
|
|
|
|
|
|
public StaffRegisterDataListener(AccountInfoRepo accountInfoRepo, StaffRepo staffRepo) { |
|
|
|
this.accountInfoRepo = accountInfoRepo; |
|
|
@@ -43,6 +45,11 @@ public class StaffRegisterDataListener implements ReadListener<StaffRegisterData |
|
|
|
if (isEmpty(data.getMobile())) builder.append("员工手机号码不能为空").append(","); |
|
|
|
if (isEmpty(data.getAgencyId())) builder.append("员工发行渠道编号不能为空").append(","); |
|
|
|
if (isEmpty(data.getServiceHallId())) builder.append("员工网点编号不能为空").append(","); |
|
|
|
if (!MyFinals.QTZL_AGENCY_ID.equals(agencyId)){ |
|
|
|
if (!agencyId.equals(data.getAgencyId())){ |
|
|
|
builder.append("非黔通人员只允许导入本渠道的员工").append(","); |
|
|
|
} |
|
|
|
} |
|
|
|
if (hasText(builder.toString())) { |
|
|
|
data.setRemark(builder.substring(0, builder.length() - 1).toString()); |
|
|
|
errors.add(data); |
|
|
@@ -54,12 +61,70 @@ public class StaffRegisterDataListener implements ReadListener<StaffRegisterData |
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed(AnalysisContext context) { |
|
|
|
if (CollectionTools.isEmpty(result)) return; |
|
|
|
//处理相同手机号或证件号 |
|
|
|
handleMobilAndIdNum(); |
|
|
|
|
|
|
|
List<AccountInfo> accountInfoList = result.stream().map(this::handleAccountInfoData).collect(Collectors.toList()); |
|
|
|
List<Staff> staffList = result.stream().map(data -> handleStaffData(data, accountInfoList)).collect(Collectors.toList()); |
|
|
|
accountInfoRepo.saveAll(accountInfoList); |
|
|
|
staffRepo.saveAll(staffList); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleMobilAndIdNum() { |
|
|
|
//按 mobile和IdNum 分组,找出重复的数据 |
|
|
|
Map<String, List<StaffRegisterData>> mobileAndIdNumGroups = result.stream() |
|
|
|
.collect(Collectors.groupingBy(data -> data.getMobile() + "|" + data.getIdNum())); |
|
|
|
// 收集重复数据 |
|
|
|
List<StaffRegisterData> duplicates1 = new ArrayList<>(); |
|
|
|
mobileAndIdNumGroups.values().stream() |
|
|
|
.filter(list -> list.size() > 1) // 手机号重复的数据 |
|
|
|
.flatMap(List::stream) |
|
|
|
.forEach(data -> { |
|
|
|
data.setRemark("错误:导入的数据中有相同的手机号:" + data.getMobile() + ";错误:导入的数据中有相同的证件号:"+ data.getIdNum() + ";"); |
|
|
|
duplicates1.add(data); |
|
|
|
}); |
|
|
|
// 从 result 中移除重复数据 |
|
|
|
result.removeAll(duplicates1); |
|
|
|
// 将重复数据加入 errors |
|
|
|
errors.addAll(duplicates1); |
|
|
|
|
|
|
|
|
|
|
|
// 按 mobile 分组 |
|
|
|
Map<String, List<StaffRegisterData>> mobileGroups = result.stream() |
|
|
|
.collect(Collectors.groupingBy(StaffRegisterData::getMobile)); |
|
|
|
// 收集重复数据 |
|
|
|
List<StaffRegisterData> duplicates2 = new ArrayList<>(); |
|
|
|
mobileGroups.values().stream() |
|
|
|
.filter(list -> list.size() > 1) // 手机号重复的数据 |
|
|
|
.flatMap(List::stream) |
|
|
|
.forEach(data -> { |
|
|
|
data.setRemark("错误:导入的数据中有相同的手机号:" + data.getMobile() + ";"); |
|
|
|
duplicates2.add(data); |
|
|
|
}); |
|
|
|
// 从 result 中移除重复数据 |
|
|
|
result.removeAll(duplicates2); |
|
|
|
// 将重复数据加入 errors |
|
|
|
errors.addAll(duplicates2); |
|
|
|
|
|
|
|
|
|
|
|
// 按 idNum 分组 |
|
|
|
Map<String, List<StaffRegisterData>> idNumGroups = result.stream() |
|
|
|
.collect(Collectors.groupingBy(StaffRegisterData::getIdNum)); |
|
|
|
List<StaffRegisterData> duplicates3 = new ArrayList<>(); |
|
|
|
|
|
|
|
idNumGroups.values().stream() |
|
|
|
.filter(list -> list.size() > 1) // 证件号重复的数据 |
|
|
|
.flatMap(List::stream) |
|
|
|
.forEach(data -> { |
|
|
|
data.setRemark("错误:导入的数据中有相同的证件号:" + data.getIdNum() + ";"); |
|
|
|
duplicates3.add(data); |
|
|
|
}); |
|
|
|
// 从 result 中移除重复数据 |
|
|
|
result.removeAll(duplicates3); |
|
|
|
// 将重复数据加入 errors |
|
|
|
errors.addAll(duplicates3); |
|
|
|
} |
|
|
|
|
|
|
|
private AccountInfo handleAccountInfoData(StaffRegisterData data) { |
|
|
|
AccountInfo accountInfo = accountInfoRepo.findByAccount(data.getMobile()); |
|
|
|
if (accountInfo == null) { |
|
|
@@ -141,4 +206,8 @@ public class StaffRegisterDataListener implements ReadListener<StaffRegisterData |
|
|
|
public void setOpenId(String openId) { |
|
|
|
this.opneId = openId; |
|
|
|
} |
|
|
|
|
|
|
|
public void setAgencyId(String agencyId){ |
|
|
|
this.agencyId = agencyId; |
|
|
|
} |
|
|
|
} |