Commit d149c51e authored by xuxin's avatar xuxin

Merge remote-tracking branch 'origin/staging' into staging

parents 0a169770 e01ba82d
...@@ -67,12 +67,12 @@ public class ShopServiceImpl implements ShopService { ...@@ -67,12 +67,12 @@ public class ShopServiceImpl implements ShopService {
} }
if (shopResultDto.getGroup() != null) { if (shopResultDto.getGroup() != null) {
Group group = groupRepository.findById(shopResultDto.getGroup()) Group group = groupRepository.findById(shopResultDto.getGroup())
.orElseThrow(() -> new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST)); .orElseThrow(() -> new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST));
} }
// 2. 对当前用户的 account 信息进行校验 // 2. 对当前用户的 account 信息进行校验
Account account = accountRepository.findByName(username) Account account = accountRepository.findByName(username)
.orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST)); .orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account.getPermission() < 4) { if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} }
...@@ -100,7 +100,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -100,7 +100,7 @@ public class ShopServiceImpl implements ShopService {
userShopRepository.save(userShop1); userShopRepository.save(userShop1);
Account parentAccount = accountRepository.findByName(account.getParent()) Account parentAccount = accountRepository.findByName(account.getParent())
.orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST)); .orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
account.setShopCount(parentAccount.getShopCount() + 1); account.setShopCount(parentAccount.getShopCount() + 1);
accountRepository.save(parentAccount); accountRepository.save(parentAccount);
} }
...@@ -159,7 +159,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -159,7 +159,7 @@ public class ShopServiceImpl implements ShopService {
userShopRepository.save(userShop1); userShopRepository.save(userShop1);
Account parentAccount = accountRepository.findByName(account.getParent()) Account parentAccount = accountRepository.findByName(account.getParent())
.orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST)); .orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
account.setShopCount(parentAccount.getShopCount() + 1); account.setShopCount(parentAccount.getShopCount() + 1);
accountRepository.save(parentAccount); accountRepository.save(parentAccount);
} }
...@@ -169,7 +169,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -169,7 +169,7 @@ public class ShopServiceImpl implements ShopService {
ids.add(id); ids.add(id);
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to add shops", e.getMessage()); logger.error("fail to add shops", e);
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE); throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
} }
} }
...@@ -201,7 +201,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -201,7 +201,7 @@ public class ShopServiceImpl implements ShopService {
// 4. 更新店铺信息 // 4. 更新店铺信息
shopRepository.save(shop_old); shopRepository.save(shop_old);
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to update", e.getMessage()); logger.error("fail to update", e);
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE); throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
} }
return shop_old.getShopId(); return shop_old.getShopId();
...@@ -276,7 +276,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -276,7 +276,7 @@ public class ShopServiceImpl implements ShopService {
userShop.setGroupId(groupId); userShop.setGroupId(groupId);
userShopRepository.save(userShop); userShopRepository.save(userShop);
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to unbind", e.getMessage()); logger.error("fail to unbind", e);
throw new ClientRequestException(BrowserErrorCode.UNKNOWN); throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
} }
...@@ -344,7 +344,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -344,7 +344,7 @@ public class ShopServiceImpl implements ShopService {
); );
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to assign", e.getMessage()); logger.error("fail to assign", e);
throw new ClientRequestException(BrowserErrorCode.UNKNOWN); throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
} }
} }
...@@ -396,15 +396,15 @@ public class ShopServiceImpl implements ShopService { ...@@ -396,15 +396,15 @@ public class ShopServiceImpl implements ShopService {
List<String> allIds = null; List<String> allIds = null;
if ("-1".equals(groupId)) { if ("-1".equals(groupId)) {
allIds = userShopRepository.findByUsername(username).stream() allIds = userShopRepository.findByUsername(username).stream()
.map(UserShop::getShopId).collect(Collectors.toList()); .map(UserShop::getShopId).collect(Collectors.toList());
// 如果分组 // 如果分组
} else { } else {
allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream() allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream()
.map(UserShop::getShopId).collect(Collectors.toList()); .map(UserShop::getShopId).collect(Collectors.toList());
} }
// 4. 根据传入的过滤条件得到 shopIds // 4. 根据传入的过滤条件得到 shopIds
List<String> shopIds = null; List<String> shopIds = new ArrayList<>();
if (shopFilterDto.getBindIp() == 0) { if (shopFilterDto.getBindIp() == 0) {
shopIds = allIds; shopIds = allIds;
...@@ -412,7 +412,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -412,7 +412,7 @@ public class ShopServiceImpl implements ShopService {
} else if (shopFilterDto.getBindIp() == 1) { } else if (shopFilterDto.getBindIp() == 1) {
// ip资源已经分配了 的店铺 // ip资源已经分配了 的店铺
shopIds = ipResourceRepository.findShopIdInList(allIds, false).stream() shopIds = ipResourceRepository.findShopIdInList(allIds, false).stream()
.flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList()); .flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList());
// 这个地方的其他情况是指什么情况 // 这个地方的其他情况是指什么情况
} else { } else {
...@@ -425,7 +425,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -425,7 +425,7 @@ public class ShopServiceImpl implements ShopService {
} }
} }
amount = amount > 100 ? 100 : amount; amount = Math.min(amount, 100);
Pageable pageable = PageRequest.of(pageNum, amount); Pageable pageable = PageRequest.of(pageNum, amount);
// 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页 // 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页
Page<Shop> shops = getShopsByFilter(shopFilterDto, shopIds, pageable); Page<Shop> shops = getShopsByFilter(shopFilterDto, shopIds, pageable);
...@@ -434,7 +434,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -434,7 +434,7 @@ public class ShopServiceImpl implements ShopService {
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().forEach(
// 设置ip资源状态 并 封装 shopResultDto信息 // 设置ip资源状态 并 封装 shopResultDto信息
x -> { x -> {
IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(x.getShopId(), false); IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(x.getShopId(), false);
...@@ -506,7 +506,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -506,7 +506,7 @@ public class ShopServiceImpl implements ShopService {
ShopSummary shopSummary = new ShopSummary(); ShopSummary shopSummary = new ShopSummary();
List<String> allShopIds = userShopRepository.findByUsername(username).stream() List<String> allShopIds = userShopRepository.findByUsername(username).stream()
.map(UserShop::getShopId).collect(Collectors.toList()); .map(UserShop::getShopId).collect(Collectors.toList());
List<String> unbind = new ArrayList<>(); List<String> unbind = new ArrayList<>();
if (!allShopIds.isEmpty()) { if (!allShopIds.isEmpty()) {
for (String id : allShopIds) { for (String id : allShopIds) {
...@@ -519,9 +519,9 @@ public class ShopServiceImpl implements ShopService { ...@@ -519,9 +519,9 @@ public class ShopServiceImpl implements ShopService {
shopSummary.setUnbind(unbind.size()); shopSummary.setUnbind(unbind.size());
List<String> shopIds = userShopRepository.findByUsername(username).stream() List<String> shopIds = userShopRepository.findByUsername(username).stream()
.map(UserShop::getShopId).collect(Collectors.toList()); .map(UserShop::getShopId).collect(Collectors.toList());
List<String> bind = ipResourceRepository.findShopIdInList(shopIds, false).stream() List<String> bind = ipResourceRepository.findShopIdInList(shopIds, false).stream()
.map(IpResource::getId).collect(Collectors.toList()); .map(IpResource::getId).collect(Collectors.toList());
int expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, bind, false); int expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, bind, false);
int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false); int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false);
shopSummary.setExpired(expired); shopSummary.setExpired(expired);
...@@ -539,9 +539,9 @@ public class ShopServiceImpl implements ShopService { ...@@ -539,9 +539,9 @@ public class ShopServiceImpl implements ShopService {
// 获取当前登录用户绑定了当前商铺的 所有子用户名 // 获取当前登录用户绑定了当前商铺的 所有子用户名
List<String> shopUsers = userShopRepository.findByShopId(shopId).stream() List<String> shopUsers = userShopRepository.findByShopId(shopId).stream()
.map(x -> x.getUsername()) .map(UserShop::getUsername)
.filter(x -> !x.equals(username)) .filter(x -> !x.equals(username))
.collect(Collectors.toList()); .collect(Collectors.toList());
return shopUsers; return shopUsers;
} }
...@@ -567,7 +567,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -567,7 +567,7 @@ public class ShopServiceImpl implements ShopService {
return shopUsers; return shopUsers;
} }
List<String> users = userShopRepository.findByShopId(maxShopId).stream().map(x -> x.getUsername()).filter(x -> !x.equals(username)).collect(Collectors.toList()); List<String> users = userShopRepository.findByShopId(maxShopId).stream().map(UserShop::getUsername).filter(x -> !x.equals(username)).collect(Collectors.toList());
for (String user : users) { for (String user : users) {
int shopCount = userShopRepository.countByUsernameAndShopIdIn(user, shopIds); int shopCount = userShopRepository.countByUsernameAndShopIdIn(user, shopIds);
if (shopCount < shopIds.size()) { if (shopCount < shopIds.size()) {
...@@ -602,21 +602,19 @@ public class ShopServiceImpl implements ShopService { ...@@ -602,21 +602,19 @@ public class ShopServiceImpl implements ShopService {
} }
} }
Integer result = 0; int result = 0;
Iterator<Map.Entry<Account, List<Account>>> entries = map.entrySet().iterator(); for (Map.Entry<Account, List<Account>> entry : map.entrySet()) {
while (entries.hasNext()) {
Map.Entry<Account, List<Account>> entry = entries.next();
List<Account> children = entry.getValue(); List<Account> children = entry.getValue();
// 查找子类所拥有的店铺 // 查找子类所拥有的店铺
List<Shop> childrenShop = shopRepository.findByOwnerIn(children.stream().map(Account::getName).collect(Collectors.toList())); List<Shop> childrenShop = shopRepository.findByOwnerIn(children.stream().map(Account::getName).collect(Collectors.toList()));
if (childrenShop.size() == 0) { if (childrenShop.size() == 0) {
continue; continue;
} }
List<String> ids = childrenShop.stream().map(x -> x.getShopId()).collect(Collectors.toList()); List<String> ids = childrenShop.stream().map(Shop::getShopId).collect(Collectors.toList());
// 查出来 父账户已有的 usershop信息 // 查出来 父账户已有的 usershop信息
List<UserShop> parentUserShops = userShopRepository.findByUsernameAndShopIdIn(entry.getKey().getName(), ids); List<UserShop> parentUserShops = userShopRepository.findByUsernameAndShopIdIn(entry.getKey().getName(), ids);
List<String> parentShopIds = parentUserShops.stream().map(x -> x.getShopId()).collect(Collectors.toList()); List<String> parentShopIds = parentUserShops.stream().map(UserShop::getShopId).collect(Collectors.toList());
// 剩下的就是 父账户的 usershop 缺失的信息 // 剩下的就是 父账户的 usershop 缺失的信息
ids.removeAll(parentShopIds); ids.removeAll(parentShopIds);
...@@ -656,7 +654,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -656,7 +654,7 @@ public class ShopServiceImpl implements ShopService {
Page<Shop> shops = null; Page<Shop> shops = null;
if (!StringUtils.isEmpty(shopFilterDto.getIpRegion())) { if (!StringUtils.isEmpty(shopFilterDto.getIpRegion())) {
List<String> filter = ipResourceRepository.findShopIdInListAndRegionLike(shopIds, false, shopFilterDto.getIpRegion()) List<String> filter = ipResourceRepository.findShopIdInListAndRegionLike(shopIds, false, shopFilterDto.getIpRegion())
.stream().flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList()); .stream().flatMap((x -> x.getShopIds().stream())).collect(Collectors.toList());
shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(filter, pageable); shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(filter, pageable);
} }
if (!StringUtils.isEmpty(shopFilterDto.getShopAccount())) { if (!StringUtils.isEmpty(shopFilterDto.getShopAccount())) {
......
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