diff --git a/server/api/v1/autocode/autocodeExample.go b/server/api/v1/autocode/auto_code_example.go similarity index 100% rename from server/api/v1/autocode/autocodeExample.go rename to server/api/v1/autocode/auto_code_example.go diff --git a/server/api/v1/enter.go b/server/api/v1/enter.go index 4f92934ec53b239021c5b9ced773cc0da300c593..919f6881fdd857a3c46bac46aa4e679697e7ffdc 100644 --- a/server/api/v1/enter.go +++ b/server/api/v1/enter.go @@ -7,8 +7,8 @@ import ( ) type ApiGroup struct { - ExampleApiGroup example.ApiGroup SystemApiGroup system.ApiGroup + ExampleApiGroup example.ApiGroup AutoCodeApiGroup autocode.ApiGroup } diff --git a/server/api/v1/example/enter.go b/server/api/v1/example/enter.go index 9149e02e20bdebc84f88c9496834548b095fdea4..efc344e1dc859d1494f3a17a56e81039cf9bb082 100644 --- a/server/api/v1/example/enter.go +++ b/server/api/v1/example/enter.go @@ -3,11 +3,11 @@ package example import "github.com/flipped-aurora/gin-vue-admin/server/service" type ApiGroup struct { - CustomerApi ExcelApi + CustomerApi FileUploadAndDownloadApi } -var fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService -var customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService var excelService = service.ServiceGroupApp.ExampleServiceGroup.ExcelService +var customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService +var fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService diff --git a/server/api/v1/system/enter.go b/server/api/v1/system/enter.go index 995522c3c0a368fcf3981425cb97b762bea994cb..8796ac067c5b0bdb5bd23a320e32aaf8d57da734 100644 --- a/server/api/v1/system/enter.go +++ b/server/api/v1/system/enter.go @@ -3,31 +3,32 @@ package system import "github.com/flipped-aurora/gin-vue-admin/server/service" type ApiGroup struct { - SystemApiApi - AuthorityApi - AutoCodeApi + DBApi + JwtApi BaseApi + SystemApi CasbinApi + AutoCodeApi + SystemApiApi + AuthorityApi DictionaryApi - DictionaryDetailApi - SystemApi - DBApi - JwtApi - OperationRecordApi AuthorityMenuApi + OperationRecordApi + AutoCodeHistoryApi + DictionaryDetailApi } -var authorityService = service.ServiceGroupApp.SystemServiceGroup.AuthorityService var apiService = service.ServiceGroupApp.SystemServiceGroup.ApiService +var jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService var menuService = service.ServiceGroupApp.SystemServiceGroup.MenuService +var userService = service.ServiceGroupApp.SystemServiceGroup.UserService +var initDBService = service.ServiceGroupApp.SystemServiceGroup.InitDBService var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService var autoCodeService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeService -var autoCodeHistoryService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeHistoryService -var dictionaryService = service.ServiceGroupApp.SystemServiceGroup.DictionaryService -var dictionaryDetailService = service.ServiceGroupApp.SystemServiceGroup.DictionaryDetailService -var initDBService = service.ServiceGroupApp.SystemServiceGroup.InitDBService -var jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService var baseMenuService = service.ServiceGroupApp.SystemServiceGroup.BaseMenuService -var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService -var userService = service.ServiceGroupApp.SystemServiceGroup.UserService +var authorityService = service.ServiceGroupApp.SystemServiceGroup.AuthorityService +var dictionaryService = service.ServiceGroupApp.SystemServiceGroup.DictionaryService var systemConfigService = service.ServiceGroupApp.SystemServiceGroup.SystemConfigService +var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService +var autoCodeHistoryService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeHistoryService +var dictionaryDetailService = service.ServiceGroupApp.SystemServiceGroup.DictionaryDetailService diff --git a/server/api/v1/system/sys_auto_code.go b/server/api/v1/system/sys_auto_code.go index 855602eb6c24e3069f6045f3fd89bc49a9aaa83d..7b24e9267e417aae9cf5d08fcf569c8deefce407 100644 --- a/server/api/v1/system/sys_auto_code.go +++ b/server/api/v1/system/sys_auto_code.go @@ -9,99 +9,15 @@ import ( "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/flipped-aurora/gin-vue-admin/server/model/system" - systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" "github.com/flipped-aurora/gin-vue-admin/server/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) -type AutoCodeApi struct { -} - -// @Tags AutoCode -// @Summary 删除回滚记录 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body systemReq.AutoHistoryByID true "删除回滚记录" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" -// @Router /autoCode/delSysHistory [post] -func (autoApi *AutoCodeApi) DelSysHistory(c *gin.Context) { - var id systemReq.AutoHistoryByID - _ = c.ShouldBindJSON(&id) - err := autoCodeHistoryService.DeletePage(id.ID) - if err != nil { - global.GVA_LOG.Error("获取失败!", zap.Error(err)) - response.FailWithMessage("获取失败", c) - } - response.OkWithMessage("删除成功", c) - -} - -// @Tags AutoCode -// @Summary 查询回滚记录 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body systemReq.SysAutoHistory true "查询回滚记录" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getSysHistory [post] -func (autoApi *AutoCodeApi) GetSysHistory(c *gin.Context) { - var search systemReq.SysAutoHistory - _ = c.ShouldBindJSON(&search) - err, list, total := autoCodeHistoryService.GetSysHistoryPage(search.PageInfo) - if err != nil { - global.GVA_LOG.Error("获取失败!", zap.Error(err)) - response.FailWithMessage("获取失败", c) - } else { - response.OkWithDetailed(response.PageResult{ - List: list, - Total: total, - Page: search.Page, - PageSize: search.PageSize, - }, "获取成功", c) - } -} - -// @Tags AutoCode -// @Summary 回滚 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body systemReq.AutoHistoryByID true "回滚自动生成代码" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}" -// @Router /autoCode/rollback [post] -func (autoApi *AutoCodeApi) RollBack(c *gin.Context) { - var id systemReq.AutoHistoryByID - _ = c.ShouldBindJSON(&id) - if err := autoCodeHistoryService.RollBack(id.ID); err != nil { - response.FailWithMessage(err.Error(), c) - return - } - response.OkWithMessage("回滚成功", c) -} - -// @Tags AutoCode -// @Summary 回滚 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body systemReq.AutoHistoryByID true "获取meta信息" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getMeta [post] -func (autoApi *AutoCodeApi) GetMeta(c *gin.Context) { - var id systemReq.AutoHistoryByID - _ = c.ShouldBindJSON(&id) - if v, err := autoCodeHistoryService.GetMeta(id.ID); err != nil { - response.FailWithMessage(err.Error(), c) - return - } else { - response.OkWithDetailed(gin.H{"meta": v}, "获取成功", c) - } - -} +type AutoCodeApi struct{} +// PreviewTemp // @Tags AutoCode // @Summary 预览创建后的代码 // @Security ApiKeyAuth @@ -126,6 +42,7 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) { } } +// CreateTemp // @Tags AutoCode // @Summary 自动代码模板 // @Security ApiKeyAuth @@ -171,40 +88,43 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) { } } +// GetDB // @Tags AutoCode -// @Summary 获取当前数据库所有表 +// @Summary 获取当前所有数据库 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getTables [get] -func (autoApi *AutoCodeApi) GetTables(c *gin.Context) { - dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) - err, tables := autoCodeService.GetTables(dbName) +// @Router /autoCode/getDatabase [get] +func (autoApi *AutoCodeApi) GetDB(c *gin.Context) { + dbs, err := autoCodeService.Database().GetDB() if err != nil { - global.GVA_LOG.Error("查询table失败!", zap.Error(err)) - response.FailWithMessage("查询table失败", c) - } else { - response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c) + global.GVA_LOG.Error("获取失败!", zap.Error(err)) + response.FailWithMessage("获取失败", c) } + response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c) } +// GetTables // @Tags AutoCode -// @Summary 获取当前所有数据库 +// @Summary 获取当前数据库所有表 // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getDatabase [get] -func (autoApi *AutoCodeApi) GetDB(c *gin.Context) { - if err, dbs := autoCodeService.GetDB(); err != nil { - global.GVA_LOG.Error("获取失败!", zap.Error(err)) - response.FailWithMessage("获取失败", c) +// @Router /autoCode/getTables [get] +func (autoApi *AutoCodeApi) GetTables(c *gin.Context) { + dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) + tables, err := autoCodeService.Database().GetTables(dbName) + if err != nil { + global.GVA_LOG.Error("查询table失败!", zap.Error(err)) + response.FailWithMessage("查询table失败", c) } else { - response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c) + response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c) } } +// GetColumn // @Tags AutoCode // @Summary 获取当前表所有字段 // @Security ApiKeyAuth @@ -215,10 +135,10 @@ func (autoApi *AutoCodeApi) GetDB(c *gin.Context) { func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) { dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) tableName := c.Query("tableName") - if err, columns := autoCodeService.GetColumn(tableName, dbName); err != nil { + columns, err := autoCodeService.Database().GetColumn(tableName, dbName) + if err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败", c) - } else { - response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c) } + response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c) } diff --git a/server/api/v1/system/sys_auto_code_history.go b/server/api/v1/system/sys_auto_code_history.go new file mode 100644 index 0000000000000000000000000000000000000000..7254b96b364749b7de89bb475da3706894340afb --- /dev/null +++ b/server/api/v1/system/sys_auto_code_history.go @@ -0,0 +1,98 @@ +package system + +import ( + "github.com/flipped-aurora/gin-vue-admin/server/global" + "github.com/flipped-aurora/gin-vue-admin/server/model/common/request" + "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" + systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" + "github.com/gin-gonic/gin" + "go.uber.org/zap" +) + +type AutoCodeHistoryApi struct{} + +// First +// @Tags AutoCode +// @Summary 获取meta信息 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body request.GetById true "请求参数" +// @Success 200 {object} response.Response{} "获取成功!" +// @Router /autoCode/getMeta [post] +func (a *AutoCodeHistoryApi) First(c *gin.Context) { + var info request.GetById + _ = c.ShouldBindJSON(&info) + data, err := autoCodeHistoryService.First(&info) + if err != nil { + response.FailWithMessage(err.Error(), c) + return + } + response.OkWithDetailed(gin.H{"meta": data}, "获取成功", c) +} + +// Delete +// @Tags AutoCode +// @Summary 删除回滚记录 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body request.GetById true "请求参数" +// @Success 200 {object} response.Response{} "删除成功!" +// @Router /autoCode/delSysHistory [post] +func (a *AutoCodeHistoryApi) Delete(c *gin.Context) { + var info request.GetById + _ = c.ShouldBindJSON(&info) + err := autoCodeHistoryService.Delete(&info) + if err != nil { + global.GVA_LOG.Error("删除失败!", zap.Error(err)) + response.FailWithMessage("删除失败", c) + return + } + response.OkWithMessage("删除成功", c) +} + +// RollBack +// @Tags AutoCode +// @Summary 回滚自动生成代码 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body request.GetById true "请求参数" +// @Success 200 {object} response.Response{} "回滚成功!" +// @Router /autoCode/rollback [post] +func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) { + var info request.GetById + _ = c.ShouldBindJSON(&info) + if err := autoCodeHistoryService.RollBack(&info); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + response.OkWithMessage("回滚成功", c) +} + +// GetList +// @Tags AutoCode +// @Summary 查询回滚记录 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.SysAutoHistory true "请求参数" +// @Success 200 {object} response.Response{} "获取成功!" +// @Router /autoCode/getSysHistory [post] +func (a *AutoCodeHistoryApi) GetList(c *gin.Context) { + var search systemReq.SysAutoHistory + _ = c.ShouldBindJSON(&search) + list, total, err := autoCodeHistoryService.GetList(search.PageInfo) + if err != nil { + global.GVA_LOG.Error("获取失败!", zap.Error(err)) + response.FailWithMessage("获取失败", c) + return + } + response.OkWithDetailed(response.PageResult{ + List: list, + Total: total, + Page: search.Page, + PageSize: search.PageSize, + }, "获取成功", c) +} diff --git a/server/api/v1/system/sys_initdb.go b/server/api/v1/system/sys_initdb.go index 800a487cda1cab2a81aa4ba5ab50e85f8e76bd7e..70645aa12269f6c609306e61c63bfca9d11a747c 100644 --- a/server/api/v1/system/sys_initdb.go +++ b/server/api/v1/system/sys_initdb.go @@ -9,9 +9,9 @@ import ( "github.com/gin-gonic/gin" ) -type DBApi struct { -} +type DBApi struct{} +// InitDB // @Tags InitDB // @Summary 初始化用户数据库 // @Produce application/json @@ -38,6 +38,7 @@ func (i *DBApi) InitDB(c *gin.Context) { response.OkWithData("自动创建数据库成功", c) } +// CheckDB // @Tags CheckDB // @Summary 初始化用户数据库 // @Produce application/json diff --git a/server/config/gorm_pgsql.go b/server/config/gorm_pgsql.go index 40464900796b74db78d04914a7e4de49a38a9300..554da8b47ad586d500d3c2c1e58f57ebedbfb150 100644 --- a/server/config/gorm_pgsql.go +++ b/server/config/gorm_pgsql.go @@ -13,6 +13,14 @@ type Pgsql struct { LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` // 是否通过zap写入日志文件 } +// Dsn 基于配置文件获取 dsn +// Author [SliverHorn](https://github.com/SliverHorn) func (p *Pgsql) Dsn() string { return "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config } + +// LinkDsn 根据 dbname 生成 dsn +// Author [SliverHorn](https://github.com/SliverHorn) +func (p *Pgsql) LinkDsn(dbname string) string { + return "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + dbname + " port=" + p.Port + " " + p.Config +} diff --git a/server/core/server.go b/server/core/server.go index 22392e7527da586e34829708f467f7fd3969e7bb..57dbfb1515bb5bad27b795046695ed114544d0ef 100644 --- a/server/core/server.go +++ b/server/core/server.go @@ -38,7 +38,7 @@ func RunWindowsServer() { fmt.Printf(` 欢迎使用 github.com/flipped-aurora/gin-vue-admin/server - 当前版本:V2.4.6 Apache + 当前版本:V2.4.6 Beta 加群方式:微信号:shouzi_1994 QQ群:622360840 默认自动化文档地址:http://127.0.0.1%s/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:8080 diff --git a/server/initialize/gorm.go b/server/initialize/gorm.go index 2d4741c6f0b180a6e66ed00986ad7db1764ce9e9..d22c3181a711457611e3cb6e25f6ccaad3dd012c 100644 --- a/server/initialize/gorm.go +++ b/server/initialize/gorm.go @@ -51,6 +51,7 @@ func RegisterTables(db *gorm.DB) { autocode.AutoCodeExample{}, // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT. ) + if err != nil { global.GVA_LOG.Error("register table failed", zap.Error(err)) os.Exit(0) diff --git a/server/initialize/router.go b/server/initialize/router.go index 0bcdef33260f03afcdb05413aea5c35b42b12599..79cb2c2d1c1d77500b1a7ed682b2efee9c80cc81 100644 --- a/server/initialize/router.go +++ b/server/initialize/router.go @@ -54,20 +54,22 @@ func Routers() *gin.Engine { PrivateGroup := Router.Group("") PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) { - systemRouter.InitApiRouter(PrivateGroup) // 注册功能api路由 - systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由 - systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由 - systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由 - systemRouter.InitSystemRouter(PrivateGroup) // system相关路由 - systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由 - systemRouter.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码 - systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由 - systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理 - systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录 - systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理 - exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 + systemRouter.InitApiRouter(PrivateGroup) // 注册功能api路由 + systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由 + systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由 + systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由 + systemRouter.InitSystemRouter(PrivateGroup) // system相关路由 + systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由 + systemRouter.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码 + systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由 + systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理 + systemRouter.InitAutoCodeHistoryRouter(PrivateGroup) // 自动化代码历史 + systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录 + systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理 + exampleRouter.InitExcelRouter(PrivateGroup) // 表格导入导出 exampleRouter.InitCustomerRouter(PrivateGroup) // 客户路由 + exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT. autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup) diff --git a/server/model/common/request/common.go b/server/model/common/request/common.go index 129c6d7ebceca940aeee73b76de00c9a65147b9c..db8bba45681e77ba90bd754f304649575f1f816d 100644 --- a/server/model/common/request/common.go +++ b/server/model/common/request/common.go @@ -1,21 +1,25 @@ package request -// Paging common input parameter structure +// PageInfo Paging common input parameter structure type PageInfo struct { Page int `json:"page" form:"page"` // 页码 PageSize int `json:"pageSize" form:"pageSize"` // 每页大小 } -// Find by id structure +// GetById Find by id structure type GetById struct { ID float64 `json:"id" form:"id"` // 主键ID } +func (r *GetById) Uint() uint { + return uint(r.ID) +} + type IdsReq struct { Ids []int `json:"ids" form:"ids"` } -// Get role by id structure +// GetAuthorityId Get role by id structure type GetAuthorityId struct { AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID } diff --git a/server/model/system/request/sys_auto_history.go b/server/model/system/request/sys_auto_history.go new file mode 100644 index 0000000000000000000000000000000000000000..3ab8aea3692870afafbe333d665b223cd6663b38 --- /dev/null +++ b/server/model/system/request/sys_auto_history.go @@ -0,0 +1,7 @@ +package request + +import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request" + +type SysAutoHistory struct { + request.PageInfo +} diff --git a/server/model/system/request/sys_autocode.go b/server/model/system/response/sys_auto_code.go similarity index 53% rename from server/model/system/request/sys_autocode.go rename to server/model/system/response/sys_auto_code.go index 7216d91f102bb3dfbb9ca371dd4a3c3cac19412e..1e44005342bb8edad5bd307513f4458f39ab5df8 100644 --- a/server/model/system/request/sys_autocode.go +++ b/server/model/system/response/sys_auto_code.go @@ -1,26 +1,16 @@ -package request +package response -import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request" - -type SysAutoHistory struct { - request.PageInfo -} - -type AutoHistoryByID struct { - ID uint `json:"id"` -} - -type DBReq struct { +type Db struct { Database string `json:"database" gorm:"column:database"` } -type TableReq struct { - TableName string `json:"tableName"` +type Table struct { + TableName string `json:"tableName" gorm:"column:table_name"` } -type ColumnReq struct { - ColumnName string `json:"columnName" gorm:"column:column_name"` +type Column struct { DataType string `json:"dataType" gorm:"column:data_type"` + ColumnName string `json:"columnName" gorm:"column:column_name"` DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"` ColumnComment string `json:"columnComment" gorm:"column:column_comment"` } diff --git a/server/model/system/response/sys_auto_code_history.go b/server/model/system/response/sys_auto_code_history.go new file mode 100644 index 0000000000000000000000000000000000000000..a503a84dbdc88caf707e6e7805e7f808fad300eb --- /dev/null +++ b/server/model/system/response/sys_auto_code_history.go @@ -0,0 +1,13 @@ +package response + +import "time" + +type AutoCodeHistory struct { + ID uint `json:"ID" gorm:"column:id"` + CreatedAt time.Time `json:"CreatedAt" gorm:"column:created_at"` + UpdatedAt time.Time `json:"UpdatedAt" gorm:"column:updated_at"` + TableName string `json:"tableName" gorm:"column:table_name"` + StructName string `json:"structName" gorm:"column:struct_name"` + StructCNName string `json:"structCNName" gorm:"column:struct_cn_name"` + Flag int `json:"flag" gorm:"column:flag"` +} diff --git a/server/model/system/sys_auto_code.go b/server/model/system/sys_auto_code.go index 99a9e2e7f189e276697aa7cb9e1169c82f4be76d..f31288980a62c756a08c85d83a9e690cb4f749b6 100644 --- a/server/model/system/sys_auto_code.go +++ b/server/model/system/sys_auto_code.go @@ -2,7 +2,7 @@ package system import "errors" -// 初始版本自动化代码工具 +// AutoCodeStruct 初始版本自动化代码工具 type AutoCodeStruct struct { StructName string `json:"structName"` // Struct名称 TableName string `json:"tableName"` // 表名 diff --git a/server/router/autocode/autocodeExample.go b/server/router/autocode/auto_code_example.go similarity index 100% rename from server/router/autocode/autocodeExample.go rename to server/router/autocode/auto_code_example.go diff --git a/server/router/example/enter.go b/server/router/example/enter.go index 03c7822661115e87387e486814c8529a179d52a1..5608b8480e29986ddca303e4621f1a94ae9486af 100644 --- a/server/router/example/enter.go +++ b/server/router/example/enter.go @@ -1,7 +1,7 @@ package example type RouterGroup struct { - CustomerRouter ExcelRouter + CustomerRouter FileUploadAndDownloadRouter } diff --git a/server/router/system/enter.go b/server/router/system/enter.go index 6231e7760bb84b4aff664357b3256cc4db7e85f4..c08492966ca01c080cf764666570d64776ecae34 100644 --- a/server/router/system/enter.go +++ b/server/router/system/enter.go @@ -2,16 +2,16 @@ package system type RouterGroup struct { ApiRouter - AuthorityRouter - AutoCodeRouter + JwtRouter + SysRouter BaseRouter - CasbinRouter - DictionaryRouter - DictionaryDetailRouter InitRouter - JwtRouter MenuRouter - OperationRecordRouter - SysRouter UserRouter + CasbinRouter + AutoCodeRouter + AuthorityRouter + DictionaryRouter + OperationRecordRouter + DictionaryDetailRouter } diff --git a/server/router/system/sys_auto_code.go b/server/router/system/sys_auto_code.go index af1edaede649c201e99e8f67988ab73d09fbcaf5..27dcce5e7b338a0f31ce700fbd222390badb60b1 100644 --- a/server/router/system/sys_auto_code.go +++ b/server/router/system/sys_auto_code.go @@ -5,21 +5,16 @@ import ( "github.com/gin-gonic/gin" ) -type AutoCodeRouter struct { -} +type AutoCodeRouter struct{} func (s *AutoCodeRouter) InitAutoCodeRouter(Router *gin.RouterGroup) { autoCodeRouter := Router.Group("autoCode") - var authorityApi = v1.ApiGroupApp.SystemApiGroup.AutoCodeApi + autoCodeApi := v1.ApiGroupApp.SystemApiGroup.AutoCodeApi { - autoCodeRouter.POST("delSysHistory", authorityApi.DelSysHistory) // 删除回滚记录 - autoCodeRouter.POST("getMeta", authorityApi.GetMeta) // 根据id获取meta信息 - autoCodeRouter.POST("getSysHistory", authorityApi.GetSysHistory) // 获取回滚记录分页 - autoCodeRouter.POST("rollback", authorityApi.RollBack) // 回滚 - autoCodeRouter.POST("preview", authorityApi.PreviewTemp) // 获取自动创建代码预览 - autoCodeRouter.POST("createTemp", authorityApi.CreateTemp) // 创建自动化代码 - autoCodeRouter.GET("getTables", authorityApi.GetTables) // 获取对应数据库的表 - autoCodeRouter.GET("getDB", authorityApi.GetDB) // 获取数据库 - autoCodeRouter.GET("getColumn", authorityApi.GetColumn) // 获取指定表所有字段信息 + autoCodeRouter.GET("getDB", autoCodeApi.GetDB) // 获取数据库 + autoCodeRouter.GET("getTables", autoCodeApi.GetTables) // 获取对应数据库的表 + autoCodeRouter.GET("getColumn", autoCodeApi.GetColumn) // 获取指定表所有字段信息 + autoCodeRouter.POST("preview", autoCodeApi.PreviewTemp) // 获取自动创建代码预览 + autoCodeRouter.POST("createTemp", autoCodeApi.CreateTemp) // 创建自动化代码 } } diff --git a/server/router/system/sys_auto_code_history.go b/server/router/system/sys_auto_code_history.go new file mode 100644 index 0000000000000000000000000000000000000000..3eaa82779bc8741b2a55313dbc23aaf43bcdf0f4 --- /dev/null +++ b/server/router/system/sys_auto_code_history.go @@ -0,0 +1,19 @@ +package system + +import ( + v1 "github.com/flipped-aurora/gin-vue-admin/server/api/v1" + "github.com/gin-gonic/gin" +) + +type AutoCodeHistoryRouter struct{} + +func (s *AutoCodeRouter) InitAutoCodeHistoryRouter(Router *gin.RouterGroup) { + autoCodeHistoryRouter := Router.Group("autoCode") + autoCodeHistoryApi := v1.ApiGroupApp.SystemApiGroup.AutoCodeHistoryApi + { + autoCodeHistoryRouter.POST("getMeta", autoCodeHistoryApi.First) // 根据id获取meta信息 + autoCodeHistoryRouter.POST("rollback", autoCodeHistoryApi.RollBack) // 回滚 + autoCodeHistoryRouter.POST("delSysHistory", autoCodeHistoryApi.Delete) // 删除回滚记录 + autoCodeHistoryRouter.POST("getSysHistory", autoCodeHistoryApi.GetList) // 获取回滚记录分页 + } +} diff --git a/server/service/autocode/autocodeExample.go b/server/service/autocode/auto_code_example.go similarity index 100% rename from server/service/autocode/autocodeExample.go rename to server/service/autocode/auto_code_example.go diff --git a/server/service/enter.go b/server/service/enter.go index 045acb633cf84dfdd41f5ae9a87e81bb3c4c5f2c..9df58598071e0a167f3574cd3ca0de81a78d8039 100644 --- a/server/service/enter.go +++ b/server/service/enter.go @@ -7,8 +7,8 @@ import ( ) type ServiceGroup struct { - ExampleServiceGroup example.ServiceGroup SystemServiceGroup system.ServiceGroup + ExampleServiceGroup example.ServiceGroup AutoCodeServiceGroup autocode.ServiceGroup } diff --git a/server/service/example/enter.go b/server/service/example/enter.go index 251a535ef362b6170b1314b74296d905f3c8db39..f9bd07a30b87532c5ab68608665b9543853bccbd 100644 --- a/server/service/example/enter.go +++ b/server/service/example/enter.go @@ -1,7 +1,7 @@ package example type ServiceGroup struct { - FileUploadAndDownloadService - CustomerService ExcelService + CustomerService + FileUploadAndDownloadService } diff --git a/server/service/system/enter.go b/server/service/system/enter.go index 836cf6fe037f22fe55d1f34cbd57a90816d1f297..4258f1e04a7b837f1538eb977160dacae76141fa 100644 --- a/server/service/system/enter.go +++ b/server/service/system/enter.go @@ -3,16 +3,16 @@ package system type ServiceGroup struct { JwtService ApiService - AuthorityService + MenuService + UserService + CasbinService + InitDBService AutoCodeService - AutoCodeHistoryService BaseMenuService - CasbinService + AuthorityService DictionaryService - DictionaryDetailService - InitDBService - MenuService - OperationRecordService SystemConfigService - UserService + AutoCodeHistoryService + OperationRecordService + DictionaryDetailService } diff --git a/server/service/system/sys_api.go b/server/service/system/sys_api.go index 1d3a83646c1ee9e8b62433b1675bbc632f5f1e9d..a9daef37af2c4ceaedbf8ea7445cca429a92105d 100644 --- a/server/service/system/sys_api.go +++ b/server/service/system/sys_api.go @@ -76,11 +76,22 @@ func (apiService *ApiService) GetAPIInfoList(api system.SysApi, info request.Pag db = db.Limit(limit).Offset(offset) if order != "" { var OrderStr string - if desc { - OrderStr = order + " desc" - } else { - OrderStr = order + // 设置有效排序key 防止sql注入 + // 感谢 Tom4t0 提交漏洞信息 + orderMap := make(map[string]bool, 5) + orderMap["id"] = true + orderMap["path"] = true + orderMap["api_group"] = true + orderMap["description"] = true + orderMap["method"] = true + if orderMap[order] { + if desc { + OrderStr = order + " desc" + } else { + OrderStr = order + } } + err = db.Order(OrderStr).Find(&apiList).Error } else { err = db.Order("api_group").Find(&apiList).Error diff --git a/server/service/system/sys_auto_code.go b/server/service/system/sys_auto_code.go index d73e8b0c5e5d0680fdc5a6260c88b59faf081928..31e11a0e751458559114220bdb54373a6f8cfb4d 100644 --- a/server/service/system/sys_auto_code.go +++ b/server/service/system/sys_auto_code.go @@ -13,7 +13,6 @@ import ( "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/system" - "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" "github.com/flipped-aurora/gin-vue-admin/server/utils" "gorm.io/gorm" @@ -301,38 +300,12 @@ func (autoCodeService *AutoCodeService) GetAllTplFile(pathName string, fileList return fileList, err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: GetTables -//@description: 获取数据库的所有表名 -//@param: dbName string -//@return: err error, TableNames []request.TableReq - -func (autoCodeService *AutoCodeService) GetTables(dbName string) (err error, TableNames []request.TableReq) { - err = global.GVA_DB.Raw("select table_name as table_name from information_schema.tables where table_schema = ?", dbName).Scan(&TableNames).Error - return err, TableNames -} - -//@author: [piexlmax](https://github.com/piexlmax) -//@function: GetDB -//@description: 获取数据库的所有数据库名 -//@return: err error, DBNames []request.DBReq - -func (autoCodeService *AutoCodeService) GetDB() (err error, DBNames []request.DBReq) { - err = global.GVA_DB.Raw("SELECT SCHEMA_NAME AS `database` FROM INFORMATION_SCHEMA.SCHEMATA;").Scan(&DBNames).Error - return err, DBNames -} - //@author: [piexlmax](https://github.com/piexlmax) //@function: GetDB //@description: 获取指定数据库和指定数据表的所有字段名,类型值等 //@param: tableName string, dbName string //@return: err error, Columns []request.ColumnReq -func (autoCodeService *AutoCodeService) GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) { - err = global.GVA_DB.Raw("SELECT COLUMN_NAME column_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT column_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columns).Error - return err, Columns -} - func (autoCodeService *AutoCodeService) DropTable(tableName string) error { return global.GVA_DB.Exec("DROP TABLE " + tableName).Error } diff --git a/server/service/system/sys_auto_code_interface.go b/server/service/system/sys_auto_code_interface.go new file mode 100644 index 0000000000000000000000000000000000000000..1042def18ac089a6ad351fc868af77707d4aef53 --- /dev/null +++ b/server/service/system/sys_auto_code_interface.go @@ -0,0 +1,23 @@ +package system + +import ( + "github.com/flipped-aurora/gin-vue-admin/server/global" + "github.com/flipped-aurora/gin-vue-admin/server/model/system/response" +) + +type Database interface { + GetDB() (data []response.Db, err error) + GetTables(dbName string) (data []response.Table, err error) + GetColumn(tableName string, dbName string) (data []response.Column, err error) +} + +func (autoCodeService *AutoCodeService) Database() Database { + switch global.GVA_CONFIG.System.DbType { + case "mysql": + return AutoCodeMysql + case "pgsql": + return AutoCodePgsql + default: + return AutoCodeMysql + } +} diff --git a/server/service/system/sys_auto_code_mysql.go b/server/service/system/sys_auto_code_mysql.go new file mode 100644 index 0000000000000000000000000000000000000000..76e8f1d4c07eece4603aa16cb6d87125da5bb1fd --- /dev/null +++ b/server/service/system/sys_auto_code_mysql.go @@ -0,0 +1,55 @@ +package system + +import ( + "github.com/flipped-aurora/gin-vue-admin/server/global" + "github.com/flipped-aurora/gin-vue-admin/server/model/system/response" +) + +var AutoCodeMysql = new(autoCodeMysql) + +type autoCodeMysql struct{} + +// GetDB 获取数据库的所有数据库名 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (s *autoCodeMysql) GetDB() (data []response.Db, err error) { + var entities []response.Db + sql := "SELECT SCHEMA_NAME AS `database` FROM INFORMATION_SCHEMA.SCHEMATA;" + err = global.GVA_DB.Raw(sql).Scan(&entities).Error + return entities, err +} + +// GetTables 获取数据库的所有表名 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (s *autoCodeMysql) GetTables(dbName string) (data []response.Table, err error) { + var entities []response.Table + sql := `select table_name as table_name from information_schema.tables where table_schema = ?` + err = global.GVA_DB.Raw(sql, dbName).Scan(&entities).Error + return entities, err +} + +// GetColumn 获取指定数据库和指定数据表的所有字段名,类型值等 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (s *autoCodeMysql) GetColumn(tableName string, dbName string) (data []response.Column, err error) { + var entities []response.Column + sql := ` + SELECT COLUMN_NAME column_name, + DATA_TYPE data_type, + CASE DATA_TYPE + WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH + WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH + WHEN 'double' THEN CONCAT_WS(',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE) + WHEN 'decimal' THEN CONCAT_WS(',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE) + WHEN 'int' THEN c.NUMERIC_PRECISION + WHEN 'bigint' THEN c.NUMERIC_PRECISION + ELSE '' END AS data_type_long, + COLUMN_COMMENT column_comment + FROM INFORMATION_SCHEMA.COLUMNS c + WHERE table_name = ? + AND table_schema = ? + ` + err = global.GVA_DB.Raw(sql, tableName, dbName).Scan(&entities).Error + return entities, err +} diff --git a/server/service/system/sys_auto_code_pgsql.go b/server/service/system/sys_auto_code_pgsql.go new file mode 100644 index 0000000000000000000000000000000000000000..659b9e44a8c0d1876c6de60273d3aef8b924d602 --- /dev/null +++ b/server/service/system/sys_auto_code_pgsql.go @@ -0,0 +1,89 @@ +package system + +import ( + "github.com/flipped-aurora/gin-vue-admin/server/global" + "github.com/flipped-aurora/gin-vue-admin/server/model/system/response" + "github.com/pkg/errors" + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/logger" + "strings" +) + +var AutoCodePgsql = new(autoCodePgsql) + +type autoCodePgsql struct{} + +// GetDB 获取数据库的所有数据库名 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (a *autoCodePgsql) GetDB() (data []response.Db, err error) { + var entities []response.Db + sql := `SELECT datname as database FROM pg_database WHERE datistemplate = false` + err = global.GVA_DB.Raw(sql).Scan(&entities).Error + return entities, err +} + +// GetTables 获取数据库的所有表名 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (a *autoCodePgsql) GetTables(dbName string) (data []response.Table, err error) { + var entities []response.Table + sql := `select table_name as table_name from information_schema.tables where table_catalog = ? and table_schema = ?` + db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}) + if _err != nil { + return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表失败!", dbName) + } + err = db.Raw(sql, dbName, "public").Scan(&entities).Error + return entities, err +} + +// GetColumn 获取指定数据库和指定数据表的所有字段名,类型值等 +// Author [piexlmax](https://github.com/piexlmax) +// Author [SliverHorn](https://github.com/SliverHorn) +func (a *autoCodePgsql) GetColumn(tableName string, dbName string) (data []response.Column, err error) { + // todo 数据获取不全, 待完善sql + sql := ` + SELECT columns.COLUMN_NAME as column_name, + columns.DATA_TYPE as data_type, + CASE + columns.DATA_TYPE + WHEN 'text' THEN + concat_ws('', '', columns.CHARACTER_MAXIMUM_LENGTH) + WHEN 'varchar' THEN + concat_ws('', '', columns.CHARACTER_MAXIMUM_LENGTH) + WHEN 'smallint' THEN + concat_ws(',', columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE) + WHEN 'decimal' THEN + concat_ws(',', columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE) + WHEN 'integer' THEN + concat_ws('', '', columns.NUMERIC_PRECISION) + WHEN 'bigint' THEN + concat_ws('', '', columns.NUMERIC_PRECISION) + ELSE '' + END AS data_type_long, + (select description.description + from pg_description description + where description.objoid = (select attribute.attrelid + from pg_attribute attribute + where attribute.attrelid = + (select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME ) + and description.objsubid = (select attribute.attnum + from pg_attribute attribute + where attribute.attrelid = + (select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )) as column_comment + FROM INFORMATION_SCHEMA.COLUMNS columns + WHERE table_catalog = '@table_catalog' + and table_schema = 'public' + and table_name = '@table_name'; + ` + var entities []response.Column + db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}) + if _err != nil { + return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表(%s)失败!", dbName, tableName) + } + sql = strings.ReplaceAll(sql, "@table_catalog", dbName) + sql = strings.ReplaceAll(sql, "@table_name", tableName) + err = db.Raw(sql).Scan(&entities).Error + return entities, err +} diff --git a/server/service/system/sys_autocode_history.go b/server/service/system/sys_autocode_history.go index e338eaf2dd6f4345296fea868a50655b78015ed0..27785ba45fb5b66e9d80d7c6bde03c2726a76718 100644 --- a/server/service/system/sys_autocode_history.go +++ b/server/service/system/sys_autocode_history.go @@ -3,6 +3,7 @@ package system import ( "errors" "fmt" + "github.com/flipped-aurora/gin-vue-admin/server/model/system/response" "path/filepath" "strings" "time" @@ -17,19 +18,14 @@ import ( var RepeatErr = errors.New("重复创建") -type AutoCodeHistoryService struct { -} +type AutoCodeHistoryService struct{} var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService) -func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string) bool { - - var count int64 - global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and flag = 0", structName).Count(&count) - return count > 0 -} - -// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2 +// CreateAutoCodeHistory 创建代码生成器历史记录 +// RouterPath : RouterPath@RouterString;RouterPath2@RouterString2 +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error { return global.GVA_DB.Create(&system.SysAutoCodeHistory{ RequestMeta: meta, @@ -42,10 +38,29 @@ func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta }).Error } +// First 根据id获取代码生成器历史的数据 +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) +func (autoCodeHistoryService *AutoCodeHistoryService) First(info *request.GetById) (string, error) { + var meta string + return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").Where("id = ?", info.Uint()).First(&meta).Error +} + +// Repeat 检测重复 +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) +func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string) bool { + var count int64 + global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and flag = 0", structName).Count(&count) + return count > 0 +} + // RollBack 回滚 -func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error { +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) +func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.GetById) error { md := system.SysAutoCodeHistory{} - if err := global.GVA_DB.First(&md, id).Error; err != nil { + if err := global.GVA_DB.Where("id = ?", info.Uint()).First(&md).Error; err != nil { return err } // 清除API表 @@ -54,7 +69,7 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error { global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err)) } // 获取全部表名 - err, dbNames := AutoCodeServiceApp.GetTables(global.GVA_CONFIG.Mysql.Dbname) + dbNames, err := AutoCodeServiceApp.Database().GetTables(global.GVA_CONFIG.Mysql.Dbname) if err != nil { global.GVA_LOG.Error("ClearTag GetTables:", zap.Error(err)) } @@ -104,26 +119,25 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error { return global.GVA_DB.Save(&md).Error } -func (autoCodeHistoryService *AutoCodeHistoryService) GetMeta(id uint) (string, error) { - var meta string - return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").First(&meta, id).Error +// Delete 删除历史数据 +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) +func (autoCodeHistoryService *AutoCodeHistoryService) Delete(info *request.GetById) error { + return global.GVA_DB.Where("id = ?", info.Uint()).Delete(&system.SysAutoCodeHistory{}).Error } -// GetSysHistoryPage 获取系统历史数据 -func (autoCodeHistoryService *AutoCodeHistoryService) GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) { +// GetList 获取系统历史数据 +// Author [SliverHorn](https://github.com/SliverHorn) +// Author [songzhibin97](https://github.com/songzhibin97) +func (autoCodeHistoryService *AutoCodeHistoryService) GetList(info request.PageInfo) (list []response.AutoCodeHistory, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&system.SysAutoCodeHistory{}) - var fileLists []system.SysAutoCodeHistory + var entities []response.AutoCodeHistory err = db.Count(&total).Error if err != nil { - return + return nil, total, err } - err = db.Limit(limit).Offset(offset).Order("updated_at desc").Select("id,created_at,updated_at,struct_name,struct_cn_name,flag,table_name").Find(&fileLists).Error - return err, fileLists, total -} - -// DeletePage 删除历史数据 -func (autoCodeHistoryService *AutoCodeHistoryService) DeletePage(id uint) error { - return global.GVA_DB.Delete(&system.SysAutoCodeHistory{}, id).Error + err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&entities).Error + return entities, total, err } diff --git a/server/service/system/sys_initdb_mysql.go b/server/service/system/sys_initdb_mysql.go index b55eb85988d6891ae804840e45d92a9b18e84042..37cd21f0d9fc8589a92bb2402e4b6297cd2b63d6 100644 --- a/server/service/system/sys_initdb_mysql.go +++ b/server/service/system/sys_initdb_mysql.go @@ -24,7 +24,7 @@ func (initDBService *InitDBService) writeMysqlConfig(mysql config.Mysql) error { for k, v := range cs { global.GVA_VP.Set(k, v) } - global.GVA_VP.Set("jwt.signing-key", uuid.NewV4()) + global.GVA_VP.Set("jwt.signing-key", uuid.NewV4().String()) return global.GVA_VP.WriteConfig() } diff --git a/server/service/system/sys_initdb_pgsql.go b/server/service/system/sys_initdb_pgsql.go index 605f362ed2bcea61854bc9d541dfb746535b63dd..76234ae18bd50a03b0cc5938397b0df3372fbd0f 100644 --- a/server/service/system/sys_initdb_pgsql.go +++ b/server/service/system/sys_initdb_pgsql.go @@ -23,7 +23,7 @@ func (initDBService *InitDBService) writePgsqlConfig(pgsql config.Pgsql) error { for k, v := range cs { global.GVA_VP.Set(k, v) } - global.GVA_VP.Set("jwt.signing-key", uuid.NewV4()) + global.GVA_VP.Set("jwt.signing-key", uuid.NewV4().String()) return global.GVA_VP.WriteConfig() } @@ -69,7 +69,7 @@ func (initDBService *InitDBService) initPgsqlDB(conf request.InitDB) error { // initPgsqlData pgsql 初始化数据 // Author [SliverHorn](https://github.com/SliverHorn) func (initDBService *InitDBService) initPgsqlData() error { - return model.MysqlDataInitialize( + return model.PgsqlDataInitialize( system.Api, system.User, system.Casbin, diff --git a/web/src/core/gin-vue-admin.js b/web/src/core/gin-vue-admin.js index ab7498a223842a64fe499457733afa6106dd2b2b..4358a1731f5cdad12e355f4d6ab8bbbb417e76f7 100644 --- a/web/src/core/gin-vue-admin.js +++ b/web/src/core/gin-vue-admin.js @@ -10,7 +10,7 @@ export default { register(app) console.log(` 欢迎使用 Gin-Vue-Admin - 当前版本:V2.4.6 Apache + 当前版本:V2.4.6 Beta 加群方式:微信:shouzi_1994 QQ群:622360840 默认自动化文档地址:http://127.0.0.1:${import.meta.env.VITE_SERVER_PORT}/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:${import.meta.env.VITE_CLI_PORT}