event_weaning.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. Remarks string `json:"remarks"`
  23. OperationId int32 `json:"operationId"`
  24. OperationName string `json:"operationName"`
  25. MessageId int32 `json:"messageId"`
  26. MessageName string `json:"messageName"`
  27. CreatedAt int64 `json:"createdAt"`
  28. UpdatedAt int64 `json:"updatedAt"`
  29. }
  30. func (e *EventWeaning) TableName() string {
  31. return "event_weaning"
  32. }
  33. func (e *EventWeaning) EventUpdate(cowInfo *Cow, weaningAt int64, weight int32, remarks string, afterPenId int32, operationUser, currentUser *SystemUser) {
  34. e.Status = pasturePb.IsShow_Ok
  35. e.RealityDay = weaningAt
  36. e.OperationId = int32(operationUser.Id)
  37. e.OperationName = operationUser.Name
  38. e.MessageId = int32(currentUser.Id)
  39. e.MessageName = currentUser.Name
  40. e.Remarks = remarks
  41. e.AfterPenId = afterPenId
  42. e.Weight = weight
  43. e.DayAge = cowInfo.GetEventDayAge(weaningAt)
  44. }
  45. func NewEventWeaning(pastureId int64, cowInfo *Cow, startDay, endDay string) *EventWeaning {
  46. motherId, _ := strconv.ParseInt(cowInfo.MotherNumber, 10, 64)
  47. return &EventWeaning{
  48. PastureId: pastureId,
  49. MotherId: motherId,
  50. BullNumber: cowInfo.LastBullNumber,
  51. CowId: cowInfo.Id,
  52. EarNumber: cowInfo.EarNumber,
  53. PlanDay: util.TimeParseLocalUnix(startDay),
  54. EndDay: util.TimeParseLocalEndUnix(endDay),
  55. Status: pasturePb.IsShow_No,
  56. BeforePenId: cowInfo.PenId,
  57. Weight: 0,
  58. }
  59. }
  60. func NewEventWeaningList(pastureId int64, cowList []*Cow, startDay, endDay string) []*EventWeaning {
  61. var weaningList = make([]*EventWeaning, 0)
  62. for _, cow := range cowList {
  63. weaningList = append(weaningList, NewEventWeaning(pastureId, cow, startDay, endDay))
  64. }
  65. return weaningList
  66. }