Commit 0840cd65 authored by renjie's avatar renjie

本地ip

parent f542b14e
......@@ -71,7 +71,7 @@ public class IpControlloer {
public ResultDto deleteIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(ipResourceService.deleteIp(principal.getName(), ipResourceRequestDto.getAddr()));
resultDto.setData(ipResourceService.deleteIp(principal.getName(), ipResourceRequestDto));
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
......@@ -118,4 +118,38 @@ public class IpControlloer {
}
return resultDto;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResultDto updateIp(Principal principal, @RequestBody IpResourceUpdateDto ipResourceUpdateDto) {
ResultDto resultDto = new ResultDto();
try {
ipResourceService.updateIp(principal.getName(), ipResourceUpdateDto);
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(value = "/query", method = RequestMethod.POST)
public ResultDto queryIp(Principal principal, @RequestBody IpResourceUpdateDto ipResourceUpdateDto) {
ResultDto resultDto = new ResultDto();
try {
HashMap<String, Boolean> map = new HashMap<>();
map.put("found", ipResourceService.queryIpExist(principal.getName(), ipResourceUpdateDto));
resultDto.setData(map);
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
}
......@@ -115,7 +115,7 @@ public class ShopController {
public ResultDto bindShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.bindShop(principal.getName(), shopRequestDto.getShopId(), shopRequestDto.getIpAddr());
shopService.bindShop(principal.getName(), shopRequestDto);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......@@ -131,7 +131,7 @@ public class ShopController {
public ResultDto unBindShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.unBindShop(principal.getName(), shopRequestDto.getShopId(), shopRequestDto.getIpAddr());
shopService.unBindShop(principal.getName(), shopRequestDto);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......
......@@ -19,7 +19,7 @@ public class IpResource {
private Vendor vendor;
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效;
private int status;
private List<String> port;
private long purchasedTime;
......
......@@ -6,7 +6,7 @@ package com.edgec.browserbackend.browser.domain;
* @CreateTime 2020/3/12 4:01 下午
**/
public enum Vendor {
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云");
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云"), local("本地");
private String value;
......
......@@ -11,6 +11,7 @@ public class IpResourceDto {
private String addr;
private Vendor vendor;
private String region;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用
private int status;
private List<String> port;
private long purchasedTIme;
......
......@@ -34,6 +34,8 @@ public class IpResourceRequestDto {
private List<String> addr = new ArrayList<>();
private List<String> ipId = new ArrayList<>();
public String getName() {
return name;
}
......@@ -165,4 +167,12 @@ public class IpResourceRequestDto {
public void setRegionCn(String regionCn) {
this.regionCn = regionCn;
}
public List<String> getIpId() {
return ipId;
}
public void setIpId(List<String> ipId) {
this.ipId = ipId;
}
}
package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpResourceUpdateDto {
private String ipId;
private String addr;
private int status;
public String getAddr() {
return addr;
}
public void setIpId(String ipId) {
this.ipId = ipId;
}
public String getIpId() {
return ipId;
}
public void setAddr(String addr) {
this.addr = addr;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
......@@ -15,6 +15,8 @@ public class ShopRequestDto {
private String ipAddr;
private String ipId;
private String group;
private String toGroup;
......@@ -116,4 +118,12 @@ public class ShopRequestDto {
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getIpId() {
return ipId;
}
public void setIpId(String ipId) {
this.ipId = ipId;
}
}
......@@ -9,8 +9,11 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface IpResourceRepository extends MongoRepository<IpResource, String> {
IpResource findByAddr(String addr);
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
IpResource findByIdAndIsDeleted(String id, boolean isDeleted);
List<IpResource> findByIdInAndIsDeleted(List<String> ipIds, boolean isDeleted);
Page<IpResource> findByIdInAndIsDeleted(List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int status, boolean isDeleted);
List<IpResource> findByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
......
......@@ -201,7 +201,10 @@ public class ShopServiceImpl implements ShopService {
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId, shop.getIp());
ShopRequestDto shopRequestDto = new ShopRequestDto();
shopRequestDto.setShopId(shopId);
shopRequestDto.setIpId(shop.getIpId());
unBindShop(username, shopRequestDto);
}
boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId);
if (result) {
......@@ -212,7 +215,8 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public void bindShop(String username, String shopId, String ipAddr) {
public void bindShop(String username, ShopRequestDto shopRequestDto) {
String shopId = shopRequestDto.getShopId();
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -224,14 +228,21 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
} else if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
}
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId, shop.getIp());
unBindShop(username, shopRequestDto);
}
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
try {
shop.setIp(ipAddr);
shop.setIp(ipResource.getAddr());
shop.setIpId(ipResource.getId());
shop.setIpRegion(ipResource.getRegion());
shopRepository.save(shop);
......@@ -250,7 +261,10 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public void unBindShop(String username, String shopId, String ipAddr) {
public void unBindShop(String username, ShopRequestDto shopRequestDto) {
String shopId = null;
if (StringUtils.isNotBlank(shopRequestDto.getShopId()))
shopId = shopRequestDto.getShopId();
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -262,10 +276,15 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
} else if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
}
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
if (!ipAddr.equals(shop.getIp()))
if (!ipResource.getId().equals(shop.getIpId()))
throw new ClientRequestException(BrowserErrorCode.IPNOTBINDTOSHOP);
try {
shop.setIp(null);
......
......@@ -11,7 +11,7 @@ public interface IpResourceService {
IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
IpOperationResultDto deleteIp(String username, List<String> ipAddrs) throws Exception;
IpOperationResultDto deleteIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
IpPageResultDto getIpList(String username, int groupType, int page, int amount, IpFilterDto ipFilterDto);
......@@ -24,4 +24,8 @@ public interface IpResourceService {
IpTransactionDto queryTransaction(String username, String transactionId);
IpSummary getIpSummary(String username);
void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto);
boolean queryIpExist(String username, IpResourceUpdateDto ipResourceUpdateDto);
}
......@@ -4,6 +4,7 @@ import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import org.springframework.web.multipart.MultipartFile;
......@@ -20,9 +21,9 @@ public interface ShopService {
void deleteShop(String username, String shopId);
void bindShop(String username, String shopId, String ipAddr);
void bindShop(String username, ShopRequestDto shopRequestDto);
void unBindShop(String username, String shopId, String ipAddr);
void unBindShop(String username, ShopRequestDto shopRequestDto);
void transferShop(String username, String shopId, String groupId);
......
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