You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.2 KiB

package {{.pkgName}}
import (
{{.imports}}
// "项目名称/orm/model" // 引入model包
// "github.com/jinzhu/copier" // 用于复制结构体
// "github.com/spf13/cast" // 用于类型转换
// "github.com/dromara/carbon/v2" // 用于时间操作
)
type {{.logic}} struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
{{if .hasDoc}}{{.doc}}{{end}}
func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} {
return &{{.logic}}{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *{{.logic}}) {{.function}}({{.request}}) {{.responseType}} {
//
// 1.
// var {{.pkgName}} model.XXX //
// copier.Copy(&{{.pkgName}}, &req) // xxx.Name = req.Name
// gormRes := l.svcCtx.GormDb.Create(&{{.pkgName}}) // Gorm的Create方法
// 2.
// var {{.pkgName}} model.XXX //
// gormRes := l.svcCtx.GormDb.Where("id = ?",req.Id).First(&{{.pkgName}}) // Gorm的First方法
// 3.
// var {{.pkgName}} model.XXX //
// gormRes := l.svcCtx.GormDb.Where("id = ?",req.Id).First(&{{.pkgName}}) // Gorm的First方法
// copier.Copy(&{{.pkgName}}, &req) // xxx.Name = req.Name
// gormRes := l.svcCtx.GormDb.Save(&{{.pkgName}}) // Gorm的Save方法
// 4.
// var {{.pkgName}} model.XXX //
// gormRes := l.svcCtx.GormDb.Where("id = ?",req.Id).Delete(&{{.pkgName}}) // Gorm的delete方法
// 5.
// var {{.pkgName}} []model.XXX //
// gormRes := l.svcCtx.GormDb.Where("name = ?",req.Name).Offset((req.Page -1) * req.PageSize).Limit(req.PageSize).Find(&{{.pkgName}}) // Gorm的Find方法
// //
// if gormRes.Error != nil { //
// return &types.Response{
// Success: false,
// Code : 500,
// Msg: "{{if .hasDoc}}{{.doc}}{{end}}"+"操作失败", //
// Data: gormRes.Error.Error(),
// },nil
// }
// //
// if gormRes.RowsAffected == 0 { //
// return &types.Response{
// Success: false,
// Code : 404,
// Msg: "{{if .hasDoc}}{{.doc}}{{end}}"+"未找到数据", //
// Data: "未找到数据",
// },nil
// }
//
return &types.Response{
Success: true,
Code : 200,
Msg: "{{if .hasDoc}}{{.doc}}{{end}}"+"操作成功", //
//Data: {{.pkgName}}, // {{.pkgName}}
},nil
}