From e7ae1f1cccca77ca89075cc663691f3befd3926e Mon Sep 17 00:00:00 2001 From: wangshuai Date: Tue, 30 Jul 2024 11:37:46 +0800 Subject: [PATCH] =?UTF-8?q?1;=20=E4=B8=A2=E5=8D=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86=20=20=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=8A=A0=20?= =?UTF-8?q?=E9=9A=A7=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeituanController.java | 1 + .../src/main/resources/application.yml | 1 + .../ruoyi/common/config/ProxyProperties.java | 12 +- .../business/service/impl/AsyncTaskImpl.java | 4 +- .../service/impl/MeituanServiceImpl.java | 300 ++++++++++-------- .../mapper/business/BusAgentInfoMapper.xml | 1 + 6 files changed, 172 insertions(+), 147 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java b/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java index 3e0a5be..399e5ad 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java @@ -81,6 +81,7 @@ public class MeituanController { * 批量获取订单 * @return */ + @ApiOperation("批量获取订单") @GetMapping("/orderInfoList") public R orderInfoList() { String result = iMeituanService.orderInfoList(); diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 785444f..266b312 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -71,6 +71,7 @@ spring: redis: # 地址 host: 43.140.224.18 +# host: localhost # 端口,默认为6379 port: 6379 # 数据库索引 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java index ec53aa9..54dddd4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java @@ -182,7 +182,7 @@ public class ProxyProperties { * 隧道 ip获取 * @return */ - public String gettps(){ + public String gettpsUrl(){ CloseableHttpClient httpclient = HttpClients.createDefault(); try { String params = "?secret_id=" + secretId + "&num=1&signature=" + secretKey; @@ -209,9 +209,9 @@ public class ProxyProperties { } return null; } - - public static void main(String[] args) { - ProxyProperties proxyProperties = new ProxyProperties(); - System.out.println(proxyProperties.gettps()); - } +// +// public static void main(String[] args) { +// ProxyProperties proxyProperties = new ProxyProperties(); +// System.out.println(proxyProperties.gettpsUrl()); +// } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java index 9b8ca6b..69e1ce7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java @@ -31,8 +31,8 @@ public class AsyncTaskImpl { LocalDateTime now = LocalDateTime.now(); //异步线程要做的事情 for (BusStoreInfo store : busStoreInfoList) { -// R flag = iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie()); - R flag = R.fail(); + R flag = iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie()); +// R flag = R.fail(); if (flag.getCode() != 200) { System.out.println(store.getStoreName()+"获取订单信息返回错误..."+store.getStoreCode()); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java index a4b2bf7..994d4fe 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java @@ -283,7 +283,6 @@ public class MeituanServiceImpl implements IMeituanService { busStoreInfo.setReturnVisitStatus("1"); List busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo); long startTime = System.currentTimeMillis(); // 开始时间 - //boolean a=studentService.batchInsert(list); List> list1= SplitListUtils.pagingList(busStoreInfoList,4); //拆分集合 CountDownLatch countDownLatch = new CountDownLatch(list1.size()); for (List list2 : list1) { @@ -385,157 +384,163 @@ public class MeituanServiceImpl implements IMeituanService { @Override @Transactional(rollbackFor = Exception.class) public R orderInfo(String wmPoiId, String date, String cookie) { //根据date,查询前一天的key,如果有,则删除 + try { + int pageNum = 1; + String getUrl = proxyProperties.gettpsUrl(); + JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie); + String code = jsonObject.getString("code"); + if ("0".equals(code)) { + JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList"); + + boolean flag = false; +// String key = wmPoiId + date; +// String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); + while (array != null && array.size() > 0) { +// if (flag) { +// break; +// } + List list = new ArrayList<>(); + for (int i = 0; i < array.size(); i++) { + BusOrderInfo orderInfo = new BusOrderInfo(); + Object o = array.get(i); + JSONObject oj = JSONObject.parseObject(JSON.toJSONString(o)); + try { + String businessType = oj.getString("businessType"); + JSONObject order0 = oj.getJSONObject("orderInfo"); + JSONObject commonInfo = oj.getJSONObject("commonInfo"); + String userId = commonInfo.getString("wmUserId"); + String daySeq = ""; String wmOrderViewId = ""; String orderTimeFmt = ""; String expectTime = ""; String statusDesc = ""; String orderCount = ""; + String privacyPhone = null; String recipientPhone = null; String recipientBindedPhone = null; + if ("1".equals(businessType)) { + JSONObject order1 = order0.getJSONObject("orderInfo"); + JSONObject foodInfo = order0.getJSONObject("foodInfo"); + JSONObject userLabelVo = foodInfo.getJSONObject("userLabelVo"); + JSONArray array1 = userLabelVo.getJSONArray("contents"); + String info = array1.getJSONObject(0).getString("info"); + JSONObject expectTimeVo = order1.getJSONObject("expectTimeVo"); + daySeq = order1.getString("dayseq"); + wmOrderViewId = order1.getString("wmOrderViewId"); + orderTimeFmt = "2024-"+order1.getString("orderTimeFmt"); + expectTime = expectTimeVo.getString("expectTimeFmt"); + statusDesc = order1.getString("statusDesc"); + if ("门店新客".equals(info)){ + orderCount = "1"; + } else if (info.contains("下单")){ + orderCount = info.substring(info.indexOf("下单")+2,info.length()-1); + } + }else if("2".equals(businessType)){ + statusDesc = "用户已收餐"; + wmOrderViewId = commonInfo.getString("wm_order_id_view"); + orderTimeFmt = order0.getString("order_time_fmt"); + expectTime = order0.getString("expectTimeFmt"); + daySeq = commonInfo.getString("wm_poi_order_dayseq"); + privacyPhone = order0.getString("privacy_phone"); + recipientPhone = order0.getString("recipient_phone"); + recipientBindedPhone = order0.getString("recipient_bindedPhone"); + + + orderCount = getOrderCountByType(getUrl,wmOrderViewId,cookie); - int pageNum = 1; - String getUrl = null; - JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie); - String code = jsonObject.getString("code"); - if ("0".equals(code)) { - JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList"); - boolean flag = false; - String key = wmPoiId + date; - String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); - while (array != null && array.size() > 0) { - if (flag) { - break; - } - List list = new ArrayList<>(); - for (int i = 0; i < array.size(); i++) { - BusOrderInfo orderInfo = new BusOrderInfo(); - Object o = array.get(i); - JSONObject oj = JSONObject.parseObject(JSON.toJSONString(o)); - try { - String businessType = oj.getString("businessType"); - JSONObject order0 = oj.getJSONObject("orderInfo"); - JSONObject commonInfo = oj.getJSONObject("commonInfo"); - String userId = commonInfo.getString("wmUserId"); - String daySeq = ""; String wmOrderViewId = ""; String orderTimeFmt = ""; String expectTime = ""; String statusDesc = ""; String orderCount = ""; - String privacyPhone = null; String recipientPhone = null; String recipientBindedPhone = null; - if ("1".equals(businessType)) { - JSONObject order1 = order0.getJSONObject("orderInfo"); - JSONObject foodInfo = order0.getJSONObject("foodInfo"); - JSONObject userLabelVo = foodInfo.getJSONObject("userLabelVo"); - JSONArray array1 = userLabelVo.getJSONArray("contents"); - String info = array1.getJSONObject(0).getString("info"); - JSONObject expectTimeVo = order1.getJSONObject("expectTimeVo"); - daySeq = order1.getString("dayseq"); - wmOrderViewId = order1.getString("wmOrderViewId"); - orderTimeFmt = "2024-"+order1.getString("orderTimeFmt"); - expectTime = expectTimeVo.getString("expectTimeFmt"); - statusDesc = order1.getString("statusDesc"); - if ("门店新客".equals(info)){ - orderCount = "1"; - } else if (info.contains("下单")){ - orderCount = info.substring(info.indexOf("下单")+2,info.length()-1); } - }else if("2".equals(businessType)){ - statusDesc = "用户已收餐"; - wmOrderViewId = commonInfo.getString("wm_order_id_view"); - orderTimeFmt = order0.getString("order_time_fmt"); - expectTime = order0.getString("expectTimeFmt"); - daySeq = commonInfo.getString("wm_poi_order_dayseq"); - privacyPhone = order0.getString("privacy_phone"); - recipientPhone = order0.getString("recipient_phone"); - recipientBindedPhone = order0.getString("recipient_bindedPhone"); +// String redisDaySeq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); +// if (redisDaySeq == null) { +// redisTemplate.opsForValue().set(key, daySeq); +// } else { +// if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) { +// redisTemplate.opsForValue().set(key, daySeq); +// } +// if (daySeq.equals(lastDayseq)) { +// flag = true; +// break; +// } +// } + orderInfo.setStoreCode(wmPoiId); + orderInfo.setDayseq(daySeq); + orderInfo.setOrderNo(wmOrderViewId); - - orderCount = getOrderCountByType(getUrl,wmOrderViewId,cookie); - - - } - String redisDaySeq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); - if (redisDaySeq == null) { - redisTemplate.opsForValue().set(key, daySeq); - } else { - if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) { - redisTemplate.opsForValue().set(key, daySeq); + if(expectTime.contains("今日")){ + expectTime = expectTime.substring(3,expectTime.length()); } - if (daySeq.equals(lastDayseq)) { - flag = true; - break; + + BusStoreInfo storeInfo = new BusStoreInfo(); + storeInfo.setStoreCode(wmPoiId); + BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); + + orderInfo.setStoreName(storeInfo1.getStoreName()); + + String completeTime = "2024-"+expectTime; + if (completeTime.contains("门店设置")){ + completeTime = completeTime.replaceAll("门店设置",""); + } + if (completeTime.contains("约今日")){ + completeTime = completeTime.replaceAll("约今日 ",""); + } + if (completeTime.contains("明日")){ + completeTime = completeTime.replaceAll("明日 ",""); } - } - orderInfo.setStoreCode(wmPoiId); - orderInfo.setDayseq(daySeq); - orderInfo.setOrderNo(wmOrderViewId); - if(expectTime.contains("今日")){ - expectTime = expectTime.substring(3,expectTime.length()); + orderInfo.setCompleteTime(completeTime); + orderInfo.setOrderStatus(statusDesc); + orderInfo.setCustomId(userId); + orderInfo.setOrderCount(orderCount); + orderInfo.setPrivcyPhone(privacyPhone); + orderInfo.setRecipientPhone(recipientPhone); + orderInfo.setRecipientBindedPhone(recipientBindedPhone); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + try { + orderInfo.setOrderTime(format.parse(orderTimeFmt)); + } catch (ParseException e) { + System.out.println(e.getMessage()); + } + orderInfo.setIsPhf(businessType); + }catch (Exception e){ + e.printStackTrace(); + continue; } + list.add(orderInfo); + } + if (list.size() > 0) { + List newList = list.stream().collect(Collectors.toMap(BusOrderInfo::getOrderNo, p->p,(p1, p2)->p1)).values().stream().collect(Collectors.toList()); + priPhoneInfo(newList,cookie,getUrl); + }else{ + break; + } + + pageNum += 1; + + JSONObject jo = merchantOrders(getUrl,pageNum, date, cookie); + if ("0".equals(jo.getString("code"))) { + array = jo.getJSONObject("data").getJSONArray("wmOrderList"); + } else if ("1001".equals(jo.getString("code"))) { BusStoreInfo storeInfo = new BusStoreInfo(); storeInfo.setStoreCode(wmPoiId); BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); + storeInfo1.setGrantStatus("2"); + busStoreInfoMapper.updateBusStoreInfo(storeInfo1); - orderInfo.setStoreName(storeInfo1.getStoreName()); - - String completeTime = "2024-"+expectTime; - if (completeTime.contains("门店设置")){ - completeTime = completeTime.replaceAll("门店设置",""); - } - if (completeTime.contains("约今日")){ - completeTime = completeTime.replaceAll("约今日 ",""); - } - if (completeTime.contains("明日")){ - completeTime = completeTime.replaceAll("明日 ",""); - } - - orderInfo.setCompleteTime(completeTime); - orderInfo.setOrderStatus(statusDesc); - orderInfo.setCustomId(userId); - orderInfo.setOrderCount(orderCount); - orderInfo.setPrivcyPhone(privacyPhone); - orderInfo.setRecipientPhone(recipientPhone); - orderInfo.setRecipientBindedPhone(recipientBindedPhone); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - try { - orderInfo.setOrderTime(format.parse(orderTimeFmt)); - } catch (ParseException e) { - System.out.println(e.getMessage()); - } - orderInfo.setIsPhf(businessType); - }catch (Exception e){ - e.printStackTrace(); - continue; + System.out.println(jo.getString("msg")); + return R.fail(jo.getString("msg")); } - list.add(orderInfo); - } - if (list.size() > 0) { - List newList = list.stream().collect(Collectors.toMap(BusOrderInfo::getOrderNo, p->p,(p1, p2)->p1)).values().stream().collect(Collectors.toList()); - - priPhoneInfo(newList,cookie,getUrl); - } - - pageNum += 1; - - JSONObject jo = merchantOrders(getUrl,pageNum, date, cookie); - if ("0".equals(jo.getString("code"))) { - array = jo.getJSONObject("data").getJSONArray("wmOrderList"); - } else if ("1001".equals(jo.getString("code"))) { - BusStoreInfo storeInfo = new BusStoreInfo(); - storeInfo.setStoreCode(wmPoiId); - BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); - storeInfo1.setGrantStatus("2"); - busStoreInfoMapper.updateBusStoreInfo(storeInfo1); - - System.out.println(jo.getString("msg")); - return R.fail(jo.getString("msg")); } + return R.ok(); + } else if ("1001".equals(code)) { + BusStoreInfo storeInfo = new BusStoreInfo(); + storeInfo.setStoreCode(wmPoiId); + BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); + storeInfo1.setGrantStatus("2"); + busStoreInfoMapper.updateBusStoreInfo(storeInfo1); } - return R.ok(); - } else if ("1001".equals(code)) { - BusStoreInfo storeInfo = new BusStoreInfo(); - storeInfo.setStoreCode(wmPoiId); - BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); - storeInfo1.setGrantStatus("2"); - busStoreInfoMapper.updateBusStoreInfo(storeInfo1); + return R.fail(jsonObject.getString("msg")); + }catch (Exception e){ + e.printStackTrace(); + return orderInfo(wmPoiId, date, cookie); } - return R.fail(jsonObject.getString("msg")); } private String getOrderCountByType(String getUrl, String wmOrderViewId,String cookie){ - CloseableHttpClient httpClient = proxyHttpClient(); + CloseableHttpClient httpClient = proxyHttpClient(getUrl); String url = "https://e.waimai.meituan.com/gw/phf/v2/order/receive/processed/r/orderAsyncInfos/v3"; Map params = new HashMap<>(); params.put("region_id", valueFromCookie("region_id",cookie)); @@ -595,7 +600,7 @@ public class MeituanServiceImpl implements IMeituanService { httpPost.setHeader("Host","waimaieapp.meituan.com"); httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); // CloseableHttpClient client = HttpClientBuilder.create().build(); HttpEntity responseEntity; String resp = null; @@ -715,7 +720,7 @@ public class MeituanServiceImpl implements IMeituanService { httpPost.setEntity(entity); httpPost.setHeader("Cookie", cookie); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); String code = null; JSONObject jsonObject = new JSONObject(); @@ -1023,10 +1028,10 @@ public class MeituanServiceImpl implements IMeituanService { return url; } - private CloseableHttpClient proxyHttpClient() { -// private CloseableHttpClient proxyHttpClient(String ipPort) { - String proxyHost = proxyProperties.getProxyAddr(); - int proxyPort = proxyProperties.getProxyPort(); +// private CloseableHttpClient proxyHttpClient() { + private CloseableHttpClient proxyHttpClient(String ipPort) { + String proxyHost = ipPort.split(":")[0]; + int proxyPort = Integer.valueOf(ipPort.split(":")[1]); String username = proxyProperties.getAccount(); String password = proxyProperties.getPwd(); HttpHost proxy = new HttpHost(proxyHost, proxyPort); @@ -1076,5 +1081,22 @@ public class MeituanServiceImpl implements IMeituanService { // httpclient.close(); // } } - + private CloseableHttpClient proxyHttpClient() { + String proxyHost = proxyProperties.getProxyAddr(); + int proxyPort = proxyProperties.getProxyPort(); + String username = proxyProperties.getAccount(); + String password = proxyProperties.getPwd(); + HttpHost proxy = new HttpHost(proxyHost, proxyPort); + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), + new UsernamePasswordCredentials(username, password)); + RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); + CloseableHttpClient httpClient = HttpClients + .custom() + .setDefaultRequestConfig(config) + .setDefaultCredentialsProvider(credsProvider) + .build(); +// CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); + return httpClient; + } } diff --git a/ruoyi-system/src/main/resources/mapper/business/BusAgentInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/business/BusAgentInfoMapper.xml index 85068de..4540fac 100644 --- a/ruoyi-system/src/main/resources/mapper/business/BusAgentInfoMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/business/BusAgentInfoMapper.xml @@ -57,6 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select ai_duration_balance from bus_agent_info where agent_account = #{account} + and del_status = '1'