update:调整异步策略

This commit is contained in:
Damonny 2025-03-03 18:10:39 +08:00
parent c0b98c69c4
commit 9a8decd608
1 changed files with 22 additions and 16 deletions

View File

@ -30,6 +30,7 @@ import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
@ -65,6 +66,9 @@ import static cn.iocoder.yudao.module.haoka.enums.ErrorCodeConstants.*;
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> implements OrdersService {
@Lazy
@Resource
private OrdersServiceImpl ordersService;
@Resource
private OrdersMapper ordersMapper;
@Resource
@ -162,13 +166,14 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> imple
ordersDO
);
// 异步判断是否自动提交审核订单
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
//异步操作
asyncSubmitAuditOrders(ordersDO);
}
});
// TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
// @Override
// public void afterCommit() {
// //异步操作
// asyncSubmitAuditOrders(ordersDO);
// }
// });
ordersService.asyncSubmitAuditOrders(ordersDO);
// 返回
return orders.getId();
}
@ -186,7 +191,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> imple
OrdersSaveReqVO ordersSaveReqVO = new OrdersSaveReqVO();
ordersSaveReqVO.setId(ordersDO.getId());
ordersSaveReqVO.setStatus(120L);
this.updateOrders(ordersSaveReqVO);
ordersService.updateOrders(ordersSaveReqVO);
}
}
@ -318,13 +323,14 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> imple
Integer autoType = oldOrderDo.getAutoType();
// 联合条件 自动生产 && 审核通过 && 提交初审
if(2 == autoType && canAudit && submit){
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
//异步操作
asyncAuditOrders(updateObj);
}
});
// TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
// @Override
// public void afterCommit() {
// //异步操作
// asyncAuditOrders(updateObj);
// }
// });
ordersService.asyncAuditOrders(updateObj);
}
}
@ -337,7 +343,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> imple
// 自动生产 调用审核
OrdersSaveReqVO ordersSaveReqVO = BeanUtils.toBean(ordersDO, OrdersSaveReqVO.class);
ordersSaveReqVO.setStatus(450L);
this.auditOrders(ordersSaveReqVO);
ordersService.auditOrders(ordersSaveReqVO);
}
/**