event_cow_disease.go 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventCowDisease struct {
  4. Id int64 `json:"id"`
  5. CowId int64 `json:"cowId"`
  6. CowType pasturePb.CowType_Kind `json:"cowType"`
  7. Lact int32 `json:"lact"`
  8. DayAge int32 `json:"dayAge"`
  9. DiseaseId int32 `json:"diseaseId"`
  10. DiseaseName string `json:"diseaseName"`
  11. DiseaseType int32 `json:"diseaseType"`
  12. DiseaseTypeName string `json:"diseaseTypeName"`
  13. DiagnoseId int32 `json:"diagnoseId"`
  14. DiagnoseName string `json:"diagnoseName"`
  15. PenId int32 `json:"penId"`
  16. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"`
  17. DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"`
  18. DiagnosedAt int64 `json:"diagnosedAt"`
  19. DiseaseAt int64 `json:"diseaseAt"`
  20. Temperature int32 `json:"temperature"`
  21. Remarks string `json:"remarks"`
  22. OperationId int32 `json:"operationId"`
  23. OperationName string `json:"operationName"`
  24. MessageId int32 `json:"messageId"`
  25. MessageName string `json:"messageName"`
  26. DiagnoseOperationId int32 `json:"diagnoseOperationId"`
  27. DiagnoseOperationName string `json:"diagnoseOperationName"`
  28. CurableAt int64 `json:"curableAt"`
  29. CreatedAt int64 `json:"createdAt"`
  30. UpdatedAt int64 `json:"updatedAt"`
  31. }
  32. func (e *EventCowDisease) TableName() string {
  33. return "event_cow_disease"
  34. }
  35. func NewEventCowDisease(cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation, currUser *SystemUser) *EventCowDisease {
  36. return &EventCowDisease{
  37. CowId: cow.Id,
  38. CowType: cow.CowType,
  39. Lact: cow.Lact,
  40. DayAge: cow.DayAge,
  41. DiseaseId: int32(disease.Id),
  42. DiseaseName: disease.Name,
  43. DiseaseType: disease.DiseaseType,
  44. DiseaseTypeName: disease.DiseaseTypeName,
  45. PenId: req.PenId,
  46. HealthStatus: pasturePb.HealthStatus_Health,
  47. DiseaseAt: int64(req.DiseaseAt),
  48. Temperature: int32(req.Temperature * 10),
  49. OperationId: int32(operation.Id),
  50. OperationName: operation.Name,
  51. MessageId: int32(currUser.Id),
  52. MessageName: currUser.Name,
  53. Remarks: req.Remarks,
  54. }
  55. }
  56. type EventCowDiseaseSlice []*EventCowDisease
  57. func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease {
  58. res := make([]*pasturePb.EventCowDisease, len(e))
  59. for i, v := range e {
  60. res[i] = &pasturePb.EventCowDisease{
  61. Id: int32(v.Id),
  62. CowId: int32(v.CowId),
  63. Lact: v.Lact,
  64. DayAge: v.DayAge,
  65. DiseaseId: v.DiseaseId,
  66. DiseaseName: v.DiseaseName,
  67. DiagnoseId: v.DiagnoseId,
  68. DiagnoseName: v.DiagnoseName,
  69. PenId: v.PenId,
  70. HealthStatus: v.HealthStatus,
  71. HealthStatusName: healthStatusMap[v.HealthStatus],
  72. Temperature: float32(v.HealthStatus / 10),
  73. DiseaseAt: int32(v.DiseaseAt),
  74. Remarks: v.Remarks,
  75. OperationId: v.OperationId,
  76. OperationName: v.OperationName,
  77. }
  78. }
  79. return res
  80. }