角色权限模块处理

master
shijie 4 years ago
parent d18b905343
commit f9a6ea993d
  1. 2
      dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java
  2. 4
      dq-financial-guarantee/pom.xml
  3. 3
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplication.java
  4. 6
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/config/IPageConfig.java
  5. 2
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgApplyAmountInfoController.java
  6. 18
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/feign/HrmsFeignService.java
  7. 7
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java
  8. 4
      dq-financial-hrms/pom.xml
  9. 2
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/IPageConfig.java
  10. 6
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java
  11. 37
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/PermissionController.java
  12. 1
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/PermissionDao.java
  13. 7
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/RolePermissionDao.java
  14. 6
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/PermissionService.java
  15. 83
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/PermissionServiceImpl.java
  16. 8
      dq-financial-hrms/src/main/resources/mapper/hrms/PermissionDao.xml
  17. 7
      dq-financial-hrms/src/main/resources/mapper/hrms/RolePermissionDao.xml
  18. 4
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/PermissionEntity.java

@ -18,6 +18,7 @@ import com.daqing.framework.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -56,6 +57,7 @@ public class CustomerController implements CustomerControllerApi {
* 查询客户列表(所有)根据创建时间筛选根据客户类型筛选根据客户编号或者名称搜索
*/
@GetMapping("/queryList")
//@PreAuthorize("hasPermission('/crms/customer/queryList','222')")
public ResponseResult queryList(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, CustomerRequest customerRequest) {
return new ResponseResult<PageUtils>().SUCCESS(customerService.queryList(page, size, customerRequest));

@ -20,12 +20,12 @@
</properties>
<dependencies>
<!-- <dependency>
<dependency>
<groupId>com.daqing.financial</groupId>
<artifactId>dq-financial-hrms-auth</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>-->
</dependency>
<!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>

@ -1,10 +1,12 @@
package com.daqing.financial.guarantee;
import com.daqing.financial.hrauth.config.SecurityConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@ -14,6 +16,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableScheduling
@EnableSwagger2
@ComponentScan(basePackages = "com.daqing")
@Import({SecurityConfig.class})
public class DqFinancialGuaranteeApplication {
public static void main(String[] args) {

@ -1,13 +1,16 @@
/*
package com.daqing.financial.guarantee.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
*/
/**
* @auther River
* @date 2020/11/5 14:38
*/
*//*
@Configuration
public class IPageConfig {
@Bean
@ -15,3 +18,4 @@ public class IPageConfig {
return new PaginationInterceptor();
}
}
*/

@ -33,6 +33,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
@ -80,6 +81,7 @@ public class DgApplyAmountInfoController implements DgApplyAmountInfoControllerA
@ApiOperation(value = "获取当前用户角色")
public ResponseResult getRoles(){
String roleIds = applyAmountInfoService.getRoles();
//List list = applyAmountInfoService.getPermission(roleIds);
return ResponseResult.SUCCESS(roleIds);
}

@ -2,6 +2,8 @@ package com.daqing.financial.guarantee.feign;
import com.daqing.framework.domain.guarantee.po.DgGuaranteePO;
import com.daqing.framework.domain.guarantee.response.EmployeeMessageResponse;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.domain.hrms.ext.EmployeeTO;
import com.daqing.framework.domain.hrms.ext.EmployeeVO;
import com.daqing.framework.model.response.ResponseResult;
@ -66,4 +68,20 @@ public interface HrmsFeignService {
@GetMapping("hrms/employee/selectUserRole")
ResponseResult selectUserRole(@RequestParam("userId") Long userId,@RequestParam("roleId")Long roleId);
/* *//**
* 根据角色id查询所有权限
*//*
@GetMapping("/hrms/permission/queryPermissionsByRoleIds")
ResponseResult queryPermissionsByRoleIds(@RequestParam("ids") Long[] ids);
*//**
* 根据主键id查询权限
* @return
*//*
@GetMapping("/hrms/permission/queryPermissionsByIds")
ResponseResult<List<PermissionEntity>> queryPermissionsByIds(@RequestParam("ids") Integer[] ids);
@GetMapping("/hrms/permission/info")
ResponseResult info(@RequestParam("id") Long id);*/
}

@ -22,6 +22,9 @@ import com.daqing.framework.domain.crms.request.DgApplyAmountInfoRequest;
import com.daqing.framework.domain.crms.response.CrmsCode;
import com.daqing.framework.domain.guarantee.*;
import com.daqing.framework.domain.guarantee.response.EmployeeMessageResponse;
import com.daqing.framework.domain.hrms.DepartmentVO;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.ext.UserDeptVO;
import com.daqing.framework.exception.ExceptionCast;
import com.daqing.framework.model.StatusCode;
import com.daqing.framework.model.response.PromptSuccess;
@ -30,7 +33,10 @@ import com.daqing.framework.util.RandomUtil;
import com.daqing.framework.util.RedisUtil;
import com.daqing.framework.utils.PageUtils;
import com.daqing.framework.utils.excel.ExcelUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -41,6 +47,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>

@ -39,12 +39,12 @@
<artifactId>ooxml-schemas</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<!-- <dependency>
<groupId>com.daqing.financial</groupId>
<artifactId>dq-financial-hrms-auth</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependency>-->
<!-- <dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>

@ -1,3 +1,4 @@
/*
package com.daqing.financial.hrms.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
@ -11,3 +12,4 @@ public class IPageConfig {
return new PaginationInterceptor();
}
}
*/

@ -1,14 +1,10 @@
package com.daqing.financial.hrms.controller;
import com.daqing.financial.hrauth.annotation.Log;
import com.daqing.financial.hrauth.enums.OperationType;
import com.daqing.financial.hrauth.enums.OperationUnit;
import com.daqing.financial.hrms.EmployeeControllerApi;
import com.daqing.financial.hrms.service.EmployeeService;
import com.daqing.framework.domain.crms.request.EmployeeDisableRequest;
import com.daqing.framework.domain.guarantee.po.DgGuaranteePO;
import com.daqing.framework.domain.guarantee.response.EmployeeMessageResponse;
import com.daqing.framework.domain.hrms.EmployeeEntity;
import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.ext.EmployeeInfoVO;
@ -44,7 +40,7 @@ public class EmployeeController implements EmployeeControllerApi {
private EmployeeService employeeService;
@GetMapping("/list")
@Log(detail = "员工列表",level = 3,operationUnit = OperationUnit.ROLE,operationType = OperationType.INSERT)
//@Log(detail = "员工列表",level = 3,operationUnit = OperationUnit.ROLE,operationType = OperationType.INSERT)
//@RequiresPermissions("hrms:employee:info")
public ResponseResult list(@RequestParam("page") Integer page,
@RequestParam("size") Integer size,

@ -5,10 +5,14 @@ import com.daqing.financial.hrms.service.PermissionService;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
@ -36,9 +40,9 @@ public class PermissionController implements PermissionControllerApi {
* 信息
*/
@Override
@GetMapping("/info/{id}")
@GetMapping("/info")
//@RequiresPermissions("hrms:permission:info")
public ResponseResult info(@PathVariable("id") Long id) {
public ResponseResult info(@RequestParam("id") Long id) {
PermissionEntity permission = permissionService.getById(id);
return new ResponseResult<PermissionEntity>().SUCCESS(permission);
}
@ -99,4 +103,33 @@ public class PermissionController implements PermissionControllerApi {
return new ResponseResult<List<RolePermissionEntity>>().SUCCESS(permissionEntityList);
}
/* @Transactional
@GetMapping("/queryPermissionsByRoleIds")
public ResponseResult queryPermissionsByRoleIds(@RequestParam("ids") Long[] ids) {
List<RolePermissionEntity> permissionEntityList = permissionService.queryPermissionsByRoleIds(Arrays.asList(ids));
return new ResponseResult<>().SUCCESS(permissionEntityList);
}
@Transactional
@GetMapping("/queryPermissionsByIds")
public ResponseResult queryPermissionsByIds(@RequestParam("ids") Integer[] ids) {
List<PermissionEntity> permissionEntityList = permissionService.queryPermissionsByIds(Arrays.asList(ids));
return new ResponseResult<List<RolePermissionEntity>>().SUCCESS(permissionEntityList);
}*/
@Transactional
@GetMapping("/getPermission")
public ResponseResult getPermission() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String token = request.getHeader("token");
String userId = RedisUtil.get("dq:token:" + token);
//获取当前用户拥有的角色ids
String roleIds= RedisUtil.get("dq:userRole:" + userId);
List list = permissionService.getPermission(roleIds);
return new ResponseResult<List<RolePermissionEntity>>().SUCCESS(list);
}
}

@ -20,4 +20,5 @@ public interface PermissionDao extends BaseMapper<PermissionEntity> {
List<RolePermissionResponse> listPermissionByRoleIds(@Param("ids") List<Long> ids);
List<PermissionEntity> queryPermissionsByIds(@Param("ids")List<Long> ids);
}

@ -1,8 +1,12 @@
package com.daqing.financial.hrms.dao;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 角色权限中间表
@ -13,5 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface RolePermissionDao extends BaseMapper<RolePermissionEntity> {
List<RolePermissionEntity> queryPermissionsByRoleIds(@Param("ids") List<Long> ids);
}

@ -22,5 +22,11 @@ public interface PermissionService extends IService<PermissionEntity> {
List<PermissionEntity> queryPermissionList();
List<RolePermissionEntity> queryRolePermissionList(Long id);
/* List<RolePermissionEntity> queryPermissionsByRoleIds(List<Long> ids);
List<PermissionEntity> queryPermissionsByIds(List<Integer> asList);*/
List getPermission(String roleIds);
}

@ -7,11 +7,15 @@ import com.daqing.financial.hrms.dao.RolePermissionDao;
import com.daqing.financial.hrms.service.PermissionService;
import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity;
import com.daqing.framework.model.response.ResponseResult;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@ -21,7 +25,9 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionDao, Permission
@Resource
PermissionDao permissionMapper;
@Resource
RolePermissionDao rolePermissionMapper;
RolePermissionDao rolePermissionDao;
@Resource
PermissionService permissionService;
@Override
public List<PermissionEntity> listWithTree() {
@ -44,8 +50,77 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionDao, Permission
@Override
public List<RolePermissionEntity> queryRolePermissionList(Long id) {
List<RolePermissionEntity> permissionEntityList = rolePermissionMapper.selectList(new QueryWrapper<RolePermissionEntity>().eq("permission_id",id));
List<RolePermissionEntity> permissionEntityList = rolePermissionDao.selectList(new QueryWrapper<RolePermissionEntity>().eq("permission_id",id));
return permissionEntityList;
}
/* @Override
public List<RolePermissionEntity> queryPermissionsByRoleIds(List<Long> ids) {
List<RolePermissionEntity> permissionEntityList = rolePermissionDao.queryPermissionsByRoleIds(ids);
return permissionEntityList;
}
@Override
public List<PermissionEntity> queryPermissionsByIds(List<Integer> ids) {
List<PermissionEntity> permissionEntityList = permissionMapper.queryPermissionsByIds(ids);
return permissionEntityList;
}*/
@Override
public List getPermission(String roleIds) {
//截取字符串
String[] strArr = roleIds.split(",");
//转换long类型的数组
Long[] strArrNum = (Long[]) ConvertUtils.convert(strArr,Long.class);
//根据角色id查询对应的权限id
List<RolePermissionEntity> rolePermissionList = rolePermissionDao.queryPermissionsByRoleIds(Arrays.asList(strArrNum));
List<Long> permissionList = new ArrayList();
for(RolePermissionEntity res : rolePermissionList){
permissionList.add(res.getPermissionId());
}
/* ResponseResult responseResult = hrmsFeignService.queryPermissionsByRoleIds(strArrNum);
List<Integer> permissionList = new ArrayList();
List<LinkedHashMap> employeeMessage = null;
if(responseResult.getData() != null){
employeeMessage = (List<LinkedHashMap>) responseResult.getData();
}
for(LinkedHashMap res : employeeMessage){
permissionList.add((Integer) res.get("permissionId"));
}*/
Long[] permissionIds = permissionList.toArray(new Long[permissionList.size()]);
//根据权限ids查询对应权限
List<PermissionEntity> permissionEntityList = permissionMapper.queryPermissionsByIds(Arrays.asList(permissionIds));
/*
ResponseResult responseResult2 = hrmsFeignService.queryPermissionsByIds(permissionIds);
List<LinkedHashMap> perList = (List<LinkedHashMap>) responseResult2.getData();
//LinkedHashMap转对象
ObjectMapper mapper = new ObjectMapper();
List<PermissionEntity> permissionEntityList = mapper.convertValue(perList, new TypeReference<List<PermissionEntity>>() { });
*/
return getListDepartmentAndEmployeeTree(permissionEntityList, 0L);
/*
List list = new ArrayList();
list.add(permissionEntityList);
list.add(roleIds);*/
}
private List<PermissionEntity> getListDepartmentAndEmployeeTree(List<PermissionEntity> list, Long parentId) {
return list.stream()
.filter(dept -> parentId.equals(dept.getParentId())) // 过滤出部门id为所选id的部门信息(也为递归的结果条件,找不到所对应的部门id)
.peek(dept -> {
dept.setChildren(getListDepartmentAndEmployeeTree(list, dept.getId())); // 设置该部门的子部门:递归调用
PermissionEntity permission = permissionService.getById(dept.getId());
})
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) // 根据所选排序信息进行排序
.collect(Collectors.toList());
}
}

@ -9,6 +9,7 @@
<result property="code" column="code"/>
<result property="name" column="name"/>
<result property="url" column="url"/>
<result property="menuUrl" column="menu_url"/>
<result property="parentId" column="parent_id"/>
<result property="level" column="level"/>
<result property="menuOrNot" column="menu_or_not"/>
@ -29,5 +30,12 @@
#{id}
</foreach>
</select>
<select id="queryPermissionsByIds" resultType="com.daqing.framework.domain.hrms.PermissionEntity">
select * from hrms_permission
where id in
<foreach collection="ids" open="(" separator="," close=")" item="id">
#{id}
</foreach>
</select>
</mapper>

@ -9,6 +9,13 @@
<result property="roleId" column="role_id"/>
<result property="permissionId" column="permission_id"/>
</resultMap>
<select id="queryPermissionsByRoleIds" resultType="com.daqing.framework.domain.hrms.RolePermissionEntity">
select permission_id from hrms_role_permission
where role_id in
<foreach collection="ids" open="(" separator="," close=")" item="id">
#{id}
</foreach>
</select>
</mapper>

@ -40,6 +40,10 @@ public class PermissionEntity implements Serializable {
* 路径
*/
private String url;
/**
* 页面路径
*/
private String menuUrl;
/**
* 父权限id
*/

Loading…
Cancel
Save