diff --git a/README.md b/README.md index 9e6aef9c..3b621e00 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,7 @@ continew-admin │ │ │ └─ online # 在线用户 │ │ └─ system # 系统管理模块 │ │ ├─ dept # 部门管理 + │ │ ├─ role # 角色管理 │ │ └─ user # 用户模块 │ │ └─ center # 个人中心 │ ├─ App.vue # 视图入口 diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/consts/Constants.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/consts/Constants.java new file mode 100644 index 00000000..bfb6aa87 --- /dev/null +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/consts/Constants.java @@ -0,0 +1,35 @@ +/* + * 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.consts; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * 系统常量 + * + * @author Charles7c + * @since 2023/2/9 22:11 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class Constants { + + /** + * 超级管理员角色编码 + */ + public static final String ADMIN_ROLE_CODE = "admin"; +} diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/enums/DataScopeEnum.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/enums/DataScopeEnum.java new file mode 100644 index 00000000..37d210d5 --- /dev/null +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/enums/DataScopeEnum.java @@ -0,0 +1,51 @@ +/* + * 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/2/8 22:58 + */ +@Getter +@RequiredArgsConstructor +public enum DataScopeEnum implements BaseEnum { + + /** 全部数据权限 */ + ALL(1, "全部数据权限"), + + /** 本部门及以下数据权限 */ + DEPT_AND_CHILD(2, "本部门及以下数据权限"), + + /** 本部门数据权限 */ + DEPT(3, "本部门数据权限"), + + /** 仅本人数据权限 */ + SELF(4, "仅本人数据权限"), + + /** 自定数据权限 */ + CUSTOM(5, "自定数据权限"),; + + private final Integer value; + private final String description; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/mapper/RoleMapper.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/mapper/RoleMapper.java new file mode 100644 index 00000000..fb39bbbe --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/mapper/RoleMapper.java @@ -0,0 +1,29 @@ +/* + * 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.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import top.charles7c.cnadmin.system.model.entity.RoleDO; + +/** + * 角色 Mapper + * + * @author Charles7c + * @since 2023/2/8 23:17 + */ +public interface RoleMapper extends BaseMapper {} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/entity/RoleDO.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/entity/RoleDO.java new file mode 100644 index 00000000..b5ff0610 --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/entity/RoleDO.java @@ -0,0 +1,85 @@ +/* + * 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.system.model.entity; + +import java.util.List; + +import lombok.Data; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; + +import top.charles7c.cnadmin.common.base.BaseDO; +import top.charles7c.cnadmin.common.enums.DataScopeEnum; +import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum; + +/** + * 角色实体 + * + * @author Charles7c + * @since 2023/2/8 22:54 + */ +@Data +@TableName(value = "sys_role", autoResultMap = true) +public class RoleDO extends BaseDO { + + private static final long serialVersionUID = 1L; + + /** + * 角色 ID + */ + @TableId + private Long roleId; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色编码 + */ + private String roleCode; + + /** + * 数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限) + */ + private DataScopeEnum dataScope; + + /** + * 数据权限范围(部门 ID 数组) + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List dataScopeDeptIds; + + /** + * 描述 + */ + private String description; + + /** + * 角色排序 + */ + private Integer roleSort; + + /** + * 状态(1启用 2禁用) + */ + private DisEnableStatusEnum status; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/query/RoleQuery.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/query/RoleQuery.java new file mode 100644 index 00000000..88c6253b --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/query/RoleQuery.java @@ -0,0 +1,55 @@ +/* + * 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.system.model.query; + +import java.io.Serializable; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.media.Schema; + +import org.springdoc.api.annotations.ParameterObject; + +import top.charles7c.cnadmin.common.annotation.Query; + +/** + * 角色查询条件 + * + * @author Charles7c + * @since 2023/2/8 23:04 + */ +@Data +@ParameterObject +@Schema(description = "角色查询条件") +public class RoleQuery implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 角色名称 + */ + @Schema(description = "角色名称") + @Query(type = Query.Type.INNER_LIKE) + private String roleName; + + /** + * 状态(1启用 2禁用) + */ + @Schema(description = "状态(1启用 2禁用)") + @Query + private Integer status; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/request/RoleRequest.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/request/RoleRequest.java new file mode 100644 index 00000000..25d667e4 --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/request/RoleRequest.java @@ -0,0 +1,100 @@ +/* + * 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.system.model.request; + +import java.util.List; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.media.Schema; + +import org.hibernate.validator.constraints.Length; + +import top.charles7c.cnadmin.common.base.BaseRequest; +import top.charles7c.cnadmin.common.enums.DataScopeEnum; +import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum; + +/** + * 创建或修改角色信息 + * + * @author Charles7c + * @since 2023/2/8 23:12 + */ +@Data +@Schema(description = "创建或修改角色信息") +public class RoleRequest extends BaseRequest { + + private static final long serialVersionUID = 1L; + + /** + * 角色 ID + */ + @Schema(description = "角色 ID") + @Null(message = "新增时,ID 必须为空", groups = Create.class) + @NotNull(message = "修改时,ID 不能为空", groups = Update.class) + private Long roleId; + + /** + * 角色名称 + */ + @Schema(description = "角色名称") + @NotBlank(message = "角色名称不能为空") + private String roleName; + + /** + * 角色编码 + */ + @Schema(description = "角色编码") + private String roleCode; + + /** + * 数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限) + */ + @Schema(description = "数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)", type = "Integer", + allowableValues = {"1", "2", "3", "4", "5"}) + private DataScopeEnum dataScope; + + /** + * 数据权限范围(部门 ID 数组) + */ + @Schema(description = "数据权限范围(部门 ID 数组)") + private List dataScopeDeptIds; + + /** + * 描述 + */ + @Schema(description = "描述") + @Length(max = 200, message = "描述长度不能超过 200 个字符") + private String description; + + /** + * 角色排序 + */ + @Schema(description = "角色排序") + @NotNull(message = "角色排序不能为空") + private Integer roleSort; + + /** + * 状态(1启用 2禁用) + */ + @Schema(description = "状态(1启用 2禁用)", type = "Integer", allowableValues = {"1", "2"}) + private DisEnableStatusEnum status; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleDetailVO.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleDetailVO.java new file mode 100644 index 00000000..e6478a8b --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleDetailVO.java @@ -0,0 +1,100 @@ +/* + * 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.system.model.vo; + +import java.util.List; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.media.Schema; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; + +import top.charles7c.cnadmin.common.base.BaseDetailVO; +import top.charles7c.cnadmin.common.config.easyexcel.ExcelBaseEnumConverter; +import top.charles7c.cnadmin.common.enums.DataScopeEnum; +import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum; + +/** + * 角色详情信息 + * + * @author Charles7c + * @since 2023/2/1 22:19 + */ +@Data +@ExcelIgnoreUnannotated +@Schema(description = "角色详情信息") +public class RoleDetailVO extends BaseDetailVO { + + private static final long serialVersionUID = 1L; + + /** + * 角色 ID + */ + @Schema(description = "角色 ID") + @ExcelProperty(value = "角色ID") + private Long roleId; + + /** + * 角色名称 + */ + @Schema(description = "角色名称") + @ExcelProperty(value = "角色名称") + private String roleName; + + /** + * 角色编码 + */ + @Schema(description = "角色编码") + @ExcelProperty(value = "角色编码") + private String roleCode; + + /** + * 数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限) + */ + @Schema(description = "数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)") + @ExcelProperty(value = "数据权限", converter = ExcelBaseEnumConverter.class) + private DataScopeEnum dataScope; + + /** + * 数据权限范围(部门 ID 数组) + */ + @Schema(description = "数据权限范围(部门 ID 数组)") + private List dataScopeDeptIds; + + /** + * 描述 + */ + @Schema(description = "描述") + @ExcelProperty(value = "描述") + private String description; + + /** + * 角色排序 + */ + @Schema(description = "角色排序") + @ExcelProperty(value = "角色排序") + private Integer roleSort; + + /** + * 状态(1启用 2禁用) + */ + @Schema(description = "状态(1启用 2禁用)") + @ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class) + private DisEnableStatusEnum status; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleVO.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleVO.java new file mode 100644 index 00000000..7ddb0426 --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/RoleVO.java @@ -0,0 +1,106 @@ +/* + * 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.system.model.vo; + +import java.util.List; + +import lombok.Data; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import top.charles7c.cnadmin.common.base.BaseVO; +import top.charles7c.cnadmin.common.consts.Constants; +import top.charles7c.cnadmin.common.enums.DataScopeEnum; +import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum; + +/** + * 角色信息 + * + * @author Charles7c + * @since 2023/2/8 23:05 + */ +@Data +@Accessors(chain = true) +@Schema(description = "角色信息") +public class RoleVO extends BaseVO { + + private static final long serialVersionUID = 1L; + + /** + * 角色 ID + */ + @Schema(description = "角色 ID") + private Long roleId; + + /** + * 角色名称 + */ + @Schema(description = "角色名称") + private String roleName; + + /** + * 角色编码 + */ + @Schema(description = "角色编码") + private String roleCode; + + /** + * 数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限) + */ + @Schema(description = "数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)") + private DataScopeEnum dataScope; + + /** + * 数据权限范围(部门 ID 数组) + */ + @Schema(description = "数据权限范围(部门 ID 数组)") + private List dataScopeDeptIds; + + /** + * 描述 + */ + @Schema(description = "描述") + private String description; + + /** + * 角色排序 + */ + @Schema(description = "角色排序") + private Integer roleSort; + + /** + * 状态(1启用 2禁用) + */ + @Schema(description = "状态(1启用 2禁用)") + private DisEnableStatusEnum status; + + /** + * 是否禁用修改 + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean disabled; + + public Boolean getDisabled() { + if (Constants.ADMIN_ROLE_CODE.equals(roleCode)) { + return true; + } + return disabled; + } +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/RoleService.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/RoleService.java new file mode 100644 index 00000000..010ee2e6 --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/RoleService.java @@ -0,0 +1,31 @@ +/* + * 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.system.service; + +import top.charles7c.cnadmin.common.base.BaseService; +import top.charles7c.cnadmin.system.model.query.RoleQuery; +import top.charles7c.cnadmin.system.model.request.RoleRequest; +import top.charles7c.cnadmin.system.model.vo.RoleDetailVO; +import top.charles7c.cnadmin.system.model.vo.RoleVO; + +/** + * 角色业务接口 + * + * @author Charles7c + * @since 2023/2/8 23:15 + */ +public interface RoleService extends BaseService {} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/RoleServiceImpl.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/RoleServiceImpl.java new file mode 100644 index 00000000..9990fb9f --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/RoleServiceImpl.java @@ -0,0 +1,147 @@ +/* + * 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.system.service.impl; + +import java.util.List; + +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; + +import cn.hutool.core.bean.BeanUtil; + +import top.charles7c.cnadmin.common.base.BaseDetailVO; +import top.charles7c.cnadmin.common.base.BaseServiceImpl; +import top.charles7c.cnadmin.common.base.BaseVO; +import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum; +import top.charles7c.cnadmin.common.model.query.PageQuery; +import top.charles7c.cnadmin.common.model.vo.PageDataVO; +import top.charles7c.cnadmin.common.util.ExceptionUtils; +import top.charles7c.cnadmin.common.util.validate.CheckUtils; +import top.charles7c.cnadmin.system.mapper.RoleMapper; +import top.charles7c.cnadmin.system.model.entity.RoleDO; +import top.charles7c.cnadmin.system.model.query.RoleQuery; +import top.charles7c.cnadmin.system.model.request.RoleRequest; +import top.charles7c.cnadmin.system.model.vo.RoleDetailVO; +import top.charles7c.cnadmin.system.model.vo.RoleVO; +import top.charles7c.cnadmin.system.service.RoleService; +import top.charles7c.cnadmin.system.service.UserService; + +/** + * 角色业务实现类 + * + * @author Charles7c + * @since 2023/2/8 23:17 + */ +@Service +@RequiredArgsConstructor +public class RoleServiceImpl extends BaseServiceImpl + implements RoleService { + + private final UserService userService; + + @Override + public PageDataVO page(RoleQuery query, PageQuery pageQuery) { + PageDataVO pageDataVO = super.page(query, pageQuery); + pageDataVO.getList().forEach(this::fill); + return pageDataVO; + } + + @Override + public RoleDetailVO get(Long id) { + RoleDetailVO roleDetailVO = super.get(id); + this.fillDetail(roleDetailVO); + return roleDetailVO; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Long create(RoleRequest request) { + String roleName = request.getRoleName(); + boolean isExist = this.checkNameExist(roleName, request.getRoleId()); + CheckUtils.throwIf(() -> isExist, String.format("新增失败,'%s'已存在", roleName)); + + // 保存信息 + RoleDO roleDO = BeanUtil.copyProperties(request, RoleDO.class); + roleDO.setStatus(DisEnableStatusEnum.ENABLE); + baseMapper.insert(roleDO); + return roleDO.getRoleId(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(RoleRequest request) { + String roleName = request.getRoleName(); + boolean isExist = this.checkNameExist(roleName, request.getRoleId()); + CheckUtils.throwIf(() -> isExist, String.format("修改失败,'%s'已存在", roleName)); + + super.update(request); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(List ids) { + super.delete(ids); + } + + /** + * 检查名称是否存在 + * + * @param roleName + * 角色名称 + * @param roleId + * 角色 ID + * @return 是否存在 + */ + private boolean checkNameExist(String roleName, Long roleId) { + return baseMapper.exists(Wrappers.lambdaQuery().eq(RoleDO::getRoleName, roleName).ne(roleId != null, + RoleDO::getRoleId, roleId)); + } + + /** + * 填充数据 + * + * @param baseVO + * 待填充列表信息 + */ + private void fill(BaseVO baseVO) { + Long createUser = baseVO.getCreateUser(); + if (createUser == null) { + return; + } + baseVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname()); + } + + /** + * 填充详情数据 + * + * @param detailVO + * 待填充详情信息 + */ + private void fillDetail(BaseDetailVO detailVO) { + this.fill(detailVO); + + Long updateUser = detailVO.getUpdateUser(); + if (updateUser == null) { + return; + } + detailVO.setUpdateUserString(ExceptionUtils.exToNull(() -> userService.getById(updateUser)).getNickname()); + } +} diff --git a/continew-admin-system/src/main/resources/mapper/RoleMapper.xml b/continew-admin-system/src/main/resources/mapper/RoleMapper.xml new file mode 100644 index 00000000..d77aa955 --- /dev/null +++ b/continew-admin-system/src/main/resources/mapper/RoleMapper.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/continew-admin-ui/src/api/system/role.ts b/continew-admin-ui/src/api/system/role.ts new file mode 100644 index 00000000..9bf6aa05 --- /dev/null +++ b/continew-admin-ui/src/api/system/role.ts @@ -0,0 +1,58 @@ +import axios from 'axios'; +import qs from 'query-string'; + +const BASE_URL = '/system/role'; + +export interface RoleRecord { + roleId?: number; + roleName: string; + roleCode?: string; + dataScope: number; + dataScopeDeptIds?: string; + description?: string; + roleSort: number; + status?: number; + createUserString?: string; + createTime?: string; + updateUserString?: string; + updateTime?: string; + disabled?: boolean; +} + +export interface RoleParam { + roleName?: string; + status?: number; + page: number; + size: number; + sort: Array; +} + +export interface RoleListRes { + list: RoleRecord[]; + total: number; +} + +export function listRole(params: RoleParam) { + return axios.get(`${BASE_URL}`, { + params, + paramsSerializer: (obj) => { + return qs.stringify(obj); + }, + }); +} + +export function getRole(id: number) { + return axios.get(`${BASE_URL}/${id}`); +} + +export function createRole(req: RoleRecord) { + return axios.post(BASE_URL, req); +} + +export function updateRole(req: RoleRecord) { + return axios.put(BASE_URL, req); +} + +export function deleteRole(ids: number | Array) { + return axios.delete(`${BASE_URL}/${ids}`); +} diff --git a/continew-admin-ui/src/locale/en-US.ts b/continew-admin-ui/src/locale/en-US.ts index 1de5e597..57e12a29 100644 --- a/continew-admin-ui/src/locale/en-US.ts +++ b/continew-admin-ui/src/locale/en-US.ts @@ -8,6 +8,7 @@ import localeMonitor from '@/views/dashboard/monitor/locale/en-US'; import localeDataAnalysis from '@/views/visualization/data-analysis/locale/en-US'; import localeMultiDAnalysis from '@/views/visualization/multi-dimension-data-analysis/locale/en-US'; +import localeRole from '@/views/system/role/locale/en-US'; import localeDept from '@/views/system/dept/locale/en-US'; import localeOnlineUser from '@/views/monitor/online/locale/en-US'; @@ -61,6 +62,7 @@ export default { ...localeDataAnalysis, ...localeMultiDAnalysis, + ...localeRole, ...localeDept, ...localeOnlineUser, diff --git a/continew-admin-ui/src/locale/zh-CN.ts b/continew-admin-ui/src/locale/zh-CN.ts index eed55cb6..252b1706 100644 --- a/continew-admin-ui/src/locale/zh-CN.ts +++ b/continew-admin-ui/src/locale/zh-CN.ts @@ -8,6 +8,7 @@ import localeMonitor from '@/views/dashboard/monitor/locale/zh-CN'; import localeDataAnalysis from '@/views/visualization/data-analysis/locale/zh-CN'; import localeMultiDAnalysis from '@/views/visualization/multi-dimension-data-analysis/locale/zh-CN'; +import localeRole from '@/views/system/role/locale/zh-CN'; import localeDept from '@/views/system/dept/locale/zh-CN'; import localeOnlineUser from '@/views/monitor/online/locale/zh-CN'; @@ -61,6 +62,7 @@ export default { ...localeDataAnalysis, ...localeMultiDAnalysis, + ...localeRole, ...localeDept, ...localeOnlineUser, diff --git a/continew-admin-ui/src/router/routes/modules/system.ts b/continew-admin-ui/src/router/routes/modules/system.ts index de283d57..9e9491d1 100644 --- a/continew-admin-ui/src/router/routes/modules/system.ts +++ b/continew-admin-ui/src/router/routes/modules/system.ts @@ -12,6 +12,16 @@ const System: AppRouteRecordRaw = { order: 2, }, children: [ + { + path: '/system/role', + name: 'Role', + component: () => import('@/views/system/role/index.vue'), + meta: { + locale: 'menu.system.role.list', + requiresAuth: true, + roles: ['*'], + }, + }, { path: '/system/dept', name: 'Dept', diff --git a/continew-admin-ui/src/views/system/role/index.vue b/continew-admin-ui/src/views/system/role/index.vue new file mode 100644 index 00000000..6daaa1d2 --- /dev/null +++ b/continew-admin-ui/src/views/system/role/index.vue @@ -0,0 +1,656 @@ + + + + + + + diff --git a/continew-admin-ui/src/views/system/role/locale/en-US.ts b/continew-admin-ui/src/views/system/role/locale/en-US.ts new file mode 100644 index 00000000..a76ceb32 --- /dev/null +++ b/continew-admin-ui/src/views/system/role/locale/en-US.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.role.list': 'Role management', +}; diff --git a/continew-admin-ui/src/views/system/role/locale/zh-CN.ts b/continew-admin-ui/src/views/system/role/locale/zh-CN.ts new file mode 100644 index 00000000..8f59ef67 --- /dev/null +++ b/continew-admin-ui/src/views/system/role/locale/zh-CN.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.role.list': '角色管理', +}; diff --git a/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/system/RoleController.java b/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/system/RoleController.java new file mode 100644 index 00000000..fa5a0635 --- /dev/null +++ b/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/system/RoleController.java @@ -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.webapi.controller.system; + +import static top.charles7c.cnadmin.common.annotation.CrudRequestMapping.Api; + +import io.swagger.v3.oas.annotations.tags.Tag; + +import org.springframework.web.bind.annotation.RestController; + +import top.charles7c.cnadmin.common.annotation.CrudRequestMapping; +import top.charles7c.cnadmin.common.base.BaseController; +import top.charles7c.cnadmin.system.model.query.RoleQuery; +import top.charles7c.cnadmin.system.model.request.RoleRequest; +import top.charles7c.cnadmin.system.model.vo.RoleDetailVO; +import top.charles7c.cnadmin.system.model.vo.RoleVO; +import top.charles7c.cnadmin.system.service.RoleService; + +/** + * 角色管理 API + * + * @author Charles7c + * @since 2023/2/8 23:11 + */ +@Tag(name = "角色管理 API") +@RestController +@CrudRequestMapping(value = "/system/role", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE}) +public class RoleController extends BaseController {} diff --git a/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_data.sql index 2c5c59d2..1d3d71fa 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_data.sql @@ -2,15 +2,23 @@ -- changeset Charles7c:1 -- 初始化默认部门 -INSERT IGNORE INTO `sys_dept` VALUES (1, 'Xxx科技有限公司', 0, 1, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (2, '天津总部', 1, 1, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (3, '研发部', 2, 1, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (4, 'UI部', 2, 2, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (5, '测试部', 2, 3, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (6, '运维部', 2, 4, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (7, '研发一组', 3, 1, NULL, 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_dept` VALUES (8, '研发二组', 3, 2, NULL, 2, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (1, 'Xxx科技有限公司', 0, '系统初始部门', 1, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (2, '天津总部', 1, '系统初始部门', 1, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (3, '研发部', 2, '系统初始部门', 1, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (4, 'UI部', 2, '系统初始部门', 2, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (5, '测试部', 2, '系统初始部门', 3, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (6, '运维部', 2, '系统初始部门', 4, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (7, '研发一组', 3, '系统初始部门', 1, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_dept` VALUES (8, '研发二组', 3, '系统初始部门', 2, 2, 1, NOW(), 1, NOW()); -- 初始化默认用户:admin/admin123;test/123456 -INSERT IGNORE INTO `sys_user` VALUES (1, 'admin', '超级管理员', '9802815bcc5baae7feb1ae0d0566baf2', 1, '18888888888', 'charles7c@126.com', NULL, NULL, 1, NOW(), 1, 1, NOW(), 1, NOW()); -INSERT IGNORE INTO `sys_user` VALUES (2, 'test', '测试员', '8e114197e1b33783a00542ad67e80516', 0, NULL, NULL, NULL, NULL, 2, NOW(), 2, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_user` VALUES (1, 'admin', '超级管理员', '9802815bcc5baae7feb1ae0d0566baf2', 1, '18888888888', 'charles7c@126.com', NULL, '系统初始用户', 1, NOW(), 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_user` VALUES (2, 'test', '测试员', '8e114197e1b33783a00542ad67e80516', 0, NULL, NULL, NULL, '系统初始用户', 2, NOW(), 2, 1, NOW(), 1, NOW()); + +-- 初始化默认角色 +INSERT IGNORE INTO `sys_role` VALUES (1, '超级管理员', 'admin', 1, NULL, '系统初始角色', 1, 1, 1, NOW(), 1, NOW()); +INSERT IGNORE INTO `sys_role` VALUES (2, '测试人员', 'test', 4, NULL, '系统初始角色', 2, 2, 1, NOW(), 1, NOW()); + +-- 初始化默认用户和角色关联数据 +INSERT IGNORE INTO `sys_user_role` VALUES (1, 1); +INSERT IGNORE INTO `sys_user_role` VALUES (2, 2); diff --git a/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_table.sql b/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_table.sql index cd1481dc..683ac865 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_table.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/v0.0.1/continew-admin_table.sql @@ -5,8 +5,8 @@ CREATE TABLE IF NOT EXISTS `sys_dept` ( `dept_id` bigint(20) unsigned AUTO_INCREMENT COMMENT '部门ID', `dept_name` varchar(255) NOT NULL COMMENT '部门名称', `parent_id` bigint(20) unsigned DEFAULT 0 COMMENT '上级部门ID', - `dept_sort` int(11) unsigned DEFAULT 999 COMMENT '部门排序', `description` varchar(512) DEFAULT NULL COMMENT '描述', + `dept_sort` int(11) unsigned DEFAULT 999 COMMENT '部门排序', `status` tinyint(1) unsigned DEFAULT 1 COMMENT '状态(1启用 2禁用)', `create_user` bigint(20) unsigned NOT NULL COMMENT '创建人', `create_time` datetime NOT NULL COMMENT '创建时间', @@ -38,11 +38,35 @@ CREATE TABLE IF NOT EXISTS `sys_user` ( PRIMARY KEY (`user_id`) USING BTREE, UNIQUE INDEX `uk_username`(`username`) USING BTREE, UNIQUE INDEX `uk_email`(`email`) USING BTREE, - INDEX `idx_create_user`(`create_user`) USING BTREE, INDEX `idx_dept_id`(`dept_id`) USING BTREE, + INDEX `idx_create_user`(`create_user`) USING BTREE, INDEX `idx_update_user`(`update_user`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; +CREATE TABLE IF NOT EXISTS `sys_role` ( + `role_id` bigint(20) unsigned AUTO_INCREMENT COMMENT '角色ID', + `role_name` varchar(255) NOT NULL COMMENT '角色名称', + `role_code` varchar(255) DEFAULT NULL COMMENT '角色编码', + `data_scope` tinyint(1) DEFAULT 4 COMMENT '数据权限(1全部数据权限 2本部门及以下数据权限 3本部门数据权限 4仅本人数据权限 5自定数据权限)', + `data_scope_dept_ids` json DEFAULT NULL COMMENT '数据权限范围(部门ID数组)', + `description` varchar(512) DEFAULT NULL COMMENT '描述', + `role_sort` int(11) unsigned DEFAULT 999 COMMENT '角色排序', + `status` tinyint(1) unsigned DEFAULT 1 COMMENT '状态(1启用 2禁用)', + `create_user` bigint(20) unsigned NOT NULL COMMENT '创建人', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_user` bigint(20) unsigned NOT NULL COMMENT '修改人', + `update_time` datetime NOT NULL COMMENT '修改时间', + PRIMARY KEY (`role_id`) USING BTREE, + INDEX `idx_create_user`(`create_user`) USING BTREE, + INDEX `idx_update_user`(`update_user`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; + +CREATE TABLE IF NOT EXISTS `sys_user_role` ( + `user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID', + `role_id` bigint(20) unsigned NOT NULL COMMENT '角色ID', + PRIMARY KEY (`user_id`,`role_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和角色关联表'; + CREATE TABLE IF NOT EXISTS `sys_log` ( `log_id` bigint(20) unsigned AUTO_INCREMENT COMMENT '日志ID', `description` varchar(255) NOT NULL COMMENT '日志描述',