Commit 30c62028 authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !153
parents 25d269e9 3f484a2b
......@@ -103,12 +103,12 @@
<artifactId>alipay-sdk-java</artifactId>
<version>3.7.110.ALL</version>
</dependency>
<dependency>
<!--<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>1.50.3</version>
<scope>test</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
......
......@@ -5,18 +5,12 @@ import com.edgec.browserbackend.account.domain.AccountDto;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.dto.SubUsersRequestDto;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
......@@ -28,6 +22,7 @@ public class AdminController {
@Autowired
AccountService accountService;
@RequestMapping(path = "/subuser/addone", method = RequestMethod.POST)
public ResultDto createSubAccount(Principal principal, @Valid @RequestBody AccountDto user) {
ResultDto resultDto = new ResultDto();
......@@ -68,7 +63,7 @@ public class AdminController {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
Account account1 =accountService.saveSub(principal.getName(), user);
Account account1 = accountService.saveSub(principal.getName(), user);
resultDto.setStatus(0);
resultDto.setData(account1);
} catch (ClientRequestException e) {
......@@ -105,7 +100,7 @@ public class AdminController {
LimitedUsers.filterIfLimitedUser(principal);
accountService.deleteSub(principal.getName(), child);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
......@@ -123,7 +118,7 @@ public class AdminController {
LimitedUsers.filterIfLimitedUser(principal);
resultDto.setData(accountService.getSubUserList(principal.getName(), shopRequestDto.getPage(), shopRequestDto.getAmount()));
resultDto.setStatus(0);
}catch (ClientRequestException e) {
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
......
......@@ -70,6 +70,7 @@ public class PaymentServiceImpl implements PaymentService {
// 当微信回调该接口时,说明微信那边已经充值成功,这个时候需要更新系统中 userpayment 充值状态
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradno);
if (byTradeNo != null && !byTradeNo.isSucceed()) {
log.info("微信支付回调确认订单" + byTradeNo.getTradeNo() + "支付状态,此时chargeType为 0");
wxCheckOrderStatus(byTradeNo.getTradeNo(), 0);
}
return "<xml>\n" +
......@@ -83,6 +84,7 @@ public class PaymentServiceImpl implements PaymentService {
public void alipaCallback(String tradno) {
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradno);
if (byTradeNo != null && !byTradeNo.isSucceed()) {
log.info("支付宝支付回调确认订单" + byTradeNo.getTradeNo() + "支付状态,此时chargeType为 0");
aliCheckOrderStatus(byTradeNo.getTradeNo(), 0);
}
}
......@@ -791,6 +793,7 @@ public class PaymentServiceImpl implements PaymentService {
// 2.1 更新 userPayment 的支付状态为成功
boolean b = userPaymentRepository.updatePaymentResult(byTradeNo, true);
if (b) {
log.info("订单 " + byTradeNo.getTradeNo() + " 的支付状态更新为成功");
// 2.2 获取充值优惠赠送
PayBack payBack = payBackRepository.findByPay(byTradeNo.getAmount());
if (payBack == null) {
......@@ -802,11 +805,13 @@ public class PaymentServiceImpl implements PaymentService {
// 2.3 构建用户充值信息并保存
UserPrePaidBilling bill = getUserPrePaidBilling(byTradeNo, byName, balance, payBack);
userPrePaidBillingRepository.save(bill);
log.info("构建订单 " + byTradeNo.getTradeNo() + " 的充值信息成功");
}
// 2.4 更新账户余额 userBalance
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + payBack.getBack());
userBalanceRepository.save(balance);
log.info("更新充值订单 " + byTradeNo.getTradeNo() + " 所对应的账户 " + balance.getUsername() + " 的余额成功");
// 2.5 如果当前用户通过邀请码注册的,则更新邀请人的佣金
if (byName.getPromotionCode() != null) {
......@@ -814,6 +819,7 @@ public class PaymentServiceImpl implements PaymentService {
if (account != null) {
account.getPromotion().setCommission(account.getPromotion().getCommission() + byTradeNo.getAmount());
accountRepository.save(account);
log.info("更新邀请人的佣金成功");
}
}
}
......
......@@ -107,13 +107,14 @@ public class UserServiceImpl implements UserService {
}
);
String hash = encoder.encode(user.getPassword());
user.setPassword(hash);
String password = user.getPassword();
String hash = encoder.encode(password);
user.setPassword(hash);
repository.save(user);
// 保存明文密码
userCodeRepository.save(new UserCode(user.getUsername(), user.getPassword()));
userCodeRepository.save(new UserCode(user.getUsername(), password));
log.info("new user has been created: {}", user.getUsername());
}
......
......@@ -18,8 +18,12 @@ public class TempController {
@Autowired
private TempService tempService;
/**
* 记住用户明文密码
*/
@PostMapping(value = "/usercode")
public void addUserCode(@RequestBody UserCode userCode) {
tempService.save(userCode);
}
}
......@@ -21,42 +21,129 @@ public class IpResource implements Serializable {
@Id
private String id;
/**
* ip 地址
*/
private String addr;
/**
* ip 类型,默认是 ip代理 模式
*/
private IpType ipType = IpType.VENDOR;
/**
* ip 的具体代理使用
*/
private Vendor vendor;
private String vendorCn;
/**
* ip 地域
*/
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
/**
* ip 的状态
* 0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
*/
private int status;
/**
* ip 端口号
*/
private List<String> port;
/**
* ip的购买时间点
*/
private long purchasedTime;
/**
* ip的过期的时间点
*/
private long validTime;
private String details;
/**
* ip的绑定历史
*/
private List<BindHistory> bindHistory = new ArrayList<>();
/**
* ip的状态
* 当 ip 资源过期的时候,系统不会直接删除 ip 资源,而是将 isDeleted 设置为 true
* 过期7天后再删除这个ip资源
*/
private boolean isDeleted;
/**
* 如果 使用的 ip 资源 是在我们系统申请的,则默认为 fangguanlianbrowser
*/
private String username;
/**
* ip 资源的购买者(拥有者)
*/
private String owner;
private String userParent;
/**
* ip访问协议
*/
private List<String> protocol;
private String password;
private double price;
private boolean specialLine; //是否使用专线
private boolean usingSpecialLine; //是否正在使用专线
//专线数据
private String proxyUsername; //专线的代理用户名
private String proxyPassword; //专线的代理密码
/**
* 是否使用专线
*/
private boolean specialLine;
/**
* 是否正在使用专线
*/
private boolean usingSpecialLine;
/**
* 专线的代理用户名
*/
private String proxyUsername;
/**
* 专线的代理密码
*/
private String proxyPassword;
/**
* ip 资源绑定的 商铺号
*/
private String shopId;
private List<String> shopIds = new ArrayList<>();
/**
* 绑定状态
*/
private boolean bind;
private boolean isLocked;
private long lockTimestamp;
private long healthLockTimestamp;
/**
* 购买方式(按月、按周)
*/
private String unit;
/**
* 购买数量
* 例如 购买了 2 个月 的 ip资源,则
* period:2
* unit:month
*/
private int period;
@Override
......
......@@ -4,11 +4,15 @@ import com.edgec.browserbackend.browser.domain.BindHistory;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.domain.Vendor;
import org.springframework.data.annotation.Id;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class IpResourceUnwindResultDto {
private String id;
private String addr;
......@@ -39,6 +43,13 @@ public class IpResourceUnwindResultDto {
private String proxyPassword; //专线的代理密码
private String shopId;
/**
* 对应 IpResource 中 shopIds 的展开字段
*/
private String shopIds;
private boolean bind;
private boolean isLocked;
......@@ -49,299 +60,83 @@ public class IpResourceUnwindResultDto {
private int period;
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getRegionCn() {
return regionCn;
}
public void setRegionCn(String regionCn) {
this.regionCn = regionCn;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public IpType getIpType() {
return ipType;
}
public void setIpType(IpType ipType) {
this.ipType = ipType;
}
public List<BindHistory> getBindHistory() {
return bindHistory;
}
public void setBindHistory(List<BindHistory> bindHistory) {
this.bindHistory = bindHistory;
}
public long getPurchasedTime() {
return purchasedTime;
}
public void setPurchasedTime(long purchasedTime) {
this.purchasedTime = purchasedTime;
}
public long getValidTime() {
return validTime;
}
public void setValidTime(long validTime) {
this.validTime = validTime;
}
public Vendor getVendor() {
return vendor;
}
public void setVendor(Vendor vendor) {
this.vendor = vendor;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public List<String> getPort() {
return port;
}
public void setPort(List<String> port) {
this.port = port;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getUserParent() {
return userParent;
}
public void setUserParent(String userParent) {
this.userParent = userParent;
}
public List<String> getProtocol() {
return protocol;
}
public void setProtocol(List<String> protocol) {
this.protocol = protocol;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public boolean isLocked() {
return isLocked;
}
public void setLocked(boolean locked) {
isLocked = locked;
}
public long getLockTimestamp() {
return lockTimestamp;
}
public void setLockTimestamp(long lockTimestamp) {
this.lockTimestamp = lockTimestamp;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public int getPeriod() {
return period;
}
public void setPeriod(int period) {
this.period = period;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getVendorCn() {
return vendorCn;
}
public IpResource toResource() {
IpResource ipResource = new IpResource();
ipResource.setId(getId());
public void setVendorCn(String vendorCn) {
this.vendorCn = vendorCn;
if (!StringUtils.isEmpty(getShopIds())) {
ipResource.setShopId(getShopIds());
ipResource.getShopIds().add(getShopIds());
}
public String getProxyPassword() {
return proxyPassword;
ipResource.setHealthLockTimestamp(getHealthLockTimestamp());
ipResource.setUsingSpecialLine(isUsingSpecialLine());
ipResource.setPeriod(getPeriod());
ipResource.setSpecialLine(isSpecialLine());
if (addr != null) {
ipResource.setAddr(getAddr());
}
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
ipResource.setStatus(getStatus());
if (proxyPassword != null) {
ipResource.setProxyPassword(getProxyPassword());
}
public String getProxyUsername() {
return proxyUsername;
if (proxyUsername != null) {
ipResource.setProxyUsername(getProxyUsername());
}
public void setProxyUsername(String proxyUsername) {
this.proxyUsername = proxyUsername;
ipResource.setLockTimestamp(getLockTimestamp());
if (username != null) {
ipResource.setUsername(getUsername());
}
public boolean isSpecialLine() {
return specialLine;
if (regionCn != null) {
ipResource.setRegionCn(getRegionCn());
}
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
if (vendorCn != null) {
ipResource.setVendorCn(getVendorCn());
}
public long getHealthLockTimestamp() {
return healthLockTimestamp;
if (password != null) {
ipResource.setPassword(getPassword());
}
public void setHealthLockTimestamp(long healthLockTimestamp) {
this.healthLockTimestamp = healthLockTimestamp;
if (unit != null) {
ipResource.setUnit(getUnit());
}
public boolean isUsingSpecialLine() {
return usingSpecialLine;
ipResource.setLocked(isLocked());
ipResource.setValidTime(getValidTime());
if (bindHistory != null) {
ipResource.setBindHistory(getBindHistory());
}
public void setUsingSpecialLine(boolean usingSpecialLine) {
this.usingSpecialLine = usingSpecialLine;
ipResource.setDeleted(isDeleted());
if (owner != null) {
ipResource.setOwner(getOwner());
}
public boolean isBind() {
return bind;
if (protocol != null) {
ipResource.setProtocol(getProtocol());
}
public void setBind(boolean bind) {
this.bind = bind;
if (userParent != null) {
ipResource.setUserParent(getUserParent());
}
public IpResource toResource() {
IpResource ipResource = new IpResource();
ipResource.setId(getId());
if (shopId != null)
ipResource.getShopIds().add(getShopId());
ipResource.setHealthLockTimestamp(getHealthLockTimestamp());
ipResource.setUsingSpecialLine(isUsingSpecialLine());
ipResource.setPeriod(getPeriod());
ipResource.setSpecialLine(isSpecialLine());
if (addr != null)
ipResource.setAddr(getAddr());
ipResource.setStatus(getStatus());
if (proxyPassword != null)
ipResource.setProxyPassword(getProxyPassword());
if (proxyUsername != null)
ipResource.setProxyUsername(getProxyUsername());
ipResource.setLockTimestamp(getLockTimestamp());
if (username != null)
ipResource.setUsername(getUsername());
if (regionCn != null)
ipResource.setRegionCn(getRegionCn());
if (vendorCn != null)
ipResource.setVendorCn(getVendorCn());
if (password != null)
ipResource.setPassword(getPassword());
if (unit != null)
ipResource.setUnit(getUnit());
ipResource.setLocked(isLocked());
ipResource.setValidTime(getValidTime());
if (bindHistory != null)
ipResource.setBindHistory(getBindHistory());
ipResource.setDeleted(isDeleted());
if (owner != null)
ipResource.setOwner(getOwner());
if (protocol != null)
ipResource.setProtocol(getProtocol());
if (userParent != null)
ipResource.setUserParent(getUserParent());
ipResource.setPurchasedTime(getPurchasedTime());
ipResource.setIpType(getIpType());
if (port != null)
if (port != null) {
ipResource.setPort(getPort());
}
ipResource.setPrice(getPrice());
if (details != null)
if (details != null) {
ipResource.setDetails(getDetails());
}
return ipResource;
}
}
......@@ -66,8 +66,10 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
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("status").is(status).and("isLocked").is(true).and("lockTimestamp").lte(timestamp).and("isDeleted").is(false));
matchCriteria.orOperator(
where("status").is(status).and("isLocked").is(false).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);
......@@ -81,8 +83,10 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
public List<IpResource> sampleTasks(List<Integer> status) {
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("validTime").gt(Instant.now().toEpochMilli()).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60 * 30).toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("healthLockTimestamp").lte(Instant.now().minusSeconds(600).toEpochMilli()).and("isDeleted").is(false));
matchCriteria.orOperator(
where("status").in(status).and("isLocked").is(false).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60 * 30).toEpochMilli()).and("validTime").gt(Instant.now().toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60 * 10).toEpochMilli())
);
MatchOperation match = Aggregation.match(matchCriteria);
......@@ -157,79 +161,52 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
public List<IpResource> findShopIdInList(List<String> shopIds, boolean isDeleted) {
MatchOperation matchOperation = Aggregation.match(where("isDeleted").is(isDeleted));
UnwindOperation unwind = Aggregation.unwind("shopIds");
MatchOperation matchshopId = Aggregation.match(where("shopIds").in(shopIds));
List<IpResourceUnwindResultDto> ipResourceUnwindResultDtos = mongoTemplate.aggregate(
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class
).getMappedResults();
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(
x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
} else {
ipResourceHashMap.put(x.getId(), x.toResource());
}
}
);
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
}
return result;
return getResult(matchOperation, shopIds);
}
@Override
public List<IpResource> findShopIdInListAndStatus(List<String> shopIds, boolean isDeleted, int status) {
MatchOperation matchOperation = Aggregation.match(where("isDeleted").is(isDeleted).and("status").is(status));
UnwindOperation unwind = Aggregation.unwind("shopIds");
MatchOperation matchshopId = Aggregation.match(where("shopIds").in(shopIds));
List<IpResourceUnwindResultDto> ipResourceUnwindResultDtos = mongoTemplate.aggregate(
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class).getMappedResults();
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
} else {
ipResourceHashMap.put(x.getId(), x.toResource());
}
});
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
}
return result;
return getResult(matchOperation, shopIds);
}
@Override
public List<IpResource> findShopIdInListAndRegionLike(List<String> shopIds, boolean isDeleted, String region) {
MatchOperation matchOperation = Aggregation.match(where("isDeleted").is(isDeleted).and("regionCn").regex(".*?\\" + region + ".*"));
return getResult(matchOperation, shopIds);
}
@Override
public List<IpResource> findIds() {
BasicQuery basicQuery = new BasicQuery(new Document());
basicQuery.fields().include("id");
return mongoTemplate.find(basicQuery, IpResource.class);
}
private List<IpResource> getResult(MatchOperation matchOperation, List<String> shopIds) {
UnwindOperation unwind = Aggregation.unwind("shopIds");
MatchOperation matchshopId = Aggregation.match(where("shopIds").in(shopIds));
List<IpResourceUnwindResultDto> ipResourceUnwindResultDtos = mongoTemplate.aggregate(
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class).getMappedResults();
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class
).getMappedResults();
List<IpResource> result = new ArrayList<>();
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
return result;
}
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
ipResourceUnwindResultDtos.forEach(
x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopIds());
} else {
ipResourceHashMap.put(x.getId(), x.toResource());
}
});
List<IpResource> result = new ArrayList<>();
}
);
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
......@@ -237,12 +214,5 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
return result;
}
@Override
public List<IpResource> findIds() {
BasicQuery basicQuery = new BasicQuery(new Document());
basicQuery.fields().include("id");
return mongoTemplate.find(basicQuery, IpResource.class);
}
}
......@@ -407,15 +407,14 @@ public class ShopServiceImpl implements ShopService {
List<String> shopIds = null;
if (shopFilterDto.getBindIp() == 0) {
shopIds = allIds;
// 这个地方有点奇怪,为啥不去 userShop 中找,而是在 ipresource 中找? 可以查看下删除绑定状态的逻辑
} else if (shopFilterDto.getBindIp() == 1) {
// ip资源已经分配了 的店铺
}
// 绑定了 ip 资源的店铺
if (shopFilterDto.getBindIp() == 1) {
shopIds = ipResourceRepository.findShopIdInList(allIds, false).stream()
.flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList());
// 这个地方的其他情况是指什么情况
} else {
}
// 未绑定 ip 资源的店铺
if (shopFilterDto.getBindIp() == 2) {
// 店铺绑定的 ip 资源被删除的 店铺
for (String id : allIds) {
IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(id, true);
......@@ -425,6 +424,14 @@ public class ShopServiceImpl implements ShopService {
}
}
// 临时试用一下
if (shopFilterDto.getBindIp() == 3) {
List<String> shopIds2 = ipResourceRepository.findShopIdInList(allIds, false).stream()
.flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList());
allIds.removeAll(shopIds2);
shopIds = allIds;
}
amount = amount > 100 ? 100 : amount;
Pageable pageable = PageRequest.of(pageNum, amount);
// 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页
......
package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.UserCodeRepository;
import com.edgec.browserbackend.browser.service.TempService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
*/
@Slf4j
@Service
public class TempServiceImpl implements TempService {
@Autowired
private UserCodeRepository userCodeRepository;
@Autowired
private IpResourceRepository ipResourceRepository;
@Override
public void save(UserCode userCode) {
userCodeRepository.save(userCode);
}
@Override
public void saveIpResource(String addr, String flag) {
IpResource ipResource = ipResourceRepository.findByAddr(addr);
if ("true".equals(flag)) {
ipResource.setSpecialLine(true);
}
if ("false".equals(flag)) {
ipResource.setSpecialLine(false);
}
ipResourceRepository.save(ipResource);
log.info("ip地址为:" + addr + "专线状态更改为:" + flag);
}
}
......@@ -7,4 +7,6 @@ import com.edgec.browserbackend.browser.domain.UserCode;
*/
public interface TempService {
void save(UserCode userCode);
void saveIpResource(String addr, String flag);
}
......@@ -206,7 +206,6 @@ public class BrowserTask {
() -> {
if (ipResourceRepository.lockTask(ipResource)) {
try {
log.error("test");
String url = URL + "/ecc/ipinfo?accountId=browser&ip=" + ipResource.getAddr();
Map<String, String> header = buildGetHeader();
String rs = HttpClientutils.doGet(url, header);
......@@ -217,9 +216,6 @@ public class BrowserTask {
log.error("fail to pars json {}", rs, e);
}
if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
log.error(ipInfoResultDto.getErrorCode());
log.error(ipInfoResultDto.getStatus());
log.error(ipInfoResultDto.getEipIPAddr());
if (StringUtils.isNotEmpty(ipInfoResultDto.getStatus())) {
ipResourceRepository.updateStatus(ipResource.getId(), 0);
}
......@@ -247,25 +243,31 @@ public class BrowserTask {
@Scheduled(cron = "0 0/5 * * * ?")
public void healthCheck() {
// 1. 随机获取未被删除的 20 个 ip 做健康检查
List<IpResource> ipResources = ipResourceRepository.sampleTasks(Arrays.asList(0, 2));
for (IpResource ipResource : ipResources) {
long start = System.currentTimeMillis();
// todo ipResourceRepository.healthLock(ipResource) 始终为 true,感觉有些多余
if (ipResourceRepository.healthLock(ipResource)) {
try {
int failTime = 0;
// 获取查询 ip 地址的 5个网址
List<QueryIpUrlList> queryIpUrlLists = queryIpUrlListRepository.findAll();
final int maxRetry = Math.max(queryIpUrlLists.size(), 5);
// 如果 ip 已经失效,且 ip 的状态不是 3:正在分配 和 6:未分配,则将 ip 的状态设置为 1 已过期
if (ipResource.getValidTime() <= Instant.now().toEpochMilli() && ipResource.getStatus() != 3 && ipResource.getStatus() != 6) {
ipResource.setStatus(1);
ipResourceRepository.save(ipResource);
// 如果 ip 为专线 ip,或者 ip 为用户自己的,但是使用了系统的专线功能
} else if (ipResource.isSpecialLine() || (ipResource.getIpType() == IpType.OWN && ipResource.isUsingSpecialLine())) {
Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword());
String sp_result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
while (!sp_result.contains(ipResource.getAddr())) {
if (failTime > maxRetry) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常:" + ipResource.getIpType(),
NotifyUtils.MsgType.WEBHOOK);
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常:" + ipResource.getIpType(), NotifyUtils.MsgType.WEBHOOK);
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常 " + sp_result);
break;
}
......@@ -273,16 +275,15 @@ public class BrowserTask {
Thread.sleep(2000);
sp_result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
}
} else if (ipResource.getIpType() == IpType.VENDOR
|| (ipResource.getIpType() == IpType.OWN && !ipResource.isUsingSpecialLine())) {
String result;
// 如果 ip 类型为 vendor
} else if (ipResource.getIpType() == IpType.VENDOR) {
Trans trans = new Trans(ipResource.getAddr(), Integer.valueOf(ipResource.getPort().size() > 1 ? ipResource.getPort().get(1) : ipResource.getPort().get(0)), ipResource.getUsername(), ipResource.getPassword());
result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
String result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
if (!result.contains(ipResource.getAddr())) {
while (!result.contains(ipResource.getAddr())) {
if (failTime > maxRetry) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常:" + ipResource.getIpType(),
NotifyUtils.MsgType.WEBHOOK);
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常:" + ipResource.getIpType(), NotifyUtils.MsgType.WEBHOOK);
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常 " + result);
break;
}
......@@ -293,7 +294,8 @@ public class BrowserTask {
}
}
} catch (Exception e) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
// todo 将代理异常改为 健康检查异常
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 健康检查异常", e, NotifyUtils.MsgType.WEBHOOK);
log.error(e.getMessage(), e);
} finally {
long end = System.currentTimeMillis();
......
......@@ -48,6 +48,7 @@ public class PaymentTask {
* chargeType 取值范围为 0-4
* 此处设置为 100 仅仅只是为了避免 wxCheckOrderStatus() 方法中 chargeType == 0 相关代码块
*/
log.info("主动确认订单" + payment.getTradeNo() + "支付状态,此时chargeType为 100");
if (PaymentMethod.WECHAT.equals(paymentMethod)) {
paymentService.wxCheckOrderStatus(payment.getTradeNo(), 100);
}
......
......@@ -92,7 +92,7 @@ public class Set3proxyTask {
bw.write("\nallow none\nproxy -p20004\nsocks -p20005\n");
bw.flush();
bw.close();
log.error("成功写入文件");
log.info("成功写入文件");
if (proxyConfigRepository.count() > 0) {
ProxyConfig proxyConfig = proxyConfigRepository.findAll().get(0);
......
......@@ -59,7 +59,9 @@ public class Trans {
String url = "http://free.ipwhois.io/json/";
Trans trans = new Trans("112.74.47.217", 20001, "fangguanlianbrowser", "5D753F36QKqIaA1");
String rs = trans.get(url);
System.out.println(rs);
System.out.println(rs.contains("112.74.47.217"));
}
/**
......
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