maintain_title_template.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package model
  2. import (
  3. "time"
  4. "git.getensh.com/common/gopkgsv2/database"
  5. "gorm.io/gorm"
  6. )
  7. type MaintenanceTitleTemplateModel interface {
  8. Insert(db *gorm.DB, data interface{}) error
  9. Count(db *gorm.DB) (int64, error)
  10. List(db *gorm.DB, pagination *Pagination) ([]MaintenanceTitleTemplate, error)
  11. Get(db *gorm.DB) (*MaintenanceTitleTemplate, error)
  12. Update(db *gorm.DB, values interface{}) error
  13. }
  14. type MaintenanceTitleTemplate struct {
  15. ID int64 `gorm:"column:id" json:"id"`
  16. Tid int64 `gorm:"column:tid" json:"tid"`
  17. StartMile int64 `gorm:"column:start_mile" json:"start_mile"`
  18. StartDate int64 `gorm:"column:start_date" json:"start_date"`
  19. MaintainMileMinCycle int64 `gorm:"column:maintain_mile_min_cycle" json:"maintain_mile_min_cycle"`
  20. MaintainDateMinCycle int64 `gorm:"column:maintain_date_min_cycle" json:"maintain_date_min_cycle"`
  21. WashCycle int64 `gorm:"column:wash_cycle" json:"wash_cycle"`
  22. RepairCycle int64 `gorm:"column:repair_cycle" json:"repair_cycle"`
  23. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  24. UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
  25. }
  26. type defaultMaintenanceTitleTemplateModel struct {
  27. tableName string
  28. fields string
  29. }
  30. func NewMaintenanceTitleTemplateModel() MaintenanceTitleTemplateModel {
  31. return &defaultMaintenanceTitleTemplateModel{
  32. "db_adm_management.t_adm_maintenance_title_template",
  33. "id, tid, start_mile, start_date, maintain_mile_min_cycle, maintain_date_min_cycle, wash_cycle, repair_cycle, created_at, updated_at",
  34. }
  35. }
  36. func (d *defaultMaintenanceTitleTemplateModel) Insert(db *gorm.DB, data interface{}) error {
  37. return database.Create(db, data, database.Option{
  38. TableName: d.tableName,
  39. })
  40. }
  41. func (d *defaultMaintenanceTitleTemplateModel) Count(db *gorm.DB) (int64, error) {
  42. return database.Count(db, database.Option{
  43. TableName: d.tableName,
  44. })
  45. }
  46. func (d *defaultMaintenanceTitleTemplateModel) List(db *gorm.DB, pagination *Pagination) ([]MaintenanceTitleTemplate, error) {
  47. var res []MaintenanceTitleTemplate
  48. err := database.List(db, &res, database.Option{
  49. TableName: d.tableName,
  50. Fields: d.fields,
  51. Limit: pagination.Limit,
  52. OffSet: pagination.Offset,
  53. })
  54. return res, err
  55. }
  56. func (d *defaultMaintenanceTitleTemplateModel) Get(db *gorm.DB) (*MaintenanceTitleTemplate, error) {
  57. var res MaintenanceTitleTemplate
  58. err := database.Get(db, &res, database.Option{
  59. TableName: d.tableName,
  60. Fields: d.fields,
  61. })
  62. return &res, err
  63. }
  64. func (d *defaultMaintenanceTitleTemplateModel) Update(db *gorm.DB, values interface{}) error {
  65. return database.Update(db, values, database.Option{
  66. TableName: d.tableName,
  67. })
  68. }