model.go.template 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models
  2. import (
  3. {{- $bb := false -}}
  4. {{- range .Columns -}}
  5. {{- $z := .IsQuery -}}
  6. {{- if ($z) -}}
  7. {{- if eq .GoType "time.Time" -}}{{- $bb = true -}}{{- end -}}
  8. {{- end -}}
  9. {{- end -}}
  10. {{- range .Columns -}}
  11. {{- if eq .GoField "CreatedAt" -}}
  12. {{- else if eq .GoField "UpdatedAt" -}}
  13. {{- else if eq .GoField "DeletedAt" -}}
  14. {{- else -}}
  15. {{- if eq .GoType "time.Time" -}}{{- $bb = true -}}{{- end -}}
  16. {{- end -}}
  17. {{- end -}}
  18. {{- if eq $bb true }}
  19. "time"
  20. {{- end }}
  21. "IotAdmin/common/models"
  22. )
  23. // {{.ClassName}} {{.FunctionName}}实体
  24. type {{.ClassName}} struct {
  25. {{- range .Columns -}}
  26. {{$x := .Pk}}
  27. {{- if ($x) }}
  28. {{- if eq .GoField "Id" }}
  29. models.Model
  30. {{- else }}
  31. {{ $a := "" }}
  32. {{- if eq .GoType "int" -}}{{$a = "autoIncrement;"}}{{end -}}
  33. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primaryKey;{{$a}}comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}}
  34. {{- else if eq .GoField "CreatedAt" -}}
  35. {{- else if eq .GoField "UpdatedAt" -}}
  36. {{- else if eq .GoField "DeletedAt" -}}
  37. {{- else if eq .GoField "CreateBy" -}}
  38. {{- else if eq .GoField "UpdateBy" -}}
  39. {{- else }}
  40. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}}
  41. {{- end }}
  42. models.ControlBy
  43. models.ModelTime
  44. }
  45. func (*{{.ClassName}}) TableName() string {
  46. return "{{.TBName}}"
  47. }
  48. func (e *{{.ClassName}}) Generate() models.ActiveRecord {
  49. o := *e
  50. return &o
  51. }
  52. func (e *{{.ClassName}}) GetId() interface{} {
  53. return e.{{.PkGoField}}
  54. }