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

根据用户ID查询租户列表

parent 1a4152fa
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 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.RestController;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/tenant")
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;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Li Jianhua
......@@ -17,4 +19,6 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit
ProductLoginEntity findFirstByPhoneNo(String phoneNo);
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;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/**
* Created by Miraculous on 2017/1/3.
......@@ -8,4 +11,6 @@ import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
public interface IOauthClientDetailsService {
OauthClientDetailsEntity findFirstByClientId(Integer clientId);
List<Integer> findTenantList(List<ProductLoginEntity> productLoginEntityList);
}
......@@ -2,9 +2,12 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
public interface IProductLoginService {
ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findSlaveByUserId(Long userId);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
......@@ -23,5 +27,17 @@ public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
......@@ -24,4 +26,11 @@ public class ProductLoginServiceImpl implements IProductLoginService {
ProductLoginEntity productLogin = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId);
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