Commit aa68278b authored by xuxin's avatar xuxin

页面打开慢加日志

parent 2301d3f9
...@@ -393,10 +393,13 @@ public class ShopServiceImpl implements ShopService { ...@@ -393,10 +393,13 @@ public class ShopServiceImpl implements ShopService {
@Override @Override
public ShopPageResultDto getShopList(String username, String groupId, int pageNum, int amount, ShopFilterDto shopFilterDto, String tag) { public ShopPageResultDto getShopList(String username, String groupId, int pageNum, int amount, ShopFilterDto shopFilterDto, String tag) {
long start = System.currentTimeMillis();
// 1. 校验当前登录用户的账户是否存在 // 1. 校验当前登录用户的账户是否存在
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST)); Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
logger.info("getshoplist step-1:{}", System.currentTimeMillis() - start);
// 2. 如有有分组校验当前查询的分组信息是否正确 // 2. 如有有分组校验当前查询的分组信息是否正确
start = System.currentTimeMillis();
Group group = null; Group group = null;
if (groupId != null) { if (groupId != null) {
group = groupRepository.findById(groupId).orElseThrow(() -> new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST)); group = groupRepository.findById(groupId).orElseThrow(() -> new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST));
...@@ -404,10 +407,11 @@ public class ShopServiceImpl implements ShopService { ...@@ -404,10 +407,11 @@ public class ShopServiceImpl implements ShopService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} }
} }
logger.info("getshoplist step-2:{}", System.currentTimeMillis() - start);
// 3. 根据 groupId 与 username 来查询 shopIds (如果当前用户是父账户,则查询结果包含子账户的shopId) // 3. 根据 groupId 与 username 来查询 shopIds (如果当前用户是父账户,则查询结果包含子账户的shopId)
start = System.currentTimeMillis();
List<String> allIds = null; List<String> allIds = null;
if (!"penghai".equals(tag)) { if (!"penghai".equals(tag)) {
if ("-1".equals(groupId)) { if ("-1".equals(groupId)) {
allIds = userShopRepository.findByUsername(username).stream().map(UserShop::getShopId).collect(Collectors.toList()); allIds = userShopRepository.findByUsername(username).stream().map(UserShop::getShopId).collect(Collectors.toList());
...@@ -421,8 +425,10 @@ public class ShopServiceImpl implements ShopService { ...@@ -421,8 +425,10 @@ public class ShopServiceImpl implements ShopService {
if ("penghai".equals(tag)) { if ("penghai".equals(tag)) {
allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().map(UserShop::getShopId).collect(Collectors.toList()); allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().map(UserShop::getShopId).collect(Collectors.toList());
} }
logger.info("getshoplist step-3:{}", System.currentTimeMillis() - start);
// 4. 根据传入的过滤条件得到 shopIds // 4. 根据传入的过滤条件得到 shopIds
start = System.currentTimeMillis();
List<String> shopIds = null; List<String> shopIds = null;
if (shopFilterDto.getBindIp() == 0) { if (shopFilterDto.getBindIp() == 0) {
shopIds = allIds; shopIds = allIds;
...@@ -450,19 +456,24 @@ public class ShopServiceImpl implements ShopService { ...@@ -450,19 +456,24 @@ public class ShopServiceImpl implements ShopService {
allIds.removeAll(shopIds2); allIds.removeAll(shopIds2);
shopIds = allIds; shopIds = allIds;
} }
logger.info("getshoplist step-4:{}", System.currentTimeMillis() - start);
amount = amount > 100 ? 100 : amount; amount = amount > 100 ? 100 : amount;
Pageable pageable = PageRequest.of(pageNum, amount); Pageable pageable = PageRequest.of(pageNum, amount);
// 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页 // 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页
start = System.currentTimeMillis();
Page<Shop> shops = getShopsByFilter(shopFilterDto, shopIds, pageable); Page<Shop> shops = getShopsByFilter(shopFilterDto, shopIds, pageable);
logger.info("getshoplist step-5:{}", System.currentTimeMillis() - start);
// 6. 封装 shopResultDtos 信息并返回 // 6. 封装 shopResultDtos 信息并返回
start = System.currentTimeMillis();
ShopPageResultDto<ShopResultDto> shopPageResultDto = new ShopPageResultDto<>(); ShopPageResultDto<ShopResultDto> shopPageResultDto = new ShopPageResultDto<>();
if (shops != null && shops.getNumberOfElements() >= 1) { if (shops != null && shops.getNumberOfElements() >= 1) {
List<ShopResultDto> shopResultDtos = new ArrayList<>(); List<ShopResultDto> shopResultDtos = new ArrayList<>();
shops.getContent().stream().forEach( shops.getContent().stream().forEach(
// 设置ip资源状态 并 封装 shopResultDto信息 // 设置ip资源状态 并 封装 shopResultDto信息
x -> { x -> {
long start1 = System.currentTimeMillis();
IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(x.getShopId(), false); IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(x.getShopId(), false);
// 如果 ip资源非空 且 addr 也非空 // 如果 ip资源非空 且 addr 也非空
if (ipResource != null && !StringUtils.isEmpty(ipResource.getAddr())) { if (ipResource != null && !StringUtils.isEmpty(ipResource.getAddr())) {
...@@ -513,6 +524,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -513,6 +524,7 @@ public class ShopServiceImpl implements ShopService {
ShopResultDto shopResultDto = getShopResultDto(username, x, ipResource); ShopResultDto shopResultDto = getShopResultDto(username, x, ipResource);
shopResultDtos.add(shopResultDto); shopResultDtos.add(shopResultDto);
logger.info("getshoplist step-6.x:{}", System.currentTimeMillis() - start1);
} }
); );
...@@ -521,7 +533,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -521,7 +533,7 @@ public class ShopServiceImpl implements ShopService {
PageInfo pageInfo = new PageInfo(shopDtoPage.getPageable().getPageNumber(), shopDtoPage.getTotalPages(), shopIds.size()); PageInfo pageInfo = new PageInfo(shopDtoPage.getPageable().getPageNumber(), shopDtoPage.getTotalPages(), shopIds.size());
shopPageResultDto.setShopPage(pageInfo); shopPageResultDto.setShopPage(pageInfo);
} }
logger.info("getshoplist step-6:{}", System.currentTimeMillis() - start);
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