event_cow_disease.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventCowDisease struct {
  7. Id int64 `json:"id"`
  8. CowId int64 `json:"cowId"`
  9. CowType pasturePb.CowType_Kind `json:"cowType"`
  10. Lact int32 `json:"lact"`
  11. DayAge int32 `json:"dayAge"`
  12. DiseaseId int32 `json:"diseaseId"`
  13. DiseaseName string `json:"diseaseName"`
  14. DiseaseType int32 `json:"diseaseType"`
  15. DiseaseTypeName string `json:"diseaseTypeName"`
  16. DiagnoseId int32 `json:"diagnoseId"`
  17. DiagnoseName string `json:"diagnoseName"`
  18. PenId int32 `json:"penId"`
  19. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"`
  20. DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"`
  21. DiagnosedAt int64 `json:"diagnosedAt"`
  22. DiseaseAt int64 `json:"diseaseAt"`
  23. Temperature int32 `json:"temperature"`
  24. Remarks string `json:"remarks"`
  25. OperationId int32 `json:"operationId"`
  26. OperationName string `json:"operationName"`
  27. MessageId int32 `json:"messageId"`
  28. MessageName string `json:"messageName"`
  29. DiagnoseOperationId int32 `json:"diagnoseOperationId"`
  30. DiagnoseOperationName string `json:"diagnoseOperationName"`
  31. CurableAt int64 `json:"curableAt"`
  32. Source string `json:"source"`
  33. CreatedAt int64 `json:"createdAt"`
  34. UpdatedAt int64 `json:"updatedAt"`
  35. }
  36. func (e *EventCowDisease) TableName() string {
  37. return "event_cow_disease"
  38. }
  39. // EventUnDiseaseUpdate 诊断未生病
  40. func (e *EventCowDisease) EventUnDiseaseUpdate(operation *SystemUser, remarks string) {
  41. e.DiagnosedResult = pasturePb.IsShow_No
  42. e.DiagnoseOperationId = int32(operation.Id)
  43. e.DiagnoseOperationName = operation.Name
  44. e.Remarks = remarks
  45. }
  46. // EventDiseaseUpdate 诊断有生病
  47. func (e *EventCowDisease) EventDiseaseUpdate(disease *Disease, operationUser *SystemUser, temp float32) {
  48. e.HealthStatus = pasturePb.HealthStatus_Disease
  49. e.DiagnosedResult = pasturePb.IsShow_Ok
  50. e.DiagnoseId = int32(disease.Id)
  51. e.DiagnoseName = disease.Name
  52. e.Temperature = int32(temp * 100)
  53. e.DiagnoseOperationId = int32(operationUser.Id)
  54. e.DiagnoseOperationName = operationUser.Name
  55. e.DiseaseAt = time.Now().Unix()
  56. }
  57. // EventHealthStatusUpdate 改变健康状态
  58. func (e *EventCowDisease) EventHealthStatusUpdate(healthStatus pasturePb.HealthStatus_Kind) {
  59. e.HealthStatus = healthStatus
  60. }
  61. // EventCurableUpdate 治愈
  62. func (e *EventCowDisease) EventCurableUpdate(cureAt int64) {
  63. e.HealthStatus = pasturePb.HealthStatus_Curable
  64. e.CurableAt = cureAt
  65. e.DiagnosedResult = pasturePb.IsShow_Ok
  66. }
  67. func NewEventCowDisease(cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation, currUser *SystemUser) *EventCowDisease {
  68. return &EventCowDisease{
  69. CowId: cow.Id,
  70. CowType: cow.CowType,
  71. Lact: cow.Lact,
  72. DayAge: cow.DayAge,
  73. DiseaseId: int32(disease.Id),
  74. DiseaseName: disease.Name,
  75. DiseaseType: disease.DiseaseType,
  76. DiseaseTypeName: disease.DiseaseTypeName,
  77. PenId: req.PenId,
  78. HealthStatus: pasturePb.HealthStatus_Health,
  79. DiseaseAt: int64(req.DiseaseAt),
  80. Temperature: int32(req.Temperature * 10),
  81. OperationId: int32(operation.Id),
  82. OperationName: operation.Name,
  83. MessageId: int32(currUser.Id),
  84. MessageName: currUser.Name,
  85. Remarks: req.Remarks,
  86. DiagnosedResult: pasturePb.IsShow_No,
  87. Source: SourceApp,
  88. DiagnosedAt: int64(req.DiseaseAt),
  89. }
  90. }
  91. type EventCowDiseaseSlice []*EventCowDisease
  92. func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease {
  93. res := make([]*pasturePb.EventCowDisease, len(e))
  94. for i, v := range e {
  95. res[i] = &pasturePb.EventCowDisease{
  96. Id: int32(v.Id),
  97. CowId: int32(v.CowId),
  98. Lact: v.Lact,
  99. DayAge: v.DayAge,
  100. DiseaseId: v.DiseaseId,
  101. DiseaseName: v.DiseaseName,
  102. DiagnoseId: v.DiagnoseId,
  103. DiagnoseName: v.DiagnoseName,
  104. PenId: v.PenId,
  105. HealthStatus: v.HealthStatus,
  106. HealthStatusName: healthStatusMap[v.HealthStatus],
  107. Temperature: float32(v.HealthStatus / 10),
  108. DiseaseAt: int32(v.DiseaseAt),
  109. Remarks: v.Remarks,
  110. OperationId: v.OperationId,
  111. OperationName: v.OperationName,
  112. }
  113. }
  114. return res
  115. }