usdt归集明细页面usdtTaskItem和USDTmanage/usdtTaskItem,添加取消归集明细任务功能。
This commit is contained in:
1 parent
2870c3fb6c
commit
62f43056e2
8 files changed
+161
-10
No files matched your search
+17
-1
@@ -33,6 +33,22 @@ public class UsdtAggregationTaskItemController extends BaseController {
|
||||
@Autowired
|
||||
private UsdtAggregationWorkflowService aggregationWorkflowService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtTaskItem:edit')")
|
||||
@Log(title = "取消归集明细", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/{id}/cancel")
|
||||
public AjaxResult cancel(@PathVariable("id") Long id) {
|
||||
aggregationWorkflowService.cancelItem(id, false);
|
||||
return AjaxResult.success("归集明细已取消");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtTaskItem:user-edit')")
|
||||
@Log(title = "取消归集明细", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/user/{id}/cancel")
|
||||
public AjaxResult userCancel(@PathVariable("id") Long id) {
|
||||
aggregationWorkflowService.cancelItem(id, true);
|
||||
return AjaxResult.success("归集明细已取消");
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动重新执行单个失败明细,仍要求配置密码。
|
||||
*/
|
||||
@@ -143,6 +159,6 @@ public class UsdtAggregationTaskItemController extends BaseController {
|
||||
}
|
||||
/*
|
||||
* 明细金额、来源地址、目标地址和执行状态均由归集工作流维护。
|
||||
* 对外只保留查询与失败项重试接口,禁止任意增删改明细。
|
||||
* 对外仅开放查询、待执行项取消与失败项重试,禁止任意增删改明细。
|
||||
*/
|
||||
}
|
||||
@@ -29,8 +29,8 @@ public class UsdtAggregationTaskItem extends BaseEntity
|
||||
@Excel(name = "钱包地址")
|
||||
private String tokenAddress;
|
||||
|
||||
/** 状态0 待执行 1 执行 2 执行失败 */
|
||||
@Excel(name = "状态0 待执行 1 执行 2 执行失败")
|
||||
/** 明细状态:0 待执行,1 成功,2 失败,3 已取消,4 执行中。取消不可恢复。 */
|
||||
@Excel(name = "状态", readConverterExp = "0=待执行,1=成功,2=失败,3=已取消,4=执行中")
|
||||
private Long status;
|
||||
|
||||
/** 金额 */
|
||||
|
||||
@@ -30,8 +30,8 @@ public class UsdtAggregationTaskItemPlus implements Serializable
|
||||
/** 钱包地址 */
|
||||
@Excel(name = "钱包地址")
|
||||
private String tokenAddress;
|
||||
/** 状态0 待执行 1 执行 2 执行失败 */
|
||||
@Excel(name = "状态0 待执行 1 执行 2 执行失败")
|
||||
/** 明细状态:0 待执行,1 成功,2 失败,3 已取消,4 执行中。取消不可恢复。 */
|
||||
@Excel(name = "状态", readConverterExp = "0=待执行,1=成功,2=失败,3=已取消,4=执行中")
|
||||
private Long status;
|
||||
/** 备注 */
|
||||
@Excel(name = "备注")
|
||||
|
||||
@@ -15,6 +15,11 @@ import com.ruoyi.system.domain.UsdtAggregationTaskItemPlus;
|
||||
*/
|
||||
public interface UsdtAggregationTaskItemMapper extends BaseMapper<UsdtAggregationTaskItemPlus>
|
||||
{
|
||||
/** 仅待执行明细可以取消;SQL 条件更新与执行抢占互斥。 */
|
||||
int cancelPendingItem(@Param("id") Long id);
|
||||
|
||||
/** 广播前原子抢占明细,防止取消成功后仍按旧快照执行。 */
|
||||
int claimItemForExecution(@Param("id") Long id);
|
||||
/**
|
||||
* 查询归集任务明细
|
||||
*
|
||||
|
||||
+32
-5
@@ -157,6 +157,26 @@ public class UsdtAggregationWorkflowService {
|
||||
.set(UsdtAggregationTaskItemPlus::getUpdatedAt, now));
|
||||
}
|
||||
|
||||
/** 取消保留原明细及资源预算作为审计记录,不能撤销已广播的链上交易。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelItem(Long itemId, boolean userMode) {
|
||||
UsdtAggregationTaskItem item = itemMapper.selectUsdtAggregationTaskItemById(itemId);
|
||||
if (item == null) {
|
||||
throw new CustomException("归集明细不存在或已删除");
|
||||
}
|
||||
UsdtAggregationTask task = taskMapper.selectUsdtAggregationTaskByIdForUpdate(item.getParentId());
|
||||
if (task == null) {
|
||||
throw new CustomException("归集任务不存在或已删除");
|
||||
}
|
||||
if (userMode && (!SecurityUtils.getUserId().equals(task.getUserId())
|
||||
|| !SecurityUtils.getUserId().equals(item.getUserId()))) {
|
||||
throw new CustomException("无权取消该归集明细");
|
||||
}
|
||||
if (itemMapper.cancelPendingItem(itemId) != 1) {
|
||||
throw new CustomException("仅待执行的归集明细可以取消,请刷新列表");
|
||||
}
|
||||
}
|
||||
|
||||
public void executeTask(Long taskId, String password, boolean userMode) {
|
||||
UsdtAggregationTaskPlus task = requireTask(taskId, userMode);
|
||||
if (!Integer.valueOf(1).equals(task.getVerifyStatus())) {
|
||||
@@ -237,12 +257,19 @@ public class UsdtAggregationWorkflowService {
|
||||
|
||||
private boolean executeItemInternal(UsdtAggregationTaskItemPlus item,
|
||||
WalletSigningService.UnlockedWalletSession session) {
|
||||
WalletAddressPlus wallet = walletService.getByTokenAndAppId(item.getTokenAddress(), item.getAppId());
|
||||
if (wallet == null) {
|
||||
markFailed(item, "钱包不存在或已不属于当前应用");
|
||||
return false;
|
||||
// 使用数据库状态而非列表快照决定是否允许广播,取消与执行只能有一方成功。
|
||||
if (itemMapper.claimItemForExecution(item.getId()) != 1) {
|
||||
UsdtAggregationTaskItem current = itemMapper.selectUsdtAggregationTaskItemById(item.getId());
|
||||
return current != null && (Long.valueOf(3L).equals(current.getStatus())
|
||||
|| Long.valueOf(1L).equals(current.getStatus()));
|
||||
}
|
||||
item.setStatus(4L);
|
||||
try {
|
||||
WalletAddressPlus wallet = walletService.getByTokenAndAppId(item.getTokenAddress(), item.getAppId());
|
||||
if (wallet == null) {
|
||||
markFailed(item, "钱包不存在或已不属于当前应用");
|
||||
return false;
|
||||
}
|
||||
String tx = session.execute(wallet, (tron, api, current) ->
|
||||
tron.usdtTransWithBroadcastRetry(api, current.getToken(),
|
||||
item.getDistTokenAddress(), item.getOpeAmount(), MAX_ATTEMPTS));
|
||||
@@ -267,7 +294,7 @@ public class UsdtAggregationWorkflowService {
|
||||
private void finishTask(UsdtAggregationTaskPlus task, boolean failed) {
|
||||
task.setStatus(failed ? 3 : 2);
|
||||
task.setUpdatedAt(DateUtils.getNowDate());
|
||||
task.setRemark(failed ? "执行完成,存在失败明细" : "全部归集成功");
|
||||
task.setRemark(failed ? "执行完成,存在失败明细" : "归集执行完成(已取消明细不参与执行)");
|
||||
taskService.updateById(task);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user