如果归集任务下面的子项都取消了,归集任务可以直接关闭
This commit is contained in:
1 parent
62f43056e2
commit
c94f0f14d2
7 files changed
+74
-12
No files matched your search
@@ -41,8 +41,8 @@ public class UsdtAggregationTask extends BaseEntity
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
/** 主任务状态:0 待执行,1 执行中,2 成功,3 存在失败,4 全部明细取消后关闭。 */
|
||||
@Excel(name = "状态", readConverterExp = "0=待执行,1=执行中,2=成功,3=存在失败,4=已关闭")
|
||||
private Integer status;
|
||||
|
||||
/** 创建时间 */
|
||||
|
||||
@@ -47,8 +47,8 @@ public class UsdtAggregationTaskPlus implements Serializable
|
||||
/** 备注 */
|
||||
@Excel(name = "备注")
|
||||
private String remark;
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
/** 主任务状态:0 待执行,1 执行中,2 成功,3 存在失败,4 全部明细取消后关闭。 */
|
||||
@Excel(name = "状态", readConverterExp = "0=待执行,1=执行中,2=成功,3=存在失败,4=已关闭")
|
||||
private Integer status;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
|
||||
@@ -15,6 +15,14 @@ import com.ruoyi.system.domain.UsdtAggregationTaskPlus;
|
||||
*/
|
||||
public interface UsdtAggregationTaskMapper extends BaseMapper<UsdtAggregationTaskPlus>
|
||||
{
|
||||
/** 所有有效子项均取消时关闭主任务;不得将空任务或部分取消误判为关闭。 */
|
||||
int closeIfAllItemsCancelled(@Param("id") Long id);
|
||||
|
||||
/** 条件抢占主任务,避免取消事务关闭后被旧执行快照重新启动。 */
|
||||
int startExecutableTask(@Param("id") Long id);
|
||||
|
||||
/** 结束执行时保留取消事务已经写入的关闭状态。 */
|
||||
int finishExecutableTask(@Param("id") Long id, @Param("status") int status, @Param("remark") String remark);
|
||||
/**
|
||||
* 查询归集任务
|
||||
*
|
||||
|
||||
+16
-8
@@ -120,15 +120,19 @@ public class UsdtAggregationWorkflowService {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void approve(Long taskId, boolean approved) {
|
||||
UsdtAggregationTaskPlus task = requireTask(taskId, false);
|
||||
UsdtAggregationTask task = taskMapper.selectUsdtAggregationTaskByIdForUpdate(taskId);
|
||||
if (task == null) {
|
||||
throw new CustomException("归集任务不存在或已删除");
|
||||
}
|
||||
if (task.getStatus() != null && task.getStatus() != 0) {
|
||||
throw new CustomException("任务已开始执行,不能重复审核");
|
||||
throw new CustomException("任务已开始执行或已关闭,不能重复审核");
|
||||
}
|
||||
task.setVerifyStatus(approved ? 1 : 2);
|
||||
task.setUpdatedAt(DateUtils.getNowDate());
|
||||
task.setRemark(approved ? "审核通过" : "审核拒绝");
|
||||
taskService.updateById(task);
|
||||
taskMapper.updateUsdtAggregationTask(task);
|
||||
}
|
||||
|
||||
/** 仅允许删除审核拒绝且尚未执行的任务;主任务与明细同事务软删除,保留审计记录。 */
|
||||
@@ -175,10 +179,15 @@ public class UsdtAggregationWorkflowService {
|
||||
if (itemMapper.cancelPendingItem(itemId) != 1) {
|
||||
throw new CustomException("仅待执行的归集明细可以取消,请刷新列表");
|
||||
}
|
||||
// 与子项取消处于同一事务;主任务行锁使并发取消串行,最后一个取消负责关闭任务。
|
||||
taskMapper.closeIfAllItemsCancelled(item.getParentId());
|
||||
}
|
||||
|
||||
public void executeTask(Long taskId, String password, boolean userMode) {
|
||||
UsdtAggregationTaskPlus task = requireTask(taskId, userMode);
|
||||
if (Integer.valueOf(4).equals(task.getStatus())) {
|
||||
throw new CustomException("归集任务已关闭,不能执行");
|
||||
}
|
||||
if (!Integer.valueOf(1).equals(task.getVerifyStatus())) {
|
||||
throw new CustomException("归集任务尚未审核通过");
|
||||
}
|
||||
@@ -190,10 +199,9 @@ public class UsdtAggregationWorkflowService {
|
||||
.eq(UsdtAggregationTaskItemPlus::getParentId, taskId)
|
||||
.in(UsdtAggregationTaskItemPlus::getStatus, 0L, 2L));
|
||||
boolean failed = walletSigningService.executeUnlocked(password, session -> {
|
||||
task.setStatus(1);
|
||||
task.setExeTime(DateUtils.getNowDate());
|
||||
task.setUpdatedAt(DateUtils.getNowDate());
|
||||
taskService.updateById(task);
|
||||
if (taskMapper.startExecutableTask(taskId) != 1) {
|
||||
throw new CustomException("任务状态已变化,可能已关闭或正在执行,请刷新后重试");
|
||||
}
|
||||
|
||||
boolean hasFailure = false;
|
||||
for (UsdtAggregationTaskItemPlus item : items) {
|
||||
@@ -295,7 +303,7 @@ public class UsdtAggregationWorkflowService {
|
||||
task.setStatus(failed ? 3 : 2);
|
||||
task.setUpdatedAt(DateUtils.getNowDate());
|
||||
task.setRemark(failed ? "执行完成,存在失败明细" : "归集执行完成(已取消明细不参与执行)");
|
||||
taskService.updateById(task);
|
||||
taskMapper.finishExecutableTask(task.getId(), task.getStatus(), task.getRemark());
|
||||
}
|
||||
|
||||
private AppsPlus resolveApp(AggregationTaskCreateRequest request, boolean userMode) {
|
||||
|
||||
Reference in new issue
Block a user