Merge branch 'dev' into test

This commit is contained in:
chenbowen
2026-01-20 08:59:11 +08:00
17 changed files with 214 additions and 25 deletions

View File

@@ -2,6 +2,7 @@ package com.zt.plat.module.system.api.dept;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.collection.CollectionUtils;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.system.api.dept.dto.*;
import com.zt.plat.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
@@ -15,6 +16,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
@FeignClient(name = ApiConstants.NAME) // TODO ZTfallbackFactory =
@Tag(name = "RPC 服务 - 部门")
public interface DeptApi {
@@ -86,6 +89,11 @@ public interface DeptApi {
@Parameter(name = "userId", description = "用户编号", example = "1", required = true)
CommonResult<Set<CompanyDeptInfoRespDTO>> getCompanyDeptInfoListByUserId(@RequestParam("userId") Long userId);
@GetMapping(PREFIX+"/up-find-company-node")
@Operation(summary = "获取公司节点信息", description = "通过部门编号,向上追溯部门信息,直到上级部门是公司,返回追溯到的部门信息列表")
@Parameter(name = "deptId", description = "部门编号", required = true, example = "1024")
CommonResult<List<DeptRespDTO>> upFindCompanyNode(@RequestParam("deptId") Long deptId);
// ========== 数据同步专用接口 ==========
@PostMapping(PREFIX + "/sync")

View File

@@ -107,6 +107,12 @@ public class DeptApiImpl implements DeptApi {
return success(BeanUtils.toBean(companyDeptInfos, CompanyDeptInfoRespDTO.class));
}
@Override
public CommonResult<List<DeptRespDTO>> upFindCompanyNode(Long deptId) {
List<DeptDO> depts = deptService.upFindCompanyNode(deptId);
return success(BeanUtils.toBean(depts, DeptRespDTO.class));
}
// ========== 数据同步专用接口 ==========
@Override

View File

@@ -165,4 +165,11 @@ public class DeptController {
return success(BeanUtils.toBean(companyDeptInfos, CompanyDeptInfoRespDTO.class));
}
@GetMapping("/up-find-company-node")
@Operation(summary = "获取公司节点信息", description = "通过部门编号,向上追溯部门信息,直到上级部门是公司,返回追溯到的部门信息列表")
@Parameter(name = "deptId", description = "部门编号", required = true, example = "1024")
public CommonResult<List<DeptRespVO>> upFindCompanyNode(@RequestParam("deptId") Long deptId) {
List<DeptDO> list = deptService.upFindCompanyNode(deptId);
return success(BeanUtils.toBean(list, DeptRespVO.class));
}
}

View File

@@ -10,6 +10,8 @@ import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
@@ -167,4 +169,9 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
);
}
@Select("""
SELECT sd.* FROM SYSTEM_DEPT sd START WITH sd.id = #{deptId}
CONNECT BY PRIOR sd.parent_id = sd.id AND PRIOR sd.is_company <> 1 ;
""")
List<DeptDO> upFindCompanyNode(@Param("deptId") Long deptId);
}

View File

@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
import java.util.Collections;
@Mapper
public interface PostMapper extends BaseMapperX<PostDO> {
@@ -35,4 +36,12 @@ public interface PostMapper extends BaseMapperX<PostDO> {
return selectOne(PostDO::getCode, code);
}
default List<PostDO> selectByCodes(Collection<String> codes) {
if (codes == null || codes.isEmpty()) {
return Collections.emptyList();
}
return selectList(new LambdaQueryWrapperX<PostDO>()
.in(PostDO::getCode, codes));
}
}

View File

@@ -185,4 +185,11 @@ public interface DeptService {
// ========== 数据同步专用接口 ==========
void syncDept(DeptSaveReqVO syncReqVO);
/**
* 向上查找公司节点信息
* @param deptId
* @return
*/
List<DeptDO> upFindCompanyNode(Long deptId);
}

View File

@@ -960,4 +960,9 @@ public class DeptServiceImpl implements DeptService {
// 注意:不发布变更事件,避免循环同步
}
@Override
public List<DeptDO> upFindCompanyNode(Long deptId) {
return deptMapper.upFindCompanyNode(deptId);
}
}

View File

@@ -322,7 +322,41 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
if (records.isEmpty()) {
return result;
}
long batchStart = System.currentTimeMillis();
result.increasePulled(records.size());
// 预取已有用户,避免逐条查询
long preloadUsersStart = System.currentTimeMillis();
Map<Long, AdminUserDO> existingUsers = new HashMap<>();
List<Long> userIds = records.stream()
.map(IWorkHrUserPageRespVO.User::getId)
.filter(Objects::nonNull)
.map(Integer::longValue)
.distinct()
.toList();
if (!userIds.isEmpty()) {
List<AdminUserDO> users = adminUserMapper.selectBatchIds(userIds);
if (CollUtil.isNotEmpty(users)) {
users.forEach(user -> existingUsers.put(user.getId(), user));
}
}
long preloadUsersMs = System.currentTimeMillis() - preloadUsersStart;
// 预取岗位,避免逐条按编码查询
long preloadPostsStart = System.currentTimeMillis();
List<String> postCodes = records.stream()
.map(IWorkHrUserPageRespVO.User::getJobtitleid)
.filter(Objects::nonNull)
.map(this::buildJobCode)
.distinct()
.toList();
if (!postCodes.isEmpty()) {
List<PostDO> posts = postMapper.selectByCodes(postCodes);
if (CollUtil.isNotEmpty(posts)) {
posts.forEach(post -> postCache.put(buildPostCacheKey(post.getCode()), post));
}
}
long preloadPostsMs = System.currentTimeMillis() - preloadPostsStart;
for (IWorkHrUserPageRespVO.User user : records) {
if (user == null) {
continue;
@@ -344,7 +378,7 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
CommonStatusEnum status = inactive ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE;
// 直接沿用 iWork 原始密码,避免重复格式化造成校验偏差
String externalPassword = trimToNull(user.getPassword());
AdminUserDO existing = adminUserMapper.selectById(user.getId());
AdminUserDO existing = user.getId() == null ? null : existingUsers.get(user.getId().longValue());
UserSyncOutcome outcome;
if (existing == null) {
if (!options.isCreateIfMissing()) {
@@ -377,6 +411,9 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
result.withMessage("同步人员失败: " + ex.getMessage());
}
}
long totalMs = System.currentTimeMillis() - batchStart;
log.info("[iWork] 人员批次同步完成 size={} preloadUsersMs={} preloadPostsMs={} totalMs={}",
records.size(), preloadUsersMs, preloadPostsMs, totalMs);
return result;
}
//TODO
@@ -495,11 +532,43 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
UserSaveReqVO req = buildUserSaveReq(source, username, deptId, postId, status);
req.setId(existing.getId());
boolean disabledChanged = CommonStatusEnum.isDisable(status.getStatus()) && CommonStatusEnum.isEnable(existing.getStatus());
adminUserService.updateUser(req);
syncPassword(existing, externalPassword);
boolean infoChanged = isUserInfoChanged(existing, req);
boolean passwordChanged = isPasswordChanged(existing, externalPassword);
if (!infoChanged && !passwordChanged) {
return new UserSyncOutcome(SyncAction.SKIPPED, false, existing.getId());
}
if (infoChanged) {
adminUserService.updateUser(req);
}
if (passwordChanged) {
syncPassword(existing, externalPassword);
}
return new UserSyncOutcome(SyncAction.UPDATED, disabledChanged, existing.getId());
}
private boolean isUserInfoChanged(AdminUserDO existing, UserSaveReqVO req) {
if (existing == null || req == null) {
return false;
}
return !Objects.equals(existing.getUsername(), req.getUsername())
|| !Objects.equals(existing.getWorkcode(), req.getWorkcode())
|| !Objects.equals(existing.getNickname(), req.getNickname())
|| !Objects.equals(existing.getRemark(), req.getRemark())
|| !Objects.equals(existing.getEmail(), req.getEmail())
|| !Objects.equals(existing.getMobile(), req.getMobile())
|| !Objects.equals(existing.getSex(), req.getSex())
|| !Objects.equals(existing.getStatus(), req.getStatus());
}
private boolean isPasswordChanged(AdminUserDO existing, String externalPassword) {
if (existing == null || StrUtil.isBlank(externalPassword)) {
return false;
}
return !StrUtil.equals(externalPassword, existing.getPassword());
}
private DeptSaveReqVO buildSubcompanySaveReq(IWorkHrSubcompanyPageRespVO.Subcompany data,
Long deptId,
Long parentId,

View File

@@ -217,11 +217,14 @@ public class IWorkSyncServiceImpl implements IWorkSyncService {
int pagesLimit = reqVO.getMaxPages() == null ? Integer.MAX_VALUE : reqVO.getMaxPages();
int processedPages = 0;
for (int page = startPage; processedPages < pagesLimit; page++) {
long pageStart = System.currentTimeMillis();
BatchExecution execution = executor.execute(page, pageSize);
long pageMs = System.currentTimeMillis() - pageStart;
if (execution == null || execution.totalPulled == 0) {
break;
}
processedPages++;
log.info("[iWork] 全量同步 {} 页={} pulled={} costMs={}", type, page, execution.totalPulled, pageMs);
IWorkSyncBatchStatVO batchStat = new IWorkSyncBatchStatVO();
batchStat.setEntityType(type);
batchStat.setPageNumber(page);
@@ -403,11 +406,14 @@ public class IWorkSyncServiceImpl implements IWorkSyncService {
int pagesLimit = reqVO.getMaxPages() == null ? Integer.MAX_VALUE : reqVO.getMaxPages();
int processedPages = 0;
for (int page = startPage; processedPages < pagesLimit; page++) {
long pageStart = System.currentTimeMillis();
BatchExecution execution = executor.execute(page, pageSize);
long pageMs = System.currentTimeMillis() - pageStart;
if (execution == null || execution.totalPulled == 0) {
break;
}
processedPages++;
log.info("[iWork] 手动同步 {} 页={} pulled={} costMs={}", type, page, execution.totalPulled, pageMs);
IWorkSyncBatchStatVO batchStat = new IWorkSyncBatchStatVO();
batchStat.setEntityType(type);
batchStat.setPageNumber(page);

View File

@@ -203,6 +203,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
.put(LoginUser.INFO_KEY_TENANT_ID, user.getTenantId().toString())
.put(LoginUser.INFO_KEY_USERNAME, user.getUsername())
.put(LoginUser.INFO_KEY_PHONE, user.getMobile())
.put(LoginUser.INFO_KEY_WORK_CODE, user.getWorkcode())
.put(LoginUser.INFO_KEY_POST_IDS, CollUtil.isEmpty(user.getPostIds()) ? "[]" : JsonUtils.toJsonString(user.getPostIds()))
.build();
} else if (userType.equals(UserTypeEnum.MEMBER.getValue())) {