Commit 0ccd72a6 authored by renjie's avatar renjie

shop接口bug修改

parent b586b3b8
...@@ -8,8 +8,8 @@ import org.springframework.data.mongodb.repository.MongoRepository; ...@@ -8,8 +8,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> { public interface ShopRepository extends MongoRepository<Shop, String> {
List<Shop> findByShopIdInAndIpRegionLike(List<String> shopIds, String ipRegion); Page<Shop> findByShopIdInAndIpRegionLike(List<String> shopIds, String ipRegion, Pageable pageable);
List<Shop> findByShopIdInAndShopAccountLike(List<String> shopIds, String shopAccount); Page<Shop> findByShopIdInAndShopAccountLike(List<String> shopIds, String shopAccount, Pageable pageable);
List<Shop> findByShopIdInAndShopNameLike(List<String> shopIds, String shopName); Page<Shop> findByShopIdInAndShopNameLike(List<String> shopIds, String shopName, Pageable pageable);
List<Shop> findByShopIdIn(List<String> shopIds); Page<Shop> findByShopIdIn(List<String> shopIds, Pageable pageable);
} }
...@@ -250,7 +250,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -250,7 +250,7 @@ public class ShopServiceImpl implements ShopService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} }
Pageable pageable = PageRequest.of(0, 100); Pageable pageable = PageRequest.of(0, 100);
List<Shop> shops = shopRepository.findByShopIdIn(shopIds); List<Shop> shops = shopRepository.findByShopIdIn(shopIds, pageable).getContent();
if (shops == null || shops.size() < 1) if (shops == null || shops.size() < 1)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
List<Account> accounts = accountRepository.findByNameIn(users); List<Account> accounts = accountRepository.findByNameIn(users);
...@@ -296,19 +296,20 @@ public class ShopServiceImpl implements ShopService { ...@@ -296,19 +296,20 @@ public class ShopServiceImpl implements ShopService {
shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream(). shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList()); map(x -> x.getShopId()).collect(Collectors.toList());
} }
List<Shop> shops; logger.error("shopIds.size " + shopIds.size());
Page<Shop> shops;
if (filterDto != null && StringUtils.isNotBlank(filterDto.getIpRegion())) if (filterDto != null && StringUtils.isNotBlank(filterDto.getIpRegion()))
shops = shopRepository.findByShopIdInAndIpRegionLike(shopIds, filterDto.getIpRegion()); shops = shopRepository.findByShopIdInAndIpRegionLike(shopIds, filterDto.getIpRegion(), pageable);
else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopAccount())) else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopAccount()))
shops = shopRepository.findByShopIdInAndShopAccountLike(shopIds, filterDto.getShopAccount()); shops = shopRepository.findByShopIdInAndShopAccountLike(shopIds, filterDto.getShopAccount(), pageable);
else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopName())) else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopName()))
shops = shopRepository.findByShopIdInAndShopNameLike(shopIds, filterDto.getShopName()); shops = shopRepository.findByShopIdInAndShopNameLike(shopIds, filterDto.getShopName(), pageable);
else else
shops = shopRepository.findByShopIdIn(shopIds); shops = shopRepository.findByShopIdIn(shopIds, pageable);
if (shops == null || shops.size() < 1) if (shops == null || shops.getNumberOfElements() < 1)
return new ShopPageResultDto(); return new ShopPageResultDto();
List<ShopDto> shopDtos = new ArrayList<>(); List<ShopDto> shopDtos = new ArrayList<>();
shops.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();
...@@ -321,7 +322,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -321,7 +322,7 @@ public class ShopServiceImpl implements ShopService {
ShopPageInfo shopPageInfo = new ShopPageInfo(); ShopPageInfo shopPageInfo = new ShopPageInfo();
shopPageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber()); shopPageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber());
shopPageInfo.setTotalPages(shopDtoPage.getTotalPages()); shopPageInfo.setTotalPages(shopDtoPage.getTotalPages());
shopPageInfo.setTotalShops(shopDtos.size()); shopPageInfo.setTotalShops(shopIds.size());
shopPageResultDto.setShopPage(shopPageInfo); shopPageResultDto.setShopPage(shopPageInfo);
return shopPageResultDto; return shopPageResultDto;
} }
......
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