12 Star 47 Fork 19

admin / cmdAdmin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

cmdAdmin

QQ群:951379340

介绍

基于SpringBoot+SpringMVC+MybatisPlus分布式敏捷开发系统架构,默认支持SAAS化,努力为中小型企业打造全方位J2EE企业级开发解决方案。

软件架构

cmdAdmin是基于Spring Cloud Alibaba体系微服务化分布式敏捷开发系统架构,支持SAAS化,提供整套公共微服务服务模块,其中包含用户管理、资源权限管理等多个模块,作为后端服务的开发脚手架。代码简洁,架构清晰,适合学习和直接项目中使用。 核心技术采用Spring Boot 2.2.7以及Spring Cloud 相关核心组件,采用Nacos注册和配置中心,集成流量卫兵Sentinel,dubbo远程调用,集成Activiti工作流,动态表单+动态工作流,工作流下拉选择代理人,前端采用vue-element-admin组件。

安装教程

  1. 安装redis jdk maven
  2. 安装Nacos 导入doc下文件 导入数据库sql
  3. 启动网关 admin log workflow 模块

使用说明

有问题请加QQ群: 951379340

  1. 超级管理员账号 13455555555/123456不参与业务只管理租户和菜单维护(操作哪些菜单租户可见)
  2. 租户管理1 13468935090/123456

主要功能

  • 演示: http://43.142.119.227/

  • 用户中心

    • 用户管理:提供用户的相关配置,新增用户后,默认密码为 cmd.c0m
    • 在线用户:统计登录用户
    • 角色管理:对权限与菜单进行分配,可根据部门设置角色的数据权限
    • 部门管理:可配置系统组织架构,树形表格展示
  • 系统中心

    • 菜单管理:已实现菜单动态路由,后端可配置化,支持多级菜单
    • 字典管理:可维护常用一些固定的数据,如:性别等
    • 存储管理: 上传附件记录
    • 表单配置:根据 form-generator 集成的表单拖拽
    • 数据管理: 动态表单的集中数据管理列表
  • 日志中心

    • 日志管理:记录用户操作日志与异常日志,方便开发人员定位排错
    • ELK 日志:未完成
  • 流程中心

    • 流程管理:手绘工作流模型
    • 待办任务:当前人审批任务
    • 请假申请:动态配置,阅读表单配置
    • 财务申请: 动态配置,阅读表单配置

项目结构

  • cmdAdmin-common 为系统的公共模块,各种工具类,公共配置存在该模块

  • cmdAdmin-gateway 网关层,所有入库经过该服务

  • cmdAdmin-modules 为系统的应用模块

  • cmdAdmin-modules-admin 基础模块

  • cmdAdmin-modules-log 日志模块

  • cmdAdmin-modules-workflow 工作流模块

  • cmdAdmin-rpc 远程调用

  • cmdadmin-template 前端页面

运行项目

  • 安装 Redis

  • 安装 Nacos

  • 创建 cmdadmin 数据库,导入 db 下的 sql 脚本

  • 打开 nacos,点开配置管理--配置列表 --导入配置 doc 下的 xxx.zip,会出现配置列表

  • 修改 cmdAdmin-modules-admin-dev.yml master 中的数据库配置,slave 是 enabled 是 false,如果需要开启也改一下数据库链接,其他模块类似,其他配置根据需求改动, registry.address 是 nacos 地址

    • 启动 cmdAdmin-gateway cmdAdmin-modules-admin 这 2 个启动就可以登录看基础功能了 日志和工作流根据需要启动
    • 启动 cmdadmin-template 前端 npm install , npm run dev 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明输入图片说明

环境配置

具体安装问题自行百度

运行环境准备

  • JDK1.8+
  • Redis
  • MYSQL5.6+
  • Maven3+
  • Nacos1.3+

开发环境

  • IDEA、Eclipse、vscode
  • 开发插件
  • Lombok:节省时间必备
  • 阿里 JAVA 开发规约插件:P3C
  • JRebel:秒级热更新神器必备

导入 SQl 文件

  • MySQL 数据库新建数据库,导入 doc 下的 sql 文件

配置文件导入

  • 启动 nacos 后 导入 doc 下 zip 文件
  • 编辑对应配置文件 比如,数据库配置

访问测试

  • 账号 13455555555/123456

开发手册

当前用户

获取当前登录用户对象

OnlineUser user = securityAdmin.currentUser(token);

例如:
@GetMapping(value = "/menus")
public ResponseEntity menus(HttpServletRequest request, @RequestHeader(value = Constants.TOKEN) String token)  {
  CmdResponse response = new CmdResponse();
  response.setData(loginService.listMenus(token));
  return ResponseEntity.ok(response);
}

@Override
	public List<MenuVO> listMenus(String token) {
		OnlineUser user = securityAdmin.currentUser(token);
		Map<String, Object> param = Maps.newHashMap();
		List<MenuVO> vos = baseMapper.getMenus(param);
		return vos;
	}

权限控制

本系统权限控制采用 RBAC 思想。简单地说,一个用户拥有若干角色,每一个角色拥有若干个菜单,菜单中存在菜单权限与按钮权限, 这样,就构造成“用户-角色-菜单” 的授权模型。在这种模型中,用户与角色、角色与菜单之间构成了多对多的关系,如下图

avatar

权限控制

本系统安全框架使用的是 Jwt Token, 访问后端接口需在请求头中携带 token 进行访问,请求头格式如下:

Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJjcmVhdGVUaW1lXCI6MTU5ODE3OTc4NDAwMCxcImRlbGV0ZWRcIjp0cnVlLFwiZGVwdElkXCI6XCIwZjY4NjZiZTcwYTJmNjkwZTY3YWQyYjZiNzExMjZiYlwiLFwiZGVwdE5hbWVcIjpcIumZleilv1wiLFwiZW5hYmxlZFwiOnRydWUsXCJpZFwiOlwid3d3XCIsXCJuaWNrTmFtZVwiOlwiY21kYWRtaW5cIixcInBhc3N3b3JkXCI6XCIyMmJiZmM0NmZlNzEwOTlkMTM5ZTJjYWEwOGQ1NWJlN1wiLFwicGhvbmVcIjpcIjEzNDU1NTU1NTU1XCIsXCJzYWx0XCI6XCIxMTFcIixcInVwZGF0ZVRpbWVcIjoxNTk4MTc5Nzg2MDAwLFwidXNlck5hbWVcIjpcImNtZGFkbWluXCJ9IiwianRpIjoiN2UzNzU3ZjUtZmU0MC00NWRhLTk2OTctN2ZmNTk3NGE1Y2RjIn0.zM1UafO-UDVrnmsBTTtQPAThVOddR5cz0gDKvjCAlrSfqj5rw-lU4MQmYFvM4k5NNy6NbRQEw5YER3k19C1ARg

avatar

权限注解

提供 EL 表达式,允许在定义接口访问的方法上面添加注解,来控制访问权限,常用的 EL 如下

表达式 描述
@CmdAdmin({"user:list"}) 当前用户是否拥有指定角色。
@CmdAdmin({"admin","user:list"}) 多个角色是一个以逗号进行分隔的字符串。如果当前用户拥有指定角色中的任意一个则返回 true。

下面的接口表示用户拥有 admin、user:add、user:update create 如果方法不加@CmdAdmin 注解,意味着所有用户都需要带上有效的 token 后能访问 create 方法

@Log("用户新增或编辑")
@CmdAdmin({"admin","user:add","user:update"})
@PutMapping
public ResponseEntity<CmdResponse> create(@RequestBody User entity) throws Exception  {
  userService.create(entity);
  return ResponseEntity.ok(new CmdResponse());
}

由于每个接口都需要给超级管理员放行,而使用 CmdAdmin('admin','user:list') 每次都需要重复的添加 admin 权限

匿名访问

在我们使用的时候,有些接口是不需要验证权限的,这个时候就需要我们给接口放行,在网关配置中添加,使用方式如下

cmd:
  filter: #需要进行过滤的白名单
    allowPaths:
      - /admin/cmd/v1/auth/login
      - /admin/cmd/v1/auth/code

远程调用

本系统使用的是Dubbo远程调用,当接口对外需要提供访问时候,在当前接口实现上加入dubbo注解

例如:

@Service
@org.apache.dubbo.config.annotation.Service(version = "1.0.0")
public class FwLogServiceImpl

如果不对外提供访问,只是内部容器调用则只使用spring的 @Service 即可

自动填充

原理:

  • 实现元对象处理器接口:com.baomidou.mybatisplus.core.handlers.MetaObjectHandler

  • 注解填充字段 @TableField(.. fill = FieldFill.INSERT) 生成器策略部分也可以配置!

/**
  * 创建时间
  */
  // 注意!这里需要标记为填充字段
@TableField(value = "create_time",fill = FieldFill.INSERT)
private Date createTime;
  • 自定义实现类 MyMetaObjectHandler
/**
 * 自动注入
 * @author cmd
 *
 */
@Component
public class BasicMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.fillStrategy(metaObject, "createTime", new Date());
		this.fillStrategy(metaObject, "enabled", true);
		this.fillStrategy(metaObject, "deleted", true);
	}

	@Override
	public void updateFill(MetaObject metaObject) {	
		this.fillStrategy(metaObject, "updateTime", new Date());
	}

}
  • FieldFill类型
public enum FieldFill {
    /**
     * 默认不处理
     */
    DEFAULT,
    /**
     * 插入填充字段
     */
    INSERT,
    /**
     * 更新填充字段
     */
    UPDATE,
    /**
     * 插入和更新填充字段
     */
    INSERT_UPDATE
}

字典翻译

在后台字典管理中新增字典数据 参考前端代码views\system\menu\index.vue

使用步骤:

- import { getDic } from '@/utils/auth'
- created() {
    this.dicType = getDic('字典编码')
  }
- formatterType({ cellValue }) {
      const item = this.dicType.find(item => item.code === cellValue)
      return item ? item.value : ''
  }
-  <vxe-table-column field="type" title="菜单类型" :formatter="formatterType" />

异常处理

我们开发项目的时候,数据在请求过程中发生错误是非常常见的事情。

如:权限不足、数据唯一异常、数据不能为空异常、义务异常等。 这些异常如果不经过处理会对前端开发人员和使用者造成不便,因此我们就需要统一处理他们。

代码位置: cmdAdmin-common 工程中com.ninong.ker.common.exception包中

处理异常在每个模块 conf 包 LogAspect

异常封装

异常实体

    /**
    * 错误类
    *
    * @author cmd
    * @date 2020年11月28日 下午11:16:13
    */
    @Data
    public class CmdError {

      private Integer status = 400;
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
      private LocalDateTime timestamp;
      private String message;

      private CmdError() {
        timestamp = LocalDateTime.now();
      }

      public static CmdError error(String message) {
        CmdError apiError = new CmdError();
        apiError.setMessage(message);
        return apiError;
      }

      public static CmdError error(Integer status, String message) {
        CmdError apiError = new CmdError();
        apiError.setStatus(status);
        apiError.setMessage(message);
        return apiError;
      }

    }

自定义异常

通用异常

封装了 CmdException,用于处理通用的异常

    /**
    * @author cmd
    * @date 2020-11-23 统一异常处理
    */
    @Getter
    public class CmdException extends RuntimeException{

        /**
      *
      */
      private static final long serialVersionUID = 1L;
      private Integer status = BAD_REQUEST.value();

        public CmdException(String msg){
            super(msg);
        }

        public CmdException(Integer status,String msg){
            super(msg);
            this.status = status;
        }
        public CmdException(BusinessEnum bus){
          super(bus.getMsg());
          this.status = bus.getStatus();
        }
    }

全局异常拦截

使用全局异常处理器 @RestControllerAdvice 处理请求发送的异常

  • @RestControllerAdvice:默认会扫描指定包中所有@RequestMapping 注解

  • @ExceptionHandler:通过@ExceptionHandler 的 value 属性可过滤拦截的条件

  /\*\*

  - 异常处理类
  -
  - @author cmd
  - @date 2020  11  28  下午 11:22:48
    \*/

  @Slf4j
  @RestControllerAdvice
  public class GlobalExceptionHandler {

      /**
      * 处理所有不可知的异常
      */
      @ExceptionHandler(Throwable.class)
      public ResponseEntity<CmdError> handleException(Throwable e) {
        // 打印堆栈信息
        log.error(ThrowableUtil.getStackTrace(e));
        return buildResponseEntity(CmdError.error(e.getMessage()));
      }

      /**
      * 处理自定义异常
      */
      @ExceptionHandler(value = CmdException.class)
      public ResponseEntity<CmdResponse> badRequestException(CmdException e) {
        CmdResponse response = new CmdResponse();
        response.setCode(e.getStatus());
        response.setMessage(e.getMessage());
        return ResponseEntity.ok(response);
      }

      /**
        * 接口参数校验不通过异常
        *
        * @param e
        * @return
        */
        @ExceptionHandler(value = MethodArgumentNotValidException.class)
        public ResponseEntity<CmdResponse> methodArgumentNotValidException(MethodArgumentNotValidException e) {
            List<FieldError> bindingResult = e.getBindingResult().getFieldErrors();
            StringBuilder sb = new StringBuilder();
            for (FieldError fieldError : bindingResult) {
                sb.append(fieldError.getDefaultMessage()).append(";");
            }
            CmdResponse response = new CmdResponse();
        response.setCode(100);
        response.setMessage(sb.toString());
            return ResponseEntity.ok(response);
        }


      /**
      * 统一返回
      */
      private ResponseEntity<CmdError> buildResponseEntity(CmdError CmdError) {
        return new ResponseEntity<>(CmdError, HttpStatus.valueOf(CmdError.getStatus()));
      }
    }

具体使用

    // 通用异常
    throw new CmdException("系统提醒");
    // 通用异常,使用自定义状态码
    throw new CmdException(402, "系统提醒");

系统日志

本系统使用 AOP 方式记录用户操作日志,只需要在 controller 的方法上使用 @Log("") 注解,就可以将用户操作记录到数据库 模块具体使用如下:

@Log("用户删除")
@CmdAdmin({"admin","user:delete"})
@DeleteMapping
public ResponseEntity<CmdResponse> delete(@RequestBody String[] ids)  {
  userService.delete(ids);
  CmdResponse response = new CmdResponse();
  response.setMessage(BusinessEnum.DELETE_SUCCESS.getMsg());
  return ResponseEntity.ok(response);
}

页面日志中心可以看到 操作日志和异常日志

输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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.

简介

cmdAdmin是基于Spring Cloud Alibaba体系微服务化分布式敏捷开发系统架构,提供整套公共微服务服务模块,其中包含用户管理、资源权限管理等多个模块,作为后端服务的开发脚手架。代码简洁,架构清晰,适合学习和直接项目中使用。 核心技术采用Spring Boot 2.2.7以及Spring Cloud 相关核心组件,采用Nacos注册和配置中心,集成流量卫兵Sentinel,dubbo远程调用,集成Activiti工作流,动态表单+动态工作流,工作流下拉选择代理人,前端采用vue-element-admin组件。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/cmdshare/cmdAdmin.git
git@gitee.com:cmdshare/cmdAdmin.git
cmdshare
cmdAdmin
cmdAdmin
master

搜索帮助