mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]base模块提出
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"pandax/apps/develop/gen"
|
||||
"pandax/apps/develop/services"
|
||||
"pandax/base/ginx"
|
||||
)
|
||||
|
||||
type GenApi struct {
|
||||
@@ -17,8 +17,8 @@ type GenApi struct {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/gen/preview/{tableId} [get]
|
||||
// @Security X-TOKEN
|
||||
func (e *GenApi) Preview(rc *ginx.ReqCtx) {
|
||||
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||
func (e *GenApi) Preview(rc *restfulx.ReqCtx) {
|
||||
tableId := restfulx.PathParamInt(rc.GinCtx, "tableId")
|
||||
rc.ResData = gen.Preview(int64(tableId))
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ func (e *GenApi) Preview(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/gen/code/{tableId} [get]
|
||||
// @Security X-TOKEN
|
||||
func (e *GenApi) GenCode(rc *ginx.ReqCtx) {
|
||||
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||
func (e *GenApi) GenCode(rc *restfulx.ReqCtx) {
|
||||
tableId := restfulx.PathParamInt(rc.GinCtx, "tableId")
|
||||
gen.GenCode(int64(tableId))
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ func (e *GenApi) GenCode(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/gen/configure/{tableId} [get]
|
||||
// @Security X-TOKEN
|
||||
func (e *GenApi) GenConfigure(rc *ginx.ReqCtx) {
|
||||
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||
menuId := ginx.QueryInt(rc.GinCtx, "menuId", 0)
|
||||
func (e *GenApi) GenConfigure(rc *restfulx.ReqCtx) {
|
||||
tableId := restfulx.PathParamInt(rc.GinCtx, "tableId")
|
||||
menuId := restfulx.QueryInt(rc.GinCtx, "menuId", 0)
|
||||
gen.GenConfigure(tableId, menuId)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/apps/develop/gen"
|
||||
"pandax/apps/develop/services"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -22,9 +22,9 @@ type GenTableApi struct {
|
||||
// @Param pageNum query int false "pageNum / 页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/table/db/list [get]
|
||||
func (g *GenTableApi) GetDBTableList(rc *ginx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
func (g *GenTableApi) GetDBTableList(rc *restfulx.ReqCtx) {
|
||||
pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
tableName := rc.GinCtx.Query("tableName")
|
||||
list, total := g.GenTableApp.FindDbTablesListPage(pageNum, pageSize, entity.DBTables{TableName: tableName})
|
||||
rc.ResData = map[string]any{
|
||||
@@ -44,9 +44,9 @@ func (g *GenTableApi) GetDBTableList(rc *ginx.ReqCtx) {
|
||||
// @Param pageIndex query int false "pageIndex / 页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/table/list [get]
|
||||
func (g *GenTableApi) GetTablePage(rc *ginx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
func (g *GenTableApi) GetTablePage(rc *restfulx.ReqCtx) {
|
||||
pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
tableName := rc.GinCtx.Query("tableName")
|
||||
tableComment := rc.GinCtx.Query("tableComment")
|
||||
list, total := g.GenTableApp.FindListPage(pageNum, pageSize, entity.DevGenTable{TableName: tableName, TableComment: tableComment})
|
||||
@@ -65,8 +65,8 @@ func (g *GenTableApi) GetTablePage(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/table/info/{tableId} [get]
|
||||
// @Security Bearer
|
||||
func (g *GenTableApi) GetTableInfo(rc *ginx.ReqCtx) {
|
||||
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||
func (g *GenTableApi) GetTableInfo(rc *restfulx.ReqCtx) {
|
||||
tableId := restfulx.PathParamInt(rc.GinCtx, "tableId")
|
||||
result := g.GenTableApp.FindOne(entity.DevGenTable{TableId: int64(tableId)}, true)
|
||||
mp := make(map[string]any)
|
||||
mp["list"] = result.Columns
|
||||
@@ -81,7 +81,7 @@ func (g *GenTableApi) GetTableInfo(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/table/info/tableName [get]
|
||||
// @Security X-TOKEN
|
||||
func (g *GenTableApi) GetTableInfoByName(rc *ginx.ReqCtx) {
|
||||
func (g *GenTableApi) GetTableInfoByName(rc *restfulx.ReqCtx) {
|
||||
tableName := rc.GinCtx.Query("tableName")
|
||||
result := g.GenTableApp.FindOne(entity.DevGenTable{TableName: tableName}, true)
|
||||
mp := make(map[string]any)
|
||||
@@ -96,7 +96,7 @@ func (g *GenTableApi) GetTableInfoByName(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /develop/code/table/tableTree [get]
|
||||
// @Security X-TOKEN
|
||||
func (g *GenTableApi) GetTableTree(rc *ginx.ReqCtx) {
|
||||
func (g *GenTableApi) GetTableTree(rc *restfulx.ReqCtx) {
|
||||
rc.ResData = g.GenTableApp.FindTree(entity.DevGenTable{})
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (g *GenTableApi) GetTableTree(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /develop/code/table [post]
|
||||
// @Security Bearer
|
||||
func (g *GenTableApi) Insert(rc *ginx.ReqCtx) {
|
||||
func (g *GenTableApi) Insert(rc *restfulx.ReqCtx) {
|
||||
tablesList := strings.Split(rc.GinCtx.Query("tables"), ",")
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
@@ -136,9 +136,9 @@ func (g *GenTableApi) Insert(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /develop/code/table [put]
|
||||
// @Security Bearer
|
||||
func (g *GenTableApi) Update(rc *ginx.ReqCtx) {
|
||||
func (g *GenTableApi) Update(rc *restfulx.ReqCtx) {
|
||||
var data entity.DevGenTable
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
g.GenTableApp.Update(data)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (g *GenTableApi) Update(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
||||
// @Router /develop/code/table/{tableId} [delete]
|
||||
func (g *GenTableApi) Delete(rc *ginx.ReqCtx) {
|
||||
func (g *GenTableApi) Delete(rc *restfulx.ReqCtx) {
|
||||
tableIds := rc.GinCtx.Param("tableId")
|
||||
group := utils.IdsStrToIdsIntGroup(tableIds)
|
||||
g.GenTableApp.Delete(group)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package entity
|
||||
|
||||
import "pandax/base/model"
|
||||
import "github.com/XM-GO/PandaKit/model"
|
||||
|
||||
type DevGenTable struct {
|
||||
TableId int64 `gorm:"primaryKey;autoIncrement" json:"tableId"` // 编号
|
||||
|
||||
@@ -3,6 +3,8 @@ package gen
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"github.com/kakuilan/kgo"
|
||||
"log"
|
||||
"os"
|
||||
@@ -10,8 +12,6 @@ import (
|
||||
"pandax/apps/develop/services"
|
||||
sysEntity "pandax/apps/system/entity"
|
||||
sysServices "pandax/apps/system/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"pandax/apps/develop/api"
|
||||
"pandax/apps/develop/services"
|
||||
"pandax/base/ginx"
|
||||
)
|
||||
|
||||
func InitGenRouter(router *gin.RouterGroup) {
|
||||
@@ -15,14 +15,14 @@ func InitGenRouter(router *gin.RouterGroup) {
|
||||
gen := router.Group("gen")
|
||||
|
||||
gen.GET("preview/:tableId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取生成代码视图").Handle(genApi.Preview)
|
||||
restfulx.NewReqCtx(c).WithLog("获取生成代码视图").Handle(genApi.Preview)
|
||||
})
|
||||
|
||||
gen.GET("code/:tableId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("生成代码").Handle(genApi.GenCode)
|
||||
restfulx.NewReqCtx(c).WithLog("生成代码").Handle(genApi.GenCode)
|
||||
})
|
||||
|
||||
gen.GET("configure/:tableId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("生成配置").Handle(genApi.GenConfigure)
|
||||
restfulx.NewReqCtx(c).WithLog("生成配置").Handle(genApi.GenConfigure)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"pandax/apps/develop/api"
|
||||
"pandax/apps/develop/services"
|
||||
"pandax/base/ginx"
|
||||
)
|
||||
|
||||
func InitGenTableRouter(router *gin.RouterGroup) {
|
||||
@@ -15,34 +15,34 @@ func InitGenTableRouter(router *gin.RouterGroup) {
|
||||
gen := router.Group("table")
|
||||
|
||||
gen.GET("/db/list", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取数据库列表").Handle(genApi.GetDBTableList)
|
||||
restfulx.NewReqCtx(c).WithLog("获取数据库列表").Handle(genApi.GetDBTableList)
|
||||
})
|
||||
|
||||
gen.GET("list", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取表列表").Handle(genApi.GetTablePage)
|
||||
restfulx.NewReqCtx(c).WithLog("获取表列表").Handle(genApi.GetTablePage)
|
||||
})
|
||||
|
||||
gen.GET("/info/tableName", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取表信息By tableName").Handle(genApi.GetTableInfoByName)
|
||||
restfulx.NewReqCtx(c).WithLog("获取表信息By tableName").Handle(genApi.GetTableInfoByName)
|
||||
})
|
||||
|
||||
gen.GET("info/:tableId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取表信息").Handle(genApi.GetTableInfo)
|
||||
restfulx.NewReqCtx(c).WithLog("获取表信息").Handle(genApi.GetTableInfo)
|
||||
})
|
||||
|
||||
gen.GET("tableTree", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("获取表树").Handle(genApi.GetTableTree)
|
||||
restfulx.NewReqCtx(c).WithLog("获取表树").Handle(genApi.GetTableTree)
|
||||
})
|
||||
|
||||
gen.POST("", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("新增表").Handle(genApi.Insert)
|
||||
restfulx.NewReqCtx(c).WithLog("新增表").Handle(genApi.Insert)
|
||||
})
|
||||
|
||||
gen.PUT("", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("修改表").Handle(genApi.Update)
|
||||
restfulx.NewReqCtx(c).WithLog("修改表").Handle(genApi.Update)
|
||||
})
|
||||
|
||||
gen.DELETE(":tableId", func(c *gin.Context) {
|
||||
ginx.NewReqCtx(c).WithLog("删除表").Handle(genApi.Delete)
|
||||
restfulx.NewReqCtx(c).WithLog("删除表").Handle(genApi.Delete)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user