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

校验是否羊小咩租户

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