Browse Source

Merge remote-tracking branch 'origin/master'

tags/24080901
CMM 1 year ago
parent
commit
be9256734c
6 changed files with 151 additions and 8 deletions
  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. +2
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/constant/LoginTypeEnum.java
  5. +13
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthProvider.java
  6. +1
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java

+ 5
- 0
pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java View File

@@ -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 View File

@@ -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 View File

@@ -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());
}

}

+ 2
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/constant/LoginTypeEnum.java View File

@@ -17,6 +17,8 @@ public enum LoginTypeEnum {
*/
DING_QR_LOGIN,

DING_MD_LOGIN,

/**
* 手机号验证码登陆
*/


+ 13
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthProvider.java View File

@@ -60,6 +60,19 @@ public class CredentialAuthProvider implements AuthenticationProvider {
user = userDetailsService.loadUserByUsername(accountId + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + loginTypeEnum.name());
}
break;
case DING_MD_LOGIN: {
String code = (String) authenticationToken.getCredentials();
GenericResult<String> accountResult = zwddAuthClient.getMobileAccountId(code);
if (!accountResult.isSuccess()) {
throw new BadCredentialsException("login fail! 浙政钉免登校验失败");
}
String accountId = accountResult.getData();
if (Objects.isNull(accountId)) {
throw new BadCredentialsException("login fail! 浙政钉免登校验失败");
}
user = userDetailsService.loadUserByUsername(accountId + UserDeatilsServiceConstant.USER_DETAILS_SERVICE_SEPARATOR + loginTypeEnum.name());
}
break;
case PHONE_VERIFICATION_CODE_LOGIN: {
if (!phoneVerifyCodeSkip) {
// 校验短信验证码


+ 1
- 0
pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java View File

@@ -50,6 +50,7 @@ public class CredentialLoginUserDetailService implements UserDetailsService {
}
}
break;
case DING_MD_LOGIN:
case DING_QR_LOGIN: {
userFullInfo = userInfoManage.queryUserInfoInAccountIdAuth(username);
if (Objects.isNull(userFullInfo)) {


Loading…
Cancel
Save