1; 丢单问题处理 多线程加 隧道
This commit is contained in:
parent
01bed91f03
commit
e7ae1f1ccc
|
@ -81,6 +81,7 @@ public class MeituanController {
|
|||
* 批量获取订单
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("批量获取订单")
|
||||
@GetMapping("/orderInfoList")
|
||||
public R orderInfoList() {
|
||||
String result = iMeituanService.orderInfoList();
|
||||
|
|
|
@ -71,6 +71,7 @@ spring:
|
|||
redis:
|
||||
# 地址
|
||||
host: 43.140.224.18
|
||||
# host: localhost
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
|
|
|
@ -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());
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -283,7 +283,6 @@ public class MeituanServiceImpl implements IMeituanService {
|
|||
busStoreInfo.setReturnVisitStatus("1");
|
||||
List<BusStoreInfo> busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo);
|
||||
long startTime = System.currentTimeMillis(); // 开始时间
|
||||
//boolean a=studentService.batchInsert(list);
|
||||
List<List<BusStoreInfo>> list1= SplitListUtils.pagingList(busStoreInfoList,4); //拆分集合
|
||||
CountDownLatch countDownLatch = new CountDownLatch(list1.size());
|
||||
for (List<BusStoreInfo> list2 : list1) {
|
||||
|
@ -385,21 +384,21 @@ 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 = null;
|
||||
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);
|
||||
// String key = wmPoiId + date;
|
||||
// String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null);
|
||||
while (array != null && array.size() > 0) {
|
||||
if (flag) {
|
||||
break;
|
||||
}
|
||||
// if (flag) {
|
||||
// break;
|
||||
// }
|
||||
List<BusOrderInfo> list = new ArrayList<>();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
BusOrderInfo orderInfo = new BusOrderInfo();
|
||||
|
@ -444,18 +443,18 @@ public class MeituanServiceImpl implements IMeituanService {
|
|||
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
|
@ -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());
|
||||
|
||||
priPhoneInfo(newList,cookie,getUrl);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
||||
pageNum += 1;
|
||||
|
@ -532,10 +533,14 @@ public class MeituanServiceImpl implements IMeituanService {
|
|||
busStoreInfoMapper.updateBusStoreInfo(storeInfo1);
|
||||
}
|
||||
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){
|
||||
CloseableHttpClient httpClient = proxyHttpClient();
|
||||
CloseableHttpClient httpClient = proxyHttpClient(getUrl);
|
||||
String url = "https://e.waimai.meituan.com/gw/phf/v2/order/receive/processed/r/orderAsyncInfos/v3";
|
||||
Map<String, Object> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
</select>
|
||||
|
||||
<insert id="insertBusAgentInfo" parameterType="BusAgentInfo">
|
||||
|
|
Loading…
Reference in New Issue