TRX 1 년 전
부모
커밋
5e34c509a0

+ 24 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/AuthModel.java

@@ -0,0 +1,24 @@
+package com.zhongshu.card.client.model.org;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class AuthModel implements Serializable {
+
+    private String modularName;
+
+    @Schema(description = "权限名称")
+    private String name;
+
+    @Schema(description = "权限值")
+    private String value;
+
+    @Schema(description = "是否已有该权限")
+    private boolean select;
+
+    @Schema(description = "排序")
+    private int index = 0;
+}

+ 20 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/EditAuthParam.java

@@ -0,0 +1,20 @@
+package com.zhongshu.card.client.model.org;
+
+import com.zhongshu.card.client.utils.type.EditType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.Set;
+
+@Data
+public class EditAuthParam {
+
+    @Schema(description = "角色ID")
+    private String roleId;
+
+    @Schema(description = "操作类型")
+    private EditType type;
+
+    @Schema(description = "权限列表")
+    private Set<String> auths;
+}

+ 17 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/ModularModel.java

@@ -0,0 +1,17 @@
+package com.zhongshu.card.client.model.org;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class ModularModel implements Serializable {
+
+    @Schema(description = "分组名称,如:角色管理")
+    private String name;
+
+    @Schema(description = "权限列表")
+    private List<AuthModel> authModels;
+}

+ 7 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/utils/type/EditType.java

@@ -0,0 +1,7 @@
+package com.zhongshu.card.client.utils.type;
+
+public enum EditType {
+
+    Add,
+    Remove
+}

+ 32 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/RoleController.java

@@ -14,10 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.web.PageableDefault;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author TRX
@@ -31,6 +28,9 @@ public class RoleController {
     @Autowired
     RoleServiceImpl roleService;
 
+    @ResourceAuth(value = "roleSave", type = AuthType.Platform, remark = "角色管理_添加编辑角色_2")
+    @ResourceAuth(value = "roleSave", type = AuthType.Project, remark = "角色管理_添加编辑角色_2")
+    @ResourceAuth(value = "roleSave", type = AuthType.School, remark = "角色管理_添加编辑角色_2")
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑角色", description = "添加-编辑角色")
     @RequestMapping(value = "addRole", method = {RequestMethod.POST})
@@ -38,6 +38,9 @@ public class RoleController {
         return this.roleService.addRole(param);
     }
 
+    @ResourceAuth(value = "roleList", type = AuthType.Platform, remark = "角色管理_角色列表_1")
+    @ResourceAuth(value = "roleList", type = AuthType.Project, remark = "角色管理_角色列表_1")
+    @ResourceAuth(value = "roleList", type = AuthType.School, remark = "角色管理_角色列表_1")
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "角色列表-分页查询", description = "角色列表-分页查询")
     @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
@@ -54,6 +57,9 @@ public class RoleController {
         return this.roleService.getAllRoles(param.getOid());
     }
 
+    @ResourceAuth(value = "roleDelete", type = AuthType.Platform, remark = "角色管理_删除角色_3")
+    @ResourceAuth(value = "roleDelete", type = AuthType.Project, remark = "角色管理_删除角色_3")
+    @ResourceAuth(value = "roleDelete", type = AuthType.School, remark = "角色管理_删除角色_3")
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "删除角色", description = "删除角色")
     @RequestMapping(value = "deleteRole", method = {RequestMethod.POST})
@@ -61,6 +67,9 @@ public class RoleController {
         return this.roleService.deleteRole(param.getId());
     }
 
+    @ResourceAuth(value = "roleDetail", type = AuthType.Platform, remark = "角色管理_角色详情_4")
+    @ResourceAuth(value = "roleDetail", type = AuthType.Project, remark = "角色管理_角色详情_4")
+    @ResourceAuth(value = "roleDetail", type = AuthType.School, remark = "角色管理_角色详情_4")
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "角色详情", description = "角色详情")
     @RequestMapping(value = "getRole", method = {RequestMethod.POST})
@@ -68,4 +77,23 @@ public class RoleController {
         return this.roleService.getRole(param.getId());
     }
 
+
+    //---------------------------角色权限 start -----------------------
+
+    @Operation(summary = "获取角色的权限列表", description = "获取角色的权限列表")
+    @RequestMapping(value = "getRoleAuthList", method = {RequestMethod.POST})
+    @ResourceAuth(value = "user", type = AuthType.User)
+    public Object getRoleAuthList(
+            @Parameter(name = "roleId", description = "角色数据ID", example = "")
+            @RequestParam("roleId") String roleId) {
+        return roleService.getList(roleId);
+    }
+
+    @Operation(summary = "修改角色权限", description = "修改角色权限")
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "editRoleAuth", method = {RequestMethod.POST})
+    public Object editRoleAuth(EditAuthParam param) {
+        return roleService.editRoleAuth(param);
+    }
+
 }

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/payment/ProjectPaySetting.java

@@ -25,7 +25,7 @@ public class ProjectPaySetting extends SuperMain {
     @Schema(description = "项目id")
     private String projectOid;
 
-    @Schema(description = "项目的支付渠道设置")
+    @Schema(description = "项目的支付渠道设置:微信支付、银联支付")
     private ProjectPayChannelType channelType;
 
 }

+ 3 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/IndexService.java

@@ -33,9 +33,12 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Objects;
+import java.util.Set;
 
 /**
  * @author TRX

+ 153 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/RoleServiceImpl.java

@@ -1,28 +1,37 @@
 package com.zhongshu.card.server.core.service.org;
 
 import com.github.microservice.auth.client.content.ResultState;
+import com.github.microservice.auth.client.model.AuthResourcesNameModel;
 import com.github.microservice.auth.client.model.RoleGroupModel;
+import com.github.microservice.auth.client.service.AuthResourcesNameService;
+import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.zhongshu.card.client.model.org.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.ret.ResultMessage;
 import com.zhongshu.card.client.utils.type.DataState;
+import com.zhongshu.card.client.utils.type.EditType;
 import com.zhongshu.card.client.utils.type.RoleType;
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.org.RoleDao;
+import com.zhongshu.card.server.core.domain.org.Organization;
 import com.zhongshu.card.server.core.domain.org.Role;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.util.BeanUtils;
+import com.zhongshu.card.server.core.util.CommonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -39,6 +48,12 @@ public class RoleServiceImpl extends SuperService {
     @Autowired
     com.github.microservice.auth.client.service.RoleService roleService;
 
+    @Autowired
+    OrganizationDao organizationDao;
+
+    @Autowired
+    private AuthResourcesNameService authResourcesNameService;
+
     /**
      * 添加/编辑角色
      *
@@ -204,6 +219,142 @@ public class RoleServiceImpl extends SuperService {
         return ResultContent.buildSuccess(models);
     }
 
+    /**
+     * 得到角色的权限数据
+     *
+     * @param roleId
+     * @return
+     */
+    public ResultContent getList(String roleId) {
+        Role roleObj = roleDao.findTopById(roleId);
+        if (roleObj == null) {
+            return ResultContent.buildFail("角色不存在");
+        }
+        Organization organization = organizationDao.findTopByOid(roleObj.getOid());
+        if (organization == null) {
+            return ResultContent.buildFail("企业不存在");
+        }
+        //获取该岗位的现在所有的权限
+        var roleGroup = roleService.getRoleGroup(roleObj.getRoleGroupId()).getContent();
+        Set<String> postAuth = new HashSet<>();
+        if (!CollectionUtils.isEmpty(roleGroup.getRoleId())) {
+            roleGroup.getRoleId().parallelStream().forEach(it -> {
+                var role = roleService.getRole(it).getContent();
+                if (role != null && !CollectionUtils.isEmpty(role.getAuth())) {
+                    postAuth.addAll(role.getAuth());
+                }
+            });
+        }
+        return ResultContent.buildContent(buildAuthList(organization.getAuthType(), postAuth));
+    }
+
+    /**
+     * 构建权限树
+     *
+     * @param organizationType
+     * @param postAuth
+     * @return
+     */
+    List<ModularModel> buildAuthList(AuthType organizationType, Set<String> postAuth) {
+        //获取系统所有权限
+        List<AuthResourcesNameModel> authResourcesNameModels = new ArrayList<>();
+        authResourcesNameModels = authResourcesNameService.list(
+                organizationType,
+                PageRequest.of(0, 9999,
+                        Sort.by(Sort.Order.desc("createTime")))).getContent().getContent();
+        List<AuthModel> authModels = new ArrayList<>();
+        authResourcesNameModels.forEach(it -> {
+            String remark = it.getRemark();
+            if (StringUtils.isNotEmpty(remark)) {
+                String[] split = remark.split("_");
+                if (split.length >= 2) {
+                    AuthModel authModel = new AuthModel();
+                    authModel.setValue(it.getName());
+                    authModel.setName(split[1]);
+                    authModel.setModularName(split[0]);
+                    int index = 1;
+                    if (split.length >= 3) {
+                        index = CommonUtil.turnStr2Inter(split[2]);
+                    }
+                    authModel.setIndex(index);
+                    if (postAuth.contains(it.getName())) {
+                        authModel.setSelect(true);
+                    }
+                    authModels.add(authModel);
+                }
+            }
+        });
+
+        Comparator comparator = new Comparator<AuthModel>() {
+            @Override
+            public int compare(AuthModel o1, AuthModel o2) {
+                return Integer.compare(o1.getIndex(), o2.getIndex());
+            }
+        };
+
+        Map<String, List<AuthModel>> maps = authModels.stream().collect(Collectors.groupingBy(AuthModel::getModularName));
+        List<ModularModel> modularModels = new ArrayList<>();
+        maps.forEach((key, val) -> {
+            ModularModel modularModel = new ModularModel();
+            modularModel.setName(key);
+            // 排序
+            if (ObjectUtils.isNotEmpty(val)) {
+                val.sort(comparator);
+            }
+            modularModel.setAuthModels(val);
+            modularModels.add(modularModel);
+        });
+        return modularModels;
+    }
+
+    /**
+     * 改变角色权限
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent editRoleAuth(EditAuthParam param) {
+        Role role = roleDao.findTopById(param.getRoleId());
+        if (role == null) {
+            return ResultContent.buildFail("角色不存在");
+        }
+        var roleGroup = roleService.getRoleGroup(role.getRoleGroupId()).getContent();
+        com.github.microservice.auth.client.model.RoleModel roleModel;
+        if (roleGroup.getRoleId() == null || CollectionUtils.isEmpty(roleGroup.getRoleId())) {
+            // 如果角色不存在,则创建角色
+            var roleByName = roleService.getRoleByName(role.getName(), role.getOid());
+            if (roleByName.getState() != com.github.microservice.auth.client.content.ResultState.Success) {
+                roleModel = new com.github.microservice.auth.client.model.RoleModel();
+                roleModel.setOrganizationId(role.getOid());
+                roleModel.setName(role.getName());
+                roleModel.setRemark(role.getRemark());
+                com.github.microservice.auth.client.content.ResultContent<String> updateRole = roleService.updateRole(roleModel);
+                roleModel.setId(updateRole.getContent());
+            } else {
+                roleModel = roleByName.getContent();
+            }
+            // 权限中心角色绑定角色组
+            roleService.addRoleToRoleGroup(roleGroup.getId(), new String[]{roleModel.getId()});
+        } else {
+            // 角色存在,查询角色信息
+            List<String> roleIds = new ArrayList<>(roleGroup.getRoleId());
+            roleModel = roleService.getRole(roleIds.get(0)).getContent();
+        }
+        Set<String> auth = roleModel.getAuth();
+        if (CollectionUtils.isEmpty(auth)) {
+            auth = new HashSet<>();
+        }
+
+        if (param.getType() == EditType.Add) {
+            auth.addAll(param.getAuths());
+        } else {
+            auth.removeAll(param.getAuths());
+        }
+        roleModel.setAuth(auth);
+        roleService.updateRole(roleModel);
+        return ResultContent.buildSuccess(roleModel);
+    }
+
     public RoleModel toModel(Role role) {
         RoleModel roleModel = new RoleModel();
         if (ObjectUtils.isNotEmpty(role)) {

+ 11 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/CommonUtil.java

@@ -500,4 +500,15 @@ public class CommonUtil {
         return month;
     }
 
+    public static int turnStr2Inter(String val) {
+        if (val != null) {
+            try {
+                return Integer.parseInt(val);
+            } catch (Exception e) {
+                log.error(e.getMessage());
+            }
+        }
+        return 0;
+    }
+
 }