event_cow_treatment.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. Remarks string `json:"remarks"`
  23. TreatmentAt int64 `json:"treatmentAt"`
  24. CreatedAt int64 `json:"createdAt"`
  25. UpdatedAt int64 `json:"updatedAt"`
  26. }
  27. func (e *EventCowTreatment) TableName() string {
  28. return "event_cow_treatment"
  29. }
  30. func NewEventCowTreatment(prescription *Prescription, req *pasturePb.CowTreatmentRequest, diseaseTypeMap map[int32]string, operation *SystemUser) *EventCowTreatment {
  31. b, _ := json.Marshal(req.PrescriptionDetail)
  32. return &EventCowTreatment{
  33. CowId: int64(req.CowId),
  34. CowDiseaseId: int64(req.Id),
  35. DiseaseId: int64(req.DiseaseId),
  36. DiseaseName: req.DiseaseName,
  37. DiseaseType: req.DiseaseType,
  38. DiseaseTypeName: diseaseTypeMap[req.DiseaseType],
  39. PrescriptionId: req.PrescriptionId,
  40. PrescriptionName: prescription.Name,
  41. PrescriptionDetail: string(b),
  42. TreatmentResult: req.TreatmentResult,
  43. OperationId: operation.Id,
  44. OperationName: operation.Name,
  45. Remarks: req.Remarks,
  46. }
  47. }
  48. type EventCowTreatmentSlice []*EventCowTreatment
  49. func (e EventCowTreatmentSlice) ToPB(eventCowDiseaseList []*EventCowDisease) []*pasturePb.EventCowTreatment {
  50. res := make([]*pasturePb.EventCowTreatment, len(e))
  51. for i, v := range e {
  52. prescriptionDetail := make([]*pasturePb.TreatmentDrugs, 0)
  53. if v.PrescriptionDetail != "" {
  54. err := json.Unmarshal([]byte(v.PrescriptionDetail), &prescriptionDetail)
  55. if err != nil {
  56. zaplog.Error("EventCowTreatmentSlice", zap.Any("err", err))
  57. }
  58. }
  59. eventCowTreatment := &pasturePb.EventCowTreatment{
  60. CowId: int32(v.CowId),
  61. CowDiseaseId: int32(v.CowDiseaseId),
  62. PrescriptionId: v.PrescriptionId,
  63. PrescriptionName: v.PrescriptionName,
  64. PrescriptionDetail: prescriptionDetail,
  65. TreatmentResult: 0,
  66. OperationId: int32(v.OperationId),
  67. OperationName: v.OperationName,
  68. Remarks: v.Remarks,
  69. CreatedAt: int32(v.CreatedAt),
  70. UpdatedAt: int32(v.UpdatedAt),
  71. DiseaseId: int32(v.DiseaseId),
  72. Id: int32(v.Id),
  73. }
  74. for _, d := range eventCowDiseaseList {
  75. if v.CowDiseaseId != d.Id {
  76. continue
  77. }
  78. eventCowTreatment.DiseaseName = d.DiseaseName
  79. eventCowTreatment.DiseaseAt = int32(d.DiseaseAt)
  80. }
  81. res[i] = eventCowTreatment
  82. }
  83. return res
  84. }