Merge branch 'dev' into test
This commit is contained in:
@@ -268,10 +268,10 @@ public class DeptDataPermissionRule implements DataPermissionRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拼接条件
|
// 拼接条件
|
||||||
if (StrUtil.isBlank(workCode)) {
|
if (StrUtil.isNotBlank(workCode) && "system_users".equals(tableName)) {
|
||||||
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new LongValue(userId));
|
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, "workcode"), new StringValue(workCode));
|
||||||
} else {
|
} else {
|
||||||
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new StringValue(workCode));
|
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new LongValue(userId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zt.plat.module.system.job.sync;
|
||||||
|
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.zt.plat.framework.tenant.core.job.TenantJob;
|
||||||
|
import com.zt.plat.module.system.service.sync.SyncIWorkOrgChangeService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于定时同步 iWork 当日变更的组织数据
|
||||||
|
* 同步时间:每日23:00
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class SyncIWorkOrgChangeJob {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SyncIWorkOrgChangeService syncIWorkOrgChangeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行定时任务
|
||||||
|
* 配置执行频率:每日23:00时执行一次
|
||||||
|
* cron表达式:0 0 23 * * ?
|
||||||
|
*/
|
||||||
|
@XxlJob("syncIWorkOrgChangeJob")
|
||||||
|
@TenantJob
|
||||||
|
public void execute() {
|
||||||
|
log.info("[syncIWorkOrgChangeJob][开始执行同步 iWork 当日变更组织任务]");
|
||||||
|
try {
|
||||||
|
int processedCount = syncIWorkOrgChangeService.process();
|
||||||
|
if (processedCount > 0) {
|
||||||
|
log.info("[syncIWorkOrgChangeJob][同步任务执行完成,处理了 {} 条记录]", processedCount);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[syncIWorkOrgChangeJob][同步任务执行失败]", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,11 @@ import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkHrUs
|
|||||||
import com.zt.plat.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
import com.zt.plat.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||||
import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
|
import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
|
||||||
import com.zt.plat.module.system.dal.dataobject.dept.PostDO;
|
import com.zt.plat.module.system.dal.dataobject.dept.PostDO;
|
||||||
|
import com.zt.plat.module.system.dal.dataobject.dept.UserPostDO;
|
||||||
import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO;
|
import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO;
|
||||||
|
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||||
import com.zt.plat.module.system.dal.mysql.dept.PostMapper;
|
import com.zt.plat.module.system.dal.mysql.dept.PostMapper;
|
||||||
|
import com.zt.plat.module.system.dal.mysql.dept.UserPostMapper;
|
||||||
import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper;
|
import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper;
|
||||||
import com.zt.plat.module.system.enums.common.SexEnum;
|
import com.zt.plat.module.system.enums.common.SexEnum;
|
||||||
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
||||||
@@ -24,6 +27,7 @@ import com.zt.plat.module.system.service.dept.DeptService;
|
|||||||
import com.zt.plat.module.system.service.dept.PostService;
|
import com.zt.plat.module.system.service.dept.PostService;
|
||||||
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncProcessor;
|
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncProcessor;
|
||||||
import com.zt.plat.module.system.service.user.AdminUserService;
|
import com.zt.plat.module.system.service.user.AdminUserService;
|
||||||
|
import com.zt.plat.module.system.service.userdept.UserDeptService;
|
||||||
import com.zt.plat.module.system.util.sync.SyncVerifyUtil;
|
import com.zt.plat.module.system.util.sync.SyncVerifyUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -33,6 +37,7 @@ import org.springframework.util.DigestUtils;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -47,8 +52,10 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
|
|||||||
private final DeptService deptService;
|
private final DeptService deptService;
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
private final PostMapper postMapper;
|
private final PostMapper postMapper;
|
||||||
|
private final UserPostMapper userPostMapper;
|
||||||
private final AdminUserService adminUserService;
|
private final AdminUserService adminUserService;
|
||||||
private final AdminUserMapper adminUserMapper;
|
private final AdminUserMapper adminUserMapper;
|
||||||
|
private final UserDeptService userDeptService;
|
||||||
|
|
||||||
private final Map<String, PostDO> postCache = new ConcurrentHashMap<>();
|
private final Map<String, PostDO> postCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@@ -531,11 +538,16 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
|
|||||||
String externalPassword) {
|
String externalPassword) {
|
||||||
UserSaveReqVO req = buildUserSaveReq(source, username, deptId, postId, status);
|
UserSaveReqVO req = buildUserSaveReq(source, username, deptId, postId, status);
|
||||||
req.setId(existing.getId());
|
req.setId(existing.getId());
|
||||||
|
Long iworkDeptId = resolveIWorkDeptId(deptId);
|
||||||
|
req.setDeptIds(null);
|
||||||
|
req.setPostIds(null);
|
||||||
boolean disabledChanged = CommonStatusEnum.isDisable(status.getStatus()) && CommonStatusEnum.isEnable(existing.getStatus());
|
boolean disabledChanged = CommonStatusEnum.isDisable(status.getStatus()) && CommonStatusEnum.isEnable(existing.getStatus());
|
||||||
boolean infoChanged = isUserInfoChanged(existing, req);
|
boolean infoChanged = isUserInfoChanged(existing, req);
|
||||||
boolean passwordChanged = isPasswordChanged(existing, externalPassword);
|
boolean passwordChanged = isPasswordChanged(existing, externalPassword);
|
||||||
|
boolean deptChanged = syncIWorkUserDeptRelations(existing.getId(), iworkDeptId);
|
||||||
|
boolean postChanged = syncIWorkUserPostRelations(existing.getId(), postId);
|
||||||
|
|
||||||
if (!infoChanged && !passwordChanged) {
|
if (!infoChanged && !passwordChanged && !deptChanged && !postChanged) {
|
||||||
return new UserSyncOutcome(SyncAction.SKIPPED, false, existing.getId());
|
return new UserSyncOutcome(SyncAction.SKIPPED, false, existing.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,8 +631,9 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
|
|||||||
req.setWorkcode(resolveWorkcode(source));
|
req.setWorkcode(resolveWorkcode(source));
|
||||||
req.setNickname(limitLength(StrUtil.blankToDefault(source.getLastname(), username), 30));
|
req.setNickname(limitLength(StrUtil.blankToDefault(source.getLastname(), username), 30));
|
||||||
req.setRemark(buildUserRemark(source));
|
req.setRemark(buildUserRemark(source));
|
||||||
if (deptId != null) {
|
Long iworkDeptId = resolveIWorkDeptId(deptId);
|
||||||
req.setDeptIds(singletonSet(deptId));
|
if (iworkDeptId != null) {
|
||||||
|
req.setDeptIds(singletonSet(iworkDeptId));
|
||||||
}
|
}
|
||||||
if (postId != null) {
|
if (postId != null) {
|
||||||
req.setPostIds(singletonSet(postId));
|
req.setPostIds(singletonSet(postId));
|
||||||
@@ -635,6 +648,74 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean syncIWorkUserDeptRelations(Long userId, Long iworkDeptId) {
|
||||||
|
if (userId == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<UserDeptDO> relations = userDeptService.getValidUserDeptListByUserIds(Collections.singleton(userId));
|
||||||
|
Set<Long> existingDeptIds = relations.stream()
|
||||||
|
.map(UserDeptDO::getDeptId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
Set<Long> existingIworkDeptIds = new LinkedHashSet<>();
|
||||||
|
if (CollUtil.isNotEmpty(existingDeptIds)) {
|
||||||
|
Map<Long, DeptDO> deptMap = deptService.getDeptMap(existingDeptIds);
|
||||||
|
existingIworkDeptIds = deptMap.values().stream()
|
||||||
|
.filter(this::isIWorkDept)
|
||||||
|
.map(DeptDO::getId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
}
|
||||||
|
Set<Long> desiredIworkDeptIds = iworkDeptId == null
|
||||||
|
? Collections.emptySet()
|
||||||
|
: Collections.singleton(iworkDeptId);
|
||||||
|
if (existingIworkDeptIds.equals(desiredIworkDeptIds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Collection<Long> toDelete = CollUtil.subtract(existingIworkDeptIds, desiredIworkDeptIds);
|
||||||
|
Collection<Long> toAdd = CollUtil.subtract(desiredIworkDeptIds, existingIworkDeptIds);
|
||||||
|
if (CollUtil.isNotEmpty(toDelete)) {
|
||||||
|
userDeptService.deleteUserDeptByUserIdAndDeptIds(userId, toDelete);
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(toAdd)) {
|
||||||
|
userDeptService.batchCreateUserDept(Collections.singletonList(
|
||||||
|
new UserDeptDO().setUserId(userId).setDeptId(iworkDeptId)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean syncIWorkUserPostRelations(Long userId, Long postId) {
|
||||||
|
if (userId == null || postId == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<UserPostDO> relations = userPostMapper.selectListByUserId(userId);
|
||||||
|
Set<Long> existingPostIds = relations.stream()
|
||||||
|
.map(UserPostDO::getPostId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
if (existingPostIds.contains(postId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
userPostMapper.insertBatch(Collections.singletonList(
|
||||||
|
new UserPostDO().setUserId(userId).setPostId(postId)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long resolveIWorkDeptId(Long deptId) {
|
||||||
|
if (deptId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DeptDO dept = deptService.getDept(deptId);
|
||||||
|
return isIWorkDept(dept) ? deptId : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isIWorkDept(DeptDO dept) {
|
||||||
|
if (dept == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Objects.equals(dept.getDeptSource(), DeptSourceEnum.IWORK.getSource());
|
||||||
|
}
|
||||||
|
|
||||||
private void mergeDeptDefaults(DeptSaveReqVO target, DeptDO existing) {
|
private void mergeDeptDefaults(DeptSaveReqVO target, DeptDO existing) {
|
||||||
target.setCode(StrUtil.blankToDefault(target.getCode(), existing.getCode()));
|
target.setCode(StrUtil.blankToDefault(target.getCode(), existing.getCode()));
|
||||||
target.setShortName(StrUtil.blankToDefault(target.getShortName(), existing.getShortName()));
|
target.setShortName(StrUtil.blankToDefault(target.getShortName(), existing.getShortName()));
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zt.plat.module.system.service.sync;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时同步 iWork 组织变更服务
|
||||||
|
*/
|
||||||
|
public interface SyncIWorkOrgChangeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行同步
|
||||||
|
* @return 拉取记录数量
|
||||||
|
*/
|
||||||
|
int process();
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.zt.plat.module.system.service.sync;
|
||||||
|
|
||||||
|
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkFullSyncReqVO;
|
||||||
|
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkFullSyncRespVO;
|
||||||
|
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SyncIWorkOrgChangeServiceImpl implements SyncIWorkOrgChangeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWorkSyncService iWorkSyncService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process() {
|
||||||
|
IWorkFullSyncReqVO reqVO = new IWorkFullSyncReqVO();
|
||||||
|
reqVO.setPageSize(10);
|
||||||
|
ZoneId zone = ZoneId.of("Asia/Shanghai");
|
||||||
|
String startOfToday = LocalDate.now(zone)
|
||||||
|
.atStartOfDay(zone)
|
||||||
|
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
reqVO.setModified(startOfToday);
|
||||||
|
IWorkFullSyncRespVO subcompanyResp = iWorkSyncService.fullSyncSubcompanies(reqVO);
|
||||||
|
IWorkFullSyncRespVO departmentResp = iWorkSyncService.fullSyncDepartments(reqVO);
|
||||||
|
return countPulled(subcompanyResp) + countPulled(departmentResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countPulled(IWorkFullSyncRespVO respVO) {
|
||||||
|
if (respVO == null || respVO.getBatches() == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return respVO.getBatches().stream()
|
||||||
|
.mapToInt(batch -> batch.getPulled() == null ? 0 : batch.getPulled())
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,13 @@ public interface UserDeptService {
|
|||||||
*/
|
*/
|
||||||
void deleteUserDeptByUserId(Long userId);
|
void deleteUserDeptByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID与部门ID集合删除用户与部门关系
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param deptIds 部门ID集合
|
||||||
|
*/
|
||||||
|
void deleteUserDeptByUserIdAndDeptIds(Long userId, Collection<Long> deptIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量创建用户与部门关系
|
* 批量创建用户与部门关系
|
||||||
* @param createReqVOList 创建信息列表
|
* @param createReqVOList 创建信息列表
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.zt.plat.module.system.service.userdept;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||||
import com.zt.plat.framework.security.core.LoginUser;
|
import com.zt.plat.framework.security.core.LoginUser;
|
||||||
|
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||||
import com.zt.plat.module.system.dal.mysql.userdept.UserDeptMapper;
|
import com.zt.plat.module.system.dal.mysql.userdept.UserDeptMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -128,10 +129,20 @@ public class UserDeptServiceImpl implements UserDeptService {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteUserDeptByUserId(Long userId) {
|
public void deleteUserDeptByUserId(Long userId) {
|
||||||
if (userId == null) return;
|
if (userId == null) return;
|
||||||
userDeptMapper.delete(new com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX<UserDeptDO>()
|
userDeptMapper.delete(new LambdaQueryWrapperX<UserDeptDO>()
|
||||||
.eq(UserDeptDO::getUserId, userId));
|
.eq(UserDeptDO::getUserId, userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUserDeptByUserIdAndDeptIds(Long userId, Collection<Long> deptIds) {
|
||||||
|
if (userId == null || CollUtil.isEmpty(deptIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
userDeptMapper.delete(new LambdaQueryWrapperX<UserDeptDO>()
|
||||||
|
.eq(UserDeptDO::getUserId, userId)
|
||||||
|
.in(UserDeptDO::getDeptId, deptIds));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void batchCreateUserDept(List<UserDeptDO> createReqVOList) {
|
public void batchCreateUserDept(List<UserDeptDO> createReqVOList) {
|
||||||
|
|||||||
Reference in New Issue
Block a user