SliverHorn
4 years ago
21 changed files with 619 additions and 355 deletions
-
14server/cmd/datas/AuthorityMenu.go
-
36server/cmd/datas/authority_Ids.go
-
79server/cmd/datas/authority_menus.go
-
31server/cmd/datas/customers.go
-
58server/cmd/datas/init.go
-
35server/cmd/gva/initdb.go
-
316server/cmd/gva/mysql.go
-
2server/cmd/gva/version.go
-
31server/cmd/information/extra/file.go
-
27server/cmd/information/system/admin.go
-
25server/cmd/information/system/api.go
-
83server/cmd/information/system/authorities_menus.go
-
28server/cmd/information/system/authority.go
-
25server/cmd/information/system/authority_menu.go
-
28server/cmd/information/system/casbin.go
-
40server/cmd/information/system/data_authorities.go
-
30server/cmd/information/system/dictionary.go
-
29server/cmd/information/system/dictionary_details.go
-
29server/cmd/information/system/menu.go
-
20server/cmd/information/system/workflow.go
-
4server/config/gorm.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视图创建成功!") |
|
||||
} |
|
@ -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) |
|
||||
} |
|
||||
} |
|
@ -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) |
|
||||
} |
|
||||
} |
|
@ -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) |
|
||||
} |
|
||||
} |
|
@ -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]-->初始化数据表成功") |
|
||||
} |
|
@ -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]--> 设置数据库零值失效成功") |
||||
|
} |
@ -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) |
|
||||
} |
|
||||
|
}) |
||||
} |
} |
@ -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) |
|
||||
} |
|
||||
|
}) |
||||
} |
} |
@ -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 |
||||
|
}) |
||||
|
} |
@ -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) |
|
||||
} |
|
||||
|
}) |
||||
} |
} |
@ -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 |
||||
|
} |
@ -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 |
||||
|
}) |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue