Commit 55925537 authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

子账户续费

See merge request !80
parents 85087095 eee0fbd5
......@@ -367,8 +367,8 @@ public class PaymentServiceImpl implements PaymentService {
Account byName = accountService.findByName(username);
if (byName == null )
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST, "account does not exist: " + username);
if (byName.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
// if (byName.getPermission() < 8)
// throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
boolean isVpsClient = true;
UserPayment internalOrder = new UserPayment();
......@@ -421,8 +421,8 @@ public class PaymentServiceImpl implements PaymentService {
Account byName = accountService.findByName(username);
if (byName == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST, "account does not exist: " + username);
if (byName.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
// if (byName.getPermission() < 8)
// throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
boolean isVpsClient = true;
......
......@@ -11,4 +11,6 @@ public interface IpResourceRepositoryCustom {
boolean unLockTask(String id);
List<IpResource> sampleTasks(int status, long timestamp);
List<IpResource> sampleTasks(List<Integer> status);
}
......@@ -65,7 +65,22 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
public List<IpResource> sampleTasks(int status, long timestamp) {
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").is(status).and("isLocked").is(false).and("isDeleted").is(false),
where("isLocked").is(true).and("lockTimestamp").lte(timestamp)).and("isDeleted").is(false);
where("status").is(status).and("isLocked").is(true).and("lockTimestamp").lte(timestamp)).and("isDeleted").is(false);
MatchOperation match = Aggregation.match(matchCriteria);
SampleOperation sample = Aggregation.sample(20);
AggregationResults<IpResource> results = mongoTemplate.aggregate(Aggregation.newAggregation(match, sample), IpResource.class, IpResource.class);
List<IpResource> mappedResults = results.getMappedResults();
return mappedResults;
}
@Override
public List<IpResource> sampleTasks(List<Integer> status) {
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("isDeleted").is(false).and("lockTimestamp").lte(Instant.now().toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("lockTimestamp").lte((Instant.now().toEpochMilli()) - 60*1000*30)).and("isDeleted").is(false);
MatchOperation match = Aggregation.match(matchCriteria);
......
......@@ -2,6 +2,8 @@ package com.edgec.browserbackend.browser.task;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.IpChargeRequestDto;
import com.edgec.browserbackend.account.domain.QueryIpUrlList;
import com.edgec.browserbackend.account.repository.QueryIpUrlListRepository;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.IpBuyResultDto;
......@@ -11,6 +13,7 @@ import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.common.commons.utils.NotifyUtils;
import com.edgec.browserbackend.common.utils.ThreadPoolUtils;
import com.edgec.browserbackend.common.utils.Trans;
import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -26,6 +29,7 @@ import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -54,6 +58,9 @@ public class BrowserTask {
@Autowired
private IpAndShopService ipAndShopService;
@Autowired
private QueryIpUrlListRepository queryIpUrlListRepository;
@Value("${spring.profiles.active}")
private String profiles;
......@@ -212,6 +219,39 @@ public class BrowserTask {
}
}
// @Scheduled(cron = "0 0/1 * * * ?")
public void healthCheck() {
String URL = (profiles.equals("dev") || profiles.equals("staging")) ? TESTURL : CLOUDAMURL;
List<IpResource> ipResources = ipResourceRepository.sampleTasks(Arrays.asList(0, 2));
for (IpResource ipResource : ipResources) {
long start = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
if (ipResourceRepository.lockTask(ipResource)) {
try {
QueryIpUrlList queryIpUrlList = queryIpUrlListRepository.findAll().get(0);
Trans trans;
if (ipResource.isSpecialLine()) {
trans = new Trans();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
long end = System.currentTimeMillis();
log.debug("queryIpTask {} execution time is: " + (end - start) / 1000 + "s", ipResource.getId());
try {
ipResourceRepository.unLockTask(ipResource.getId());
} catch (Throwable th) {
log.error("unlock failed", th);
//try again
ipResourceRepository.unLockTask(ipResource.getId());
}
}
}
}, ThreadPoolUtils.queryIpTasksPool);
}
}
public static class HttpClientutils {
static OkHttpClient.Builder builder = new OkHttpClient.Builder();
......
package com.edgec.browserbackend.common.utils;
import com.edgec.browserbackend.common.commons.utils.NotifyUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
......@@ -33,6 +34,10 @@ public class Trans {
this.username = username;
}
public Trans() {
}
/**
* 主入口方法
* @param args
......@@ -41,7 +46,6 @@ public class Trans {
String url = "http://pv.sohu.com/cityjson";
Trans trans = new Trans("120.76.135.212", 20001, "fangguanlianbrowser", "2rbvtg9GQ1JraA1");
String result = trans.get(url, false);
System.out.println(result);
}
public HttpClient getHttpClient() {
......@@ -82,10 +86,10 @@ public class Trans {
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e);
} catch (IOException e) {
// TODO Auto-generated catch block
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e);
}
System.out.println(sb.toString());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment