admin
2024-07-29 734dfe9eb0a2176103dce8245c69b1194574c68e
src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java
@@ -1,7 +1,10 @@
package com.taoke.autopay.manager;
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.service.KeyOrderService;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.utils.StringUtil;
import lombok.Builder;
import lombok.Data;
import org.springframework.stereotype.Component;
@@ -41,6 +44,9 @@
    private Queue<OrderQueue> orderQueues=new PriorityQueue<>();
    @Resource
    private SystemConfigService systemConfigService;
    public void clearCacheData(){
        reProcessCountMap.clear();
        orderQueues.clear();
@@ -67,22 +73,34 @@
           }
            reProcessCountMap.put(queue.getId(), reProcessCountMap.get(queue.getId())+1);
            keyOrderService.removeDistributedClient(queue.getId());
            String clientIds = systemConfigService.getValueCache(SystemConfigKeyEnum.RE_EXCUTE_PAY_CLIENTS);
            // 移除已经分配的设备,改变状态为未分配
            KeyOrder update=new KeyOrder();
            update.setId(queue.getId());
            update.setState(KeyOrder.STATE_NOT_PROCESS);
            update.setStateDesc("重新分配");
            if (!StringUtil.isNullOrEmpty(clientIds)) {
                String[] cids = clientIds.split(",");
                int index = (int) Math.round(Math.random() * cids.length);
                if (index + 1 > cids.length) {
                    index = cids.length - 1;
                }
                update.setDistributeClientUid(Long.parseLong(cids[index]));
            }
            keyOrderService.update(update);
        }
    }
    /**
     * @return void
     * @author hxh
     * @description 处理支付失败
     * @date 21:28 2024/7/26
     * @param: id
     * @param: msg
     * @return void
     **/
    @Transactional(rollbackFor = Exception.class)
    public void processPayFail(String id,String msg){