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

@@ -152,6 +152,11 @@
<update id="updateTaskStatus">
UPDATE print_task SET status = #{status}, update_time = NOW() WHERE id = #{id}
</update>
<update id="compareAndSetTaskStatus">
UPDATE print_task
SET status = #{newStatus}, update_time = NOW()
WHERE id = #{id} AND status = #{expectStatus}
</update>
<update id="setPhotoCropped">
UPDATE member_print SET crop_url = #{url}, update_time = NOW(), print_url = null WHERE id = #{id}
</update>
@@ -172,4 +177,4 @@
<delete id="deleteUserPhoto">
DELETE FROM member_print WHERE member_id = #{memberId} AND scenic_id = #{scenicId} AND id = #{relationId} LIMIT 1;
</delete>
</mapper>
</mapper>