1; 丢单问题处理 多线程加 隧道

This commit is contained in:
wangshuai 2024-07-30 11:37:46 +08:00
parent 01bed91f03
commit e7ae1f1ccc
6 changed files with 172 additions and 147 deletions

View File

@ -81,6 +81,7 @@ public class MeituanController {
* 批量获取订单 * 批量获取订单
* @return * @return
*/ */
@ApiOperation("批量获取订单")
@GetMapping("/orderInfoList") @GetMapping("/orderInfoList")
public R orderInfoList() { public R orderInfoList() {
String result = iMeituanService.orderInfoList(); String result = iMeituanService.orderInfoList();

View File

@ -71,6 +71,7 @@ spring:
redis: redis:
# 地址 # 地址
host: 43.140.224.18 host: 43.140.224.18
# host: localhost
# 端口默认为6379 # 端口默认为6379
port: 6379 port: 6379
# 数据库索引 # 数据库索引

View File

@ -182,7 +182,7 @@ public class ProxyProperties {
* 隧道 ip获取 * 隧道 ip获取
* @return * @return
*/ */
public String gettps(){ public String gettpsUrl(){
CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpClient httpclient = HttpClients.createDefault();
try { try {
String params = "?secret_id=" + secretId + "&num=1&signature=" + secretKey; String params = "?secret_id=" + secretId + "&num=1&signature=" + secretKey;
@ -209,9 +209,9 @@ public class ProxyProperties {
} }
return null; return null;
} }
//
public static void main(String[] args) { // public static void main(String[] args) {
ProxyProperties proxyProperties = new ProxyProperties(); // ProxyProperties proxyProperties = new ProxyProperties();
System.out.println(proxyProperties.gettps()); // System.out.println(proxyProperties.gettpsUrl());
} // }
} }

View File

@ -31,8 +31,8 @@ public class AsyncTaskImpl {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
//异步线程要做的事情 //异步线程要做的事情
for (BusStoreInfo store : busStoreInfoList) { for (BusStoreInfo store : busStoreInfoList) {
// R flag = iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie()); R flag = iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie());
R flag = R.fail(); // R flag = R.fail();
if (flag.getCode() != 200) { if (flag.getCode() != 200) {
System.out.println(store.getStoreName()+"获取订单信息返回错误..."+store.getStoreCode()); System.out.println(store.getStoreName()+"获取订单信息返回错误..."+store.getStoreCode());
} }

View File

@ -283,7 +283,6 @@ public class MeituanServiceImpl implements IMeituanService {
busStoreInfo.setReturnVisitStatus("1"); busStoreInfo.setReturnVisitStatus("1");
List<BusStoreInfo> busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo); List<BusStoreInfo> busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo);
long startTime = System.currentTimeMillis(); // 开始时间 long startTime = System.currentTimeMillis(); // 开始时间
//boolean a=studentService.batchInsert(list);
List<List<BusStoreInfo>> list1= SplitListUtils.pagingList(busStoreInfoList,4); //拆分集合 List<List<BusStoreInfo>> list1= SplitListUtils.pagingList(busStoreInfoList,4); //拆分集合
CountDownLatch countDownLatch = new CountDownLatch(list1.size()); CountDownLatch countDownLatch = new CountDownLatch(list1.size());
for (List<BusStoreInfo> list2 : list1) { for (List<BusStoreInfo> list2 : list1) {
@ -385,21 +384,21 @@ public class MeituanServiceImpl implements IMeituanService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public R orderInfo(String wmPoiId, String date, String cookie) { //根据date,查询前一天的key,如果有则删除 public R orderInfo(String wmPoiId, String date, String cookie) { //根据date,查询前一天的key,如果有则删除
try {
int pageNum = 1; int pageNum = 1;
String getUrl = null; String getUrl = proxyProperties.gettpsUrl();
JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie); JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie);
String code = jsonObject.getString("code"); String code = jsonObject.getString("code");
if ("0".equals(code)) { if ("0".equals(code)) {
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList"); JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList");
boolean flag = false; boolean flag = false;
String key = wmPoiId + date; // String key = wmPoiId + date;
String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); // String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null);
while (array != null && array.size() > 0) { while (array != null && array.size() > 0) {
if (flag) { // if (flag) {
break; // break;
} // }
List<BusOrderInfo> list = new ArrayList<>(); List<BusOrderInfo> list = new ArrayList<>();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
BusOrderInfo orderInfo = new BusOrderInfo(); BusOrderInfo orderInfo = new BusOrderInfo();
@ -444,18 +443,18 @@ public class MeituanServiceImpl implements IMeituanService {
} }
String redisDaySeq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null); // String redisDaySeq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null);
if (redisDaySeq == null) { // if (redisDaySeq == null) {
redisTemplate.opsForValue().set(key, daySeq); // redisTemplate.opsForValue().set(key, daySeq);
} else { // } else {
if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) { // if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) {
redisTemplate.opsForValue().set(key, daySeq); // redisTemplate.opsForValue().set(key, daySeq);
} // }
if (daySeq.equals(lastDayseq)) { // if (daySeq.equals(lastDayseq)) {
flag = true; // flag = true;
break; // break;
} // }
} // }
orderInfo.setStoreCode(wmPoiId); orderInfo.setStoreCode(wmPoiId);
orderInfo.setDayseq(daySeq); orderInfo.setDayseq(daySeq);
orderInfo.setOrderNo(wmOrderViewId); orderInfo.setOrderNo(wmOrderViewId);
@ -505,6 +504,8 @@ public class MeituanServiceImpl implements IMeituanService {
List<BusOrderInfo> newList = list.stream().collect(Collectors.toMap(BusOrderInfo::getOrderNo, p->p,(p1, p2)->p1)).values().stream().collect(Collectors.toList()); List<BusOrderInfo> newList = list.stream().collect(Collectors.toMap(BusOrderInfo::getOrderNo, p->p,(p1, p2)->p1)).values().stream().collect(Collectors.toList());
priPhoneInfo(newList,cookie,getUrl); priPhoneInfo(newList,cookie,getUrl);
}else{
break;
} }
pageNum += 1; pageNum += 1;
@ -532,10 +533,14 @@ public class MeituanServiceImpl implements IMeituanService {
busStoreInfoMapper.updateBusStoreInfo(storeInfo1); busStoreInfoMapper.updateBusStoreInfo(storeInfo1);
} }
return R.fail(jsonObject.getString("msg")); return R.fail(jsonObject.getString("msg"));
}catch (Exception e){
e.printStackTrace();
return orderInfo(wmPoiId, date, cookie);
}
} }
private String getOrderCountByType(String getUrl, String wmOrderViewId,String cookie){ 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"; String url = "https://e.waimai.meituan.com/gw/phf/v2/order/receive/processed/r/orderAsyncInfos/v3";
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("region_id", valueFromCookie("region_id",cookie)); 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("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"); 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(); // CloseableHttpClient client = HttpClientBuilder.create().build();
HttpEntity responseEntity; HttpEntity responseEntity;
String resp = null; String resp = null;
@ -715,7 +720,7 @@ public class MeituanServiceImpl implements IMeituanService {
httpPost.setEntity(entity); httpPost.setEntity(entity);
httpPost.setHeader("Cookie", cookie); httpPost.setHeader("Cookie", cookie);
CloseableHttpClient client = proxyHttpClient(); CloseableHttpClient client = proxyHttpClient(getUrl);
String code = null; String code = null;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
@ -1023,10 +1028,10 @@ public class MeituanServiceImpl implements IMeituanService {
return url; return url;
} }
private CloseableHttpClient proxyHttpClient() { // private CloseableHttpClient proxyHttpClient() {
// private CloseableHttpClient proxyHttpClient(String ipPort) { private CloseableHttpClient proxyHttpClient(String ipPort) {
String proxyHost = proxyProperties.getProxyAddr(); String proxyHost = ipPort.split(":")[0];
int proxyPort = proxyProperties.getProxyPort(); int proxyPort = Integer.valueOf(ipPort.split(":")[1]);
String username = proxyProperties.getAccount(); String username = proxyProperties.getAccount();
String password = proxyProperties.getPwd(); String password = proxyProperties.getPwd();
HttpHost proxy = new HttpHost(proxyHost, proxyPort); HttpHost proxy = new HttpHost(proxyHost, proxyPort);
@ -1076,5 +1081,22 @@ public class MeituanServiceImpl implements IMeituanService {
// httpclient.close(); // 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;
}
} }

View File

@ -57,6 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select ai_duration_balance select ai_duration_balance
from bus_agent_info from bus_agent_info
where agent_account = #{account} where agent_account = #{account}
and del_status = '1'
</select> </select>
<insert id="insertBusAgentInfo" parameterType="BusAgentInfo"> <insert id="insertBusAgentInfo" parameterType="BusAgentInfo">