tmr_gear.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package models
  2. import (
  3. "fmt"
  4. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  5. "sort"
  6. "time"
  7. )
  8. type TmrGear struct {
  9. Id int64 `json:"id"`
  10. TmrId int64 `json:"tmr_id"`
  11. Gear string `json:"name"`
  12. Rev int64 `json:"rev"`
  13. CreatedAt int64 `json:"created_at"`
  14. UpdatedAt int64 `json:"updated_at"`
  15. }
  16. func (t *TmrGear) TableName() string {
  17. return "tmr_gear"
  18. }
  19. func NewTmrGearList(tmrId int64, req *operationPb.UpdateOrCreateTmrGearRequest) []*TmrGear {
  20. sort.Slice(req.Params, func(i, j int) bool {
  21. return req.Params[i].Rev < req.Params[j].Rev
  22. })
  23. res := make([]*TmrGear, len(req.Params))
  24. for i, v := range req.Params {
  25. res[i] = &TmrGear{
  26. TmrId: tmrId,
  27. Gear: fmt.Sprintf("%d", i+1),
  28. Rev: int64(v.Rev),
  29. CreatedAt: time.Now().Unix(),
  30. UpdatedAt: time.Now().Unix(),
  31. }
  32. }
  33. return res
  34. }
  35. type TmrGearDetail struct {
  36. BCode string `json:"bcode"`
  37. CCount int32 `json:"ccount"`
  38. FName string `json:"fname"`
  39. GearRate float64 `json:"gear_rate"`
  40. Length int32 `json:"length"`
  41. Sort int32 `json:"sort"`
  42. Speed float64 `json:"speed"`
  43. UseInBar string `json:"useinbar"`
  44. Weight float64 `json:"weight"`
  45. Pid int64 `json:"pid"`
  46. FBarid int64 `json:"fbarid"`
  47. }