wangliang 3 rokov pred
rodič
commit
3c58dfdda1

+ 118 - 0
distributed-print/src/main/java/com/qmth/distributed/print/api/SysRoleController.java

@@ -0,0 +1,118 @@
+package com.qmth.distributed.print.api;
+
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.SysRole;
+import com.qmth.teachcloud.common.service.SysRoleService;
+import com.qmth.teachcloud.common.util.Result;
+import com.qmth.teachcloud.common.util.ResultUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * <p>
+ * 角色表 前端控制器
+ * </p>
+ *
+ * @author xf
+ * @since 2021-03-23
+ */
+@Api(tags = "角色Controller")
+@RestController
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.sys}/role")
+@Validated
+public class SysRoleController {
+
+    @Autowired
+    private SysRoleService sysRoleService;
+
+    /**
+     * 查询
+     *
+     * @param name
+     * @param enable
+     * @param pageNumber
+     * @param pageSize
+     * @return
+     */
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "/list", method = RequestMethod.POST)
+    public Result list(@RequestParam(value = "name", required = false) String name,
+                       @RequestParam(value = "enable", required = false) Boolean enable,
+                       @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                       @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        return ResultUtil.ok(sysRoleService.list(name, enable, pageNumber, pageSize));
+    }
+
+    /**
+     * 新增用户时查询角色方法
+     *
+     * @return
+     */
+    @ApiOperation(value = "新增用户时查询角色方法")
+    @RequestMapping(value = "/list_to_user", method = RequestMethod.POST)
+    public Result listToUser() {
+        return ResultUtil.ok(sysRoleService.listToUser());
+    }
+
+    /**
+     * 新增/修改
+     *
+     * @param role
+     * @return
+     */
+    @ApiOperation(value = "新增/修改")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    public Result save(@Valid @RequestBody SysRole role, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        return ResultUtil.ok(sysRoleService.saveRoleNew(role));
+    }
+
+    /**
+     * 启用/禁用
+     *
+     * @param role
+     * @return
+     */
+    @ApiOperation(value = "启用/禁用")
+    @RequestMapping(value = "/enable", method = RequestMethod.POST)
+    public Result enable(@RequestBody SysRole role) throws NoSuchAlgorithmException {
+        return ResultUtil.ok(sysRoleService.enableReport(role));
+    }
+
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    @ApiOperation(value = "删除")
+    @RequestMapping(value = "/remove", method = RequestMethod.POST)
+    public Result remove(@RequestParam(value = "id", required = true) Long id) {
+        return ResultUtil.ok(sysRoleService.removeReport(id));
+    }
+
+    /**
+     * 用户已绑定角色列表
+     *
+     * @param userId
+     * @return
+     */
+    @ApiOperation(value = "用户已绑定角色列表")
+    @RequestMapping(value = "/get_user_roles", method = RequestMethod.POST)
+    public Result getUserRoles(@RequestParam(value = "userId", required = true) Long userId) {
+        return ResultUtil.ok(sysRoleService.getUserRoles(userId));
+    }
+}
+

+ 12 - 13
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysRoleServiceImpl.java

@@ -146,6 +146,18 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
             } else if (Objects.nonNull(schoolId)) {
                 role.setSchoolId(schoolId);
             }
+            // 系统默认内置角色(不允许和系统默认角色重名)
+            List<String> defaultRoleNames = this.list(new QueryWrapper<SysRole>().lambda()
+                            .eq(SysRole::getDefaultRole, true)
+                            .eq(SysRole::getEnable, true))
+                    .stream()
+                    .map(SysRole::getName)
+                    .distinct()
+                    .collect(Collectors.toList());
+            String roleName = role.getName();
+            if (defaultRoleNames.contains(roleName)) {
+                throw ExceptionResultEnum.ERROR.exception("自定义角色名称不能和系统默认角色【" + roleName + "】同名");
+            }
             if (Objects.nonNull(role.getId())) {//编辑
                 List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(role.getId());
                 QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
@@ -212,19 +224,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
             } else if (Objects.nonNull(schoolId)) {
                 role.setSchoolId(schoolId);
             }
-            // 系统默认内置角色(不允许和系统默认角色重名)
-            List<String> defaultRoleNames = this.list(new QueryWrapper<SysRole>().lambda()
-                    .eq(SysRole::getDefaultRole,true)
-                    .eq(SysRole::getEnable,true))
-                    .stream()
-                    .map(SysRole::getName)
-                    .distinct()
-                    .collect(Collectors.toList());
-            String roleName = role.getName();
-            if (defaultRoleNames.contains(roleName)){
-                throw ExceptionResultEnum.ERROR.exception("自定义角色名称不能和系统默认角色【" + roleName + "】同名");
-            }
-
             if (Objects.nonNull(role.getId())) {//编辑
                 List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(role.getId());
                 QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();

+ 1 - 1
teachcloud-common-api/src/main/java/com/qmth/teachcloud/common/api/api/SysRoleController.java → teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/SysRoleController.java

@@ -1,4 +1,4 @@
-package com.qmth.teachcloud.common.api.api;
+package com.qmth.teachcloud.report.api;
 
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.teachcloud.common.contant.SystemConstant;