Bladeren bron

每日更新员工

master
PoffyZhang 1 jaar geleden
bovenliggende
commit
5ed5b1f572
4 gewijzigde bestanden met toevoegingen van 136 en 9 verwijderingen
  1. +5
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java
  2. +73
    -8
      pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java
  3. +57
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/BatchUpdateEmployeeTask.java
  4. +1
    -1
      pmapi/src/main/resources/application.yml

+ 5
- 0
pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java Bestand weergeven

@@ -43,4 +43,9 @@ public class DingInfoPullController {
public void employeeBatchGetByRegionCode(@PathVariable String regionCode) {
employeeBatchGetTask.batchGetEmployeeTaskByRegionCode(regionCode);
}

@GetMapping("/employeeByOrdCode/{orgCode}")
public void employeeBatchGetByOrdCode(@PathVariable String orgCode) {
employeeBatchGetTask.batchGetEmployeeTaskByOrdCode(orgCode);
}
}

+ 73
- 8
pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java Bestand weergeven

@@ -5,7 +5,9 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.model.GenericResult;
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;
@@ -335,13 +337,76 @@ public class EmployeeBatchGetTask {
}
}

// 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);
// }
// }
public void batchGetEmployeeTaskByOrdCode(String orgCode) {
DingOrganization org = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class)
.eq(DingOrganization::getOrganizationCode, orgCode)
.last(BizConst.LIMIT_1));
VUtils.isTrue(Objects.isNull(org)).throwMessage("单位不存在");
log.info("所属单位 {} 要更新员工信息了",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(PAGE_SIZE);

// 查询组织下 用户信息
GenericResult<Page<OrganizationEmployeePosition>> firstPageGenericResult = zwddClient.pageOrganizationEmployeePositions(query);
Page<OrganizationEmployeePosition> data = firstPageGenericResult.getData();
if (Objects.isNull(data)){
log.info("响应为空:{}",organizationCode);
return;
}
if (CollUtil.isNotEmpty(data.getData())) {
allOrganizationEmployeePositionList.addAll(data.getData());
}
Long totalSize = data.getTotalSize();

log.info("dingOrganization :{}", JSON.toJSONString(org));

log.info("totalSize :{},{}", totalSize,org.getOrganizationName());
if (totalSize > PAGE_SIZE) {
if (totalSize > MAX_SIZE) {
//超过1万 按1万的处理
totalSize = MAX_SIZE.longValue();
}

int restPageNo = totalSize % PAGE_SIZE > 0 ? 1 : 0;
int maxPageNo = (int) Math.ceil(totalSize / PAGE_SIZE) + restPageNo;
for (pageNo = 2; pageNo <= maxPageNo; pageNo++) {
query.setPageNo(pageNo);
GenericResult<Page<OrganizationEmployeePosition>> pageGenericResult = zwddClient.pageOrganizationEmployeePositions(query);
// log.info("pageGenericResult :{}", JSON.toJSONString(pageGenericResult));
if(pageGenericResult.isSuccess()){
allOrganizationEmployeePositionList.addAll(pageGenericResult.getData().getData());
}else{
log.error(pageGenericResult.getMsg());
}
}
}

// 批量查询 成员的accountId
List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList = new ArrayList<>();
if (allOrganizationEmployeePositionList.size() <= GROUP_SIZE) {
log.info("assemblerAccountId :{}", allOrganizationEmployeePositionList.size());
assemblerAccountId(allOrganizationEmployeePositionList, dingEmployeeInfoSaveRecordList);
} else {
log.info("assemblerAccountId :{}", allOrganizationEmployeePositionList.size());
List<List<OrganizationEmployeePosition>> split = Lists.partition(allOrganizationEmployeePositionList, GROUP_SIZE);
for (List<OrganizationEmployeePosition> segment : split) {
assemblerAccountId(segment, dingEmployeeInfoSaveRecordList);
}
}
// 批量保存用户信息
saveBatch(dingEmployeeInfoSaveRecordList);

log.info("员工同步完成");

}

}

+ 57
- 0
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/BatchUpdateEmployeeTask.java Bestand weergeven

@@ -0,0 +1,57 @@
package com.ningdatech.pmapi.scheduler.task;

import cn.hutool.core.date.StopWatch;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.ningdatech.pmapi.organization.service.IDingOrganizationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

/**
* @author liuxinxin
* @date 2023/1/12 上午9:53
* 批量获取/更新部门信息任务
*/
@Component
@Slf4j
@RequiredArgsConstructor
public class BatchUpdateEmployeeTask {

@Value("${hostname}")
private String HOST_NAME;

private final EmployeeBatchGetTask employeeBatchGetTask;
private final IDingOrganizationService organizationService;

@Scheduled(cron = "0 45 1 * * ?")
public void doTask() throws UnknownHostException {
if (!HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) {
return;
}

log.info("=========== 每日更新 浙政钉员工信息 (根据现有单位) ======== 任务开始");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// 1.查出浙政钉 所有单位
List<DingOrganization> units = organizationService.list(Wrappers.lambdaQuery(DingOrganization.class)
.eq(DingOrganization::getTypeCode, "GOV_UNIT"));

log.info("需要更新的 单位数量为 {}",units.size());

for(DingOrganization organization : units){
log.info("当前单位是 {}",organization.getOrganizationName());
employeeBatchGetTask.batchGetEmployeeTaskByOrdCode(organization.getOrganizationCode());
}

stopWatch.stop();
log.info("=========== 每日更新 浙政钉员工信息 (根据现有单位) ======== 任务结束 {}s", stopWatch.getTotalTimeSeconds());
}

}

+ 1
- 1
pmapi/src/main/resources/application.yml Bestand weergeven

@@ -1,3 +1,3 @@
spring:
profiles:
active: dev
active: prod

Laden…
Annuleren
Opslaan