event_cow_treatment.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package model
  2. import (
  3. "encoding/json"
  4. "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  5. "go.uber.org/zap"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. )
  8. type EventCowTreatment struct {
  9. Id int64 `json:"id"`
  10. CowId int64 `json:"cowId"`
  11. CowDiseaseId int64 `json:"cowDiseaseId"`
  12. DiseaseId int64 `json:"diseaseId"`
  13. DiseaseName string `json:"diseaseName"`
  14. DiseaseType int32 `json:"diseaseType"`
  15. DiseaseTypeName string `json:"diseaseTypeName"`
  16. PrescriptionId int32 `json:"prescriptionId"`
  17. PrescriptionName string `json:"prescriptionName"`
  18. PrescriptionDetail string `json:"prescriptionDetail"`
  19. TreatmentResult pasturePb.TreatmentResult_Kind `json:"treatmentResult"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. MessageId int64 `json:"messageId"`
  23. MessageName string `json:"messageName"`
  24. Remarks string `json:"remarks"`
  25. TreatmentAt int64 `json:"treatmentAt"`
  26. CreatedAt int64 `json:"createdAt"`
  27. UpdatedAt int64 `json:"updatedAt"`
  28. }
  29. func (e *EventCowTreatment) TableName() string {
  30. return "event_cow_treatment"
  31. }
  32. func NewEventCowTreatment(
  33. prescription *Prescription,
  34. req *pasturePb.CowTreatmentRequest,
  35. diseaseTypeMap map[int32]string,
  36. operation, currentUser *SystemUser,
  37. ) *EventCowTreatment {
  38. b, _ := json.Marshal(req.PrescriptionDetail)
  39. return &EventCowTreatment{
  40. CowId: int64(req.CowId),
  41. CowDiseaseId: int64(req.Id),
  42. DiseaseId: int64(req.DiseaseId),
  43. DiseaseName: req.DiseaseName,
  44. DiseaseType: req.DiseaseType,
  45. DiseaseTypeName: diseaseTypeMap[req.DiseaseType],
  46. PrescriptionId: req.PrescriptionId,
  47. PrescriptionName: prescription.Name,
  48. PrescriptionDetail: string(b),
  49. TreatmentResult: req.TreatmentResult,
  50. OperationId: operation.Id,
  51. OperationName: operation.Name,
  52. MessageId: currentUser.Id,
  53. MessageName: currentUser.Name,
  54. Remarks: req.Remarks,
  55. }
  56. }
  57. type EventCowTreatmentSlice []*EventCowTreatment
  58. func (e EventCowTreatmentSlice) ToPB(eventCowDiseaseList []*EventCowDisease) []*pasturePb.EventCowTreatment {
  59. res := make([]*pasturePb.EventCowTreatment, len(e))
  60. for i, v := range e {
  61. prescriptionDetail := make([]*pasturePb.PrescriptionDrugsList, 0)
  62. if v.PrescriptionDetail != "" {
  63. err := json.Unmarshal([]byte(v.PrescriptionDetail), &prescriptionDetail)
  64. if err != nil {
  65. zaplog.Error("EventCowTreatmentSlice", zap.Any("err", err))
  66. }
  67. }
  68. eventCowTreatment := &pasturePb.EventCowTreatment{
  69. CowId: int32(v.CowId),
  70. CowDiseaseId: int32(v.CowDiseaseId),
  71. PrescriptionId: v.PrescriptionId,
  72. PrescriptionName: v.PrescriptionName,
  73. PrescriptionDetail: prescriptionDetail,
  74. TreatmentResult: 0,
  75. OperationId: int32(v.OperationId),
  76. OperationName: v.OperationName,
  77. Remarks: v.Remarks,
  78. CreatedAt: int32(v.CreatedAt),
  79. UpdatedAt: int32(v.UpdatedAt),
  80. DiseaseId: int32(v.DiseaseId),
  81. Id: int32(v.Id),
  82. }
  83. for _, d := range eventCowDiseaseList {
  84. if v.CowDiseaseId != d.Id {
  85. continue
  86. }
  87. eventCowTreatment.DiseaseName = d.DiseaseName
  88. eventCowTreatment.DiseaseAt = int32(d.DiseaseAt)
  89. }
  90. res[i] = eventCowTreatment
  91. }
  92. return res
  93. }