maintain_title.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package model
  2. import (
  3. "time"
  4. "git.getensh.com/common/gopkgsv2/database"
  5. "gorm.io/gorm"
  6. )
  7. type MaintainTitleModel interface {
  8. Get(db *gorm.DB) (*GdMaintainTitle, error)
  9. Insert(db *gorm.DB, data interface{}) error
  10. Update(db *gorm.DB, values interface{}) error
  11. Delete(db *gorm.DB) error
  12. }
  13. type GdMaintainTitle struct {
  14. ID int64 `gorm:"column:id" json:"id"`
  15. StyleId string `gorm:"column:style_id" json:"style_id"`
  16. StartMile int64 `gorm:"column:start_mile" json:"start_mile"`
  17. StartDate int64 `gorm:"column:start_date" json:"start_date"`
  18. MaintainMileMinCycle int64 `gorm:"column:maintain_mile_min_cycle" json:"maintain_mile_min_cycle"`
  19. MaintainDateMinCycle int64 `gorm:"column:maintain_date_min_cycle" json:"maintain_date_min_cycle"`
  20. WashCycle int64 `gorm:"column:wash_cycle" json:"wash_cycle"`
  21. RepairCycle int64 `gorm:"column:repair_cycle" json:"repair_cycle"`
  22. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  23. UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
  24. }
  25. type defalutMaintainTitleModel struct {
  26. tableName string
  27. fileds string
  28. }
  29. func NewMaintainTitleModel() MaintainTitleModel {
  30. return &defalutMaintainTitleModel{
  31. tableName: "db_adm_dws.t_adm_ads13",
  32. fileds: "id, style_id, start_mile, start_date, maintain_mile_min_cycle, maintain_date_min_cycle, wash_cycle, repair_cycle, created_at, updated_at",
  33. }
  34. }
  35. func (d *defalutMaintainTitleModel) Get(db *gorm.DB) (*GdMaintainTitle, error) {
  36. var res GdMaintainTitle
  37. err := database.Get(db, &res, database.Option{
  38. TableName: d.tableName,
  39. Fields: d.fileds,
  40. })
  41. return &res, err
  42. }
  43. func (d *defalutMaintainTitleModel) Insert(db *gorm.DB, data interface{}) error {
  44. return database.Create(db, data, database.Option{
  45. TableName: d.tableName,
  46. })
  47. }
  48. func (d *defalutMaintainTitleModel) Update(db *gorm.DB, values interface{}) error {
  49. return database.Update(db, values, database.Option{
  50. TableName: d.tableName,
  51. })
  52. }
  53. func (d *defalutMaintainTitleModel) Delete(db *gorm.DB) error {
  54. m := GdMaintainTitle{}
  55. return db.Table(d.tableName).Delete(&m).Error
  56. }