prescription.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package model
  2. import (
  3. "strconv"
  4. "strings"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type Prescription struct {
  8. Id int32 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. Name string `json:"name"`
  11. ApplicableDisease string `json:"applicableDisease"`
  12. UseDays int32 `json:"useDays"`
  13. UseCount int32 `json:"useCount"`
  14. MeatExpiredDays int32 `json:"meatExpiredDays"`
  15. MilkExpiredDays int32 `json:"milkExpiredDays"`
  16. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  17. Remarks string `json:"remarks"`
  18. OperationId int64 `json:"operationId"`
  19. OperationName string `json:"operationName"`
  20. CreatedAt int64 `json:"createdAt"`
  21. UpdatedAt int64 `json:"updatedAt"`
  22. }
  23. func (p *Prescription) TableName() string {
  24. return "prescription"
  25. }
  26. func (p *Prescription) EventUseCountUpdate() {
  27. p.UseCount += 1
  28. }
  29. func NewPrescription(
  30. pastureId int64,
  31. req *pasturePb.PrescriptionRequest,
  32. applicableDisease string,
  33. useDays,
  34. meatExpiredDays,
  35. milkExpiredDays int32,
  36. systemUser *SystemUser,
  37. ) *Prescription {
  38. return &Prescription{
  39. PastureId: pastureId,
  40. Name: req.Name,
  41. ApplicableDisease: applicableDisease,
  42. UseDays: useDays,
  43. UseCount: 0,
  44. MeatExpiredDays: meatExpiredDays,
  45. MilkExpiredDays: milkExpiredDays,
  46. IsShow: req.IsShow,
  47. Remarks: req.Remarks,
  48. OperationId: systemUser.Id,
  49. OperationName: systemUser.Name,
  50. }
  51. }
  52. type PrescriptionSlice []*Prescription
  53. func (p PrescriptionSlice) ToPB(prescriptionDrugsList []*PrescriptionDrugs, diseaseMap map[int64]*Disease) []*pasturePb.SearchPrescriptionList {
  54. res := make([]*pasturePb.SearchPrescriptionList, len(p))
  55. for i, v := range p {
  56. drugsList := make([]*pasturePb.PrescriptionDrugsList, 0)
  57. for _, pl := range prescriptionDrugsList {
  58. if pl.PrescriptionId != v.Id {
  59. continue
  60. }
  61. drugsList = append(drugsList, &pasturePb.PrescriptionDrugsList{
  62. Id: pl.Id,
  63. DrugsId: int32(pl.DrugsId),
  64. DrugsName: pl.DrugsName,
  65. Unit: pl.Unit,
  66. UnitName: pl.UnitName,
  67. Dosages: pl.Dosages,
  68. UseDays: pl.UseDays,
  69. Specs: pl.Specs,
  70. })
  71. }
  72. applicableDiseaseList := strings.Split(v.ApplicableDisease, ",")
  73. applicableDiseaseNames := make([]string, 0)
  74. applicableDiseaseIds := make([]int32, 0)
  75. for _, ad := range applicableDiseaseList {
  76. diseaseId, _ := strconv.ParseInt(ad, 10, 64)
  77. applicableDiseaseIds = append(applicableDiseaseIds, int32(diseaseId))
  78. if dis, ok := diseaseMap[diseaseId]; ok {
  79. applicableDiseaseNames = append(applicableDiseaseNames, dis.Name)
  80. }
  81. }
  82. res[i] = &pasturePb.SearchPrescriptionList{
  83. Id: int32(v.Id),
  84. Name: v.Name,
  85. ApplicableDisease: v.ApplicableDisease,
  86. ApplicableDiseaseIds: applicableDiseaseIds,
  87. ApplicableDiseaseNames: applicableDiseaseNames,
  88. UseDays: v.UseDays,
  89. UseCount: v.UseCount,
  90. MeatExpiredDays: v.MeatExpiredDays,
  91. MilkExpiredDays: v.MilkExpiredDays,
  92. IsShow: v.IsShow,
  93. Remarks: v.Remarks,
  94. OperationId: int32(v.OperationId),
  95. OperationName: v.OperationName,
  96. CreatedAt: int32(v.CreatedAt),
  97. UpdatedAt: int32(v.UpdatedAt),
  98. DrugsList: drugsList,
  99. }
  100. }
  101. return res
  102. }
  103. func (p PrescriptionSlice) ToPB2() []*pasturePb.ConfigOptionsList {
  104. res := make([]*pasturePb.ConfigOptionsList, len(p))
  105. for i, d := range p {
  106. res[i] = &pasturePb.ConfigOptionsList{
  107. Value: int32(d.Id),
  108. Label: d.Name,
  109. Disabled: true,
  110. }
  111. }
  112. return res
  113. }