From fa677dec1c55db004a31beefb1e346e18c7858c2 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 20 二月 2025 18:41:29 +0800 Subject: [PATCH] bug修改 --- src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java | 75 ++++++++++++++++++++++++++++--------- 1 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java b/src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java index 9c3e4df..1eebde3 100644 --- a/src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java +++ b/src/main/java/com/taoke/autopay/manager/OrderPayFailProcessor.java @@ -1,7 +1,10 @@ package com.taoke.autopay.manager; +import com.taoke.autopay.dao.KeyOrderMapper; +import com.taoke.autopay.entity.ClientInfo; 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,15 +14,12 @@ 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 * @title: OrderPayFailProcessor - * @description: TODO + * @description: 璁㈠崟鏀粯澶辫触澶勭悊鍣� * @date 2024/7/26 21:27 */ @Component @@ -47,9 +47,45 @@ @Resource private SystemConfigService systemConfigService; + @Resource + private ClientInfoService clientInfoService; + public void clearCacheData() { reProcessCountMap.clear(); orderQueues.clear(); + } + + private Long getTargetClientId() { + List<Long> clientIds = clientInfoService.getRePayClientIds(); + if (clientIds != null && clientIds.size() > 0) { + // 鏌ヨ璁惧鏈墽琛岀殑鏁伴噺 + List<List<Long>> clist=new ArrayList<>(); + for (Long cuid : clientIds) { + KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); + daoQuery.distributeClientUid =cuid; + daoQuery.state = KeyOrder.STATE_NOT_PAY; + daoQuery.minCreateTime=new Date(System.currentTimeMillis() - 1000*60*30L); + long count = keyOrderService.count(daoQuery); + clist.add(Arrays.asList(new Long[]{cuid,count})); + } + clist.sort(new Comparator<List<Long>>() { + @Override + public int compare(List<Long> o1, List<Long> o2) { + return (int)(o1.get(1)-o2.get(1)); + } + }); + if(clist.size()>1) { + for (int i = 1; i < clist.size(); i++) { + if (clist.get(i).get(1).longValue() != clist.get(i - 1).get(1)) { + clist = clist.subList(0, i); + break; + } + } + } + Collections.shuffle(clist); + return clist.get(0).get(0); + } + return null; } @Transactional(rollbackFor = Exception.class) @@ -57,8 +93,12 @@ if (orderQueues.isEmpty()) { return; } + Long targetCUID = getTargetClientId(); + if (targetCUID == null) { + return; + } OrderQueue queue = orderQueues.peek(); - if (queue != null && System.currentTimeMillis() > queue.expireTime) { + if (queue != null && System.currentTimeMillis() >= queue.expireTime) { queue = orderQueues.poll(); KeyOrder order = keyOrderService.selectById(queue.getId()); if (order == null || order.getState() != KeyOrder.STATE_REJECT_PAY) { @@ -68,28 +108,24 @@ 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); - - // 绉婚櫎宸茬粡鍒嗛厤鐨勮澶囷紝鏀瑰彉鐘舵�佷负鏈垎閰� 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])); - } + update.setDistributeClientUid(targetCUID); + update.setDistributeTime(new Date()); keyOrderService.update(update); } } @@ -108,12 +144,13 @@ return; } //鍔犲叆閲嶈瘯闃熷垪 - orderQueues.add(OrderQueue.builder().id(id).expireTime(System.currentTimeMillis() + 2 * 60 * 1000).build()); + orderQueues.add(OrderQueue.builder().id(id).expireTime(System.currentTimeMillis()).build()); KeyOrder update = new KeyOrder(); update.setId(id); update.setState(KeyOrder.STATE_REJECT_PAY); update.setStateDesc(msg); keyOrderService.update(update); + processFromQueue(); } public static void main(String[] args) { -- Gitblit v1.8.0