Commit 15ec249f authored by renjie's avatar renjie

删除多个ip接口

parent 82fec7a6
...@@ -58,7 +58,7 @@ public class IpControlloer { ...@@ -58,7 +58,7 @@ public class IpControlloer {
public ResultDto deleteIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) { public ResultDto deleteIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
ipResourceService.deleteIp(principal.getName(), ipResourceRequestDto.getAddr().get(0)); resultDto.setData(ipResourceService.deleteIp(principal.getName(), ipResourceRequestDto.getAddr()));
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (Exception e) { }catch (Exception e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
......
...@@ -3,8 +3,9 @@ package com.edgec.browserbackend.browser.dto; ...@@ -3,8 +3,9 @@ package com.edgec.browserbackend.browser.dto;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RenewIpReturnDto { public class IpOperationResultDto {
List<String> successList = new ArrayList<>(); List<String> successList = new ArrayList<>();
List<String> failList = new ArrayList<>();
public List<String> getSuccessList() { public List<String> getSuccessList() {
return successList; return successList;
...@@ -13,4 +14,12 @@ public class RenewIpReturnDto { ...@@ -13,4 +14,12 @@ public class RenewIpReturnDto {
public void setSuccessList(List<String> successList) { public void setSuccessList(List<String> successList) {
this.successList = successList; this.successList = successList;
} }
public List<String> getFailList() {
return failList;
}
public void setFailList(List<String> failList) {
this.failList = failList;
}
} }
...@@ -3,7 +3,7 @@ package com.edgec.browserbackend.browser.dto; ...@@ -3,7 +3,7 @@ package com.edgec.browserbackend.browser.dto;
public class PageInfo { public class PageInfo {
int currentPage; int currentPage;
int totalPages; int totalPages;
int totalShops; int totalItems;
public int getCurrentPage() { public int getCurrentPage() {
return currentPage; return currentPage;
...@@ -21,11 +21,11 @@ public class PageInfo { ...@@ -21,11 +21,11 @@ public class PageInfo {
this.totalPages = totalPage; this.totalPages = totalPage;
} }
public int getTotalShops() { public int getTotalItems() {
return totalShops; return totalItems;
} }
public void setTotalShops(int totalShops) { public void setTotalItems(int totalItems) {
this.totalShops = totalShops; this.totalItems = totalItems;
} }
} }
...@@ -156,7 +156,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -156,7 +156,7 @@ public class IpResourceServiceImpl implements IpResourceService {
} }
@Override @Override
public RenewIpReturnDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception { public IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
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);
...@@ -184,14 +184,14 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -184,14 +184,14 @@ public class IpResourceServiceImpl implements IpResourceService {
RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class); RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class);
if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode())) if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode()))
throw new Exception(renewIpResultDto.getErrorCode()); throw new Exception(renewIpResultDto.getErrorCode());
RenewIpReturnDto renewIpReturnDto = new RenewIpReturnDto(); IpOperationResultDto ipOperationResultDto = new IpOperationResultDto();
renewIpResultDto.getIplist().forEach(x -> { renewIpResultDto.getIplist().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false);
ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli()); ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli());
ipResourceRepository.save(ipResource); ipResourceRepository.save(ipResource);
renewIpReturnDto.getSuccessList().add(x.getIp()); ipOperationResultDto.getSuccessList().add(x.getIp());
}); });
return renewIpReturnDto; return ipOperationResultDto;
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to renew ip", e.getMessage()); logger.error("fail to renew ip", e.getMessage());
logger.error(e.getMessage()); logger.error(e.getMessage());
...@@ -200,20 +200,26 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -200,20 +200,26 @@ public class IpResourceServiceImpl implements IpResourceService {
} }
@Override @Override
public void deleteIp(String username, String ipAddr) throws Exception { public IpOperationResultDto deleteIp(String username, List<String> ipAddrs) throws Exception {
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);
IpOperationResultDto ipOperationResultDto = new IpOperationResultDto();
ipAddrs.forEach(ipAddr -> {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null) if (ipResource == null) {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); ipOperationResultDto.getFailList().add(ipAddr);
return;
}
UserShop userShop = null; UserShop userShop = null;
if (ipResource.getShopId() != null) { if (ipResource.getShopId() != null) {
userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId()); userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId());
if (userShop == null) if (userShop == null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); ipOperationResultDto.getFailList().add(ipAddr);
return;
}
} else if (!ipResource.getOwner().equals(username)) { } else if (!ipResource.getOwner().equals(username)) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); return;
} }
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = buildGetHeader(); HttpHeaders headers = buildGetHeader();
...@@ -236,11 +242,14 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -236,11 +242,14 @@ public class IpResourceServiceImpl implements IpResourceService {
userShop.setIpId(null); userShop.setIpId(null);
userShopRepository.save(userShop); userShopRepository.save(userShop);
} }
ipOperationResultDto.getSuccessList().add(ipAddr);
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to renew ip", e.getMessage()); logger.error("fail to renew ip", e.getMessage());
logger.error(e.getMessage()); ipOperationResultDto.getFailList().add(ipAddr);
throw new Exception(e.getMessage()); throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
} }
});
return ipOperationResultDto;
} }
@Override @Override
...@@ -347,7 +356,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -347,7 +356,7 @@ public class IpResourceServiceImpl implements IpResourceService {
PageInfo pageInfo = new PageInfo(); PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(ipResourceDtoPage.getPageable().getPageNumber()); pageInfo.setCurrentPage(ipResourceDtoPage.getPageable().getPageNumber());
pageInfo.setTotalPages(ipResourceDtoPage.getTotalPages()); pageInfo.setTotalPages(ipResourceDtoPage.getTotalPages());
pageInfo.setTotalShops(allIpIds.size()); pageInfo.setTotalItems(allIpIds.size());
ipPageResultDto.setIpPage(pageInfo); ipPageResultDto.setIpPage(pageInfo);
return ipPageResultDto; return ipPageResultDto;
} }
......
...@@ -338,7 +338,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -338,7 +338,7 @@ public class ShopServiceImpl implements ShopService {
PageInfo pageInfo = new PageInfo(); PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber()); pageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber());
pageInfo.setTotalPages(shopDtoPage.getTotalPages()); pageInfo.setTotalPages(shopDtoPage.getTotalPages());
pageInfo.setTotalShops(shopIds.size()); pageInfo.setTotalItems(shopIds.size());
shopPageResultDto.setShopPage(pageInfo); shopPageResultDto.setShopPage(pageInfo);
return shopPageResultDto; return shopPageResultDto;
} }
......
...@@ -8,9 +8,9 @@ public interface IpResourceService { ...@@ -8,9 +8,9 @@ public interface IpResourceService {
List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception; List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
RenewIpReturnDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception; IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
void deleteIp(String username, String ipAddr) throws Exception; IpOperationResultDto deleteIp(String username, List<String> ipAddrs) throws Exception;
IpPageResultDto getIpList(String username, int groupType, int page, int amount, IpFilterDto ipFilterDto); IpPageResultDto getIpList(String username, int groupType, int page, int amount, IpFilterDto ipFilterDto);
} }
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