pixel
5 years ago
8 changed files with 515 additions and 32 deletions
-
84QMPlusServer/autoCode/fe/autocode/api/api.js
-
118QMPlusServer/autoCode/te/autocode/api/api.go
-
52QMPlusServer/autoCode/te/autocode/model/model.go
-
18QMPlusServer/autoCode/te/autocode/router/router.go
-
82QMPlusServer/model/autoCodeModel/autoCode.go
-
84QMPlusServer/tpl/fe/api.js.tpl
-
91QMPlusServer/tpl/te/api.go.tpl
-
18QMPlusServer/tpl/te/router.go.tpl
@ -0,0 +1,84 @@ |
|||
import service from '@/utils/request' |
|||
|
|||
// @Tags Test
|
|||
// @Summary 创建Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "创建Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /t/createTest [post]
|
|||
export const createTest = (data) => { |
|||
return service({ |
|||
url: "/t/createTest", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 删除Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "删除Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|||
// @Router /t/deleteTest [post]
|
|||
export const deleteTest = (data) => { |
|||
return service({ |
|||
url: "/t/deleteTest", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
// @Tags Test
|
|||
// @Summary 更新Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "更新Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
|||
// @Router /t/updateTest [post]
|
|||
export const updateTest = (data) => { |
|||
return service({ |
|||
url: "/t/updateTest", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 用id查询Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "用id查询Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|||
// @Router /t/findTest [post]
|
|||
export const findTest = (data) => { |
|||
return service({ |
|||
url: "/t/findTest", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 分页获取Test列表
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body modelInterface.PageInfo true "分页获取Test列表"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /t/getTestList [post]
|
|||
export const getTestList = (data) => { |
|||
return service({ |
|||
url: "/t/getTestList", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
@ -0,0 +1,118 @@ |
|||
package api |
|||
|
|||
import ( |
|||
"fmt" |
|||
"gin-vue-admin/controller/servers" |
|||
"gin-vue-admin/model/modelInterface" |
|||
// 请自行引入model路径
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 创建Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "创建Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /t/createTest [post]
|
|||
func CreateTest(c *gin.Context) { |
|||
var t autocode.Test |
|||
_ = c.ShouldBindJSON(&t) |
|||
err := t.CreateTest() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "创建成功", gin.H{}) |
|||
} |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 删除Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "删除Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|||
// @Router /t/deleteTest [post]
|
|||
func DeleteTest(c *gin.Context) { |
|||
var t autocode.Test |
|||
_ = c.ShouldBindJSON(&t) |
|||
err := t.DeleteTest() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "创建成功", gin.H{}) |
|||
} |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 更新Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "更新Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
|||
// @Router /t/updateTest [post]
|
|||
func UpdateTest(c *gin.Context) { |
|||
var t autocode.Test |
|||
_ = c.ShouldBindJSON(&t) |
|||
err,ret := t.UpdateTest() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("更新失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "更新成功", gin.H{ |
|||
"ret":ret, |
|||
}) |
|||
} |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 用id查询Test
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body autocode.Test true "用id查询Test"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|||
// @Router /t/findTest [post]
|
|||
func FindTest(c *gin.Context) { |
|||
var t autocode.Test |
|||
_ = c.ShouldBindJSON(&t) |
|||
err,ret := t.FindById() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("查询失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "查询成功", gin.H{ |
|||
"ret":ret, |
|||
}) |
|||
} |
|||
} |
|||
|
|||
|
|||
// @Tags Test
|
|||
// @Summary 分页获取Test列表
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body modelInterface.PageInfo true "分页获取Test列表"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /t/getTestList [post]
|
|||
func GetTestList(c *gin.Context) { |
|||
var pageInfo modelInterface.PageInfo |
|||
_ = c.ShouldBindJSON(&pageInfo) |
|||
err, list, total := new(autocode.Test).GetInfoList(pageInfo) |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "获取数据成功", gin.H{ |
|||
"autocodeList": list, |
|||
"total": total, |
|||
"page": pageInfo.Page, |
|||
"pageSize": pageInfo.PageSize, |
|||
}) |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
// 自动生成模板Test
|
|||
package autocode |
|||
|
|||
import ( |
|||
"gin-vue-admin/controller/servers" |
|||
"gin-vue-admin/init/qmsql" |
|||
"gin-vue-admin/model/modelInterface" |
|||
"github.com/jinzhu/gorm" |
|||
) |
|||
|
|||
type Test struct { |
|||
gorm.Model |
|||
TestComponent string `json:"testComponent"` |
|||
TestBigComponent int `json:"testBigComponent"` |
|||
} |
|||
|
|||
// 创建Test
|
|||
func (t *Test)CreateTest()(err error){ |
|||
err = qmsql.DEFAULTDB.Create(t).Error |
|||
return err |
|||
} |
|||
|
|||
// 删除Test
|
|||
func (t *Test)DeleteTest()(err error){ |
|||
err = qmsql.DEFAULTDB.Delete(t).Error |
|||
return err |
|||
} |
|||
|
|||
// 更新Test
|
|||
func (t *Test)UpdateTest()(err error, ret Test){ |
|||
err = qmsql.DEFAULTDB.Save(t).Error |
|||
return err, *t |
|||
} |
|||
|
|||
// 根据ID查看单条Test
|
|||
func (t *Test)FindById()(err error,ret Test){ |
|||
err = qmsql.DEFAULTDB.Where("id = ?",t.ID).First(&ret).Error |
|||
return err,ret |
|||
} |
|||
|
|||
// 分页获取Test
|
|||
func (t *Test)GetInfoList(info modelInterface.PageInfo)(err error, list interface{}, total int){ |
|||
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
|
|||
err, db, total := servers.PagingServer(t, info) |
|||
if err != nil { |
|||
return |
|||
} else { |
|||
var reTestList []Test |
|||
err = db.Find(&reTestList).Error |
|||
return err, reTestList, total |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"gin-vue-admin/controller/api" |
|||
"gin-vue-admin/middleware" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func InitTestRouter(Router *gin.RouterGroup) { |
|||
TestRouter := Router.Group("t").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) |
|||
{ |
|||
TestRouter.POST("createTest", api.CreateTest) // 新建Test
|
|||
TestRouter.POST("deleteTest", api.DeleteTest) //删除Test
|
|||
TestRouter.POST("updateTest", api.UpdateTest) //更新Test
|
|||
TestRouter.POST("findTest ", api.FindTest) // 根据ID获取Test
|
|||
TestRouter.POST("getTestList", api.GetTestList) //获取Test列表
|
|||
} |
|||
} |
@ -0,0 +1,84 @@ |
|||
import service from '@/utils/request' |
|||
|
|||
// @Tags {{.StructName}} |
|||
// @Summary 创建{{.StructName}} |
|||
// @Security ApiKeyAuth |
|||
// @accept application/json |
|||
// @Produce application/json |
|||
// @Param data body {{.PackageName}}.{{.StructName}} true "创建{{.StructName}}" |
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
|||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post] |
|||
export const create{{.StructName}} = (data) => { |
|||
return service({ |
|||
url: "/{{.Abbreviation}}/create{{.StructName}}", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags {{.StructName}} |
|||
// @Summary 删除{{.StructName}} |
|||
// @Security ApiKeyAuth |
|||
// @accept application/json |
|||
// @Produce application/json |
|||
// @Param data body {{.PackageName}}.{{.StructName}} true "删除{{.StructName}}" |
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" |
|||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [post] |
|||
export const delete{{.StructName}} = (data) => { |
|||
return service({ |
|||
url: "/{{.Abbreviation}}/delete{{.StructName}}", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
// @Tags {{.StructName}} |
|||
// @Summary 更新{{.StructName}} |
|||
// @Security ApiKeyAuth |
|||
// @accept application/json |
|||
// @Produce application/json |
|||
// @Param data body {{.PackageName}}.{{.StructName}} true "更新{{.StructName}}" |
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" |
|||
// @Router /{{.Abbreviation}}/update{{.StructName}} [post] |
|||
export const update{{.StructName}} = (data) => { |
|||
return service({ |
|||
url: "/{{.Abbreviation}}/update{{.StructName}}", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags {{.StructName}} |
|||
// @Summary 用id查询{{.StructName}} |
|||
// @Security ApiKeyAuth |
|||
// @accept application/json |
|||
// @Produce application/json |
|||
// @Param data body {{.PackageName}}.{{.StructName}} true "用id查询{{.StructName}}" |
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" |
|||
// @Router /{{.Abbreviation}}/find{{.StructName}} [post] |
|||
export const find{{.StructName}} = (data) => { |
|||
return service({ |
|||
url: "/{{.Abbreviation}}/find{{.StructName}}", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags {{.StructName}} |
|||
// @Summary 分页获取{{.StructName}}列表 |
|||
// @Security ApiKeyAuth |
|||
// @accept application/json |
|||
// @Produce application/json |
|||
// @Param data body modelInterface.PageInfo true "分页获取{{.StructName}}列表" |
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
|||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [post] |
|||
export const get{{.StructName}}List = (data) => { |
|||
return service({ |
|||
url: "/{{.Abbreviation}}/get{{.StructName}}List", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
@ -0,0 +1,18 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"gin-vue-admin/controller/api" |
|||
"gin-vue-admin/middleware" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func Init{{.StructName}}Router(Router *gin.RouterGroup) { |
|||
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) |
|||
{ |
|||
{{.StructName}}Router.POST("create{{.StructName}}", api.Create{{.StructName}}) // 新建{{.StructName}} |
|||
{{.StructName}}Router.POST("delete{{.StructName}}", api.Delete{{.StructName}}) //删除{{.StructName}} |
|||
{{.StructName}}Router.POST("update{{.StructName}}", api.Update{{.StructName}}) //更新{{.StructName}} |
|||
{{.StructName}}Router.POST("find{{.StructName}} ", api.Find{{.StructName}}) // 根据ID获取{{.StructName}} |
|||
{{.StructName}}Router.POST("get{{.StructName}}List", api.Get{{.StructName}}List) //获取{{.StructName}}列表 |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue