same_time.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package model
  2. import (
  3. "encoding/json"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type SameTime struct {
  7. Id int64 `json:"id"`
  8. Name string `json:"name"`
  9. WeekType pasturePb.Week_Kind `json:"weekType"`
  10. CowType pasturePb.CowType_Kind `json:"cowType"`
  11. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  12. IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
  13. PostpartumDaysStart int32 `json:"postpartumDaysStart"`
  14. PostpartumDaysEnd int32 `json:"postpartumDaysEnd"`
  15. SameTimeDetails string `json:"sameTimeDetails"`
  16. Remarks string `json:"remarks"`
  17. OperationId int64 `json:"operationId"`
  18. CreatedAt int64 `json:"createdAt"`
  19. UpdatedAt int64 `json:"updatedAt"`
  20. }
  21. func (e *SameTime) TableName() string {
  22. return "same_time"
  23. }
  24. func NewSameTime(currentUser *SystemUser, req *pasturePb.SearchSameTimeList) *SameTime {
  25. sameTimeDetails, _ := json.Marshal(req.CollateNodes)
  26. return &SameTime{
  27. Name: req.Name,
  28. WeekType: req.WeekType,
  29. CowType: req.CowType,
  30. IsShow: pasturePb.IsShow_Ok,
  31. IsDelete: pasturePb.IsShow_Ok,
  32. PostpartumDaysStart: req.PostpartumDaysStart,
  33. PostpartumDaysEnd: req.PostpartumDaysEnd,
  34. SameTimeDetails: string(sameTimeDetails),
  35. Remarks: req.Remarks,
  36. OperationId: currentUser.Id,
  37. }
  38. }
  39. type SameTimeSlice []*SameTime
  40. func (e SameTimeSlice) ToPB(
  41. weekMap map[pasturePb.Week_Kind]string,
  42. cowTypeMap map[pasturePb.CowType_Kind]string,
  43. systemUserList []*SystemUser,
  44. ) []*pasturePb.SearchSameTimeList {
  45. res := make([]*pasturePb.SearchSameTimeList, len(e))
  46. for i, v := range e {
  47. operationName := ""
  48. for _, u := range systemUserList {
  49. if u.Id != v.OperationId {
  50. continue
  51. }
  52. operationName = u.Name
  53. }
  54. res[i] = &pasturePb.SearchSameTimeList{
  55. Id: int32(v.Id),
  56. Name: v.Name,
  57. WeekType: v.WeekType,
  58. WeekName: weekMap[v.WeekType],
  59. CowType: v.CowType,
  60. CowTypeName: cowTypeMap[v.CowType],
  61. IsShow: v.IsShow,
  62. PostpartumDaysStart: v.PostpartumDaysStart,
  63. PostpartumDaysEnd: v.PostpartumDaysEnd,
  64. Remarks: v.Remarks,
  65. OperationId: int32(v.OperationId),
  66. OperationName: operationName,
  67. CreatedAt: int32(v.CreatedAt),
  68. UpdatedAt: int32(v.UpdatedAt),
  69. }
  70. }
  71. return res
  72. }