修改,兼容go-admin sdk方案

This commit is contained in:
linwenxiang committed 2021-03-09 19:12:49 +08:00
1 parent c541d09076
commit 25d8364bf4
151 files changed
+578 -3525

No files matched your search

+8 -8
View File
@@ -1,14 +1,14 @@
package tools
import (
"go-admin/common/apis"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/common/apis"
)
// @Summary 分页列表数据 / page list data
@@ -27,14 +27,14 @@ func GetDBColumnList(c *gin.Context) {
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools2.StringToInt(size)
pageSize, err = pkg.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools2.StringToInt(index)
pageIndex, err = pkg.StringToInt(index)
}
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -42,9 +42,9 @@ func GetDBColumnList(c *gin.Context) {
}
data.TableName = c.Request.FormValue("tableName")
tools2.Assert(data.TableName == "", "table name cannot be empty!", 500)
pkg.Assert(data.TableName == "", "table name cannot be empty!", 500)
result, count, err := data.GetPage(db, pageSize, pageIndex)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
+8 -8
View File
@@ -1,15 +1,15 @@
package tools
import (
"go-admin/common/apis"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/config"
"go-admin/common/apis"
)
// @Summary 分页列表数据 / page list data
@@ -34,14 +34,14 @@ func GetDBTableList(c *gin.Context) {
}
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools2.StringToInt(size)
pageSize, err = pkg.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools2.StringToInt(index)
pageIndex, err = pkg.StringToInt(index)
}
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -50,7 +50,7 @@ func GetDBTableList(c *gin.Context) {
data.TableName = c.Request.FormValue("tableName")
result, count, err := data.GetPage(db, pageSize, pageIndex)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
+55 -55
View File
@@ -2,39 +2,39 @@ package tools
import (
"bytes"
"go-admin/common/apis"
"net/http"
"text/template"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/config"
"go-admin/common/apis"
)
func Preview(c *gin.Context) {
log := apis.GetRequestLogger(c)
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
id, err := pkg.StringToInt(c.Param("tableId"))
pkg.HasError(err, "", -1)
table.TableId = id
t1, err := template.ParseFiles("template/v4/model.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t2, err := template.ParseFiles("template/v4/no_actions/apis.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t3, err := template.ParseFiles("template/v4/js.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t4, err := template.ParseFiles("template/v4/vue.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t5, err := template.ParseFiles("template/v4/no_actions/router_check_role.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t6, err := template.ParseFiles("template/v4/dto.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -71,10 +71,10 @@ func Preview(c *gin.Context) {
func GenCodeV3(c *gin.Context) {
log := apis.GetRequestLogger(c)
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
id, err := pkg.StringToInt(c.Param("tableId"))
pkg.HasError(err, "", -1)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -103,26 +103,26 @@ func NOActionsGenV3(tab tools.SysTables) {
}
t1, err := template.ParseFiles(basePath + "model.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t2, err := template.ParseFiles(basePath + "no_actions/apis.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t3, err := template.ParseFiles(routerFile)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t4, err := template.ParseFiles(basePath + "js.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t5, err := template.ParseFiles(basePath + "vue.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t6, err := template.ParseFiles(basePath + "dto.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t7, err := template.ParseFiles(basePath + "no_actions/service.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
_ = pkg.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName)
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
@@ -138,13 +138,13 @@ func NOActionsGenV3(tab tools.SysTables) {
err = t6.Execute(&b6, tab)
var b7 bytes.Buffer
err = t7.Execute(&b7, tab)
tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
tools2.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+"/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
tools2.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.BusinessName+".go")
pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
pkg.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+"/"+tab.BusinessName+".go")
pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
pkg.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.BusinessName+".go")
}
@@ -157,21 +157,21 @@ func ActionsGenV3(tab tools.SysTables) {
}
t1, err := template.ParseFiles(basePath + "model.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t3, err := template.ParseFiles(routerFile)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t4, err := template.ParseFiles(basePath + "js.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t5, err := template.ParseFiles(basePath + "vue.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
t6, err := template.ParseFiles(basePath + "dto.go.template")
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
@@ -184,22 +184,22 @@ func ActionsGenV3(tab tools.SysTables) {
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
func GenMenuAndApi(c *gin.Context) {
log := apis.GetRequestLogger(c)
table := tools.SysTables{}
timeNow := tools2.GetCurrentTime()
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
timeNow := pkg.GetCurrentTime()
id, err := pkg.StringToInt(c.Param("tableId"))
pkg.HasError(err, "", -1)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
+27 -26
View File
@@ -1,16 +1,17 @@
package tools
import (
"go-admin/common/apis"
"gorm.io/gorm"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"gorm.io/gorm"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/common/apis"
)
// @Summary 分页列表数据
@@ -29,14 +30,14 @@ func GetSysTableList(c *gin.Context) {
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools2.StringToInt(size)
pageSize, err = pkg.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools2.StringToInt(index)
pageIndex, err = pkg.StringToInt(index)
}
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -46,7 +47,7 @@ func GetSysTableList(c *gin.Context) {
data.TBName = c.Request.FormValue("tableName")
data.TableComment = c.Request.FormValue("tableComment")
result, count, err := data.GetPage(db, pageSize, pageIndex)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
@@ -69,7 +70,7 @@ func GetSysTableList(c *gin.Context) {
// @Security Bearer
func GetSysTables(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -77,9 +78,9 @@ func GetSysTables(c *gin.Context) {
}
var data tools.SysTables
data.TableId, _ = tools2.StringToInt(c.Param("tableId"))
data.TableId, _ = pkg.StringToInt(c.Param("tableId"))
result, err := data.Get(db)
tools2.HasError(err, "抱歉未找到相关信息", -1)
pkg.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
@@ -92,7 +93,7 @@ func GetSysTables(c *gin.Context) {
func GetSysTablesInfo(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -104,7 +105,7 @@ func GetSysTablesInfo(c *gin.Context) {
data.TBName = c.Request.FormValue("tableName")
}
result, err := data.Get(db)
tools2.HasError(err, "抱歉未找到相关信息", -1)
pkg.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
@@ -117,7 +118,7 @@ func GetSysTablesInfo(c *gin.Context) {
func GetSysTablesTree(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -126,7 +127,7 @@ func GetSysTablesTree(c *gin.Context) {
var data tools.SysTables
result, err := data.GetTree(db)
tools2.HasError(err, "抱歉未找到相关信息", -1)
pkg.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
@@ -145,7 +146,7 @@ func GetSysTablesTree(c *gin.Context) {
// @Security Bearer
func InsertSysTable(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -158,7 +159,7 @@ func InsertSysTable(c *gin.Context) {
data, err := genTableInit(db, tablesList, i, c)
_, err = data.Create(db)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
}
var res app.Response
res.Msg = "添加成功!"
@@ -171,7 +172,7 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
var dbTable tools.DBTables
var dbColumn tools.DBColumns
data.TBName = tablesList[i]
data.CreateBy = tools2.GetUserIdStr(c)
data.CreateBy = user.GetUserIdStr(c)
dbTable.TableName = data.TBName
dbtable, err := dbTable.Get(tx)
@@ -190,7 +191,7 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
data.Crud = true
dbcolumn, err := dbColumn.GetList(tx)
data.CreateBy = tools2.GetUserIdStr(c)
data.CreateBy = user.GetUserIdStr(c)
data.TableComment = dbtable.TableComment
if dbtable.TableComment == "" {
data.TableComment = data.ClassName
@@ -279,19 +280,19 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
func UpdateSysTable(c *gin.Context) {
var data tools.SysTables
err := c.Bind(&data)
tools2.HasError(err, "数据解析失败", 500)
pkg.HasError(err, "数据解析失败", 500)
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
data.UpdateBy = tools2.GetUserIdStr(c)
data.UpdateBy = user.GetUserIdStr(c)
result, err := data.Update(db)
tools2.HasError(err, "", -1)
pkg.HasError(err, "", -1)
var res app.Response
res.Data = result
@@ -308,7 +309,7 @@ func UpdateSysTable(c *gin.Context) {
// @Router /api/v1/sys/tables/info/{tableId} [delete]
func DeleteSysTables(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := tools2.GetOrm(c)
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
@@ -316,9 +317,9 @@ func DeleteSysTables(c *gin.Context) {
}
var data tools.SysTables
IDS := tools2.IdsStrToIdsIntGroup("tableId", c)
IDS := pkg.IdsStrToIdsIntGroup("tableId", c)
_, err = data.BatchDelete(db, IDS)
tools2.HasError(err, "删除失败", 500)
pkg.HasError(err, "删除失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())