From 3f57da32adc1c0eba4357b751c487859efd642e6 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Mon, 26 Oct 2020 15:51:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E6=9C=8D=E5=8A=A1=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/bootstrap.properties | 70 ++++++++++------ .../controller/RolePermissionController.java | 14 ++++ .../hrauth/feign/HrauthFeignService.java | 20 +++++ .../hrauth/feign/HrmsFeignService.java | 8 -- .../financial/hrauth/handle/SecurityUser.java | 5 +- .../hrauth/service/RolePermissionService.java | 3 + .../impl/RolePermissionServiceImpl.java | 24 ++++++ .../service/impl/UserDetailsServiceImpl.java | 22 +++-- .../mapper/hrauth/AuthEmployeeRoleDao.xml | 2 +- .../src/main/resources/bootstrap.properties | 80 +++++++++---------- .../src/main/resources/jwt.properties | 3 - 11 files changed, 167 insertions(+), 84 deletions(-) create mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java delete mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrmsFeignService.java diff --git a/dq-financial-crms/src/main/resources/bootstrap.properties b/dq-financial-crms/src/main/resources/bootstrap.properties index 7c6afdbc..6cccc927 100644 --- a/dq-financial-crms/src/main/resources/bootstrap.properties +++ b/dq-financial-crms/src/main/resources/bootstrap.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 \ No newline at end of file +# +#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 \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java index ba1a5007..f869fd25 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java @@ -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 roleList = permissionService.getUserRoles(userId); + + return new ResponseResult>().SUCCESS(roleList); + } + } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java new file mode 100644 index 00000000..46c59db4 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java @@ -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> getUserRoles(@RequestParam("userId")Integer userId); +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrmsFeignService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrmsFeignService.java deleted file mode 100644 index 4179700b..00000000 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrmsFeignService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.daqing.financial.hrauth.feign; - -/** - * @auther River - * @date 2020/10/22 14:04 - */ -public class HrmsFeignService { -} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/SecurityUser.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/SecurityUser.java index 3be8f07e..e2be78f7 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/SecurityUser.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/SecurityUser.java @@ -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 getAuthorities() { Collection 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; diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java index cae12dde..101abebc 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java @@ -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 { int uniqueRoleName(String name); List queryPermissionArrById(Long roleId); + + List getUserRoles(Integer userId); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java index cbca161f..d025999f 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java @@ -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 implements RolePermissionService { + @Resource + private AuthRoleDao roleMapper; + @Resource + private AuthEmployeeRoleDao userRoleMapper; + @Override public List listWithTree() { Listlist = this.getBaseMapper().queryPermissionTree(); @@ -108,4 +121,15 @@ public class RolePermissionServiceImpl extends ServiceImpl getUserRoles(Integer userId) { + List userRoles = userRoleMapper.selectList(new QueryWrapper().eq("user_id", userId)); + List roleList = new LinkedList<>(); + for (EmployeeRoleEntity userRole : userRoles) { + RoleEntity role = roleMapper.selectById(userRole.getRoleId()); + roleList.add(role); + } + return roleList; + } + } \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java index c1d1c46b..e5fe5b68 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserDetailsServiceImpl.java @@ -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 getUserRoles(Integer userId) { - List userRoles = userRoleMapper.selectList(new QueryWrapper().eq("user_id", userId)); - List roleList = new LinkedList<>(); - for (EmployeeRoleEntity userRole : userRoles) { - RoleEntity role = roleMapper.selectById(userRole.getRoleId()); - roleList.add(role); - } +// List userRoles = userRoleMapper.selectList(new QueryWrapper().eq("user_id", userId)); +// List roleList = new LinkedList<>(); +// for (EmployeeRoleEntity userRole : userRoles) { +// RoleEntity role = roleMapper.selectById(userRole.getRoleId()); +// roleList.add(role); +// } + log.info("来了调用远程接口~~~~~~~~~~~~~~~~~~~~~~~~~~"); + ResponseResult responseResult = hrauthFeignService.getUserRoles(userId); + List roleList = (List) responseResult.getData(); return roleList; } diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/AuthEmployeeRoleDao.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/AuthEmployeeRoleDao.xml index 24033297..fb11b158 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/AuthEmployeeRoleDao.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/AuthEmployeeRoleDao.xml @@ -4,7 +4,7 @@ - + diff --git a/dq-financial-hrms/src/main/resources/bootstrap.properties b/dq-financial-hrms/src/main/resources/bootstrap.properties index 06998181..beabdee9 100644 --- a/dq-financial-hrms/src/main/resources/bootstrap.properties +++ b/dq-financial-hrms/src/main/resources/bootstrap.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/dq-govern-gateway/src/main/resources/jwt.properties b/dq-govern-gateway/src/main/resources/jwt.properties index 40efcb9f..0c8fa6ed 100644 --- a/dq-govern-gateway/src/main/resources/jwt.properties +++ b/dq-govern-gateway/src/main/resources/jwt.properties @@ -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,\