admin
2024-08-04 bc56870059cca013649077af0e53891cba8dbfd1
src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java
@@ -2,6 +2,7 @@
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.service.ClientInfoService;
import com.taoke.autopay.service.KeyOrderService;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.utils.StringUtil;
@@ -11,10 +12,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.*;
/**
 * @author hxh
@@ -47,6 +45,9 @@
    @Resource
    private SystemConfigService systemConfigService;
    @Resource
    private ClientInfoService clientInfoService;
    public void clearCacheData() {
        reProcessCountMap.clear();
        orderQueues.clear();
@@ -68,27 +69,29 @@
                return;
            }
            // 超时30分钟不执行
            if(System.currentTimeMillis() - order.getCreateTime().getTime()> 30*60*1000L){
                return;
            }
            if (!reProcessCountMap.containsKey(queue.getId())) {
                reProcessCountMap.put(queue.getId(), 0);
            }
            reProcessCountMap.put(queue.getId(), reProcessCountMap.get(queue.getId()) + 1);
            keyOrderService.removeDistributedClient(queue.getId());
            String clientIds = systemConfigService.getValueCache(SystemConfigKeyEnum.RE_EXCUTE_PAY_CLIENTS);
            List<Long> clientIds = clientInfoService.getRePayClientIds();
            // 移除已经分配的设备,改变状态为未分配
            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;
            if (clientIds!=null&&clientIds.size()>0) {
                int index = (int) Math.round(Math.random() *clientIds.size());
                if (index + 1 > clientIds.size()) {
                    index = clientIds.size() - 1;
                }
                update.setDistributeClientUid(Long.parseLong(cids[index]));
                update.setDistributeClientUid(clientIds.get(index));
            }
            keyOrderService.update(update);
        }
@@ -108,7 +111,7 @@
            return;
        }
        //加入重试队列
        orderQueues.add(OrderQueue.builder().id(id).expireTime(System.currentTimeMillis() + 2 * 60 * 1000).build());
        orderQueues.add(OrderQueue.builder().id(id).expireTime(System.currentTimeMillis() + 1 * 60 * 1000).build());
        KeyOrder update = new KeyOrder();
        update.setId(id);
        update.setState(KeyOrder.STATE_REJECT_PAY);