event_cow_disease.go 5.3 KB

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