From b7c816b9cbfab160487da3d44e1a34a217568df0 Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Sun, 3 May 2020 21:52:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=9B=E5=BB=BAapi=E5=85=A5=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E5=BC=80=E5=85=B3=20=E5=8F=AF=E8=87=AA=E5=8A=A8=E4=BA=A7?= =?UTF-8?q?=E7=94=9Fapi=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_auto_code.go | 44 ++++++++++++++++++++++++++++++++++ server/model/sys_auto_code.go | 9 +++---- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/sys_auto_code.go index 4ffd6458..a2182cd5 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/sys_auto_code.go @@ -6,6 +6,7 @@ import ( "gin-vue-admin/model" "gin-vue-admin/service" "github.com/gin-gonic/gin" + "net/url" "os" ) @@ -21,6 +22,49 @@ func CreateTemp(c *gin.Context) { var a model.AutoCodeStruct _ = c.ShouldBindJSON(&a) err := service.CreateTemp(a) + if a.AutoCreateApiToSql { + apiList := [5]model.SysApi{ + { + Path: "/" + a.Abbreviation + "/" + "create" + a.StructName, + Description: "新增" + a.StructName, + ApiGroup: a.Abbreviation, + Method: "POST", + }, + { + Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName, + Description: "删除" + a.StructName, + ApiGroup: a.Abbreviation, + Method: "DELETE", + }, + { + Path: "/" + a.Abbreviation + "/" + "update" + a.StructName, + Description: "更新" + a.StructName, + ApiGroup: a.Abbreviation, + Method: "POST", + }, + { + Path: "/" + a.Abbreviation + "/" + "find" + a.StructName, + Description: "根据ID获取" + a.StructName, + ApiGroup: a.Abbreviation, + Method: "GET", + }, + { + Path: "/" + a.Abbreviation + "/" + "get" + a.StructName + "List", + Description: "获取" + a.StructName + "列表", + ApiGroup: a.StructName, + Method: "GET", + }, + } + for _, v := range apiList { + errC := service.CreateApi(v) + if errC != nil { + c.Writer.Header().Add("success", "false") + c.Writer.Header().Add("msg", url.QueryEscape(fmt.Sprintf("自动化创建失败,%v,请自行清空垃圾数据", errC))) + return + } + } + } + if err != nil { response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) os.Remove("./ginvueadmin.zip") diff --git a/server/model/sys_auto_code.go b/server/model/sys_auto_code.go index 6fbb5e13..9023f31d 100644 --- a/server/model/sys_auto_code.go +++ b/server/model/sys_auto_code.go @@ -2,10 +2,11 @@ package model // 初始版本自动化代码工具 type AutoCodeStruct struct { - StructName string `json:"structName"` - PackageName string `json:"packageName"` - Abbreviation string `json:"abbreviation"` - Fields []Field `json:"fields"` + StructName string `json:"structName"` + PackageName string `json:"packageName"` + Abbreviation string `json:"abbreviation"` + AutoCreateApiToSql bool `json:"autoCreateApiToSql"` + Fields []Field `json:"fields"` } type Field struct { -- GitLab