event_cow_disease.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. Lact int32 `json:"lact"`
  7. DayAge int32 `json:"dayAge"`
  8. DiseaseId int32 `json:"diseaseId"`
  9. DiseaseName string `json:"diseaseName"`
  10. DiagnoseId int32 `json:"diagnoseId"`
  11. DiagnoseName string `json:"diagnoseName"`
  12. PenId int32 `json:"penId"`
  13. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"`
  14. DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"`
  15. DiseaseAt int64 `json:"diseaseAt"`
  16. Temperature int32 `json:"temperature"`
  17. Remarks string `json:"remarks"`
  18. OperationId int32 `json:"operationId"`
  19. OperationName string `json:"operationName"`
  20. DiagnoseOperationId int32 `json:"diagnoseOperationId"`
  21. DiagnoseOperationName string `json:"diagnoseOperationName"`
  22. CurableAt int64 `json:"curableAt"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (e *EventCowDisease) TableName() string {
  27. return "event_cow_disease"
  28. }
  29. func NewEventCowDisease(cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation *SystemUser) *EventCowDisease {
  30. return &EventCowDisease{
  31. CowId: cow.Id,
  32. Lact: cow.Lact,
  33. DayAge: cow.DayAge,
  34. DiseaseId: int32(disease.Id),
  35. DiseaseName: disease.Name,
  36. PenId: req.PenId,
  37. HealthStatus: pasturePb.HealthStatus_Health,
  38. DiseaseAt: int64(req.DiseaseAt),
  39. Temperature: int32(req.Temperature * 10),
  40. OperationId: int32(operation.Id),
  41. OperationName: operation.Name,
  42. Remarks: req.Remarks,
  43. }
  44. }
  45. type EventCowDiseaseSlice []*EventCowDisease
  46. func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease {
  47. res := make([]*pasturePb.EventCowDisease, len(e))
  48. for i, v := range e {
  49. res[i] = &pasturePb.EventCowDisease{
  50. Id: int32(v.Id),
  51. CowId: int32(v.CowId),
  52. Lact: v.Lact,
  53. DayAge: v.DayAge,
  54. DiseaseId: v.DiseaseId,
  55. DiseaseName: v.DiseaseName,
  56. DiagnoseId: v.DiagnoseId,
  57. DiagnoseName: v.DiagnoseName,
  58. PenId: v.PenId,
  59. HealthStatus: v.HealthStatus,
  60. HealthStatusName: healthStatusMap[v.HealthStatus],
  61. Temperature: float32(v.HealthStatus / 10),
  62. DiseaseAt: int32(v.DiseaseAt),
  63. Remarks: v.Remarks,
  64. OperationId: v.OperationId,
  65. OperationName: v.OperationName,
  66. }
  67. }
  68. return res
  69. }