未验证 提交 458152ed 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

Merge pull request #811 from flipped-aurora/pgsqlDevelop

2.4.6 优化 && 修复
......@@ -7,8 +7,8 @@ import (
)
type ApiGroup struct {
ExampleApiGroup example.ApiGroup
SystemApiGroup system.ApiGroup
ExampleApiGroup example.ApiGroup
AutoCodeApiGroup autocode.ApiGroup
}
......
......@@ -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
......@@ -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
......@@ -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)
}
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)
}
......@@ -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
......
......@@ -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
}
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
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
}
......
package request
import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
type SysAutoHistory struct {
request.PageInfo
}
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"`
}
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"`
}
......@@ -2,7 +2,7 @@ package system
import "errors"
// 初始版本自动化代码工具
// AutoCodeStruct 初始版本自动化代码工具
type AutoCodeStruct struct {
StructName string `json:"structName"` // Struct名称
TableName string `json:"tableName"` // 表名
......
package example
type RouterGroup struct {
CustomerRouter
ExcelRouter
CustomerRouter
FileUploadAndDownloadRouter
}
......@@ -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
}
......@@ -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) // 创建自动化代码
}
}
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) // 获取回滚记录分页
}
}
......@@ -7,8 +7,8 @@ import (
)
type ServiceGroup struct {
ExampleServiceGroup example.ServiceGroup
SystemServiceGroup system.ServiceGroup
ExampleServiceGroup example.ServiceGroup
AutoCodeServiceGroup autocode.ServiceGroup
}
......
package example
type ServiceGroup struct {
FileUploadAndDownloadService
CustomerService
ExcelService
CustomerService
FileUploadAndDownloadService
}
......@@ -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
}
......@@ -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
......
......@@ -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
}
......
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
}
}
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
}
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
}
......@@ -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
}
......@@ -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()
}
......
......@@ -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,
......
......@@ -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}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册