event_seme_time.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  4. )
  5. type EventSemeTime struct {
  6. Id int64 `json:"id"`
  7. Name string `json:"name"`
  8. WeekType pasturePb.Week_Kind `json:"week_type"`
  9. CowType pasturePb.CowType_Kind `json:"cow_type"`
  10. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  11. IsDelete pasturePb.IsShow_Kind `json:"is_delete"`
  12. PostpartumDays int32 `json:"postpartum_days"`
  13. Remarks string `json:"remarks"`
  14. OperationId int64 `json:"operation_id"`
  15. CreatedAt int64 `json:"created_at"`
  16. UpdatedAt int64 `json:"updated_at"`
  17. }
  18. func (e *EventSemeTime) TableName() string {
  19. return "event_seme_time"
  20. }
  21. func NewEventSemeTime(currentUser *SystemUser, req *pasturePb.SemeTimeRequest) *EventSemeTime {
  22. return &EventSemeTime{
  23. Name: req.Form.Name,
  24. WeekType: req.Form.WeekType,
  25. CowType: req.Form.CowType,
  26. IsShow: pasturePb.IsShow_Ok,
  27. IsDelete: pasturePb.IsShow_Ok,
  28. PostpartumDays: req.Form.PostpartumDays,
  29. Remarks: req.Form.Remarks,
  30. OperationId: currentUser.Id,
  31. }
  32. }
  33. type EventSemeTimeSlice []*EventSemeTime
  34. func (e EventSemeTimeSlice) ToPB(
  35. weekMap map[pasturePb.Week_Kind]string,
  36. cowTypeMap map[pasturePb.CowType_Kind]string,
  37. systemUserList []*SystemUser,
  38. ) []*pasturePb.SearchSemeTimeList {
  39. res := make([]*pasturePb.SearchSemeTimeList, len(e))
  40. for i, v := range e {
  41. operationName := ""
  42. for _, u := range systemUserList {
  43. if u.Id != v.OperationId {
  44. continue
  45. }
  46. operationName = u.Name
  47. }
  48. res[i] = &pasturePb.SearchSemeTimeList{
  49. Id: int32(v.Id),
  50. Name: v.Name,
  51. WeekType: v.WeekType,
  52. WeekName: weekMap[v.WeekType],
  53. CowType: v.CowType,
  54. CowTypeName: cowTypeMap[v.CowType],
  55. IsShow: v.IsShow,
  56. PostpartumDays: v.PostpartumDays,
  57. Remarks: v.Remarks,
  58. OperationId: int32(v.OperationId),
  59. OperationName: operationName,
  60. CreatedAt: int32(v.CreatedAt),
  61. UpdatedAt: int32(v.UpdatedAt),
  62. }
  63. }
  64. return res
  65. }