vo.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package syncer
  2. import (
  3. "encoding/json"
  4. "time"
  5. )
  6. const (
  7. SYNC_ACTION_INSERT = "Insert"
  8. SYNC_ACTION_UPDATE = "Update"
  9. SYNC_ACTION_DELETE = "Delete"
  10. // ClientPriceUpdate
  11. TYPE_CLIENT_PRICE_UPDATE = "ClientPriceUpdate"
  12. )
  13. type Model struct {
  14. ID uint64 `json:"id" gorm:"primary_key"`
  15. Type string `json:"type" gorm:"not null"`
  16. CreatedAt time.Time `json:"create_at"`
  17. UpdatedAt time.Time `json:"update_at"`
  18. }
  19. func (m Model) GetId() uint64 {
  20. return m.ID
  21. }
  22. func (m Model) GetType() string {
  23. return m.Type
  24. }
  25. type SyncLog struct {
  26. Model
  27. DataType string `json:"data_type"` // data type
  28. Data string `json:"data" sql:"type:varchar(5000)"` // data in json string
  29. Action string `json:"action"` // [Insert,Update,Delete]
  30. Synced bool `json:"synced"`
  31. }
  32. // Client data
  33. type ClientPriceUpdate struct {
  34. Model
  35. CompanyId uint64 `json:"company_id"` // only used by FOS
  36. StationId uint64 `json:"station_id"` // only used by FOS
  37. PriceUpdateId uint64 `json:"price_update_id"`
  38. GradeId uint64 `json:"grade_id"`
  39. GradeText string `json:"grade_text"`
  40. GradePrice uint64 `json:"grade_price"`
  41. NewGradePrice uint64 `json:"new_grade_price"`
  42. RecCreatedAt string `json:"rec_create_at"`
  43. RecUpdatedAt string `json:"rec_update_at"`
  44. }
  45. // Custom unmarshal for date time of the record
  46. func (s *ClientPriceUpdate) UnmarshalJSON(data []byte) error {
  47. var aux ClientPriceUpdate
  48. if err := json.Unmarshal(data, &aux); err != nil {
  49. return err
  50. }
  51. createdAt, e := time.Parse("2006-01-02 15:04:05.999999999-07:00", aux.RecCreatedAt)
  52. if e != nil {
  53. return e
  54. }
  55. updatedAt, e := time.Parse("2006-01-02 15:04:05.999999999-07:00", aux.RecUpdatedAt)
  56. if e != nil {
  57. return e
  58. }
  59. s.CreatedAt = createdAt
  60. s.UpdatedAt = updatedAt
  61. return nil
  62. }