Commit b5ee5643 authored by 李健华's avatar 李健华

根据用户ID查询租户列表

parent 1a4152fa
package cn.quantgroup.xyqb.controller.tenant; package cn.quantgroup.xyqb.controller.tenant;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/tenant") @RequestMapping("/tenant")
public class TenantController { public class TenantController {
@Autowired
private IProductLoginService productLoginService;
@Autowired
private IOauthClientDetailsService oauthClientDetailsService;
/**
* 根据用户ID查询租户列表
* @param userId
* @return
*/
@PostMapping("/userIdTenantList")
public JsonResult findTenantByUserId(Long userId) {
// 通过userId获取租户机构和产品
List<ProductLoginEntity> productLoginEntityList = productLoginService.findSlaveByUserId(userId);
if (productLoginEntityList.isEmpty()) {
return JsonResult.buildErrorStateResult("该用户不存在", null);
}
// 通过机构和产品Id 获取租户id
List<Integer> tenantList = oauthClientDetailsService.findTenantList(productLoginEntityList);
return JsonResult.buildSuccessResult("租户列表", tenantList);
}
} }
...@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.entity.ProductLoginEntity; ...@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* Li Jianhua * Li Jianhua
...@@ -17,4 +19,6 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit ...@@ -17,4 +19,6 @@ 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> findAllByExtensionAccountId(Long userId);
} }
\ No newline at end of file
package cn.quantgroup.xyqb.service.user; package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity; import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/** /**
* Created by Miraculous on 2017/1/3. * Created by Miraculous on 2017/1/3.
...@@ -8,4 +11,6 @@ import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity; ...@@ -8,4 +11,6 @@ import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
public interface IOauthClientDetailsService { public interface IOauthClientDetailsService {
OauthClientDetailsEntity findFirstByClientId(Integer clientId); OauthClientDetailsEntity findFirstByClientId(Integer clientId);
List<Integer> findTenantList(List<ProductLoginEntity> productLoginEntityList);
} }
...@@ -2,9 +2,12 @@ package cn.quantgroup.xyqb.service.user; ...@@ -2,9 +2,12 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.ProductLoginEntity; import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
*/ */
public interface IProductLoginService { public interface IProductLoginService {
ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId); ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findSlaveByUserId(Long userId);
} }
package cn.quantgroup.xyqb.service.user.impl; package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity; import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository; import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService; import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
*/ */
...@@ -22,6 +26,18 @@ public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService ...@@ -22,6 +26,18 @@ public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(clientId); OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(clientId);
return oauthClientDetailsEntity; return oauthClientDetailsEntity;
} }
@Override
public List<Integer> findTenantList(List<ProductLoginEntity> productLoginEntityList) {
List<Integer> tenantList = new ArrayList<>();
for (ProductLoginEntity ple : productLoginEntityList) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsRepository.findFirstByInstitutionIdAndProductId(ple.getInstitutionId(), ple.getProductId());
if (null != oauthClientDetails) {
tenantList.add(oauthClientDetails.getClientId());
}
}
return tenantList;
}
} }
...@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* Created by 11 on 2016/12/29. * Created by 11 on 2016/12/29.
*/ */
...@@ -24,4 +26,11 @@ public class ProductLoginServiceImpl implements IProductLoginService { ...@@ -24,4 +26,11 @@ public class ProductLoginServiceImpl implements IProductLoginService {
ProductLoginEntity productLogin = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId); ProductLoginEntity productLogin = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId);
return productLogin; return productLogin;
} }
@Override
@TargetDataSource(type = DSType.SLAVE)//查询从库
public List<ProductLoginEntity> findSlaveByUserId(Long userId) {
List<ProductLoginEntity> productLoginEntityList = productLoginRepository.findAllByExtensionAccountId(userId);
return productLoginEntityList;
}
} }
This diff is collapsed.
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