event_pregnant_check.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventPregnantCheck struct {
  4. Id int64 `json:"id"`
  5. CowId int64 `json:"cow_id"`
  6. DayAge int32 `json:"day_age"`
  7. Lact int8 `json:"lact"`
  8. PregnantCheckAt int64 `json:"pregnant_check_at"`
  9. PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnant_check_result"`
  10. PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnant_check_method"`
  11. StaffMemberId int64 `json:"staff_member_id"`
  12. OperationId int64 `json:"operation_id"`
  13. Remarks string `json:"remarks"`
  14. CreatedAt int64 `json:"created_at"`
  15. UpdatedAt int64 `json:"updated_at"`
  16. }
  17. func (e *EventPregnantCheck) TableName() string {
  18. return "event_pregnant_check"
  19. }
  20. func NewEventPregnantCheck(
  21. cow *Cow,
  22. systemUser *SystemUser,
  23. req *pasturePb.EventPregnantCheck,
  24. pregnantCheckResult pasturePb.PregnantCheckResult_Kind,
  25. ) *EventPregnantCheck {
  26. return &EventPregnantCheck{
  27. CowId: cow.Id,
  28. DayAge: cow.GetDayAge(),
  29. Lact: int8(cow.Lact),
  30. PregnantCheckAt: int64(req.PregnantCheckAt),
  31. PregnantCheckResult: pregnantCheckResult,
  32. PregnantCheckMethod: req.PregnantCheckMethod,
  33. StaffMemberId: int64(req.StaffMemberId),
  34. OperationId: systemUser.Id,
  35. Remarks: req.Remarks,
  36. }
  37. }
  38. type EventPregnantCheckSlice []*EventPregnantCheck
  39. func (e EventPregnantCheckSlice) ToPB(systemUserList []*SystemUser, pregnantCheckResult, pregnantCheckMethod []*pasturePb.ConfigOptionsList) []*pasturePb.SearchPregnantCheckList {
  40. result := make([]*pasturePb.SearchPregnantCheckList, len(e))
  41. for i, v := range e {
  42. var pregnantCheckResultName, pregnantCheckMethodName, staffMemberName, operationName = "", "", "", ""
  43. for _, u := range systemUserList {
  44. if v.StaffMemberId == u.Id {
  45. staffMemberName = u.Name
  46. }
  47. if v.OperationId == u.Id {
  48. operationName = u.Name
  49. }
  50. }
  51. for _, s := range pregnantCheckResult {
  52. if int32(v.PregnantCheckResult) != s.Value {
  53. continue
  54. }
  55. pregnantCheckResultName = s.Label
  56. }
  57. for _, m := range pregnantCheckMethod {
  58. if int32(v.PregnantCheckMethod) != m.Value {
  59. continue
  60. }
  61. pregnantCheckMethodName = m.Label
  62. }
  63. result[i] = &pasturePb.SearchPregnantCheckList{
  64. Id: int32(v.Id),
  65. CowId: int32(v.CowId),
  66. DayAge: v.DayAge,
  67. Lact: int32(v.Lact),
  68. PregnantCheckAt: int32(v.PregnantCheckAt),
  69. PregnantCheckResult: v.PregnantCheckResult,
  70. PregnantCheckResultName: pregnantCheckResultName,
  71. PregnantCheckMethod: v.PregnantCheckMethod,
  72. PregnantCheckMethodName: pregnantCheckMethodName,
  73. StaffMemberId: int32(v.StaffMemberId),
  74. StaffMemberName: staffMemberName,
  75. Remarks: v.Remarks,
  76. OperationId: int32(v.OperationId),
  77. OperationName: operationName,
  78. CreatedAt: int32(v.CreatedAt),
  79. UpdatedAt: int32(v.UpdatedAt),
  80. }
  81. }
  82. return result
  83. }