优化:部门新增类型字段,用于标识部门是系统内置或自定义

1.系统内置部门不允许禁用、删除、修改上级部门
2.抽取 getAncestors 方法,用于复用获取祖级列表
3.删除部门时,自动删除角色和部门关联
This commit is contained in:
2023-03-19 22:10:37 +08:00
parent 6b73aeb8a9
commit b345e4450d
16 changed files with 169 additions and 52 deletions

View File

@@ -144,7 +144,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
@Operation(summary = "新增数据")
@ResponseBody
@PostMapping
protected R<Long> add(@Validated @RequestBody C request) {
protected R<Long> add(@Validated(BaseRequest.Add.class) @RequestBody C request) {
this.checkPermission("add");
Long id = baseService.add(request);
return R.ok("新增成功", id);
@@ -162,7 +162,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
@Operation(summary = "修改数据")
@ResponseBody
@PutMapping("/{id}")
protected R update(@Validated @RequestBody C request, @PathVariable Long id) {
protected R update(@Validated(BaseRequest.Update.class) @RequestBody C request, @PathVariable Long id) {
this.checkPermission("update");
baseService.update(request, id);
return R.ok("修改成功");

View File

@@ -25,6 +25,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* VO 基类
@@ -63,4 +64,10 @@ public class BaseVO implements Serializable {
@Schema(description = "创建时间")
@ExcelProperty(value = "创建时间")
private LocalDateTime createTime;
/**
* 是否禁用修改
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean disabled;
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.cnadmin.common.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import top.charles7c.cnadmin.common.base.BaseEnum;
/**
* 数据类型枚举
*
* @author Charles7c
* @since 2023/3/19 12:17
*/
@Getter
@RequiredArgsConstructor
public enum DataTypeEnum implements BaseEnum<Integer, String> {
/** 系统内置 */
SYSTEM(1, "系统内置"),
/** 自定义 */
CUSTOM(2, "自定义"),;
private final Integer value;
private final String description;
}