Bladeren bron

模板调整完成 TODO:自动代码移动

pixel 3 jaren geleden
bovenliggende
commit
c8527ac589

+ 16 - 16
server/api/v1/autocode/autocodeExample.go

@@ -3,7 +3,7 @@ package autocode
 import (
 	"gin-vue-admin/global"
 	"gin-vue-admin/model/autocode"
-	"gin-vue-admin/model/autocode/requset"
+	autocodeReq "gin-vue-admin/model/autocode/requset"
 	"gin-vue-admin/model/common/response"
 	"gin-vue-admin/service"
 	"gin-vue-admin/utils"
@@ -25,9 +25,9 @@ var autoCodeExampleService = service.ServiceGroupApp.AutoCodeServiceGroup.AutoCo
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
 // @Router /autoCodeExample/createAutoCodeExample [post]
 func (autoCodeExampleApi *AutoCodeExampleApi) CreateAutoCodeExample(c *gin.Context) {
-	var detail autocode.AutoCodeExample
-	_ = c.ShouldBindJSON(&detail)
-	if err := autoCodeExampleService.CreateAutoCodeExample(detail); err != nil {
+	var autoCodeExample autocode.AutoCodeExample
+	_ = c.ShouldBindJSON(&autoCodeExample)
+	if err := autoCodeExampleService.CreateAutoCodeExample(autoCodeExample); err != nil {
 		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
 		response.FailWithMessage("创建失败", c)
 	} else {
@@ -44,9 +44,9 @@ func (autoCodeExampleApi *AutoCodeExampleApi) CreateAutoCodeExample(c *gin.Conte
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
 // @Router /autoCodeExample/deleteAutoCodeExample [delete]
 func (autoCodeExampleApi *AutoCodeExampleApi) DeleteAutoCodeExample(c *gin.Context) {
-	var detail autocode.AutoCodeExample
-	_ = c.ShouldBindJSON(&detail)
-	if err := autoCodeExampleService.DeleteAutoCodeExample(detail); err != nil {
+	var autoCodeExample autocode.AutoCodeExample
+	_ = c.ShouldBindJSON(&autoCodeExample)
+	if err := autoCodeExampleService.DeleteAutoCodeExample(autoCodeExample); err != nil {
 		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
 		response.FailWithMessage("删除失败", c)
 	} else {
@@ -63,9 +63,9 @@ func (autoCodeExampleApi *AutoCodeExampleApi) DeleteAutoCodeExample(c *gin.Conte
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
 // @Router /autoCodeExample/updateAutoCodeExample [put]
 func (autoCodeExampleApi *AutoCodeExampleApi) UpdateAutoCodeExample(c *gin.Context) {
-	var detail autocode.AutoCodeExample
-	_ = c.ShouldBindJSON(&detail)
-	if err := autoCodeExampleService.UpdateAutoCodeExample(&detail); err != nil {
+	var autoCodeExample autocode.AutoCodeExample
+	_ = c.ShouldBindJSON(&autoCodeExample)
+	if err := autoCodeExampleService.UpdateAutoCodeExample(&autoCodeExample); err != nil {
 		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
 		response.FailWithMessage("更新失败", c)
 	} else {
@@ -82,13 +82,13 @@ func (autoCodeExampleApi *AutoCodeExampleApi) UpdateAutoCodeExample(c *gin.Conte
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
 // @Router /autoCodeExample/findAutoCodeExample [get]
 func (autoCodeExampleApi *AutoCodeExampleApi) FindAutoCodeExample(c *gin.Context) {
-	var detail autocode.AutoCodeExample
-	_ = c.ShouldBindQuery(&detail)
-	if err := utils.Verify(detail, utils.IdVerify); err != nil {
+	var autoCodeExample autocode.AutoCodeExample
+	_ = c.ShouldBindQuery(&autoCodeExample)
+	if err := utils.Verify(autoCodeExample, utils.IdVerify); err != nil {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(detail.ID); err != nil {
+	if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(autoCodeExample.ID); err != nil {
 		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
 		response.FailWithMessage("查询失败", c)
 	} else {
@@ -101,11 +101,11 @@ func (autoCodeExampleApi *AutoCodeExampleApi) FindAutoCodeExample(c *gin.Context
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body request.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件"
+// @Param data body autocodeReq.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
 // @Router /autoCodeExample/getAutoCodeExampleList [get]
 func (autoCodeExampleApi *AutoCodeExampleApi) GetAutoCodeExampleList(c *gin.Context) {
-	var pageInfo request.AutoCodeExampleSearch
+	var pageInfo autocodeReq.AutoCodeExampleSearch
 	_ = c.ShouldBindQuery(&pageInfo)
 	if err, list, total := autoCodeExampleService.GetAutoCodeExampleInfoList(pageInfo); err != nil {
 		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))

+ 2 - 0
server/api/v1/autocode/enter.go

@@ -1,5 +1,7 @@
 package autocode
 
 type ApiGroup struct {
+	// Code generated by gin-vue-admin Begin; DO NOT EDIT.
 	AutoCodeExampleApi
+	// Code generated by gin-vue-admin End; DO NOT EDIT.
 }

+ 32 - 24
server/resource/template/server/api.go.tpl

@@ -2,27 +2,35 @@ package v1
 
 import (
 	"gin-vue-admin/global"
-    "gin-vue-admin/model"
-    "gin-vue-admin/model/request"
-    "gin-vue-admin/model/response"
+    "gin-vue-admin/model/autocode"
+    "gin-vue-admin/model/common/requset"
+    autocodeReq "gin-vue-admin/model/autocode/requset"
+    "gin-vue-admin/model/common/response"
     "gin-vue-admin/service"
+    "gin-vue-admin/utils"
     "github.com/gin-gonic/gin"
     "go.uber.org/zap"
 )
 
+type {{.StructName}}Api struct {
+}
+
+var {{.Abbreviation}}Service = service.ServiceGroupApp.AutoCodeServiceGroup.{{.StructName}}Service
+
+
 // Create{{.StructName}} 创建{{.StructName}}
 // @Tags {{.StructName}}
 // @Summary 创建{{.StructName}}
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body model.{{.StructName}} true "创建{{.StructName}}"
+// @Param data body autocode.{{.StructName}} true "创建{{.StructName}}"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
 // @Router /{{.Abbreviation}}/create{{.StructName}} [post]
-func Create{{.StructName}}(c *gin.Context) {
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) {
 	var {{.Abbreviation}} model.{{.StructName}}
 	_ = c.ShouldBindJSON(&{{.Abbreviation}})
-	if err := service.Create{{.StructName}}({{.Abbreviation}}); err != nil {
+	if err := {{.Abbreviation}}Service.Create{{.StructName}}({{.Abbreviation}}); err != nil {
         global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
 		response.FailWithMessage("创建失败", c)
 	} else {
@@ -36,13 +44,13 @@ func Create{{.StructName}}(c *gin.Context) {
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body model.{{.StructName}} true "删除{{.StructName}}"
+// @Param data body autocode.{{.StructName}} true "删除{{.StructName}}"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
 // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
-func Delete{{.StructName}}(c *gin.Context) {
-	var {{.Abbreviation}} model.{{.StructName}}
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
+	var {{.Abbreviation}} autocode.{{.StructName}}
 	_ = c.ShouldBindJSON(&{{.Abbreviation}})
-	if err := service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
+	if err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
         global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
 		response.FailWithMessage("删除失败", c)
 	} else {
@@ -59,10 +67,10 @@ func Delete{{.StructName}}(c *gin.Context) {
 // @Param data body request.IdsReq true "批量删除{{.StructName}}"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
 // @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
-func Delete{{.StructName}}ByIds(c *gin.Context) {
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) {
 	var IDS request.IdsReq
     _ = c.ShouldBindJSON(&IDS)
-	if err := service.Delete{{.StructName}}ByIds(IDS); err != nil {
+	if err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds(IDS); err != nil {
         global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
 		response.FailWithMessage("批量删除失败", c)
 	} else {
@@ -76,13 +84,13 @@ func Delete{{.StructName}}ByIds(c *gin.Context) {
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body model.{{.StructName}} true "更新{{.StructName}}"
+// @Param data body autocode.{{.StructName}} true "更新{{.StructName}}"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
 // @Router /{{.Abbreviation}}/update{{.StructName}} [put]
-func Update{{.StructName}}(c *gin.Context) {
-	var {{.Abbreviation}} model.{{.StructName}}
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) {
+	var {{.Abbreviation}} autocode.{{.StructName}}
 	_ = c.ShouldBindJSON(&{{.Abbreviation}})
-	if err := service.Update{{.StructName}}({{.Abbreviation}}); err != nil {
+	if err := {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}}); err != nil {
         global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
 		response.FailWithMessage("更新失败", c)
 	} else {
@@ -96,13 +104,13 @@ func Update{{.StructName}}(c *gin.Context) {
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body model.{{.StructName}} true "用id查询{{.StructName}}"
+// @Param data body autocode.{{.StructName}} true "用id查询{{.StructName}}"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
 // @Router /{{.Abbreviation}}/find{{.StructName}} [get]
-func Find{{.StructName}}(c *gin.Context) {
-	var {{.Abbreviation}} model.{{.StructName}}
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) {
+	var {{.Abbreviation}} autocode.{{.StructName}}
 	_ = c.ShouldBindQuery(&{{.Abbreviation}})
-	if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
+	if err, re{{.Abbreviation}} := {{.Abbreviation}}Service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
         global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
 		response.FailWithMessage("查询失败", c)
 	} else {
@@ -116,13 +124,13 @@ func Find{{.StructName}}(c *gin.Context) {
 // @Security ApiKeyAuth
 // @accept application/json
 // @Produce application/json
-// @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表"
+// @Param data body autocodeReq.{{.StructName}}Search true "分页获取{{.StructName}}列表"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
 // @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
-func Get{{.StructName}}List(c *gin.Context) {
-	var pageInfo request.{{.StructName}}Search
+func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) {
+	var pageInfo autocodeReq.{{.StructName}}Search
 	_ = c.ShouldBindQuery(&pageInfo)
-	if err, list, total := service.Get{{.StructName}}InfoList(pageInfo); err != nil {
+	if err, list, total := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil {
 	    global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
         response.FailWithMessage("获取失败", c)
     } else {

+ 6 - 3
server/resource/template/server/request.go.tpl

@@ -1,8 +1,11 @@
 package request
 
-import "gin-vue-admin/model"
+import (
+	"gin-vue-admin/model/autocode"
+	"gin-vue-admin/model/common/request"
+)
 
 type {{.StructName}}Search struct{
-    model.{{.StructName}}
-    PageInfo
+    autocode.{{.StructName}}
+    request.PageInfo
 }

+ 12 - 8
server/resource/template/server/router.go.tpl

@@ -6,15 +6,19 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
+type {{.StructName}}Router struct {
+}
+
 // Init{{.StructName}}Router 初始化 {{.StructName}} 路由信息
-func Init{{.StructName}}Router(Router *gin.RouterGroup) {
-	{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord())
+func (s *{{.StructName}}Router) Init{{.StructName}}Router(Router *gin.RouterGroup) {
+	{{.Abbreviation}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord())
+	var {{.Abbreviation}}Api = v1.ApiGroupApp.AutoCodeApiGroup.{{.StructName}}Api
 	{
-		{{.StructName}}Router.POST("create{{.StructName}}", v1.Create{{.StructName}})   // 新建{{.StructName}}
-		{{.StructName}}Router.DELETE("delete{{.StructName}}", v1.Delete{{.StructName}}) // 删除{{.StructName}}
-		{{.StructName}}Router.DELETE("delete{{.StructName}}ByIds", v1.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}}
-		{{.StructName}}Router.PUT("update{{.StructName}}", v1.Update{{.StructName}})    // 更新{{.StructName}}
-		{{.StructName}}Router.GET("find{{.StructName}}", v1.Find{{.StructName}})        // 根据ID获取{{.StructName}}
-		{{.StructName}}Router.GET("get{{.StructName}}List", v1.Get{{.StructName}}List)  // 获取{{.StructName}}列表
+		{{.Abbreviation}}Router.POST("create{{.StructName}}", {{.Abbreviation}}Api.Create{{.StructName}})   // 新建{{.StructName}}
+		{{.Abbreviation}}Router.DELETE("delete{{.StructName}}", {{.Abbreviation}}Api.Delete{{.StructName}}) // 删除{{.StructName}}
+		{{.Abbreviation}}Router.DELETE("delete{{.StructName}}ByIds", {{.Abbreviation}}Api.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}}
+		{{.Abbreviation}}Router.PUT("update{{.StructName}}", {{.Abbreviation}}Api.Update{{.StructName}})    // 更新{{.StructName}}
+		{{.Abbreviation}}Router.GET("find{{.StructName}}", {{.Abbreviation}}Api.Find{{.StructName}})        // 根据ID获取{{.StructName}}
+		{{.Abbreviation}}Router.GET("get{{.StructName}}List", {{.Abbreviation}}Api.Get{{.StructName}}List)  // 获取{{.StructName}}列表
 	}
 }

+ 14 - 11
server/resource/template/server/service.go.tpl

@@ -2,53 +2,56 @@ package service
 
 import (
 	"gin-vue-admin/global"
-	"gin-vue-admin/model"
-	"gin-vue-admin/model/request"
+	"gin-vue-admin/model/autocode"
+	"gin-vue-admin/model/autocode/request"
 )
 
+type {{.StructName}}Service struct {
+}
+
 // Create{{.StructName}} 创建{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
+func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
 	err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
 	return err
 }
 
 // Delete{{.StructName}} 删除{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
+func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
 	err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error
 	return err
 }
 
 // Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
-	err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error
+func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
+	err = global.GVA_DB.Delete(&[]autocode.{{.StructName}}{},"id in ?",ids.Ids).Error
 	return err
 }
 
 // Update{{.StructName}} 更新{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
+func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
 	err = global.GVA_DB.Save(&{{.Abbreviation}}).Error
 	return err
 }
 
 // Get{{.StructName}} 根据id获取{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) {
+func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} autocode.{{.StructName}}) {
 	err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
 	return
 }
 
 // Get{{.StructName}}InfoList 分页获取{{.StructName}}记录
 // Author [piexlmax](https://github.com/piexlmax)
-func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
+func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
     // 创建db
-	db := global.GVA_DB.Model(&model.{{.StructName}}{})
-    var {{.Abbreviation}}s []model.{{.StructName}}
+	db := global.GVA_DB.Model(&autocode.{{.StructName}}{})
+    var {{.Abbreviation}}s []autocode.{{.StructName}}
     // 如果有条件搜索 下方会自动创建搜索语句
         {{- range .Fields}}
             {{- if .FieldSearchType}}

+ 2 - 0
server/router/autocode/enter.go

@@ -1,5 +1,7 @@
 package autocode
 
 type RouterGroup struct {
+	// Code generated by gin-vue-admin Begin; DO NOT EDIT.
 	AutoCodeExampleRouter
+	// Code generated by gin-vue-admin End; DO NOT EDIT.
 }

+ 2 - 0
server/service/autocode/enter.go

@@ -1,5 +1,7 @@
 package autocode
 
 type ServiceGroup struct {
+	// Code generated by gin-vue-admin Begin; DO NOT EDIT.
 	AutoCodeExampleService
+	// Code generated by gin-vue-admin End; DO NOT EDIT.
 }