Commit badce8a8 authored by huangjiamin's avatar huangjiamin

购买失败处理以及注释

parent 2b52de95
......@@ -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<>();
......
......@@ -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);
}
......@@ -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