Merge branch 'dev' into test
This commit is contained in:
@@ -13,6 +13,9 @@ public class DeptRespDTO {
|
||||
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "部门编码", example = "XXXXXXX")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "父部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long parentId;
|
||||
|
||||
|
||||
@@ -105,18 +105,18 @@ public class DeptController {
|
||||
@GetMapping("/top-level-list")
|
||||
@Operation(summary = "获取顶级部门列表", description = "用于懒加载,只返回没有父部门的顶级部门")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<List<DeptSimpleRespVO>> getTopLevelDeptList() {
|
||||
public CommonResult<List<DeptRespVO>> getTopLevelDeptList() {
|
||||
List<DeptDO> list = deptService.getTopLevelDeptList();
|
||||
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
|
||||
return success(BeanUtils.toBean(list, DeptRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/children")
|
||||
@Operation(summary = "根据父部门ID获取子部门列表", description = "用于懒加载,根据父部门ID返回直接子部门")
|
||||
@Parameter(name = "parentId", description = "父部门ID", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<List<DeptSimpleRespVO>> getChildrenDeptList(@RequestParam("parentId") Long parentId) {
|
||||
public CommonResult<List<DeptRespVO>> getChildrenDeptList(@RequestParam("parentId") Long parentId) {
|
||||
List<DeptDO> list = deptService.getDirectChildDeptList(parentId);
|
||||
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
|
||||
return success(BeanUtils.toBean(list, DeptRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
|
||||
@@ -20,7 +20,6 @@ public class DeptSaveReqVO {
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "部门编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "DEPT_001")
|
||||
@NotBlank(message = "部门编码不能为空")
|
||||
@Size(max = 50, message = "部门编码长度不能超过 50 个字符")
|
||||
private String code;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
@@ -58,4 +60,36 @@ public class SyncLogController {
|
||||
return success(success);
|
||||
}
|
||||
|
||||
@PostMapping("/batch-rerun")
|
||||
@Operation(summary = "根据服务类型批量重跑异常的同步接口")
|
||||
@PreAuthorize("@ss.hasPermission('system:sync-log:batch-rerun')")
|
||||
public CommonResult<Integer> batchRerunByServiceName(
|
||||
@RequestParam("serviceName") String serviceName,
|
||||
@RequestParam(value = "batchSize", defaultValue = "200") Integer batchSize) {
|
||||
// 参数校验
|
||||
if (batchSize > 500) {
|
||||
throw new IllegalArgumentException("批次大小不能超过500");
|
||||
}
|
||||
|
||||
Integer count = syncLogService.markForBatchRerun(serviceName, batchSize);
|
||||
return success(count);
|
||||
}
|
||||
|
||||
@GetMapping("/batch-rerun/progress")
|
||||
@Operation(summary = "查询批量重跑进度")
|
||||
@PreAuthorize("@ss.hasPermission('system:sync-log:query')")
|
||||
public CommonResult<Map<String, Object>> getBatchRerunProgress(
|
||||
@RequestParam("serviceName") String serviceName) {
|
||||
Map<String, Object> progress = syncLogService.getBatchRerunProgress(serviceName);
|
||||
return success(progress);
|
||||
}
|
||||
|
||||
@PostMapping("/batch-rerun/pause")
|
||||
@Operation(summary = "暂停批量重跑(将重试中状态重置为原失败状态)")
|
||||
@PreAuthorize("@ss.hasPermission('system:sync-log:batch-rerun')")
|
||||
public CommonResult<Integer> pauseBatchRerun(@RequestParam("serviceName") String serviceName) {
|
||||
Integer count = syncLogService.pauseBatchRerun(serviceName);
|
||||
return success(count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ public enum SyncLogStatusEnum {
|
||||
SIGNATURE_VERIFY_FAILED(2, "签名验证失败"),
|
||||
AUTH_FAILED(3, "认证失败"),
|
||||
BUSINESS_FAILED(4, "业务处理失败"),
|
||||
SYSTEM_ERROR(5, "系统异常");
|
||||
SYSTEM_ERROR(5, "系统异常"),
|
||||
RETRYING(6, "重试中"),
|
||||
RETRY_FAILED(7, "重试失败");
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package cn.iocoder.yudao.module.system.job.sync;
|
||||
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
import cn.iocoder.yudao.module.system.service.sync.SyncLogService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 同步日志自动标记重试任务
|
||||
*
|
||||
* 该任务定期扫描失败状态的同步日志记录,自动标记为"重试中"状态
|
||||
* 实现完全自动化的重试闭环
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SyncLogAutoMarkRetryJob {
|
||||
|
||||
@Resource
|
||||
private SyncLogService syncLogService;
|
||||
|
||||
/**
|
||||
* 自动标记重试任务
|
||||
*
|
||||
* 建议配置执行频率:每5分钟执行一次
|
||||
* cron表达式:0 0/5 * * * ?
|
||||
*
|
||||
* 该任务会按服务类型自动标记失败记录为重试状态:
|
||||
* 1. 优先处理SYSTEM_ERROR状态的记录
|
||||
* 2. 然后处理其他失败状态的记录
|
||||
* 3. 每次每种服务类型最多标记100条记录
|
||||
*/
|
||||
@XxlJob("syncLogAutoMarkRetryJob")
|
||||
@TenantJob
|
||||
public void execute() {
|
||||
log.info("[syncLogAutoMarkRetryJob][开始执行同步日志自动标记重试任务]");
|
||||
|
||||
try {
|
||||
// 定义需要处理的服务类型
|
||||
String[] serviceNames = {
|
||||
"OrgCreateService",
|
||||
"OrgUpdateService",
|
||||
"OrgDeleteService",
|
||||
"UserCreateService",
|
||||
"UserUpdateService",
|
||||
"UserDeleteService"
|
||||
};
|
||||
|
||||
int totalMarkedCount = 0;
|
||||
|
||||
// 为每种服务类型自动标记重试
|
||||
for (String serviceName : serviceNames) {
|
||||
try {
|
||||
// 每种服务类型最多标记100条记录,避免一次性处理过多
|
||||
Integer markedCount = syncLogService.autoMarkForRetry(serviceName, 100);
|
||||
totalMarkedCount += markedCount;
|
||||
|
||||
if (markedCount > 0) {
|
||||
log.info("[syncLogAutoMarkRetryJob][服务类型 {} 自动标记了 {} 条记录为重试状态]",
|
||||
serviceName, markedCount);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[syncLogAutoMarkRetryJob][处理服务类型 {} 时发生异常]", serviceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalMarkedCount > 0) {
|
||||
log.info("[syncLogAutoMarkRetryJob][自动标记重试任务执行完成,总共标记了 {} 条记录]", totalMarkedCount);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[syncLogAutoMarkRetryJob][自动标记重试任务执行异常]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.system.job.sync;
|
||||
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
import cn.iocoder.yudao.module.system.service.sync.SyncLogService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 同步日志批量重跑任务
|
||||
*
|
||||
* 该任务定期扫描状态为"重试中"的同步日志记录,进行分批重跑处理
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SyncLogBatchRerunJob {
|
||||
|
||||
@Resource
|
||||
private SyncLogService syncLogService;
|
||||
|
||||
/**
|
||||
* 执行批量重跑任务
|
||||
*
|
||||
* 建议配置执行频率:每30秒执行一次
|
||||
* cron表达式:0/30 * * * * ?
|
||||
*/
|
||||
@XxlJob("syncLogBatchRerunJob")
|
||||
@TenantJob
|
||||
public void execute() {
|
||||
log.info("[syncLogBatchRerunJob][开始执行同步日志批量重跑任务]");
|
||||
|
||||
try {
|
||||
// 执行批量重跑处理,每次处理50条记录
|
||||
int processedCount = syncLogService.processBatchRerun(50);
|
||||
|
||||
if (processedCount > 0) {
|
||||
log.info("[syncLogBatchRerunJob][批量重跑任务执行完成,处理了 {} 条记录]", processedCount);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[syncLogBatchRerunJob][批量重跑任务执行异常]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
import cn.iocoder.yudao.module.system.enums.dept.DeptSourceEnum;
|
||||
|
||||
/**
|
||||
* 部门 Service 实现类
|
||||
*
|
||||
@@ -173,7 +171,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
@VisibleForTesting
|
||||
void validateDeptCodeUnique(Long id, String code) {
|
||||
if (StrUtil.isBlank(code)) {
|
||||
throw exception(DEPT_CODE_NOT_NULL);
|
||||
return;
|
||||
}
|
||||
DeptDO dept = deptMapper.selectByCode(code);
|
||||
if (dept == null) {
|
||||
|
||||
@@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sync.vo.SyncLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sync.SyncLogDO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 同步接口日志 Service 接口
|
||||
*
|
||||
@@ -107,4 +109,46 @@ public interface SyncLogService {
|
||||
*/
|
||||
boolean rerunSyncLog(Long logId);
|
||||
|
||||
/**
|
||||
* 根据服务类型批量标记为重试状态
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @param batchSize 批次大小(限制单次标记的最大数量)
|
||||
* @return 标记的记录数量
|
||||
*/
|
||||
Integer markForBatchRerun(String serviceName, Integer batchSize);
|
||||
|
||||
/**
|
||||
* 自动标记失败记录为重试状态(由XXL-Job调用)
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @param batchSize 批次大小
|
||||
* @return 标记的记录数量
|
||||
*/
|
||||
Integer autoMarkForRetry(String serviceName, Integer batchSize);
|
||||
|
||||
/**
|
||||
* 处理批量重跑(由XXL-Job调用)
|
||||
*
|
||||
* @param batchSize 每次处理的记录数量
|
||||
* @return 实际处理的记录数量
|
||||
*/
|
||||
int processBatchRerun(int batchSize);
|
||||
|
||||
/**
|
||||
* 获取批量重跑进度
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @return 进度信息
|
||||
*/
|
||||
Map<String, Object> getBatchRerunProgress(String serviceName);
|
||||
|
||||
/**
|
||||
* 暂停批量重跑(将重试中状态重置为系统异常状态)
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @return 暂停的记录数量
|
||||
*/
|
||||
Integer pauseBatchRerun(String serviceName);
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user