dto.go.template 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package dto
  2. import (
  3. "IotAdmin/app/{{.PackageName}}/models"
  4. "IotAdmin/common/dto"
  5. comModels "IotAdmin/common/models"
  6. "time"
  7. )
  8. type {{.ClassName}}GetPageReq struct {
  9. dto.Pagination `search:"-"`
  10. {{- $tablename := .TBName -}}
  11. {{- range .Columns -}}
  12. {{- if (eq .GoField "CreatedAt") }}
  13. BeginTime string `form:"beginTime" search:"type:gte;column:created_at;table:{{$tablename}}" comment:"创建时间"`
  14. EndTime string `form:"endTime" search:"type:lte;column:created_at;table:{{$tablename}}" comment:"创建时间"`
  15. {{- else if eq .IsQuery "1" }}
  16. {{- if and (eq .HtmlType "datetime") }}
  17. Begin{{.GoField}} string `form:"begin{{.GoField}}" search:"type:gte;column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"`
  18. End{{.GoField}} string `form:"end{{.GoField}}" search:"type:lte;column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"`
  19. {{- else if and (eq .HtmlType "datetime") }}
  20. {{.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}}"`
  21. {{- end }}
  22. {{- end }}
  23. {{- end }}
  24. {{.ClassName}}Order
  25. }
  26. type {{.ClassName}}Order struct {
  27. {{- range .Columns -}}
  28. {{- if eq .IsSort "1"}}
  29. {{.GoField}} string `form:"{{.JsonField}}Order" search:"type:order;column:{{.ColumnName}};table:{{$tablename}}"`
  30. {{- end -}}
  31. {{- end }}
  32. }
  33. func (m *{{.ClassName}}GetPageReq) GetNeedSearch() interface{} {
  34. return *m
  35. }
  36. // {{.ClassName}}InsertReq 添加{{.FunctionName}}请求参数
  37. type {{.ClassName}}InsertReq struct {
  38. {{- range .Columns -}}
  39. {{$x := .Pk}}
  40. {{- if ($x) }}
  41. {{.GoField}} {{.GoType}} `json:"-" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  42. {{- else if eq .GoField "CreatedAt" -}}
  43. {{- else if eq .GoField "UpdatedAt" -}}
  44. {{- else if eq .GoField "DeletedAt" -}}
  45. {{- else if eq .GoField "CreateBy" -}}
  46. {{- else if eq .GoField "UpdateBy" -}}
  47. {{- else if eq .IsInsert "1"}}
  48. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  49. {{- end -}}
  50. {{- end }}
  51. comModels.ControlBy
  52. }
  53. func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) {
  54. {{- range .Columns -}}
  55. {{$x := .Pk}}
  56. {{- if ($x) }}
  57. if s.{{.GoField}} == 0 {
  58. {{- if eq .GoField "Id" }}
  59. model.Model = comModels.Model{ {{.GoField}}: s.{{.GoField}} }
  60. {{- else }}
  61. model.{{.GoField}} = s.{{.GoField}}
  62. {{- end }}
  63. }
  64. {{- else if eq .GoField "CreatedAt" -}}
  65. {{- else if eq .GoField "UpdatedAt" -}}
  66. {{- else if eq .GoField "DeletedAt" -}}
  67. {{- else if eq .GoField "CreateBy"}}
  68. model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的
  69. {{- else if eq .GoField "UpdateBy" -}}
  70. {{- else if eq .IsInsert "1"}}
  71. model.{{.GoField}} = s.{{.GoField}}
  72. {{- end -}}
  73. {{- end }}
  74. }
  75. func (s *{{.ClassName}}InsertReq) GetId() interface{} {
  76. return s.{{.PkGoField}}
  77. }
  78. // {{.ClassName}}UpdateReq 修改{{.FunctionName}}请求参数
  79. type {{.ClassName}}UpdateReq struct {
  80. {{- range .Columns -}}
  81. {{$x := .Pk}}
  82. {{- if ($x) }}
  83. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  84. {{- else if eq .GoField "CreatedAt" -}}
  85. {{- else if eq .GoField "UpdatedAt" -}}
  86. {{- else if eq .GoField "DeletedAt" -}}
  87. {{- else if eq .GoField "CreateBy" -}}
  88. {{- else if eq .GoField "UpdateBy" -}}
  89. {{- else if eq .IsInsert "1"}}
  90. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  91. {{- end -}}
  92. {{- end }}
  93. comModels.ControlBy
  94. }
  95. func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) {
  96. {{- range .Columns -}}
  97. {{$x := .Pk}}
  98. {{- if ($x) }}
  99. if s.{{.GoField}} == 0 {
  100. {{- if eq .GoField "Id" }}
  101. model.Model = comModels.Model{ {{.GoField}}: s.{{.GoField}} }
  102. {{- else }}
  103. model.{{.GoField}} = s.{{.GoField}}
  104. {{- end }}
  105. }
  106. {{- else if eq .GoField "CreatedAt" -}}
  107. {{- else if eq .GoField "UpdatedAt" -}}
  108. {{- else if eq .GoField "DeletedAt" -}}
  109. {{- else if eq .GoField "CreateBy" -}}
  110. {{- else if eq .GoField "UpdateBy"}}
  111. model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的
  112. {{- else if eq .IsInsert "1" }}
  113. model.{{.GoField}} = s.{{.GoField}}
  114. {{- end -}}
  115. {{- end }}
  116. }
  117. func (s *{{.ClassName}}UpdateReq) GetId() interface{} {
  118. return s.{{.PkGoField}}
  119. }
  120. // {{.ClassName}}GetReq 获取{{.FunctionName}}请求参数
  121. type {{.ClassName}}GetReq struct {
  122. {{- range .Columns -}}
  123. {{$x := .Pk}}
  124. {{- if ($x) }}
  125. Id {{.GoType}} `uri:"id"`
  126. {{- end }}
  127. {{- end }}
  128. }
  129. func (s *{{.ClassName}}GetReq) GetId() interface{} {
  130. return s.Id
  131. }
  132. // {{.ClassName}}DeleteReq 删除{{.FunctionName}}请求参数
  133. type {{.ClassName}}DeleteReq struct {
  134. Ids []int `json:"ids"`
  135. }
  136. func (s *{{.ClassName}}DeleteReq) GetId() interface{} {
  137. return s.Ids
  138. }
  139. // {{.ClassName}}Resp 获取{{.FunctionName}}响应参数
  140. type {{.ClassName}}Resp struct {
  141. {{- range .Columns -}}
  142. {{$x := .Pk}}
  143. {{- if ($x) }}
  144. {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
  145. {{- else if eq .GoField "UpdatedAt" -}}
  146. {{- else if eq .GoField "DeletedAt" -}}
  147. {{- else if eq .GoField "CreateBy" }}
  148. {{.GoField}} int `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  149. {{- else if eq .GoField "UpdateBy" -}}
  150. {{- else if eq .IsInsert "1"}}
  151. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
  152. {{- end -}}
  153. {{- end }}
  154. }
  155. func (s *{{.ClassName}}Resp) Generate(model *models.{{.ClassName}}) {
  156. {{- range .Columns -}}
  157. {{- if eq .GoField "CreatedAt" }}
  158. s.{{.GoField}} = model.{{.GoField}}
  159. {{- else if eq .GoField "UpdatedAt" -}}
  160. {{- else if eq .GoField "DeletedAt" -}}
  161. {{- else if eq .GoField "CreateBy" }}
  162. s.{{.GoField}} = model.{{.GoField}}
  163. {{- else if eq .GoField "UpdateBy" -}}
  164. {{- else if eq .IsInsert "1"}}
  165. s.{{.GoField}} = model.{{.GoField}}
  166. {{- end -}}
  167. {{- end }}
  168. }