diff --git a/.gitignore b/.gitignore index 41aca02a..e7cc5a9d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ yarn-error.log* go.sum /server/log/ +/server/gva /server/latest_log *.iml diff --git a/README-en.md b/README-en.md index 2aed4fce..fdc1bd81 100644 --- a/README-en.md +++ b/README-en.md @@ -70,7 +70,7 @@ We are excited that you are interested in contributing to gin-vue-admin. Before ``` - node version > v8.6.0 -- golang version >= v1.11 +- golang version >= v1.14 - IDE recommendation: Goland - We recommend you to apply for your own cloud service in QINIU. Replace the public key, private key, warehouse name and default url address with your own, so as not to mess up the test database. ``` diff --git a/README.md b/README.md index b66509a9..b75d9975 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ [English](./README-en.md) | 简体中文 +[国内仓库地址](https://gitee.com/FLIPPED-AURORA/gin-vue-admin) + # 项目文档 [在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/ @@ -65,7 +67,7 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm ``` - node版本 > v8.6.0 -- golang版本 >= v1.11 +- golang版本 >= v1.14 - IDE推荐:Goland - gormv2版本初始化数据库可以利用批量创建功能,这里已经写好初始化代码,需要在main.go内打开 initialize.Data() 的注释即可 - 替换掉项目中的七牛云公钥,私钥,仓名和默认url地址,以免发生测试文件数据错乱 diff --git a/server/Makefile b/server/Makefile new file mode 100644 index 00000000..68550a1e --- /dev/null +++ b/server/Makefile @@ -0,0 +1,41 @@ +.PHONY: all build run gotool clean help + +BINARY="server" +GVA = "gva" + +all: check gva initdb run + +gva: + 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 - 格式化 Go 代码, 并编译生成二进制文件" + @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'" \ No newline at end of file diff --git a/server/api/v1/sys_user.go b/server/api/v1/sys_user.go index 0b898760..2daff2c3 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/sys_user.go @@ -22,7 +22,7 @@ import ( // @Produce application/json // @Param data body model.SysUser true "用户注册接口" // @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}" -// @Router /base/register [post] +// @Router /user/register [post] func Register(c *gin.Context) { var R request.RegisterStruct _ = c.ShouldBindJSON(&R) diff --git a/server/build.bat b/server/build.bat new file mode 100644 index 00000000..ca5c4cbe --- /dev/null +++ b/server/build.bat @@ -0,0 +1,12 @@ +@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########################### \ No newline at end of file diff --git a/server/cmd/datas/AuthorityMenu.go b/server/cmd/datas/AuthorityMenu.go new file mode 100644 index 00000000..b7892331 --- /dev/null +++ b/server/cmd/datas/AuthorityMenu.go @@ -0,0 +1,7 @@ +package datas + +import "gorm.io/gorm" + +func InitAuthorityMenu(db *gorm.DB) (err error) { + return 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 +} diff --git a/server/cmd/datas/apis.go b/server/cmd/datas/apis.go new file mode 100644 index 00000000..48c22272 --- /dev/null +++ b/server/cmd/datas/apis.go @@ -0,0 +1,86 @@ +package datas + +import ( + "gin-vue-admin/model" + "time" + + "gorm.io/gorm" +) + +var Apis = []model.SysApi{ + {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"}, + {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/register", "用户注册", "base", "POST"}, + {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"}, + {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"}, + {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"}, + {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApi", "删除Api", "api", "POST"}, + {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/updateApi", "更新Api", "api", "POST"}, + {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getAllApis", "获取所有api", "api", "POST"}, + {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"}, + {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"}, + {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"}, + {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"}, + {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"}, + {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"}, + {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"}, + {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addMenuAuthority", "增加menu和角色关联关系", "menu", "POST"}, + {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuAuthority", "获取指定角色menu", "menu", "POST"}, + {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"}, + {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"}, + {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"}, + {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"}, + {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"}, + {gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"}, + {gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"}, + {gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"}, + {gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"}, + {gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"}, + {gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"}, + {gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单", "jwt", "POST"}, + {gorm.Model{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"}, + {gorm.Model{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"}, + {gorm.Model{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"}, + {gorm.Model{ID: 34, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "创建客户", "customer", "POST"}, + {gorm.Model{ID: 35, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "更新客户", "customer", "PUT"}, + {gorm.Model{ID: 36, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "删除客户", "customer", "DELETE"}, + {gorm.Model{ID: 37, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "获取单一客户", "customer", "GET"}, + {gorm.Model{ID: 38, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customerList", "获取客户列表", "customer", "GET"}, + {gorm.Model{ID: 39, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/casbinTest/:pathParam", "RESTFUL模式测试", "casbin", "GET"}, + {gorm.Model{ID: 40, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/createTemp", "自动化代码", "autoCode", "POST"}, + {gorm.Model{ID: 41, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/updateAuthority", "更新角色信息", "authority", "PUT"}, + {gorm.Model{ID: 42, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/copyAuthority", "拷贝角色", "authority", "POST"}, + {gorm.Model{ID: 43, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/deleteUser", "删除用户", "user", "DELETE"}, + {gorm.Model{ID: 44, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/createSysDictionaryDetail", "新增字典内容", "sysDictionaryDetail", "POST"}, + {gorm.Model{ID: 45, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/deleteSysDictionaryDetail", "删除字典内容", "sysDictionaryDetail", "DELETE"}, + {gorm.Model{ID: 46, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/updateSysDictionaryDetail", "更新字典内容", "sysDictionaryDetail", "PUT"}, + {gorm.Model{ID: 47, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/findSysDictionaryDetail", "根据ID获取字典内容", "sysDictionaryDetail", "GET"}, + {gorm.Model{ID: 48, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/getSysDictionaryDetailList", "获取字典内容列表", "sysDictionaryDetail", "GET"}, + {gorm.Model{ID: 49, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/createSysDictionary", "新增字典", "sysDictionary", "POST"}, + {gorm.Model{ID: 50, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/deleteSysDictionary", "删除字典", "sysDictionary", "DELETE"}, + {gorm.Model{ID: 51, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/updateSysDictionary", "更新字典", "sysDictionary", "PUT"}, + {gorm.Model{ID: 52, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/findSysDictionary", "根据ID获取字典", "sysDictionary", "GET"}, + {gorm.Model{ID: 53, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/getSysDictionaryList", "获取字典列表", "sysDictionary", "GET"}, + {gorm.Model{ID: 54, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/createSysOperationRecord", "新增操作记录", "sysOperationRecord", "POST"}, + {gorm.Model{ID: 55, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecord", "删除操作记录", "sysOperationRecord", "DELETE"}, + {gorm.Model{ID: 56, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/findSysOperationRecord", "根据ID获取操作记录", "sysOperationRecord", "GET"}, + {gorm.Model{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"}, + {gorm.Model{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"}, + {gorm.Model{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"}, + {gorm.Model{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"}, + {gorm.Model{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"}, + {gorm.Model{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"}, + {gorm.Model{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"}, + {gorm.Model{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"}, + {gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"}, + {gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"}, + {gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"}, +} + +func InitSysApi(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/authorities.go b/server/cmd/datas/authorities.go new file mode 100644 index 00000000..5aecfe07 --- /dev/null +++ b/server/cmd/datas/authorities.go @@ -0,0 +1,23 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +var Authorities = []model.SysAuthority{ + {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"}, + {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"}, + {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"}, +} + +func InitSysAuthority(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/authority_Ids.go b/server/cmd/datas/authority_Ids.go new file mode 100644 index 00000000..2cd6d807 --- /dev/null +++ b/server/cmd/datas/authority_Ids.go @@ -0,0 +1,27 @@ +package datas + +import ( + "gorm.io/gorm" +) + +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) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/authority_menus.go b/server/cmd/datas/authority_menus.go new file mode 100644 index 00000000..133f567b --- /dev/null +++ b/server/cmd/datas/authority_menus.go @@ -0,0 +1,75 @@ +package datas + +import ( + "gorm.io/gorm" +) + +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}, + {"8881", 1}, + {"8881", 2}, + {"8881", 8}, + {"8881", 17}, + {"8881", 18}, + {"8881", 19}, + {"8881", 20}, + {"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", 13}, + {"9528", 14}, + {"9528", 15}, + {"9528", 17}, + {"9528", 18}, + {"9528", 19}, + {"9528", 20}, +} + +func InitSysAuthorityMenus(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/casbins.go b/server/cmd/datas/casbins.go new file mode 100644 index 00000000..ebce8047 --- /dev/null +++ b/server/cmd/datas/casbins.go @@ -0,0 +1,161 @@ +package datas + +import ( + gormadapter "github.com/casbin/gorm-adapter/v3" + "gorm.io/gorm" +) + +var Carbines = []gormadapter.CasbinRule{ + {PType: "p", V0: "888", V1: "/base/login", V2: "POST"}, + {PType: "p", V0: "888", V1: "/base/register", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/createApi", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/getApiList", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/getApiById", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/deleteApi", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/updateApi", V2: "POST"}, + {PType: "p", V0: "888", V1: "/api/getAllApis", V2: "POST"}, + {PType: "p", V0: "888", V1: "/authority/createAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/authority/deleteAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/authority/getAuthorityList", V2: "POST"}, + {PType: "p", V0: "888", V1: "/authority/setDataAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/authority/updateAuthority", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/authority/copyAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/getMenu", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/getMenuList", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/addBaseMenu", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/getBaseMenuTree", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/addMenuAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/getMenuAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/deleteBaseMenu", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/updateBaseMenu", V2: "POST"}, + {PType: "p", V0: "888", V1: "/menu/getBaseMenuById", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/changePassword", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/getUserList", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"}, + {PType: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"}, + {PType: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"}, + {PType: "p", V0: "888", V1: "/casbin/updateCasbin", V2: "POST"}, + {PType: "p", V0: "888", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"}, + {PType: "p", V0: "888", V1: "/casbin/casbinTest/:pathParam", V2: "GET"}, + {PType: "p", V0: "888", V1: "/jwt/jsonInBlacklist", V2: "POST"}, + {PType: "p", V0: "888", V1: "/system/getSystemConfig", V2: "POST"}, + {PType: "p", V0: "888", V1: "/system/setSystemConfig", V2: "POST"}, + {PType: "p", V0: "888", V1: "/customer/customer", V2: "POST"}, + {PType: "p", V0: "888", V1: "/customer/customer", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/customer/customer", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"}, + {PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"}, + {PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"}, + {PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"}, + {PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"}, + {PType: "p", V0: "888", V1: "/autoCode/getColume", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"}, + {PType: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysDictionaryDetail/getSysDictionaryDetailList", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysDictionary/createSysDictionary", V2: "POST"}, + {PType: "p", V0: "888", V1: "/sysDictionary/deleteSysDictionary", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/sysDictionary/updateSysDictionary", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/sysDictionary/findSysDictionary", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysDictionary/getSysDictionaryList", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/updateSysOperationRecord", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"}, + {PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"}, + {PType: "p", V0: "888", V1: "/email/emailTest", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/base/login", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/base/register", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/getApiList", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/getApiById", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/deleteApi", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/updateApi", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/api/getAllApis", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/authority/createAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/authority/deleteAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/authority/getAuthorityList", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/authority/setDataAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/getMenu", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/getMenuList", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/addBaseMenu", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/getBaseMenuTree", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/addMenuAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/getMenuAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/deleteBaseMenu", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/updateBaseMenu", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/menu/getBaseMenuById", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/user/changePassword", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/user/getUserList", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/user/setUserAuthority", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/upload", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/getFileList", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/casbin/updateCasbin", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/jwt/jsonInBlacklist", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/system/getSystemConfig", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/system/setSystemConfig", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/customer/customer", V2: "POST"}, + {PType: "p", V0: "8881", V1: "/customer/customer", V2: "PUT"}, + {PType: "p", V0: "8881", V1: "/customer/customer", V2: "DELETE"}, + {PType: "p", V0: "8881", V1: "/customer/customer", V2: "GET"}, + {PType: "p", V0: "8881", V1: "/customer/customerList", V2: "GET"}, + {PType: "p", V0: "9528", V1: "/base/login", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/base/register", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/createApi", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/getApiList", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/getApiById", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/deleteApi", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/updateApi", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/api/getAllApis", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/authority/createAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/authority/deleteAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/authority/getAuthorityList", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/authority/setDataAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/getMenu", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/getMenuList", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/addBaseMenu", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/getBaseMenuTree", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/addMenuAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/getMenuAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/deleteBaseMenu", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/updateBaseMenu", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/menu/getBaseMenuById", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/user/changePassword", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/user/getUserList", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/user/setUserAuthority", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/upload", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/getFileList", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/casbin/updateCasbin", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/jwt/jsonInBlacklist", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/system/getSystemConfig", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/system/setSystemConfig", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/customer/customer", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/customer/customer", V2: "PUT"}, + {PType: "p", V0: "9528", V1: "/customer/customer", V2: "DELETE"}, + {PType: "p", V0: "9528", V1: "/customer/customer", V2: "GET"}, + {PType: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"}, + {PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"}, +} + +func InitCasbinModel(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if !tx.Migrator().HasTable("casbin_rule") { + if err := tx.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil { + return err + } + } + if tx.Create(&Carbines).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/customers.go b/server/cmd/datas/customers.go new file mode 100644 index 00000000..e432d380 --- /dev/null +++ b/server/cmd/datas/customers.go @@ -0,0 +1,21 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +var Customers = []model.ExaCustomer{ + {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"}, +} + +func InitExaCustomer(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/dictionaries.go b/server/cmd/datas/dictionaries.go new file mode 100644 index 00000000..4230abb6 --- /dev/null +++ b/server/cmd/datas/dictionaries.go @@ -0,0 +1,54 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +type SysDictionaryToPostgresql struct { + gorm.Model + Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` + Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` + Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` + Description string `json:"description" form:"description" gorm:"column:description;comment:'描述'"` + SysDictionaryDetails []model.SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"` +} + +func InitSysDictionary(db *gorm.DB) (err error) { + var status = new(bool) + *status = true + Dictionaries := []model.SysDictionary{ + {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"}, + {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"}, + {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"}, + {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"}, + {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"}, + {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"}, + } + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} + +func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) { + status := new(bool) + *status = true + tx := db.Begin() // 开始事务 + insert := []SysDictionaryToPostgresql{ + {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"}, + {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"}, + {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"}, + {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Description: "数据库浮点型"}, + {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"}, + {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"}, + } + if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 + tx.Rollback() + } + return tx.Commit().Error +} diff --git a/server/cmd/datas/dictionary_details.go b/server/cmd/datas/dictionary_details.go new file mode 100644 index 00000000..3a7b97bb --- /dev/null +++ b/server/cmd/datas/dictionary_details.go @@ -0,0 +1,44 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +func InitSysDictionaryDetail(db *gorm.DB) (err error) { + status := new(bool) + *status = true + DictionaryDetail := []model.SysDictionaryDetail{ + {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2}, + {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2}, + {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2}, + {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2}, + {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3}, + {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3}, + {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3}, + {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3}, + {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3}, + {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4}, + {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4}, + {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4}, + {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5}, + {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5}, + {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5}, + {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5}, + {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5}, + {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5}, + {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5}, + {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5}, + {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5}, + {gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5}, + {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6}, + } + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/files.go b/server/cmd/datas/files.go new file mode 100644 index 00000000..73d14b79 --- /dev/null +++ b/server/cmd/datas/files.go @@ -0,0 +1,22 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +var Files = []model.ExaFileUploadAndDownload{ + {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"}, + {gorm.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) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/init.go b/server/cmd/datas/init.go new file mode 100644 index 00000000..33bba52e --- /dev/null +++ b/server/cmd/datas/init.go @@ -0,0 +1,108 @@ +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) { + var err error + err = InitSysApi(db) + err = InitSysUser(db) + err = InitExaCustomer(db) + err = InitCasbinModel(db) + err = InitSysAuthority(db) + err = InitSysBaseMenus(db) + err = InitAuthorityMenu(db) + err = InitSysDictionary(db) + err = InitSysAuthorityMenus(db) + err = InitSysDataAuthorityId(db) + err = InitSysDictionaryDetail(db) + err = InitExaFileUploadAndDownload(db) + if err != nil { + color.Warn.Printf("[Mysql]-->初始化数据失败,err: %v\n", err) + os.Exit(0) + } + color.Info.Println("[Mysql]-->初始化数据成功") +} + +func InitMysqlTables(db *gorm.DB) { + var err error + err = db.AutoMigrate( + model.SysApi{}, + model.SysUser{}, + model.ExaFile{}, + model.ExaCustomer{}, + model.SysBaseMenu{}, + model.SysWorkflow{}, + model.SysAuthority{}, + model.JwtBlacklist{}, + model.ExaFileChunk{}, + model.SysDictionary{}, + model.ExaSimpleUploader{}, + model.SysOperationRecord{}, + model.SysWorkflowStepInfo{}, + model.SysDictionaryDetail{}, + model.SysBaseMenuParameter{}, + model.ExaFileUploadAndDownload{}, + ) + if err != nil { + color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err) + os.Exit(0) + } + color.Info.Println("[Mysql]-->初始化数据表成功") +} + +func InitPostgresqlData(db *gorm.DB) { + var err error + err = InitSysApi(db) + err = InitSysUser(db) + err = InitExaCustomer(db) + err = InitCasbinModel(db) + err = InitSysAuthority(db) + err = InitSysBaseMenus(db) + err = InitAuthorityMenu(db) + err = InitSysAuthorityMenus(db) + err = InitSysDataAuthorityId(db) + err = InitSysDictionaryDetail(db) + err = InitExaFileUploadAndDownload(db) + err = InitSysDictionaryToPostgresql(db) + if err != nil { + color.Error.Printf("[Postgresql]-->初始化数据失败,err: %v\n", err) + os.Exit(0) + } + color.Info.Println("[Postgresql]-->初始化数据成功") +} + +func InitPostgresqlTables(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.SysWorkflow{}, + model.SysAuthority{}, + model.JwtBlacklist{}, + model.ExaFileChunk{}, + model.ExaSimpleUploader{}, + model.SysOperationRecord{}, + model.SysWorkflowStepInfo{}, + model.SysDictionaryDetail{}, + model.SysBaseMenuParameter{}, + model.ExaFileUploadAndDownload{}, + SysDictionaryToPostgresql{}, + ) + if err != nil { + color.Error.Printf("[Postgresql]-->初始化数据表失败,err: %v\n", err) + os.Exit(0) + } + color.Info.Println("[Postgresql]-->初始化数据表成功") +} diff --git a/server/cmd/datas/menus.go b/server/cmd/datas/menus.go new file mode 100644 index 00000000..8a63369a --- /dev/null +++ b/server/cmd/datas/menus.go @@ -0,0 +1,47 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + "gorm.io/gorm" +) + +var BaseMenus = []model.SysBaseMenu{ + {Model: gorm.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"}}, + {Model: gorm.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"}}, + {Model: gorm.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"}}, + {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}}, + {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}}, + {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}}, + {Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}}, + {Model: gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}}, + {Model: gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}}, + {Model: gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "table", Name: "table", Component: "view/example/table/table.vue", Sort: 1, Meta: model.Meta{Title: "表格示例", Icon: "s-order"}}, + {Model: gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "form", Name: "form", Component: "view/example/form/form.vue", Sort: 2, Meta: model.Meta{Title: "表单示例", Icon: "document"}}, + {Model: gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "rte", Name: "rte", Component: "view/example/rte/rte.vue", Sort: 3, Meta: model.Meta{Title: "富文本编辑器", Icon: "reading"}}, + {Model: gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}}, + {Model: gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "上传下载", Icon: "upload"}}, + {Model: gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}}, + {Model: gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}}, + {Model: gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}}, + {Model: gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}}, + {Model: gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}}, + {Model: gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}}, + {Model: gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "iconList", Name: "iconList", Component: "view/iconList/index.vue", Sort: 2, Meta: model.Meta{Title: "图标集合", Icon: "star-on"}}, + {Model: gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}}, + {Model: gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}}, + {Model: gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}}, + {Model: gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}}, + {Model: gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}}, + {Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}}, +} + +func InitSysBaseMenus(db *gorm.DB) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/datas/users.go b/server/cmd/datas/users.go new file mode 100644 index 00000000..5759a29f --- /dev/null +++ b/server/cmd/datas/users.go @@ -0,0 +1,23 @@ +package datas + +import ( + "time" + + "gin-vue-admin/model" + uuid "github.com/satori/go.uuid" + "gorm.io/gorm" +) + +var Users = []model.SysUser{ + {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/1571627762timg.jpg", AuthorityId: "888"}, + {Model: gorm.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) (err error) { + return db.Transaction(func(tx *gorm.DB) error { + if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务 + return err + } + return nil + }) +} diff --git a/server/cmd/gva/initdb.go b/server/cmd/gva/initdb.go new file mode 100644 index 00000000..101c0fe6 --- /dev/null +++ b/server/cmd/gva/initdb.go @@ -0,0 +1,75 @@ +/* +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/datas" + "gin-vue-admin/core" + "gin-vue-admin/initialize" + + "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) { + path, _ := cmd.Flags().GetString("path") + core.Viper(path) + db := initialize.GormMysql() + switch global.GVA_CONFIG.System.DbType { + case "mysql": + datas.InitMysqlTables(db) + datas.InitMysqlData(db) + case "postgresql": + datas.InitPostgresqlTables(db) + datas.InitPostgresqlData(db) + case "sqlite": + color.Info.Println("sqlite功能开发中") + case "sqlserver": + color.Info.Println("sqlserver功能开发中") + default: + datas.InitMysqlTables(db) + datas.InitMysqlData(db) + color.Info.Println("sqlserver功能开发中") + } + frame, _ := cmd.Flags().GetString("frame") + if frame == "gf" { + color.Info.Println("gf功能开发中") + return + } else { + return + } + }, +} + +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") +} diff --git a/server/cmd/gva/root.go b/server/cmd/gva/root.go new file mode 100644 index 00000000..b5dddd79 --- /dev/null +++ b/server/cmd/gva/root.go @@ -0,0 +1,94 @@ +/* +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()) + } +} diff --git a/server/cmd/gva/version.go b/server/cmd/gva/version.go new file mode 100644 index 00000000..4b5555da --- /dev/null +++ b/server/cmd/gva/version.go @@ -0,0 +1,36 @@ +/* +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.2") + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/server/cmd/main.go b/server/cmd/main.go new file mode 100644 index 00000000..5b27198b --- /dev/null +++ b/server/cmd/main.go @@ -0,0 +1,22 @@ +/* +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() +} diff --git a/server/config.yaml b/server/config.yaml index 0e478e1e..29cf05d8 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -42,8 +42,6 @@ system: addr: 8888 db-type: 'mysql' oss-type: 'local' - config-env: 'GVA_CONFIG' - need-init-data: false use-multipoint: false # captcha configuration @@ -63,36 +61,6 @@ mysql: max-open-conns: 10 log-mode: false -# sqlite connect configuration (sqlite需要gcc支持 windows用户需要自行安装gcc) -sqlite: - path: 'db.db' - max-idle-conns: 10 - max-open-conns: 10 - logger: true - -# Sqlserver connect configuration -sqlserver: - path: 'localhost:9930' - db-name: 'gorm' - username: 'gorm' - password: 'LoremIpsum86' - max-idle-conns: 10 - max-open-conns: 10 - logger: true - -# Postgresql connect configuration -postgresql: - host: '127.0.0.1' - port: '9920' - config: 'sslmode=disable TimeZone=Asia/Shanghai' - db-name: 'gorm' - username: 'gorm' - password: 'gorm' - max-idle-conns: 10 - max-open-conns: 10 - prefer-simple-protocol: true - logger: false - # local configuration local: path: 'uploads/file' diff --git a/server/config/config.go b/server/config/config.go index 6bbc0024..71506081 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -10,9 +10,6 @@ type Server struct { Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"` // gorm Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"` - Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"` - Sqlserver Sqlserver `mapstructure:"sqlserver" json:"sqlserver" yaml:"sqlserver"` - Postgresql Postgresql `mapstructure:"postgresql" json:"postgresql" yaml:"postgresql"` // oss Local Local `mapstructure:"local" json:"local" yaml:"local"` Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"` diff --git a/server/config/gorm.go b/server/config/gorm.go index ac6708db..9290ab10 100644 --- a/server/config/gorm.go +++ b/server/config/gorm.go @@ -10,34 +10,3 @@ type Mysql struct { MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` } - -type Sqlite struct { - Path string `mapstructure:"path" json:"path" yaml:"path"` - MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` - MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` - Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"` -} - -type Sqlserver struct { - Path string `mapstructure:"path" json:"path" yaml:"path"` - Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` - Username string `mapstructure:"username" json:"username" yaml:"username"` - Password string `mapstructure:"password" json:"password" yaml:"password"` - MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` - MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` - Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"` -} - -type Postgresql struct { - Host string `mapstructure:"host" json:"host" yaml:"host"` - Port string `mapstructure:"port" json:"port" yaml:"port"` - Config string `mapstructure:"config" json:"config" yaml:"config"` - Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` - Username string `mapstructure:"username" json:"username" yaml:"username"` - Password string `mapstructure:"password" json:"password" yaml:"password"` - MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` - MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` - PreferSimpleProtocol bool `mapstructure:"prefer-simple-protocol" json:"preferSimpleProtocol" yaml:"prefer-simple-protocol"` - Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"` -} - diff --git a/server/config/system.go b/server/config/system.go index 53f52ad0..d072379a 100644 --- a/server/config/system.go +++ b/server/config/system.go @@ -5,7 +5,5 @@ type System struct { Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` - ConfigEnv string `mapstructure:"config-env" json:"configEnv" yaml:"config-env"` - NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"` UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` } diff --git a/server/core/config.go b/server/core/config.go deleted file mode 100644 index e3ac9094..00000000 --- a/server/core/config.go +++ /dev/null @@ -1,49 +0,0 @@ -package core - -import ( - "flag" - "fmt" - "gin-vue-admin/global" - _ "gin-vue-admin/packfile" - "github.com/fsnotify/fsnotify" - "github.com/spf13/viper" - "os" -) - -var config string - -const defaultConfigFile = "config.yaml" - -func init() { - flag.StringVar(&config, "c", "", "choose config file.") - flag.Parse() - if config == "" { // 优先级: 命令行 > 环境变量 > 默认值 - if configEnv := os.Getenv(global.GVA_CONFIG.System.ConfigEnv); configEnv == "" { - config = defaultConfigFile - fmt.Printf("您正在使用config的默认值,config的路径为%v\n", defaultConfigFile) - } else { - config = configEnv - fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config) - } - } else { - fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config) - } - v := viper.New() - v.SetConfigFile(config) - err := v.ReadInConfig() - if err != nil { - panic(fmt.Errorf("Fatal error config file: %s \n", err)) - } - v.WatchConfig() - - v.OnConfigChange(func(e fsnotify.Event) { - fmt.Println("config file changed:", e.Name) - if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { - fmt.Println(err) - } - }) - if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { - fmt.Println(err) - } - global.GVA_VP = v -} diff --git a/server/core/viper.go b/server/core/viper.go new file mode 100644 index 00000000..e1d67b83 --- /dev/null +++ b/server/core/viper.go @@ -0,0 +1,54 @@ +package core + +import ( + "flag" + "fmt" + "gin-vue-admin/global" + _ "gin-vue-admin/packfile" + "gin-vue-admin/utils" + "github.com/fsnotify/fsnotify" + "github.com/spf13/viper" + "os" +) + +func Viper(path ...string) *viper.Viper { + var config string + if len(path) == 0 { + flag.StringVar(&config, "c", "", "choose config file.") + flag.Parse() + if config == "" { // 优先级: 命令行 > 环境变量 > 默认值 + if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" { + config = utils.ConfigFile + fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile) + } else { + config = configEnv + fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config) + } + } else { + fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config) + } + } else { + config = path[0] + fmt.Printf("您正在使用func Viper()传递的值,config的路径为%v\n", config) + } + + v := viper.New() + v.SetConfigFile(config) + err := v.ReadInConfig() + if err != nil { + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } + v.WatchConfig() + + v.OnConfigChange(func(e fsnotify.Event) { + fmt.Println("config file changed:", e.Name) + if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { + fmt.Println(err) + } + }) + + if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { + fmt.Println(err) + } + return v +} diff --git a/server/core/zap.go b/server/core/zap.go index d3597433..9519cdd2 100644 --- a/server/core/zap.go +++ b/server/core/zap.go @@ -4,20 +4,15 @@ import ( "fmt" "gin-vue-admin/global" "gin-vue-admin/utils" - zaprotatelogs "github.com/lestrrat-go/file-rotatelogs" "go.uber.org/zap" "go.uber.org/zap/zapcore" "os" "time" ) -var ( - err error - level zapcore.Level - writer zapcore.WriteSyncer -) +var level zapcore.Level -func init() { +func Zap() (logger *zap.Logger) { if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹 fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director) _ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm) @@ -42,34 +37,15 @@ func init() { level = zap.InfoLevel } - writer, err = getWriteSyncer() // 使用file-rotatelogs进行日志分割 - if err != nil { - fmt.Printf("Get Write Syncer Failed err:%v", err.Error()) - return - } - if level == zap.DebugLevel || level == zap.ErrorLevel { - global.GVA_LOG = zap.New(getEncoderCore(), zap.AddStacktrace(level)) + logger = zap.New(getEncoderCore(), zap.AddStacktrace(level)) } else { - global.GVA_LOG = zap.New(getEncoderCore()) + logger = zap.New(getEncoderCore()) } if global.GVA_CONFIG.Zap.ShowLine { - global.GVA_LOG.WithOptions(zap.AddCaller()) + logger.WithOptions(zap.AddCaller()) } -} - -// getWriteSyncer zap logger中加入file-rotatelogs -func getWriteSyncer() (zapcore.WriteSyncer, error) { - fileWriter, err := zaprotatelogs.New( - global.GVA_CONFIG.Zap.Director+string(os.PathSeparator)+"%Y-%m-%d.log", - zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName), - zaprotatelogs.WithMaxAge(7*24*time.Hour), - zaprotatelogs.WithRotationTime(24*time.Hour), - ) - if global.GVA_CONFIG.Zap.LogInConsole { - return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err - } - return zapcore.AddSync(fileWriter), err + return logger } // getEncoderConfig 获取zapcore.EncoderConfig @@ -87,7 +63,7 @@ func getEncoderConfig() (config zapcore.EncoderConfig) { EncodeDuration: zapcore.SecondsDurationEncoder, EncodeCaller: zapcore.FullCallerEncoder, } - switch { + switch { case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认) config.EncodeLevel = zapcore.LowercaseLevelEncoder case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色 @@ -96,6 +72,8 @@ func getEncoderConfig() (config zapcore.EncoderConfig) { config.EncodeLevel = zapcore.CapitalLevelEncoder case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色 config.EncodeLevel = zapcore.CapitalColorLevelEncoder + default: + config.EncodeLevel = zapcore.LowercaseLevelEncoder } return config } @@ -110,6 +88,11 @@ func getEncoder() zapcore.Encoder { // getEncoderCore 获取Encoder的zapcore.Core func getEncoderCore() (core zapcore.Core) { + writer, err := utils.GetWriteSyncer() // 使用file-rotatelogs进行日志分割 + if err != nil { + fmt.Printf("Get Write Syncer Failed err:%v", err.Error()) + return + } return zapcore.NewCore(getEncoder(), writer, level) } diff --git a/server/docs/docs.go b/server/docs/docs.go index 7bc23b00..a4a318a0 100644 --- a/server/docs/docs.go +++ b/server/docs/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-08-31 21:50:05.0136259 +0800 CST m=+0.193314401 +// 2020-10-18 12:17:37.2292991 +0800 CST m=+0.263609801 package docs @@ -593,36 +593,6 @@ var doc = `{ } } }, - "/base/register": { - "post": { - "produces": [ - "application/json" - ], - "tags": [ - "Base" - ], - "summary": "用户注册账号", - "parameters": [ - { - "description": "用户注册接口", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/model.SysUser" - } - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, "/casbin/UpdateCasbin": { "post": { "security": [ @@ -883,6 +853,30 @@ var doc = `{ } } }, + "/email/emailTest": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "system" + ], + "summary": "发送测试邮件", + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"返回成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/fileUploadAndDownload/breakpointContinue": { "post": { "security": [ @@ -2161,6 +2155,30 @@ var doc = `{ } } }, + "/system/getServerInfo": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "system" + ], + "summary": "获取服务器信息", + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/system/getSystemConfig": { "post": { "security": [ @@ -2331,6 +2349,36 @@ var doc = `{ } } }, + "/user/register": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Base" + ], + "summary": "用户注册账号", + "parameters": [ + { + "description": "用户注册接口", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.SysUser" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/user/setUserAuthority": { "post": { "security": [ @@ -2369,6 +2417,44 @@ var doc = `{ } } }, + "/user/setUserInfo": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SysUser" + ], + "summary": "删除用户", + "parameters": [ + { + "description": "删除用户", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.SysUser" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"修改成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/workflow/createWorkFlow": { "post": { "produces": [ @@ -2423,6 +2509,32 @@ var doc = `{ } } }, + "config.Email": { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "host": { + "type": "string" + }, + "isSSL": { + "type": "boolean" + }, + "nickname": { + "type": "string" + }, + "port": { + "type": "integer" + }, + "secret": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, "config.JWT": { "type": "object", "properties": { @@ -2431,33 +2543,10 @@ var doc = `{ } } }, - "config.LocalUpload": { + "config.Local": { "type": "object", "properties": { - "avatarPath": { - "type": "string" - }, - "filePath": { - "type": "string" - }, - "local": { - "type": "boolean" - } - } - }, - "config.Log": { - "type": "object", - "properties": { - "file": { - "type": "string" - }, - "logFile": { - "type": "boolean" - }, - "prefix": { - "type": "string" - }, - "stdout": { + "path": { "type": "string" } } @@ -2491,6 +2580,41 @@ var doc = `{ } } }, + "config.Postgresql": { + "type": "object", + "properties": { + "config": { + "type": "string" + }, + "dbname": { + "type": "string" + }, + "host": { + "type": "string" + }, + "logger": { + "type": "boolean" + }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, + "password": { + "type": "string" + }, + "port": { + "type": "string" + }, + "preferSimpleProtocol": { + "type": "boolean" + }, + "username": { + "type": "string" + } + } + }, "config.Qiniu": { "type": "object", "properties": { @@ -2505,6 +2629,15 @@ var doc = `{ }, "secretKey": { "type": "string" + }, + "useCdnDomains": { + "type": "boolean" + }, + "useHttps": { + "type": "boolean" + }, + "zone": { + "type": "string" } } }, @@ -2533,22 +2666,28 @@ var doc = `{ "type": "object", "$ref": "#/definitions/config.Casbin" }, + "email": { + "type": "object", + "$ref": "#/definitions/config.Email" + }, "jwt": { "type": "object", "$ref": "#/definitions/config.JWT" }, - "localUpload": { + "local": { + "description": "oss", "type": "object", - "$ref": "#/definitions/config.LocalUpload" - }, - "log": { - "type": "object", - "$ref": "#/definitions/config.Log" + "$ref": "#/definitions/config.Local" }, "mysql": { + "description": "gorm", "type": "object", "$ref": "#/definitions/config.Mysql" }, + "postgresql": { + "type": "object", + "$ref": "#/definitions/config.Postgresql" + }, "qiniu": { "type": "object", "$ref": "#/definitions/config.Qiniu" @@ -2561,21 +2700,52 @@ var doc = `{ "type": "object", "$ref": "#/definitions/config.Sqlite" }, + "sqlserver": { + "type": "object", + "$ref": "#/definitions/config.Sqlserver" + }, "system": { "type": "object", "$ref": "#/definitions/config.System" + }, + "zap": { + "type": "object", + "$ref": "#/definitions/config.Zap" } } }, "config.Sqlite": { "type": "object", "properties": { - "config": { + "logger": { + "type": "boolean" + }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, + "path": { + "type": "string" + } + } + }, + "config.Sqlserver": { + "type": "object", + "properties": { + "dbname": { "type": "string" }, - "logMode": { + "logger": { "type": "boolean" }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, "password": { "type": "string" }, @@ -2599,11 +2769,49 @@ var doc = `{ "env": { "type": "string" }, + "needInitData": { + "type": "boolean" + }, + "ossType": { + "type": "string" + }, "useMultipoint": { "type": "boolean" } } }, + "config.Zap": { + "type": "object", + "properties": { + "director": { + "type": "string" + }, + "encodeLevel": { + "type": "string" + }, + "format": { + "type": "string" + }, + "level": { + "type": "string" + }, + "linkName": { + "type": "string" + }, + "logInConsole": { + "type": "boolean" + }, + "prefix": { + "type": "string" + }, + "showLine": { + "type": "boolean" + }, + "stacktraceKey": { + "type": "string" + } + } + }, "model.AutoCodeStruct": { "type": "object", "properties": { @@ -2971,7 +3179,7 @@ var doc = `{ "description": "是否是完结流节点", "type": "boolean" }, - "isStrat": { + "isStart": { "description": "是否是开始流节点", "type": "boolean" }, diff --git a/server/docs/swagger.json b/server/docs/swagger.json index 51eac007..7d17841a 100644 --- a/server/docs/swagger.json +++ b/server/docs/swagger.json @@ -576,36 +576,6 @@ } } }, - "/base/register": { - "post": { - "produces": [ - "application/json" - ], - "tags": [ - "Base" - ], - "summary": "用户注册账号", - "parameters": [ - { - "description": "用户注册接口", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/model.SysUser" - } - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, "/casbin/UpdateCasbin": { "post": { "security": [ @@ -866,6 +836,30 @@ } } }, + "/email/emailTest": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "system" + ], + "summary": "发送测试邮件", + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"返回成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/fileUploadAndDownload/breakpointContinue": { "post": { "security": [ @@ -2144,6 +2138,30 @@ } } }, + "/system/getServerInfo": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "system" + ], + "summary": "获取服务器信息", + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/system/getSystemConfig": { "post": { "security": [ @@ -2314,6 +2332,36 @@ } } }, + "/user/register": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Base" + ], + "summary": "用户注册账号", + "parameters": [ + { + "description": "用户注册接口", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.SysUser" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/user/setUserAuthority": { "post": { "security": [ @@ -2352,6 +2400,44 @@ } } }, + "/user/setUserInfo": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SysUser" + ], + "summary": "删除用户", + "parameters": [ + { + "description": "删除用户", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.SysUser" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"修改成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/workflow/createWorkFlow": { "post": { "produces": [ @@ -2406,6 +2492,32 @@ } } }, + "config.Email": { + "type": "object", + "properties": { + "from": { + "type": "string" + }, + "host": { + "type": "string" + }, + "isSSL": { + "type": "boolean" + }, + "nickname": { + "type": "string" + }, + "port": { + "type": "integer" + }, + "secret": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, "config.JWT": { "type": "object", "properties": { @@ -2414,33 +2526,10 @@ } } }, - "config.LocalUpload": { + "config.Local": { "type": "object", "properties": { - "avatarPath": { - "type": "string" - }, - "filePath": { - "type": "string" - }, - "local": { - "type": "boolean" - } - } - }, - "config.Log": { - "type": "object", - "properties": { - "file": { - "type": "string" - }, - "logFile": { - "type": "boolean" - }, - "prefix": { - "type": "string" - }, - "stdout": { + "path": { "type": "string" } } @@ -2474,6 +2563,41 @@ } } }, + "config.Postgresql": { + "type": "object", + "properties": { + "config": { + "type": "string" + }, + "dbname": { + "type": "string" + }, + "host": { + "type": "string" + }, + "logger": { + "type": "boolean" + }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, + "password": { + "type": "string" + }, + "port": { + "type": "string" + }, + "preferSimpleProtocol": { + "type": "boolean" + }, + "username": { + "type": "string" + } + } + }, "config.Qiniu": { "type": "object", "properties": { @@ -2488,6 +2612,15 @@ }, "secretKey": { "type": "string" + }, + "useCdnDomains": { + "type": "boolean" + }, + "useHttps": { + "type": "boolean" + }, + "zone": { + "type": "string" } } }, @@ -2516,22 +2649,28 @@ "type": "object", "$ref": "#/definitions/config.Casbin" }, + "email": { + "type": "object", + "$ref": "#/definitions/config.Email" + }, "jwt": { "type": "object", "$ref": "#/definitions/config.JWT" }, - "localUpload": { + "local": { + "description": "oss", "type": "object", - "$ref": "#/definitions/config.LocalUpload" - }, - "log": { - "type": "object", - "$ref": "#/definitions/config.Log" + "$ref": "#/definitions/config.Local" }, "mysql": { + "description": "gorm", "type": "object", "$ref": "#/definitions/config.Mysql" }, + "postgresql": { + "type": "object", + "$ref": "#/definitions/config.Postgresql" + }, "qiniu": { "type": "object", "$ref": "#/definitions/config.Qiniu" @@ -2544,21 +2683,52 @@ "type": "object", "$ref": "#/definitions/config.Sqlite" }, + "sqlserver": { + "type": "object", + "$ref": "#/definitions/config.Sqlserver" + }, "system": { "type": "object", "$ref": "#/definitions/config.System" + }, + "zap": { + "type": "object", + "$ref": "#/definitions/config.Zap" } } }, "config.Sqlite": { "type": "object", "properties": { - "config": { + "logger": { + "type": "boolean" + }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, + "path": { + "type": "string" + } + } + }, + "config.Sqlserver": { + "type": "object", + "properties": { + "dbname": { "type": "string" }, - "logMode": { + "logger": { "type": "boolean" }, + "maxIdleConns": { + "type": "integer" + }, + "maxOpenConns": { + "type": "integer" + }, "password": { "type": "string" }, @@ -2582,11 +2752,49 @@ "env": { "type": "string" }, + "needInitData": { + "type": "boolean" + }, + "ossType": { + "type": "string" + }, "useMultipoint": { "type": "boolean" } } }, + "config.Zap": { + "type": "object", + "properties": { + "director": { + "type": "string" + }, + "encodeLevel": { + "type": "string" + }, + "format": { + "type": "string" + }, + "level": { + "type": "string" + }, + "linkName": { + "type": "string" + }, + "logInConsole": { + "type": "boolean" + }, + "prefix": { + "type": "string" + }, + "showLine": { + "type": "boolean" + }, + "stacktraceKey": { + "type": "string" + } + } + }, "model.AutoCodeStruct": { "type": "object", "properties": { @@ -2954,7 +3162,7 @@ "description": "是否是完结流节点", "type": "boolean" }, - "isStrat": { + "isStart": { "description": "是否是开始流节点", "type": "boolean" }, diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml index 7ebc26ce..8c5f0675 100644 --- a/server/docs/swagger.yaml +++ b/server/docs/swagger.yaml @@ -14,29 +14,31 @@ definitions: modelPath: type: string type: object + config.Email: + properties: + from: + type: string + host: + type: string + isSSL: + type: boolean + nickname: + type: string + port: + type: integer + secret: + type: string + to: + type: string + type: object config.JWT: properties: signingKey: type: string type: object - config.LocalUpload: + config.Local: properties: - avatarPath: - type: string - filePath: - type: string - local: - type: boolean - type: object - config.Log: - properties: - file: - type: string - logFile: - type: boolean - prefix: - type: string - stdout: + path: type: string type: object config.Mysql: @@ -58,6 +60,29 @@ definitions: username: type: string type: object + config.Postgresql: + properties: + config: + type: string + dbname: + type: string + host: + type: string + logger: + type: boolean + maxIdleConns: + type: integer + maxOpenConns: + type: integer + password: + type: string + port: + type: string + preferSimpleProtocol: + type: boolean + username: + type: string + type: object config.Qiniu: properties: accessKey: @@ -68,6 +93,12 @@ definitions: type: string secretKey: type: string + useCdnDomains: + type: boolean + useHttps: + type: boolean + zone: + type: string type: object config.Redis: properties: @@ -86,17 +117,22 @@ definitions: casbin: $ref: '#/definitions/config.Casbin' type: object + email: + $ref: '#/definitions/config.Email' + type: object jwt: $ref: '#/definitions/config.JWT' type: object - localUpload: - $ref: '#/definitions/config.LocalUpload' - type: object - log: - $ref: '#/definitions/config.Log' + local: + $ref: '#/definitions/config.Local' + description: oss type: object mysql: $ref: '#/definitions/config.Mysql' + description: gorm + type: object + postgresql: + $ref: '#/definitions/config.Postgresql' type: object qiniu: $ref: '#/definitions/config.Qiniu' @@ -107,16 +143,37 @@ definitions: sqlite: $ref: '#/definitions/config.Sqlite' type: object + sqlserver: + $ref: '#/definitions/config.Sqlserver' + type: object system: $ref: '#/definitions/config.System' type: object + zap: + $ref: '#/definitions/config.Zap' + type: object type: object config.Sqlite: properties: - config: - type: string - logMode: + logger: type: boolean + maxIdleConns: + type: integer + maxOpenConns: + type: integer + path: + type: string + type: object + config.Sqlserver: + properties: + dbname: + type: string + logger: + type: boolean + maxIdleConns: + type: integer + maxOpenConns: + type: integer password: type: string path: @@ -132,9 +189,34 @@ definitions: type: string env: type: string + needInitData: + type: boolean + ossType: + type: string useMultipoint: type: boolean type: object + config.Zap: + properties: + director: + type: string + encodeLevel: + type: string + format: + type: string + level: + type: string + linkName: + type: string + logInConsole: + type: boolean + prefix: + type: string + showLine: + type: boolean + stacktraceKey: + type: string + type: object model.AutoCodeStruct: properties: abbreviation: @@ -378,7 +460,7 @@ definitions: isEnd: description: 是否是完结流节点 type: boolean - isStrat: + isStart: description: 是否是开始流节点 type: boolean stepAuthorityID: @@ -919,25 +1001,6 @@ paths: summary: 用户登录 tags: - Base - /base/register: - post: - parameters: - - description: 用户注册接口 - in: body - name: data - required: true - schema: - $ref: '#/definitions/model.SysUser' - produces: - - application/json - responses: - "200": - description: '{"success":true,"data":{},"msg":"注册成功"}' - schema: - type: string - summary: 用户注册账号 - tags: - - Base /casbin/UpdateCasbin: post: consumes: @@ -1096,6 +1159,20 @@ paths: summary: 获取权限客户列表 tags: - SysApi + /email/emailTest: + post: + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"返回成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 发送测试邮件 + tags: + - system /fileUploadAndDownload/breakpointContinue: post: consumes: @@ -1870,6 +1947,20 @@ paths: summary: 设置配置文件内容 tags: - system + /system/getServerInfo: + post: + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"获取成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 获取服务器信息 + tags: + - system /system/getSystemConfig: post: produces: @@ -1972,6 +2063,25 @@ paths: summary: 分页获取用户列表 tags: - SysUser + /user/register: + post: + parameters: + - description: 用户注册接口 + in: body + name: data + required: true + schema: + $ref: '#/definitions/model.SysUser' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"注册成功"}' + schema: + type: string + summary: 用户注册账号 + tags: + - Base /user/setUserAuthority: post: consumes: @@ -1995,6 +2105,29 @@ paths: summary: 设置用户权限 tags: - SysUser + /user/setUserInfo: + put: + consumes: + - application/json + parameters: + - description: 删除用户 + in: body + name: data + required: true + schema: + $ref: '#/definitions/model.SysUser' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"修改成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 删除用户 + tags: + - SysUser /workflow/createWorkFlow: post: parameters: diff --git a/server/go.mod b/server/go.mod index f289d76d..a9ecdc2f 100644 --- a/server/go.mod +++ b/server/go.mod @@ -5,6 +5,7 @@ go 1.12 require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 + github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect github.com/casbin/casbin v1.9.1 github.com/casbin/casbin/v2 v2.11.0 github.com/casbin/gorm-adapter/v3 v3.0.2 @@ -20,12 +21,14 @@ require ( github.com/go-redis/redis v6.15.7+incompatible github.com/go-sql-driver/mysql v1.5.0 github.com/golang/protobuf v1.4.2 // indirect + github.com/gookit/color v1.3.1 github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 github.com/json-iterator/go v1.1.10 // indirect github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible github.com/lestrrat-go/strftime v1.0.3 // indirect github.com/mailru/easyjson v0.7.1 // indirect + github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.2.2 // indirect github.com/mojocn/base64Captcha v1.3.1 github.com/onsi/ginkgo v1.7.0 // indirect @@ -37,12 +40,14 @@ require ( github.com/shirou/gopsutil v2.20.8+incompatible github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/cobra v1.1.1 github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/viper v1.6.2 + github.com/spf13/viper v1.7.0 github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/swag v1.6.7 github.com/tebeka/strftime v0.1.3 // indirect github.com/unrolled/secure v1.0.7 + github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect go.uber.org/zap v1.10.0 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect diff --git a/server/gva/init_data/init_data.go b/server/gva/init_data/init_data.go index d044dbab..e69de29b 100644 --- a/server/gva/init_data/init_data.go +++ b/server/gva/init_data/init_data.go @@ -1,501 +0,0 @@ -package init_data - -import ( - "gin-vue-admin/global" - "gin-vue-admin/model" - gormadapter "github.com/casbin/gorm-adapter/v3" - "github.com/satori/go.uuid" - "go.uber.org/zap" - "gorm.io/gorm" - "time" -) - -type SysAuthorityMenus struct { - SysAuthorityAuthorityId string - SysBaseMenuId uint -} - -type SysDataAuthorityId struct { - SysAuthorityAuthorityId string - DataAuthorityIdAuthorityId string -} - -func InitSysApi() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysApi{ - {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"}, - {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/register", "用户注册", "base", "POST"}, - {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"}, - {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"}, - {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"}, - {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApi", "删除Api", "api", "POST"}, - {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/updateApi", "更新Api", "api", "POST"}, - {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getAllApis", "获取所有api", "api", "POST"}, - {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"}, - {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"}, - {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"}, - {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"}, - {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"}, - {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"}, - {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"}, - {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addMenuAuthority", "增加menu和角色关联关系", "menu", "POST"}, - {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuAuthority", "获取指定角色menu", "menu", "POST"}, - {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"}, - {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"}, - {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"}, - {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"}, - {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"}, - {gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"}, - {gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"}, - {gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"}, - {gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"}, - {gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"}, - {gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"}, - {gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单", "jwt", "POST"}, - {gorm.Model{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"}, - {gorm.Model{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"}, - {gorm.Model{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"}, - {gorm.Model{ID: 34, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "创建客户", "customer", "POST"}, - {gorm.Model{ID: 35, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "更新客户", "customer", "PUT"}, - {gorm.Model{ID: 36, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "删除客户", "customer", "DELETE"}, - {gorm.Model{ID: 37, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "获取单一客户", "customer", "GET"}, - {gorm.Model{ID: 38, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customerList", "获取客户列表", "customer", "GET"}, - {gorm.Model{ID: 39, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/casbinTest/:pathParam", "RESTFUL模式测试", "casbin", "GET"}, - {gorm.Model{ID: 40, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/createTemp", "自动化代码", "autoCode", "POST"}, - {gorm.Model{ID: 41, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/updateAuthority", "更新角色信息", "authority", "PUT"}, - {gorm.Model{ID: 42, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/copyAuthority", "拷贝角色", "authority", "POST"}, - {gorm.Model{ID: 43, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/deleteUser", "删除用户", "user", "DELETE"}, - {gorm.Model{ID: 44, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/createSysDictionaryDetail", "新增字典内容", "sysDictionaryDetail", "POST"}, - {gorm.Model{ID: 45, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/deleteSysDictionaryDetail", "删除字典内容", "sysDictionaryDetail", "DELETE"}, - {gorm.Model{ID: 46, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/updateSysDictionaryDetail", "更新字典内容", "sysDictionaryDetail", "PUT"}, - {gorm.Model{ID: 47, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/findSysDictionaryDetail", "根据ID获取字典内容", "sysDictionaryDetail", "GET"}, - {gorm.Model{ID: 48, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/getSysDictionaryDetailList", "获取字典内容列表", "sysDictionaryDetail", "GET"}, - {gorm.Model{ID: 49, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/createSysDictionary", "新增字典", "sysDictionary", "POST"}, - {gorm.Model{ID: 50, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/deleteSysDictionary", "删除字典", "sysDictionary", "DELETE"}, - {gorm.Model{ID: 51, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/updateSysDictionary", "更新字典", "sysDictionary", "PUT"}, - {gorm.Model{ID: 52, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/findSysDictionary", "根据ID获取字典", "sysDictionary", "GET"}, - {gorm.Model{ID: 53, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/getSysDictionaryList", "获取字典列表", "sysDictionary", "GET"}, - {gorm.Model{ID: 54, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/createSysOperationRecord", "新增操作记录", "sysOperationRecord", "POST"}, - {gorm.Model{ID: 55, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecord", "删除操作记录", "sysOperationRecord", "DELETE"}, - {gorm.Model{ID: 56, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/findSysOperationRecord", "根据ID获取操作记录", "sysOperationRecord", "GET"}, - {gorm.Model{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"}, - {gorm.Model{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"}, - {gorm.Model{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"}, - {gorm.Model{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"}, - {gorm.Model{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"}, - {gorm.Model{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"}, - {gorm.Model{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"}, - {gorm.Model{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"}, - {gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"}, - {gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"}, - {gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysUser() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysUser{ - {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/1571627762timg.jpg", AuthorityId: "888"}, - {Model: gorm.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"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitExaCustomer() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.ExaCustomer{ - {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitCasbinModel() (err error) { - if !global.GVA_DB.Migrator().HasTable("casbin_rule") { - if err := global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil { - return err - } - } - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.CasbinModel{ - {"p", "888", "/base/login", "POST"}, - {"p", "888", "/base/register", "POST"}, - {"p", "888", "/api/createApi", "POST"}, - {"p", "888", "/api/getApiList", "POST"}, - {"p", "888", "/api/getApiById", "POST"}, - {"p", "888", "/api/deleteApi", "POST"}, - {"p", "888", "/api/updateApi", "POST"}, - {"p", "888", "/api/getAllApis", "POST"}, - {"p", "888", "/authority/createAuthority", "POST"}, - {"p", "888", "/authority/deleteAuthority", "POST"}, - {"p", "888", "/authority/getAuthorityList", "POST"}, - {"p", "888", "/authority/setDataAuthority", "POST"}, - {"p", "888", "/authority/updateAuthority", "PUT"}, - {"p", "888", "/authority/copyAuthority", "POST"}, - {"p", "888", "/menu/getMenu", "POST"}, - {"p", "888", "/menu/getMenuList", "POST"}, - {"p", "888", "/menu/addBaseMenu", "POST"}, - {"p", "888", "/menu/getBaseMenuTree", "POST"}, - {"p", "888", "/menu/addMenuAuthority", "POST"}, - {"p", "888", "/menu/getMenuAuthority", "POST"}, - {"p", "888", "/menu/deleteBaseMenu", "POST"}, - {"p", "888", "/menu/updateBaseMenu", "POST"}, - {"p", "888", "/menu/getBaseMenuById", "POST"}, - {"p", "888", "/user/changePassword", "POST"}, - {"p", "888", "/user/getUserList", "POST"}, - {"p", "888", "/user/setUserAuthority", "POST"}, - {"p", "888", "/user/deleteUser", "DELETE"}, - {"p", "888", "/fileUploadAndDownload/upload", "POST"}, - {"p", "888", "/fileUploadAndDownload/getFileList", "POST"}, - {"p", "888", "/fileUploadAndDownload/deleteFile", "POST"}, - {"p", "888", "/casbin/updateCasbin", "POST"}, - {"p", "888", "/casbin/getPolicyPathByAuthorityId", "POST"}, - {"p", "888", "/casbin/casbinTest/:pathParam", "GET"}, - {"p", "888", "/jwt/jsonInBlacklist", "POST"}, - {"p", "888", "/system/getSystemConfig", "POST"}, - {"p", "888", "/system/setSystemConfig", "POST"}, - {"p", "888", "/system/getServerInfo", "POST"}, - {"p", "888", "/customer/customer", "POST"}, - {"p", "888", "/customer/customer", "PUT"}, - {"p", "888", "/customer/customer", "DELETE"}, - {"p", "888", "/customer/customer", "GET"}, - {"p", "888", "/customer/customerList", "GET"}, - {"p", "888", "/autoCode/createTemp", "POST"}, - {"p", "888", "/autoCode/getTables", "GET"}, - {"p", "888", "/autoCode/getDB", "GET"}, - {"p", "888", "/autoCode/getColume", "GET"}, - {"p", "888", "/sysDictionaryDetail/createSysDictionaryDetail", "POST"}, - {"p", "888", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE"}, - {"p", "888", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT"}, - {"p", "888", "/sysDictionaryDetail/findSysDictionaryDetail", "GET"}, - {"p", "888", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET"}, - {"p", "888", "/sysDictionary/createSysDictionary", "POST"}, - {"p", "888", "/sysDictionary/deleteSysDictionary", "DELETE"}, - {"p", "888", "/sysDictionary/updateSysDictionary", "PUT"}, - {"p", "888", "/sysDictionary/findSysDictionary", "GET"}, - {"p", "888", "/sysDictionary/getSysDictionaryList", "GET"}, - {"p", "888", "/sysOperationRecord/createSysOperationRecord", "POST"}, - {"p", "888", "/sysOperationRecord/deleteSysOperationRecord", "DELETE"}, - {"p", "888", "/sysOperationRecord/updateSysOperationRecord", "PUT"}, - {"p", "888", "/sysOperationRecord/findSysOperationRecord", "GET"}, - {"p", "888", "/sysOperationRecord/getSysOperationRecordList", "GET"}, - {"p", "888", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE"}, - {"p", "888", "/user/setUserInfo", "PUT"}, - {"p", "888", "/email/emailTest", "POST"}, - {"p", "8881", "/base/login", "POST"}, - {"p", "8881", "/base/register", "POST"}, - {"p", "8881", "/api/createApi", "POST"}, - {"p", "8881", "/api/getApiList", "POST"}, - {"p", "8881", "/api/getApiById", "POST"}, - {"p", "8881", "/api/deleteApi", "POST"}, - {"p", "8881", "/api/updateApi", "POST"}, - {"p", "8881", "/api/getAllApis", "POST"}, - {"p", "8881", "/authority/createAuthority", "POST"}, - {"p", "8881", "/authority/deleteAuthority", "POST"}, - {"p", "8881", "/authority/getAuthorityList", "POST"}, - {"p", "8881", "/authority/setDataAuthority", "POST"}, - {"p", "8881", "/menu/getMenu", "POST"}, - {"p", "8881", "/menu/getMenuList", "POST"}, - {"p", "8881", "/menu/addBaseMenu", "POST"}, - {"p", "8881", "/menu/getBaseMenuTree", "POST"}, - {"p", "8881", "/menu/addMenuAuthority", "POST"}, - {"p", "8881", "/menu/getMenuAuthority", "POST"}, - {"p", "8881", "/menu/deleteBaseMenu", "POST"}, - {"p", "8881", "/menu/updateBaseMenu", "POST"}, - {"p", "8881", "/menu/getBaseMenuById", "POST"}, - {"p", "8881", "/user/changePassword", "POST"}, - {"p", "8881", "/user/getUserList", "POST"}, - {"p", "8881", "/user/setUserAuthority", "POST"}, - {"p", "8881", "/fileUploadAndDownload/upload", "POST"}, - {"p", "8881", "/fileUploadAndDownload/getFileList", "POST"}, - {"p", "8881", "/fileUploadAndDownload/deleteFile", "POST"}, - {"p", "8881", "/casbin/updateCasbin", "POST"}, - {"p", "8881", "/casbin/getPolicyPathByAuthorityId", "POST"}, - {"p", "8881", "/jwt/jsonInBlacklist", "POST"}, - {"p", "8881", "/system/getSystemConfig", "POST"}, - {"p", "8881", "/system/setSystemConfig", "POST"}, - {"p", "8881", "/customer/customer", "POST"}, - {"p", "8881", "/customer/customer", "PUT"}, - {"p", "8881", "/customer/customer", "DELETE"}, - {"p", "8881", "/customer/customer", "GET"}, - {"p", "8881", "/customer/customerList", "GET"}, - {"p", "9528", "/base/login", "POST"}, - {"p", "9528", "/base/register", "POST"}, - {"p", "9528", "/api/createApi", "POST"}, - {"p", "9528", "/api/getApiList", "POST"}, - {"p", "9528", "/api/getApiById", "POST"}, - {"p", "9528", "/api/deleteApi", "POST"}, - {"p", "9528", "/api/updateApi", "POST"}, - {"p", "9528", "/api/getAllApis", "POST"}, - {"p", "9528", "/authority/createAuthority", "POST"}, - {"p", "9528", "/authority/deleteAuthority", "POST"}, - {"p", "9528", "/authority/getAuthorityList", "POST"}, - {"p", "9528", "/authority/setDataAuthority", "POST"}, - {"p", "9528", "/menu/getMenu", "POST"}, - {"p", "9528", "/menu/getMenuList", "POST"}, - {"p", "9528", "/menu/addBaseMenu", "POST"}, - {"p", "9528", "/menu/getBaseMenuTree", "POST"}, - {"p", "9528", "/menu/addMenuAuthority", "POST"}, - {"p", "9528", "/menu/getMenuAuthority", "POST"}, - {"p", "9528", "/menu/deleteBaseMenu", "POST"}, - {"p", "9528", "/menu/updateBaseMenu", "POST"}, - {"p", "9528", "/menu/getBaseMenuById", "POST"}, - {"p", "9528", "/user/changePassword", "POST"}, - {"p", "9528", "/user/getUserList", "POST"}, - {"p", "9528", "/user/setUserAuthority", "POST"}, - {"p", "9528", "/fileUploadAndDownload/upload", "POST"}, - {"p", "9528", "/fileUploadAndDownload/getFileList", "POST"}, - {"p", "9528", "/fileUploadAndDownload/deleteFile", "POST"}, - {"p", "9528", "/casbin/updateCasbin", "POST"}, - {"p", "9528", "/casbin/getPolicyPathByAuthorityId", "POST"}, - {"p", "9528", "/jwt/jsonInBlacklist", "POST"}, - {"p", "9528", "/system/getSystemConfig", "POST"}, - {"p", "9528", "/system/setSystemConfig", "POST"}, - {"p", "9528", "/customer/customer", "POST"}, - {"p", "9528", "/customer/customer", "PUT"}, - {"p", "9528", "/customer/customer", "DELETE"}, - {"p", "9528", "/customer/customer", "GET"}, - {"p", "9528", "/customer/customerList", "GET"}, - {"p", "9528", "/autoCode/createTemp", "POST"}, - } - if tx.Table("casbin_rule").Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysAuthority() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysAuthority{ - {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"}, - {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"}, - {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysBaseMenus() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysBaseMenu{ - {Model: gorm.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"}}, - {Model: gorm.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"}}, - {Model: gorm.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"}}, - {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}}, - {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}}, - {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}}, - {Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}}, - {Model: gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}}, - {Model: gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}}, - {Model: gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "table", Name: "table", Component: "view/example/table/table.vue", Sort: 1, Meta: model.Meta{Title: "表格示例", Icon: "s-order"}}, - {Model: gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "form", Name: "form", Component: "view/example/form/form.vue", Sort: 2, Meta: model.Meta{Title: "表单示例", Icon: "document"}}, - {Model: gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "rte", Name: "rte", Component: "view/example/rte/rte.vue", Sort: 3, Meta: model.Meta{Title: "富文本编辑器", Icon: "reading"}}, - {Model: gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}}, - {Model: gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "上传下载", Icon: "upload"}}, - {Model: gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}}, - {Model: gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}}, - {Model: gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}}, - {Model: gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}}, - {Model: gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}}, - {Model: gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}}, - {Model: gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "iconList", Name: "iconList", Component: "view/iconList/index.vue", Sort: 2, Meta: model.Meta{Title: "图标集合", Icon: "star-on"}}, - {Model: gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}}, - {Model: gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}}, - {Model: gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}}, - {Model: gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}}, - {Model: gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}}, - {Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}}, - {Model: gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "workflow", Name: "workflow", Hidden: false, Component: "view/workflow/index.vue", Sort: 6, Meta: model.Meta{Title: "工作流管理", Icon: "s-flag"}}, - {Model: gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "28", Path: "workflowCreate", Name: "workflowCreate", Hidden: false, Component: "view/workflow/workflowCreate/workflowCreate.vue", Sort: 6, Meta: model.Meta{Title: "工作流创建", Icon: "plus"}}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitAuthorityMenu() (err error) { - return 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 -} - -func InitSysDictionary() (err error) { - status := new(bool) - *status = true - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysDictionary{ - {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"}, - {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"}, - {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"}, - {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"}, - {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"}, - {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysAuthorityMenus() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []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}, - {"8881", 17}, - {"8881", 18}, - {"8881", 19}, - {"8881", 20}, - {"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", 13}, - {"9528", 14}, - {"9528", 15}, - {"9528", 17}, - {"9528", 18}, - {"9528", 19}, - {"9528", 20}, - } - if tx.Table("sys_authority_menus").Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysDataAuthorityId() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []SysDataAuthorityId{ - {"888", "888"}, - {"888", "8881"}, - {"888", "9528"}, - {"9528", "8881"}, - {"9528", "9528"}, - } - if global.GVA_DB.Migrator().HasTable("sys_data_authority_ids") { - if tx.Table("sys_data_authority_ids").Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error - } - if tx.Table("sys_data_authority_id").Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitSysDictionaryDetail() (err error) { - status := new(bool) - *status = true - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.SysDictionaryDetail{ - {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2}, - {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2}, - {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2}, - {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2}, - {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3}, - {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3}, - {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3}, - {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3}, - {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3}, - {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4}, - {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4}, - {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4}, - {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5}, - {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5}, - {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5}, - {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5}, - {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5}, - {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5}, - {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5}, - {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5}, - {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5}, - {gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5}, - {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitExaFileUploadAndDownload() (err error) { - tx := global.GVA_DB.Begin() // 开始事务 - insert := []model.ExaFileUploadAndDownload{ - {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"}, - {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"}, - } - if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务 - tx.Rollback() - } - return tx.Commit().Error -} - -func InitData() { - var err error - err = InitSysApi() - err = InitSysUser() - err = InitExaCustomer() - err = InitCasbinModel() - err = InitSysAuthority() - err = InitSysBaseMenus() - err = InitAuthorityMenu() - err = InitSysDictionary() - err = InitSysAuthorityMenus() - err = InitSysDataAuthorityId() - err = InitSysDictionaryDetail() - err = InitExaFileUploadAndDownload() - if err != nil { - global.GVA_LOG.Error("initialize data failed", zap.Any("err", err)) - } - global.GVA_LOG.Info("initialize data success") -} diff --git a/server/initialize/gorm.go b/server/initialize/gorm.go index 35b60f7f..f722495b 100644 --- a/server/initialize/gorm.go +++ b/server/initialize/gorm.go @@ -5,33 +5,23 @@ import ( "gin-vue-admin/model" "go.uber.org/zap" "gorm.io/driver/mysql" - "gorm.io/driver/postgres" - "gorm.io/driver/sqlserver" "gorm.io/gorm" "gorm.io/gorm/logger" "os" ) -var err error - // Gorm 初始化数据库并产生数据库全局变量 -func Gorm() { +func Gorm() *gorm.DB { switch global.GVA_CONFIG.System.DbType { case "mysql": - GormMysql() - case "postgresql": - GormPostgreSql() - //case "sqlite": // sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可 - // GormSqlite() - case "sqlserver": - GormSqlServer() + return GormMysql() default: - GormMysql() + return GormMysql() } } -// GormDBTables 注册数据库表专用 -func GormDBTables(db *gorm.DB) { +// MysqlTables 注册数据库表专用 +func MysqlTables(db *gorm.DB) { err := db.AutoMigrate( model.SysUser{}, model.SysAuthority{}, @@ -58,7 +48,7 @@ func GormDBTables(db *gorm.DB) { } // GormMysql 初始化Mysql数据库 -func GormMysql() { +func GormMysql() *gorm.DB { m := global.GVA_CONFIG.Mysql dsn := m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config mysqlConfig := mysql.Config{ @@ -69,80 +59,29 @@ func GormMysql() { DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列 SkipInitializeWithVersion: false, // 根据版本自动配置 } - gormConfig := config(m.LogMode) - if global.GVA_DB, err = gorm.Open(mysql.New(mysqlConfig), gormConfig); err != nil { + if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig(m.LogMode)); err != nil { global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err)) os.Exit(0) + return nil } else { - GormDBTables(global.GVA_DB) - sqlDB, _ := global.GVA_DB.DB() + sqlDB, _ := db.DB() sqlDB.SetMaxIdleConns(m.MaxIdleConns) sqlDB.SetMaxOpenConns(m.MaxOpenConns) + return db } } -// GormPostgreSql 初始化PostgreSql数据库 -func GormPostgreSql() { - p := global.GVA_CONFIG.Postgresql - dsn := "host="+ p.Host + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config - postgresConfig := postgres.Config{ - DSN: dsn, // DSN data source name - PreferSimpleProtocol: p.PreferSimpleProtocol, // 禁用隐式 prepared statement - } - gormConfig := config(p.Logger) - if global.GVA_DB, err = gorm.Open(postgres.New(postgresConfig), gormConfig); err != nil { - global.GVA_LOG.Error("PostgreSql启动异常", zap.Any("err", err)) - os.Exit(0) - } else { - GormDBTables(global.GVA_DB) - sqlDB, _ := global.GVA_DB.DB() - sqlDB.SetMaxIdleConns(p.MaxIdleConns) - sqlDB.SetMaxOpenConns(p.MaxOpenConns) - } -} - -// GormSqlite 初始化Sqlite数据库 sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可 -//func GormSqlite() { -// s := global.GVA_CONFIG.Sqlite -// gormConfig := config(s.Logger) -// if global.GVA_DB, err = gorm.Open(sqlite.Open(s.Path), gormConfig); err != nil { -// global.GVA_LOG.Error("Sqlite启动异常", zap.Any("err", err)) -// os.Exit(0) -// } else { -// GormDBTables(global.GVA_DB) -// sqlDB, _ := global.GVA_DB.DB() -// sqlDB.SetMaxIdleConns(s.MaxIdleConns) -// sqlDB.SetMaxOpenConns(s.MaxOpenConns) -// } -//} - -// GormSqlServer 初始化SqlServer数据库 -func GormSqlServer() { - ss := global.GVA_CONFIG.Sqlserver - dsn := "sqlserver://" + ss.Username + ":" + ss.Password + "@" + ss.Path + "?database=gorm" - if global.GVA_DB, err = gorm.Open(sqlserver.Open(dsn), &gorm.Config{}); err != nil { - global.GVA_LOG.Error("SqlServer启动异常", zap.Any("err", err)) - os.Exit(0) - } else { - GormDBTables(global.GVA_DB) - sqlDB, _ := global.GVA_DB.DB() - sqlDB.SetMaxIdleConns(ss.MaxIdleConns) - sqlDB.SetMaxOpenConns(ss.MaxOpenConns) - } -} - -// config 根据配置决定是否开启日志 -func config(mod bool) (c *gorm.Config) { +// gormConfig 根据配置决定是否开启日志 +func gormConfig(mod bool) *gorm.Config { if mod { - c = &gorm.Config{ + return &gorm.Config{ Logger: logger.Default.LogMode(logger.Info), DisableForeignKeyConstraintWhenMigrating: true, } } else { - c = &gorm.Config{ + return &gorm.Config{ Logger: logger.Default.LogMode(logger.Silent), DisableForeignKeyConstraintWhenMigrating: true, } } - return -} +} \ No newline at end of file diff --git a/server/main.go b/server/main.go index ce88bebd..119043a4 100644 --- a/server/main.go +++ b/server/main.go @@ -3,7 +3,6 @@ package main import ( "gin-vue-admin/core" "gin-vue-admin/global" - "gin-vue-admin/gva/init_data" "gin-vue-admin/initialize" ) @@ -15,10 +14,10 @@ import ( // @name x-token // @BasePath / func main() { - initialize.Gorm() - if global.GVA_CONFIG.System.NeedInitData { - init_data.InitData() // 通过配置文件初始化数据 默认为 false 首次运行需要将 ./config.yaml中 system下的 need-init-data 修改为true - } + global.GVA_VP = core.Viper() // 初始化Viper + global.GVA_LOG = core.Zap() // 初始化zap日志库 + global.GVA_DB = initialize.Gorm() // gorm连接数据库 + initialize.MysqlTables(global.GVA_DB) // 初始化表 // 程序结束前关闭数据库链接 db, _ := global.GVA_DB.DB() defer db.Close() diff --git a/server/model/sys_operation_record.go b/server/model/sys_operation_record.go index 015b9306..e94bfaaa 100644 --- a/server/model/sys_operation_record.go +++ b/server/model/sys_operation_record.go @@ -16,7 +16,7 @@ type SysOperationRecord struct { Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟"` Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"` ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` - Body string `json:"body" form:"body" gorm:"column:body;comment:请求Body"` + Body string `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"` Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"` UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` User SysUser `json:"user"` diff --git a/server/router/sys_base.go b/server/router/sys_base.go index 33d7c001..20da80dc 100644 --- a/server/router/sys_base.go +++ b/server/router/sys_base.go @@ -8,7 +8,6 @@ import ( func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { BaseRouter := Router.Group("base") { - BaseRouter.POST("register", v1.Register) BaseRouter.POST("login", v1.Login) BaseRouter.POST("captcha", v1.Captcha) } diff --git a/server/router/sys_user.go b/server/router/sys_user.go index 88be4677..12d49a30 100644 --- a/server/router/sys_user.go +++ b/server/router/sys_user.go @@ -12,6 +12,7 @@ func InitUserRouter(Router *gin.RouterGroup) { Use(middleware.CasbinHandler()). Use(middleware.OperationRecord()) { + UserRouter.POST("register", v1.Register) UserRouter.POST("changePassword", v1.ChangePassword) // 修改密码 UserRouter.POST("getUserList", v1.GetUserList) // 分页获取用户列表 UserRouter.POST("setUserAuthority", v1.SetUserAuthority) // 设置用户权限 diff --git a/server/utils/constant.go b/server/utils/constant.go new file mode 100644 index 00000000..bb50e80c --- /dev/null +++ b/server/utils/constant.go @@ -0,0 +1,6 @@ +package utils + +const ( + ConfigEnv = "GVA_CONFIG" + ConfigFile = "config.yaml" +) diff --git a/server/utils/rotatelogs_unix.go b/server/utils/rotatelogs_unix.go new file mode 100644 index 00000000..f2759d8f --- /dev/null +++ b/server/utils/rotatelogs_unix.go @@ -0,0 +1,26 @@ +// +build !windows + +package utils + +import ( + "gin-vue-admin/global" + zaprotatelogs "github.com/lestrrat-go/file-rotatelogs" + "go.uber.org/zap/zapcore" + "os" + "path" + "time" +) + +// GetWriteSyncer zap logger中加入file-rotatelogs +func GetWriteSyncer() (zapcore.WriteSyncer, error) { + fileWriter, err := zaprotatelogs.New( + path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"), + zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName), + zaprotatelogs.WithMaxAge(7*24*time.Hour), + zaprotatelogs.WithRotationTime(24*time.Hour), + ) + if global.GVA_CONFIG.Zap.LogInConsole { + return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err + } + return zapcore.AddSync(fileWriter), err +} \ No newline at end of file diff --git a/server/utils/rotatelogs_windows.go b/server/utils/rotatelogs_windows.go new file mode 100644 index 00000000..6c7a3742 --- /dev/null +++ b/server/utils/rotatelogs_windows.go @@ -0,0 +1,23 @@ +package utils + +import ( + "gin-vue-admin/global" + zaprotatelogs "github.com/lestrrat-go/file-rotatelogs" + "go.uber.org/zap/zapcore" + "os" + "path" + "time" +) + +// GetWriteSyncer zap logger中加入file-rotatelogs +func GetWriteSyncer() (zapcore.WriteSyncer, error) { + fileWriter, err := zaprotatelogs.New( + path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"), + zaprotatelogs.WithMaxAge(7*24*time.Hour), + zaprotatelogs.WithRotationTime(24*time.Hour), + ) + if global.GVA_CONFIG.Zap.LogInConsole { + return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err + } + return zapcore.AddSync(fileWriter), err +} \ No newline at end of file diff --git a/web/openDocument.js b/web/openDocument.js new file mode 100644 index 00000000..0999755f --- /dev/null +++ b/web/openDocument.js @@ -0,0 +1,23 @@ +/* + 商用代码公司自用产品无需授权 + 若作为代码出售的产品(任何涉及代码交付第三方作为后续开发)必须保留此脚本 + 或标注原作者信息 + 否则将依法维权 +*/ + +var child_process = require("child_process"); + +var url = "https://www.gin-vue-admin.com", + cmd = ''; +console.log(process.platform) +switch (process.platform) { + case 'win32': + cmd = 'start'; + child_process.exec(cmd + ' ' + url); + break; + + case 'darwin': + cmd = 'open'; + child_process.exec(cmd + ' ' + url); + break; +} \ No newline at end of file diff --git a/web/package.json b/web/package.json index f3077039..d3acc090 100644 --- a/web/package.json +++ b/web/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "serve": "start https://www.gin-vue-admin.com && vue-cli-service serve", + "serve": "node openDocument.js && vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, diff --git a/web/src/api/user.js b/web/src/api/user.js index 6871e94d..06136e23 100644 --- a/web/src/api/user.js +++ b/web/src/api/user.js @@ -30,7 +30,7 @@ export const captcha = (data) => { // @Router /base/resige [post] export const register = (data) => { return service({ - url: "/base/register", + url: "/user/register", method: 'post', data: data }) diff --git a/web/src/main.js b/web/src/main.js index 085b2493..fd5b1f81 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -54,7 +54,7 @@ auth(Vue) import uploader from 'vue-simple-uploader' Vue.use(uploader) -new Vue({ +export default new Vue({ render: h => h(App), router, store diff --git a/web/src/permission.js b/web/src/permission.js index 3edbae77..48a7dc5f 100644 --- a/web/src/permission.js +++ b/web/src/permission.js @@ -3,7 +3,7 @@ import { store } from '@/store/index' let asyncRouterFlag = 0 -const whiteList = ['login', 'register'] +const whiteList = ['login'] router.beforeEach(async(to, from, next) => { const token = store.getters['user/token'] diff --git a/web/src/router/index.js b/web/src/router/index.js index 3e41cdcb..98e12194 100644 --- a/web/src/router/index.js +++ b/web/src/router/index.js @@ -12,12 +12,6 @@ const baseRouters = [{ name: 'login', component: () => import ('@/view/login/login.vue') - }, - { - path: '/register', - name: 'register', - component: () => - import ('@/view/login/register.vue') } ] diff --git a/web/src/utils/request.js b/web/src/utils/request.js index 8821cd61..b97abfbb 100644 --- a/web/src/utils/request.js +++ b/web/src/utils/request.js @@ -1,12 +1,12 @@ import axios from 'axios'; // 引入axios -import { Message, Loading } from 'element-ui'; +import { Message } from 'element-ui'; import { store } from '@/store/index' +import context from '@/main.js' const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API, timeout: 99999 }) let acitveAxios = 0 -let loadingInstance let timer const showLoading = () => { acitveAxios++ @@ -15,7 +15,7 @@ const showLoading = () => { } timer = setTimeout(() => { if (acitveAxios > 0) { - loadingInstance = Loading.service({ fullscreen: true }) + context.$bus.emit("showLoading") } }, 400); } @@ -24,13 +24,12 @@ const closeLoading = () => { acitveAxios-- if (acitveAxios <= 0) { clearTimeout(timer) - loadingInstance && loadingInstance.close() + context.$bus.emit("closeLoading") } } //http request 拦截器 service.interceptors.request.use( config => { - console.log(config) if (!config.donNotShowLoading) { showLoading() } diff --git a/web/src/view/example/rte/rte.vue b/web/src/view/example/rte/rte.vue index 85d101b2..57f9ad29 100644 --- a/web/src/view/example/rte/rte.vue +++ b/web/src/view/example/rte/rte.vue @@ -1,5 +1,6 @@