dao.template 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // ==========================================================================
  2. // GFast自动生成dao操作代码,无需手动修改,重新生成不会自动覆盖.
  3. // 生成日期:{{.table.CreateTime}}
  4. // 生成路径: {{.table.PackageName}}/dao/{{.table.TableName}}.go
  5. // 生成人:{{.table.FunctionAuthor}}
  6. // ==========================================================================
  7. package dao
  8. {{$hasGTime:=false}}
  9. {{range $index, $column := .table.Columns}}
  10. {{if and (eq $column.GoType "Time") (or (eq $column.IsInsert "1") (eq $column.IsEdit "1"))}}
  11. {{$hasGTime = true}}
  12. {{end}}
  13. {{end}}
  14. import (
  15. comModel "gfast/app/common/model"
  16. "{{.table.PackageName}}/dao/internal"
  17. {{if $hasGTime}}
  18. "github.com/gogf/gf/os/gtime"
  19. {{end}}
  20. )
  21. // {{.table.BusinessName | CaseCamelLower}}Dao is the manager for logic model data accessing and custom defined data operations functions management.
  22. // You can define custom methods on it to extend its functionality as you wish.
  23. type {{.table.BusinessName | CaseCamelLower}}Dao struct {
  24. *internal.{{.table.BusinessName | CaseCamel}}Dao
  25. }
  26. var (
  27. // {{.table.ClassName}} is globally public accessible object for table tools_gen_table operations.
  28. {{.table.ClassName}} = {{.table.BusinessName | CaseCamelLower}}Dao{
  29. internal.New{{.table.ClassName}}Dao(),
  30. }
  31. )
  32. // Fill with you ideas below.
  33. // {{.table.ClassName}}SearchReq 分页请求参数
  34. type {{.table.ClassName}}SearchReq struct {
  35. {{range $index, $column := .table.Columns}}
  36. {{if eq $column.IsQuery "1"}}
  37. {{$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}}
  38. {{end}}
  39. {{end}}
  40. comModel.PageReq
  41. }
  42. // {{.table.ClassName}}AddReq 添加操作请求参数
  43. type {{.table.ClassName}}AddReq struct {
  44. {{range $index, $column := .table.Columns}}
  45. {{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
  46. {{$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}}`
  47. {{end}}
  48. {{if eq $column.ColumnName "created_by"}}CreatedBy uint64 {{end}}
  49. {{end}}
  50. }
  51. // {{.table.ClassName}}EditReq 修改操作请求参数
  52. type {{.table.ClassName}}EditReq struct {
  53. {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
  54. {{range $index, $column := .table.Columns}}
  55. {{if eq $column.IsEdit "1"}}
  56. {{$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}}
  57. {{if eq $column.ColumnName "updated_by"}}UpdatedBy uint64 {{end}}
  58. {{end}}
  59. }
  60. {{range $index,$column:= .table.Columns}}
  61. {{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
  62. // {{$.table.ClassName}}{{$column.GoField}}Req 设置用户状态参数
  63. type {{$.table.ClassName}}{{$column.GoField}}Req struct {
  64. {{$.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"`
  65. {{$column.GoField}} {{$column.GoType}} `p:"{{$column.HtmlField}}" v:"required#{{$column.ColumnComment}}不能为空"`
  66. }
  67. {{end}}
  68. {{end}}