Commit f4a103c5 authored by Administrator's avatar Administrator

Merge branch 'feature-purchaseFailure' into 'master'

Feature purchase failure

See merge request !190
parents 9deeeb23 badce8a8
......@@ -30,7 +30,6 @@ public class Account {
*/
private String parent;
/**
* 子用户使用的密码
*/
......@@ -87,7 +86,10 @@ public class Account {
private int shopCount = 0;
private int authorized; // 0: 未认证; 1: 认证中; 2: 已认证;
/**
* 0: 未认证; 1: 认证中; 2: 已认证;
*/
private int authorized;
private List<String> queryIpUrlList = new ArrayList<>();
......
......@@ -74,6 +74,7 @@ public class AccountDto {
List<String> ownWhiteList = new ArrayList<>(account.getWhiteList());
ownWhiteList.add("google.com/recaptcha");
ownWhiteList.add("google.com/js");
ownWhiteList.add("cap.attempts.securecode.com");
this.setOwnWhiteList(ownWhiteList);
this.setQueryIpUrlList(account.getQueryIpUrlList());
if (account.getPromotion() != null) {
......
......@@ -7,7 +7,9 @@ public class IpChargeRequestDto {
private String unit = "month";
private String target;
//0 -- 充值, 1 -- newip, 2 --renew, 3 -- 退还
/**
* 0 -- 充值, 1 -- newip, 2 --renew, 3 -- 退还
*/
private int chargeType = 0;
/**
......@@ -16,7 +18,9 @@ public class IpChargeRequestDto {
private String chargeIp;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信
/**
* 0 -- 余额, 1 -- 支付宝, 2 -- 微信
*/
private int payMethod = 0;
private float daysPerMonth = 0;
......@@ -112,4 +116,21 @@ public class IpChargeRequestDto {
public void setChargeIp(String chargeIp) {
this.chargeIp = chargeIp;
}
@Override
public String toString() {
return "IpChargeRequestDto{" +
"period=" + period +
", amount=" + amount +
", region='" + region + '\'' +
", unit='" + unit + '\'' +
", target='" + target + '\'' +
", chargeType=" + chargeType +
", chargeIp='" + chargeIp + '\'' +
", payMethod=" + payMethod +
", daysPerMonth=" + daysPerMonth +
", tradeNo='" + tradeNo + '\'' +
", services='" + services + '\'' +
'}';
}
}
......@@ -168,6 +168,44 @@ public class IpResource implements Serializable {
return Objects.hash(getId());
}
@Override
public String toString() {
return "IpResource{" +
"id='" + id + '\'' +
", addr='" + addr + '\'' +
", ipType=" + ipType +
", vendor=" + vendor +
", vendorCn='" + vendorCn + '\'' +
", region='" + region + '\'' +
", regionCn='" + regionCn + '\'' +
", status=" + status +
", port=" + port +
", purchasedTime=" + purchasedTime +
", validTime=" + validTime +
", details='" + details + '\'' +
", bindHistory=" + bindHistory +
", isDeleted=" + isDeleted +
", username='" + username + '\'' +
", owner='" + owner + '\'' +
", userParent='" + userParent + '\'' +
", protocol=" + protocol +
", password='" + password + '\'' +
", price=" + price +
", specialLine=" + specialLine +
", usingSpecialLine=" + usingSpecialLine +
", proxyUsername='" + proxyUsername + '\'' +
", proxyPassword='" + proxyPassword + '\'' +
", shopId='" + shopId + '\'' +
", shopIds=" + shopIds +
", bind=" + bind +
", isLocked=" + isLocked +
", lockTimestamp=" + lockTimestamp +
", healthLockTimestamp=" + healthLockTimestamp +
", unit='" + unit + '\'' +
", period=" + period +
", secondaryProxyPort='" + secondaryProxyPort + '\'' +
'}';
}
}
......
......@@ -70,4 +70,14 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
IpResource findFirstByAddrOrderByPurchasedTimeDesc(String addr);
/**
* 查询出未分配成功的数据
*
* @param status 状态
* @param isDeleted 是否被删除
* @param isLocked 是否被锁定
* @return list
*/
List<IpResource> findByStatusInAndIsDeletedAndIsLocked(List<Integer> status, boolean isDeleted, boolean isLocked);
}
......@@ -670,7 +670,7 @@ public class IpResourceServiceImpl implements IpResourceService {
// 1. 如果 ip 资源的 addr 非空
if (StringUtils.isNotBlank(x.getAddr())) {
// 1.1 锁定时间在 2分钟内 且 IpType 为 VENDOR 且 (IP资源状态 为 0:正常 或 2:即将过期)
if (x.getLockTimestamp() >= Instant.now().minusSeconds(2 * 60).toEpochMilli() && x.getIpType() == IpType.VENDOR && (x.getStatus() == 0 || x.getStatus() == 2)) {
if (x.getLockTimestamp() >= Instant.now().minusSeconds(1 * 60).toEpochMilli() && x.getIpType() == IpType.VENDOR && (x.getStatus() == 0 || x.getStatus() == 2)) {
x.setStatus(3);
// 1.2 ip资源在未来七天内到期,且 ip 资源的状态不是 3(正在分配)、5(已失效)、6(未分配),则将 ip 资源设置为 2(即将过期)
......@@ -713,10 +713,6 @@ public class IpResourceServiceImpl implements IpResourceService {
x.setStatus(3);
}
if(x.isSpecialLine() && x.getStatus() == 0 && x.getPurchasedTime() > (Instant.now().minusSeconds(14 * 60).toEpochMilli())) {
x.setSpecialLine(false);
}
// 3. 如果 ip 资源的 status 为 3(正在分配)
if (x.getStatus() == 3) {
x.setAddr("");
......
......@@ -394,10 +394,16 @@ public class ShopServiceImpl implements ShopService {
ipResourceDto = new IpResourceDto(ipResource, null, false);
}
if(org.apache.commons.lang3.StringUtils.isNotBlank(ipResource.getRegion()) && region.contains(ipResource.getRegion())){
//海外设置KCP端口
if (org.apache.commons.lang3.StringUtils.isNotBlank(ipResource.getRegion()) && region.contains(ipResource.getRegion())) {
ipResourceDto.setSecondaryProxyPort("20020");
}
//刚购买14分钟内的专线设置为不可用
if (ipResource.getStatus() == 0 && ipResource.getPurchasedTime() > (Instant.now().minusSeconds(14 * 60).toEpochMilli())) {
ipResource.setSpecialLine(false);
}
// 3. 封装 ShopResultDto 信息并返回
return ShopResultDto.of(shop, userShop.getGroupId(), ipResourceDto);
}
......
......@@ -2,6 +2,8 @@ package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import java.util.List;
public interface IpAndShopService {
void bindShop(String username, ShopRequestDto shopRequestDto);
......@@ -9,4 +11,6 @@ public interface IpAndShopService {
void unBindShop(String username, ShopRequestDto shopRequestDto);
void unBindShops(String username, ShopRequestDto shopRequestDto);
//void unBindShops(String username, String id, List<String> shopIds);
}
......@@ -199,6 +199,40 @@ public class BrowserTask {
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).join();
}
private static int OVER40MIN = 40 * 60 * 1000;
/**
* 购买失败处理
* 购买后,长时间未能成功的ip资源视为购买失败。
* 每半个小时进行一次,将状态为3、购买时长超过40分钟的ip资源释放,
* 并将购买花销退回账户余额
*/
@Scheduled(cron = "0 0/1 * * * ?")
public void purchaseFailureHandling() {
long now = Instant.now().minusSeconds(300).toEpochMilli();
//List<IpResource> ipResources = ipResourceRepository.findByStatusInAndIsDeletedAndIsLocked(Arrays.asList(3, 6));
List<IpResource> ipResources = ipResourceRepository.findByStatusInAndIsDeletedAndIsLocked(Arrays.asList(3, 6), false, false);
ipResources.forEach(ipResource -> {
if (ipResourceRepository.lockTask(ipResource)) {
if((now - ipResource.getPurchasedTime()) > OVER40MIN){
String username = ipResource.getUsername();
String id = ipResource.getId();
List<String> shopIds = ipResource.getShopIds();
log.error("Ip resource purchase failure, {}", ipResource);
log.error("charge by money, {}, {}, {}", username, -ipResource.getPrice(), buildIpChargeRequestDto(ipResource, 3, 0));
//accountService.chargeByMoney(username, -ipResource.getPrice(), buildIpChargeRequestDto(ipResource, 3, 0));
if (shopIds != null && shopIds.size() > 0) {
log.error("unbind Shops, {}, {}, {}", username, id, shopIds);
//ipAndShopService.unBindShops(username, ipResource.getId(), shopIds);
}
log.error("delete ip resource, {}", id);
//ipResourceRepository.deleteById(id);
}
}
ipResourceRepository.unLockTask(ipResource.getId());
});
}
@Scheduled(cron = "0 0/1 * * * ?")
public void queryIpTasks() {
String URL = (profiles.equals("dev") || profiles.equals("staging")) ? TESTURL : CLOUDAMURL;
......
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