event_cow_disease.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. PenId int32 `json:"penId"`
  15. PenName string `json:"penName"`
  16. DiseaseId int32 `json:"diseaseId"`
  17. DiseaseName string `json:"diseaseName"`
  18. DiseaseType int32 `json:"diseaseType"`
  19. DiseaseTypeName string `json:"diseaseTypeName"`
  20. DiagnoseId int32 `json:"diagnoseId"`
  21. DiagnoseName string `json:"diagnoseName"`
  22. HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"`
  23. DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"`
  24. DiagnosedAt int64 `json:"diagnosedAt"`
  25. DiseaseAt int64 `json:"diseaseAt"`
  26. FirstTreatmentAt int64 `json:"firstTreatmentAt"`
  27. LastTreatmentAt int64 `json:"lastTreatmentAt"`
  28. LastPrescriptionName string `json:"LastPrescriptionName"`
  29. Temperature int32 `json:"temperature"`
  30. Remarks string `json:"remarks"`
  31. OperationId int32 `json:"operationId"`
  32. OperationName string `json:"operationName"`
  33. MessageId int32 `json:"messageId"`
  34. MessageName string `json:"messageName"`
  35. DiagnoseOperationId int32 `json:"diagnoseOperationId"`
  36. DiagnoseOperationName string `json:"diagnoseOperationName"`
  37. CurableAt int64 `json:"curableAt"`
  38. Source string `json:"source"`
  39. CreatedAt int64 `json:"createdAt"`
  40. UpdatedAt int64 `json:"updatedAt"`
  41. }
  42. func (e *EventCowDisease) TableName() string {
  43. return "event_cow_disease"
  44. }
  45. // EventUnDiseaseUpdate 诊断未生病
  46. func (e *EventCowDisease) EventUnDiseaseUpdate(operation *SystemUser, remarks string) {
  47. e.DiagnosedResult = pasturePb.IsShow_No
  48. e.DiagnoseOperationId = int32(operation.Id)
  49. e.DiagnoseOperationName = operation.Name
  50. e.Remarks = remarks
  51. }
  52. // EventDiseaseUpdate 诊断有生病
  53. func (e *EventCowDisease) EventDiseaseUpdate(disease *Disease, operationUser *SystemUser, temp float32) {
  54. e.HealthStatus = pasturePb.HealthStatus_Disease
  55. e.DiagnosedResult = pasturePb.IsShow_Ok
  56. e.DiagnoseId = int32(disease.Id)
  57. e.DiagnoseName = disease.Name
  58. e.Temperature = int32(temp * 100)
  59. e.DiagnoseOperationId = int32(operationUser.Id)
  60. e.DiagnoseOperationName = operationUser.Name
  61. e.DiseaseAt = time.Now().Unix()
  62. }
  63. // EventTreatmentUpdate 治疗更新
  64. func (e *EventCowDisease) EventTreatmentUpdate(healthStatus pasturePb.HealthStatus_Kind, treatmentAt int64, prescriptionName string) {
  65. if e.FirstTreatmentAt <= 0 {
  66. e.FirstTreatmentAt = treatmentAt
  67. }
  68. e.LastTreatmentAt = treatmentAt
  69. e.LastPrescriptionName = prescriptionName
  70. e.HealthStatus = healthStatus
  71. }
  72. // EventCurableUpdate 治愈
  73. func (e *EventCowDisease) EventCurableUpdate(cureAt int64) {
  74. e.HealthStatus = pasturePb.HealthStatus_Curable
  75. e.CurableAt = cureAt
  76. e.DiagnosedResult = pasturePb.IsShow_Ok
  77. }
  78. func NewEventCowDisease(pastureId int64, cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation, currUser *SystemUser) *EventCowDisease {
  79. return &EventCowDisease{
  80. PastureId: pastureId,
  81. CowId: cow.Id,
  82. EarNumber: cow.EarNumber,
  83. CowType: cow.CowType,
  84. Lact: cow.Lact,
  85. DayAge: cow.DayAge,
  86. DiseaseId: int32(disease.Id),
  87. DiseaseName: disease.Name,
  88. DiseaseType: disease.DiseaseType,
  89. DiseaseTypeName: disease.DiseaseTypeName,
  90. PenId: cow.PenId,
  91. PenName: cow.PenName,
  92. HealthStatus: pasturePb.HealthStatus_Health,
  93. DiseaseAt: int64(req.DiseaseAt),
  94. Temperature: int32(req.Temperature * 10),
  95. OperationId: int32(operation.Id),
  96. OperationName: operation.Name,
  97. MessageId: int32(currUser.Id),
  98. MessageName: currUser.Name,
  99. Remarks: req.Remarks,
  100. DiagnosedResult: pasturePb.IsShow_No,
  101. Source: SourceApp,
  102. DiagnosedAt: int64(req.DiseaseAt),
  103. }
  104. }
  105. type EventCowDiseaseSlice []*EventCowDisease
  106. func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease {
  107. res := make([]*pasturePb.EventCowDisease, len(e))
  108. for i, v := range e {
  109. lastTreatedTimeFormat := ""
  110. if v.LastTreatmentAt > 0 {
  111. lastTreatedTimeFormat = time.Unix(v.LastTreatmentAt, 0).Format(LayoutDate2)
  112. }
  113. onsetDays := int32(0)
  114. if v.FirstTreatmentAt > 0 {
  115. firstTime := time.Unix(v.FirstTreatmentAt, 0)
  116. diff := time.Now().Sub(firstTime)
  117. onsetDays = int32(diff.Hours() / 24)
  118. }
  119. res[i] = &pasturePb.EventCowDisease{
  120. Id: int32(v.Id),
  121. CowId: int32(v.CowId),
  122. EarNumber: v.EarNumber,
  123. Lact: v.Lact,
  124. DayAge: v.DayAge,
  125. DiseaseId: v.DiseaseId,
  126. DiseaseName: v.DiseaseName,
  127. DiagnoseId: v.DiagnoseId,
  128. DiagnoseName: v.DiagnoseName,
  129. PenId: v.PenId,
  130. PenName: v.PenName,
  131. HealthStatus: v.HealthStatus,
  132. HealthStatusName: healthStatusMap[v.HealthStatus],
  133. Temperature: float32(v.HealthStatus / 10),
  134. DiseaseAt: int32(v.DiseaseAt),
  135. Remarks: v.Remarks,
  136. OperationId: v.OperationId,
  137. OperationName: v.OperationName,
  138. LastPrescriptionName: v.LastPrescriptionName,
  139. LastTreatedTimeFormat: lastTreatedTimeFormat,
  140. OnsetDays: onsetDays,
  141. }
  142. }
  143. return res
  144. }