event_weaning.go 2.4 KB

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