1. 提高 databus api 的网络失败重试次数,避免复用旧链接导致的 connection reset 错误
2. 兼容顶级组织同步时的组织编码生成逻辑
This commit is contained in:
@@ -47,6 +47,7 @@ public class HttpStepHandler implements ApiStepHandler {
|
|||||||
private final ExpressionExecutor expressionExecutor;
|
private final ExpressionExecutor expressionExecutor;
|
||||||
|
|
||||||
private static final Duration RETRY_DELAY = Duration.ofMillis(200);
|
private static final Duration RETRY_DELAY = Duration.ofMillis(200);
|
||||||
|
private static final int RETRY_ATTEMPTS = 3;
|
||||||
|
|
||||||
private static final Set<String> DEFAULT_FORWARDED_HEADERS = Set.of(
|
private static final Set<String> DEFAULT_FORWARDED_HEADERS = Set.of(
|
||||||
"authorization",
|
"authorization",
|
||||||
@@ -388,7 +389,7 @@ public class HttpStepHandler implements ApiStepHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Object> applyResilientRetry(Mono<Object> responseMono, ApiStepDefinition stepDefinition) {
|
private Mono<Object> applyResilientRetry(Mono<Object> responseMono, ApiStepDefinition stepDefinition) {
|
||||||
return responseMono.retryWhen(Retry.fixedDelay(1, RETRY_DELAY)
|
return responseMono.retryWhen(Retry.fixedDelay(RETRY_ATTEMPTS, RETRY_DELAY)
|
||||||
.filter(this::isRetryableException)
|
.filter(this::isRetryableException)
|
||||||
.doBeforeRetry(signal -> {
|
.doBeforeRetry(signal -> {
|
||||||
if (log.isWarnEnabled()) {
|
if (log.isWarnEnabled()) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode USER_REGISTER_DISABLED = new ErrorCode(1_002_003_011, "注册功能已关闭");
|
ErrorCode USER_REGISTER_DISABLED = new ErrorCode(1_002_003_011, "注册功能已关闭");
|
||||||
|
|
||||||
// ========== 部门模块 1-002-004-000 ==========
|
// ========== 部门模块 1-002-004-000 ==========
|
||||||
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门");
|
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "当前上级部门已存在同名子部门");
|
||||||
ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1_002_004_001,"父级部门不存在");
|
ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1_002_004_001,"父级部门不存在");
|
||||||
ErrorCode DEPT_NOT_FOUND = new ErrorCode(1_002_004_002, "机构不存在或当前账号无权限修改");
|
ErrorCode DEPT_NOT_FOUND = new ErrorCode(1_002_004_002, "机构不存在或当前账号无权限修改");
|
||||||
ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1_002_004_003, "存在子部门,无法删除");
|
ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1_002_004_003, "存在子部门,无法删除");
|
||||||
|
|||||||
@@ -71,9 +71,16 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
// 校验部门名的唯一性
|
// 校验部门名的唯一性
|
||||||
validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
||||||
// 生成并校验部门编码
|
// 生成并校验部门编码
|
||||||
String generatedCode = generateDeptCode(createReqVO.getParentId());
|
Long effectiveParentId = normalizeParentId(createReqVO.getParentId());
|
||||||
createReqVO.setCode(generatedCode);
|
boolean isTopLevel = Objects.equals(effectiveParentId, DeptDO.PARENT_ID_ROOT);
|
||||||
validateDeptCodeUnique(null, generatedCode);
|
String resolvedCode;
|
||||||
|
if (isTopLevel) {
|
||||||
|
resolvedCode = resolveTopLevelCode(null, createReqVO.getCode());
|
||||||
|
} else {
|
||||||
|
resolvedCode = generateDeptCode(effectiveParentId);
|
||||||
|
validateDeptCodeUnique(null, resolvedCode);
|
||||||
|
}
|
||||||
|
createReqVO.setCode(resolvedCode);
|
||||||
|
|
||||||
// 插入部门
|
// 插入部门
|
||||||
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
||||||
@@ -104,11 +111,26 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
Long oldParentId = normalizeParentId(originalDept.getParentId());
|
Long oldParentId = normalizeParentId(originalDept.getParentId());
|
||||||
boolean parentChanged = !Objects.equals(newParentId, oldParentId);
|
boolean parentChanged = !Objects.equals(newParentId, oldParentId);
|
||||||
if (parentChanged) {
|
if (parentChanged) {
|
||||||
String newCode = generateDeptCode(updateReqVO.getParentId());
|
String newCode;
|
||||||
|
if (Objects.equals(newParentId, DeptDO.PARENT_ID_ROOT)) {
|
||||||
|
newCode = resolveTopLevelCode(updateReqVO.getId(), updateReqVO.getCode());
|
||||||
|
} else {
|
||||||
|
newCode = generateDeptCode(updateReqVO.getParentId());
|
||||||
|
validateDeptCodeUnique(updateReqVO.getId(), newCode);
|
||||||
|
}
|
||||||
updateReqVO.setCode(newCode);
|
updateReqVO.setCode(newCode);
|
||||||
|
} else {
|
||||||
|
if (Objects.equals(newParentId, DeptDO.PARENT_ID_ROOT)) {
|
||||||
|
String requestedCode = updateReqVO.getCode();
|
||||||
|
if (StrUtil.isNotBlank(requestedCode) && !StrUtil.equals(requestedCode.trim(), originalDept.getCode())) {
|
||||||
|
updateReqVO.setCode(resolveTopLevelCode(updateReqVO.getId(), requestedCode));
|
||||||
} else {
|
} else {
|
||||||
updateReqVO.setCode(originalDept.getCode());
|
updateReqVO.setCode(originalDept.getCode());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
updateReqVO.setCode(originalDept.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 更新部门
|
// 更新部门
|
||||||
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
||||||
@@ -189,7 +211,11 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void validateDeptNameUnique(Long id, Long parentId, String name) {
|
void validateDeptNameUnique(Long id, Long parentId, String name) {
|
||||||
DeptDO dept = deptMapper.selectByParentIdAndName(parentId, name);
|
Long effectiveParentId = normalizeParentId(parentId);
|
||||||
|
if (Objects.equals(effectiveParentId, DeptDO.PARENT_ID_ROOT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DeptDO dept = deptMapper.selectByParentIdAndName(effectiveParentId, name);
|
||||||
if (dept == null) {
|
if (dept == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -312,6 +338,18 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
deptMapper.updateById(update);
|
deptMapper.updateById(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveTopLevelCode(Long currentDeptId, String requestedCode) {
|
||||||
|
String candidate = requestedCode;
|
||||||
|
if (candidate != null) {
|
||||||
|
candidate = candidate.trim();
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(candidate)) {
|
||||||
|
candidate = generateDeptCode(DeptDO.PARENT_ID_ROOT);
|
||||||
|
}
|
||||||
|
validateDeptCodeUnique(currentDeptId, candidate);
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeptDO getDept(Long id) {
|
public DeptDO getDept(Long id) {
|
||||||
return deptMapper.selectById(id);
|
return deptMapper.selectById(id);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user