feat(printer): 实现任务状态的原子性更新与同步锁机制

- 添加 compareAndSetTaskStatus 方法以支持基于期望状态的任务更新
- 引入 ReentrantLock 实现任务同步处理,防止并发冲突
- 在 XML 映射文件中定义 compareAndSetTaskStatus 的 SQL 更新语句
- 定义任务状态常量:TASK_STATUS_PENDING 和 TASK_STATUS_PROCESSING
- 优化任务获取逻辑,确保任务状态在处理前正确更新为 PROCESSING
This commit is contained in:
2025-10-23 21:24:58 +08:00
parent 3f8b911e6f
commit bed3a4e3c9
3 changed files with 36 additions and 7 deletions

View File

@@ -28,6 +28,10 @@ public interface PrinterMapper {
int updateTaskStatus(@Param("id") Integer id, @Param("status") Integer status);
int compareAndSetTaskStatus(@Param("id") Integer id,
@Param("expectStatus") Integer expectStatus,
@Param("newStatus") Integer newStatus);
PrintTaskEntity getTaskById(Integer id);
List<PrinterResp> listByScenicId(@Param("scenicId") Long scenicId);
@@ -51,4 +55,4 @@ public interface PrinterMapper {
void updateUserPhotoListToPrinter(Long memberId, Long scenicId, Integer printerId);
List<MemberPrintResp> listRelationByOrderId(Long orderId);
}
}