diff --git a/template/v2/dto.go.template b/template/v2/dto.go.template index 8f044fd3..dccd3815 100644 --- a/template/v2/dto.go.template +++ b/template/v2/dto.go.template @@ -5,6 +5,7 @@ import ( "go-admin/app/admin/models" "go-admin/common/dto" common "go-admin/common/models" + "gorm.io/gorm" ) type {{.ClassName}}Search struct { @@ -13,7 +14,7 @@ type {{.ClassName}}Search struct { {{ range .Columns -}} {{$z := .IsQuery}} {{- if ($z) -}} - {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}"` // {{.ColumnComment}} + {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` {{ end -}} {{- end }} @@ -44,18 +45,18 @@ type {{.ClassName}}Control struct { {{ range .Columns -}} {{$x := .Pk}} {{- if ($x) }} - {{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}} + {{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}} {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} - - {{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}} + + {{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- else if eq .GoField "UpdateBy" -}} - {{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}} + {{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- else }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}"` // {{.ColumnComment}}{{end -}} + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{end -}} {{- end }} } @@ -105,4 +106,4 @@ func (s *{{.ClassName}}ById) Generate() dto.Control { func (s *{{.ClassName}}ById) GenerateM() (common.ActiveRecord, error) { return &models.{{.ClassName}}{}, nil -} \ No newline at end of file +} diff --git a/template/v2/model.go.template b/template/v2/model.go.template index 7f31a694..9b101069 100644 --- a/template/v2/model.go.template +++ b/template/v2/model.go.template @@ -1,7 +1,6 @@ package models import ( - "strconv" {{- if eq .IsActions 2 -}} "go-admin/common/dto" @@ -9,6 +8,7 @@ import ( orm "go-admin/common/global" {{ end }} "go-admin/common/models" + "gorm.io/gorm" ) type {{.ClassName}} struct { @@ -40,13 +40,13 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord { } func (e *{{.ClassName}}) GetId() interface{} { - return e.{{.PkGoField}} + return e.ID } func (e *{{.ClassName}}) SetCreateBy(createBy uint) { - e.CreateBy = strconv.Itoa(int(createBy)) + e.CreateBy = createBy } func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) { - e.UpdateBy = strconv.Itoa(int(updateBy)) -} \ No newline at end of file + e.UpdateBy = updateBy +}