frozen_semen.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type FrozenSemen struct {
  4. Id int64 `json:"id"`
  5. PastureId int64 `json:"pasture_id"`
  6. ParentId int64 `json:"parent_id"`
  7. Producer string `json:"producer"`
  8. BullId string `json:"bull_id"`
  9. KindId pasturePb.CowKind_Kind `json:"kind_id"`
  10. KindName string `json:"kind_name"`
  11. FrozenSemenType pasturePb.FrozenSemenType_Kind `json:"frozen_semen_type"`
  12. Quantity int32 `json:"quantity"`
  13. Unit pasturePb.Unit_Kind `json:"unit"`
  14. Remarks string `json:"remarks"`
  15. OperationId int64 `json:"operation_id"`
  16. CreatedAt int64 `json:"created_at"`
  17. UpdatedAt int64 `json:"updated_at"`
  18. }
  19. func NewFrozenSemen(pastureId int64, req *pasturePb.SearchFrozenSemenList, currentUser *SystemUser) *FrozenSemen {
  20. return &FrozenSemen{
  21. PastureId: pastureId,
  22. Producer: req.Producer,
  23. BullId: req.BullId,
  24. KindId: req.CowKind,
  25. KindName: req.CowKindName,
  26. FrozenSemenType: req.FrozenSemenType,
  27. Quantity: req.Quantity,
  28. Unit: req.Unit,
  29. Remarks: req.Remarks,
  30. OperationId: currentUser.Id,
  31. }
  32. }
  33. func (e *FrozenSemen) TableName() string {
  34. return "frozen_semen"
  35. }
  36. func (e *FrozenSemen) EventQuantityUpdate(quantity int32) {
  37. e.Quantity -= quantity
  38. }
  39. type FrozenSemenSlice []*FrozenSemen
  40. func (e FrozenSemenSlice) ToPB(
  41. frozenSemenTypeMap map[pasturePb.FrozenSemenType_Kind]string,
  42. unitMap map[pasturePb.Unit_Kind]string) []*pasturePb.SearchFrozenSemenList {
  43. res := make([]*pasturePb.SearchFrozenSemenList, len(e))
  44. for i, v := range e {
  45. res[i] = &pasturePb.SearchFrozenSemenList{
  46. Id: int32(v.Id),
  47. ParentId: int32(v.ParentId),
  48. Producer: v.Producer,
  49. BullId: v.BullId,
  50. CowKind: v.KindId,
  51. CowKindName: v.KindName,
  52. FrozenSemenType: v.FrozenSemenType,
  53. FrozenSemenTypeName: frozenSemenTypeMap[v.FrozenSemenType],
  54. Quantity: v.Quantity,
  55. Unit: v.Unit,
  56. UnitName: unitMap[v.Unit],
  57. Remarks: v.Remarks,
  58. OperationId: int32(v.OperationId),
  59. CreatedAt: int32(v.CreatedAt),
  60. UpdatedAt: int32(v.UpdatedAt),
  61. }
  62. }
  63. return res
  64. }