跨服务调用

master
shijie 4 years ago
parent 9ed590b83e
commit 3f57da32ad
  1. 70
      dq-financial-crms/src/main/resources/bootstrap.properties
  2. 14
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java
  3. 20
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java
  4. 8
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrmsFeignService.java
  5. 5
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/SecurityUser.java
  6. 3
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java
  7. 24
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java
  8. 22
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java
  9. 2
      dq-financial-hrms-auth/src/main/resources/mapper/hrauth/AuthEmployeeRoleDao.xml
  10. 80
      dq-financial-hrms/src/main/resources/bootstrap.properties
  11. 3
      dq-govern-gateway/src/main/resources/jwt.properties

@ -1,39 +1,59 @@
# 开发和测试环境(dev)
#服务名称
spring.application.name=dq-financial-crms
#配置中心地址
spring.cloud.nacos.config.server-addr=192.168.31.142:8848
spring.cloud.nacos.config.namespace=1f69d47e-0aeb-4a1e-8ab4-0e84dfb86354
#spring.cloud.nacos.config.group=prod
spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
spring.cloud.nacos.config.ext-config[0].group=dev
spring.cloud.nacos.config.ext-config[0].refresh=true
spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
spring.cloud.nacos.config.ext-config[1].group=dev
spring.cloud.nacos.config.ext-config[1].refresh=true
spring.cloud.nacos.config.ext-config[2].data-id=other.yml
spring.cloud.nacos.config.ext-config[2].group=dev
spring.cloud.nacos.config.ext-config[2].refresh=true
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123456
spring.redis.database=0
spring.redis.timeout=30000
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-wait=-1
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.min-idle=0
# 正式环境(prod)
#服务名称
#spring.application.name=dq-financial-crms
##配置中心地址
#spring.cloud.nacos.config.server-addr=192.168.31.142:8848
#spring.cloud.nacos.config.namespace=1f69d47e-0aeb-4a1e-8ab4-0e84dfb86354
#spring.cloud.nacos.config.server-addr=120.78.127.12:8848
#spring.cloud.nacos.config.namespace=25ce05e2-a0eb-4842-92e4-d8b550a489dd
##spring.cloud.nacos.config.group=prod
#
#spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
#spring.cloud.nacos.config.ext-config[0].group=dev
#spring.cloud.nacos.config.ext-config[0].group=prod
#spring.cloud.nacos.config.ext-config[0].refresh=true
#
#spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
#spring.cloud.nacos.config.ext-config[1].group=dev
#spring.cloud.nacos.config.ext-config[1].group=prod
#spring.cloud.nacos.config.ext-config[1].refresh=true
#
#spring.cloud.nacos.config.ext-config[2].data-id=other.yml
#spring.cloud.nacos.config.ext-config[2].group=dev
#spring.cloud.nacos.config.ext-config[2].group=prod
#spring.cloud.nacos.config.ext-config[2].refresh=true
# 正式环境(prod)
#服务名称
spring.application.name=dq-financial-crms
#配置中心地址
spring.cloud.nacos.config.server-addr=120.78.127.12:8848
spring.cloud.nacos.config.namespace=25ce05e2-a0eb-4842-92e4-d8b550a489dd
#spring.cloud.nacos.config.group=prod
spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
spring.cloud.nacos.config.ext-config[0].group=prod
spring.cloud.nacos.config.ext-config[0].refresh=true
spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
spring.cloud.nacos.config.ext-config[1].group=prod
spring.cloud.nacos.config.ext-config[1].refresh=true
spring.cloud.nacos.config.ext-config[2].data-id=other.yml
spring.cloud.nacos.config.ext-config[2].group=prod
spring.cloud.nacos.config.ext-config[2].refresh=true
#
#spring.redis.host=127.0.0.1
#spring.redis.port=6379
#spring.redis.password=dq123456
#spring.redis.database=0
#spring.redis.timeout=30000
#spring.redis.jedis.pool.max-active=8
#spring.redis.jedis.pool.max-wait=-1
#spring.redis.jedis.pool.max-idle=8
#spring.redis.jedis.pool.min-idle=0

@ -2,6 +2,7 @@ package com.daqing.financial.hrauth.controller;
import com.daqing.financial.hrauth.service.RolePermissionService;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.domain.hrms.request.RolePermissionRequest;
import com.daqing.framework.domain.hrms.response.HrmsCode;
@ -156,5 +157,18 @@ public class RolePermissionController {
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
}
/**
* 根据用户Id查询角色信息
* @param userId
* @return
*/
@Transactional
@GetMapping("/getUserRoles")
public ResponseResult getUserRoles(@RequestParam("userId")Integer userId) {
List<RoleEntity> roleList = permissionService.getUserRoles(userId);
return new ResponseResult<List<RoleEntity>>().SUCCESS(roleList);
}
}

@ -0,0 +1,20 @@
package com.daqing.financial.hrauth.feign;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.model.response.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* 这是一个声明式的远程调用
*/
@FeignClient("dq-financial-hrms-auth")
public interface HrauthFeignService {
@GetMapping("/hrms/auth/permission/getUserRoles")
ResponseResult<List<RoleEntity>> getUserRoles(@RequestParam("userId")Integer userId);
}

@ -1,8 +0,0 @@
package com.daqing.financial.hrauth.feign;
/**
* @auther River
* @date 2020/10/22 14:04
*/
public class HrmsFeignService {
}

@ -1,5 +1,7 @@
package com.daqing.financial.hrauth.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.UserEntity;
import lombok.Data;
@ -56,11 +58,12 @@ public class SecurityUser implements UserDetails {
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> authorities = new ArrayList<>();
if (!CollectionUtils.isEmpty(this.roleList)) {
for (RoleEntity role : this.roleList) {
for (Object role : this.roleList) {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("user_role");
authorities.add(authority);
}
}
// SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ADMIN");
// authorities.add(authority);
return authorities;

@ -2,6 +2,7 @@ package com.daqing.financial.hrauth.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.domain.hrms.request.RolePermissionRequest;
import com.daqing.framework.domain.hrms.response.RolePermissionResponse;
@ -39,5 +40,7 @@ public interface RolePermissionService extends IService<RolePermissionEntity> {
int uniqueRoleName(String name);
List<RolePermissionEntity> queryPermissionArrById(Long roleId);
List<RoleEntity> getUserRoles(Integer userId);
}

@ -1,11 +1,17 @@
package com.daqing.financial.hrauth.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daqing.financial.hrauth.dao.AuthEmployeeRoleDao;
import com.daqing.financial.hrauth.dao.AuthRoleDao;
import com.daqing.financial.hrauth.dao.RolePermissionMapper;
import com.daqing.financial.hrauth.dao.UserLoginDao;
import com.daqing.financial.hrauth.service.RolePermissionService;
import com.daqing.framework.domain.hrms.EmployeeRoleEntity;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.domain.hrms.request.RolePermissionRequest;
import com.daqing.framework.domain.hrms.response.RolePermissionResponse;
@ -13,7 +19,9 @@ import com.daqing.framework.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@ -21,6 +29,11 @@ import java.util.stream.Collectors;
@Service("rolePermissionService")
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermissionEntity> implements RolePermissionService {
@Resource
private AuthRoleDao roleMapper;
@Resource
private AuthEmployeeRoleDao userRoleMapper;
@Override
public List<PermissionEntity> listWithTree() {
List<PermissionEntity>list = this.getBaseMapper().queryPermissionTree();
@ -108,4 +121,15 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
return this.getBaseMapper().queryPermissionArrById(roleId);
}
@Override
public List<RoleEntity> getUserRoles(Integer userId) {
List<EmployeeRoleEntity> userRoles = userRoleMapper.selectList(new QueryWrapper<EmployeeRoleEntity>().eq("user_id", userId));
List<RoleEntity> roleList = new LinkedList<>();
for (EmployeeRoleEntity userRole : userRoles) {
RoleEntity role = roleMapper.selectById(userRole.getRoleId());
roleList.add(role);
}
return roleList;
}
}

@ -5,11 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daqing.financial.hrauth.dao.AuthEmployeeRoleDao;
import com.daqing.financial.hrauth.dao.AuthRoleDao;
import com.daqing.financial.hrauth.dao.UserLoginDao;
import com.daqing.financial.hrauth.feign.HrauthFeignService;
import com.daqing.financial.hrauth.handle.SecurityUser;
import com.daqing.framework.domain.hrms.EmployeeRoleEntity;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.ext.EmployeeTO;
import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@ -31,6 +35,7 @@ import java.util.List;
* @description :
* @date : 2019/10/14 17:46
*/
@Slf4j
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
@ -40,6 +45,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private AuthRoleDao roleMapper;
@Resource
private AuthEmployeeRoleDao userRoleMapper;
@Autowired
private HrauthFeignService hrauthFeignService;
/***
* 根据账号获取用户信息
@ -91,12 +98,15 @@ public class UserDetailsServiceImpl implements UserDetailsService {
* @return
*/
private List<RoleEntity> getUserRoles(Integer userId) {
List<EmployeeRoleEntity> userRoles = userRoleMapper.selectList(new QueryWrapper<EmployeeRoleEntity>().eq("user_id", userId));
List<RoleEntity> roleList = new LinkedList<>();
for (EmployeeRoleEntity userRole : userRoles) {
RoleEntity role = roleMapper.selectById(userRole.getRoleId());
roleList.add(role);
}
// List<EmployeeRoleEntity> userRoles = userRoleMapper.selectList(new QueryWrapper<EmployeeRoleEntity>().eq("user_id", userId));
// List<RoleEntity> roleList = new LinkedList<>();
// for (EmployeeRoleEntity userRole : userRoles) {
// RoleEntity role = roleMapper.selectById(userRole.getRoleId());
// roleList.add(role);
// }
log.info("来了调用远程接口~~~~~~~~~~~~~~~~~~~~~~~~~~");
ResponseResult responseResult = hrauthFeignService.getUserRoles(userId);
List<RoleEntity> roleList = (List<RoleEntity>) responseResult.getData();
return roleList;
}

@ -4,7 +4,7 @@
<mapper namespace="com.daqing.financial.hrauth.dao.AuthEmployeeRoleDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.EmployeeRoleEntity" id="employeeRoleMap">
<resultMap type="com.daqing.framework.domain.hrms.EmployeeRoleEntity" id="authEmployeeRoleMap">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="roleId" column="role_id"/>

@ -1,61 +1,61 @@
##服务名称
#spring.application.name=dq-financial-hrms
##配置中心地址
#spring.cloud.nacos.config.server-addr=192.168.31.142:8848
#spring.cloud.nacos.config.namespace=4c56c2f9-b6a3-4e7b-88b8-b1001e86dfd6
##spring.cloud.nacos.config.group=prod
#
#spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
#spring.cloud.nacos.config.ext-config[0].group=dev
#spring.cloud.nacos.config.ext-config[0].refresh=true
#
#spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
#spring.cloud.nacos.config.ext-config[1].group=dev
#spring.cloud.nacos.config.ext-config[1].refresh=true
#
#spring.cloud.nacos.config.ext-config[2].data-id=other.yml
#spring.cloud.nacos.config.ext-config[2].group=dev
#spring.cloud.nacos.config.ext-config[2].refresh=true
#
#spring.redis.host=127.0.0.1
#spring.redis.port=6379
#spring.redis.password=123456
#spring.redis.database=0
#spring.redis.timeout=30000
#spring.redis.jedis.pool.max-active=8
#spring.redis.jedis.pool.max-wait=-1
#spring.redis.jedis.pool.max-idle=8
#spring.redis.jedis.pool.min-idle=0
#
#spring.servlet.multipart.max-file-size=10MB
#spring.servlet.multipart.max-request-size=10MB
# 正式环境(prod)
#服务名称
spring.application.name=dq-financial-hrms
#配置中心地址
spring.cloud.nacos.config.server-addr=120.78.127.12:8848
spring.cloud.nacos.config.namespace=69614b55-1521-421c-ac58-dbe4a5b01b43
spring.cloud.nacos.config.server-addr=192.168.31.142:8848
spring.cloud.nacos.config.namespace=4c56c2f9-b6a3-4e7b-88b8-b1001e86dfd6
#spring.cloud.nacos.config.group=prod
spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
spring.cloud.nacos.config.ext-config[0].group=prod
spring.cloud.nacos.config.ext-config[0].group=dev
spring.cloud.nacos.config.ext-config[0].refresh=true
spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
spring.cloud.nacos.config.ext-config[1].group=prod
spring.cloud.nacos.config.ext-config[1].group=dev
spring.cloud.nacos.config.ext-config[1].refresh=true
spring.cloud.nacos.config.ext-config[2].data-id=other.yml
spring.cloud.nacos.config.ext-config[2].group=prod
spring.cloud.nacos.config.ext-config[2].group=dev
spring.cloud.nacos.config.ext-config[2].refresh=true
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=dq123456
spring.redis.password=123456
spring.redis.database=0
spring.redis.timeout=30000
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-wait=-1
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.min-idle=0
spring.redis.jedis.pool.min-idle=0
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
# 正式环境(prod)
#服务名称
#spring.application.name=dq-financial-hrms
##配置中心地址
#spring.cloud.nacos.config.server-addr=120.78.127.12:8848
#spring.cloud.nacos.config.namespace=69614b55-1521-421c-ac58-dbe4a5b01b43
##spring.cloud.nacos.config.group=prod
#
#spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
#spring.cloud.nacos.config.ext-config[0].group=prod
#spring.cloud.nacos.config.ext-config[0].refresh=true
#
#spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
#spring.cloud.nacos.config.ext-config[1].group=prod
#spring.cloud.nacos.config.ext-config[1].refresh=true
#
#spring.cloud.nacos.config.ext-config[2].data-id=other.yml
#spring.cloud.nacos.config.ext-config[2].group=prod
#spring.cloud.nacos.config.ext-config[2].refresh=true
#
#spring.redis.host=127.0.0.1
#spring.redis.port=6379
#spring.redis.password=dq123456
#spring.redis.database=0
#spring.redis.timeout=30000
#spring.redis.jedis.pool.max-active=8
#spring.redis.jedis.pool.max-wait=-1
#spring.redis.jedis.pool.max-idle=8
#spring.redis.jedis.pool.min-idle=0

@ -3,9 +3,6 @@ jwt.ignoreUrlList=/apiHrmsAuth/hrms/auth/userlogin/getBackPwd,\
/apiHrmsAuth/hrms/auth/userlogin/verifyMobile,\
/apiHrmsAuth/hrms/auth/userlogin/wxLoginUrl,\
/apiHrmsAuth/hrms/auth/userlogin/user/callback,\
/apiHrmsAuth/hrms/auth/userlogin/wxLoginUrl,\
/api-hrms/hrms/user/callbackBinding,\
/api-hrms/hrms/user/callback,\
/api-crms/sweagger-ui.html,\
/api-crms/crms/customer/excelTemplate,\
/api-crms/crms/customer/excelExport,\

Loading…
Cancel
Save