model.tpl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package model
  2. import (
  3. "time"
  4. "ulink-admin/pkg/base"
  5. )
  6. type {{.ClassNameUpper}} struct { {{range $index, $item := .Columns}}
  7. {{$item.ColumnNameUpper}} {{$item.GoType}} `excel:"name={{$item.ColumnComment}} {{if eq $item.Source "3"}},format={{$item.Input}}{{end}}" xorm:"{{if $item.ColumnKey }}pk {{if $item.Extra }}autoincr{{end}}{{else}}{{$item.ColumnType}}{{end}} {{if eq $item.IsNullable "NO"}} notnull {{end}} {{if $item.ColumnDefault}}default{{if eq $item.GoType "string"}}('{{$item.ColumnDefault}}'){{else}}({{$item.ColumnDefault}}){{end}}{{end}} comment('{{$item.ColumnComment}}')" json:"{{$item.ColumnNameLower}}" {{if eq $item.IsRequired "1" }}binding:"required{{if eq $item.Source "3"}},oneof={{$item.Keys}}{{end}}"{{end}}` //{{$item.ColumnDesc}}{{end}}
  8. }
  9. func (this {{.ClassNameUpper}}) TableName() string {
  10. return "{{.TableName}}"
  11. }
  12. func (this *{{.ClassNameUpper}}) Key() int64 {
  13. return this.Id
  14. }
  15. func (this *{{.ClassNameUpper}}) Model() interface{} {
  16. return this
  17. }
  18. func (this *{{.ClassNameUpper}}) BeforeUpdate() {
  19. user := base.GetCurUser()
  20. if user != nil {
  21. this.UpdateBy = user.Name
  22. }{{range $index, $item := .Columns}}{{if eq $item.ColumnNameUpper "CompanyId"}}
  23. if user.ComponyId > 0 {
  24. this.CompanyId = user.ComponyId
  25. }{{end}}{{end}}
  26. }
  27. func (this *{{.ClassNameUpper}}) BeforeInsert() {
  28. user := base.GetCurUser()
  29. if user != nil {
  30. this.CreateBy = user.Name
  31. this.UpdateBy = user.Name
  32. }{{range $index, $item := .Columns}}{{if eq $item.ColumnNameUpper "CompanyId"}}
  33. if user.ComponyId > 0 {
  34. this.CompanyId = user.ComponyId
  35. }{{end}}{{end}}
  36. }