|
|
@@ -1,12 +1,17 @@ |
|
|
|
package com.ningdatech.pmapi.ding.task; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.ningdatech.basic.model.GenericResult; |
|
|
|
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; |
|
|
|
import com.ningdatech.pmapi.organization.model.entity.DingOrganization; |
|
|
|
import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; |
|
|
|
import com.ningdatech.pmapi.organization.service.IDingOrganizationService; |
|
|
|
import com.ningdatech.pmapi.user.constant.UserAvailableEnum; |
|
|
|
import com.ningdatech.pmapi.user.entity.UserInfo; |
|
|
|
import com.ningdatech.pmapi.user.service.IUserInfoService; |
|
|
|
import com.ningdatech.zwdd.ZwddIntegrationProperties; |
|
|
|
import com.ningdatech.zwdd.client.ZwddClient; |
|
|
|
import com.ningdatech.zwdd.model.Page; |
|
|
@@ -20,9 +25,7 @@ import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@@ -49,6 +52,9 @@ public class EmployeeBatchGetTask { |
|
|
|
@Autowired |
|
|
|
private ZwddIntegrationProperties zwddIntegrationProperties; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IUserInfoService iUserInfoService; |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void batchGetEmployeeTask() { |
|
|
|
|
|
|
@@ -107,16 +113,18 @@ public class EmployeeBatchGetTask { |
|
|
|
List<String> employeeCodes = segment.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); |
|
|
|
GenericResult<List<EmployeeAccountIdDTO>> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); |
|
|
|
List<EmployeeAccountIdDTO> employeeAccountIdDTOList = listGenericResult.getData(); |
|
|
|
Map<String, Long> employeeCodeAccountIdMap = employeeAccountIdDTOList.stream() |
|
|
|
.collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); |
|
|
|
if (CollUtil.isNotEmpty(employeeAccountIdDTOList)) { |
|
|
|
Map<String, Long> employeeCodeAccountIdMap = employeeAccountIdDTOList.stream().filter(Objects::nonNull) |
|
|
|
.collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); |
|
|
|
|
|
|
|
List<DingEmployeeInfo> dingEmployeeInfos = buildDingEmployeeInfoRecordList(segment); |
|
|
|
List<DingEmployeeInfo> dingEmployeeInfos = buildDingEmployeeInfoRecordList(segment); |
|
|
|
|
|
|
|
dingEmployeeInfos = dingEmployeeInfos.stream().map(r -> { |
|
|
|
r.setAccountId(employeeCodeAccountIdMap.get(r.getEmployeeCode())); |
|
|
|
return r; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
dingEmployeeInfoSaveRecordList.addAll(dingEmployeeInfos); |
|
|
|
dingEmployeeInfos = dingEmployeeInfos.stream().map(r -> { |
|
|
|
r.setAccountId(employeeCodeAccountIdMap.get(r.getEmployeeCode())); |
|
|
|
return r; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
dingEmployeeInfoSaveRecordList.addAll(dingEmployeeInfos); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private List<DingEmployeeInfo> buildDingEmployeeInfoRecordList(List<OrganizationEmployeePosition> allOrganizationEmployeePositionList) { |
|
|
@@ -154,13 +162,66 @@ public class EmployeeBatchGetTask { |
|
|
|
} |
|
|
|
|
|
|
|
private void saveBatch(List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList) { |
|
|
|
if (dingEmployeeInfoSaveRecordList.size() <= GROUP_SIZE) { |
|
|
|
iDingEmployeeInfoService.saveBatch(dingEmployeeInfoSaveRecordList); |
|
|
|
} else { |
|
|
|
List<List<DingEmployeeInfo>> split = Lists.partition(dingEmployeeInfoSaveRecordList, GROUP_SIZE); |
|
|
|
for (List<DingEmployeeInfo> segment : split) { |
|
|
|
iDingEmployeeInfoService.saveBatch(segment); |
|
|
|
dingEmployeeInfoSaveRecordList = dingEmployeeInfoSaveRecordList.stream() |
|
|
|
.filter(r -> "true".equals(r.getMainJob()) |
|
|
|
&& "A".equals(r.getEmpStatus()) |
|
|
|
&& StringUtils.isNotBlank(r.getOrganizationCode()) |
|
|
|
&& StringUtils.isNotBlank(r.getEmployeeCode()) |
|
|
|
).collect(Collectors.toList()); |
|
|
|
|
|
|
|
Set<String> uniqueKeySet = new HashSet<String>(); |
|
|
|
|
|
|
|
List<DingEmployeeInfo> saveList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (DingEmployeeInfo dingEmployeeInfo : dingEmployeeInfoSaveRecordList) { |
|
|
|
if (uniqueKeySet.add(dingEmployeeInfo.getEmployeeCode() + dingEmployeeInfo.getOrganizationCode())) { |
|
|
|
saveList.add(dingEmployeeInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (DingEmployeeInfo dingEmployeeInfo : saveList) { |
|
|
|
String employeeCode = dingEmployeeInfo.getEmployeeCode(); |
|
|
|
|
|
|
|
DingEmployeeInfo employeeInfo = iDingEmployeeInfoService.getOne(Wrappers.lambdaQuery(DingEmployeeInfo.class) |
|
|
|
.eq(DingEmployeeInfo::getOrganizationCode, dingEmployeeInfo.getOrganizationCode()) |
|
|
|
.eq(DingEmployeeInfo::getEmployeeCode, employeeCode)); |
|
|
|
if (Objects.isNull(employeeInfo)) { |
|
|
|
iDingEmployeeInfoService.save(dingEmployeeInfo); |
|
|
|
} else { |
|
|
|
dingEmployeeInfo.setId(employeeInfo.getId()); |
|
|
|
iDingEmployeeInfoService.saveOrUpdate(dingEmployeeInfo); |
|
|
|
} |
|
|
|
generateOrUpdateUserInfo(dingEmployeeInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void generateOrUpdateUserInfo(DingEmployeeInfo dingEmployeeInfo) { |
|
|
|
String employeeCode = dingEmployeeInfo.getEmployeeCode(); |
|
|
|
UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) |
|
|
|
.eq(UserInfo::getEmployeeCode, employeeCode)); |
|
|
|
if (Objects.isNull(userInfo)) { |
|
|
|
userInfo = UserInfo.builder() |
|
|
|
.accountId(dingEmployeeInfo.getAccountId()) |
|
|
|
.username(dingEmployeeInfo.getEmployeeName()) |
|
|
|
.realName(dingEmployeeInfo.getEmployeeName()) |
|
|
|
.employeeCode(dingEmployeeInfo.getEmployeeCode()) |
|
|
|
.available(UserAvailableEnum.DISABLE.name()) |
|
|
|
.createBy(-1L) |
|
|
|
.updateBy(-1L) |
|
|
|
.createOn(LocalDateTime.now()) |
|
|
|
.updateOn(LocalDateTime.now()) |
|
|
|
.build(); |
|
|
|
iUserInfoService.save(userInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// if (saveList.size() <= GROUP_SIZE) { |
|
|
|
// iDingEmployeeInfoService.saveBatch(saveList); |
|
|
|
// } else { |
|
|
|
// List<List<DingEmployeeInfo>> split = Lists.partition(saveList, GROUP_SIZE); |
|
|
|
// for (List<DingEmployeeInfo> segment : split) { |
|
|
|
// iDingEmployeeInfoService.saveBatch(segment); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
} |