mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[修复]代码生成
This commit is contained in:
@@ -34,3 +34,16 @@ func (e *GenApi) GenCode(rc *ctx.ReqCtx) {
|
|||||||
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||||
gen.GenCode(int64(tableId))
|
gen.GenCode(int64(tableId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary 配置生成
|
||||||
|
// @Description 生成API和菜单
|
||||||
|
// @Tags 工具 / 生成工具
|
||||||
|
// @Param tableId path int true "tableId"
|
||||||
|
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||||
|
// @Router /develop/code/gen/configure/{tableId} [get]
|
||||||
|
// @Security X-TOKEN
|
||||||
|
func (e *GenApi) GenConfigure(rc *ctx.ReqCtx) {
|
||||||
|
tableId := ginx.PathParamInt(rc.GinCtx, "tableId")
|
||||||
|
menuId := ginx.QueryInt(rc.GinCtx, "menuId", 0)
|
||||||
|
gen.GenConfigure(tableId, menuId)
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ type DevGenTable struct {
|
|||||||
BusinessName string `gorm:"business_name" json:"businessName"` // 生成业务名
|
BusinessName string `gorm:"business_name" json:"businessName"` // 生成业务名
|
||||||
FunctionName string `gorm:"function_name" json:"functionName"` // 生成功能名
|
FunctionName string `gorm:"function_name" json:"functionName"` // 生成功能名
|
||||||
FunctionAuthor string `gorm:"function_author" json:"functionAuthor"` // 生成功能作者
|
FunctionAuthor string `gorm:"function_author" json:"functionAuthor"` // 生成功能作者
|
||||||
TreeCode string `gorm:"tree_code" json:"treeCode"`
|
Options string `gorm:"options" json:"options"` // 其它生成选项
|
||||||
TreeParentCode string `gorm:"tree_parent_code" json:"treeParentCode"`
|
Remark string `gorm:"remark" json:"remark"` // 备注
|
||||||
TreeName string `gorm:"tree_name" json:"treeName"`
|
|
||||||
Options string `gorm:"options" json:"options"` // 其它生成选项
|
|
||||||
Remark string `gorm:"remark" json:"remark"` // 备注
|
|
||||||
PkColumn string `gorm:"pk_column;" json:"pkColumn"`
|
PkColumn string `gorm:"pk_column;" json:"pkColumn"`
|
||||||
PkGoField string `gorm:"pk_go_field" json:"pkGoField"`
|
PkGoField string `gorm:"pk_go_field" json:"pkGoField"`
|
||||||
PkJsonField string `gorm:"pk_json_field" json:"pkJsonField"`
|
PkJsonField string `gorm:"pk_json_field" json:"pkJsonField"`
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ package gen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/kakuilan/kgo"
|
"github.com/kakuilan/kgo"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"pandax/apps/develop/entity"
|
"pandax/apps/develop/entity"
|
||||||
"pandax/apps/develop/services"
|
"pandax/apps/develop/services"
|
||||||
|
sysEntity "pandax/apps/system/entity"
|
||||||
|
sysServices "pandax/apps/system/services"
|
||||||
"pandax/base/biz"
|
"pandax/base/biz"
|
||||||
"pandax/base/config"
|
"pandax/base/config"
|
||||||
"pandax/base/global"
|
"pandax/base/global"
|
||||||
@@ -411,8 +414,8 @@ func GenCode(tableId int64) {
|
|||||||
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/router/", os.ModePerm)
|
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/router/", os.ModePerm)
|
||||||
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/services/", os.ModePerm)
|
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/services/", os.ModePerm)
|
||||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/", os.ModePerm)
|
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/", os.ModePerm)
|
||||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.ModuleName+"/", os.ModePerm)
|
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/", os.ModePerm)
|
||||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.ModuleName+"/"+"component"+"/", os.ModePerm)
|
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/", os.ModePerm)
|
||||||
|
|
||||||
var b1 bytes.Buffer
|
var b1 bytes.Buffer
|
||||||
err = t1.Execute(&b1, tab)
|
err = t1.Execute(&b1, tab)
|
||||||
@@ -433,7 +436,105 @@ func GenCode(tableId int64) {
|
|||||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/services/"+tab.TableName+".go", b2.Bytes())
|
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/services/"+tab.TableName+".go", b2.Bytes())
|
||||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/api/"+tab.TableName+".go", b3.Bytes())
|
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/api/"+tab.TableName+".go", b3.Bytes())
|
||||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/router/"+tab.TableName+".go", b4.Bytes())
|
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/router/"+tab.TableName+".go", b4.Bytes())
|
||||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.ModuleName+".js", b5.Bytes())
|
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.BusinessName+".js", b5.Bytes())
|
||||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.ModuleName+"/index.vue", b6.Bytes())
|
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/index.vue", b6.Bytes())
|
||||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.ModuleName+"/"+"component"+"/editModule.vue", b7.Bytes())
|
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/editModule.vue", b7.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenConfigure 生成菜单,api
|
||||||
|
func GenConfigure(tableId, parentId int) {
|
||||||
|
tab := services.DevGenTableModelDao.FindOne(entity.DevGenTable{TableId: int64(tableId)}, false)
|
||||||
|
|
||||||
|
//生成菜单 一个菜单 三个按钮
|
||||||
|
component := "Layout"
|
||||||
|
if parentId != 0 {
|
||||||
|
component = fmt.Sprintf("/%s/%s/index", tab.PackageName, tab.BusinessName)
|
||||||
|
}
|
||||||
|
menu := sysEntity.SysMenu{
|
||||||
|
ParentId: int64(parentId),
|
||||||
|
MenuName: tab.TableComment,
|
||||||
|
MenuType: "C",
|
||||||
|
Sort: 1,
|
||||||
|
Icon: "elementSetting",
|
||||||
|
Path: fmt.Sprintf("/%s/%s", tab.PackageName, tab.BusinessName),
|
||||||
|
Component: component,
|
||||||
|
IsIframe: "1",
|
||||||
|
IsHide: "0",
|
||||||
|
IsKeepAlive: "1",
|
||||||
|
IsAffix: "1",
|
||||||
|
Permission: fmt.Sprintf("%s:%s:list", tab.PackageName, tab.BusinessName),
|
||||||
|
Status: "0",
|
||||||
|
CreateBy: "admin",
|
||||||
|
}
|
||||||
|
insert := sysServices.SysMenuModelDao.Insert(menu)
|
||||||
|
log.Println("insert", insert.MenuId)
|
||||||
|
//新增按钮
|
||||||
|
menuA := sysEntity.SysMenu{
|
||||||
|
ParentId: insert.MenuId,
|
||||||
|
MenuName: "新增" + tab.TableComment,
|
||||||
|
MenuType: "F",
|
||||||
|
Sort: 1,
|
||||||
|
Permission: fmt.Sprintf("%s:%s:add", tab.PackageName, tab.BusinessName),
|
||||||
|
Status: "0",
|
||||||
|
CreateBy: "admin",
|
||||||
|
}
|
||||||
|
go sysServices.SysMenuModelDao.Insert(menuA)
|
||||||
|
//修改按钮
|
||||||
|
menuE := sysEntity.SysMenu{
|
||||||
|
ParentId: insert.MenuId,
|
||||||
|
MenuName: "修改" + tab.TableComment,
|
||||||
|
MenuType: "F",
|
||||||
|
Sort: 2,
|
||||||
|
Permission: fmt.Sprintf("%s:%s:edit", tab.PackageName, tab.BusinessName),
|
||||||
|
Status: "0",
|
||||||
|
CreateBy: "admin",
|
||||||
|
}
|
||||||
|
go sysServices.SysMenuModelDao.Insert(menuE)
|
||||||
|
//删除按钮
|
||||||
|
menuD := sysEntity.SysMenu{
|
||||||
|
ParentId: insert.MenuId,
|
||||||
|
MenuName: "删除" + tab.TableComment,
|
||||||
|
MenuType: "F",
|
||||||
|
Sort: 3,
|
||||||
|
Permission: fmt.Sprintf("%s:%s:delete", tab.PackageName, tab.BusinessName),
|
||||||
|
Status: "0",
|
||||||
|
CreateBy: "admin",
|
||||||
|
}
|
||||||
|
go sysServices.SysMenuModelDao.Insert(menuD)
|
||||||
|
//生成api
|
||||||
|
apiL := sysEntity.SysApi{
|
||||||
|
Path: fmt.Sprintf("/%s/%s/list", tab.PackageName, tab.BusinessName),
|
||||||
|
Description: fmt.Sprintf("查询%s列表(分页)", tab.TableComment),
|
||||||
|
ApiGroup: tab.BusinessName,
|
||||||
|
Method: "GET",
|
||||||
|
}
|
||||||
|
go sysServices.SysApiModelDao.Insert(apiL)
|
||||||
|
apiG := sysEntity.SysApi{
|
||||||
|
Path: fmt.Sprintf("/%s/%s/:%s", tab.PackageName, tab.BusinessName, tab.PkJsonField),
|
||||||
|
Description: fmt.Sprintf("获取%s信息", tab.TableComment),
|
||||||
|
ApiGroup: tab.BusinessName,
|
||||||
|
Method: "GET",
|
||||||
|
}
|
||||||
|
go sysServices.SysApiModelDao.Insert(apiG)
|
||||||
|
apiA := sysEntity.SysApi{
|
||||||
|
Path: fmt.Sprintf("/%s/%s", tab.PackageName, tab.BusinessName),
|
||||||
|
Description: fmt.Sprintf("添加%s信息", tab.TableComment),
|
||||||
|
ApiGroup: tab.BusinessName,
|
||||||
|
Method: "POST",
|
||||||
|
}
|
||||||
|
go sysServices.SysApiModelDao.Insert(apiA)
|
||||||
|
apiE := sysEntity.SysApi{
|
||||||
|
Path: fmt.Sprintf("/%s/%s", tab.PackageName, tab.BusinessName),
|
||||||
|
Description: fmt.Sprintf("修改%s信息", tab.TableComment),
|
||||||
|
ApiGroup: tab.BusinessName,
|
||||||
|
Method: "PUT",
|
||||||
|
}
|
||||||
|
go sysServices.SysApiModelDao.Insert(apiE)
|
||||||
|
apiD := sysEntity.SysApi{
|
||||||
|
Path: fmt.Sprintf("/%s/%s/:%s", tab.PackageName, tab.BusinessName, tab.PkJsonField),
|
||||||
|
Description: fmt.Sprintf("删除%s信息", tab.TableComment),
|
||||||
|
ApiGroup: tab.BusinessName,
|
||||||
|
Method: "DELETE",
|
||||||
|
}
|
||||||
|
go sysServices.SysApiModelDao.Insert(apiD)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ func InitGenRouter(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
genConfigureLog := ctx.NewLogInfo("生成配置")
|
genConfigureLog := ctx.NewLogInfo("生成配置")
|
||||||
gen.GET("configure/:tableId", func(c *gin.Context) {
|
gen.GET("configure/:tableId", func(c *gin.Context) {
|
||||||
ctx.NewReqCtxWithGin(c).WithLog(genConfigureLog).Handle(genApi.GenCode)
|
ctx.NewReqCtxWithGin(c).WithLog(genConfigureLog).Handle(genApi.GenConfigure)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"pandax/base/config"
|
"pandax/base/config"
|
||||||
"pandax/base/global"
|
"pandax/base/global"
|
||||||
"pandax/base/utils"
|
"pandax/base/utils"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +177,7 @@ func (m *devGenTableModelImpl) Update(data entity.DevGenTable) *entity.DevGenTab
|
|||||||
tableMap := make(map[string]*entity.DevGenTable)
|
tableMap := make(map[string]*entity.DevGenTable)
|
||||||
if len(tableNames) > 0 {
|
if len(tableNames) > 0 {
|
||||||
err = global.Db.Table(m.table).Where("table_name in (?)", tableNames).Find(&tables).Error
|
err = global.Db.Table(m.table).Where("table_name in (?)", tableNames).Find(&tables).Error
|
||||||
biz.ErrIsNil(err, err.Error())
|
biz.ErrIsNil(err, "关联表不存在")
|
||||||
for i := range tables {
|
for i := range tables {
|
||||||
tableMap[tables[i].TableName] = &tables[i]
|
tableMap[tables[i].TableName] = &tables[i]
|
||||||
}
|
}
|
||||||
@@ -189,17 +188,9 @@ func (m *devGenTableModelImpl) Update(data entity.DevGenTable) *entity.DevGenTab
|
|||||||
t, ok := tableMap[data.Columns[i].LinkTableName]
|
t, ok := tableMap[data.Columns[i].LinkTableName]
|
||||||
if ok {
|
if ok {
|
||||||
data.Columns[i].LinkTableClass = t.ClassName
|
data.Columns[i].LinkTableClass = t.ClassName
|
||||||
data.Columns[i].LinkTablePackage = t.ModuleName
|
data.Columns[i].LinkTablePackage = t.PackageName
|
||||||
} else {
|
data.Columns[i].LinkLabelId = t.PkColumn
|
||||||
tableNameList := strings.Split(data.Columns[i].LinkTableName, "_")
|
data.Columns[i].LinkLabelName = t.PkGoField
|
||||||
data.Columns[i].LinkTableClass = ""
|
|
||||||
data.Columns[i].LinkTablePackage = ""
|
|
||||||
for a := 0; a < len(tableNameList); a++ {
|
|
||||||
strStart := string([]byte(tableNameList[a])[:1])
|
|
||||||
strEnd := string([]byte(tableNameList[a])[1:])
|
|
||||||
data.Columns[i].LinkTableClass += strings.ToUpper(strStart) + strEnd
|
|
||||||
data.Columns[i].LinkTablePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DevTableColumnModelDao.Update(data.Columns[i])
|
DevTableColumnModelDao.Update(data.Columns[i])
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type SysTenantsApi struct {
|
|||||||
// @Param pageSize query int false "页条数"
|
// @Param pageSize query int false "页条数"
|
||||||
// @Param pageNum query int false "页码"
|
// @Param pageNum query int false "页码"
|
||||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||||
// @Router /admin/sysTenants/list [get]
|
// @Router /admin/tenant/list [get]
|
||||||
// @Security
|
// @Security
|
||||||
func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) {
|
func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) {
|
||||||
data := entity.SysTenants{}
|
data := entity.SysTenants{}
|
||||||
@@ -44,7 +44,7 @@ func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) {
|
|||||||
// @Tags SysTenants
|
// @Tags SysTenants
|
||||||
// @Param tenantId path int true "tenantId"
|
// @Param tenantId path int true "tenantId"
|
||||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||||
// @Router /admin/sysTenants/{tenantId} [get]
|
// @Router /admin/tenant/{tenantId} [get]
|
||||||
// @Security
|
// @Security
|
||||||
func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) {
|
func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) {
|
||||||
tenantId := ginx.PathParamInt(rc.GinCtx, "tenantId")
|
tenantId := ginx.PathParamInt(rc.GinCtx, "tenantId")
|
||||||
@@ -59,7 +59,7 @@ func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) {
|
|||||||
// @Param data body entity.SysTenants true "data"
|
// @Param data body entity.SysTenants true "data"
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||||
// @Router /admin/sysTenants [post]
|
// @Router /admin/tenant [post]
|
||||||
// @Security X-TOKEN
|
// @Security X-TOKEN
|
||||||
func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) {
|
func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) {
|
||||||
var data entity.SysTenants
|
var data entity.SysTenants
|
||||||
@@ -76,7 +76,7 @@ func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) {
|
|||||||
// @Param data body entity.SysTenants true "body"
|
// @Param data body entity.SysTenants true "body"
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||||
// @Router /admin/sysTenants [put]
|
// @Router /admin/tenant [put]
|
||||||
// @Security X-TOKEN
|
// @Security X-TOKEN
|
||||||
func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) {
|
func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) {
|
||||||
var data entity.SysTenants
|
var data entity.SysTenants
|
||||||
@@ -91,9 +91,8 @@ func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) {
|
|||||||
// @Param tenantId path string true "tenantId"
|
// @Param tenantId path string true "tenantId"
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||||
// @Router /admin/sysTenants/{tenantId} [delete]
|
// @Router /admin/tenant/{tenantId} [delete]
|
||||||
func (p *SysTenantsApi) DeleteSysTenants(rc *ctx.ReqCtx) {
|
func (p *SysTenantsApi) DeleteSysTenants(rc *ctx.ReqCtx) {
|
||||||
|
|
||||||
tenantId := rc.GinCtx.Param("tenantId")
|
tenantId := rc.GinCtx.Param("tenantId")
|
||||||
tenantIds := utils.IdsStrToIdsIntGroup(tenantId)
|
tenantIds := utils.IdsStrToIdsIntGroup(tenantId)
|
||||||
p.SysTenantsApp.Delete(tenantIds)
|
p.SysTenantsApp.Delete(tenantIds)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func InitApiRouter(router *gin.RouterGroup) {
|
func InitApiRouter(router *gin.RouterGroup) {
|
||||||
s := &api.SystemApiApi{
|
s := &api.SystemApiApi{
|
||||||
ApiApp: services.SysSysApiModelDao,
|
ApiApp: services.SysApiModelDao,
|
||||||
}
|
}
|
||||||
api := router.Group("api")
|
api := router.Group("api")
|
||||||
|
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ type (
|
|||||||
Delete(ids []int64)
|
Delete(ids []int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
sysSysApiModelImpl struct {
|
sysApiModelImpl struct {
|
||||||
table string
|
table string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var SysSysApiModelDao SysApiModel = &sysSysApiModelImpl{
|
var SysApiModelDao SysApiModel = &sysApiModelImpl{
|
||||||
table: `sys_apis`,
|
table: `sys_apis`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) Insert(api entity.SysApi) *entity.SysApi {
|
func (m *sysApiModelImpl) Insert(api entity.SysApi) *entity.SysApi {
|
||||||
err := global.Db.Table(m.table).Where("path = ? AND method = ?", api.Path, api.Method).First(&entity.SysApi{}).Error
|
err := global.Db.Table(m.table).Where("path = ? AND method = ?", api.Path, api.Method).First(&entity.SysApi{}).Error
|
||||||
biz.IsTrue(errors.Is(err, gorm.ErrRecordNotFound), "存在相同api")
|
biz.IsTrue(errors.Is(err, gorm.ErrRecordNotFound), "存在相同api")
|
||||||
err = global.Db.Table(m.table).Create(&api).Error
|
err = global.Db.Table(m.table).Create(&api).Error
|
||||||
@@ -36,14 +36,14 @@ func (m *sysSysApiModelImpl) Insert(api entity.SysApi) *entity.SysApi {
|
|||||||
return &api
|
return &api
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) FindOne(id int64) (resData *entity.SysApi) {
|
func (m *sysApiModelImpl) FindOne(id int64) (resData *entity.SysApi) {
|
||||||
resData = new(entity.SysApi)
|
resData = new(entity.SysApi)
|
||||||
err := global.Db.Table(m.table).Where("id = ?", id).First(&resData).Error
|
err := global.Db.Table(m.table).Where("id = ?", id).First(&resData).Error
|
||||||
biz.ErrIsNil(err, "查询Api失败")
|
biz.ErrIsNil(err, "查询Api失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) FindListPage(page, pageSize int, data entity.SysApi) (*[]entity.SysApi, int64) {
|
func (m *sysApiModelImpl) FindListPage(page, pageSize int, data entity.SysApi) (*[]entity.SysApi, int64) {
|
||||||
list := make([]entity.SysApi, 0)
|
list := make([]entity.SysApi, 0)
|
||||||
var total int64 = 0
|
var total int64 = 0
|
||||||
offset := pageSize * (page - 1)
|
offset := pageSize * (page - 1)
|
||||||
@@ -73,7 +73,7 @@ func (m *sysSysApiModelImpl) FindListPage(page, pageSize int, data entity.SysApi
|
|||||||
return &list, total
|
return &list, total
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) FindList(data entity.SysApi) *[]entity.SysApi {
|
func (m *sysApiModelImpl) FindList(data entity.SysApi) *[]entity.SysApi {
|
||||||
list := make([]entity.SysApi, 0)
|
list := make([]entity.SysApi, 0)
|
||||||
db := global.Db.Table(m.table)
|
db := global.Db.Table(m.table)
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ func (m *sysSysApiModelImpl) FindList(data entity.SysApi) *[]entity.SysApi {
|
|||||||
return &list
|
return &list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) Update(api entity.SysApi) *entity.SysApi {
|
func (m *sysApiModelImpl) Update(api entity.SysApi) *entity.SysApi {
|
||||||
var oldA entity.SysApi
|
var oldA entity.SysApi
|
||||||
err := global.Db.Table(m.table).Where("id = ?", api.Id).First(&oldA).Error
|
err := global.Db.Table(m.table).Where("id = ?", api.Id).First(&oldA).Error
|
||||||
biz.ErrIsNil(err, "【修改api】查询api失败")
|
biz.ErrIsNil(err, "【修改api】查询api失败")
|
||||||
@@ -113,7 +113,7 @@ func (m *sysSysApiModelImpl) Update(api entity.SysApi) *entity.SysApi {
|
|||||||
return &api
|
return &api
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *sysSysApiModelImpl) Delete(ids []int64) {
|
func (m *sysApiModelImpl) Delete(ids []int64) {
|
||||||
err := global.Db.Table(m.table).Delete(&entity.SysApi{}, "id in (?)", ids).Error
|
err := global.Db.Table(m.table).Delete(&entity.SysApi{}, "id in (?)", ids).Error
|
||||||
biz.ErrIsNil(err, "删除配置信息失败")
|
biz.ErrIsNil(err, "删除配置信息失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ var SysMenuModelDao SysMenuModel = &sysMenuModelImpl{
|
|||||||
func (m *sysMenuModelImpl) Insert(data entity.SysMenu) *entity.SysMenu {
|
func (m *sysMenuModelImpl) Insert(data entity.SysMenu) *entity.SysMenu {
|
||||||
err := global.Db.Table(m.table).Create(&data).Error
|
err := global.Db.Table(m.table).Create(&data).Error
|
||||||
biz.ErrIsNil(err, "添加菜单失败")
|
biz.ErrIsNil(err, "添加菜单失败")
|
||||||
//m.InitPaths(&data)
|
|
||||||
return &data
|
return &data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package api
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// 生成日期:{{.CreatedAt}}
|
// 生成日期:{{.CreatedAt}}
|
||||||
// 生成路径: apps/{{.PackageName}}/api/{{.TableName}}.go
|
// 生成路径: apps/{{.PackageName}}/api/{{.TableName}}.go
|
||||||
|
|||||||
@@ -14,8 +14,15 @@ package entity
|
|||||||
{{if $hasGTime -}}import "time"{{- end }}
|
{{if $hasGTime -}}import "time"{{- end }}
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
{{range $index, $column := .Columns}}
|
{{- range $index, $column := .Columns}}
|
||||||
{{if eq $column.IsPk "1"}} {{$column.GoField}} {{if eq $column.GoType "Time"}}time.Time{{else}}{{$column.GoType}}{{end}} `gorm:"primary_key;{{if eq $column.IsIncrement "1"}}AUTO_INCREMENT{{end}}" json:"{{$column.JsonField}}"` // {{$column.ColumnComment}} {{else}} {{$column.GoField}} {{if eq $column.GoType "Time"}}time.Time{{else}}{{$column.GoType}}{{end}} `gorm:"{{$column.ColumnName}};type:{{$column.ColumnType}};comment:{{$column.ColumnComment}}" json:"{{$column.JsonField}}" {{if eq $column.IsRequired "1"}}binding:"required"{{end}}` // {{$column.ColumnComment}} {{end}}
|
{{- if eq $column.IsPk "1" }}
|
||||||
|
{{$column.GoField}} {{if eq $column.GoType "Time"}}time.Time{{else}}{{$column.GoType}}{{end}} `gorm:"primary_key;{{if eq $column.IsIncrement "1"}}AUTO_INCREMENT{{end}}" json:"{{$column.JsonField}}"` // {{$column.ColumnComment}}
|
||||||
|
{{- else if ne $column.LinkTableName ""}}
|
||||||
|
{{$column.GoField}} {{if eq $column.GoType "Time"}}time.Time{{else}}{{$column.GoType}}{{end}} `gorm:"{{$column.ColumnName}};type:{{$column.ColumnType}};comment:{{$column.ColumnComment}}" json:"{{$column.JsonField}}"`
|
||||||
|
{{$column.LinkTableClass}} {{$column.LinkTableClass}} `json:"{{$column.LinkTablePackage}}" gorm:"foreignKey:{{$column.LinkLabelName}};references:{{$column.GoField}};"`
|
||||||
|
{{- else }}
|
||||||
|
{{$column.GoField}} {{if eq $column.GoType "Time"}}time.Time{{else}}{{$column.GoType}}{{end}} `gorm:"{{$column.ColumnName}};type:{{$column.ColumnType}};comment:{{$column.ColumnComment}}" json:"{{$column.JsonField}}" {{if eq $column.IsRequired "1"}}binding:"required"{{- end }}` // {{$column.ColumnComment}}
|
||||||
|
{{- end -}}
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ func (m *{{.BusinessName}}ModelImpl) FindListPage(page, pageSize int, data entit
|
|||||||
{{- if eq $column.ColumnName "delete_time" }}
|
{{- if eq $column.ColumnName "delete_time" }}
|
||||||
db.Where("delete_time IS NULL")
|
db.Where("delete_time IS NULL")
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- if ne $column.LinkTableName "" }}
|
||||||
|
db.Preload("{{$column.LinkTableClass}}")
|
||||||
|
{{- end -}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
err := db.Count(&total).Error
|
err := db.Count(&total).Error
|
||||||
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||||
|
|||||||
Reference in New Issue
Block a user