123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package syncer
- import (
- "encoding/json"
- "time"
- )
- const (
- SYNC_ACTION_INSERT = "Insert"
- SYNC_ACTION_UPDATE = "Update"
- SYNC_ACTION_DELETE = "Delete"
-
- TYPE_CLIENT_PRICE_UPDATE = "ClientPriceUpdate"
- )
- type Model struct {
- ID uint64 `json:"id" gorm:"primary_key"`
- Type string `json:"type" gorm:"not null"`
- CreatedAt time.Time `json:"create_at"`
- UpdatedAt time.Time `json:"update_at"`
- }
- func (m Model) GetId() uint64 {
- return m.ID
- }
- func (m Model) GetType() string {
- return m.Type
- }
- type SyncLog struct {
- Model
- DataType string `json:"data_type"`
- Data string `json:"data" sql:"type:varchar(5000)"`
- Action string `json:"action"`
- Synced bool `json:"synced"`
- }
- type ClientPriceUpdate struct {
- Model
- CompanyId uint64 `json:"company_id"`
- StationId uint64 `json:"station_id"`
- PriceUpdateId uint64 `json:"price_update_id"`
- GradeId uint64 `json:"grade_id"`
- GradeText string `json:"grade_text"`
- GradePrice uint64 `json:"grade_price"`
- NewGradePrice uint64 `json:"new_grade_price"`
- RecCreatedAt time.Time `json:"rec_create_at"`
- RecUpdatedAt time.Time `json:"rec_update_at"`
- }
- func (s *ClientPriceUpdate) UnmarshalJSON(data []byte) error {
- type Alias ClientPriceUpdate
- aux := &struct {
- RecCreatedAt string `json:"rec_create_at"`
- RecUpdatedAt string `json:"rec_update_at"`
- *Alias
- }{
- Alias: (*Alias)(s),
- }
- if err := json.Unmarshal(data, &aux); err != nil {
- return err
- }
- createdAt, e := time.Parse("2006-01-02 15:04:05.999999999-07:00", aux.RecCreatedAt)
- if e != nil {
- return e
- }
- updatedAt, e := time.Parse("2006-01-02 15:04:05.999999999-07:00", aux.RecUpdatedAt)
- if e != nil {
- return e
- }
- s.RecCreatedAt = createdAt
- s.RecUpdatedAt = updatedAt
- return nil
- }
|