event_cow_log.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package model
  2. import (
  3. "fmt"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. const ShardTableNumber = 6
  7. type EventCowLog struct {
  8. Id int64 `json:"id"`
  9. CowId int64 `json:"cowId"`
  10. DayAge int32 `json:"dayAge"`
  11. Lact int32 `json:"lact"`
  12. PenId int32 `json:"penId"`
  13. PenName string `json:"penName"`
  14. CowType pasturePb.CowType_Kind `json:"cowType"`
  15. CowTypeName string `json:"cowTypeName"`
  16. EventType int64 `json:"eventType"`
  17. EventTypeName string `json:"eventTypeName"`
  18. EventDescription string `json:"eventDescription"`
  19. OperationId int64 `json:"operationId"`
  20. OperationName string `json:"operationName"`
  21. EventAt string `json:"eventAt"`
  22. Remarks string `json:"remarks"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (e *EventCowLog) UnShardTableName() string {
  27. return "event_cow_log"
  28. }
  29. // TableName 表名
  30. func (e *EventCowLog) TableName() string {
  31. return fmt.Sprintf("%s_%04d", e.UnShardTableName(), e.CowId%ShardTableNumber)
  32. }
  33. func NewCowEventLog(cow *Cow, penMap map[int32]*Pen, cowType map[pasturePb.CowType_Kind]string, operation *SystemUser) *EventCowLog {
  34. penName := ""
  35. if pen, ok := penMap[cow.PenId]; ok {
  36. penName = pen.Name
  37. }
  38. return &EventCowLog{
  39. CowId: cow.Id,
  40. DayAge: cow.GetDayAge(),
  41. Lact: cow.Lact,
  42. PenId: cow.PenId,
  43. PenName: penName,
  44. CowType: cow.CowType,
  45. CowTypeName: cowType[cow.CowType],
  46. EventType: 0,
  47. EventTypeName: "",
  48. EventDescription: "",
  49. OperationId: operation.Id,
  50. OperationName: operation.Name,
  51. EventAt: "",
  52. Remarks: "",
  53. }
  54. }