fix:定时job同步用户

This commit is contained in:
2026-03-27 11:49:08 +08:00
parent b23087d714
commit e146368ff9
3 changed files with 37 additions and 2 deletions

View File

@@ -1,9 +1,15 @@
package com.honeycombis.honeycom.tenant.job;
import com.honeycombis.honeycom.common.core.exception.HoneycomException;
import com.honeycombis.honeycom.common.core.util.R;
import com.honeycombis.honeycom.common.data.tenant.TenantContextHolder;
import com.honeycombis.honeycom.tenant.feign.RemoteSpdmService;
import com.honeycombis.honeycom.tenant.service.SysHrSyncLogService;
import com.honeycombis.honeycom.tenant.service.SysTKMoldService;
import com.honeycombis.honeycom.tenant.service.SysTenantService;
import com.honeycombis.honeycom.tenant.sync.SyncDataService;
import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto;
import com.honeycombis.honeycom.tenant.vo.tenant.TenantVO;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
@@ -15,7 +21,9 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.xxl.job.core.biz.model.ReturnT.SUCCESS;
@@ -27,6 +35,10 @@ public class SyncDataJob {
private final SyncDataService syncDataService;
private final SysTenantService sysTenantService;
private final SysTKMoldService tkMoldService;
private final SysHrSyncLogService sysHrSyncLogService;
private final RemoteSpdmService remoteSpdmService;
/**
* 每天凌晨一点执行
*/
@@ -46,6 +58,27 @@ public class SyncDataJob {
}
/**
* 每天凌晨一点执行
*/
@Scheduled(cron = "0 0 1 * * ?")
public void allSyncLyricUsers() {
// 获取利元亨用户数据(带部门)
R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(null);
if (userListR.getData() != null) {
Map<String, List<LyricUserDto>> userMapByWorkType = userListR.getData().stream().collect(Collectors.groupingBy(LyricUserDto::getWork_type_name));
for (String workType : userMapByWorkType.keySet()) {
log.info("-------------------------开始定时同步{}的用户数据----------------------", workType);
try {
tkMoldService.allSyncLyricUsers(userMapByWorkType.get(workType), workType);
} catch (Exception e) {
log.error("全量同步用户数据失败", e);
throw new HoneycomException(e.getMessage());
}
}
}
}
private void syncData(TenantVO tenant) {
TenantContextHolder.setTenantId(tenant.getTenantId());
log.info("开始同步组织架构 【岗位】信息!");

View File

@@ -556,7 +556,7 @@ public class SysStaffServiceImpl extends ServiceImpl<SysStaffMapper, SysStaffEnt
throw new HoneycomException(ErrorType.PARAM_ERROR.getCode());
}
R<List<SysUserOnTenantVO>> userListR = honeycomUserServiceFeign.findStaffUserByIds(userIds, SecurityConstants.FROM_IN);
R<List<SysUserOnTenantVO>> userListR = honeycomUserServiceFeign.findStaffUserByIdsForSpdm(userIds, SecurityConstants.FROM_IN);
if (Objects.isNull(userListR) || !userListR.isSuccess() || CollectionUtils.isEmpty(userListR.getData())) {
throw new HoneycomException(TenantErrorType.USER_INFO_QUERY_FAILED.getCode());
}

View File

@@ -374,7 +374,7 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
if (!userList.isEmpty()) {
// 筛选新用户
userList = filerNewUserList(userList);
if (userList.size() > 0) {
if (!userList.isEmpty()) {
log.info("开始同步,租户{}",tenantId);
StringBuilder message = new StringBuilder("全量同步:");
@@ -504,6 +504,8 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
sysStaffPostService.saveBatch(sysStaffPostEntities);
sysStaffRoleService.saveBatch(staffRoleList);
}
} else {
log.info("本次没有新增用户");
}
}
}