dao.template 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // ==========================================================================
  2. // GFast自动生成dao操作代码,无需手动修改,重新生成不会自动覆盖.
  3. // 生成日期:{{.table.CreateTime}}
  4. // 生成路径: {{.table.PackageName}}/dao/{{.table.TableName}}.go
  5. // 生成人:{{.table.FunctionAuthor}}
  6. // ==========================================================================
  7. ////
  8. package dao
  9. {{$hasGTime:=false}}
  10. {{range $index, $column := .table.Columns}}
  11. {{if eq $column.GoType "Time"}}
  12. {{$hasGTime = true}}
  13. {{end}}
  14. {{end}}
  15. import (
  16. comModel "gfast/app/common/model"
  17. "{{.table.PackageName}}/dao/internal"
  18. {{if $hasGTime}}
  19. "github.com/gogf/gf/os/gtime"
  20. {{end}}
  21. )
  22. // {{.table.BusinessName | CaseCamelLower}}Dao is the manager for logic model data accessing and custom defined data operations functions management.
  23. // You can define custom methods on it to extend its functionality as you wish.
  24. type {{.table.BusinessName | CaseCamelLower}}Dao struct {
  25. *internal.{{.table.BusinessName | CaseCamel}}Dao
  26. }
  27. var (
  28. // {{.table.ClassName}} is globally public accessible object for table tools_gen_table operations.
  29. {{.table.ClassName}} = {{.table.BusinessName | CaseCamelLower}}Dao{
  30. internal.New{{.table.ClassName}}Dao(),
  31. }
  32. )
  33. ////
  34. // Fill with you ideas below.
  35. ////
  36. // {{.table.ClassName}}SearchReq 分页请求参数
  37. type {{.table.ClassName}}SearchReq struct {
  38. {{range $index, $column := .table.Columns}}
  39. {{if eq $column.IsQuery "1"}}
  40. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64")}}string{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}"` //{{$column.ColumnComment}}
  41. {{end}}
  42. {{end}}
  43. comModel.PageReq
  44. }
  45. // {{.table.ClassName}}AddReq 添加操作请求参数
  46. type {{.table.ClassName}}AddReq struct {
  47. {{range $index, $column := .table.Columns}}
  48. {{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
  49. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if eq $column.IsRequired "1"}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}`
  50. {{end}}
  51. {{if eq $column.ColumnName "created_by"}}CreatedBy uint64 {{end}}
  52. {{end}}
  53. }
  54. // {{.table.ClassName}}EditReq 修改操作请求参数
  55. type {{.table.ClassName}}EditReq struct {
  56. {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
  57. {{range $index, $column := .table.Columns}}
  58. {{if eq $column.IsEdit "1"}}
  59. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if eq $column.IsRequired "1"}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}`{{end}}
  60. {{if eq $column.ColumnName "updated_by"}}UpdatedBy uint64 {{end}}
  61. {{end}}
  62. }
  63. {{range $index,$column:= .table.Columns}}
  64. {{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
  65. // {{$.table.ClassName}}{{$column.GoField}}Req 设置状态参数
  66. type {{$.table.ClassName}}{{$column.GoField}}Req struct {
  67. {{$.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
  68. {{$column.GoField}} {{$column.GoType}} `p:"{{$column.HtmlField}}" v:"required#{{$column.ColumnComment}}不能为空"`
  69. }
  70. {{end}}
  71. {{end}}
  72. // {{.table.ClassName}}ListRes 列表返回结果
  73. type {{.table.ClassName}}ListRes struct {
  74. {{if eq .table.TplCategory "tree"}}
  75. {{range $index, $column := .table.Columns}}
  76. {{if or (eq $column.HtmlField $.table.TreeCode) (eq $column.HtmlField $.table.TreeParentCode) (eq $column.HtmlField $.table.TreeName) }}
  77. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}"`
  78. {{end}}
  79. {{end}}
  80. {{range $index, $column := .table.Columns}}
  81. {{if and (eq $column.IsList "1") (ne $column.HtmlField $.table.TreeCode) (ne $column.HtmlField $.table.TreeParentCode) (ne $column.HtmlField $.table.TreeName) }}
  82. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}"`
  83. {{end}}
  84. {{end}}
  85. {{else}}
  86. {{range $index, $column := .table.Columns}}
  87. {{if or (eq $column.IsList "1") (eq $column.IsPk "1") }}
  88. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}"`
  89. {{end}}
  90. {{end}}
  91. {{end}}
  92. }
  93. // {{.table.ClassName}}InfoRes 数据返回结果
  94. type {{.table.ClassName}}InfoRes struct {
  95. {{range $index, $column := .table.Columns}}
  96. {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}"`
  97. {{end}}
  98. }