|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.mapper.order;
|
|
package com.cyksj.mapper.order;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
+import com.cyksj.model.dto.MultiQuantityTicketCountDto;
|
|
|
import com.cyksj.model.entity.OrderDonTicketRecord;
|
|
import com.cyksj.model.entity.OrderDonTicketRecord;
|
|
|
import org.apache.ibatis.annotations.Insert;
|
|
import org.apache.ibatis.annotations.Insert;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Param;
|
|
@@ -27,15 +28,42 @@ public interface OrderDonTicketRecordMapper extends BaseMapper<OrderDonTicketRec
|
|
|
@Select("select count(*) from order_don_ticket_record where order_id = #{orderId}")
|
|
@Select("select count(*) from order_don_ticket_record where order_id = #{orderId}")
|
|
|
int countByOrderId(@Param("orderId") Long orderId);
|
|
int countByOrderId(@Param("orderId") Long orderId);
|
|
|
|
|
|
|
|
|
|
+ @Select({"<script>",
|
|
|
|
|
+ "select order_id as orderId, count(*) as ticketTotalNum,",
|
|
|
|
|
+ "sum(case when status = 'success' then 1 else 0 end) as ticketSuccessNum,",
|
|
|
|
|
+ "sum(case when status = 'processing' then 1 else 0 end) as ticketProcessingNum,",
|
|
|
|
|
+ "sum(case when status in ('pending', 'failed') or (status = 'processing' and processing_time < date_sub(now(), interval 5 minute)) then 1 else 0 end) as ticketRedeliverableNum,",
|
|
|
|
|
+ "sum(case when status = 'pending' then 1 else 0 end) as ticketPendingNum,",
|
|
|
|
|
+ "sum(case when status = 'failed' then 1 else 0 end) as ticketFailedNum,",
|
|
|
|
|
+ "sum(case when status = 'refunding' then 1 else 0 end) as ticketRefundingNum,",
|
|
|
|
|
+ "sum(case when status = 'refunded' then 1 else 0 end) as ticketRefundedNum,",
|
|
|
|
|
+ "sum(case when status = 'cleared' then 1 else 0 end) as ticketClearedNum",
|
|
|
|
|
+ "from order_don_ticket_record where order_id in",
|
|
|
|
|
+ "<foreach collection='orderIds' item='orderId' open='(' separator=',' close=')'>",
|
|
|
|
|
+ "#{orderId}",
|
|
|
|
|
+ "</foreach>",
|
|
|
|
|
+ "group by order_id",
|
|
|
|
|
+ "</script>"})
|
|
|
|
|
+ List<MultiQuantityTicketCountDto> selectTicketCounts(@Param("orderIds") List<Long> orderIds);
|
|
|
|
|
+
|
|
|
@Update("update order_don_ticket_record set status = 'processing', worker_token = #{workerToken}, processing_time = now(), retry_num = retry_num + 1, error_msg = null, update_time = now() where id = #{id} and retry_num < #{maxRetries} and (status = 'pending' or (status = 'failed' and update_time <= date_sub(now(), interval 1 minute)))")
|
|
@Update("update order_don_ticket_record set status = 'processing', worker_token = #{workerToken}, processing_time = now(), retry_num = retry_num + 1, error_msg = null, update_time = now() where id = #{id} and retry_num < #{maxRetries} and (status = 'pending' or (status = 'failed' and update_time <= date_sub(now(), interval 1 minute)))")
|
|
|
int claim(@Param("id") Long id, @Param("workerToken") String workerToken,
|
|
int claim(@Param("id") Long id, @Param("workerToken") String workerToken,
|
|
|
@Param("maxRetries") int maxRetries);
|
|
@Param("maxRetries") int maxRetries);
|
|
|
|
|
|
|
|
|
|
+ @Update("update order_don_ticket_record r inner join order_don o on o.id = r.order_id set r.status = 'processing', r.worker_token = #{workerToken}, r.processing_time = now(), r.retry_num = r.retry_num + 1, r.error_msg = null, r.update_time = now() where r.id = #{id} and r.order_id = #{orderId} and o.status in ('hasPayment', 'complete') and r.status in ('pending', 'failed') and not exists (select 1 from order_don_business_event e where e.order_id = r.order_id and e.event_type = 'refund' and e.status in ('processing', 'success'))")
|
|
|
|
|
+ int claimManually(@Param("orderId") Long orderId,
|
|
|
|
|
+ @Param("id") Long id,
|
|
|
|
|
+ @Param("workerToken") String workerToken);
|
|
|
|
|
+
|
|
|
|
|
+ @Update("update order_don_ticket_record r set r.status = 'failed', r.worker_token = null, r.processing_time = null, r.error_msg = 'delivery lease expired; waiting for manual redelivery', r.update_time = now() where r.order_id = #{orderId} and r.status = 'processing' and r.processing_time < date_sub(now(), interval #{minutes} minute) and not exists (select 1 from order_don_business_event e where e.order_id = r.order_id and e.event_type = 'refund' and e.status in ('processing', 'success'))")
|
|
|
|
|
+ int recoverExpiredProcessingForOrder(@Param("orderId") Long orderId,
|
|
|
|
|
+ @Param("minutes") int minutes);
|
|
|
|
|
+
|
|
|
@Select("select * from order_don_ticket_record where id = #{id} and status = 'processing' and worker_token = #{workerToken} limit 1 for update")
|
|
@Select("select * from order_don_ticket_record where id = #{id} and status = 'processing' and worker_token = #{workerToken} limit 1 for update")
|
|
|
OrderDonTicketRecord lockClaim(@Param("id") Long id,
|
|
OrderDonTicketRecord lockClaim(@Param("id") Long id,
|
|
|
@Param("workerToken") String workerToken);
|
|
@Param("workerToken") String workerToken);
|
|
|
|
|
|
|
|
- @Update("update order_don_ticket_record set status = 'success', relation_id = #{relationId}, worker_token = null, processing_time = null, error_msg = null, update_time = now() where id = #{id} and status = 'processing' and worker_token = #{workerToken}")
|
|
|
|
|
|
|
+ @Update("update order_don_ticket_record set status = 'success', relation_id = #{relationId}, active_relation_id = #{relationId}, worker_token = null, processing_time = null, error_msg = null, update_time = now() where id = #{id} and status = 'processing' and worker_token = #{workerToken}")
|
|
|
int markSuccess(@Param("id") Long id, @Param("relationId") Long relationId, @Param("workerToken") String workerToken);
|
|
int markSuccess(@Param("id") Long id, @Param("relationId") Long relationId, @Param("workerToken") String workerToken);
|
|
|
|
|
|
|
|
@Update("update order_don_ticket_record set status = 'failed', worker_token = null, processing_time = null, error_msg = #{errorMsg}, update_time = now() where id = #{id} and status = 'processing' and worker_token = #{workerToken}")
|
|
@Update("update order_don_ticket_record set status = 'failed', worker_token = null, processing_time = null, error_msg = #{errorMsg}, update_time = now() where id = #{id} and status = 'processing' and worker_token = #{workerToken}")
|
|
@@ -79,33 +107,33 @@ public interface OrderDonTicketRecordMapper extends BaseMapper<OrderDonTicketRec
|
|
|
int countAvailable(@Param("orderId") Long orderId);
|
|
int countAvailable(@Param("orderId") Long orderId);
|
|
|
|
|
|
|
|
@Update("update order_don_ticket_record r " +
|
|
@Update("update order_don_ticket_record r " +
|
|
|
- "inner join groups_relation old_gr on old_gr.id = r.active_relation_id " +
|
|
|
|
|
|
|
+ "inner join groups_relation old_gr on old_gr.id = coalesce(r.active_relation_id, r.relation_id) " +
|
|
|
"inner join groups_trips old_gt on old_gt.id = old_gr.groups_id " +
|
|
"inner join groups_trips old_gt on old_gt.id = old_gr.groups_id " +
|
|
|
"inner join groups_relation new_gr on new_gr.id = #{newRelationId} " +
|
|
"inner join groups_relation new_gr on new_gr.id = #{newRelationId} " +
|
|
|
"inner join groups_trips new_gt on new_gt.id = new_gr.groups_id " +
|
|
"inner join groups_trips new_gt on new_gt.id = new_gr.groups_id " +
|
|
|
- "set r.relation_id = #{newRelationId}, r.update_time = now() " +
|
|
|
|
|
- "where r.active_relation_id = #{oldRelationId} and r.status = 'success' " +
|
|
|
|
|
|
|
+ "set r.active_relation_id = #{newRelationId}, r.update_time = now() " +
|
|
|
|
|
+ "where coalesce(r.active_relation_id, r.relation_id) = #{oldRelationId} and r.status = 'success' " +
|
|
|
"and old_gt.sku_id = new_gt.sku_id")
|
|
"and old_gt.sku_id = new_gt.sku_id")
|
|
|
int replaceActiveRelation(@Param("oldRelationId") Long oldRelationId,
|
|
int replaceActiveRelation(@Param("oldRelationId") Long oldRelationId,
|
|
|
@Param("newRelationId") Long newRelationId);
|
|
@Param("newRelationId") Long newRelationId);
|
|
|
|
|
|
|
|
- @Select("select r.* from order_don_ticket_record r inner join groups_relation gr on gr.id = r.relation_id where gr.groups_id = #{groupsId} and r.status = 'success' order by r.item_index")
|
|
|
|
|
|
|
+ @Select("select r.* from order_don_ticket_record r inner join groups_relation gr on gr.id = coalesce(r.active_relation_id, r.relation_id) where gr.groups_id = #{groupsId} and r.status = 'success' order by r.item_index")
|
|
|
List<OrderDonTicketRecord> selectSuccessfulByGroupsId(@Param("groupsId") Long groupsId);
|
|
List<OrderDonTicketRecord> selectSuccessfulByGroupsId(@Param("groupsId") Long groupsId);
|
|
|
|
|
|
|
|
@Select("select distinct r.order_id from order_don_ticket_record r " +
|
|
@Select("select distinct r.order_id from order_don_ticket_record r " +
|
|
|
"inner join order_don o on o.id = r.order_id " +
|
|
"inner join order_don o on o.id = r.order_id " +
|
|
|
- "inner join groups_relation gr on gr.id = r.relation_id " +
|
|
|
|
|
|
|
+ "inner join groups_relation gr on gr.id = coalesce(r.active_relation_id, r.relation_id) " +
|
|
|
"where gr.groups_id = #{groupsId} and r.status = 'success' " +
|
|
"where gr.groups_id = #{groupsId} and r.status = 'success' " +
|
|
|
"and o.status in ('hasPayment', 'complete') order by r.order_id")
|
|
"and o.status in ('hasPayment', 'complete') order by r.order_id")
|
|
|
List<Long> selectSuccessfulOrderIdsByGroupsId(@Param("groupsId") Long groupsId);
|
|
List<Long> selectSuccessfulOrderIdsByGroupsId(@Param("groupsId") Long groupsId);
|
|
|
|
|
|
|
|
- @Update("update order_don_ticket_record set status = 'cleared', worker_token = null, processing_time = null, error_msg = null, update_time = now() where active_relation_id = #{relationId} and status = 'success'")
|
|
|
|
|
|
|
+ @Update("update order_don_ticket_record set status = 'cleared', worker_token = null, processing_time = null, error_msg = null, update_time = now() where coalesce(active_relation_id, relation_id) = #{relationId} and status = 'success'")
|
|
|
int clearActiveRelation(@Param("relationId") Long relationId);
|
|
int clearActiveRelation(@Param("relationId") Long relationId);
|
|
|
|
|
|
|
|
- @Select("select * from order_don_ticket_record where active_relation_id = #{relationId} limit 1")
|
|
|
|
|
|
|
+ @Select("select * from order_don_ticket_record where coalesce(active_relation_id, relation_id) = #{relationId} limit 1")
|
|
|
OrderDonTicketRecord selectActiveByRelationId(@Param("relationId") Long relationId);
|
|
OrderDonTicketRecord selectActiveByRelationId(@Param("relationId") Long relationId);
|
|
|
|
|
|
|
|
- @Select("select * from order_don_ticket_record where active_relation_id = #{relationId} limit 1 for update")
|
|
|
|
|
|
|
+ @Select("select * from order_don_ticket_record where coalesce(active_relation_id, relation_id) = #{relationId} limit 1 for update")
|
|
|
OrderDonTicketRecord selectActiveByRelationIdForUpdate(@Param("relationId") Long relationId);
|
|
OrderDonTicketRecord selectActiveByRelationIdForUpdate(@Param("relationId") Long relationId);
|
|
|
|
|
|
|
|
@Select("select count(*) from order_don_ticket_record where order_id = #{orderId} and status = #{status}")
|
|
@Select("select count(*) from order_don_ticket_record where order_id = #{orderId} and status = #{status}")
|