Browse Source

升级gva 工具 支持创建数据库与utf8mb4的sql修正功能, 版本迭代为v0.0.4

main
SliverHorn 4 years ago
parent
commit
ef41dc4213
  1. 14
      server/cmd/datas/AuthorityMenu.go
  2. 36
      server/cmd/datas/authority_Ids.go
  3. 79
      server/cmd/datas/authority_menus.go
  4. 31
      server/cmd/datas/customers.go
  5. 58
      server/cmd/datas/init.go
  6. 35
      server/cmd/gva/initdb.go
  7. 316
      server/cmd/gva/mysql.go
  8. 2
      server/cmd/gva/version.go
  9. 31
      server/cmd/information/extra/file.go
  10. 27
      server/cmd/information/system/admin.go
  11. 25
      server/cmd/information/system/api.go
  12. 83
      server/cmd/information/system/authorities_menus.go
  13. 28
      server/cmd/information/system/authority.go
  14. 25
      server/cmd/information/system/authority_menu.go
  15. 28
      server/cmd/information/system/casbin.go
  16. 40
      server/cmd/information/system/data_authorities.go
  17. 30
      server/cmd/information/system/dictionary.go
  18. 29
      server/cmd/information/system/dictionary_details.go
  19. 29
      server/cmd/information/system/menu.go
  20. 20
      server/cmd/information/system/workflow.go
  21. 4
      server/config/gorm.go

14
server/cmd/datas/AuthorityMenu.go

@ -1,14 +0,0 @@
package datas
import (
"github.com/gookit/color"
"gorm.io/gorm"
)
func InitAuthorityMenu(db *gorm.DB) {
if err := db.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error; err != nil {
color.Danger.Println("authority_menu视图已存在!")
return
}
color.Info.Println("authority_menu视图创建成功!")
}

36
server/cmd/datas/authority_Ids.go

@ -1,36 +0,0 @@
package datas
import (
"github.com/gookit/color"
"gorm.io/gorm"
"os"
)
type SysDataAuthorityId struct {
SysAuthorityAuthorityId string
DataAuthorityIdAuthorityId string
}
var DataAuthorityId = []SysDataAuthorityId{
{"888", "888"},
{"888", "8881"},
{"888", "9528"},
{"9528", "8881"},
{"9528", "9528"},
}
func InitSysDataAuthorityId(db *gorm.DB) {
if err := db.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ?", []string{"888", "9528"}).Find(&[]SysDataAuthorityId{}).RowsAffected == 5 {
color.Danger.Println("sys_data_authority_id表的初始数据已存在!")
return nil
}
if err := tx.Create(&DataAuthorityId).Error; err != nil { // 遇到错误时回滚事务
return err
}
return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_data_authority_id 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}

79
server/cmd/datas/authority_menus.go

@ -1,79 +0,0 @@
package datas
import (
"github.com/gookit/color"
"gorm.io/gorm"
"os"
)
type SysAuthorityMenus struct {
SysAuthorityAuthorityId string
SysBaseMenuId uint
}
var AuthorityMenus = []SysAuthorityMenus{
{"888", 1},
{"888", 2},
{"888", 3},
{"888", 4},
{"888", 5},
{"888", 6},
{"888", 7},
{"888", 8},
{"888", 9},
{"888", 10},
{"888", 11},
{"888", 12},
{"888", 13},
{"888", 14},
{"888", 15},
{"888", 16},
{"888", 17},
{"888", 18},
{"888", 19},
{"888", 20},
{"888", 21},
{"888", 22},
{"888", 23},
{"888", 24},
{"888", 25},
{"888", 26},
{"888", 27},
{"888", 28},
{"888", 29},
{"8881", 1},
{"8881", 2},
{"8881", 8},
{"9528", 1},
{"9528", 2},
{"9528", 3},
{"9528", 4},
{"9528", 5},
{"9528", 6},
{"9528", 7},
{"9528", 8},
{"9528", 9},
{"9528", 10},
{"9528", 11},
{"9528", 12},
{"9528", 14},
{"9528", 15},
{"9528", 16},
{"9528", 17},
}
func InitSysAuthorityMenus(db *gorm.DB) {
if err := db.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ?", []string{"888", "8881", "9528"}).Find(&[]SysAuthorityMenus{}).RowsAffected == 53 {
color.Danger.Println("sys_authority_menus表的初始数据已存在!")
return nil
}
if err := tx.Create(&AuthorityMenus).Error; err != nil { // 遇到错误时回滚事务
return err
}
return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_authority_menus 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}

31
server/cmd/datas/customers.go

@ -1,31 +0,0 @@
package datas
import (
"gin-vue-admin/global"
"github.com/gookit/color"
"os"
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
var Customers = []model.ExaCustomer{
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
}
func InitExaCustomer(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ? ", []int{1}).Find(&[]model.ExaCustomer{}).RowsAffected == 1 {
color.Danger.Println("exa_customers表的初始数据已存在!")
return nil
}
if err := tx.Create(&Customers).Error; err != nil { // 遇到错误时回滚事务
return err
}
return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> exa_customers 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}

58
server/cmd/datas/init.go

@ -1,58 +0,0 @@
package datas
import (
"gin-vue-admin/model"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color"
"gorm.io/gorm"
"os"
)
func InitMysqlData(db *gorm.DB) {
InitSysApi(db)
InitSysUser(db)
InitExaCustomer(db)
InitCasbinModel(db)
InitSysAuthority(db)
InitSysBaseMenus(db)
InitAuthorityMenu(db)
InitSysDictionary(db)
InitSysAuthorityMenus(db)
InitSysDataAuthorityId(db)
InitSysDictionaryDetail(db)
InitExaFileUploadAndDownload(db)
InitWkProcess(db)
}
func InitMysqlTables(db *gorm.DB) {
var err error
if !db.Migrator().HasTable("casbin_rule") {
err = db.Migrator().CreateTable(&gormadapter.CasbinRule{})
}
err = db.AutoMigrate(
model.SysApi{},
model.SysUser{},
model.ExaFile{},
model.ExaCustomer{},
model.SysBaseMenu{},
model.SysAuthority{},
model.JwtBlacklist{},
model.ExaFileChunk{},
model.SysDictionary{},
model.ExaSimpleUploader{},
model.SysOperationRecord{},
model.SysDictionaryDetail{},
model.SysBaseMenuParameter{},
model.ExaFileUploadAndDownload{},
model.WorkflowProcess{},
model.WorkflowNode{},
model.WorkflowEdge{},
model.WorkflowStartPoint{},
model.WorkflowEndPoint{},
)
if err != nil {
color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err)
os.Exit(0)
}
color.Info.Println("[Mysql]-->初始化数据表成功")
}

35
server/cmd/gva/initdb.go

@ -16,10 +16,7 @@ limitations under the License.
package gva package gva
import ( import (
"gin-vue-admin/cmd/datas"
"gin-vue-admin/core" "gin-vue-admin/core"
"gin-vue-admin/initialize"
"github.com/gookit/color" "github.com/gookit/color"
_ "gin-vue-admin/core" _ "gin-vue-admin/core"
@ -38,30 +35,22 @@ var initdbCmd = &cobra.Command{
3. sqlite未适配, 3. sqlite未适配,
4. sqlserver未适配`, 4. sqlserver未适配`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
frame, _ := cmd.Flags().GetString("frame")
path, _ := cmd.Flags().GetString("path") path, _ := cmd.Flags().GetString("path")
global.GVA_VP = core.Viper(path) global.GVA_VP = core.Viper(path)
global.GVA_LOG = core.Zap() // 初始化zap日志库 global.GVA_LOG = core.Zap() // 初始化zap日志库
db := initialize.GormMysql()
switch global.GVA_CONFIG.System.DbType {
case "mysql":
datas.InitMysqlTables(db)
datas.InitMysqlData(db)
case "postgresql":
color.Info.Println("postgresql功能开发中")
case "sqlite":
color.Info.Println("sqlite功能开发中")
case "sqlserver":
color.Info.Println("sqlserver功能开发中")
default:
datas.InitMysqlTables(db)
datas.InitMysqlData(db)
}
frame, _ := cmd.Flags().GetString("frame")
if frame == "gf" {
Mysql.CheckDatabase()
Mysql.CheckUtf8mb4()
Mysql.Info()
Mysql.Init()
switch frame {
case "gin":
if global.GVA_CONFIG.System.DbType == "mysql" {
Mysql.AutoMigrateTables()
Mysql.InitData()
}
case "gf":
color.Info.Println("gf功能开发中") color.Info.Println("gf功能开发中")
return
} else {
return
} }
}, },
} }

316
server/cmd/gva/mysql.go

@ -0,0 +1,316 @@
package gva
import (
"fmt"
information "gin-vue-admin/cmd/information/extra"
data "gin-vue-admin/cmd/information/system"
"gin-vue-admin/global"
"gin-vue-admin/model"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"os"
"strings"
)
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: 256, // 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]--> 设置数据库零值失效成功")
}

2
server/cmd/gva/version.go

@ -27,7 +27,7 @@ var versionCmd = &cobra.Command{
Short: "版本信息", Short: "版本信息",
Long: `版本的长信息`, Long: `版本的长信息`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
color.Green.Println("v0.0.3")
color.Green.Println("v0.0.4")
}, },
} }

31
server/cmd/datas/files.go → server/cmd/information/extra/file.go

@ -1,33 +1,34 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"github.com/gookit/color"
"os"
"time"
"gin-vue-admin/model" "gin-vue-admin/model"
"github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
var Files = []model.ExaFileUploadAndDownload{
var File = new(file)
type file struct{}
var files = []model.ExaFileUploadAndDownload{
{global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"}, {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
{global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"}, {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
} }
func InitExaFileUploadAndDownload(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: exa_file_upload_and_downloads 表初始化数据
func (f *file) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 { if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 {
color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!")
color.Danger.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Files).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&files).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("[Mysql]-->初始数据成功")
color.Info.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> exa_file_upload_and_downloads 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

27
server/cmd/datas/users.go → server/cmd/information/system/admin.go

@ -1,33 +1,36 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gin-vue-admin/model"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"gorm.io/gorm" "gorm.io/gorm"
) )
var Users = []model.SysUser{
var Admin = new(admin)
type admin struct{}
var admins = []model.SysUser{
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/gva_header.jpg", AuthorityId: "888"}, {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/gva_header.jpg", AuthorityId: "888"},
{GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"}, {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"},
} }
func InitSysUser(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_users 表数据初始化
func (a *admin) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.SysUser{}).RowsAffected == 2 { if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.SysUser{}).RowsAffected == 2 {
color.Danger.Println("sys_users表的初始数据已存在!")
color.Danger.Println("\n[Mysql] --> sys_users 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Users).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&admins).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_users 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_users 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

25
server/cmd/datas/apis.go → server/cmd/information/system/api.go

@ -1,16 +1,19 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model" "gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
) )
var Apis = []model.SysApi{
var Api = new(api)
type api struct{}
var apis = []model.SysApi{
{global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"}, {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"},
{global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/register", "用户注册", "user", "POST"}, {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/register", "用户注册", "user", "POST"},
{global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"}, {global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"},
@ -91,18 +94,18 @@ var Apis = []model.SysApi{
{global.GVA_MODEL{ID: 79, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/completeWorkflowMove", "提交工作流", "workflowProcess", "POST"}, {global.GVA_MODEL{ID: 79, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/completeWorkflowMove", "提交工作流", "workflowProcess", "POST"},
} }
func InitSysApi(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_apis 表数据初始化
func (a *api) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 67}).Find(&[]model.SysApi{}).RowsAffected == 2 { if tx.Where("id IN ?", []int{1, 67}).Find(&[]model.SysApi{}).RowsAffected == 2 {
color.Danger.Println("sys_apis表的初始数据已存在!")
color.Danger.Println("\n[Mysql] --> sys_apis 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Apis).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&apis).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_apis 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_apis 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

83
server/cmd/information/system/authorities_menus.go

@ -0,0 +1,83 @@
package information
import (
"gin-vue-admin/global"
"github.com/gookit/color"
"gorm.io/gorm"
)
var AuthoritiesMenus = new(authoritiesMenus)
type authoritiesMenus struct{}
type AuthorityMenus struct {
AuthorityId string `gorm:"column:sys_authority_authority_id"`
BaseMenuId uint `gorm:"column:sys_base_menu_id"`
}
var authorityMenus = []AuthorityMenus{
{"888", 1},
{"888", 2},
{"888", 3},
{"888", 4},
{"888", 5},
{"888", 6},
{"888", 7},
{"888", 8},
{"888", 9},
{"888", 10},
{"888", 11},
{"888", 12},
{"888", 13},
{"888", 14},
{"888", 15},
{"888", 16},
{"888", 17},
{"888", 18},
{"888", 19},
{"888", 20},
{"888", 21},
{"888", 22},
{"888", 23},
{"888", 24},
{"888", 25},
{"888", 26},
{"888", 27},
{"888", 28},
{"888", 29},
{"8881", 1},
{"8881", 2},
{"8881", 8},
{"9528", 1},
{"9528", 2},
{"9528", 3},
{"9528", 4},
{"9528", 5},
{"9528", 6},
{"9528", 7},
{"9528", 8},
{"9528", 9},
{"9528", 10},
{"9528", 11},
{"9528", 12},
{"9528", 14},
{"9528", 15},
{"9528", 16},
{"9528", 17},
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_authority_menus 表数据初始化
func (a *authoritiesMenus) Init() error {
return global.GVA_DB.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ('888', '8881', '9528')").Find(&[]AuthorityMenus{}).RowsAffected == 48 {
color.Danger.Println("\n[Mysql] --> sys_authority_menus 表的初始数据已存在!")
return nil
}
if err := tx.Create(&authorityMenus).Error; err != nil { // 遇到错误时回滚事务
return err
}
color.Info.Println("\n[Mysql] --> sys_authority_menus 表初始数据成功!")
return nil
})
}

28
server/cmd/datas/authorities.go → server/cmd/information/system/authority.go

@ -1,32 +1,36 @@
package datas
package information
import ( import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gin-vue-admin/model"
"gorm.io/gorm" "gorm.io/gorm"
) )
var Authorities = []model.SysAuthority{
var Authority = new(authority)
type authority struct{}
var authorities = []model.SysAuthority{
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"}, {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"}, {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"}, {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
} }
func InitSysAuthority(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_authorities 表数据初始化
func (a *authority) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 { if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 {
color.Danger.Println("sys_authorities表的初始数据已存在!")
color.Danger.Println("\n[Mysql] --> sys_authorities 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Authorities).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&authorities).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_authorities 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_authorities 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

25
server/cmd/information/system/authority_menu.go

@ -0,0 +1,25 @@
package information
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color"
)
var AuthorityMenu = new(authorityMenu)
type authorityMenu struct{}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: authority_menu 视图数据初始化
func (a *authorityMenu) Init() error {
if global.GVA_DB.Find(&[]model.SysMenu{}).RowsAffected > 0 {
color.Danger.Println("\n[Mysql] --> authority_menu 视图已存在!")
return nil
}
if err := global.GVA_DB.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error; err != nil {
return err
}
color.Info.Println("\n[Mysql] --> authority_menu 视图创建成功!")
return nil
}

28
server/cmd/datas/casbins.go → server/cmd/information/system/casbin.go

@ -1,13 +1,17 @@
package datas
package information
import ( import (
"gin-vue-admin/global"
gormadapter "github.com/casbin/gorm-adapter/v3" gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color" "github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
"os"
) )
var Carbines = []gormadapter.CasbinRule{
var Casbin = new(casbin)
type casbin struct{}
var carbines = []gormadapter.CasbinRule{
{PType: "p", V0: "888", V1: "/base/login", V2: "POST"}, {PType: "p", V0: "888", V1: "/base/login", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/register", V2: "POST"}, {PType: "p", V0: "888", V1: "/user/register", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/createApi", V2: "POST"}, {PType: "p", V0: "888", V1: "/api/createApi", V2: "POST"},
@ -164,18 +168,18 @@ var Carbines = []gormadapter.CasbinRule{
{PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"}, {PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"},
} }
func InitCasbinModel(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
if tx.Where("p_type = ? AND v0 IN ?", "p", []string{"888", "8881", "9528"}).Find(&[]gormadapter.CasbinRule{}).RowsAffected == 142 {
color.Danger.Println("casbin_rule表的初始数据已存在!")
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: casbin_rule 表数据初始化
func (c *casbin) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Find(&[]gormadapter.CasbinRule{}).RowsAffected == 154 {
color.Danger.Println("\n[Mysql] --> casbin_rule 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Carbines).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&carbines).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> casbin_rule 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> casbin_rule 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

40
server/cmd/information/system/data_authorities.go

@ -0,0 +1,40 @@
package information
import (
"gin-vue-admin/global"
"github.com/gookit/color"
"gorm.io/gorm"
)
var DataAuthorities = new(dataAuthorities)
type dataAuthorities struct{}
type DataAuthority struct {
AuthorityId string `gorm:"column:sys_authority_authority_id"`
DataAuthority string `gorm:"column:data_authority_id_authority_id"`
}
var infos = []DataAuthority{
{"888", "888"},
{"888", "8881"},
{"888", "9528"},
{"9528", "8881"},
{"9528", "9528"},
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_data_authority_id 表数据初始化
func (d *dataAuthorities) Init() error {
return global.GVA_DB.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
if tx.Where("authority_id IN ('888', '9528') ").Find(&[]DataAuthority{}).RowsAffected == 5 {
color.Danger.Println("\n[Mysql] --> sys_data_authority_id 表初始数据已存在!")
return nil
}
if err := tx.Create(&infos).Error; err != nil { // 遇到错误时回滚事务
return err
}
color.Info.Println("\n[Mysql] --> sys_data_authority_id 表初始数据成功!")
return nil
})
}

30
server/cmd/datas/dictionaries.go → server/cmd/information/system/dictionary.go

@ -1,19 +1,25 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gin-vue-admin/model"
"gorm.io/gorm" "gorm.io/gorm"
) )
func InitSysDictionary(db *gorm.DB) {
var status = new(bool)
var Dictionary = new(dictionary)
type dictionary struct{}
var status = new(bool)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_dictionaries 表数据初始化
func (d *dictionary) Init() error {
*status = true *status = true
Dictionaries := []model.SysDictionary{
var dictionaries = []model.SysDictionary{
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"}, {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"},
{GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"}, {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
{GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"}, {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
@ -21,17 +27,15 @@ func InitSysDictionary(db *gorm.DB) {
{GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"}, {GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
{GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"}, {GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
} }
if err := db.Transaction(func(tx *gorm.DB) error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 6}).Find(&[]model.SysDictionary{}).RowsAffected == 2 { if tx.Where("id IN ?", []int{1, 6}).Find(&[]model.SysDictionary{}).RowsAffected == 2 {
color.Danger.Println("sys_dictionaries表初始数据已存在!")
color.Danger.Println("\n[Mysql] --> sys_dictionaries 表初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&Dictionaries).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&dictionaries).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_dictionaries 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_dictionaries 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

29
server/cmd/datas/dictionary_details.go → server/cmd/information/system/dictionary_details.go

@ -1,19 +1,22 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gin-vue-admin/model"
"gorm.io/gorm" "gorm.io/gorm"
) )
func InitSysDictionaryDetail(db *gorm.DB) {
status := new(bool)
*status = true
DictionaryDetail := []model.SysDictionaryDetail{
var DictionaryDetail = new(dictionaryDetail)
type dictionaryDetail struct{}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: dictionary_details 表数据初始化
func (d *dictionaryDetail) Init() error {
var details = []model.SysDictionaryDetail{
{global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2}, {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2},
{global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2}, {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2},
{global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2}, {global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2},
@ -38,17 +41,15 @@ func InitSysDictionaryDetail(db *gorm.DB) {
{global.GVA_MODEL{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5}, {global.GVA_MODEL{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5},
{global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6}, {global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
} }
if err := db.Transaction(func(tx *gorm.DB) error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 23}).Find(&[]model.SysDictionaryDetail{}).RowsAffected == 2 { if tx.Where("id IN ?", []int{1, 23}).Find(&[]model.SysDictionaryDetail{}).RowsAffected == 2 {
color.Danger.Println("sys_dictionary_details表的初始数据已存在!")
color.Danger.Println("\n[Mysql] --> sys_dictionary_details 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&DictionaryDetail).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&details).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_dictionary_details 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_dictionary_details 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

29
server/cmd/datas/menus.go → server/cmd/information/system/menu.go

@ -1,16 +1,19 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"os"
"time" "time"
"gin-vue-admin/model"
"gorm.io/gorm" "gorm.io/gorm"
) )
var BaseMenus = []model.SysBaseMenu{
var BaseMenu = new(menu)
type menu struct{}
var menus = []model.SysBaseMenu{
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}}, {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}},
{GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}}, {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}},
{GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}}, {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}},
@ -42,18 +45,18 @@ var BaseMenus = []model.SysBaseMenu{
{GVA_MODEL: global.GVA_MODEL{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "24", Path: "need", Name: "need", Hidden: false, Component: "view/workflow/userList/need.vue", Sort: 0, Meta: model.Meta{Title: "我的待办", Icon: "s-platform"}}, {GVA_MODEL: global.GVA_MODEL{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "24", Path: "need", Name: "need", Hidden: false, Component: "view/workflow/userList/need.vue", Sort: 0, Meta: model.Meta{Title: "我的待办", Icon: "s-platform"}},
} }
func InitSysBaseMenus(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 23}).Find(&[]model.SysBaseMenu{}).RowsAffected == 2 {
color.Danger.Println("sys_base_menus表的初始数据已存在!")
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_base_menus 表数据初始化
func (m *menu) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 29}).Find(&[]model.SysBaseMenu{}).RowsAffected == 2 {
color.Danger.Println("\n[Mysql] --> sys_base_menus 表的初始数据已存在!")
return nil return nil
} }
if err := tx.Create(&BaseMenus).Error; err != nil { // 遇到错误时回滚事务
if err := tx.Create(&menus).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> sys_base_menus 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_base_menus 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

20
server/cmd/datas/sys_workflow.go → server/cmd/information/system/workflow.go

@ -1,14 +1,17 @@
package datas
package information
import ( import (
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model" "gin-vue-admin/model"
"github.com/gookit/color" "github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
"os"
"time" "time"
) )
var Workflow = new(workflow)
type workflow struct{}
var WorkflowProcess = []model.WorkflowProcess{ var WorkflowProcess = []model.WorkflowProcess{
{ID: "leaveFlow", CreatedAt: time.Now(), UpdatedAt: time.Now(), Name: "leaveFlow", Clazz: "process", Label: "请假流程(演示)", HideIcon: false, Description: "请假流程演示", View: "view/iconList/index.vue"}, {ID: "leaveFlow", CreatedAt: time.Now(), UpdatedAt: time.Now(), Name: "leaveFlow", Clazz: "process", Label: "请假流程(演示)", HideIcon: false, Description: "请假流程演示", View: "view/iconList/index.vue"},
} }
@ -36,8 +39,10 @@ var WorkflowEndPoint = []model.WorkflowEndPoint{
{WorkflowEdgeID: "flow1604985881207", GVA_MODEL: global.GVA_MODEL{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, X: 517.5, Y: 302, Index: 2}, {WorkflowEdgeID: "flow1604985881207", GVA_MODEL: global.GVA_MODEL{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, X: 517.5, Y: 302, Index: 2},
} }
func InitWkProcess(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: 工作流相关 表数据初始化
func (w *workflow) Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&WorkflowProcess).Error; err != nil { // 遇到错误时回滚事务 if err := tx.Create(&WorkflowProcess).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
@ -53,10 +58,7 @@ func InitWkProcess(db *gorm.DB) {
if err := tx.Create(&WorkflowEndPoint).Error; err != nil { // 遇到错误时回滚事务 if err := tx.Create(&WorkflowEndPoint).Error; err != nil { // 遇到错误时回滚事务
return err return err
} }
color.Info.Println("\n[Mysql] --> 工作流相关 表初始数据成功!")
return nil return nil
}); err != nil {
color.Warn.Printf("[Mysql]-->工作流相关 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
})
} }

4
server/config/gorm.go

@ -11,3 +11,7 @@ type Mysql struct {
LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
LogZap string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` LogZap string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
} }
func (m *Mysql) Dsn() string {
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config
}
Loading…
Cancel
Save