Merge pull request #42 from lanyulei/dev

Dev
This commit is contained in:
lanyulei 2020-09-08 23:03:54 +08:00 committed by GitHub
commit c7e8f894c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 392 additions and 1 deletions

381
config/ferry.sql Normal file
View File

@ -0,0 +1,381 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50729
Source Host : localhost:3306
Source Schema : ferry
Target Server Type : MySQL
Target Server Version : 50729
File Encoding : 65001
Date: 05/09/2020 16:42:32
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for casbin_rule
-- ----------------------------
DROP TABLE IF EXISTS `casbin_rule`;
CREATE TABLE `casbin_rule` (
`p_type` varchar(100) DEFAULT NULL,
`v0` varchar(100) DEFAULT NULL,
`v1` varchar(100) DEFAULT NULL,
`v2` varchar(100) DEFAULT NULL,
`v3` varchar(100) DEFAULT NULL,
`v4` varchar(100) DEFAULT NULL,
`v5` varchar(100) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_casbin_rule_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=794 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_process_classify
-- ----------------------------
DROP TABLE IF EXISTS `p_process_classify`;
CREATE TABLE `p_process_classify` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`name` varchar(128) DEFAULT NULL,
`creator` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_p_process_classify_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_process_info
-- ----------------------------
DROP TABLE IF EXISTS `p_process_info`;
CREATE TABLE `p_process_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`name` varchar(128) DEFAULT NULL,
`structure` json DEFAULT NULL,
`classify` int(11) DEFAULT NULL,
`tpls` json DEFAULT NULL,
`task` json DEFAULT NULL,
`submit_count` int(11) DEFAULT '0',
`creator` int(11) DEFAULT NULL,
`notice` json DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_p_process_info_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_task_history
-- ----------------------------
DROP TABLE IF EXISTS `p_task_history`;
CREATE TABLE `p_task_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`task` int(11) DEFAULT NULL,
`name` varchar(256) DEFAULT NULL,
`task_type` int(11) DEFAULT NULL,
`execution_time` varchar(128) DEFAULT NULL,
`result` longtext,
PRIMARY KEY (`id`),
KEY `idx_p_task_history_delete_time` (`delete_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_task_info
-- ----------------------------
DROP TABLE IF EXISTS `p_task_info`;
CREATE TABLE `p_task_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`name` varchar(256) DEFAULT NULL,
`task_type` varchar(45) DEFAULT NULL,
`content` longtext,
`creator` int(11) DEFAULT NULL,
`remarks` longtext,
PRIMARY KEY (`id`),
KEY `idx_p_task_info_delete_time` (`delete_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_tpl_info
-- ----------------------------
DROP TABLE IF EXISTS `p_tpl_info`;
CREATE TABLE `p_tpl_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`name` varchar(128) DEFAULT NULL,
`form_structure` json DEFAULT NULL,
`creator` int(11) DEFAULT NULL,
`remarks` longtext,
PRIMARY KEY (`id`),
KEY `idx_p_tpl_info_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_work_order_circulation_history
-- ----------------------------
DROP TABLE IF EXISTS `p_work_order_circulation_history`;
CREATE TABLE `p_work_order_circulation_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`title` varchar(128) DEFAULT NULL,
`work_order` int(11) DEFAULT NULL,
`state` varchar(128) DEFAULT NULL,
`source` varchar(128) DEFAULT NULL,
`target` varchar(128) DEFAULT NULL,
`circulation` varchar(128) DEFAULT NULL,
`processor` varchar(45) DEFAULT NULL,
`processor_id` int(11) DEFAULT NULL,
`cost_duration` varchar(128) DEFAULT NULL,
`remarks` longtext,
PRIMARY KEY (`id`),
KEY `idx_p_work_order_circulation_history_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_work_order_info
-- ----------------------------
DROP TABLE IF EXISTS `p_work_order_info`;
CREATE TABLE `p_work_order_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`title` varchar(128) DEFAULT NULL,
`priority` int(11) DEFAULT NULL,
`process` int(11) DEFAULT NULL,
`classify` int(11) DEFAULT NULL,
`is_end` int(11) DEFAULT '0',
`is_denied` int(11) DEFAULT '0',
`state` json DEFAULT NULL,
`related_person` json DEFAULT NULL,
`creator` int(11) DEFAULT NULL,
`urge_count` int(11) DEFAULT '0',
`urge_last_time` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_p_work_order_info_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for p_work_order_tpl_data
-- ----------------------------
DROP TABLE IF EXISTS `p_work_order_tpl_data`;
CREATE TABLE `p_work_order_tpl_data` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`work_order` int(11) DEFAULT NULL,
`form_structure` json DEFAULT NULL,
`form_data` json DEFAULT NULL,
`tpl` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_p_work_order_tpl_data_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_dept
-- ----------------------------
DROP TABLE IF EXISTS `sys_dept`;
CREATE TABLE `sys_dept` (
`dept_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
`dept_path` varchar(255) DEFAULT NULL,
`dept_name` varchar(128) DEFAULT NULL,
`sort` int(4) DEFAULT NULL,
`leader` int(11) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`email` varchar(64) DEFAULT NULL,
`status` int(1) DEFAULT NULL,
`create_by` varchar(64) DEFAULT NULL,
`update_by` varchar(64) DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`dept_id`),
KEY `idx_sys_dept_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_loginlog
-- ----------------------------
DROP TABLE IF EXISTS `sys_loginlog`;
CREATE TABLE `sys_loginlog` (
`info_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(128) DEFAULT NULL,
`status` int(1) DEFAULT NULL,
`ipaddr` varchar(255) DEFAULT NULL,
`login_location` varchar(255) DEFAULT NULL,
`browser` varchar(255) DEFAULT NULL,
`os` varchar(255) DEFAULT NULL,
`platform` varchar(255) DEFAULT NULL,
`login_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
`msg` varchar(255) DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`info_id`),
KEY `idx_sys_loginlog_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=147 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_menu
-- ----------------------------
DROP TABLE IF EXISTS `sys_menu`;
CREATE TABLE `sys_menu` (
`menu_id` int(11) NOT NULL AUTO_INCREMENT,
`menu_name` varchar(128) DEFAULT NULL,
`title` varchar(64) DEFAULT NULL,
`icon` varchar(128) DEFAULT NULL,
`path` varchar(128) DEFAULT NULL,
`paths` varchar(128) DEFAULT NULL,
`menu_type` varchar(1) DEFAULT NULL,
`action` varchar(16) DEFAULT NULL,
`permission` varchar(32) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`no_cache` char(1) DEFAULT NULL,
`breadcrumb` varchar(255) DEFAULT NULL,
`component` varchar(255) DEFAULT NULL,
`sort` int(4) DEFAULT NULL,
`visible` char(1) DEFAULT NULL,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`is_frame` int(1) DEFAULT '0',
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`menu_id`),
KEY `idx_sys_menu_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=362 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_post
-- ----------------------------
DROP TABLE IF EXISTS `sys_post`;
CREATE TABLE `sys_post` (
`post_id` int(11) NOT NULL AUTO_INCREMENT,
`post_name` varchar(128) DEFAULT NULL,
`post_code` varchar(128) DEFAULT NULL,
`sort` int(4) DEFAULT NULL,
`status` int(1) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`post_id`),
KEY `idx_sys_post_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_role
-- ----------------------------
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role` (
`role_id` int(11) NOT NULL AUTO_INCREMENT,
`role_name` varchar(128) DEFAULT NULL,
`status` int(1) DEFAULT NULL,
`role_key` varchar(128) DEFAULT NULL,
`role_sort` int(4) DEFAULT NULL,
`flag` varchar(128) DEFAULT NULL,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
`admin` char(1) DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`role_id`),
KEY `idx_sys_role_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_role_dept
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_dept`;
CREATE TABLE `sys_role_dept` (
`role_id` int(11) DEFAULT NULL,
`dept_id` int(11) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_role_menu
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_menu`;
CREATE TABLE `sys_role_menu` (
`role_id` int(11) DEFAULT NULL,
`menu_id` int(11) DEFAULT NULL,
`role_name` varchar(128) DEFAULT NULL,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1538 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_settings
-- ----------------------------
DROP TABLE IF EXISTS `sys_settings`;
CREATE TABLE `sys_settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`classify` int(11) DEFAULT NULL,
`content` json DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_sys_settings_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`nick_name` varchar(128) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`role_id` int(11) DEFAULT NULL,
`salt` varchar(255) DEFAULT NULL,
`avatar` varchar(255) DEFAULT NULL,
`sex` varchar(255) DEFAULT NULL,
`email` varchar(128) DEFAULT NULL,
`dept_id` int(11) DEFAULT NULL,
`post_id` int(11) DEFAULT NULL,
`create_by` varchar(128) DEFAULT NULL,
`update_by` varchar(128) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
`status` int(1) DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
`delete_time` timestamp NULL DEFAULT NULL,
`username` varchar(64) DEFAULT NULL,
`password` varchar(128) DEFAULT NULL,
PRIMARY KEY (`user_id`),
KEY `idx_sys_user_delete_time` (`delete_time`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -1,11 +1,14 @@
package middleware package middleware
import ( import (
"ferry/global/orm"
"ferry/models/system"
mycasbin "ferry/pkg/casbin" mycasbin "ferry/pkg/casbin"
"ferry/pkg/jwtauth" "ferry/pkg/jwtauth"
_ "ferry/pkg/jwtauth" _ "ferry/pkg/jwtauth"
"ferry/pkg/logger" "ferry/pkg/logger"
"ferry/tools" "ferry/tools"
"fmt"
"net/http" "net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -14,6 +17,8 @@ import (
//权限检查中间件 //权限检查中间件
func AuthCheckRole() gin.HandlerFunc { func AuthCheckRole() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
var menuValue system.Menu
data, _ := c.Get("JWT_PAYLOAD") data, _ := c.Get("JWT_PAYLOAD")
v := data.(jwtauth.MapClaims) v := data.(jwtauth.MapClaims)
e, err := mycasbin.Casbin() e, err := mycasbin.Casbin()
@ -24,12 +29,17 @@ func AuthCheckRole() gin.HandlerFunc {
tools.HasError(err, "", 500) tools.HasError(err, "", 500)
err = orm.Eloquent.Model(&menuValue).
Where("path = ? and action = ?", c.Request.URL.Path, c.Request.Method).
Find(&menuValue).Error
tools.HasError(err, "", 500)
if res { if res {
c.Next() c.Next()
} else { } else {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 403, "code": 403,
"msg": "对不起,您没有该接口访问权限,请联系管理员", "msg": fmt.Sprintf("对不起,您没有 <%v> 访问权限,请联系管理员", menuValue.Title),
}) })
c.Abort() c.Abort()
return return