dto.go.template 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package dto
  2. import (
  3. "go-admin/app/{{.PackageName}}/models"
  4. "go-admin/common/dto"
  5. common "go-admin/common/models"
  6. {{- $bb := false -}}
  7. {{- range .Columns -}}
  8. {{$z := .IsQuery}}
  9. {{- if ($z) }}
  10. {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
  11. {{- end -}}
  12. {{- end -}}
  13. {{- range .Columns -}}
  14. {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
  15. {{- end -}}
  16. {{- if eq $bb true -}}
  17. "time"
  18. {{- end }}
  19. )
  20. type {{.ClassName}}GetPageReq struct {
  21. dto.Pagination `search:"-"`
  22. {{- $tablename := .TBName -}}
  23. {{- range .Columns -}}
  24. {{$z := .IsQuery}}
  25. {{- if ($z) }}
  26. {{.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}}"`
  27. {{- end }}
  28. {{- end }}
  29. {{.ClassName}}Order
  30. }
  31. type {{.ClassName}}Order struct {
  32. {{- $tablename := .TBName -}}
  33. {{- range .Columns -}}
  34. {{.GoField}} {{.GoType}} `form:"{{.JsonField}}Order" search:"type:order;column:{{.ColumnName}};table:{{$tablename}}"`
  35. {{ end }}
  36. }
  37. func (m *{{.ClassName}}GetPageReq) GetNeedSearch() interface{} {
  38. return *m
  39. }
  40. type {{.ClassName}}InsertReq struct {
  41. {{- range .Columns -}}
  42. {{$x := .Pk}}
  43. {{- if ($x) }}
  44. {{.GoField}} {{.GoType}} `json:"-" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  45. {{- else if eq .GoField "CreatedAt" -}}
  46. {{- else if eq .GoField "UpdatedAt" -}}
  47. {{- else if eq .GoField "DeletedAt" -}}
  48. {{- else if eq .GoField "CreateBy" -}}
  49. {{- else if eq .GoField "UpdateBy" -}}
  50. {{- else }}
  51. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  52. {{- end -}}
  53. {{- end }}
  54. common.ControlBy
  55. }
  56. func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) {
  57. {{- range .Columns -}}
  58. {{$x := .Pk}}
  59. {{- if ($x) }}
  60. if s.{{.GoField}} == 0 {
  61. model.Model = common.Model{ {{.GoField}}: s.{{.GoField}} }
  62. }
  63. {{- else if eq .GoField "CreatedAt" -}}
  64. {{- else if eq .GoField "UpdatedAt" -}}
  65. {{- else if eq .GoField "DeletedAt" -}}
  66. {{- else if eq .GoField "CreateBy" -}}
  67. {{- else if eq .GoField "UpdateBy" -}}
  68. {{- else }}
  69. model.{{.GoField}} = s.{{.GoField}}
  70. {{- end -}}
  71. {{- end }}
  72. }
  73. func (s *{{.ClassName}}InsertReq) GetId() interface{} {
  74. return s.{{.PkGoField}}
  75. }
  76. type {{.ClassName}}UpdateReq struct {
  77. {{- range .Columns -}}
  78. {{$x := .Pk}}
  79. {{- if ($x) }}
  80. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  81. {{- else if eq .GoField "CreatedAt" -}}
  82. {{- else if eq .GoField "UpdatedAt" -}}
  83. {{- else if eq .GoField "DeletedAt" -}}
  84. {{- else if eq .GoField "CreateBy" -}}
  85. {{- else if eq .GoField "UpdateBy" -}}
  86. {{- else }}
  87. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  88. {{- end -}}
  89. {{- end }}
  90. common.ControlBy
  91. }
  92. func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) {
  93. {{- range .Columns -}}
  94. {{$x := .Pk}}
  95. {{- if ($x) }}
  96. if s.{{.GoField}} == 0 {
  97. model.Model = common.Model{ {{.GoField}}: s.{{.GoField}} }
  98. }
  99. {{- else if eq .GoField "CreatedAt" -}}
  100. {{- else if eq .GoField "UpdatedAt" -}}
  101. {{- else if eq .GoField "DeletedAt" -}}
  102. {{- else if eq .GoField "CreateBy" -}}
  103. {{- else if eq .GoField "UpdateBy" -}}
  104. {{- else }}
  105. model.{{.GoField}} = s.{{.GoField}}
  106. {{- end -}}
  107. {{- end }}
  108. }
  109. func (s *{{.ClassName}}UpdateReq) GetId() interface{} {
  110. return s.{{.PkGoField}}
  111. }
  112. // {{.ClassName}}GetReq 功能获取请求参数
  113. type {{.ClassName}}GetReq struct {
  114. {{- range .Columns -}}
  115. {{$x := .Pk}}
  116. {{- if ($x) }}
  117. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}"`
  118. {{- end }}
  119. {{- end }}
  120. }
  121. func (s *{{.ClassName}}GetReq) GetId() interface{} {
  122. return s.{{.PkGoField}}
  123. }
  124. // {{.ClassName}}DeleteReq 功能删除请求参数
  125. type {{.ClassName}}DeleteReq struct {
  126. Ids []int `json:"ids"`
  127. }
  128. func (s *{{.ClassName}}DeleteReq) GetId() interface{} {
  129. return s.Ids
  130. }