Bladeren bron

feat(web): 新增角色管理功能并优化租户支持

- 在 AddRoleParam 和 RoleListDTO 中添加 tenantId 字段以支持多租户
- 为 TblRole 实体类增加 tenantId 属性
- 更新 WebGateway 接口,将 disableRole 方法替换为 deleteRole 并调整参数类型
- 修改 TblRoleServiceImpl 中的 queryByRoleCode 方法提高代码简洁性
- 在 WebGatewayImpl 中实现新的 deleteRole 逻辑,使用软删除替代禁用状态- 新增 WebRoleController 控制器统一处理角色相关请求
- 移除旧的角色接口方法从 WebSystemController 中- 添加新的错误枚举项 ROLE_ID_IS_NULL用于校验 roleId 参数
- 实现 logout 方法增强用户会话管理
hxd 3 weken geleden
bovenliggende
commit
da0132c1f1

+ 49 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebRoleController.java

@@ -0,0 +1,49 @@
+package com.hfln.portal.application.controller.web;
+
+
+import cn.hfln.framework.catchlog.CatchAndLog;
+import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.dto.data.role.RoleListDTO;
+import com.hfln.portal.common.request.web.AddRoleParam;
+import com.hfln.portal.domain.gateway.WebGateway;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
+
+@RestController
+@CatchAndLog
+@Tag(name = "web端角色相关")
+@Slf4j
+@RequestMapping("/web/role")
+public class WebRoleController {
+    @Autowired
+    private WebGateway webGateway;
+
+    @PostMapping("/add")
+    @Operation(summary = "新增角色")
+    public ApiResult<Void> addRole(@RequestBody @Valid AddRoleParam params) {
+
+        webGateway.addRole(params);
+        return ApiResult.success();
+    }
+
+    @PostMapping("/delete")
+    @Operation(summary = "禁用角色")
+    public ApiResult<Void> deleteRole(@RequestParam Long roleId) {
+
+        webGateway.deleteRole(roleId);
+        return ApiResult.success();
+    }
+
+    @GetMapping("/queryList")
+    @Operation(summary = "获取角色列表")
+    public ApiResult<List<RoleListDTO>> roleList() {
+        List<RoleListDTO> roleList = webGateway.roleList();
+        return ApiResult.success(roleList);
+    }
+}

+ 0 - 23
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebSystemController.java

@@ -6,7 +6,6 @@ import cn.hfln.framework.dto.ApiResult;
 import com.hfln.portal.common.dto.data.menu.MenuListDTO;
 import com.hfln.portal.common.dto.data.menu.MenuTreeDTO;
 import com.hfln.portal.common.dto.data.parameter.ParameterDTO;
-import com.hfln.portal.common.dto.data.role.RoleListDTO;
 import com.hfln.portal.common.dto.data.rolemenu.RoleMenuTreeDTO;
 import com.hfln.portal.common.request.web.*;
 import com.hfln.portal.domain.gateway.WebGateway;
@@ -32,28 +31,6 @@ public class WebSystemController {
     @Autowired
     private WebGateway webGateway;
 
-    @PostMapping("/addRole")
-    @Operation(summary = "新增角色")
-    public ApiResult<Void> addRole(@RequestBody @Valid AddRoleParam params) {
-
-        webGateway.addRole(params);
-        return ApiResult.success();
-    }
-
-    @PostMapping("/disable")
-    @Operation(summary = "禁用角色")
-    public ApiResult<Void> disableRole(@RequestParam @Parameter(description = "角色编码") String roleCode) {
-
-        webGateway.disableRole(roleCode);
-        return ApiResult.success();
-    }
-
-    @GetMapping("/roleList")
-    @Operation(summary = "获取角色列表")
-    public ApiResult<List<RoleListDTO>> roleList() {
-        List<RoleListDTO> roleList = webGateway.roleList();
-        return ApiResult.success(roleList);
-    }
 
     @PostMapping("/addMenu")
     @Operation(summary = "添加菜单")

+ 3 - 0
portal-service-common/src/main/java/com/hfln/portal/common/dto/data/role/RoleListDTO.java

@@ -22,4 +22,7 @@ public class RoleListDTO extends BaseDto {
 
     @Schema(description = "角色描述")
     private String roleDesc;
+
+    @Schema(description = "租户id")
+    private Long tenantId;
 }

+ 1 - 23
portal-service-common/src/main/java/com/hfln/portal/common/request/web/AddRoleParam.java

@@ -1,23 +1 @@
-package com.hfln.portal.common.request.web;
-
-import com.hfln.portal.common.vo.BaseVO;
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import javax.validation.constraints.NotBlank;
-
-
-@Data
-public class AddRoleParam extends BaseVO {
-
-    @Schema(description = "角色编码")
-    @NotBlank(message = "角色编码不能为空!")
-    private String roleCode;
-
-    @Schema(description = "角色名称")
-    @NotBlank(message = "角色名称不能为空!")
-    private String roleName;
-
-    @Schema(description = "角色描述")
-    private String roleDesc;
-}
+package com.hfln.portal.common.request.web;

import com.hfln.portal.common.vo.BaseVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;


@Data
public class AddRoleParam extends BaseVO {

    @Schema(description = "角色编码")
    @NotBlank(message = "角色编码不能为空!")
    private String roleCode;

    @Schema(description = "角色名称")
    @NotBlank(message = "角色名称不能为空!")
    private String roleName;

    @Schema(description = "角色描述")
    private String roleDesc;

    @Schema(description = "所属租户")
    private Long tenantId;
}

+ 1 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/exception/ErrorEnum.java

@@ -104,6 +104,7 @@ public enum ErrorEnum implements ErrorEnumInterface {
     ROLE_ALREADY_DISABLED("90002", "角色已禁用!"),
     ROLE_CODE_NOT_NULL("90003", "角色编码不能为空!"),
     ROLE_NOT_EXIST("90004", "角色不存在!"),
+    ROLE_ID_IS_NULL("90005", "角色ID不能为空!"),
 
     /**
      * 分享相关

+ 3 - 2
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebGateway.java

@@ -35,6 +35,8 @@ public interface WebGateway {
 
     void sendCode();
 
+    void logout();
+
     /**
      * web超管相关
      */
@@ -48,11 +50,10 @@ public interface WebGateway {
      */
     void addRole(AddRoleParam param);
 
-    void disableRole(String roleCode);
+    void deleteRole(Long roleId);
 
     List<RoleListDTO> roleList();
 
-    void logout();
 
 
     /**

+ 9 - 13
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java

@@ -444,25 +444,21 @@ public class WebGatewayImpl implements WebGateway {
     }
 
     @Override
-    public void disableRole(String roleCode) {
-        //1.判断roleCode非
-        if (Objects.isNull(roleCode)) {
-            throw new BizException(ErrorEnum.ROLE_CODE_NOT_NULL.getErrorCode(), ErrorEnum.ROLE_CODE_NOT_NULL.getErrorMessage());
+    public void deleteRole(Long roleId) {
+        // 1.判断roleId是否为
+        if (roleId == null) {
+            throw new BizException(ErrorEnum.ROLE_ID_IS_NULL.getErrorCode(), ErrorEnum.ROLE_ID_IS_NULL.getErrorMessage());
         }
-        TblRole role = tblRoleService.queryByRoleCode(roleCode);
-        //2.判断rolecode是否存在
+
+        // 2.判断要删除的角色是否存在
+        TblRole role = tblRoleService.getById(roleId);
         if (role == null) {
             throw new BizException(ErrorEnum.ROLE_NOT_EXIST.getErrorCode(), ErrorEnum.ROLE_NOT_EXIST.getErrorMessage());
         }
 
-        //3.检查角色是否已经禁用
-        if (Objects.equals(role.getIsDeleted(), 1)) {
-            throw new BizException(ErrorEnum.ROLE_ALREADY_DISABLED.getErrorCode(), ErrorEnum.ROLE_ALREADY_DISABLED.getErrorMessage());
-        }
-
-        //4.将对应数据is_deleted 字段置为1
+        // 3.软删除
         role.setIsDeleted(BasePO.DeleteFlag.DELETED);
-        tblRoleService.updateById(role);
+        tblRoleService.removeById(role);
     }
 
     @Override

+ 6 - 1
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/po/TblRole.java

@@ -32,4 +32,9 @@ public class TblRole extends BasePO {
      * 角色描述
      */
     private String roleDesc;
-} 
+
+    /**
+     * 租户id
+     */
+    private Long tenantId;
+}

+ 1 - 2
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/TblRoleServiceImpl.java

@@ -38,8 +38,7 @@ public class TblRoleServiceImpl extends ServiceImpl<TblRoleMapper, TblRole> impl
         LambdaQueryWrapper<TblRole> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(TblRole::getRoleCode, roleCode);
         queryWrapper.eq(TblRole::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
-        TblRole tblRole = this.baseMapper.selectOne(queryWrapper);
-        return tblRole;
+        return this.baseMapper.selectOne(queryWrapper);
     }