prescription.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type Prescription struct {
  8. Id int64 `json:"id"`
  9. Name string `json:"name"`
  10. ApplicableDisease string `json:"applicable_disease"`
  11. UseDays int32 `json:"use_days"`
  12. UseCount int32 `json:"use_count"`
  13. MeatExpiredDays int32 `json:"meat_expired_days"`
  14. MilkExpiredDays int32 `json:"milk_expired_days"`
  15. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  16. Remarks string `json:"remarks"`
  17. OperationId int64 `json:"operation_id"`
  18. CreatedAt int64 `json:"created_at"`
  19. UpdatedAt int64 `json:"updated_at"`
  20. }
  21. func (p *Prescription) TableName() string {
  22. return "prescription"
  23. }
  24. func NewPrescription(req *pasturePb.PrescriptionRequest, useDays, meatExpiredDays, milkExpiredDays int32, operationId int64) *Prescription {
  25. applicableDisease := ""
  26. for _, v := range req.ApplicableDisease {
  27. applicableDisease += fmt.Sprintf("%d", v) + "|"
  28. }
  29. return &Prescription{
  30. Name: req.Name,
  31. ApplicableDisease: applicableDisease,
  32. UseDays: useDays,
  33. UseCount: 0,
  34. MeatExpiredDays: meatExpiredDays,
  35. MilkExpiredDays: milkExpiredDays,
  36. IsShow: req.IsShow,
  37. Remarks: req.Remarks,
  38. OperationId: operationId,
  39. }
  40. }
  41. type PrescriptionSlice []*Prescription
  42. func (p PrescriptionSlice) ToPB(userList []*SystemUser, prescriptionDrugsList []*PrescriptionDrugs) []*pasturePb.SearchPrescriptionList {
  43. res := make([]*pasturePb.SearchPrescriptionList, len(p))
  44. for i, v := range p {
  45. operationName := ""
  46. for _, u := range userList {
  47. if u.Id == v.OperationId {
  48. operationName = u.Name
  49. break
  50. }
  51. }
  52. drugsList := make([]*pasturePb.PrescriptionDrugsList, 0)
  53. for _, d := range prescriptionDrugsList {
  54. if d.PrescriptionId != v.Id {
  55. continue
  56. }
  57. drugsList = append(drugsList, &pasturePb.PrescriptionDrugsList{
  58. Id: int32(d.Id),
  59. DrugsId: int32(d.DrugsId),
  60. Unit: d.Unit,
  61. UnitName: d.UnitName,
  62. Dosages: d.Dosages,
  63. UseDays: d.UseDays,
  64. })
  65. }
  66. res[i] = &pasturePb.SearchPrescriptionList{
  67. Id: int32(v.Id),
  68. Name: v.Name,
  69. ApplicableDisease: strings.Split(v.ApplicableDisease, "|"),
  70. UseDays: v.UseDays,
  71. UseCount: v.UseCount,
  72. MeatExpiredDays: v.MeatExpiredDays,
  73. MilkExpiredDays: v.MilkExpiredDays,
  74. IsShow: v.IsShow,
  75. Remarks: v.Remarks,
  76. OperationId: int32(v.OperationId),
  77. OperationName: operationName,
  78. CreatedAt: int32(v.CreatedAt),
  79. UpdatedAt: int32(v.UpdatedAt),
  80. DrugsList: drugsList,
  81. }
  82. }
  83. return res
  84. }