模版修改

This commit is contained in:
linwenxiang
2020-09-14 20:02:55 +08:00
parent c6735c4b1a
commit 9cab65af6a
2 changed files with 13 additions and 12 deletions
+6 -5
View File
@@ -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 }}
}
+4 -4
View File
@@ -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))
e.UpdateBy = updateBy
}