From d761b91dc9a7ccb8e667608194beb83139f092da Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Fri, 24 Apr 2020 21:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/template/te/service.go.tpl | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 server/resource/template/te/service.go.tpl diff --git a/server/resource/template/te/service.go.tpl b/server/resource/template/te/service.go.tpl new file mode 100644 index 00000000..120b4bbd --- /dev/null +++ b/server/resource/template/te/service.go.tpl @@ -0,0 +1,68 @@ +package service + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model" + "gin-vue-admin/model/request" +) + +// @title Create{{.StructName}} +// @description create a {{.StructName}} +// @param {{.Abbreviation}} model.{{.StructName}} +// @auth (2020/04/05 20:22) +// @return err error + +func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { + err = global.GVA_DB.Create(&{{.Abbreviation}}).Error + return err +} + +// @title Delete{{.StructName}} +// @description delete a {{.StructName}} +// @auth (2020/04/05 20:22) +// @param {{.Abbreviation}} model.{{.StructName}} +// @return error + +func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { + err = global.GVA_DB.Delete({{.Abbreviation}}).Error + return err +} + +// @title Update{{.StructName}} +// @description update a {{.StructName}} +// @param {{.Abbreviation}} *model.{{.StructName}} +// @auth (2020/04/05 20:22) +// @return error + +func Update{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) { + err = global.GVA_DB.Save({{.Abbreviation}}).Error + return err +} + +// @title Get{{.StructName}} +// @description get the info of a {{.StructName}} +// @auth (2020/04/05 20:22) +// @param id uint +// @return error +// @return {{.StructName}} {{.StructName}} + +func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { + err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error + return +} + +// @title Get{{.StructName}}InfoList +// @description get {{.StructName}} list by pagination, 分页获取用户列表 +// @auth (2020/04/05 20:22) +// @param info PageInfo +// @return error + +func Get{{.StructName}}InfoList(info request.PageInfo) (err error, list interface{}, total int) { + limit := info.PageSize + offset := info.PageSize * (info.Page - 1) + db := global.GVA_DB + var {{.Abbreviation}}s []model.{{.StructName}} + err = db.Find(&{{.Abbreviation}}s).Count(&total).Error + err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error + return err,{{.Abbreviation}}s, total +}