权限管理和人员绑定页面接口
This commit is contained in:
parent
ea0e0948c4
commit
fe7c60b713
|
|
@ -61,6 +61,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
<artifactId>pagehelper</artifactId>
|
<artifactId>pagehelper</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.github.jsqlparser</groupId>
|
||||||
|
<artifactId>jsqlparser</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
<version>5.1.2</version>
|
<version>5.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 添加分页插件
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,9 +3,8 @@ package com.electromagnetic.industry.software.manage.controller;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
import com.electromagnetic.industry.software.manage.service.RoleService;
|
||||||
import com.electromagnetic.industry.software.manage.service.UserService;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.CommonService;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -17,13 +16,10 @@ public class RoleController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RoleService roleService;
|
private RoleService roleService;
|
||||||
@Resource
|
|
||||||
private CommonService commonService;
|
|
||||||
|
|
||||||
@ApiOperation(value = "新建角色", notes = "")
|
@ApiOperation(value = "新建角色", notes = "")
|
||||||
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
||||||
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
||||||
commonService.queryAllPrjInfo();
|
|
||||||
return ElectromagneticResultUtil.success(roleService.createRole(roleDTO));
|
return ElectromagneticResultUtil.success(roleService.createRole(roleDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,4 +40,22 @@ public class RoleController {
|
||||||
public ElectromagneticResult<?> getRole(@PathVariable("roleId") String roleId) {
|
public ElectromagneticResult<?> getRole(@PathVariable("roleId") String roleId) {
|
||||||
return ElectromagneticResultUtil.success(roleService.getRole(roleId));
|
return ElectromagneticResultUtil.success(roleService.getRole(roleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取角色列表", notes = "")
|
||||||
|
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
||||||
|
public ElectromagneticResult<?> getRoles(@RequestBody RolePageDTO rolePageDTO) {
|
||||||
|
return ElectromagneticResultUtil.success(roleService.getRoles(rolePageDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value="通过角色名查看角色权限", notes = "")
|
||||||
|
@GetMapping(value = "/getRoleByName")
|
||||||
|
public ElectromagneticResult<?> getRoleByName(@RequestParam("roleName") String roleName) {
|
||||||
|
return ElectromagneticResultUtil.success(roleService.getRoleByName(roleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "角色名列表", notes = "")
|
||||||
|
@GetMapping(value = "/getRoleNames")
|
||||||
|
public ElectromagneticResult<?> getRoleNames() {
|
||||||
|
return ElectromagneticResultUtil.success(roleService.getAllRoleNames());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.*;
|
import com.electromagnetic.industry.software.manage.pojo.req.*;
|
||||||
|
|
@ -70,6 +71,13 @@ public class UserController {
|
||||||
return userService.logout(token);
|
return userService.logout(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "人员绑定界面查询用户", notes = "")
|
||||||
|
@RequestMapping(value = "/bindRole/list", method = RequestMethod.POST)
|
||||||
|
public ElectromagneticResult<?> getPublishedUsers(@RequestBody SearchUserRequest searchUserRequest) {
|
||||||
|
searchUserRequest.setIsPublished(PublishEnum.PUBLISHED.getCode().toString());
|
||||||
|
return userService.searchUser(searchUserRequest);
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "人员绑定", notes = "")
|
@ApiOperation(value = "人员绑定", notes = "")
|
||||||
@RequestMapping(value = "/bindRoles", method = RequestMethod.POST)
|
@RequestMapping(value = "/bindRoles", method = RequestMethod.POST)
|
||||||
public ElectromagneticResult<?> bindRoles(@RequestBody UserRoleRequest userRoleRequest) {
|
public ElectromagneticResult<?> bindRoles(@RequestBody UserRoleRequest userRoleRequest) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,38 @@
|
||||||
package com.electromagnetic.industry.software.manage.mapper;
|
package com.electromagnetic.industry.software.manage.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface RoleMapper extends BaseMapper<Role> {
|
public interface RoleMapper extends BaseMapper<Role> {
|
||||||
|
|
||||||
|
|
||||||
|
@Select("<script>" +
|
||||||
|
"SELECT " +
|
||||||
|
" r.role_id AS roleId, " +
|
||||||
|
" r.role_name AS roleName, " +
|
||||||
|
" r.role_desc AS roleDesc, " +
|
||||||
|
" GROUP_CONCAT(DISTINCT f.file_name) AS dataScope, " +
|
||||||
|
" GROUP_CONCAT(DISTINCT rp.permission_code) AS allowedActions " +
|
||||||
|
"FROM " +
|
||||||
|
" ed_role r " +
|
||||||
|
"LEFT JOIN " +
|
||||||
|
" ed_role_permission rp ON r.role_id = rp.role_id " +
|
||||||
|
"LEFT JOIN " +
|
||||||
|
" ed_file_info f ON rp.file_id = f.id " +
|
||||||
|
"WHERE " +
|
||||||
|
"<if test='ew != null'>" +
|
||||||
|
" ${ew.sqlSegment} " +
|
||||||
|
"</if>" +
|
||||||
|
"GROUP BY " +
|
||||||
|
" r.role_id" +
|
||||||
|
"</script>")
|
||||||
|
Page<RoleDTO> getPageRoleDTO(Page<RoleDTO> page, @Param(Constants.WRAPPER) QueryWrapper<Role> queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,4 +75,10 @@ public interface UserMapper {
|
||||||
*/
|
*/
|
||||||
int deleteUser(UserDeleteKeyWords userDeleteKeyWords);
|
int deleteUser(UserDeleteKeyWords userDeleteKeyWords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找用户角色名称
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> selectUserRoles(String userId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,6 @@ public class Role {
|
||||||
@TableField(value = "role_desc")
|
@TableField(value = "role_desc")
|
||||||
private String roleDesc;
|
private String roleDesc;
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色状态
|
|
||||||
*/
|
|
||||||
@TableField(value = "role_status")
|
|
||||||
private String roleStatus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建者用户编码
|
* 创建者用户编码
|
||||||
*/
|
*/
|
||||||
|
|
@ -74,7 +68,6 @@ public class Role {
|
||||||
* 是否有效:0-无效 1-有效
|
* 是否有效:0-无效 1-有效
|
||||||
*/
|
*/
|
||||||
@TableField(value="effect_flag")
|
@TableField(value="effect_flag")
|
||||||
@TableLogic(value = "1", delval = "0")
|
|
||||||
private Integer effectFlag;
|
private Integer effectFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,11 @@ public class User {
|
||||||
*/
|
*/
|
||||||
private String userTitle;
|
private String userTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账户
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录密码
|
* 登录密码
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,10 +70,15 @@ public class User {
|
||||||
private Date internshipEndDate;
|
private Date internshipEndDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否已发布
|
* 是否已发布(系统管理员)
|
||||||
*/
|
*/
|
||||||
private Integer isPublished;
|
private Integer isPublished;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已激活(安全管理员)
|
||||||
|
*/
|
||||||
|
private Integer isActivated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 盐
|
* 盐
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ public class SearchKeyWords {
|
||||||
*/
|
*/
|
||||||
private String isPublished;
|
private String isPublished;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户激活状态
|
||||||
|
*/
|
||||||
|
private String isActivated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序方式: "asc" 或 "desc" 或 “”
|
* 排序方式: "asc" 或 "desc" 或 “”
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SingleUserResponse {
|
public class SingleUserResponse {
|
||||||
|
|
@ -45,11 +46,26 @@ public class SingleUserResponse {
|
||||||
*/
|
*/
|
||||||
private String userTitle;
|
private String userTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账户
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录密码
|
* 登录密码
|
||||||
*/
|
*/
|
||||||
private String userPwd;
|
private String userPwd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称拼接字符串
|
||||||
|
*/
|
||||||
|
private String roles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称列表
|
||||||
|
*/
|
||||||
|
private List<String> roleList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入职日期
|
* 入职日期
|
||||||
*/
|
*/
|
||||||
|
|
@ -72,6 +88,11 @@ public class SingleUserResponse {
|
||||||
*/
|
*/
|
||||||
private Integer isPublished;
|
private Integer isPublished;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已激活
|
||||||
|
*/
|
||||||
|
private Integer isActivated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 盐
|
* 盐
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RolePageDTO {
|
||||||
|
/**
|
||||||
|
* 角色编号
|
||||||
|
*/
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色姓名
|
||||||
|
*/
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页码
|
||||||
|
*/
|
||||||
|
private Integer pageIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页数据量
|
||||||
|
*/
|
||||||
|
private Integer pageSize;
|
||||||
|
}
|
||||||
|
|
@ -9,9 +9,14 @@ import java.util.Map;
|
||||||
public class RolePermissionDTO {
|
public class RolePermissionDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 目录(文件)编号
|
* 目录(文件)主键
|
||||||
*/
|
*/
|
||||||
private String fileId;
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父ID
|
||||||
|
*/
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 目录(文件)名称
|
* 目录(文件)名称
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ public class SearchUserRequest extends BaseRequest implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String isPublished;
|
private String isPublished;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户激活状态
|
||||||
|
*/
|
||||||
|
private String isActivated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序方式: "asc" 或 "desc" 或 “”
|
* 排序方式: "asc" 或 "desc" 或 “”
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserBindRoleDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称列表(角色名称唯一)
|
||||||
|
*/
|
||||||
|
List<String> roleList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,13 +7,6 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class UserRoleRequest {
|
public class UserRoleRequest {
|
||||||
|
|
||||||
/**
|
List<UserBindRoleDTO> bindData;
|
||||||
* 用户编号
|
|
||||||
*/
|
|
||||||
String userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色编号列表
|
|
||||||
*/
|
|
||||||
List<String> roleIds;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ public interface PermissionService {
|
||||||
* 查询当前用户在当前目录的功能权限
|
* 查询当前用户在当前目录的功能权限
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param fileId
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map<String, Boolean> getUserPermission(String userId, String fileId);
|
Map<String, Boolean> getUserPermission(String userId, String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户有权限访问的目录id
|
* 获取当前用户有权限访问的目录id
|
||||||
|
|
@ -20,4 +20,19 @@ public interface PermissionService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<String> getAccessibleTree();
|
List<String> getAccessibleTree();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得当前角色权限
|
||||||
|
* @param roleId
|
||||||
|
* @param fileId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getPermissionCodes(String roleId, String fileId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户权限列表 转换为 哈希
|
||||||
|
* @param permissionCodes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, Boolean> transToMap(List<String> permissionCodes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package com.electromagnetic.industry.software.manage.service;
|
package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface RoleService extends IService<Role> {
|
public interface RoleService extends IService<Role> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,5 +38,25 @@ public interface RoleService extends IService<Role> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
RoleDTO getRole(String roleId);
|
RoleDTO getRole(String roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看角色列表
|
||||||
|
* @param rolePageDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IPage<RoleDTO> getRoles(RolePageDTO rolePageDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有角色名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getAllRoleNames();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过角色名称查看角色权限
|
||||||
|
* @param roleName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
RoleDTO getRoleByName(String roleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.electromagnetic.industry.software.common.enums.FilePermission;
|
import com.electromagnetic.industry.software.common.enums.FilePermission;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
|
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
|
||||||
|
|
@ -28,32 +28,21 @@ public class PermissionServiceImpl implements PermissionService {
|
||||||
* 查询当前用户在当前目录的功能权限
|
* 查询当前用户在当前目录的功能权限
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param fileId
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> getUserPermission(String userId, String fileId) {
|
public Map<String, Boolean> getUserPermission(String userId, String id) {
|
||||||
Map<String, Boolean> result = new HashMap<>();
|
|
||||||
|
|
||||||
QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
|
List<String> roleIds = getRoles(userId);
|
||||||
queryWrapper.select("role_id").eq("user_id", userId);
|
|
||||||
List<Object> roleIds = userRoleMapper.selectObjs(queryWrapper);
|
|
||||||
|
|
||||||
QueryWrapper<RolePermission> queryWrapper1 = new QueryWrapper<>();
|
LambdaQueryWrapper<RolePermission> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
queryWrapper1.select("permission_code")
|
queryWrapper1.select(RolePermission::getPermissionCode)
|
||||||
.eq("file_id", fileId)
|
.eq(RolePermission::getFileId, id)
|
||||||
.in("role_id", roleIds);
|
.in(RolePermission::getRoleId, roleIds);
|
||||||
List<Object> permissionCodes = rolePermissionMapper.selectObjs(queryWrapper1);
|
List<String> permissionCodes = rolePermissionMapper.selectObjs(queryWrapper1).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
|
||||||
List<String> allCodes = FilePermission.getAllCodes();
|
return transToMap(permissionCodes);
|
||||||
for (String code : allCodes) {
|
|
||||||
if (permissionCodes.contains(code)) {
|
|
||||||
result.put(code, true);
|
|
||||||
} else {
|
|
||||||
result.put(code, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,18 +53,57 @@ public class PermissionServiceImpl implements PermissionService {
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAccessibleTree() {
|
public List<String> getAccessibleTree() {
|
||||||
String userId = UserThreadLocal.getUserId();
|
String userId = UserThreadLocal.getUserId();
|
||||||
QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
|
List<String> roleIds = getRoles(userId);
|
||||||
queryWrapper.select("role_id").eq("user_id", userId);
|
|
||||||
List<Object> roleIds = userRoleMapper.selectObjs(queryWrapper);
|
|
||||||
|
|
||||||
QueryWrapper<RolePermission> queryWrapper1 = new QueryWrapper<>();
|
LambdaQueryWrapper<RolePermission> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
queryWrapper1.select("file_id")
|
queryWrapper1.select(RolePermission::getFileId)
|
||||||
.in("role_id", roleIds)
|
.in(RolePermission::getRoleId, roleIds)
|
||||||
.eq("permission_code", FilePermission.VIEW);
|
.eq(RolePermission::getPermissionCode, FilePermission.VIEW);
|
||||||
List<Object> fileIds = rolePermissionMapper.selectObjs(queryWrapper1);
|
return rolePermissionMapper.selectObjs(queryWrapper1).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
return fileIds.stream()
|
/**
|
||||||
.map(Object::toString) // 将 Object 转为 String
|
* 根据用户获得角色
|
||||||
.collect(Collectors.toList());
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<String> getRoles (String userId) {
|
||||||
|
LambdaQueryWrapper<UserRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.select(UserRole::getRoleId).eq(UserRole::getUserId, userId);
|
||||||
|
return userRoleMapper.selectObjs(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得角色权限
|
||||||
|
* @param roleId
|
||||||
|
* @param fileId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getPermissionCodes(String roleId, String fileId) {
|
||||||
|
LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.select(RolePermission::getPermissionCode)
|
||||||
|
.eq(RolePermission::getFileId, fileId)
|
||||||
|
.eq(RolePermission::getRoleId, roleId);
|
||||||
|
return rolePermissionMapper.selectObjs(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户权限列表 转换为 哈希
|
||||||
|
* @param permissionCodes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Boolean> transToMap(List<String> permissionCodes) {
|
||||||
|
Map<String, Boolean> result = new HashMap<>();
|
||||||
|
List<String> allCodes = FilePermission.getAllCodes();
|
||||||
|
for (String code : allCodes) {
|
||||||
|
if (permissionCodes.contains(code)) {
|
||||||
|
result.put(code, true);
|
||||||
|
} else {
|
||||||
|
result.put(code, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,35 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePermissionDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePermissionDTO;
|
||||||
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
import com.electromagnetic.industry.software.manage.service.*;
|
||||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import com.electromagnetic.industry.software.manage.service.UserRoleService;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.PRJ_PARENT_ID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||||
|
|
@ -30,8 +38,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
private RolePermissionService rolePermissionService;
|
private RolePermissionService rolePermissionService;
|
||||||
@Resource
|
@Resource
|
||||||
private UserRoleService userRoleService;
|
private UserRoleService userRoleService;
|
||||||
|
@Resource
|
||||||
|
private CommonService commonService;
|
||||||
|
@Resource
|
||||||
|
private PermissionService permissionService;
|
||||||
|
|
||||||
private EleLog log = new EleLog(RoleServiceImpl.class);
|
private EleLog log = new EleLog(RoleServiceImpl.class);
|
||||||
|
@Autowired
|
||||||
|
private RoleMapper roleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建角色
|
* 新建角色
|
||||||
|
|
@ -73,18 +87,20 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateRole(RoleDTO roleDTO){
|
public Boolean updateRole(RoleDTO roleDTO){
|
||||||
|
|
||||||
|
checkRoleNameUnique(roleDTO);
|
||||||
|
|
||||||
// 更新角色信息
|
// 更新角色信息
|
||||||
UpdateWrapper<Role> updateWrapper = new UpdateWrapper<>();
|
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.eq("role_id", roleDTO.getRoleId());
|
updateWrapper.eq(Role::getRoleId, roleDTO.getRoleId())
|
||||||
updateWrapper.set("role_name", roleDTO.getRoleName());
|
.set(Role::getRoleName, roleDTO.getRoleName())
|
||||||
updateWrapper.set("role_desc", roleDTO.getRoleDesc());
|
.set(Role::getRoleDesc, roleDTO.getRoleDesc())
|
||||||
updateWrapper.set("modifier", UserThreadLocal.getUserId());
|
.set(Role::getModifier, UserThreadLocal.getUserId())
|
||||||
updateWrapper.set("modifier_name", UserThreadLocal.getUsername());
|
.set(Role::getModifierName, UserThreadLocal.getUsername());
|
||||||
this.update(updateWrapper);
|
this.update(updateWrapper);
|
||||||
|
|
||||||
// 删除旧权限信息
|
// 删除旧权限信息
|
||||||
QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
|
LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq("role_id", roleDTO.getRoleId());
|
queryWrapper.eq(RolePermission::getRoleId, roleDTO.getRoleId());
|
||||||
rolePermissionService.remove(queryWrapper);
|
rolePermissionService.remove(queryWrapper);
|
||||||
|
|
||||||
// 插入新权限信息
|
// 插入新权限信息
|
||||||
|
|
@ -106,15 +122,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
|
|
||||||
// 保留角色权限关联表
|
// 保留角色权限关联表
|
||||||
// 删除用户角色关联表
|
// 删除用户角色关联表
|
||||||
QueryWrapper<UserRole> queryWrapper1 = new QueryWrapper<>();
|
LambdaQueryWrapper<UserRole> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
queryWrapper1.eq("role_id", roleId);
|
queryWrapper1.eq(UserRole::getRoleId, roleId);
|
||||||
userRoleService.remove(queryWrapper1);
|
userRoleService.remove(queryWrapper1);
|
||||||
|
|
||||||
// 逻辑删除角色
|
// 逻辑删除角色
|
||||||
QueryWrapper<Role> queryWrapper2 = new QueryWrapper<>();
|
LambdaUpdateWrapper<Role> queryWrapper2 = new LambdaUpdateWrapper<>();
|
||||||
queryWrapper2.eq("role_id", roleId);
|
queryWrapper2.eq(Role::getRoleId, roleId)
|
||||||
this.remove(queryWrapper2);
|
.set(Role::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
||||||
return true;
|
return this.update(queryWrapper2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,9 +150,85 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
roleDTO.setRoleName(role.getRoleName());
|
roleDTO.setRoleName(role.getRoleName());
|
||||||
roleDTO.setRoleDesc(role.getRoleDesc());
|
roleDTO.setRoleDesc(role.getRoleDesc());
|
||||||
|
|
||||||
|
// 查询当前层级树,若层级树查询条件修改,此处也需修改
|
||||||
|
List<EdFileInfo> infos = commonService.selectAllAdminFolder(PRJ_PARENT_ID);
|
||||||
|
|
||||||
|
List<RolePermissionDTO> nodes = new ArrayList<>();
|
||||||
|
for (EdFileInfo info : infos) {
|
||||||
|
RolePermissionDTO rolePermissionDTO = new RolePermissionDTO();
|
||||||
|
rolePermissionDTO.setId(info.getId());
|
||||||
|
rolePermissionDTO.setParentId(info.getParentId());
|
||||||
|
rolePermissionDTO.setFileName(info.getFileName());
|
||||||
|
List<String> permissionCodes = permissionService.getPermissionCodes(roleId, info.getId());
|
||||||
|
if (!permissionCodes.isEmpty()) {
|
||||||
|
Map<String, Boolean> dataAuth = new HashMap<>();
|
||||||
|
dataAuth.put("data", true);
|
||||||
|
rolePermissionDTO.setDataAuth(dataAuth);
|
||||||
|
} else {
|
||||||
|
Map<String, Boolean> dataAuth = new HashMap<>();
|
||||||
|
dataAuth.put("data", false);
|
||||||
|
rolePermissionDTO.setDataAuth(dataAuth);
|
||||||
|
}
|
||||||
|
rolePermissionDTO.setPermission(permissionService.transToMap(permissionCodes));
|
||||||
|
nodes.add(rolePermissionDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
roleDTO.setData(buildTree(nodes));
|
||||||
|
|
||||||
return roleDTO;
|
return roleDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过角色名查看角色
|
||||||
|
* @param roleName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public RoleDTO getRoleByName(String roleName){
|
||||||
|
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(Role::getRoleName, roleName);
|
||||||
|
Role role = this.getOne(queryWrapper);
|
||||||
|
return getRole(role.getRoleId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看角色列表
|
||||||
|
* @param rolePageDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public IPage<RoleDTO> getRoles(RolePageDTO rolePageDTO) {
|
||||||
|
|
||||||
|
// 创建分页对象
|
||||||
|
Page<RoleDTO> page = new Page<>(rolePageDTO.getPageIndex(), rolePageDTO.getPageSize());
|
||||||
|
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(rolePageDTO.getRoleId())){
|
||||||
|
queryWrapper.eq("r.role_id", rolePageDTO.getRoleId());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(rolePageDTO.getRoleName())){
|
||||||
|
queryWrapper.eq("r.role_name", rolePageDTO.getRoleName());
|
||||||
|
}
|
||||||
|
queryWrapper.eq("r.effect_flag", EffectFlagEnum.EFFECT.code);
|
||||||
|
|
||||||
|
return roleMapper.getPageRoleDTO(page, queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有角色名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public List<String> getAllRoleNames() {
|
||||||
|
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.select(Role::getRoleName)
|
||||||
|
.eq(Role::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||||
|
return this.listObjs(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验当前角色名称是否唯一
|
* 校验当前角色名称是否唯一
|
||||||
*
|
*
|
||||||
|
|
@ -172,7 +264,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
|
|
||||||
node.getPermission().forEach((code, hasPermission) -> {
|
node.getPermission().forEach((code, hasPermission) -> {
|
||||||
if (Boolean.TRUE.equals(hasPermission)) { // 检查权限值是否为 true
|
if (Boolean.TRUE.equals(hasPermission)) { // 检查权限值是否为 true
|
||||||
flatList.add(new RolePermission(roleId, node.getFileId(), code));
|
flatList.add(new RolePermission(roleId, node.getId(), code));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 添加当前节点
|
// 添加当前节点
|
||||||
|
|
@ -182,5 +274,28 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建层级结构
|
||||||
|
private List<RolePermissionDTO> buildTree(List<RolePermissionDTO> nodes) {
|
||||||
|
// 找到所有的根节点
|
||||||
|
List<RolePermissionDTO> rootNodes = nodes.stream()
|
||||||
|
.filter(node -> node.getParentId().equals(PRJ_PARENT_ID))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 递归设置子节点
|
||||||
|
for (RolePermissionDTO rootNode : rootNodes) {
|
||||||
|
rootNode.setChildren(findChildren(rootNode, nodes));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归查找子节点
|
||||||
|
private List<RolePermissionDTO> findChildren(RolePermissionDTO parent, List<RolePermissionDTO> nodes) {
|
||||||
|
return nodes.stream()
|
||||||
|
.filter(node -> parent.getId().equals(node.getParentId())) // 匹配父子关系
|
||||||
|
.peek(node -> node.setChildren(findChildren(node, nodes))) // 递归设置子节点
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,20 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.SystemClock;
|
import cn.hutool.core.date.SystemClock;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.ActiveEnum;
|
||||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
import com.electromagnetic.industry.software.common.enums.ElectromagneticErrorEnum;
|
import com.electromagnetic.industry.software.common.enums.ElectromagneticErrorEnum;
|
||||||
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.*;
|
import com.electromagnetic.industry.software.common.util.*;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.TokenMapper;
|
import com.electromagnetic.industry.software.manage.mapper.*;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.UserMapper;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.UserMappers;
|
|
||||||
import com.electromagnetic.industry.software.manage.mapper.UserRoleMapper;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Token;
|
import com.electromagnetic.industry.software.manage.pojo.models.Token;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.User;
|
import com.electromagnetic.industry.software.manage.pojo.models.User;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
||||||
|
|
@ -28,12 +30,13 @@ import com.electromagnetic.industry.software.manage.pojo.resp.UserSearchResponse
|
||||||
import com.electromagnetic.industry.software.manage.service.UserService;
|
import com.electromagnetic.industry.software.manage.service.UserService;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static cn.hutool.core.date.DateTime.now;
|
import static cn.hutool.core.date.DateTime.now;
|
||||||
|
|
||||||
|
|
@ -46,6 +49,8 @@ public class UserServiceImpl implements UserService {
|
||||||
private TokenMapper tokenMapper;
|
private TokenMapper tokenMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private UserRoleMapper userRoleMapper;
|
private UserRoleMapper userRoleMapper;
|
||||||
|
@Autowired
|
||||||
|
private RoleMapper roleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
|
|
@ -81,14 +86,12 @@ public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
public Boolean checkUserValid(User user) {
|
public Boolean checkUserValid(User user) {
|
||||||
if (user == null
|
if (user == null
|
||||||
|| user.getIsPublished() == PublishEnum.UNPUBLISHED.getCode()
|
|| Objects.equals(user.getIsPublished(), PublishEnum.UNPUBLISHED.getCode())
|
||||||
|| user.getEffectFlag() == EffectFlagEnum.NOT_EFFECTIVE.code
|
|| Objects.equals(user.getIsActivated(), ActiveEnum.UNACTIVATED.getCode())
|
||||||
|
|| Objects.equals(user.getEffectFlag(), EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
} else if (user.getInternshipEndDate() != null && user.getInternshipEndDate().before(now())) {
|
} else return user.getInternshipEndDate() == null || !user.getInternshipEndDate().before(now());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createToken(UserLoginInfo loginInfo) {
|
public String createToken(UserLoginInfo loginInfo) {
|
||||||
|
|
@ -123,6 +126,11 @@ public class UserServiceImpl implements UserService {
|
||||||
user.setUserId(IdWorker.getSnowFlakeIdString());
|
user.setUserId(IdWorker.getSnowFlakeIdString());
|
||||||
user.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + user.getSalt()));
|
user.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + user.getSalt()));
|
||||||
user.setIsPublished(UserConstants.DEFAULT_PUBLISH_STATUS);
|
user.setIsPublished(UserConstants.DEFAULT_PUBLISH_STATUS);
|
||||||
|
user.setIsActivated(UserConstants.DEFAULT_ACTIVE_STATUS);
|
||||||
|
|
||||||
|
// 暂时将账户设置为工号
|
||||||
|
user.setUserAccount(user.getWorkNumber());
|
||||||
|
|
||||||
user.setCreator(UserThreadLocal.getUserId());
|
user.setCreator(UserThreadLocal.getUserId());
|
||||||
user.setCreatorName(UserThreadLocal.getUsername());
|
user.setCreatorName(UserThreadLocal.getUsername());
|
||||||
return ElectromagneticResultUtil.success(userMapper.insert(user) > 0);
|
return ElectromagneticResultUtil.success(userMapper.insert(user) > 0);
|
||||||
|
|
@ -203,12 +211,23 @@ public class UserServiceImpl implements UserService {
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<?> searchUser(SearchUserRequest searchUserRequest) {
|
public ElectromagneticResult<?> searchUser(SearchUserRequest searchUserRequest) {
|
||||||
searchUserRequest.setPageIndex((searchUserRequest.getPageIndex() - 1) * searchUserRequest.getPageSize());
|
searchUserRequest.setPageIndex((searchUserRequest.getPageIndex() - 1) * searchUserRequest.getPageSize());
|
||||||
SearchKeyWords model = UserMappers.INSTANCE.getSearchKeywordsRequestToModel(searchUserRequest);
|
SearchKeyWords model = new SearchKeyWords();
|
||||||
|
BeanUtils.copyProperties(searchUserRequest, model);
|
||||||
List<User> userList = userMapper.search(model);
|
List<User> userList = userMapper.search(model);
|
||||||
int totalCount = userMapper.getTotalCount(model);
|
int totalCount = userMapper.getTotalCount(model);
|
||||||
List<SingleUserResponse> singleUserResponseList = UserMappers.INSTANCE.userListToResponseList(userList);
|
|
||||||
|
List<SingleUserResponse> list = new ArrayList<>();
|
||||||
|
for (User user : userList) {
|
||||||
|
SingleUserResponse singleUserResponse = new SingleUserResponse();
|
||||||
|
BeanUtils.copyProperties(user, singleUserResponse);
|
||||||
|
List<String> roleList = userMapper.selectUserRoles(user.getUserId());
|
||||||
|
String roles = String.join(",", roleList);
|
||||||
|
singleUserResponse.setRoles(roles);
|
||||||
|
singleUserResponse.setRoleList(roleList);
|
||||||
|
list.add(singleUserResponse);
|
||||||
|
}
|
||||||
UserSearchResponse userSearchResponse = new UserSearchResponse();
|
UserSearchResponse userSearchResponse = new UserSearchResponse();
|
||||||
userSearchResponse.setUserList(singleUserResponseList);
|
userSearchResponse.setUserList(list);
|
||||||
userSearchResponse.setTotalCount(totalCount);
|
userSearchResponse.setTotalCount(totalCount);
|
||||||
return ElectromagneticResultUtil.success(userSearchResponse);
|
return ElectromagneticResultUtil.success(userSearchResponse);
|
||||||
}
|
}
|
||||||
|
|
@ -247,24 +266,44 @@ public class UserServiceImpl implements UserService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean bindRoles(UserRoleRequest userRolesRequest) {
|
public Boolean bindRoles(UserRoleRequest userRolesRequest) {
|
||||||
String userId = userRolesRequest.getUserId();
|
if (userRolesRequest==null || userRolesRequest.getBindData().isEmpty()) {
|
||||||
List<String> roleIds = userRolesRequest.getRoleIds();
|
throw new BizException(HttpStatus.BAD_REQUEST.value(), "请勿发布空数据");
|
||||||
if (userId == null) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
}
|
||||||
|
for (UserBindRoleDTO dto: userRolesRequest.getBindData()) {
|
||||||
|
activeRole(dto);
|
||||||
|
bindRole(dto);
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void activeRole (UserBindRoleDTO dto) {
|
||||||
|
User user = userMapper.getSingleUser(dto.getUserId());
|
||||||
|
if (user.getIsActivated().equals(ActiveEnum.UNACTIVATED.getCode())) {
|
||||||
|
user.setIsActivated(ActiveEnum.ACTIVATED.getCode());
|
||||||
|
userMapper.modify(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindRole (UserBindRoleDTO dto) {
|
||||||
|
String userId = dto.getUserId();
|
||||||
|
List<String> roleNames = dto.getRoleList();
|
||||||
// 删除当前用户原绑定角色
|
// 删除当前用户原绑定角色
|
||||||
QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("user_id", userId);
|
queryWrapper.eq("user_id", userId);
|
||||||
userRoleMapper.delete(queryWrapper);
|
userRoleMapper.delete(queryWrapper);
|
||||||
|
|
||||||
if (roleIds != null) {
|
if (roleNames != null) {
|
||||||
for (String roleId : roleIds) {
|
for (String roleName : roleNames) {
|
||||||
|
LambdaQueryWrapper<Role> roleQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
roleQueryWrapper.select(Role::getRoleId)
|
||||||
|
.eq(Role::getRoleName, roleName);
|
||||||
|
String roleId = roleMapper.selectOne(roleQueryWrapper).getRoleId();
|
||||||
|
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setUserId(userId);
|
userRole.setUserId(userId);
|
||||||
userRole.setRoleId(roleId);
|
userRole.setRoleId(roleId);
|
||||||
userRoleMapper.insert(userRole);
|
userRoleMapper.insert(userRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
<result column="user_pwd" jdbcType="VARCHAR" property="userPwd"/>
|
<result column="user_pwd" jdbcType="VARCHAR" property="userPwd"/>
|
||||||
<result column="join_time" jdbcType="TIMESTAMP" property="joinTime"/>
|
<result column="join_time" jdbcType="TIMESTAMP" property="joinTime"/>
|
||||||
<result column="is_published" jdbcType="TINYINT" property="isPublished"/>
|
<result column="is_published" jdbcType="TINYINT" property="isPublished"/>
|
||||||
|
<result column="is_activated" jdbcType="TINYINT" property="isActivated"/>
|
||||||
<result column="salt" jdbcType="VARCHAR" property="salt"/>
|
<result column="salt" jdbcType="VARCHAR" property="salt"/>
|
||||||
<result column="user_status" jdbcType="VARCHAR" property="userStatus"/>
|
<result column="user_status" jdbcType="VARCHAR" property="userStatus"/>
|
||||||
<result column="internship_end_date" jdbcType="DATE" property="internshipEndDate"/>
|
<result column="internship_end_date" jdbcType="DATE" property="internshipEndDate"/>
|
||||||
|
|
@ -34,6 +35,7 @@
|
||||||
user_pwd,
|
user_pwd,
|
||||||
join_time,
|
join_time,
|
||||||
is_published,
|
is_published,
|
||||||
|
is_activated,
|
||||||
salt,
|
salt,
|
||||||
user_status,
|
user_status,
|
||||||
internship_end_date,
|
internship_end_date,
|
||||||
|
|
@ -58,6 +60,7 @@
|
||||||
<if test="userPwd != null and userPwd !='' ">user_pwd,</if>
|
<if test="userPwd != null and userPwd !='' ">user_pwd,</if>
|
||||||
<if test="joinTime != null">join_time,</if>
|
<if test="joinTime != null">join_time,</if>
|
||||||
<if test="isPublished != null">is_published,</if>
|
<if test="isPublished != null">is_published,</if>
|
||||||
|
<if test="isActivated != null">is_activated,</if>
|
||||||
<if test="salt != null and salt !='' ">salt,</if>
|
<if test="salt != null and salt !='' ">salt,</if>
|
||||||
<if test="userStatus != null and userStatus !='' ">user_status,</if>
|
<if test="userStatus != null and userStatus !='' ">user_status,</if>
|
||||||
<if test="internshipEndDate != null">internship_end_date,</if>
|
<if test="internshipEndDate != null">internship_end_date,</if>
|
||||||
|
|
@ -75,6 +78,7 @@
|
||||||
<if test="userPwd != null and userPwd !='' ">#{userPwd},</if>
|
<if test="userPwd != null and userPwd !='' ">#{userPwd},</if>
|
||||||
<if test="joinTime != null">#{joinTime},</if>
|
<if test="joinTime != null">#{joinTime},</if>
|
||||||
<if test="isPublished != null">#{isPublished},</if>
|
<if test="isPublished != null">#{isPublished},</if>
|
||||||
|
<if test="isActivated != null">#{isActivated},</if>
|
||||||
<if test="salt != null and salt !='' ">#{salt},</if>
|
<if test="salt != null and salt !='' ">#{salt},</if>
|
||||||
<if test="userStatus != null and userStatus !='' ">#{userStatus},</if>
|
<if test="userStatus != null and userStatus !='' ">#{userStatus},</if>
|
||||||
<if test="internshipEndDate != null">#{internshipEndDate},</if>
|
<if test="internshipEndDate != null">#{internshipEndDate},</if>
|
||||||
|
|
@ -95,6 +99,7 @@
|
||||||
<if test="userTitle != null and userTitle != ''">user_title = #{userTitle},</if>
|
<if test="userTitle != null and userTitle != ''">user_title = #{userTitle},</if>
|
||||||
<if test="joinTime != null">join_time = #{joinTime},</if>
|
<if test="joinTime != null">join_time = #{joinTime},</if>
|
||||||
<if test="userStatus != null and userStatus != ''">user_status = #{userStatus},</if>
|
<if test="userStatus != null and userStatus != ''">user_status = #{userStatus},</if>
|
||||||
|
<if test="isActivated != null and isActivated != ''">is_activated = #{isActivated},</if>
|
||||||
internship_end_date = #{internshipEndDate},
|
internship_end_date = #{internshipEndDate},
|
||||||
<if test="modifier != null and modifier != ''">modifier = #{modifier},</if>
|
<if test="modifier != null and modifier != ''">modifier = #{modifier},</if>
|
||||||
<if test="modifierName != null and modifierName != ''">modifier_name = #{modifierName},</if>
|
<if test="modifierName != null and modifierName != ''">modifier_name = #{modifierName},</if>
|
||||||
|
|
@ -145,6 +150,15 @@
|
||||||
</when>
|
</when>
|
||||||
</choose>
|
</choose>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
<!-- 条件 4:按激活状态搜索 -->
|
||||||
|
<if test="isActivated != null and isActivated != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="isActivated != 'all'">
|
||||||
|
AND is_activated = CAST(#{isActivated} AS SIGNED)
|
||||||
|
</when>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
and effect_flag=1
|
and effect_flag=1
|
||||||
</where>
|
</where>
|
||||||
|
|
||||||
|
|
@ -190,6 +204,15 @@
|
||||||
</when>
|
</when>
|
||||||
</choose>
|
</choose>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
<!-- 条件 4:按激活状态搜索 -->
|
||||||
|
<if test="isActivated != null and isActivated != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="isActivated != 'all'">
|
||||||
|
AND is_activated = CAST(#{isActivated} AS SIGNED)
|
||||||
|
</when>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
and effect_flag=1
|
and effect_flag=1
|
||||||
</where>
|
</where>
|
||||||
|
|
||||||
|
|
@ -228,4 +251,11 @@
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="selectUserRoles" parameterType="String" resultType="String">
|
||||||
|
select r.role_name from ed_role r where r.role_id in (
|
||||||
|
select ur.role_id from ed_users u
|
||||||
|
left join ed_user_role ur on u.user_id = ur.user_id
|
||||||
|
where u.user_id = #{userId})
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -8,10 +8,15 @@ public interface UserConstants {
|
||||||
String DEFAULT_PASSWORD = "123456";
|
String DEFAULT_PASSWORD = "123456";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认发布状态(未发布)
|
* 默认发布状态(未发布) 系统管理员
|
||||||
*/
|
*/
|
||||||
int DEFAULT_PUBLISH_STATUS = 0;
|
int DEFAULT_PUBLISH_STATUS = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认激活状态(未激活)安全管理员
|
||||||
|
*/
|
||||||
|
int DEFAULT_ACTIVE_STATUS = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认令牌过期时间(7天)
|
* 默认令牌过期时间(7天)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.electromagnetic.industry.software.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
/**
|
||||||
|
* 安全管理员
|
||||||
|
*/
|
||||||
|
public enum ActiveEnum {
|
||||||
|
/**
|
||||||
|
* 已发布
|
||||||
|
*/
|
||||||
|
ACTIVATED(1, "已激活"),
|
||||||
|
/**
|
||||||
|
* 未发布
|
||||||
|
*/
|
||||||
|
UNACTIVATED(0, "未激活"),
|
||||||
|
;
|
||||||
|
private final Integer code;
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue