Commit 1c989b65 authored by renjie's avatar renjie

Ip接口

parent 0ccd72a6
package com.edgec.browserbackend.browser.controller; package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto; import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.*; import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.service.IpResourceService; import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
...@@ -30,10 +29,10 @@ public class IpControlloer { ...@@ -30,10 +29,10 @@ public class IpControlloer {
List<IpResourceDto> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto); List<IpResourceDto> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto); resultDto.setData(ipResourceDto);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (Exception e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode()); statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage()); statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo); resultDto.setStatusInfo(statusInfo);
} }
......
...@@ -3,7 +3,7 @@ package com.edgec.browserbackend.browser.controller; ...@@ -3,7 +3,7 @@ package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto; import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.Shop; import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto; import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopDto; import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto; import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto; import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.ShopService; import com.edgec.browserbackend.browser.service.ShopService;
...@@ -27,11 +27,11 @@ public class ShopController { ...@@ -27,11 +27,11 @@ public class ShopController {
private ShopService shopService; private ShopService shopService;
@RequestMapping(value = "/add", method = RequestMethod.POST) @RequestMapping(value = "/add", method = RequestMethod.POST)
public ResultDto addShop(Principal principal, @RequestBody ShopDto shopDto) { public ResultDto addShop(Principal principal, @RequestBody ShopResultDto shopResultDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
ShopStringResultDto shopStringResultDto = new ShopStringResultDto(); ShopStringResultDto shopStringResultDto = new ShopStringResultDto();
shopStringResultDto.setId(shopService.addShop(principal.getName(), shopDto)); shopStringResultDto.setId(shopService.addShop(principal.getName(), shopResultDto));
resultDto.setData(shopStringResultDto); resultDto.setData(shopStringResultDto);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
...@@ -50,11 +50,11 @@ public class ShopController { ...@@ -50,11 +50,11 @@ public class ShopController {
} }
@RequestMapping(value = "/update", method = RequestMethod.POST) @RequestMapping(value = "/update", method = RequestMethod.POST)
public ResultDto updateShop(Principal principal, @RequestBody ShopDto shopDto) { public ResultDto updateShop(Principal principal, @RequestBody ShopResultDto shopResultDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
ShopStringResultDto shopStringResultDto = new ShopStringResultDto(); ShopStringResultDto shopStringResultDto = new ShopStringResultDto();
shopStringResultDto.setId(shopService.updateShop(principal.getName(), shopDto)); shopStringResultDto.setId(shopService.updateShop(principal.getName(), shopResultDto));
resultDto.setData(shopStringResultDto); resultDto.setData(shopStringResultDto);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
......
...@@ -15,13 +15,11 @@ public class IpResource { ...@@ -15,13 +15,11 @@ public class IpResource {
private String addr; private String addr;
private IpType ipType = IpType.VENDOR; private IpType ipType = IpType.VENDOR;
private String vendor; private String vendor;
private String ipRegion; private String region;
private IpStatus ipStatus; private IpStatus ipStatus;
private Platform platform;
private List<Interval> port; private List<Interval> port;
private long purchasedTime; private long purchasedTime;
private long validTime; private long validTime;
private long leftTime;
private String details; private String details;
List<String> bindHistory; List<String> bindHistory;
private boolean isDeleted; private boolean isDeleted;
...@@ -29,6 +27,8 @@ public class IpResource { ...@@ -29,6 +27,8 @@ public class IpResource {
private String userParent; private String userParent;
private String shopId; private String shopId;
private String shopName; private String shopName;
private List<String> protocol;
private String password;
public String getDetails() { public String getDetails() {
return details; return details;
...@@ -46,12 +46,12 @@ public class IpResource { ...@@ -46,12 +46,12 @@ public class IpResource {
this.id = id; this.id = id;
} }
public String getIpRegion() { public String getRegion() {
return ipRegion; return region;
} }
public void setIpRegion(String ipRegion) { public void setRegion(String region) {
this.ipRegion = ipRegion; this.region = region;
} }
public IpStatus getIpStatus() { public IpStatus getIpStatus() {
...@@ -86,14 +86,6 @@ public class IpResource { ...@@ -86,14 +86,6 @@ public class IpResource {
this.purchasedTime = purchasedTime; this.purchasedTime = purchasedTime;
} }
public long getLeftTime() {
return leftTime;
}
public void setLeftTime(long leftTime) {
this.leftTime = leftTime;
}
public long getValidTime() { public long getValidTime() {
return validTime; return validTime;
} }
...@@ -126,14 +118,6 @@ public class IpResource { ...@@ -126,14 +118,6 @@ public class IpResource {
isDeleted = deleted; isDeleted = deleted;
} }
public List<Interval> getPorts() {
return port;
}
public void setPorts(List<Interval> ports) {
this.port = ports;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
...@@ -182,11 +166,19 @@ public class IpResource { ...@@ -182,11 +166,19 @@ public class IpResource {
this.shopId = shopId; this.shopId = shopId;
} }
public Platform getPlatform() { public List<String> getProtocol() {
return platform; return protocol;
}
public void setProtocol(List<String> protocol) {
this.protocol = protocol;
}
public String getPassword() {
return password;
} }
public void setPlatform(Platform platform) { public void setPassword(String password) {
this.platform = platform; this.password = password;
} }
} }
package com.edgec.browserbackend.browser.domain; package com.edgec.browserbackend.browser.domain;
import com.edgec.browserbackend.browser.dto.ShopDto; import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -41,7 +41,7 @@ public class Shop { ...@@ -41,7 +41,7 @@ public class Shop {
} }
//创建店铺使用 //创建店铺使用
public Shop of(ShopDto shop) { public Shop of(ShopResultDto shop) {
if (shop.getShopUrl() != null) if (shop.getShopUrl() != null)
this.setShopUrl(shop.getShopUrl()); this.setShopUrl(shop.getShopUrl());
if (shop.getOwner() != null) if (shop.getOwner() != null)
......
package com.edgec.browserbackend.browser.dto;
public class DeleteIpResultDto {
private String errorCode = "";
private String result;
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}
\ No newline at end of file
package com.edgec.browserbackend.browser.dto; package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpStatus; import com.edgec.browserbackend.browser.domain.IpStatus;
import com.edgec.browserbackend.browser.domain.IpType; import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.domain.Shop;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.Id;
import java.util.List; import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class IpResourceDto { public class IpResourceDto {
private String id; private String id;
private String ipAddr; private String addr;
private IpType ipType; private String vendor;
private String ipProvider; private String region;
private String ipRegion;
private IpStatus ipStatus; private IpStatus ipStatus;
private List<Interval> ports; private List<Interval> port;
private long purchasedTIme; private long purchasedTIme;
private long validTime; private long validTime;
private long leftTime;
private String username; private String username;
private String details; private String details;
List<String> bindHistory; private String password;
private String shopId; ShopDto shopDto;
private String shopName;
public String getShopId() { public IpResourceDto(){
return shopId;
} }
public void setShopId(String shopId) { public IpResourceDto(IpResource ipResource, ShopDto shopDto){
this.shopId = shopId; this.id = ipResource.getId();
} this.addr = ipResource.getAddr();
this.vendor = ipResource.getVendor();
public String getShopName() { this.region = ipResource.getRegion();
return shopName; this.ipStatus = ipResource.getIpStatus();
} this.port = ipResource.getPort();
this.purchasedTIme = ipResource.getPurchasedTime();
public void setShopName(String shopName) { this.validTime = ipResource.getValidTime();
this.shopName = shopName; this.username = ipResource.getUsername();
this.details = ipResource.getDetails();
this.password = ipResource.getPassword();
this.shopDto = shopDto;
} }
public String getId() { public String getId() {
...@@ -49,44 +49,36 @@ public class IpResourceDto { ...@@ -49,44 +49,36 @@ public class IpResourceDto {
this.id = id; this.id = id;
} }
public List<Interval> getPorts() { public List<Interval> getPort() {
return ports; return port;
}
public void setPorts(List<Interval> ports) {
this.ports = ports;
} }
public String getIpRegion() { public void setPort(List<Interval> port) {
return ipRegion; this.port = port;
} }
public void setIpRegion(String ipRegion) { public String getRegion() {
this.ipRegion = ipRegion; return region;
} }
public List<String> getBindHistory() { public void setRegion(String region) {
return bindHistory; this.region = region;
} }
public void setBindHistory(List<String> bindHistory) { public String getVendor() {
this.bindHistory = bindHistory; return vendor;
} }
public String getIpProvider() { public void setVendor(String vendor) {
return ipProvider; this.vendor = vendor;
} }
public void setIpProvider(String ipProvider) { public String getAddr() {
this.ipProvider = ipProvider; return addr;
} }
public String getIpAddr() { public void setAddr(String addr) {
return ipAddr; this.addr = addr;
}
public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
} }
public long getValidTime() { public long getValidTime() {
...@@ -97,14 +89,6 @@ public class IpResourceDto { ...@@ -97,14 +89,6 @@ public class IpResourceDto {
this.validTime = validTime; this.validTime = validTime;
} }
public long getLeftTime() {
return leftTime;
}
public void setLeftTime(long leftTime) {
this.leftTime = leftTime;
}
public long getPurchasedTIme() { public long getPurchasedTIme() {
return purchasedTIme; return purchasedTIme;
} }
...@@ -113,14 +97,6 @@ public class IpResourceDto { ...@@ -113,14 +97,6 @@ public class IpResourceDto {
this.purchasedTIme = purchasedTIme; this.purchasedTIme = purchasedTIme;
} }
public IpType getIpType() {
return ipType;
}
public void setIpType(IpType ipType) {
this.ipType = ipType;
}
public IpStatus getIpStatus() { public IpStatus getIpStatus() {
return ipStatus; return ipStatus;
} }
...@@ -144,4 +120,20 @@ public class IpResourceDto { ...@@ -144,4 +120,20 @@ public class IpResourceDto {
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public ShopDto getShopDto() {
return shopDto;
}
public void setShopDto(ShopDto shopDto) {
this.shopDto = shopDto;
}
} }
package com.edgec.browserbackend.browser.dto;
import java.util.ArrayList;
import java.util.List;
public class RenewIpResultDto {
private String errorCode="";
private int balance = 0;
private List<IpBuyResultDto.IPData> iplist = new ArrayList<>();
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public List<IpBuyResultDto.IPData> getIplist() {
return iplist;
}
public void setIplist(List<IpBuyResultDto.IPData> iplist) {
this.iplist = iplist;
}
public static class IPData {
private String ip;
private String validTill;
public IPData(String ip, String validTill) {
this.ip = ip;
this.validTill = validTill;
}
public IPData() {
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getValidTill() {
return validTill;
}
public void setValidTill(String validTill) {
this.validTill = validTill;
}
}
}
\ No newline at end of file
package com.edgec.browserbackend.browser.dto; package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.TransferStatus;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class ShopDto { public class ShopDto {
private String shopId; private String shopId;
private String shopName; private String shopName;
private String owner;
private TransferStatus transferStatus;
private String group;
private String shopUrl;
private String shopPlatform;
private String shopAccount; private String shopAccount;
private String shopPassword; private String shopPassword;
private String shopPlatform;
private String shopUA;
private String shopCookie;
private IpResource bindIp;
public static ShopDto of(Shop shop, String group, IpResource ipResources) {
ShopDto shopDto = new ShopDto();
shopDto.setShopId(shop.getShopId());
if (shop.getShopName() != null)
shopDto.setShopName(shop.getShopName());
if (shop.getShopPlatform() != null)
shopDto.setShopPlatform(shop.getShopPlatform());
if (shop.getShopPassword() != null)
shopDto.setShopPassword(shop.getShopPassword());
if (shop.getTransferStatus() != null)
shopDto.setTransferStatus(shop.getTransferStatus());
if (shop.getOwner() != null)
shopDto.setOwner(shop.getOwner());
if (shop.getShopUrl() != null)
shopDto.setShopUrl(shop.getShopUrl());
if (shop.getShopUA() != null)
shopDto.setShopUA(shop.getShopUA());
if (shop.getShopCookie() != null)
shopDto.setShopCookie(shop.getShopCookie());
if (shop.getShopAccount() != null)
shopDto.setShopAccount(shop.getShopAccount());
shopDto.setGroup(group);
shopDto.setBindIp(ipResources);
return shopDto;
}
public String getShopPlatform() {
return shopPlatform;
}
public void setShopPlatform(String shopPlatform) {
this.shopPlatform = shopPlatform;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getShopPassword() {
return shopPassword;
}
public void setShopPassword(String shopPassword) {
this.shopPassword = shopPassword;
}
public String getShopAccount() {
return shopAccount;
}
public void setShopAccount(String shopAccount) {
this.shopAccount = shopAccount;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getShopId() { public String getShopId() {
return shopId; return shopId;
...@@ -108,51 +19,35 @@ public class ShopDto { ...@@ -108,51 +19,35 @@ public class ShopDto {
this.shopId = shopId; this.shopId = shopId;
} }
public String getOwner() { public String getShopName() {
return owner; return shopName;
}
public void setOwner(String owner) {
this.owner = owner;
}
public TransferStatus getTransferStatus() {
return transferStatus;
}
public void setTransferStatus(TransferStatus transferStatus) {
this.transferStatus = transferStatus;
}
public String getShopUrl() {
return shopUrl;
} }
public void setShopUrl(String shopUrl) { public void setShopName(String shopName) {
this.shopUrl = shopUrl; this.shopName = shopName;
} }
public IpResource getBindIp() { public String getShopAccount() {
return bindIp; return shopAccount;
} }
public void setBindIp(IpResource bindIp) { public void setShopAccount(String shopAccount) {
this.bindIp = bindIp; this.shopAccount = shopAccount;
} }
public String getShopUA() { public String getShopPassword() {
return shopUA; return shopPassword;
} }
public void setShopUA(String shopUA) { public void setShopPassword(String shopPassword) {
this.shopUA = shopUA; this.shopPassword = shopPassword;
} }
public String getShopCookie() { public String getShopPlatform() {
return shopCookie; return shopPlatform;
} }
public void setShopCookie(String shopCookie) { public void setShopPlatform(String shopPlatform) {
this.shopCookie = shopCookie; this.shopPlatform = shopPlatform;
} }
} }
...@@ -3,14 +3,14 @@ package com.edgec.browserbackend.browser.dto; ...@@ -3,14 +3,14 @@ package com.edgec.browserbackend.browser.dto;
import java.util.List; import java.util.List;
public class ShopPageResultDto { public class ShopPageResultDto {
List<ShopDto> shopList; List<ShopResultDto> shopList;
ShopPageInfo shopPage; ShopPageInfo shopPage;
public List<ShopDto> getShopList() { public List<ShopResultDto> getShopList() {
return shopList; return shopList;
} }
public void setShopList(List<ShopDto> shopList) { public void setShopList(List<ShopResultDto> shopList) {
this.shopList = shopList; this.shopList = shopList;
} }
......
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.TransferStatus;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopResultDto {
private String shopId;
private String shopName;
private String owner;
private TransferStatus transferStatus;
private String group;
private String shopUrl;
private String shopPlatform;
private String shopAccount;
private String shopPassword;
private String shopUA;
private String shopCookie;
private IpResource bindIp;
public static ShopResultDto of(Shop shop, String group, IpResource ipResources) {
ShopResultDto shopResultDto = new ShopResultDto();
shopResultDto.setShopId(shop.getShopId());
if (shop.getShopName() != null)
shopResultDto.setShopName(shop.getShopName());
if (shop.getShopPlatform() != null)
shopResultDto.setShopPlatform(shop.getShopPlatform());
if (shop.getShopPassword() != null)
shopResultDto.setShopPassword(shop.getShopPassword());
if (shop.getTransferStatus() != null)
shopResultDto.setTransferStatus(shop.getTransferStatus());
if (shop.getOwner() != null)
shopResultDto.setOwner(shop.getOwner());
if (shop.getShopUrl() != null)
shopResultDto.setShopUrl(shop.getShopUrl());
if (shop.getShopUA() != null)
shopResultDto.setShopUA(shop.getShopUA());
if (shop.getShopCookie() != null)
shopResultDto.setShopCookie(shop.getShopCookie());
if (shop.getShopAccount() != null)
shopResultDto.setShopAccount(shop.getShopAccount());
shopResultDto.setGroup(group);
shopResultDto.setBindIp(ipResources);
return shopResultDto;
}
public String getShopPlatform() {
return shopPlatform;
}
public void setShopPlatform(String shopPlatform) {
this.shopPlatform = shopPlatform;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getShopPassword() {
return shopPassword;
}
public void setShopPassword(String shopPassword) {
this.shopPassword = shopPassword;
}
public String getShopAccount() {
return shopAccount;
}
public void setShopAccount(String shopAccount) {
this.shopAccount = shopAccount;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public TransferStatus getTransferStatus() {
return transferStatus;
}
public void setTransferStatus(TransferStatus transferStatus) {
this.transferStatus = transferStatus;
}
public String getShopUrl() {
return shopUrl;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
public IpResource getBindIp() {
return bindIp;
}
public void setBindIp(IpResource bindIp) {
this.bindIp = bindIp;
}
public String getShopUA() {
return shopUA;
}
public void setShopUA(String shopUA) {
this.shopUA = shopUA;
}
public String getShopCookie() {
return shopCookie;
}
public void setShopCookie(String shopCookie) {
this.shopCookie = shopCookie;
}
}
package com.edgec.browserbackend.browser.service.Impl; package com.edgec.browserbackend.browser.service.Impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.Account; import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository; import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode; import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.IpResource; import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpStatus;
import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.dto.*; import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.service.IpResourceService; import com.edgec.browserbackend.browser.service.IpResourceService;
...@@ -14,10 +19,9 @@ import org.slf4j.LoggerFactory; ...@@ -14,10 +19,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.time.Instant;
import java.util.*; import java.util.*;
@Service @Service
...@@ -27,6 +31,11 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -27,6 +31,11 @@ public class IpResourceServiceImpl implements IpResourceService {
private static String CLOUDAMURL = "https://www.cloudam.cn"; private static String CLOUDAMURL = "https://www.cloudam.cn";
private static String TESTURL = "http://112.74.13.2"; private static String TESTURL = "http://112.74.13.2";
private static String USERNAME = "fangguanlianbrowser";
private static List<Interval> port = Arrays.asList(new Interval("22"), new Interval("443"), new Interval("20000"), new Interval("20001"));
private static List<String> protocol = Arrays.asList("http", "https", "socks5", "ssr");
@Autowired @Autowired
private AccountRepository accountRepository; private AccountRepository accountRepository;
...@@ -37,18 +46,31 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -37,18 +46,31 @@ public class IpResourceServiceImpl implements IpResourceService {
public HttpHeaders buildPostHeader() { public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders(); HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON); header.setContentType(MediaType.APPLICATION_JSON);
header.setBearerAuth("5aFM6ntBcLDD8e8PGMXBybx1UsWYYWvQ0jKOal28XoMhaz7gJyxX5GtayPcY6vec"); header.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
return header; return header;
} }
public HttpHeaders buildGetHeader() { public HttpHeaders buildGetHeader() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth("5aFM6ntBcLDD8e8PGMXBybx1UsWYYWvQ0jKOal28XoMhaz7gJyxX5GtayPcY6vec"); headers.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
return headers; return headers;
} }
public static String makeRandomPassword(int len){
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*.?".toCharArray();
StringBuilder sb = new StringBuilder();
Random r = new Random();
for (int x = 0; x < len; ++x) {
sb.append(charr[r.nextInt(charr.length)]);
}
return sb.toString();
}
@Override @Override
public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) { public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
List<IpResourceDto> ipResourceDtos = new ArrayList<>(); List<IpResourceDto> ipResourceDtos = new ArrayList<>();
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders header = buildPostHeader(); HttpHeaders header = buildPostHeader();
...@@ -59,11 +81,13 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -59,11 +81,13 @@ public class IpResourceServiceImpl implements IpResourceService {
map.put("provider", ipResourceRequestDto.getVendor()); map.put("provider", ipResourceRequestDto.getVendor());
map.put("unit", ipResourceRequestDto.getUnit()); map.put("unit", ipResourceRequestDto.getUnit());
map.put("amount", String.valueOf(ipResourceRequestDto.getAmount())); map.put("amount", String.valueOf(ipResourceRequestDto.getAmount()));
map.put("instanceSpecKey", String.valueOf(ipResourceRequestDto.getInstanceSpecKey())); map.put("loginPassword", makeRandomPassword(16));
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header); HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto ipBuyResultDto = null; IpBuyResultDto ipBuyResultDto = null;
try { try {
ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources?accountId=superbrowser", httpEntity, IpBuyResultDto.class); ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode()))
throw new Exception(ipBuyResultDto.getErrorCode());
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to post request", e.getMessage()); logger.error("fail to post request", e.getMessage());
logger.error(e.getMessage()); logger.error(e.getMessage());
...@@ -72,17 +96,36 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -72,17 +96,36 @@ public class IpResourceServiceImpl implements IpResourceService {
try { try {
if (ipBuyResultDto != null && ipBuyResultDto.getIplist() != null && ipBuyResultDto.getIplist().size() < 1) { if (ipBuyResultDto != null && ipBuyResultDto.getIplist() != null && ipBuyResultDto.getIplist().size() < 1) {
ipBuyResultDto.getIplist().forEach(x -> { ipBuyResultDto.getIplist().forEach(x -> {
IpInfoResultDto ipInfoResultDto = new IpInfoResultDto(); // IpInfoResultDto ipInfoResultDto = new IpInfoResultDto();
Map<String, String> params = new HashMap<String, String>(); // Map<String, String> params = new HashMap<String, String>();
params.put("accountId", "superbrowser"); // params.put("accountId", "browser");
params.put("ip", x.getIp()); // params.put("ip", x.getIp());
HttpHeaders headers = buildGetHeader(); // HttpHeaders headers = buildGetHeader();
HttpEntity<Map<String, String>> entity = new HttpEntity<>(params, headers); // HttpEntity<Map<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/ecc/ipinfo?accountId={accountId}&ip={ip}", HttpMethod.GET, entity, String.class); // ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/ecc/ipinfo?accountId={accountId}&ip={ip}", HttpMethod.GET, entity, String.class);
if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) { // JSONObject jsonObject = JSON.parseObject(result.getBody());
// if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
IpResource ipResource = new IpResource(); IpResource ipResource = new IpResource();
ipResource.setIpAddr(x.getIp());
} ipResource.setIpType(IpType.VENDOR);
// ipResource.setPurchasedTime(Long.valueOf((String) jsonObject.get("createdWhen")));
// ipResource.setValidTime(Long.valueOf((String)jsonObject.get("validTill")));
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
if (ipResourceRequestDto.getUnit().equals("month"))
ipResource.setValidTime(Instant.now().plusSeconds(60*60*24*30).toEpochMilli());
else if (ipResourceRequestDto.getUnit().equals("week"))
ipResource.setValidTime(Instant.now().plusSeconds(60*60*24*7).toEpochMilli());
ipResource.setPort(port);
ipResource.setVendor(ipResourceRequestDto.getVendor());
ipResource.setIpStatus(IpStatus.NORMAL);
ipResource.setUsername(username);
if (account.getParent() != null)
ipResource.setUserParent(account.getParent());
ipResource.setRegion(ipResourceRequestDto.getRegion());
ipResource.setProtocol(protocol);
ipResourceRepository.save(ipResource);
ipResourceDtos.add(new IpResourceDto(ipResource, null));
// }
}); });
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -94,13 +137,62 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -94,13 +137,62 @@ public class IpResourceServiceImpl implements IpResourceService {
} }
@Override @Override
public void renewIp(String username, IpResourceRequestDto ipResourceRequestDto) { public void renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
RestTemplate restTemplate = new RestTemplate();
HashMap<String, Object> map = new HashMap<>();
map.put("iplist", ipResourceRequestDto.getIplist());
map.put("period", ipResourceRequestDto.getPeriod());
HttpHeaders headers = buildPostHeader();
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers);
ipResourceRequestDto.getIplist().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x, false);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
});
try {
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/renewip?accountId=browser", HttpMethod.PUT, entity, String.class);
RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class);
if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode()))
throw new Exception(renewIpResultDto.getErrorCode());
renewIpResultDto.getIplist().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false);
ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli());
ipResourceRepository.save(ipResource);
});
} catch (Exception e) {
logger.error("fail to renew ip", e.getMessage());
logger.error(e.getMessage());
throw new Exception(e.getMessage());
}
} }
@Override @Override
public void deleteIp(String username, String ipAddr) { public void deleteIp(String username, String ipAddr) throws Exception {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = buildGetHeader();
Map<String, String> params = new HashMap<String, String>();
params.put("id", "1");
HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers);
try {
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class);
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode()))
throw new Exception(deleteIpResultDto.getErrorCode());
ipResourceRepository.delete(ipResource);
} catch (Exception e) {
logger.error("fail to renew ip", e.getMessage());
logger.error(e.getMessage());
throw new Exception(e.getMessage());
}
} }
@Override @Override
......
...@@ -9,7 +9,7 @@ import com.edgec.browserbackend.browser.domain.IpResource; ...@@ -9,7 +9,7 @@ import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop; import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.UserShop; import com.edgec.browserbackend.browser.domain.UserShop;
import com.edgec.browserbackend.browser.dto.FilterDto; import com.edgec.browserbackend.browser.dto.FilterDto;
import com.edgec.browserbackend.browser.dto.ShopDto; import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.ShopPageInfo; import com.edgec.browserbackend.browser.dto.ShopPageInfo;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto; import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.repository.GroupRepository; import com.edgec.browserbackend.browser.repository.GroupRepository;
...@@ -18,7 +18,6 @@ import com.edgec.browserbackend.browser.repository.ShopRepository; ...@@ -18,7 +18,6 @@ import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository; import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.service.ShopService; import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -56,7 +55,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -56,7 +55,7 @@ public class ShopServiceImpl implements ShopService {
IpResourceRepository ipResourceRepository; IpResourceRepository ipResourceRepository;
@Override @Override
public String addShop(String username, ShopDto shopDto) { public String addShop(String username, ShopResultDto shopResultDto) {
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
String id = null; String id = null;
if (account == null) { if (account == null) {
...@@ -68,21 +67,21 @@ public class ShopServiceImpl implements ShopService { ...@@ -68,21 +67,21 @@ public class ShopServiceImpl implements ShopService {
if (account.getShopCount() >= 10000) { if (account.getShopCount() >= 10000) {
throw new ClientRequestException(AccountErrorCode.SHOPMAX); throw new ClientRequestException(AccountErrorCode.SHOPMAX);
} }
UserShop us = userShopRepository.findByUsernameAndShopId(username, shopDto.getShopId()); UserShop us = userShopRepository.findByUsernameAndShopId(username, shopResultDto.getShopId());
Group group = groupRepository.findById(shopDto.getGroup()).orElse(null); Group group = groupRepository.findById(shopResultDto.getGroup()).orElse(null);
if (group == null) { if (group == null) {
throw new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST);
} }
try { try {
shopDto.setOwner(username); shopResultDto.setOwner(username);
Shop shop = new Shop(); Shop shop = new Shop();
shop.of(shopDto); shop.of(shopResultDto);
id = shopRepository.save(shop).getShopId(); id = shopRepository.save(shop).getShopId();
UserShop userShop = new UserShop(); UserShop userShop = new UserShop();
userShop.setUsername(username); userShop.setUsername(username);
userShop.setShopId(id); userShop.setShopId(id);
if (shopDto.getGroup() != null && us == null) { if (shopResultDto.getGroup() != null && us == null) {
userShop.setGroupId(shopDto.getGroup()); userShop.setGroupId(shopResultDto.getGroup());
} }
userShopRepository.save(userShop); userShopRepository.save(userShop);
}catch (Exception e) { }catch (Exception e) {
...@@ -97,23 +96,23 @@ public class ShopServiceImpl implements ShopService { ...@@ -97,23 +96,23 @@ public class ShopServiceImpl implements ShopService {
} }
@Override @Override
public String updateShop(String username, ShopDto shopDto) { public String updateShop(String username, ShopResultDto shopResultDto) {
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) { if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
} }
if (shopDto == null || StringUtils.isBlank(shopDto.getShopId())) { if (shopResultDto == null || StringUtils.isBlank(shopResultDto.getShopId())) {
throw new ClientRequestException(AccountErrorCode.OTHERS); throw new ClientRequestException(AccountErrorCode.OTHERS);
} }
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopDto.getShopId()); UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopResultDto.getShopId());
if (account.getPermission() < 4 || userShop == null) { if (account.getPermission() < 4 || userShop == null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} }
Shop shop_old = shopRepository.findById(shopDto.getShopId()).orElseGet(null); Shop shop_old = shopRepository.findById(shopResultDto.getShopId()).orElseGet(null);
if (shop_old == null) if (shop_old == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
try { try {
shop_old = shop_old.of(shopDto); shop_old = shop_old.of(shopResultDto);
shopRepository.save(shop_old); shopRepository.save(shop_old);
}catch (Exception e) { }catch (Exception e) {
logger.error("fail to update", e.getMessage()); logger.error("fail to update", e.getMessage());
...@@ -170,7 +169,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -170,7 +169,7 @@ public class ShopServiceImpl implements ShopService {
try { try {
shop.setIp(ipAddr); shop.setIp(ipAddr);
shop.setIpId(ipResource.getId()); shop.setIpId(ipResource.getId());
shop.setIpRegion(ipResource.getIpRegion()); shop.setIpRegion(ipResource.getRegion());
shopRepository.save(shop); shopRepository.save(shop);
List<String> history = ipResource.getBindHistory(); List<String> history = ipResource.getBindHistory();
history.add(shop.getShopId()); history.add(shop.getShopId());
...@@ -308,15 +307,15 @@ public class ShopServiceImpl implements ShopService { ...@@ -308,15 +307,15 @@ public class ShopServiceImpl implements ShopService {
shops = shopRepository.findByShopIdIn(shopIds, pageable); shops = shopRepository.findByShopIdIn(shopIds, pageable);
if (shops == null || shops.getNumberOfElements() < 1) if (shops == null || shops.getNumberOfElements() < 1)
return new ShopPageResultDto(); return new ShopPageResultDto();
List<ShopDto> shopDtos = new ArrayList<>(); List<ShopResultDto> shopResultDtos = new ArrayList<>();
shops.getContent().stream().forEach(x -> { shops.getContent().stream().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false);
if (ipResource == null) if (ipResource == null)
ipResource = new IpResource(); ipResource = new IpResource();
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId(); String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
shopDtos.add(ShopDto.of(x, group1, ipResource)); shopResultDtos.add(ShopResultDto.of(x, group1, ipResource));
}); });
Page<ShopDto> shopDtoPage = new PageImpl<>(shopDtos, pageable, shopDtos.size()); Page<ShopResultDto> shopDtoPage = new PageImpl<>(shopResultDtos, pageable, shopIds.size());
ShopPageResultDto shopPageResultDto = new ShopPageResultDto(); ShopPageResultDto shopPageResultDto = new ShopPageResultDto();
shopPageResultDto.setShopList(shopDtoPage.getContent()); shopPageResultDto.setShopList(shopDtoPage.getContent());
ShopPageInfo shopPageInfo = new ShopPageInfo(); ShopPageInfo shopPageInfo = new ShopPageInfo();
......
package com.edgec.browserbackend.browser.service; package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.FilterDto; import com.edgec.browserbackend.browser.dto.FilterDto;
import com.edgec.browserbackend.browser.dto.IpBuyResultDto;
import com.edgec.browserbackend.browser.dto.IpResourceDto; import com.edgec.browserbackend.browser.dto.IpResourceDto;
import com.edgec.browserbackend.browser.dto.IpResourceRequestDto; import com.edgec.browserbackend.browser.dto.IpResourceRequestDto;
...@@ -12,9 +10,9 @@ public interface IpResourceService { ...@@ -12,9 +10,9 @@ public interface IpResourceService {
List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto); List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto);
void renewIp(String username, IpResourceRequestDto ipResourceRequestDto); void renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
void deleteIp(String username, String ipAddr); void deleteIp(String username, String ipAddr) throws Exception;
List<IpResourceDto> getIpList(String username, int type, int page, int amount, FilterDto filterDto); List<IpResourceDto> getIpList(String username, int type, int page, int amount, FilterDto filterDto);
} }
...@@ -3,17 +3,17 @@ package com.edgec.browserbackend.browser.service; ...@@ -3,17 +3,17 @@ package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.Shop; import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.FilterDto; import com.edgec.browserbackend.browser.dto.FilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto; import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopDto; import com.edgec.browserbackend.browser.dto.ShopResultDto;
import java.util.List; import java.util.List;
public interface ShopService { public interface ShopService {
String addShop(String useranme, ShopDto shopDto); String addShop(String useranme, ShopResultDto shopResultDto);
List<String> addShops(String username, List<Shop> shops); List<String> addShops(String username, List<Shop> shops);
String updateShop(String username, ShopDto shopDto); String updateShop(String username, ShopResultDto shopResultDto);
void deleteShop(String username, String shopId); void deleteShop(String username, String shopId);
......
package com.edgec.browserbackend.browser.task;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class BrowserTask {
private static final Logger log = LoggerFactory.getLogger(BrowserTask.class);
// 每天
@Scheduled(cron = "0 * * * * ?")
// @Scheduled(cron = "0 * * * * ?")
public void checkIpStatus() {
}
}
...@@ -26,6 +26,10 @@ public class ClientRequestException extends IllegalArgumentException { ...@@ -26,6 +26,10 @@ public class ClientRequestException extends IllegalArgumentException {
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public ClientRequestException(int errorCode, String message){
super(message);
}
public String getAdditionalInfo() { public String getAdditionalInfo() {
return additionalInfo; return additionalInfo;
} }
...@@ -37,4 +41,5 @@ public class ClientRequestException extends IllegalArgumentException { ...@@ -37,4 +41,5 @@ public class ClientRequestException extends IllegalArgumentException {
public Object[] getArgs() { public Object[] getArgs() {
return this.args; return this.args;
} }
} }
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