event_weaning.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. "strconv"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventWeaning struct {
  8. Id int64 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. CowId int64 `json:"cowId"`
  11. EarNumber string `json:"earNumber"`
  12. DayAge int32 `json:"dayAge"`
  13. MotherId int64 `json:"motherId"`
  14. BullNumber string `json:"bullNumber"`
  15. PlanDay int64 `json:"planDay"`
  16. EndDay int64 `json:"endDay"`
  17. RealityDay int64 `json:"realityDay"`
  18. Status pasturePb.IsShow_Kind `json:"status"`
  19. BeforePenId int32 `json:"beforePenId"`
  20. AfterPenId int32 `json:"afterPenId"`
  21. Weight int32 `json:"weight"`
  22. BirthWeight int32 `json:"birthWeight"`
  23. BirthAt int64 `json:"birthAt"`
  24. Remarks string `json:"remarks"`
  25. OperationId int32 `json:"operationId"`
  26. OperationName string `json:"operationName"`
  27. MessageId int32 `json:"messageId"`
  28. MessageName string `json:"messageName"`
  29. CreatedAt int64 `json:"createdAt"`
  30. UpdatedAt int64 `json:"updatedAt"`
  31. }
  32. func (e *EventWeaning) TableName() string {
  33. return "event_weaning"
  34. }
  35. func (e *EventWeaning) EventUpdate(cowInfo *Cow, weaningAt int64, weight int32, remarks string, afterPenId int32, operationUser, currentUser *SystemUser) {
  36. e.Status = pasturePb.IsShow_Ok
  37. e.RealityDay = weaningAt
  38. e.OperationId = int32(operationUser.Id)
  39. e.OperationName = operationUser.Name
  40. e.MessageId = int32(currentUser.Id)
  41. e.MessageName = currentUser.Name
  42. e.Remarks = remarks
  43. e.AfterPenId = afterPenId
  44. e.Weight = weight
  45. e.DayAge = cowInfo.GetEventDayAge(weaningAt)
  46. e.BirthWeight = int32(cowInfo.BirthWeight)
  47. e.BirthAt = cowInfo.BirthAt
  48. }
  49. func NewEventWeaning(pastureId int64, cowInfo *Cow, startDay, endDay string) *EventWeaning {
  50. motherId, _ := strconv.ParseInt(cowInfo.MotherNumber, 10, 64)
  51. return &EventWeaning{
  52. PastureId: pastureId,
  53. MotherId: motherId,
  54. BullNumber: cowInfo.LastBullNumber,
  55. CowId: cowInfo.Id,
  56. EarNumber: cowInfo.EarNumber,
  57. PlanDay: util.TimeParseLocalUnix(startDay),
  58. EndDay: util.TimeParseLocalEndUnix(endDay),
  59. Status: pasturePb.IsShow_No,
  60. BeforePenId: cowInfo.PenId,
  61. Weight: 0,
  62. }
  63. }
  64. func NewEventWeaningList(pastureId int64, cowList []*Cow, startDay, endDay string) []*EventWeaning {
  65. var weaningList = make([]*EventWeaning, 0)
  66. for _, cow := range cowList {
  67. weaningList = append(weaningList, NewEventWeaning(pastureId, cow, startDay, endDay))
  68. }
  69. return weaningList
  70. }