disease.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import (
  3. "strings"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type Disease struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. Name string `json:"name"`
  10. Symptoms string `json:"symptoms"`
  11. DiseaseType int32 `json:"diseaseType"`
  12. DiseaseTypeName string `json:"diseaseTypeName"`
  13. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  14. Remarks string `json:"remarks"`
  15. OperationId int64 `json:"operationId"`
  16. CreatedAt int64 `json:"createdAt"`
  17. UpdatedAt int64 `json:"updatedAt"`
  18. }
  19. func (d *Disease) TableName() string {
  20. return "disease"
  21. }
  22. type DiseaseSlice []*Disease
  23. func (d DiseaseSlice) ToPB(lang string, user []*SystemUser, diseaseTypeList []*ConfigDiseaseType) []*pasturePb.SearchDiseaseList {
  24. res := make([]*pasturePb.SearchDiseaseList, len(d))
  25. for i, dl := range d {
  26. operationName, diseaseTypeName := "", ""
  27. for _, u := range user {
  28. if u.Id == dl.OperationId {
  29. operationName = u.NickName
  30. break
  31. }
  32. }
  33. for _, dt := range diseaseTypeList {
  34. if dt.Id == int64(dl.DiseaseType) {
  35. diseaseTypeName = dt.Zh
  36. if lang == "en" {
  37. diseaseTypeName = dt.En
  38. }
  39. break
  40. }
  41. }
  42. res[i] = &pasturePb.SearchDiseaseList{
  43. Id: int32(dl.Id),
  44. Remarks: dl.Remarks,
  45. OperationId: int32(dl.OperationId),
  46. OperationName: operationName,
  47. Name: dl.Name,
  48. DiseaseTypeId: dl.DiseaseType,
  49. DiseaseTypeName: diseaseTypeName,
  50. Symptoms: strings.Split(dl.Symptoms, "|"),
  51. IsShow: dl.IsShow,
  52. CreatedAt: int32(dl.CreatedAt),
  53. UpdatedAt: int32(dl.UpdatedAt),
  54. }
  55. }
  56. return res
  57. }
  58. func (d DiseaseSlice) ToPB2() []*pasturePb.ConfigOptionsList {
  59. res := make([]*pasturePb.ConfigOptionsList, len(d))
  60. for i, d := range d {
  61. res[i] = &pasturePb.ConfigOptionsList{
  62. Value: int32(d.Id),
  63. Label: d.Name,
  64. Disabled: true,
  65. }
  66. }
  67. return res
  68. }