+ * 返回值为受影响行数:1 表示释放成功;0 表示记录不存在/状态不符/冻结不足。
+ */
+ @Update("""
+ UPDATE glt_user_ticket
+ SET available_qty = COALESCE(available_qty, 0) + #{qty},
+ frozen_qty = COALESCE(frozen_qty, 0) - #{qty},
+ released_qty = COALESCE(released_qty, 0) + #{qty},
+ update_time = #{now}
+ WHERE id = #{id}
+ AND user_id = #{userId}
+ AND tenant_id = #{tenantId}
+ AND status = 0
+ AND deleted = 0
+ AND COALESCE(frozen_qty, 0) >= #{qty}
+ """)
+ int releaseFrozenQty(@Param("id") Integer id,
+ @Param("userId") Integer userId,
+ @Param("tenantId") Integer tenantId,
+ @Param("qty") Integer qty,
+ @Param("now") LocalDateTime now);
+
}
diff --git a/src/main/java/com/gxwebsoft/glt/mapper/GltUserTicketReleaseMapper.java b/src/main/java/com/gxwebsoft/glt/mapper/GltUserTicketReleaseMapper.java
index aef1462..baf5639 100644
--- a/src/main/java/com/gxwebsoft/glt/mapper/GltUserTicketReleaseMapper.java
+++ b/src/main/java/com/gxwebsoft/glt/mapper/GltUserTicketReleaseMapper.java
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.glt.entity.GltUserTicketRelease;
import com.gxwebsoft.glt.param.GltUserTicketReleaseParam;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
+import java.time.LocalDateTime;
import java.util.List;
/**
@@ -34,4 +37,37 @@ public interface GltUserTicketReleaseMapper extends BaseMapper
+ * 现有发放类型为 10(见 GltTicketIssueService.CHANGE_TYPE_ISSUE),这里取 11。
+ */
+ private static final int CHANGE_TYPE_RELEASE = 11;
+
+ /** release.status:待释放 */
+ private static final int RELEASE_STATUS_PENDING = 0;
+ /** release.status:已释放 */
+ private static final int RELEASE_STATUS_DONE = 1;
+ /** release.status:释放失败(数据异常/冻结不足等,需人工处理) */
+ private static final int RELEASE_STATUS_FAILED = 2;
+
+ private final GltUserTicketReleaseMapper releaseMapper;
+ private final GltUserTicketMapper userTicketMapper;
+ private final GltUserTicketLogMapper userTicketLogMapper;
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int releaseDue(LocalDateTime now, int batchSize) {
+ int limit = Math.max(batchSize, 1);
+ List