Commit 82fec7a6 authored by renjie's avatar renjie

店铺绑定解绑接口

parent 36b44b1c
...@@ -71,10 +71,10 @@ public class IpControlloer { ...@@ -71,10 +71,10 @@ public class IpControlloer {
} }
@RequestMapping(value = "/list", method = RequestMethod.POST) @RequestMapping(value = "/list", method = RequestMethod.POST)
public ResultDto getIpList(Principal principal, IpListRequestDto ipListRequestDto) { public ResultDto getIpList(Principal principal, @RequestBody IpListRequestDto ipListRequestDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
List<IpResourceDto> ipResourceDto = ipResourceService.getIpList(principal.getName(), ipListRequestDto.getType(), ipListRequestDto.getPage(), IpPageResultDto ipResourceDto = ipResourceService.getIpList(principal.getName(), ipListRequestDto.getGroupType(), ipListRequestDto.getPage(),
ipListRequestDto.getAmount(), ipListRequestDto.getIpFilterDto()); ipListRequestDto.getAmount(), ipListRequestDto.getIpFilterDto());
resultDto.setData(ipResourceDto); resultDto.setData(ipResourceDto);
resultDto.setStatus(0); resultDto.setStatus(0);
......
...@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; ...@@ -5,6 +5,7 @@ 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;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Document(collection = "ipresource") @Document(collection = "ipresource")
...@@ -16,12 +17,13 @@ public class IpResource { ...@@ -16,12 +17,13 @@ public class IpResource {
private IpType ipType = IpType.VENDOR; private IpType ipType = IpType.VENDOR;
private String vendor; private String vendor;
private String region; private String region;
private IpStatus ipStatus; //0:正常, 1:已过期, 2:即将过期
private List<Interval> port; private int status;
private List<String> port;
private long purchasedTime; private long purchasedTime;
private long validTime; private long validTime;
private String details; private String details;
List<String> bindHistory; List<String> bindHistory = new ArrayList<>();
private boolean isDeleted; private boolean isDeleted;
private String username; private String username;
private String owner; private String owner;
...@@ -55,12 +57,12 @@ public class IpResource { ...@@ -55,12 +57,12 @@ public class IpResource {
this.region = region; this.region = region;
} }
public IpStatus getIpStatus() { public int getStatus() {
return ipStatus; return status;
} }
public void setIpStatus(IpStatus ipStatus) { public void setStatus(int status) {
this.ipStatus = ipStatus; this.status = status;
} }
public IpType getIpType() { public IpType getIpType() {
...@@ -127,11 +129,11 @@ public class IpResource { ...@@ -127,11 +129,11 @@ public class IpResource {
this.username = username; this.username = username;
} }
public List<Interval> getPort() { public List<String> getPort() {
return port; return port;
} }
public void setPort(List<Interval> port) { public void setPort(List<String> port) {
this.port = port; this.port = port;
} }
......
package com.edgec.browserbackend.browser.dto; package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpListRequestDto { public class IpListRequestDto {
private int type; private int groupType;
private int page; private int page;
private int amount; private int amount;
private IpFilterDto ipFilterDto; private IpFilterDto ipFilterDto;
private List<String> addr = new ArrayList<>();
public int getAmount() { public int getAmount() {
return amount; return amount;
...@@ -18,12 +20,12 @@ public class IpListRequestDto { ...@@ -18,12 +20,12 @@ public class IpListRequestDto {
this.amount = amount; this.amount = amount;
} }
public int getType() { public int getGroupType() {
return type; return groupType;
} }
public void setType(int type) { public void setGroupType(int groupType) {
this.type = type; this.groupType = groupType;
} }
public int getPage() { public int getPage() {
...@@ -41,12 +43,4 @@ public class IpListRequestDto { ...@@ -41,12 +43,4 @@ public class IpListRequestDto {
public void setIpFilterDto(IpFilterDto ipFilterDto) { public void setIpFilterDto(IpFilterDto ipFilterDto) {
this.ipFilterDto = ipFilterDto; this.ipFilterDto = ipFilterDto;
} }
public List<String> getAddr() {
return addr;
}
public void setAddr(List<String> addr) {
this.addr = addr;
}
} }
package com.edgec.browserbackend.browser.dto;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/11 11:13 上午
**/
public class IpPageResultDto<T> {
List<T> ipList;
PageInfo ipPage;
public List<T> getIpList() {
return ipList;
}
public void setIpList(List<T> ipList) {
this.ipList = ipList;
}
public PageInfo getIpPage() {
return ipPage;
}
public void setIpPage(PageInfo ipPage) {
this.ipPage = ipPage;
}
}
...@@ -14,8 +14,8 @@ public class IpResourceDto { ...@@ -14,8 +14,8 @@ public class IpResourceDto {
private String addr; private String addr;
private String vendor; private String vendor;
private String region; private String region;
private IpStatus ipStatus; private int status;
private List<Interval> port; private List<String> port;
private long purchasedTIme; private long purchasedTIme;
private long validTime; private long validTime;
private String username; private String username;
...@@ -32,7 +32,7 @@ public class IpResourceDto { ...@@ -32,7 +32,7 @@ public class IpResourceDto {
this.addr = ipResource.getAddr(); this.addr = ipResource.getAddr();
this.vendor = ipResource.getVendor(); this.vendor = ipResource.getVendor();
this.region = ipResource.getRegion(); this.region = ipResource.getRegion();
this.ipStatus = ipResource.getIpStatus(); this.status = ipResource.getStatus();
this.port = ipResource.getPort(); this.port = ipResource.getPort();
this.purchasedTIme = ipResource.getPurchasedTime(); this.purchasedTIme = ipResource.getPurchasedTime();
this.validTime = ipResource.getValidTime(); this.validTime = ipResource.getValidTime();
...@@ -51,11 +51,11 @@ public class IpResourceDto { ...@@ -51,11 +51,11 @@ public class IpResourceDto {
this.id = id; this.id = id;
} }
public List<Interval> getPort() { public List<String> getPort() {
return port; return port;
} }
public void setPort(List<Interval> port) { public void setPort(List<String> port) {
this.port = port; this.port = port;
} }
...@@ -99,12 +99,12 @@ public class IpResourceDto { ...@@ -99,12 +99,12 @@ public class IpResourceDto {
this.purchasedTIme = purchasedTIme; this.purchasedTIme = purchasedTIme;
} }
public IpStatus getIpStatus() { public int getStatus() {
return ipStatus; return status;
} }
public void setIpStatus(IpStatus ipStatus) { public void setStatus(int status) {
this.ipStatus = ipStatus; this.status = status;
} }
public String getDetails() { public String getDetails() {
......
package com.edgec.browserbackend.browser.dto; package com.edgec.browserbackend.browser.dto;
public class ShopPageInfo { public class PageInfo {
int currentPage; int currentPage;
int totalPages; int totalPages;
int totalShops; int totalShops;
......
...@@ -2,23 +2,23 @@ package com.edgec.browserbackend.browser.dto; ...@@ -2,23 +2,23 @@ package com.edgec.browserbackend.browser.dto;
import java.util.List; import java.util.List;
public class ShopPageResultDto { public class ShopPageResultDto<T> {
List<ShopResultDto> shopList; List<T> shopList;
ShopPageInfo shopPage; PageInfo shopPage;
public List<ShopResultDto> getShopList() { public List<T> getShopList() {
return shopList; return shopList;
} }
public void setShopList(List<ShopResultDto> shopList) { public void setShopList(List<T> shopList) {
this.shopList = shopList; this.shopList = shopList;
} }
public ShopPageInfo getShopPage() { public PageInfo getShopPage() {
return shopPage; return shopPage;
} }
public void setShopPage(ShopPageInfo shopPage) { public void setShopPage(PageInfo shopPage) {
this.shopPage = shopPage; this.shopPage = shopPage;
} }
} }
package com.edgec.browserbackend.browser.repository; package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource; import com.edgec.browserbackend.browser.domain.IpResource;
import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
public interface IpResourceRepository extends MongoRepository<IpResource, String> { public interface IpResourceRepository extends MongoRepository<IpResource, String> {
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted); IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
List<IpResource> findByOwnerAndShopIdIsNull(String owner);
List<IpResource> findByIdIn(List<String> ipIds); List<IpResource> findByIdIn(List<String> ipIds);
List<IpResource> findByAddrLikeAndIdIn(String addr, List<String> ipIds); List<IpResource> findByOwnerAndShopIdIsNull(String owner);
List<IpResource> findByVendorLikeAndIdIn(String vendor, List<String> ipIds); List<IpResource> findByOwnerAndStatusAndShopIdIsNull(String owner, int status);
List<IpResource> findByRegionLikeAndIdIn(String region, List<String> ipIds); List<IpResource> findByStatusAndIdIn(int status, List<String> ipIds);
Page<IpResource> findByAddrLikeAndIdIn(String addr, List<String> ipIds, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdIn(String vendor, List<String> ipIds, Pageable pageable);
Page<IpResource> findByRegionLikeAndIdIn(String region, List<String> ipIds, Pageable pageable);
} }
...@@ -2,7 +2,6 @@ package com.edgec.browserbackend.browser.service.Impl; ...@@ -2,7 +2,6 @@ package com.edgec.browserbackend.browser.service.Impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.edgec.browserbackend.account.domain.Account; import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.User;
import com.edgec.browserbackend.account.exception.AccountErrorCode; 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;
...@@ -17,6 +16,10 @@ import org.apache.commons.lang3.StringUtils; ...@@ -17,6 +16,10 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -34,9 +37,9 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -34,9 +37,9 @@ public class IpResourceServiceImpl implements IpResourceService {
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 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> port = Arrays.asList("20000", "20001");
private static List<String> protocol = Arrays.asList("http", "https", "socks5", "ssr"); private static List<String> protocol = Arrays.asList("socks5", "proxy");
private static String startscript = ""; private static String startscript = "";
...@@ -131,7 +134,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -131,7 +134,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResource.setValidTime(Instant.now().plusSeconds(60*60*24*7).toEpochMilli()); ipResource.setValidTime(Instant.now().plusSeconds(60*60*24*7).toEpochMilli());
ipResource.setPort(port); ipResource.setPort(port);
ipResource.setVendor(ipResourceRequestDto.getVendor()); ipResource.setVendor(ipResourceRequestDto.getVendor());
ipResource.setIpStatus(IpStatus.NORMAL); ipResource.setStatus(0);
ipResource.setUsername(USERNAME); ipResource.setUsername(USERNAME);
if (account.getParent() != null) if (account.getParent() != null)
ipResource.setUserParent(account.getParent()); ipResource.setUserParent(account.getParent());
...@@ -204,8 +207,9 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -204,8 +207,9 @@ public class IpResourceServiceImpl implements IpResourceService {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
UserShop userShop = null;
if (ipResource.getShopId() != null) { if (ipResource.getShopId() != null) {
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId()); userShop = userShopRepository.findByUsernameAndShopId(username, ipResource.getShopId());
if (userShop == null) if (userShop == null)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} else if (!ipResource.getOwner().equals(username)) { } else if (!ipResource.getOwner().equals(username)) {
...@@ -221,6 +225,17 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -221,6 +225,17 @@ public class IpResourceServiceImpl implements IpResourceService {
if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode())) if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode()))
throw new Exception(deleteIpResultDto.getErrorCode()); throw new Exception(deleteIpResultDto.getErrorCode());
ipResourceRepository.delete(ipResource); ipResourceRepository.delete(ipResource);
if (userShop != null){
Shop shop = shopRepository.findById(ipResource.getShopId()).orElse(null);
if (shop != null) {
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
shopRepository.save(shop);
}
userShop.setIpId(null);
userShopRepository.save(userShop);
}
} 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());
...@@ -229,67 +244,112 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -229,67 +244,112 @@ public class IpResourceServiceImpl implements IpResourceService {
} }
@Override @Override
public List<IpResourceDto> getIpList(String username, int type, int page, int amount, IpFilterDto ipFilterDto) { public IpPageResultDto getIpList(String username, int groupType, int page, int amount, IpFilterDto ipFilterDto) {
if (amount > 100)
amount = 100;
Pageable pageable = PageRequest.of(page, amount);
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);
List<String> IpIds = userShopRepository.findByUsername(username).stream().map(x -> x.getShopId()).filter(x -> x == null).collect(Collectors.toList());
List<IpResource> ipResources = ipResourceRepository.findByIdIn(IpIds);
List<IpResource> notUsed = ipResourceRepository.findByOwnerAndShopIdIsNull(username);
ipResources.addAll(notUsed);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> ipIds = userShopRepository.findByUsername(username).stream().filter(x -> (x.getShopId() != null && x.getIpId() != null))
.map(x -> x.getIpId()).collect(Collectors.toList());
List<IpResource> ipResources = new ArrayList<>();
List<IpResource> notUsed = null;
switch (groupType) {
case 1:
ipResources = ipResourceRepository.findByIdIn(ipIds);;
notUsed = ipResourceRepository.findByOwnerAndShopIdIsNull(username);
break;
case 2:
ipResources = ipResourceRepository.findByStatusAndIdIn(2, ipIds);;
notUsed = ipResourceRepository.findByOwnerAndStatusAndShopIdIsNull(username, 2);
break;
case 3:
ipResources = ipResourceRepository.findByStatusAndIdIn(1, ipIds);;
notUsed = ipResourceRepository.findByOwnerAndStatusAndShopIdIsNull(username, 1);
break;
case 4:
notUsed = ipResourceRepository.findByOwnerAndShopIdIsNull(username);
break;
}
if (notUsed != null)
ipResources.addAll(notUsed);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList());
if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) { if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) {
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList()); Page<IpResource> ipResources1 = ipResourceRepository.findByRegionLikeAndIdIn(ipFilterDto.getRegion(), allIpIds, pageable);
List<IpResource> ipResources1 = ipResourceRepository.findByRegionLikeAndIdIn(ipFilterDto.getRegion(), allIpIds); ipResources1.getContent().forEach(x -> {
ipResources1.forEach(x -> {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
ShopDto shopDto; ShopDto shopDto;
if (shop != null) if (x.getShopId() == null) {
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto(); shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
}
ipResourceDtos.add(new IpResourceDto(x, shopDto)); ipResourceDtos.add(new IpResourceDto(x, shopDto));
}); });
} }
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getAddr())) { else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getAddr())) {
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList()); Page<IpResource> ipResources1 = ipResourceRepository.findByAddrLikeAndIdIn(ipFilterDto.getAddr(), allIpIds, pageable);
List<IpResource> ipResources1 = ipResourceRepository.findByAddrLikeAndIdIn(ipFilterDto.getAddr(), allIpIds); ipResources1.getContent().forEach(x -> {
ipResources1.forEach(x -> {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
ShopDto shopDto; ShopDto shopDto;
if (shop != null) if (x.getShopId() == null) {
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto(); shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
}
ipResourceDtos.add(new IpResourceDto(x, shopDto)); ipResourceDtos.add(new IpResourceDto(x, shopDto));
}); });
} }
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) { else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) {
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList()); Page<IpResource> ipResources1 = ipResourceRepository.findByVendorLikeAndIdIn(ipFilterDto.getVendor(), allIpIds, pageable);
List<IpResource> ipResources1 = ipResourceRepository.findByVendorLikeAndIdIn(ipFilterDto.getVendor(), allIpIds); ipResources1.getContent().forEach(x -> {
ipResources1.forEach(x -> {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
ShopDto shopDto; ShopDto shopDto;
if (shop != null) if (x.getShopId() == null) {
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto(); shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
}
ipResourceDtos.add(new IpResourceDto(x, shopDto)); ipResourceDtos.add(new IpResourceDto(x, shopDto));
}); });
} else { } else {
ipResources.forEach(x -> { ipResources.forEach(x -> {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
ShopDto shopDto; ShopDto shopDto;
if (shop != null) if (x.getShopId() == null) {
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto(); shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
}
ipResourceDtos.add(new IpResourceDto(x, shopDto)); ipResourceDtos.add(new IpResourceDto(x, shopDto));
}); });
} }
return ipResourceDtos; Page<IpResourceDto> ipResourceDtoPage = new PageImpl<>(ipResourceDtos, pageable, allIpIds.size());
IpPageResultDto ipPageResultDto = new IpPageResultDto();
ipPageResultDto.setIpList(ipResourceDtoPage.getContent());
PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(ipResourceDtoPage.getPageable().getPageNumber());
pageInfo.setTotalPages(ipResourceDtoPage.getTotalPages());
pageInfo.setTotalShops(allIpIds.size());
ipPageResultDto.setIpPage(pageInfo);
return ipPageResultDto;
} }
......
package com.edgec.browserbackend.browser.service.Impl; package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.account.domain.Account; import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.User;
import com.edgec.browserbackend.account.exception.AccountErrorCode; 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;
...@@ -11,7 +10,7 @@ import com.edgec.browserbackend.browser.domain.Shop; ...@@ -11,7 +10,7 @@ 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.ShopFilterDto; import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto; import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.ShopPageInfo; import com.edgec.browserbackend.browser.dto.PageInfo;
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;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; import com.edgec.browserbackend.browser.repository.IpResourceRepository;
...@@ -68,7 +67,11 @@ public class ShopServiceImpl implements ShopService { ...@@ -68,7 +67,11 @@ 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, shopResultDto.getShopId()); UserShop us = null;
if (shopResultDto.getShopId() != null)
us = userShopRepository.findByUsernameAndShopId(username, shopResultDto.getShopId());
if (shopResultDto.getGroup() == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Group group = groupRepository.findById(shopResultDto.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);
...@@ -285,10 +288,10 @@ public class ShopServiceImpl implements ShopService { ...@@ -285,10 +288,10 @@ public class ShopServiceImpl implements ShopService {
} }
@Override @Override
public ShopPageResultDto getShopList(String username, String groupId, int page, int amout, ShopFilterDto shopFilterDto) { public ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto) {
if (amout > 100) if (amount > 100)
amout = 100; amount = 100;
Pageable pageable = PageRequest.of(page, amout); Pageable pageable = PageRequest.of(page, amount);
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);
...@@ -332,11 +335,11 @@ public class ShopServiceImpl implements ShopService { ...@@ -332,11 +335,11 @@ public class ShopServiceImpl implements ShopService {
Page<ShopResultDto> shopDtoPage = new PageImpl<>(shopResultDtos, pageable, shopIds.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(); PageInfo pageInfo = new PageInfo();
shopPageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber()); pageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber());
shopPageInfo.setTotalPages(shopDtoPage.getTotalPages()); pageInfo.setTotalPages(shopDtoPage.getTotalPages());
shopPageInfo.setTotalShops(shopIds.size()); pageInfo.setTotalShops(shopIds.size());
shopPageResultDto.setShopPage(shopPageInfo); shopPageResultDto.setShopPage(pageInfo);
return shopPageResultDto; return shopPageResultDto;
} }
} }
...@@ -12,5 +12,5 @@ public interface IpResourceService { ...@@ -12,5 +12,5 @@ public interface IpResourceService {
void deleteIp(String username, String ipAddr) throws Exception; void deleteIp(String username, String ipAddr) throws Exception;
List<IpResourceDto> getIpList(String username, int type, 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