Commit e37ea877 authored by guangjing.gao's avatar guangjing.gao

校验是否羊小咩租户

parent ce324a54
...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.event.DisableActiveEvent; ...@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.event.DisableActiveEvent;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -15,6 +16,7 @@ import java.util.Map; ...@@ -15,6 +16,7 @@ import java.util.Map;
/** /**
* 用户信息 * 用户信息
*/ */
@Slf4j
@RestController("middleUserController") @RestController("middleUserController")
@RequestMapping("/middle_office/user") @RequestMapping("/middle_office/user")
public class UserController { public class UserController {
...@@ -85,10 +87,11 @@ public class UserController { ...@@ -85,10 +87,11 @@ public class UserController {
*/ */
@PostMapping("/getByUuidsOrUserIds") @PostMapping("/getByUuidsOrUserIds")
public JsonResult getByUuidsOrUserIds(@RequestBody Map<String, Object> params) { public JsonResult getByUuidsOrUserIds(@RequestBody Map<String, Object> params) {
log.info("根据uuid或者userids 获取用户信息 {}", params);
List<String> vals = (List<String>) params.get("vals"); List<String> vals = (List<String>) params.get("vals");
Integer type = (Integer) params.get("type"); Integer type = (Integer) params.get("type");
Integer tenantId = Integer.valueOf(String.valueOf(params.get("tenantId"))); Integer tenantId = Integer.valueOf(String.valueOf(params.get("tenantId")));
if (type == null || (type != 1 && type != 2)) { if (type == null || (type != 1 && type != 2)) {
return JsonResult.buildErrorStateResult("type错误", null); return JsonResult.buildErrorStateResult("type错误", null);
} }
......
...@@ -19,8 +19,10 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit ...@@ -19,8 +19,10 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit
ProductLoginEntity findFirstByPhoneNo(String phoneNo); ProductLoginEntity findFirstByPhoneNo(String phoneNo);
ProductLoginEntity findByInstitutionIdAndProductIdAndExtensionAccountId(String institutionId, String productId, Long userId); ProductLoginEntity findByInstitutionIdAndProductIdAndExtensionAccountId(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findByInstitutionIdAndProductIdAndExtensionAccountIdIn(String institutionId, String productId, List<Long> userIds);
List<ProductLoginEntity> findAllByExtensionAccountId(Long userId); List<ProductLoginEntity> findAllByExtensionAccountId(Long userId);
List<ProductLoginEntity> findAllByExtensionAccountIdIn(List<Long> userId);
/** /**
* @author -REYLI * @author -REYLI
......
...@@ -9,7 +9,9 @@ import java.util.List; ...@@ -9,7 +9,9 @@ import java.util.List;
*/ */
public interface IProductLoginService { public interface IProductLoginService {
ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId); ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findSlaveByPloginInfos(String institutionId, String productId, List<Long> userId);
List<ProductLoginEntity> findSlaveByUserId(Long userId); List<ProductLoginEntity> findSlaveByUserId(Long userId);
List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds);
/** /**
* @author -REYLI * @author -REYLI
......
...@@ -27,6 +27,12 @@ public class ProductLoginServiceImpl implements IProductLoginService { ...@@ -27,6 +27,12 @@ public class ProductLoginServiceImpl implements IProductLoginService {
return productLogin; return productLogin;
} }
@Override
public List<ProductLoginEntity> findSlaveByPloginInfos(String institutionId, String productId, List<Long> userIds) {
List<ProductLoginEntity> list = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountIdIn(institutionId, productId, userIds);
return list;
}
@Override @Override
@TargetDataSource(type = DSType.SLAVE)//查询从库 @TargetDataSource(type = DSType.SLAVE)//查询从库
public List<ProductLoginEntity> findSlaveByUserId(Long userId) { public List<ProductLoginEntity> findSlaveByUserId(Long userId) {
...@@ -34,6 +40,12 @@ public class ProductLoginServiceImpl implements IProductLoginService { ...@@ -34,6 +40,12 @@ public class ProductLoginServiceImpl implements IProductLoginService {
return productLoginEntityList; return productLoginEntityList;
} }
@Override
public List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds) {
List<ProductLoginEntity> productLoginEntityList = productLoginRepository.findAllByExtensionAccountIdIn(userIds);
return productLoginEntityList;
}
@Override @Override
public List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId) { public List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId) {
return productLoginRepository.findProductLoginsByInstitutionIdAndProductId(institutionId, productId); return productLoginRepository.findProductLoginsByInstitutionIdAndProductId(institutionId, productId);
......
...@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; ...@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
...@@ -124,18 +125,19 @@ public class TenantServiceImpl implements ITenantService { ...@@ -124,18 +125,19 @@ public class TenantServiceImpl implements ITenantService {
@Override @Override
public List<User> selectUsersByTenantId(List<User> users, Integer tenantId) { public List<User> selectUsersByTenantId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>(); List<User> result = new ArrayList<>();
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId); if (users != null) {
if (oauthClientDetails != null) { OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
List<ProductLoginEntity> productLoginEntities = productLoginService.findProductLoginsByInstitutionIdAndProductId(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId()); if (oauthClientDetails != null) {
if (productLoginEntities != null && productLoginEntities.size()>0) { List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
users.forEach(a->{ List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByPloginInfos(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
productLoginEntities.forEach(b->{ if (productLoginEntities != null && productLoginEntities.size()>0) {
if (a.getPhoneNo().equals(b.getPhoneNo())) { List<String> phoneNos = productLoginEntities.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
a.setPassword(b.getPassword()); users.forEach(a->{
if (phoneNos.contains(a.getPhoneNo())) {
result.add(a); result.add(a);
} }
}); });
}); }
} }
} }
return result; return result;
...@@ -160,17 +162,30 @@ public class TenantServiceImpl implements ITenantService { ...@@ -160,17 +162,30 @@ public class TenantServiceImpl implements ITenantService {
@Override @Override
public List<User> validationTentIdByTentId(List<User> users, Integer tenantId) { public List<User> validationTentIdByTentId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>(); List<User> result = new ArrayList<>();
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId); if (users != null) {
if (oauthClientDetails != null) { List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
List<ProductLoginEntity> productLoginEntities = productLoginService.findProductLoginsByInstitutionIdAndProductId(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId()); OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (productLoginEntities == null || productLoginEntities.size()>0) { if (oauthClientDetails != null) {
List<ProductLoginEntity> slaveByPloginInfos = productLoginService.findSlaveByPloginInfos(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
users.forEach(a->{ users.forEach(a->{
productLoginEntities.forEach(b->{ if (slaveByPloginInfos != null && slaveByPloginInfos.size()>0) {
if (a.getPhoneNo().equals(b.getPhoneNo())) { List<String> phoneNos = slaveByPloginInfos.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
a.setPassword(b.getPassword()); if (phoneNos.contains(a.getPhoneNo())) {
result.add(a); result.add(a);
} }
}); }
});
}
List<ProductLoginEntity> slaveByUserIds = productLoginService.findSlaveByUserIds(userIds);
if (slaveByUserIds != null) {
List<Long> collect = slaveByUserIds.stream().map(ProductLoginEntity::getExtensionAccountId).collect(Collectors.toList());
users.forEach(a->{
if (collect != null) {
if (!collect.contains(a.getId())) {
result.add(a);
}
}
}); });
} }
} }
......
...@@ -21,6 +21,7 @@ import java.util.ArrayList; ...@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* Created by 11 on 2017/3/22. * Created by 11 on 2017/3/22.
...@@ -47,29 +48,38 @@ public class UserCenterServiceImpl implements UserCenterService { ...@@ -47,29 +48,38 @@ public class UserCenterServiceImpl implements UserCenterService {
@Override @Override
public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) { public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) {
List<UserAttached> resultProductUsers = new ArrayList<>();
List<UserAttached> userAttacheds = userAttachedRepository.findByUserIdIn(userIds); List<UserAttached> userAttacheds = userAttachedRepository.findByUserIdIn(userIds);
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) { if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
if (userAttacheds != null) { if (userAttacheds != null) {
//租户ID校验 //租户ID校验
if (!TenantUtil.validationTenantIdIsNullOrZero(tenantId)) { if (!TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
List<UserAttached> resultProductUsers = new ArrayList<>();
List<User> users = userRepository.findByIdIn(userIds); List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers = tenantService.selectUsersByTenantId(users, tenantId); List<User> productUsers = tenantService.selectUsersByTenantId(users, tenantId);
if (productUsers != null) { if (productUsers != null) {
List<Long> collect = productUsers.stream().map(User::getId).collect(Collectors.toList());
userAttacheds.forEach(a->{ userAttacheds.forEach(a->{
productUsers.forEach(b->{ if (collect.contains(a.getUserId())) {
if (a.getUserId().equals(b.getId())) { resultProductUsers.add(a);
resultProductUsers.add(a); }
}
});
}); });
} }
return resultProductUsers; return resultProductUsers;
} }
} }
}else {
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers = tenantService.validationTentIdByTentId(users, tenantId);
if (productUsers != null) {
List<Long> collect = productUsers.stream().map(User::getId).collect(Collectors.toList());
userAttacheds.forEach(a->{
if (collect.contains(a.getUserId())) {
resultProductUsers.add(a);
}
});
}
} }
return userAttacheds; return resultProductUsers;
} }
@Override @Override
......
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