Browse Source

自动初始化数据库功能后端部分完成

pixel 4 years ago
parent
commit
18ef727164

+ 0 - 45
server/Makefile

@@ -1,45 +0,0 @@
-.PHONY: all build run gotool clean help
-
-BINARY="gin-vue-admin"
-GVA = "gva"
-
-all: check gva initdb run
-
-gva:
-	go env -w GO111MODULE=on
-	go env -w GOPROXY=https://goproxy.io,direct
-	go build -o ${GVA} cmd/main.go
-
-initdb:
-	@if [ -f ${GVA} ] ; then ./gva initdb && rm ${GVA} ; fi
-
-linux-build:
-	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
-
-windows-build:
-	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ${BINARY}.exe
-
-mac-build:
-	CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${BINARY}
-
-run:
-	@go run main.go
-
-check:
-	go fmt ./
-	go vet ./
-
-clean:
-	@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
-	@if [ -f ${GVA} ] ; then rm ${GVA} ; fi
-
-help:
-	@echo "make - 构建gva终端工具并初始化数据,初始化数据后删除gva终端工具,启动server项目"
-	@echo "make gva - 构建gva终端工具"
-	@echo "make initdb - 如果有gva终端工具就初始化数据,初始化数据后删除gva终端工具,没有则不会执行"
-	@echo "make linux-build - 编译 Go 代码, 生成Linux系统的二进制文件"
-	@echo "make windows-build - 编译 Go 代码, 生成Windows系统的exe文件"
-	@echo "make mac-build - 编译 Go 代码, 生成Mac系统的二进制文件"
-	@echo "make run - 直接运行 main.go"
-	@echo "make clean - 移除二进制文件"
-	@echo "make check - 运行 Go 工具 'fmt' and 'vet'"

+ 0 - 65
server/cmd/gva/initdb.go

@@ -1,65 +0,0 @@
-/*
-Copyright © 2020 SliverHorn
-
-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 gva
-
-import (
-	"gin-vue-admin/cmd/source"
-	"gin-vue-admin/core"
-	"github.com/gookit/color"
-
-	_ "gin-vue-admin/core"
-	"gin-vue-admin/global"
-
-	"github.com/spf13/cobra"
-)
-
-// initdbCmd represents the initdb command
-var initdbCmd = &cobra.Command{
-	Use:   "initdb",
-	Short: "gin-vue-admin初始化数据",
-	Long: `gin-vue-admin初始化数据适配数据库情况: 
-1. mysql完美适配,
-2. postgresql不能保证完美适配,
-3. sqlite未适配,
-4. sqlserver未适配`,
-	Run: func(cmd *cobra.Command, args []string) {
-		frame, _ := cmd.Flags().GetString("frame")
-		path, _ := cmd.Flags().GetString("path")
-		global.GVA_VP = core.Viper(path)
-		global.GVA_LOG = core.Zap() // 初始化zap日志库
-
-		source.Mysql.CheckDatabase()
-		source.Mysql.CheckUtf8mb4()
-		source.Mysql.Info()
-		source.Mysql.Init()
-		switch frame {
-		case "gin":
-			if global.GVA_CONFIG.System.DbType == "mysql" {
-				source.Mysql.AutoMigrateTables()
-				source.Mysql.InitData()
-			}
-		case "gf":
-			color.Info.Println("gf功能开发中")
-		}
-	},
-}
-
-func init() {
-	rootCmd.AddCommand(initdbCmd)
-	initdbCmd.Flags().StringP("path", "p", "./config.yaml", "自定配置文件路径(绝对路径)")
-	initdbCmd.Flags().StringP("frame", "f", "gin", "可选参数为gin,gf")
-	initdbCmd.Flags().StringP("type", "t", "mysql", "可选参数为mysql,postgresql,sqlite,sqlserver")
-}

+ 0 - 94
server/cmd/gva/root.go

@@ -1,94 +0,0 @@
-/*
-Copyright © 2020 SliverHorn
-
-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 gva
-
-import (
-	"github.com/mitchellh/go-homedir"
-	"os"
-
-	"github.com/gookit/color"
-	"github.com/spf13/cobra"
-
-	"github.com/spf13/viper"
-)
-
-var cfgFile string
-
-// rootCmd represents the base command when called without any subcommands
-var rootCmd = &cobra.Command{
-	Use:   "gva",
-	Short: "这是一款amazing的终端工具",
-	Long: `欢迎使用gva终端工具
- ________ ____   ____   _____   
- /  _____/ \   \ /   /  /  _  \  
-/   \  ___  \   Y   /  /  /_\  \ 
-\    \_\  \  \     /  /    |    \
- \______  /   \___/   \____|__  /
-        \/                    \/ 
-`,
-	// Uncomment the following line if your bare application
-	// has an action associated with it:
-	//	Run: func(cmd *cobra.Command, args []string) { },
-}
-
-// Execute adds all child commands to the root command and sets flags appropriately.
-// This is called by main.main(). It only needs to happen once to the rootCmd.
-func Execute() {
-	if err := rootCmd.Execute(); err != nil {
-		color.Warn.Println(err)
-		os.Exit(1)
-	}
-}
-
-func init() {
-	cobra.OnInitialize(initConfig)
-
-	// Here you will define your flags and configuration settings.
-	// Cobra supports persistent flags, which, if defined here,
-	// will be global for your application.
-
-	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gva.yaml)")
-
-	// Cobra also supports local flags, which will only run
-	// when this action is called directly.
-	rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-}
-
-// initConfig reads in config file and ENV variables if set.
-func initConfig() {
-	if cfgFile != "" {
-		// Use config file from the flag.
-		viper.SetConfigFile(cfgFile)
-	} else {
-		// Find home directory.
-		home, err := homedir.Dir()
-		if err != nil {
-			color.Warn.Println(err)
-			os.Exit(1)
-		}
-
-		// Search config in home directory with name ".gva" (without extension).
-		viper.AddConfigPath(home)
-		viper.SetConfigName(".gva")
-	}
-
-	viper.AutomaticEnv() // read in environment variables that match
-
-	// If a config file is found, read it in.
-	if err := viper.ReadInConfig(); err == nil {
-		color.Warn.Println("Using config file:", viper.ConfigFileUsed())
-	}
-}

+ 0 - 53
server/cmd/gva/run.go

@@ -1,53 +0,0 @@
-/*
-Copyright © 2020 NAME HERE <EMAIL ADDRESS>
-
-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 gva
-
-import (
-	"gin-vue-admin/utils"
-	"github.com/spf13/cobra"
-	"os"
-)
-
-// runCmd represents the run command
-var runCmd = &cobra.Command{
-	Use:   "run",
-	Short: "running go codes with hot-compiled-like feature",
-	Long: `
-	The "run" command is used for running go codes with hot-compiled-like feature,     
-	which compiles and runs the go codes asynchronously when codes change.
-`,
-	Run: func(cmd *cobra.Command, args []string) {
-		w := utils.NewWatch()
-		t := utils.NewT()
-		path, _ := os.Getwd()
-		go w.Watch(path, t)
-		t.RunTask()
-	},
-}
-
-func init() {
-	rootCmd.AddCommand(runCmd)
-
-	// Here you will define your flags and configuration settings.
-
-	// Cobra supports Persistent Flags which will work for this command
-	// and all subcommands, e.g.:
-	// runCmd.PersistentFlags().String("foo", "", "A help for foo")
-
-	// Cobra supports local flags which will only run when this command
-	// is called directly, e.g.:
-	// runCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-}

+ 0 - 36
server/cmd/gva/version.go

@@ -1,36 +0,0 @@
-/*
-Copyright © 2020 SliverHorn
-
-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 gva
-
-import (
-	"github.com/gookit/color"
-
-	"github.com/spf13/cobra"
-)
-
-// versionCmd represents the version command
-var versionCmd = &cobra.Command{
-	Use:   "version",
-	Short: "版本信息",
-	Long:  `版本的长信息`,
-	Run: func(cmd *cobra.Command, args []string) {
-		color.Green.Println("v0.0.4")
-	},
-}
-
-func init() {
-	rootCmd.AddCommand(versionCmd)
-}

+ 0 - 22
server/cmd/main.go

@@ -1,22 +0,0 @@
-/*
-Copyright © 2020 SliverHorn
-
-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 main
-
-import "gin-vue-admin/cmd/gva"
-
-func main() {
-	gva.Execute()
-}

+ 0 - 53
server/cmd/source/init_db.go

@@ -1,53 +0,0 @@
-package source
-
-import (
-	"database/sql"
-	"github.com/spf13/viper"
-)
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: CreateTable
-//@description: 创建数据库(mysql)
-//@param: dsn string, driver string, createSql
-//@return: error
-
-func CreateTable(dsn string, driver string, createSql string) error {
-	db, err := sql.Open(driver, dsn)
-	if err != nil {
-		return err
-	}
-	defer db.Close()
-	if err = db.Ping(); err != nil {
-		return err
-	}
-	_, err = db.Exec(createSql)
-	return err
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: WriteConfig
-//@description: 回写配置
-//@param:
-//@return: error
-
-func WriteConfig(viper *viper.Viper, conf map[string]interface{}) error {
-	for k, v := range conf {
-		viper.Set(k, v)
-	}
-	return viper.WriteConfig()
-}
-
-//@author: [Songzhibin97](https://github.com/Songzhibin97)
-//@function: InitDB
-//@description: 初始化db
-//@param:
-//@return: error
-
-func InitDB() {
-	Mysql.CheckDatabase()
-	Mysql.CheckUtf8mb4()
-	Mysql.Info()
-	Mysql.Init()
-	Mysql.AutoMigrateTables()
-	Mysql.InitData()
-}

+ 0 - 317
server/cmd/source/mysql.go

@@ -1,317 +0,0 @@
-package source
-
-import (
-	"fmt"
-	information "gin-vue-admin/cmd/information/extra"
-	data "gin-vue-admin/cmd/information/system"
-	"gin-vue-admin/global"
-	"gin-vue-admin/model"
-	"os"
-	"strings"
-
-	gormadapter "github.com/casbin/gorm-adapter/v3"
-	"github.com/gookit/color"
-	"gorm.io/driver/mysql"
-	"gorm.io/gorm"
-	"gorm.io/gorm/logger"
-)
-
-type DatabaseInfo struct {
-	Value        string `gorm:"column:Value"`
-	VariableName string `gorm:"column:Variable_name"`
-}
-
-var Mysql = &_mysql{_config: &gorm.Config{}}
-
-type _mysql struct {
-	db      *gorm.DB
-	err     error
-	_config *gorm.Config
-
-	old       string // 配置文件第一次读取数据库数据
-	input     string
-	version   string
-	character string
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: gorm连接mysql数据库
-func (m *_mysql) Init() {
-	if global.GVA_CONFIG.Mysql.LogMode {
-		m._config.Logger = logger.Default.LogMode(logger.Info)
-	} else {
-		m._config.Logger = logger.Default.LogMode(logger.Silent)
-	}
-	m._config.DisableForeignKeyConstraintWhenMigrating = true
-	m.db, m.err = gorm.Open(mysql.New(mysql.Config{
-		DSN:                       global.GVA_CONFIG.Mysql.Dsn(), // DSN data source name
-		DefaultStringSize:         191,                           // string 类型字段的默认长度
-		DisableDatetimePrecision:  true,                          // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
-		DontSupportRenameIndex:    true,                          // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
-		DontSupportRenameColumn:   true,                          // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
-		SkipInitializeWithVersion: false,                         // 根据当前 MySQL 版本自动配置
-	}), m._config)
-	global.GVA_DB = m.db
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: gorm 同步模型 生成mysql表
-func (m *_mysql) AutoMigrateTables() {
-	if !global.GVA_DB.Migrator().HasTable("casbin_rule") {
-		m.err = global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{})
-	}
-	m.err = m.db.AutoMigrate(
-		new(model.SysApi),
-		new(model.SysUser),
-		new(model.SysBaseMenu),
-		new(model.SysAuthority),
-		new(model.SysDictionary),
-		new(model.JwtBlacklist),
-		new(model.SysOperationRecord),
-		new(model.SysDictionaryDetail),
-		new(model.SysBaseMenuParameter),
-
-		new(model.WorkflowNode),
-		new(model.WorkflowEdge),
-		new(model.WorkflowProcess),
-		new(model.WorkflowEndPoint),
-		new(model.WorkflowStartPoint),
-
-		new(model.ExaFileUploadAndDownload),
-		new(model.ExaFile),
-		new(model.ExaFileChunk),
-	)
-	if m.err != nil {
-		color.Warn.Printf("[Mysql] --> 初始化数据表失败, err: %v\n", m.err)
-		os.Exit(0)
-	}
-	color.Info.Println("[Mysql] --> 初始化数据表成功! ")
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 初始化数据
-func (m *_mysql) InitData() {
-	if m.err = data.Api.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> sys_apis 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.Admin.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> sys_users 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.Casbin.Init(); m.err != nil {
-		color.Error.Println("\n[Mysql] --> casbin_rule 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.BaseMenu.Init(); m.err != nil {
-		color.Error.Println("\n[Mysql] --> sys_base_menus 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.Authority.Init(); m.err != nil {
-		color.Error.Println("\n[Mysql] --> sys_authorities 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.AuthorityMenu.Init(); m.err != nil {
-		color.Error.Println("\n[Mysql] --> authority_menu 视图创建失败!, err:%v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.Dictionary.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> dictionaries 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.AuthoritiesMenus.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> sys_authority_menus 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.DataAuthorities.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> sys_data_authority_id 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.DictionaryDetail.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> sys_dictionary_details 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = data.Workflow.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> 工作流相关 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	if m.err = information.File.Init(); m.err != nil {
-		color.Warn.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据失败, err: %v", m.err)
-		os.Exit(0)
-	}
-	color.Info.Println("\n[Mysql] --> 初始化数据成功!\n")
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 检查数据库是否存在
-func (m *_mysql) CheckDatabase() {
-	var unknownDatabase = fmt.Sprintf("Unknown database '%v'", global.GVA_CONFIG.Mysql.Dbname)
-	m.Init()
-	if m.err != nil {
-		if strings.Split(m.err.Error(), ": ")[1] == unknownDatabase {
-			color.Debug.Print("\n[Mysql] -->配置文件的数据库名为:")
-			color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-			color.Debug.Println("不存在!\n")
-			color.Debug.Println("您的配置文件所配置的数据库不存在,请选择:")
-			color.Debug.Print("0:请自行创建配置文件所配置的数据库名为:")
-			color.LightGreen.Printf(" {%v} \n", global.GVA_CONFIG.Mysql.Dbname)
-			color.Debug.Print("1:尝试使用sql为您创建配置文件所配置的数据库名为:")
-			color.LightGreen.Printf(" {%v} \n", global.GVA_CONFIG.Mysql.Dbname)
-			color.Debug.Println("2:忽略错误! 注意: 如果不修复, 将会退出初始化数据的进程!")
-			color.Warn.Println("\n注意!!!!!!!")
-			color.Warn.Println("输入1之后,如果配置文件的mysql用户名为root才会有百分百的权限去创建数据库,不是root的话就会跳过创建数据库步骤!\n")
-			color.Debug.Println("请输入指令:")
-			if n, _ := fmt.Scanln(&m.input); n != 0 {
-				if m.input == "1" {
-					if global.GVA_CONFIG.Mysql.Username == "root" {
-						m.database()
-					} else {
-						color.Debug.Print("\n很抱歉,您的配置文件的mysql用户名配置不是root,不确定你有无权限创建数据库,为您跳过创建数据库操作,请自行创建配置文件所配置的数据库名为:")
-						color.LightGreen.Printf(" {%v} \n", global.GVA_CONFIG.Mysql.Dbname)
-					}
-				} else if m.input == "2" {
-					os.Exit(0)
-				} else {
-					color.Warn.Println("[Mysql] --> 请自行创建数据库!")
-					os.Exit(0)
-				}
-			}
-		}
-	}
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 检查数据库编码是不是utf8mb4
-func (m *_mysql) CheckUtf8mb4() {
-	m.Character()
-	if m.character != "utf8mb4" {
-		color.Info.Println("您当前的数据库编码不是utf8mb4,请选择:")
-		color.Info.Println("0:请自行修改数据的编码为utf8mb4!")
-		color.Info.Println("1:尝试使用sql为您修改编码为utf8mb4!")
-		color.Info.Println("2:忽略错误! 注意如果不修复,生成初始数据的时候也许或许可能有几率报错的喔!")
-		color.Info.Println("请输入指令:")
-		if n, _ := fmt.Scanln(&m.input); n != 0 {
-			if m.input == "1" {
-				m.utf8mb4()
-			} else if m.input == "2" {
-				return
-			} else {
-				color.Warn.Println("[Mysql] --> 请自行修改数据的编码为utf8mb4!")
-				os.Exit(0)
-			}
-		}
-	}
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 打印数据库基本信息
-func (m *_mysql) Info() {
-	m.Version()
-	color.Debug.Print("\n您当前的数据库版本: ")
-	color.LightGreen.Printf(" {%v} ", m.version)
-	color.Debug.Print(", 使用的数据库是: ")
-	color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-	color.Debug.Print(", 数据库编码是: ")
-	color.LightGreen.Printf(" {%v} \n\n", m.character)
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 获取数据库版本
-func (m *_mysql) Version() {
-	color.Debug.Println("[Mysql] -->获取数据库版本中.......")
-	if err := global.GVA_DB.Raw("SELECT VERSION() AS version;").Scan(&m.version).Error; err != nil {
-		color.Info.Printf("[Mysql] -->获取数据库版本失败! err: %v", err)
-		m.version = "未知版本~~~"
-	}
-	color.Debug.Printf("\n[Mysql] -->获取数据库版本成功!\n")
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 获取数据库编码
-func (m *_mysql) Character() {
-	var info DatabaseInfo
-	color.Debug.Println("\n[Mysql] -->获取数据库编码中.......")
-	if err := global.GVA_DB.Raw("show variables like 'character_set_database' ").Scan(&info).Error; err != nil {
-		color.Error.Printf("[Mysql] -->获取数据库编码失败! err:%v\n", err)
-		m.character = "未知编码~~~"
-	}
-	color.Debug.Println("\n[Mysql] -->获取数据库编码成功!\n")
-	m.character = info.Value
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 设置配置文件的数据库编码为utf8mb4
-func (m *_mysql) utf8mb4() {
-	color.Debug.Print("\n[Mysql] --> 设置数据库名为:")
-	color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-	color.Debug.Print("数据库的编码为utf8mb4中.......\n")
-	if err := global.GVA_DB.Debug().Exec("ALTER DATABASE " + global.GVA_CONFIG.Mysql.Dbname + " CHARACTER SET `utf8mb4` COLLATE `utf8mb4_general_ci`").Error; err != nil {
-		color.Debug.Print("\n[Mysql] --> 设置数据库名为:")
-		color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-		color.Debug.Print("数据库的编码为utf8mb4失败!请手动修改数据库名为:")
-		color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-		color.Debug.Println("的编码为utf8mb4\n")
-		return
-	}
-	color.Info.Print("\n[Mysql] --> 设置数据库名为:")
-	color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-	color.Debug.Print("的编码为utf8mb4成功!\n")
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 创建配置文件的数据库
-func (m *_mysql) database() {
-	m.old = global.GVA_CONFIG.Mysql.Dbname
-	global.GVA_CONFIG.Mysql.Dbname = "mysql"
-	color.Debug.Printf("\n[Mysql] --> 正在连接 mysql 数据库中.......\n")
-	m.Init()
-	if m.err != nil {
-		color.Error.Printf("\n[Mysql] --> 链接 mysql 数据库失败!, err: %v\n", m.err)
-		color.Error.Printf("[Mysql] --> 请自行创建配置文件所需的数据库!\n")
-		os.Exit(0)
-	}
-	color.Debug.Printf("\n[Mysql] --> 连接 mysql 数据库成功\n")
-	global.GVA_CONFIG.Mysql.Dbname = m.old
-	color.Debug.Print("\n[Mysql] --> 正在为您创建数据库名为:")
-	color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-	color.Debug.Print("中.......\n")
-	if m.err = global.GVA_DB.Exec("CREATE DATABASE IF NOT EXISTS " + global.GVA_CONFIG.Mysql.Dbname + " DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;").Error; m.err != nil {
-		color.Debug.Print("\n[Mysql] --> 创建数据库名为:")
-		color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-		color.Debug.Print("失败!请手动修改数据库名为")
-		color.LightGreen.Printf(" {%v} \n", global.GVA_CONFIG.Mysql.Dbname)
-		os.Exit(0)
-		return
-	}
-	color.Debug.Print("\n[Mysql] --> 正在为您创建数据库名为:")
-	color.LightGreen.Printf(" {%v} ", global.GVA_CONFIG.Mysql.Dbname)
-	color.Debug.Print("成功!\n")
-}
-
-//@author: [SliverHorn](https://github.com/SliverHorn)
-//@description: 处理零值
-func (m *_mysql) zero() {
-	var info DatabaseInfo
-	color.Info.Println("\n[Mysql]--> 获取数据库数据中.......")
-	if err := global.GVA_DB.Raw("show variables like 'sql_mode';").Scan(&info).Error; err != nil {
-		color.Error.Printf("\n[Mysql]-->获取数据库数据失败! err:%v\n", err)
-	}
-	color.Info.Println("\n[Mysql]--> 处理数据库返回数据.......")
-	var values = strings.Split(info.Value, ",")
-	info.Value = ""
-	for i, value := range values {
-		if value == "NO_ZERO_IN_DATE" || value == "NO_ZERO_DATE" {
-		} else {
-			if i == len(values)-1 {
-				info.Value += value
-			} else {
-				info.Value += value + ","
-			}
-		}
-	}
-	if err := global.GVA_DB.Exec("set global sql_mode='" + info.Value + "';").Error; err != nil {
-		color.Error.Printf("\n[Mysql]--> 设置数据库的零值失效失败! err:%v\n", err)
-		return
-	}
-	color.Info.Println("\n[Mysql]--> 设置数据库零值失效成功")
-}

+ 0 - 12
server/initdb.bat

@@ -1,12 +0,0 @@
-@echo ##########Formatting code#########################################
-go fmt ./ && go vet ./
-@echo ##########Format the code successfully############################
-@echo ##########Compiling gva.exe#######################################
-go build -o gva.exe cmd/main.go
-@echo ##########Successfully compiled gva.exe###########################
-@echo ##########Initializing data using gva.exe#########################
-gva.exe initdb
-@echo ##########Use gva.exe to initialize data successfully#############
-@echo ##########Deleting gva.exe########################################
-del gva.exe
-@echo ##########Deleting gva.exe successfully###########################

+ 0 - 20
server/middleware/init.go

@@ -1,20 +0,0 @@
-package middleware
-
-import (
-	"gin-vue-admin/global"
-	"gin-vue-admin/model/response"
-
-	"github.com/gin-gonic/gin"
-)
-
-func InitCheck() gin.HandlerFunc {
-	return func(c *gin.Context) {
-		if global.GVA_DB == nil {
-			// 未初始化
-			response.FailWithDetailed(gin.H{"database": true}, "数据库未初始化", c)
-			c.Abort()
-			return
-		}
-		c.Next()
-	}
-}

+ 1 - 0
server/model/sys_initdb.go

@@ -0,0 +1 @@
+package model

+ 1 - 0
server/router/sys_init.go

@@ -0,0 +1 @@
+package router

+ 0 - 0
server/cmd/information/system/admin.go → server/source/admin.go


+ 0 - 0
server/cmd/information/system/api.go → server/source/api.go


+ 0 - 0
server/cmd/information/system/authorities_menus.go → server/source/authorities_menus.go


+ 0 - 0
server/cmd/information/system/authority.go → server/source/authority.go


+ 0 - 0
server/cmd/information/system/authority_menu.go → server/source/authority_menu.go


+ 0 - 0
server/cmd/information/system/casbin.go → server/source/casbin.go


+ 0 - 0
server/cmd/information/system/data_authorities.go → server/source/data_authorities.go


+ 0 - 0
server/cmd/information/system/dictionary.go → server/source/dictionary.go


+ 0 - 0
server/cmd/information/system/dictionary_details.go → server/source/dictionary_details.go


+ 0 - 0
server/cmd/information/extra/file.go → server/source/file.go


+ 0 - 0
server/cmd/information/system/menu.go → server/source/menu.go


+ 0 - 0
server/cmd/information/system/workflow.go → server/source/workflow.go


+ 0 - 199
server/utils/cmd_Task.go

@@ -1,199 +0,0 @@
-package utils
-
-import (
-	"bytes"
-	"context"
-	"fmt"
-	"io"
-	"os"
-	"os/exec"
-	"runtime"
-	"sync"
-)
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@interface_name: RunTask
-//@description: Task接口
-
-type RunTask interface {
-	AddTask()
-	RunTask()
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@struct_name: T
-//@description: Task任务
-
-type T struct {
-	sync.Mutex
-
-	// 获取事件channel
-	ch chan struct{}
-
-	closeChan chan struct{}
-
-	// 记录process对象
-	p *os.Process
-
-	// 执行任务
-	f func(chan struct{}) error
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: NewT
-//@description: T的实例化方法
-//@return: *T
-
-func NewT() *T {
-	return newT(nil)
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: newT
-//@description:
-//@param: f func(chan struct{}) error
-//@return: *T
-
-func newT(f func(chan struct{}) error) *T {
-	t := &T{
-		Mutex:     sync.Mutex{},
-		ch:        make(chan struct{}, 1),
-		closeChan: make(chan struct{}),
-		f:         f,
-	}
-	if f == nil {
-		t.f = t.DefaultF
-	}
-	return t
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: *T
-//@function: AddTask
-//@description: 添加任务
-
-func (t *T) AddTask() {
-	select {
-	case t.ch <- struct{}{}:
-	default:
-		// 代表已经有任务了
-		// 直接丢弃这次任务
-	}
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: *T
-//@function: RunTask
-//@description: 启动任务
-
-func (t *T) RunTask() {
-	fmt.Println("进入")
-	// 这里做的make 是用于关闭上一个执行的任务
-	ch := make(chan struct{})
-	// 先run服务
-	go t.f(ch)
-	for {
-		_, ok := <-t.ch
-		if !ok {
-			return
-		}
-		ch <- struct{}{}
-		// 等待上一个关闭
-		<-t.closeChan
-		go t.f(ch)
-	}
-
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: t *T
-//@function: DefaultF
-//@description: 默认的StartFunction
-//@param: ch chan struct{}
-//@return: error
-
-func (t *T) DefaultF(ch chan struct{}) error {
-	var buildCmd *exec.Cmd
-	var cmd *exec.Cmd
-
-	// 检测系统是否有编译环境
-	_, err := exec.LookPath("go")
-	if err != nil {
-		return err
-	}
-	// build
-
-	switch runtime.GOOS {
-	case "windows":
-		buildCmd = exec.Command("go", "build", "-o", "server.exe", "main.go")
-	default:
-		buildCmd = exec.Command("go", "build", "-o", "server", "main.go")
-	}
-	//cmd = exec.Command("go", "run", "main.go")
-	err = buildCmd.Run()
-	if err != nil {
-		return err
-	}
-	fmt.Println("build 执行完成")
-	// 执行
-	switch runtime.GOOS {
-	case "windows":
-		cmd = exec.Command("server.exe")
-	default:
-		cmd = exec.Command("./server")
-	}
-
-	// 开始执行任务
-	ctx, cancel := context.WithCancel(context.Background())
-	err = t.echo(cmd, ctx)
-	<-ch
-	// 回收资源
-	fmt.Println("pid:", t.p.Pid, "->Kill")
-	err = t.p.Kill()
-	cancel()
-	// 发送关闭完成信号
-	t.closeChan <- struct{}{}
-	return err
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: t *T
-//@function: echo
-//@description: 封装回显
-//@param: cmd *exec.Cmd, ctx context.Context
-//@return: error
-
-func (t *T) echo(cmd *exec.Cmd, ctx context.Context) error {
-	var stdoutBuf bytes.Buffer
-	stdoutIn, _ := cmd.StdoutPipe()
-	var errStdout error
-	stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
-	err := cmd.Start()
-	if err != nil {
-		return err
-	}
-	go func(ctx context.Context) {
-		_, errStdout = io.Copy(stdout, stdoutIn)
-		select {
-		case <-ctx.Done():
-			return
-		default:
-		}
-	}(ctx)
-	t.p = cmd.Process
-	fmt.Println("pid", t.p.Pid)
-	go func() {
-		_ = cmd.Wait()
-		if errStdout != nil {
-			fmt.Printf("failed to capture stdout or stderr\n")
-		}
-		fmt.Printf("%s\n", string(stdoutBuf.Bytes()))
-		select {
-		case <-ctx.Done():
-			//_ = os.Stdout.Close()
-			return
-		default:
-		}
-	}()
-	return nil
-}

+ 0 - 174
server/utils/cmd_monitor.go

@@ -1,174 +0,0 @@
-package utils
-
-import (
-	"errors"
-	"fmt"
-	"github.com/fsnotify/fsnotify"
-	"io/ioutil"
-	"os"
-	"path/filepath"
-)
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@struct_name: Watch
-//@description: 监控对象
-
-type Watch struct {
-	*fsnotify.Watcher
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: NewWatch
-//@description: Watch的实例化方法
-//@return: *Watch
-
-func NewWatch() *Watch {
-	obj, _ := fsnotify.NewWatcher()
-	return &Watch{obj}
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: w *Watch
-//@function: Watch
-//@description: 监控对象
-//@param: path string, t *T
-//@return: error
-
-func (w *Watch) Watch(path string, t *T) error {
-	// 先转化为绝对路径
-	path, err := filepath.Abs(path)
-	if err != nil {
-		return err
-	}
-	// 判断是单个文件还是目录文件
-	fileInfo, err := os.Stat(path)
-	if err != nil {
-		return err
-	}
-	// 判断是否是目录 添加监控
-	if fileInfo.IsDir() {
-		// dir
-		err = w.watchDir(path)
-
-	} else {
-		err = w.watchFile(path)
-
-	}
-	if err != nil {
-		return err
-	}
-	c := make(chan error)
-	// 启动监控
-	go func() {
-		for {
-			select {
-			case even, ok := <-w.Events:
-				if !ok {
-					// close
-					fmt.Println("Errors close")
-					c <- errors.New("errors close")
-					return
-				}
-				// 判断事件
-				switch {
-				case even.Op&fsnotify.Create == fsnotify.Create:
-					//这里获取新创建文件的信息,如果是目录,则加入监控中
-					fmt.Println("创建文件 : ", even.Name)
-					//t.AddTask()
-					_ = w.Add(even.Name)
-				case even.Op&fsnotify.Write == fsnotify.Write:
-					fmt.Println("修改文件 : ", even.Name)
-					w.addTask(t, even.Name)
-				case even.Op&fsnotify.Remove == fsnotify.Remove || even.Op&fsnotify.Rename == fsnotify.Rename:
-					fmt.Println("删除或重命名文件 : ", even.Name)
-					_ = w.Remove(even.Name)
-					w.addTask(t, even.Name)
-				}
-			case err = <-w.Errors:
-				fmt.Println("even Error:", err)
-				c <- err
-				return
-			}
-		}
-	}()
-	return <-c
-
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: w *Watch
-//@function: watchDir
-//@description: 处理监控目录
-//@param: path string
-//@return: error
-
-func (w *Watch) watchDir(path string) error {
-	// 先将自己添加到监控
-	err := w.Add(path)
-
-	if err != nil {
-		return err
-	}
-	fileSlice, err := ioutil.ReadDir(path)
-	if err != nil {
-		return err
-	}
-	for _, f := range fileSlice {
-		fPath := filepath.Join(path, f.Name())
-		if !f.IsDir() {
-			// 判断是否可监控的文件
-			if chickPower(fPath) {
-				err = w.watchFile(fPath)
-				if err != nil {
-					return err
-				}
-			}
-		} else {
-			err := w.watchDir(fPath)
-			if err != nil {
-				return err
-			}
-		}
-	}
-	return err
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: w *Watch
-//@function: watchDir
-//@description: 处理监控单文件
-//@param: path string
-//@return: error
-
-func (w *Watch) watchFile(path string) error {
-	var err error
-	if chickPower(path) {
-		err = w.Add(path)
-	}
-	return err
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@function: chickPower
-//@description: 判断是否在可控范围内
-//@param: path string
-//@return: error
-
-func chickPower(name string) bool {
-	name = filepath.Ext(name)
-	return name == ".go" || name == ".yaml"
-}
-
-//@author: [songzhibin97](https://github.com/songzhibin97)
-//@object: w *Watch
-//@function: addTask
-//@description: 偏函数 简化发送任务
-//@param: path string
-//@return: error
-
-func (w *Watch) addTask(t *T, name string) {
-	if chickPower(name) {
-		fmt.Println("Add Task->>>>>>")
-		t.AddTask()
-	}
-}