Commit 0cbfbe94 authored by xuxin's avatar xuxin

未绑定店铺的信息获取

parent 18f61d97
......@@ -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;
}
}
......@@ -161,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());
......@@ -241,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);
}
}
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