提交 da7f1eb6 作者: 洪东保

权限相关接口

父级 23a57087
......@@ -7,6 +7,7 @@ import com.cmeeting.constant.PermissionPruposeType;
import com.cmeeting.pojo.ModulePermission;
import com.cmeeting.service.ModulePermissionService;
import com.cmeeting.util.R;
import com.cmeeting.vo.AuthVO;
import com.cmeeting.vo.PermissionVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -47,14 +48,15 @@ public class PermissionController {
* 授权用户
* @param vo
* @return
* TODO 授权所有人未处理
*/
@PostMapping("/auth")
public R auth(@Validated @RequestBody PermissionVO.Auth vo) {
public R auth(@Validated @RequestBody AuthVO vo) {
return R.ok(modulePermissionService.auth(vo.getAuthData()));
}
@PostMapping("/remove")
public R remove(@Validated PermissionVO.Add vo) {
public R remove(@Validated @RequestBody AuthVO.Add vo) {
boolean needTarget = vo.getPurpose().equals(PermissionPruposeType.TEMPLATE_TYPE_PERMISSION)
|| vo.getPurpose().equals(PermissionPruposeType.TEMPLATE_PERMISSION);
if (needTarget && vo.getTargetId() == null) {
......
......@@ -44,6 +44,7 @@ public class PermissionCheckedDTO implements Serializable {
* 0 部门 / 1 用户
*/
private Integer type;
private Integer userType;
private String name;
private String deptName;
}
......
......@@ -3,6 +3,7 @@ package com.cmeeting.service;
import com.cmeeting.dto.PermissionCheckedDTO;
import com.cmeeting.pojo.ModulePermission;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cmeeting.vo.AuthVO;
import com.cmeeting.vo.PermissionVO;
import java.util.List;
......@@ -19,7 +20,7 @@ public interface ModulePermissionService extends IService<ModulePermission> {
List<PermissionCheckedDTO.CateOrUser> checkedList(String search, Integer purpose, Long targetId);
Boolean auth(List<PermissionVO.Add> authData);
Boolean auth(List<AuthVO.Add> authData);
List<PermissionCheckedDTO.User> personalCancelList();
}
......@@ -15,6 +15,7 @@ import com.cmeeting.service.IShareUserService;
import com.cmeeting.service.ModulePermissionService;
import com.cmeeting.mapper.primary.ModulePermissionMapper;
import com.cmeeting.service.SysUserSyncService;
import com.cmeeting.vo.AuthVO;
import com.cmeeting.vo.PermissionVO;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
......@@ -51,20 +52,23 @@ public class ModulePermissionServiceImpl extends ServiceImpl<ModulePermissionMap
Set<String> deptIds = permissions.stream()
.filter(e -> e.getType().equals(RecordTemplateConstant.REL_TYPE_DEPT))
.map(ModulePermission::getRelId).collect(Collectors.toSet());
Set<String> userIds = permissions.stream().filter(e -> e.getType().equals(RecordTemplateConstant.REL_TYPE_USER))
.map(ModulePermission::getRelId).collect(Collectors.toSet());
// 授权了所有人
boolean all = userIds.contains(CategoryConstant.ALL_EN) || deptIds.contains(CategoryConstant.ALL_EN);
List<PermissionCheckedDTO.Category> categoryList = dto.getCategoryList();
if (CollUtil.isNotEmpty(deptIds) && CollUtil.isEmpty(categoryList)) {
for (PermissionCheckedDTO.Category category : categoryList) {
if (deptIds.contains(category.getId())) {
if (all || deptIds.contains(category.getId())) {
category.setCheck(true);
}
}
}
List<PermissionCheckedDTO.User> userList = dto.getUserList();
Set<String> userIds = permissions.stream().filter(e -> e.getType().equals(RecordTemplateConstant.REL_TYPE_USER))
.map(ModulePermission::getRelId).collect(Collectors.toSet());
if (CollUtil.isNotEmpty(userIds) && CollUtil.isEmpty(userList)) {
for (PermissionCheckedDTO.User user : userList) {
if (userIds.contains(user.getId())) {
if (all || userIds.contains(user.getId())) {
user.setCheck(true);
}
}
......@@ -99,34 +103,45 @@ public class ModulePermissionServiceImpl extends ServiceImpl<ModulePermissionMap
.eq(targetId != null, ModulePermission::getTargetId, targetId)
.select(ModulePermission::getRelId, ModulePermission::getType)
);
if (CollUtil.isNotEmpty(modulePermissions)) {
List<String> cateIds = modulePermissions.stream().filter(e -> Objects.equals(e.getType(), RecordTemplateConstant.REL_TYPE_DEPT)).map(ModulePermission::getRelId).collect(Collectors.toList());
List<String> userIds = modulePermissions.stream().filter(e -> Objects.equals(e.getType(), RecordTemplateConstant.REL_TYPE_USER)).map(ModulePermission::getRelId).collect(Collectors.toList());
Set<String> ids = modulePermissions.stream().map(ModulePermission::getRelId).collect(Collectors.toSet());
if (CollUtil.isNotEmpty(ids) && ids.contains(CategoryConstant.ALL_EN)) {
PermissionCheckedDTO.CateOrUser cateOrUser = PermissionCheckedDTO.CateOrUser.builder()
.id(CategoryConstant.ALL_EN).name("所有人").deptName("所有人").userType(UserTypeConstant.SYNC).type(RecordTemplateConstant.REL_TYPE_USER).build();
retList.add(cateOrUser);
return retList;
}
PermissionCheckedDTO permissionCheckedDTO = permissionList(search, null, null, purpose, cateIds, userIds);
if (CollUtil.isNotEmpty(permissionCheckedDTO.getUserList())) {
for (PermissionCheckedDTO.User user : permissionCheckedDTO.getUserList()) {
if (userIds.contains(user.getId())) {
PermissionCheckedDTO.CateOrUser cateOrUser = PermissionCheckedDTO.CateOrUser.builder()
.id(user.getId()).name(user.getName()).deptName(user.getDeptName()).type(RecordTemplateConstant.REL_TYPE_USER).build();
.id(user.getId()).name(user.getName()).deptName(user.getDeptName()).userType(user.getUserType()).type(RecordTemplateConstant.REL_TYPE_USER).build();
retList.add(cateOrUser);
}
}
}
if (CollUtil.isNotEmpty(permissionCheckedDTO.getCategoryList())) {
for (PermissionCheckedDTO.Category category : permissionCheckedDTO.getCategoryList()) {
if (cateIds.contains(category.getId())) {
PermissionCheckedDTO.CateOrUser cateOrUser = PermissionCheckedDTO.CateOrUser.builder()
.id(category.getId()).name(category.getName()).deptName(category.getName()).type(RecordTemplateConstant.REL_TYPE_DEPT).build();
.id(category.getId()).name(category.getName()).deptName(category.getName()).userType(category.getUserType()).type(RecordTemplateConstant.REL_TYPE_DEPT).build();
retList.add(cateOrUser);
}
}
}
}
return retList;
}
@Override
public Boolean auth(List<PermissionVO.Add> authData) {
public Boolean auth(List<AuthVO.Add> authData) {
if (CollUtil.isNotEmpty(authData)) {
List<ModulePermission> list = new ArrayList<>();
for (PermissionVO.Add authDatum : authData) {
for (AuthVO.Add authDatum : authData) {
ModulePermission permission = BeanUtil.copyProperties(authDatum, ModulePermission.class);
permission.setCreateTime(new Date());
list.add(permission);
......
package com.cmeeting.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthVO {
@NotEmpty(message = "param ids cant be null!")
private List<Add> authData;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Add {
/**
* 类型,0-分类,1-用户
*/
@NotNull
private Integer type;
/**
* 用户类型,2-通讯录,3-超管分享
*/
@NotNull
private Integer userType;
/**
* 0-授权纪要功能,1-纪要类型分享,2-纪要模板分享,3-用户自己关闭纪要功能
*/
@NotNull
private Integer purpose;
/**
* 关联id(分类id或用户id) 为all时 表示所有人授权/清空所有权限
*/
@NotNull
private String relId;
/**
* purpose为0/3时为空,为1时是纪要类型id,2时纪要模板id
*/
private Long targetId;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Remove {
/**
* 类型,0-分类,1-用户
*/
@NotNull
private Integer type;
/**
* 用户类型,2-通讯录,3-超管分享
*/
@NotNull
private Integer userType;
/**
* 0-授权纪要功能,1-纪要类型分享,2-纪要模板分享,3-用户自己关闭纪要功能
*/
@NotNull
private Integer purpose;
/**
* 关联id(分类id或用户id) 为all时 表示所有人授权/清空所有权限
*/
@NotNull
private String relId;
/**
* purpose为0/3时为空,为1时是纪要类型id,2时纪要模板id
*/
private Long targetId;
}
}
......@@ -52,45 +52,5 @@ public class PermissionVO {
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Auth {
@NotEmpty(message = "param ids cant be null!")
private List<Add> authData;
}
@Data
public static class Add {
/**
* 类型,0-分类,1-用户
*/
@NotNull
private Integer type;
/**
* 用户类型,2-通讯录,3-超管分享
*/
@NotNull
private Integer userType;
/**
* 0-授权纪要功能,1-纪要类型分享,2-纪要模板分享,3-用户自己关闭纪要功能
*/
@NotNull
private Integer purpose;
/**
* 关联id(分类id或用户id) 为all时 表示所有人授权/清空所有权限
*/
@NotNull
private String relId;
/**
* purpose为0/3时为空,为1时是纪要类型id,2时纪要模板id
*/
private Long targetId;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论