lift_base_info.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "github.com/jaryhe/gopkgs/database"
  6. "github.com/jinzhu/gorm"
  7. "time"
  8. "lift-monitor/model"
  9. )
  10. func LiftFrameBaseInfoWrite(record *model.LiftBaseInfo) error {
  11. p := &model.LiftBaseInfo{}
  12. where := map[string]interface{}{
  13. "SN": record.SN,
  14. "LiftNo": record.LiftNo,
  15. "LiftDirect":record.LiftDirect,
  16. "ProjectID": record.ProjectID,
  17. }
  18. err := p.Find(database.DB(), where)
  19. if err != nil && err != gorm.ErrRecordNotFound {
  20. return err
  21. }
  22. if p.ID == 0 {
  23. record.CreatedAt = time.Now()
  24. record.UpdatedAt = record.CreatedAt
  25. return record.Insert(database.DB())
  26. }
  27. values := map[string]interface{}{
  28. "EmptyWeightAD":record.EmptyWeightAD,
  29. "EmptyWeight":record.EmptyWeight,
  30. "LoadWeightAD":record.LoadWeightAD,
  31. "LoadWeight":record.LoadWeight,
  32. "LowHighAD":record.LowHighAD,
  33. "LowHigh":record.LowHigh,
  34. "TopHighAD":record.TopHighAD,
  35. "TopHigh":record.TopHigh,
  36. "CreatedAt": time.Now(),
  37. }
  38. where = map[string]interface{}{
  39. "ID": p.ID,
  40. }
  41. return p.Update(database.DB(), where, values)
  42. }
  43. // 暂时保留
  44. func LiftFrameBaseInfoRequestHandle(sn string, liftNo byte, version byte, data []byte) (res []byte, err error) {
  45. return nil, nil
  46. }