|
|
@@ -0,0 +1,224 @@ |
|
|
|
package com.ningdatech.pmapi.irs; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.ningdatech.basic.function.VUtils; |
|
|
|
import com.ningdatech.basic.model.GenericResult; |
|
|
|
import com.ningdatech.pmapi.AppTests; |
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
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; |
|
|
|
import com.ningdatech.zwdd.model.dto.EmployeeAccountIdDTO; |
|
|
|
import com.ningdatech.zwdd.model.query.PageOrganizationEmployeePositionsQuery; |
|
|
|
import com.ningdatech.zwdd.model.response.OrganizationEmployeePosition; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Classname EmployeeTest |
|
|
|
* @Description |
|
|
|
* @Date 2023/9/11 10:59 |
|
|
|
* @Author PoffyZhang |
|
|
|
*/ |
|
|
|
public class EmployeeTest extends AppTests { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IDingOrganizationService iDingOrganizationService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ZwddIntegrationProperties zwddIntegrationProperties; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IDingEmployeeInfoService iDingEmployeeInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ZwddClient zwddClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IUserInfoService iUserInfoService; |
|
|
|
|
|
|
|
@Test |
|
|
|
public void test(){ |
|
|
|
String orgCode = "GO_3663776dcc2c414db2ed947e225bfc5b"; |
|
|
|
DingOrganization org = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) |
|
|
|
.eq(DingOrganization::getOrganizationCode, orgCode) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
VUtils.isTrue(Objects.isNull(org)).throwMessage("单位不存在"); |
|
|
|
System.out.println("所属单位 {} 要更新员工信息了:" + org.getOrganizationName()); |
|
|
|
|
|
|
|
List<OrganizationEmployeePosition> allOrganizationEmployeePositionList = new ArrayList<>(); |
|
|
|
String organizationCode = orgCode; |
|
|
|
PageOrganizationEmployeePositionsQuery query = new PageOrganizationEmployeePositionsQuery(); |
|
|
|
query.setEmployeeStatus("A"); |
|
|
|
query.setOrganizationCode(organizationCode); |
|
|
|
query.setReturnTotalSize(true); |
|
|
|
query.setTenantId(zwddIntegrationProperties.getTenantId()); |
|
|
|
int pageNo = 1; |
|
|
|
query.setPageNo(pageNo); |
|
|
|
query.setPageSize(100); |
|
|
|
|
|
|
|
// 查询组织下 用户信息 |
|
|
|
GenericResult<Page<OrganizationEmployeePosition>> firstPageGenericResult = zwddClient.pageOrganizationEmployeePositions(query); |
|
|
|
Page<OrganizationEmployeePosition> data = firstPageGenericResult.getData(); |
|
|
|
if (Objects.isNull(data)){ |
|
|
|
System.out.println("响应为空:{}" + organizationCode); |
|
|
|
return; |
|
|
|
} |
|
|
|
System.out.println(JSON.toJSONString(data.getData())); |
|
|
|
if (CollUtil.isNotEmpty(data.getData())) { |
|
|
|
allOrganizationEmployeePositionList.addAll(data.getData()); |
|
|
|
} |
|
|
|
Long totalSize = data.getTotalSize(); |
|
|
|
|
|
|
|
System.out.println("dingOrganization :{}" + JSON.toJSONString(org)); |
|
|
|
|
|
|
|
System.out.println("totalSize :{},{}" + totalSize + "," + org.getOrganizationName()); |
|
|
|
|
|
|
|
List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList = new ArrayList<>(); |
|
|
|
assemblerAccountId(allOrganizationEmployeePositionList, dingEmployeeInfoSaveRecordList); |
|
|
|
System.out.println("dingEmployeeInfoSaveRecordList :{}" + JSON.toJSONString(dingEmployeeInfoSaveRecordList)); |
|
|
|
// 批量保存用户信息 |
|
|
|
saveBatch(dingEmployeeInfoSaveRecordList); |
|
|
|
} |
|
|
|
|
|
|
|
private void saveBatch(List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList) { |
|
|
|
dingEmployeeInfoSaveRecordList = dingEmployeeInfoSaveRecordList.stream() |
|
|
|
.filter(r -> ("true".equals(r.getMainJob()) |
|
|
|
&& "A".equals(r.getEmpStatus()) |
|
|
|
&& StringUtils.isNotBlank(r.getEmpPosUnitCode()) |
|
|
|
&& StringUtils.isNotBlank(r.getEmployeeCode())) |
|
|
|
|| "GE_48606ed7c10d4d15b0f931a9a4b89f21".equals(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.getEmpPosUnitCode())) { |
|
|
|
saveList.add(dingEmployeeInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<DingOrganization> organizations = iDingOrganizationService.list(); |
|
|
|
Map<String, DingOrganization> organizationMap = organizations.stream().collect(Collectors.toMap(DingOrganization::getOrganizationCode, o -> o)); |
|
|
|
|
|
|
|
System.out.println("saveList:" + JSON.toJSONString(saveList)); |
|
|
|
for (DingEmployeeInfo dingEmployeeInfo : saveList) { |
|
|
|
String employeeCode = dingEmployeeInfo.getEmployeeCode(); |
|
|
|
|
|
|
|
DingEmployeeInfo employeeInfo = iDingEmployeeInfoService.getOne(Wrappers.lambdaQuery(DingEmployeeInfo.class) |
|
|
|
.eq(DingEmployeeInfo::getEmployeeCode, employeeCode) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
if (Objects.isNull(employeeInfo)) { |
|
|
|
iDingEmployeeInfoService.save(dingEmployeeInfo); |
|
|
|
} else { |
|
|
|
dingEmployeeInfo.setId(employeeInfo.getId()); |
|
|
|
iDingEmployeeInfoService.saveOrUpdate(dingEmployeeInfo); |
|
|
|
} |
|
|
|
generateOrUpdateUserInfo(dingEmployeeInfo,organizationMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void assemblerAccountId(List<OrganizationEmployeePosition> segment, List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList) { |
|
|
|
List<String> employeeCodes = segment.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); |
|
|
|
GenericResult<List<EmployeeAccountIdDTO>> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); |
|
|
|
List<EmployeeAccountIdDTO> employeeAccountIdDTOList = listGenericResult.getData(); |
|
|
|
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); |
|
|
|
|
|
|
|
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) { |
|
|
|
List<DingEmployeeInfo> saveRecordList = new ArrayList<>(); |
|
|
|
for (OrganizationEmployeePosition organizationEmployeePosition : allOrganizationEmployeePositionList) { |
|
|
|
List<OrganizationEmployeePosition.GovEmployeePosition> govEmployeePositions = organizationEmployeePosition.getGovEmployeePositions(); |
|
|
|
if (CollUtil.isNotEmpty(govEmployeePositions)) { |
|
|
|
List<DingEmployeeInfo> segmentSaveRecordList = new ArrayList<>(); |
|
|
|
for (OrganizationEmployeePosition.GovEmployeePosition govEmployeePosition : govEmployeePositions) { |
|
|
|
DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); |
|
|
|
BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); |
|
|
|
dingEmployeeInfo.setMainJob(govEmployeePosition.getMainJob()); |
|
|
|
dingEmployeeInfo.setEmpPosUnitCode(govEmployeePosition.getEmpPosUnitCode()); |
|
|
|
dingEmployeeInfo.setEmpPosEmployeeRoleCode(govEmployeePosition.getEmpPosEmployeeRoleCode()); |
|
|
|
dingEmployeeInfo.setEmpPosInnerInstitutionCode(govEmployeePosition.getEmpPosInnerInstitutionCode()); |
|
|
|
dingEmployeeInfo.setEmployeeCode(govEmployeePosition.getEmployeeCode()); |
|
|
|
dingEmployeeInfo.setJobAttributesCode(govEmployeePosition.getJobAttributesCode()); |
|
|
|
dingEmployeeInfo.setOrganizationCode(govEmployeePosition.getOrganizationCode()); |
|
|
|
dingEmployeeInfo.setEmpPosVirtualOrganizationCode(govEmployeePosition.getEmpPosVirtualOrganizationCode()); |
|
|
|
dingEmployeeInfo.setEmpStatus(govEmployeePosition.getStatus()); |
|
|
|
dingEmployeeInfo.setCreateOn(LocalDateTime.now()); |
|
|
|
dingEmployeeInfo.setUpdateOn(LocalDateTime.now()); |
|
|
|
dingEmployeeInfo.setCreateBy(-1L); |
|
|
|
dingEmployeeInfo.setUpdateBy(-1L); |
|
|
|
segmentSaveRecordList.add(dingEmployeeInfo); |
|
|
|
} |
|
|
|
saveRecordList.addAll(segmentSaveRecordList); |
|
|
|
} else { |
|
|
|
DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); |
|
|
|
BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); |
|
|
|
saveRecordList.add(dingEmployeeInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
return saveRecordList; |
|
|
|
} |
|
|
|
|
|
|
|
public void generateOrUpdateUserInfo(DingEmployeeInfo dingEmployeeInfo,Map<String, DingOrganization> organizationMap) { |
|
|
|
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()) |
|
|
|
.empPosUnitCode(dingEmployeeInfo.getEmpPosUnitCode()) |
|
|
|
.avatar(dingEmployeeInfo.getAvatar()) |
|
|
|
.build(); |
|
|
|
if(StringUtils.isNotBlank(userInfo.getEmpPosUnitCode()) && organizationMap.containsKey(userInfo.getEmpPosUnitCode())){ |
|
|
|
DingOrganization dingOrganization = organizationMap.get(userInfo.getEmpPosUnitCode()); |
|
|
|
userInfo.setEmpPosUnitName(dingOrganization.getOrganizationName()); |
|
|
|
userInfo.setRegionCode(dingOrganization.getDivisionCode()); |
|
|
|
} |
|
|
|
iUserInfoService.save(userInfo); |
|
|
|
}else{ |
|
|
|
userInfo.setAvatar(dingEmployeeInfo.getAvatar()); |
|
|
|
userInfo.setEmpPosUnitCode(dingEmployeeInfo.getEmpPosUnitCode()); |
|
|
|
if(StringUtils.isNotBlank(userInfo.getEmpPosUnitCode()) && organizationMap.containsKey(userInfo.getEmpPosUnitCode())){ |
|
|
|
DingOrganization dingOrganization = organizationMap.get(userInfo.getEmpPosUnitCode()); |
|
|
|
userInfo.setEmpPosUnitName(dingOrganization.getOrganizationName()); |
|
|
|
userInfo.setRegionCode(dingOrganization.getDivisionCode()); |
|
|
|
} |
|
|
|
iUserInfoService.updateById(userInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |