package dto import ( "IotAdmin/app/{{.PackageName}}/models" "IotAdmin/common/dto" comModels "IotAdmin/common/models" "time" ) type {{.ClassName}}GetPageReq struct { dto.Pagination `search:"-"` {{- $tablename := .TBName -}} {{- range .Columns -}} {{- if (eq .GoField "CreatedAt") }} BeginTime string `form:"beginTime" search:"type:gte;column:created_at;table:{{$tablename}}" comment:"创建时间"` EndTime string `form:"endTime" search:"type:lte;column:created_at;table:{{$tablename}}" comment:"创建时间"` {{- else if eq .IsQuery "1" }} {{- if and (eq .HtmlType "datetime") }} Begin{{.GoField}} string `form:"begin{{.GoField}}" search:"type:gte;column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` End{{.GoField}} string `form:"end{{.GoField}}" search:"type:lte;column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` {{- else if and (eq .HtmlType "datetime") }} {{.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}}"` {{- end }} {{- end }} {{- end }} {{.ClassName}}Order } type {{.ClassName}}Order struct { {{- range .Columns -}} {{- if eq .IsSort "1"}} {{.GoField}} string `form:"{{.JsonField}}Order" search:"type:order;column:{{.ColumnName}};table:{{$tablename}}"` {{- end -}} {{- end }} } func (m *{{.ClassName}}GetPageReq) GetNeedSearch() interface{} { return *m } // {{.ClassName}}InsertReq 添加{{.FunctionName}}请求参数 type {{.ClassName}}InsertReq struct { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} {{.GoField}} {{.GoType}} `json:"-" comment:"{{.ColumnComment}}"` // {{.ColumnComment}} {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} {{- else if eq .GoField "UpdateBy" -}} {{- else if eq .IsInsert "1"}} {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- end -}} {{- end }} comModels.ControlBy } func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} if s.{{.GoField}} == 0 { {{- if eq .GoField "Id" }} model.Model = comModels.Model{ {{.GoField}}: s.{{.GoField}} } {{- else }} model.{{.GoField}} = s.{{.GoField}} {{- end }} } {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy"}} model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的 {{- else if eq .GoField "UpdateBy" -}} {{- else if eq .IsInsert "1"}} model.{{.GoField}} = s.{{.GoField}} {{- end -}} {{- end }} } func (s *{{.ClassName}}InsertReq) GetId() interface{} { return s.{{.PkGoField}} } // {{.ClassName}}UpdateReq 修改{{.FunctionName}}请求参数 type {{.ClassName}}UpdateReq struct { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}} {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} {{- else if eq .GoField "UpdateBy" -}} {{- else if eq .IsInsert "1"}} {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- end -}} {{- end }} comModels.ControlBy } func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} if s.{{.GoField}} == 0 { {{- if eq .GoField "Id" }} model.Model = comModels.Model{ {{.GoField}}: s.{{.GoField}} } {{- else }} model.{{.GoField}} = s.{{.GoField}} {{- end }} } {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} {{- else if eq .GoField "UpdateBy"}} model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的 {{- else if eq .IsInsert "1" }} model.{{.GoField}} = s.{{.GoField}} {{- end -}} {{- end }} } func (s *{{.ClassName}}UpdateReq) GetId() interface{} { return s.{{.PkGoField}} } // {{.ClassName}}GetReq 获取{{.FunctionName}}请求参数 type {{.ClassName}}GetReq struct { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} Id {{.GoType}} `uri:"id"` {{- end }} {{- end }} } func (s *{{.ClassName}}GetReq) GetId() interface{} { return s.Id } // {{.ClassName}}DeleteReq 删除{{.FunctionName}}请求参数 type {{.ClassName}}DeleteReq struct { Ids []int `json:"ids"` } func (s *{{.ClassName}}DeleteReq) GetId() interface{} { return s.Ids } // {{.ClassName}}Resp 获取{{.FunctionName}}响应参数 type {{.ClassName}}Resp struct { {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" }} {{.GoField}} int `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- else if eq .GoField "UpdateBy" -}} {{- else if eq .IsInsert "1"}} {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{- end -}} {{- end }} } func (s *{{.ClassName}}Resp) Generate(model *models.{{.ClassName}}) { {{- range .Columns -}} {{- if eq .GoField "CreatedAt" }} s.{{.GoField}} = model.{{.GoField}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" }} s.{{.GoField}} = model.{{.GoField}} {{- else if eq .GoField "UpdateBy" -}} {{- else if eq .IsInsert "1"}} s.{{.GoField}} = model.{{.GoField}} {{- end -}} {{- end }} }