资料中心
parent
e68f1127f3
commit
18cf4b4469
|
|
@ -0,0 +1,63 @@
|
|||
package com.gunshi.project.ss.controller;
|
||||
|
||||
|
||||
import com.gunshi.project.ss.entity.vo.UserRoleVo;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import com.gunshi.project.ss.service.DocCategoryService;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "资料类别")
|
||||
@RestController
|
||||
@RequestMapping(value = "/docCategory")
|
||||
public class DocCategoryController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DocCategoryService docCategoryService;
|
||||
|
||||
@Operation(summary = "新增分类")
|
||||
@PostMapping("/insert")
|
||||
public R<Boolean> insert(@RequestBody DocCategory docCategory){
|
||||
Boolean flg = docCategoryService.insert(docCategory);
|
||||
return R.ok(flg);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新分类")
|
||||
@PostMapping("/edit")
|
||||
public R<Boolean> edit(@RequestBody DocCategory docCategory){
|
||||
Boolean flg = docCategoryService.edit(docCategory);
|
||||
return R.ok(flg);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新分类")
|
||||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> edit(@PathVariable("id") Long id){
|
||||
Boolean flg = docCategoryService.del(id);
|
||||
return R.ok(flg);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取树状结构和配置的权限")
|
||||
@GetMapping("/list")
|
||||
public R<DocCategory> list() {
|
||||
DocCategory docCategory = docCategoryService.tree();
|
||||
return R.ok(docCategory);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取全部角色/部门下用户")
|
||||
@GetMapping("/getAllUserAndRole")
|
||||
public R<UserRoleVo> getAllUserAndRole(){
|
||||
UserRoleVo vo = docCategoryService.getAllUserAndRole();
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "检查是否有权限")
|
||||
@GetMapping("/checkPermission/{userId}/{docCategoryId}")
|
||||
public R<String[]> checkPermission(@PathVariable("userId") Long userId,@PathVariable("docCategoryId") Long docCategoryId){
|
||||
String[] strings = docCategoryService.checkPermission(docCategoryId, userId);
|
||||
return R.ok(strings);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.gunshi.project.ss.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DocSysDeptUserVo {
|
||||
private String deptId;
|
||||
|
||||
private String deptName;
|
||||
|
||||
private List<DocSysDeptUserVo> children;
|
||||
|
||||
private List<DocSysUserVo> users;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.gunshi.project.ss.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DocSysRoleVo {
|
||||
|
||||
private String roleId;
|
||||
|
||||
private String roleName;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.gunshi.project.ss.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DocSysUserVo {
|
||||
|
||||
private String userId;
|
||||
|
||||
private String userName;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.gunshi.project.ss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DocCategoryMapper extends BaseMapper<DocCategory> {
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.gunshi.project.ss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.ss.model.DocPermissionConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DocPermissionConfigMapper extends BaseMapper<DocPermissionConfig> {
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.gunshi.project.ss.model;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.functions.Insert;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.project.ss.common.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("doc_category")
|
||||
@Schema(description = "资料类别表")
|
||||
public class DocCategory {
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@NotNull(message = "id不能为空", groups = {Update.class})
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@TableField("category_name")
|
||||
@NotNull(message = "分类名称不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "分类名称")
|
||||
private String categoryName;
|
||||
|
||||
@TableField("parent_id")
|
||||
@Schema(description = "父级id 0为第一级")
|
||||
private Long parentId;
|
||||
|
||||
@TableField("category_code")
|
||||
@Schema(description = "当前类目代码")
|
||||
private String categoryCode;
|
||||
|
||||
@TableField("sort_order")
|
||||
@Schema(description = "显示顺序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@TableField("create_time")
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("level")
|
||||
@Schema(description = "当前层级")
|
||||
private Integer level;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "子分类列表")
|
||||
private List<DocCategory> children;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "所有者权限")
|
||||
private List<DocPermissionConfig> permissions;
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.gunshi.project.ss.model;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.functions.Insert;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.project.ss.common.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("doc_center")
|
||||
@Schema(description = "资料中心")
|
||||
public class DocCenter {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@NotNull(message = "id不能为空", groups = {Update.class})
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@TableField("doc_name")
|
||||
@NotNull(message = "档案名称不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "档案名称")
|
||||
private String docName;
|
||||
|
||||
@TableField("replace_id")
|
||||
@NotNull(message = "替换档案id不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "替换档案id")
|
||||
private Long replaceId;
|
||||
|
||||
@TableField("doc_category_id")
|
||||
@Schema(description = "资料类别id")
|
||||
private Integer docCategoryId;
|
||||
|
||||
@TableField("group_id")
|
||||
@Schema(description = "组id - 用于替换档案时")
|
||||
private Long groupId;
|
||||
|
||||
@TableField("doc_number")
|
||||
@NotNull(message = "档案编号不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "档案编号SS-XX-XX-0000")
|
||||
private String docNumber;
|
||||
|
||||
@TableField("doc_version")
|
||||
@Schema(description = "档案版本")
|
||||
private Integer docVersion;
|
||||
|
||||
@TableField("create_time")
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("abolish_time")
|
||||
@Schema(description = "废止时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime abolishTime;
|
||||
|
||||
@TableField("user_id")
|
||||
@Schema(description = "归档人id")
|
||||
private Long userId;
|
||||
|
||||
@TableField("business_name")
|
||||
@Schema(description = "业务名称(用于不同业务文件归档后的文件查询)")
|
||||
private String businessName;
|
||||
|
||||
@TableField("secret_level")
|
||||
@Schema(description = "保密级别 0公开 1秘密 2机密")
|
||||
private Integer secretLevel;
|
||||
|
||||
@TableField("is_abolish")
|
||||
@Schema(description = "0未废止 1已废止")
|
||||
private Integer isAbolish;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "归档人名称")
|
||||
private String userName;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "资料分类名称")
|
||||
private String categoryName;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "文件列表")
|
||||
private List<FileAssociations> files;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "操作日志列表")
|
||||
private List<DocOperateLog> logs;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.gunshi.project.ss.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("doc_operate_log")
|
||||
@Schema(description = "档案行为日志表")
|
||||
public class DocOperateLog {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
@TableField("user_id")
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@TableField("operate_type")
|
||||
@Schema(description = "操作类型")
|
||||
private String operateType;
|
||||
|
||||
@TableField("doc_number")
|
||||
@Schema(description = "相关档案编号")
|
||||
private String docNumber;
|
||||
|
||||
@TableField("doc_name")
|
||||
@Schema(description = "档案名称")
|
||||
private String docName;
|
||||
|
||||
@TableField("file_id")
|
||||
@Schema(description = "文件id")
|
||||
private Long fileId;
|
||||
|
||||
@TableField("create_time")
|
||||
@Schema(description = "操作时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "用户名称")
|
||||
private String userName;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "操作类型名称")
|
||||
private String operateTypeName;
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.gunshi.project.ss.model;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.functions.Insert;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.gunshi.project.ss.common.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("doc_permission_config")
|
||||
@Schema(description = "资料权限配置表")
|
||||
public class DocPermissionConfig {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@NotNull(message = "id不能为空", groups = {Update.class})
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
@TableField("category_id")
|
||||
@NotNull(message = "资料分类id不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "资料分类id")
|
||||
private Long categoryId;
|
||||
|
||||
@TableField("target_type")
|
||||
@NotNull(message = "权限目标类型不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "权限目标类型 1-角色,2-人员")
|
||||
private Short targetType;
|
||||
|
||||
@TableField("targer_id")
|
||||
@NotNull(message = "目标ID不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "目标ID(角色ID,或者用户ID)")
|
||||
private Long targerId;
|
||||
|
||||
@TableField("permission_code")
|
||||
@NotNull(message = "权限编码不能为空", groups = {Insert.class, Update.class})
|
||||
@Schema(description = "所有权限,比如:add,edit,delete,view,download 权限以,分隔开")
|
||||
private String permissionCode;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "目标名称(角色名称或用户名称)")
|
||||
private String targetName;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "资料分类名称")
|
||||
private String categoryName;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "权限列表")
|
||||
private List<String> permissions;
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
package com.gunshi.project.ss.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.ss.entity.vo.UserRoleVo;
|
||||
import com.gunshi.project.ss.mapper.DocCategoryMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import com.gunshi.project.ss.model.DocPermissionConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class DocCategoryService extends ServiceImpl<DocCategoryMapper, DocCategory> {
|
||||
|
||||
@Autowired
|
||||
private DocCategoryMapper docCategoryMapper;
|
||||
|
||||
@Autowired
|
||||
private DocPermissionConfigService docPermissionConfigService;
|
||||
|
||||
|
||||
|
||||
public DocCategory tree() {
|
||||
LambdaQueryWrapper<DocCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocCategory::getParentId,0);
|
||||
queryWrapper.last("limit 1");
|
||||
DocCategory docCategory = docCategoryMapper.selectOne(queryWrapper);
|
||||
List<DocCategory> allList = docCategoryMapper.selectList(null);
|
||||
buildTree(docCategory,allList);
|
||||
return docCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采用BFS 非递归方式进行树形结构的构建
|
||||
* @param docCategory
|
||||
* @return
|
||||
*/
|
||||
private DocCategory buildTree(DocCategory docCategory,List<DocCategory> allList) {
|
||||
Queue<DocCategory> docCategoryDeque = new LinkedList<>();
|
||||
if(docCategory != null){
|
||||
docCategoryDeque.add(docCategory);
|
||||
}
|
||||
while(!docCategoryDeque.isEmpty()){
|
||||
int size = docCategoryDeque.size();
|
||||
while(size > 0){
|
||||
DocCategory pop = docCategoryDeque.remove();
|
||||
List<DocCategory> childrens = allList.stream().filter(o -> {
|
||||
return o.getParentId().equals(pop.getId());
|
||||
}).sorted(Comparator.comparing(DocCategory::getSortOrder)) // 升序排列
|
||||
.collect(Collectors.toList());
|
||||
pop.setChildren(childrens);
|
||||
//判断赋予的权限
|
||||
if(pop.getLevel() != null && pop.getLevel() == 3){
|
||||
//只有最后一层才有权限
|
||||
List<DocPermissionConfig> permissions = docPermissionConfigService.getPermissionByDocId(pop.getId());
|
||||
pop.setPermissions(permissions);
|
||||
}
|
||||
childrens.forEach(item -> {docCategoryDeque.add(item);});
|
||||
size--;
|
||||
}
|
||||
}
|
||||
return docCategory;
|
||||
}
|
||||
|
||||
public UserRoleVo getAllUserAndRole() {
|
||||
return docPermissionConfigService.getAllUserAndRole();
|
||||
}
|
||||
|
||||
public Boolean insert(DocCategory docCategory) {
|
||||
docCategory.setCreateTime(LocalDateTime.now());
|
||||
checkCategoryCodeSame(docCategory);
|
||||
save(docCategory);
|
||||
List<DocPermissionConfig> permissions = docCategory.getPermissions();
|
||||
for (DocPermissionConfig permission : permissions) {
|
||||
permission.setCategoryId(docCategory.getId());
|
||||
}
|
||||
docPermissionConfigService.saveBatch(permissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkCategoryCodeSame(DocCategory docCategory) {
|
||||
if(docCategory.getLevel() != 2){
|
||||
return;
|
||||
}
|
||||
String categoryCode = docCategory.getCategoryCode();
|
||||
LambdaQueryWrapper<DocCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocCategory::getLevel,2);
|
||||
queryWrapper.eq(DocCategory::getCategoryCode,categoryCode);
|
||||
Long count = docCategoryMapper.selectCount(queryWrapper);
|
||||
if(count > 0){
|
||||
throw new IllegalArgumentException("对不起,二级类目代码重复,请检查");
|
||||
}
|
||||
}
|
||||
|
||||
public String[] checkPermission(Long docCategoryId,Long loginUserId) {
|
||||
// //对于超级管理员来说,直接赋予所有权限
|
||||
// if(loginUserId == 1l){
|
||||
// return new String[]{"add","edit","delete","view","download"};
|
||||
// }
|
||||
String[] permissions = docPermissionConfigService.checkPermission(docCategoryId,loginUserId);
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public Boolean edit(DocCategory docCategory) {
|
||||
updateById(docCategory);
|
||||
docPermissionConfigService.deleteByDocCategoryId(docCategory.getId());
|
||||
List<DocPermissionConfig> permissions = docCategory.getPermissions();
|
||||
permissions.stream().forEach(item -> {item.setCategoryId(docCategory.getId());});
|
||||
docPermissionConfigService.saveBatch(permissions);
|
||||
//TODO 同步更新所有关联档案的档案号(这里不用该,我到时候直接递归查上来然后进行拼接即可)
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean del(Long id) {
|
||||
LambdaQueryWrapper<DocCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocCategory::getId, id);
|
||||
DocCategory docCategory = this.baseMapper.selectOne(queryWrapper);
|
||||
if(docCategory == null){
|
||||
return true;
|
||||
}
|
||||
Integer level = docCategory.getLevel();
|
||||
if(level == 1){
|
||||
throw new IllegalArgumentException("对不起,无法删除一级类目数据");
|
||||
}else if(level == 2){
|
||||
//如果二级类目下有三级类目,则无法删除
|
||||
LambdaQueryWrapper<DocCategory> childrenQueryWrapper = new LambdaQueryWrapper<>();
|
||||
childrenQueryWrapper.eq(DocCategory::getParentId, docCategory.getId());
|
||||
Long count = this.baseMapper.selectCount(childrenQueryWrapper);
|
||||
if(count > 0){
|
||||
throw new IllegalArgumentException("对不起,该类目下设有下级类目,无法删除");
|
||||
}
|
||||
}else{
|
||||
//TODO 三级类目,如果关联有档案,则无法删除
|
||||
}
|
||||
docPermissionConfigService.deleteByDocCategoryId(docCategory.getId());
|
||||
this.baseMapper.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
package com.gunshi.project.ss.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.ss.entity.vo.DocSysDeptUserVo;
|
||||
import com.gunshi.project.ss.entity.vo.DocSysRoleVo;
|
||||
import com.gunshi.project.ss.entity.vo.DocSysUserVo;
|
||||
import com.gunshi.project.ss.entity.vo.UserRoleVo;
|
||||
import com.gunshi.project.ss.mapper.DocPermissionConfigMapper;
|
||||
import com.gunshi.project.ss.model.DocPermissionConfig;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class DocPermissionConfigService extends ServiceImpl<DocPermissionConfigMapper, DocPermissionConfig> {
|
||||
|
||||
@Autowired
|
||||
private DocPermissionConfigMapper docPermissionConfigMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private SysDeptMapper sysDeptMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
public List<DocPermissionConfig> getPermissionByDocId(Long id) {
|
||||
LambdaQueryWrapper<DocPermissionConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocPermissionConfig::getCategoryId,id);
|
||||
List<DocPermissionConfig> permissionConfigs = docPermissionConfigMapper.selectList(queryWrapper);
|
||||
for (DocPermissionConfig permissionConfig : permissionConfigs) {
|
||||
Short targetType = permissionConfig.getTargetType();
|
||||
if(targetType == 1){
|
||||
//表示是根据角色
|
||||
SysRole sysRole = sysRoleMapper.selectRoleById(permissionConfig.getTargerId());
|
||||
if(sysRole != null){
|
||||
permissionConfig.setTargetName(sysRole.getRoleName());
|
||||
}
|
||||
}else{
|
||||
//表示是按用户id
|
||||
SysUser sysUser = sysUserMapper.selectUserById(permissionConfig.getTargerId());
|
||||
if(sysUser != null){
|
||||
permissionConfig.setTargetName(sysUser.getNickName());
|
||||
}
|
||||
}
|
||||
String permissionCode = permissionConfig.getPermissionCode();
|
||||
if(StringUtils.isNotEmpty(permissionCode)){
|
||||
String[] split = permissionCode.split(",");
|
||||
List<String> permissionList = Arrays.asList(split);
|
||||
permissionConfig.setPermissions(permissionList);
|
||||
}
|
||||
}
|
||||
return permissionConfigs;
|
||||
}
|
||||
|
||||
public UserRoleVo getAllUserAndRole() {
|
||||
UserRoleVo vo = new UserRoleVo();
|
||||
SysRole sysRole = new SysRole();
|
||||
sysRole.setStatus("0");
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectRoleList(sysRole);
|
||||
List<DocSysRoleVo> docSysRoleVos = new ArrayList<>();
|
||||
vo.setDocSysRoles(docSysRoleVos);
|
||||
sysRoles.forEach(sysRole1 -> {
|
||||
DocSysRoleVo docSysRoleVo = new DocSysRoleVo();
|
||||
docSysRoleVo.setRoleName(sysRole1.getRoleName());
|
||||
docSysRoleVo.setRoleId(sysRole1.getRoleId().toString());
|
||||
docSysRoleVos.add(docSysRoleVo);
|
||||
});
|
||||
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setStatus("0");
|
||||
List<SysDept> sysDepts = sysDeptMapper.selectDeptList(sysDept);
|
||||
List<SysDept> topLevelDepts = filterTopLevelDepts(sysDepts);
|
||||
List<DocSysDeptUserVo> docSysDeptUserVos = new ArrayList<>();
|
||||
vo.setDocSysDeptUsers(docSysDeptUserVos);
|
||||
for (SysDept dept : topLevelDepts) {
|
||||
DocSysDeptUserVo docSysDeptUserVo = new DocSysDeptUserVo();
|
||||
docSysDeptUserVo.setDeptId(dept.getDeptId().toString());
|
||||
docSysDeptUserVo.setDeptName(dept.getDeptName());
|
||||
buildDeptTree(docSysDeptUserVo,sysDepts);
|
||||
docSysDeptUserVos.add(docSysDeptUserVo);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public List<SysDept> filterTopLevelDepts(List<SysDept> allDepts) {
|
||||
// 收集所有部门的ID
|
||||
Set<Long> allDeptIds = allDepts.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 找出所有顶级部门
|
||||
return allDepts.stream()
|
||||
.filter(dept -> {
|
||||
Long parentId = dept.getParentId();
|
||||
// 条件1: parentId为null
|
||||
// 条件2: parentId为0(如果0表示顶级)
|
||||
// 条件3: parentId不在现有部门ID列表中
|
||||
return parentId == null
|
||||
|| parentId == 0
|
||||
|| !allDeptIds.contains(parentId);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public DocSysDeptUserVo buildDeptTree(DocSysDeptUserVo doc,List<SysDept> allDepts) {
|
||||
List<SysDept> childrens = new ArrayList<>();
|
||||
for (SysDept dept : allDepts) {
|
||||
String delFlag = dept.getDelFlag();
|
||||
Long parentId = dept.getParentId();
|
||||
if(parentId.toString().equals(doc.getDeptId()) && delFlag.equals("0")){
|
||||
childrens.add(dept);
|
||||
}
|
||||
}
|
||||
if(!childrens.isEmpty()){
|
||||
List<DocSysDeptUserVo> chirldren = new ArrayList<>();
|
||||
childrens.forEach(sysDept -> {
|
||||
DocSysDeptUserVo docSysDeptUserVo = new DocSysDeptUserVo();
|
||||
docSysDeptUserVo.setDeptId(sysDept.getDeptId().toString());
|
||||
docSysDeptUserVo.setDeptName(sysDept.getDeptName());
|
||||
chirldren.add(docSysDeptUserVo);
|
||||
});
|
||||
doc.setChildren(chirldren);
|
||||
for (DocSysDeptUserVo docSysDeptUserVo : chirldren) {
|
||||
buildDeptTree(docSysDeptUserVo,allDepts);
|
||||
}
|
||||
}else{
|
||||
//查看
|
||||
SysUser user = new SysUser();
|
||||
user.setStatus("0");
|
||||
user.setDeptId(Long.valueOf(doc.getDeptId()));
|
||||
List<SysUser> sysUsers = sysUserMapper.selectUserList(user);
|
||||
List<DocSysUserVo> docSysUserVos = new ArrayList<>();
|
||||
doc.setUsers(docSysUserVos);
|
||||
for (SysUser sysUser : sysUsers) {
|
||||
DocSysUserVo docSysUserVo = new DocSysUserVo();
|
||||
docSysUserVo.setUserId(sysUser.getUserId().toString());
|
||||
docSysUserVo.setUserName(sysUser.getUserName());
|
||||
docSysUserVos.add(docSysUserVo);
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
public String[] checkPermission(Long categoryId, Long loginUserId) {
|
||||
LambdaQueryWrapper<DocPermissionConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocPermissionConfig::getCategoryId,categoryId);
|
||||
List<DocPermissionConfig> permissionConfigs = this.baseMapper.selectList(queryWrapper);
|
||||
if(permissionConfigs.isEmpty()){
|
||||
return new String[0];
|
||||
}
|
||||
Short targetType = permissionConfigs.get(0).getTargetType();//只会出现一种
|
||||
if(targetType == 1){
|
||||
//角色
|
||||
SysUser sysUser = sysUserMapper.selectUserById(loginUserId);
|
||||
if(sysUser != null){
|
||||
//根据用户获取角色id
|
||||
List<SysRole> roles = sysUser.getRoles();
|
||||
if(roles.isEmpty()){
|
||||
return new String[0];
|
||||
}
|
||||
List<Long> collect = roles.stream().filter(Objects::nonNull).map(SysRole::getRoleId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
queryWrapper.in(DocPermissionConfig::getTargerId,collect);
|
||||
//去查询
|
||||
List<DocPermissionConfig> permissions = this.baseMapper.selectList(queryWrapper);
|
||||
if(!permissions.isEmpty()){
|
||||
String[] res = null;
|
||||
int ans = 0;
|
||||
for (DocPermissionConfig permission : permissions) {
|
||||
if(StringUtils.isNotEmpty(permission.getPermissionCode())){
|
||||
String[] split = permission.getPermissionCode().split(",");
|
||||
if(split.length > ans){
|
||||
res = split;
|
||||
ans = split.length;
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}else{
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//人员
|
||||
queryWrapper.eq(DocPermissionConfig::getTargerId,loginUserId);
|
||||
DocPermissionConfig docPermissionConfig = this.baseMapper.selectOne(queryWrapper);
|
||||
if(docPermissionConfig != null){
|
||||
String permissionCode = docPermissionConfig.getPermissionCode();
|
||||
if(StringUtils.isNotEmpty(permissionCode)){
|
||||
String[] split = permissionCode.split(",");
|
||||
return split;
|
||||
}else{
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public void deleteByDocCategoryId(Long docCatrgoryId) {
|
||||
LambdaQueryWrapper<DocPermissionConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocPermissionConfig::getCategoryId,docCatrgoryId);
|
||||
this.baseMapper.delete(queryWrapper);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue