Commit 83c6d537 authored by renjie's avatar renjie

shopusers

parent 6cae06fb
...@@ -196,4 +196,21 @@ public class ShopController { ...@@ -196,4 +196,21 @@ public class ShopController {
} }
return resultDto; return resultDto;
} }
@RequestMapping(value = "/subusers", method = RequestMethod.POST)
public ResultDto getShopSubUsers(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
List<String> subUsers = shopService.getShopUsers(principal.getName(), shopRequestDto.getShopId());
resultDto.setData(subUsers);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
} }
...@@ -262,6 +262,10 @@ public class ShopServiceImpl implements ShopService { ...@@ -262,6 +262,10 @@ public class ShopServiceImpl implements ShopService {
List<Account> accounts = accountRepository.findByNameIn(users); List<Account> accounts = accountRepository.findByNameIn(users);
if (accounts == null || accounts.size() != users.size()) if (accounts == null || accounts.size() != users.size())
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
for (Account ac : accounts) {
if (ac.getParent() == null)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
shops.stream().forEach(shop -> { shops.stream().forEach(shop -> {
try { try {
userShopRepository.deleteByShopIdExceptOwner(shop.getShopId(), shop.getOwner()); userShopRepository.deleteByShopIdExceptOwner(shop.getShopId(), shop.getOwner());
...@@ -269,6 +273,8 @@ public class ShopServiceImpl implements ShopService { ...@@ -269,6 +273,8 @@ public class ShopServiceImpl implements ShopService {
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId()); UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId());
if (userShop1 != null) if (userShop1 != null)
return; return;
userShop1 = new UserShop(account1.getName(), shop.getShopId(), "-1");
userShopRepository.save(userShop1);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to assign", e.getMessage()); logger.error("fail to assign", e.getMessage());
...@@ -393,4 +399,15 @@ public class ShopServiceImpl implements ShopService { ...@@ -393,4 +399,15 @@ public class ShopServiceImpl implements ShopService {
shopSummary.setTotal(userShopRepository.countByUsername(username)); shopSummary.setTotal(userShopRepository.countByUsername(username));
return shopSummary; return shopSummary;
} }
@Override
public List<String> getShopUsers(String username, String shopId) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getParent() != null)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
List<String> shopUsers = userShopRepository.findByShopId(shopId).stream().map(x -> x.getUsername()).filter(x -> x!=username).collect(Collectors.toList());
return shopUsers;
}
} }
...@@ -28,4 +28,6 @@ public interface ShopService { ...@@ -28,4 +28,6 @@ public interface ShopService {
ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto); ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto);
ShopSummary getShopSummary(String username); ShopSummary getShopSummary(String username);
List<String> getShopUsers(String username, String shopId);
} }
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