dao.template 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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}}{{$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}}{{$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}}