dto.go.template 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package dto
  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 .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
  12. {{- end -}}
  13. {{- if eq $bb true -}}
  14. "time"
  15. {{- end }}
  16. "go-admin/app/{{.PackageName}}/models"
  17. "go-admin/common/dto"
  18. common "go-admin/common/models"
  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}} string `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. model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的
  68. {{- else if eq .GoField "UpdateBy" -}}
  69. {{- else }}
  70. model.{{.GoField}} = s.{{.GoField}}
  71. {{- end -}}
  72. {{- end }}
  73. }
  74. func (s *{{.ClassName}}InsertReq) GetId() interface{} {
  75. return s.{{.PkGoField}}
  76. }
  77. type {{.ClassName}}UpdateReq struct {
  78. {{- range .Columns -}}
  79. {{$x := .Pk}}
  80. {{- if ($x) }}
  81. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  82. {{- else if eq .GoField "CreatedAt" -}}
  83. {{- else if eq .GoField "UpdatedAt" -}}
  84. {{- else if eq .GoField "DeletedAt" -}}
  85. {{- else if eq .GoField "CreateBy" -}}
  86. {{- else if eq .GoField "UpdateBy" -}}
  87. {{- else }}
  88. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  89. {{- end -}}
  90. {{- end }}
  91. common.ControlBy
  92. }
  93. func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) {
  94. {{- range .Columns -}}
  95. {{$x := .Pk}}
  96. {{- if ($x) }}
  97. if s.{{.GoField}} == 0 {
  98. model.Model = common.Model{ {{.GoField}}: s.{{.GoField}} }
  99. }
  100. {{- else if eq .GoField "CreatedAt" -}}
  101. {{- else if eq .GoField "UpdatedAt" -}}
  102. {{- else if eq .GoField "DeletedAt" -}}
  103. {{- else if eq .GoField "CreateBy" -}}
  104. {{- else if eq .GoField "UpdateBy"}}
  105. model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的
  106. {{- else }}
  107. model.{{.GoField}} = s.{{.GoField}}
  108. {{- end -}}
  109. {{- end }}
  110. }
  111. func (s *{{.ClassName}}UpdateReq) GetId() interface{} {
  112. return s.{{.PkGoField}}
  113. }
  114. // {{.ClassName}}GetReq 功能获取请求参数
  115. type {{.ClassName}}GetReq struct {
  116. {{- range .Columns -}}
  117. {{$x := .Pk}}
  118. {{- if ($x) }}
  119. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}"`
  120. {{- end }}
  121. {{- end }}
  122. }
  123. func (s *{{.ClassName}}GetReq) GetId() interface{} {
  124. return s.{{.PkGoField}}
  125. }
  126. // {{.ClassName}}DeleteReq 功能删除请求参数
  127. type {{.ClassName}}DeleteReq struct {
  128. Ids []int `json:"ids"`
  129. }
  130. func (s *{{.ClassName}}DeleteReq) GetId() interface{} {
  131. return s.Ids
  132. }