calendar.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package model
  2. import (
  3. "fmt"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type Calendar struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. Name string `json:"name"`
  10. CalendarType pasturePb.CalendarType_Kind `json:"calendarType"`
  11. Count int32 `json:"count"`
  12. StartDay string `json:"startDay"`
  13. EndDay string `json:"endDay"`
  14. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  15. Backup string `json:"backup"`
  16. CreatedAt int64 `json:"createdAt"`
  17. UpdatedAt int64 `json:"updatedAt"`
  18. }
  19. func (w *Calendar) TableName() string {
  20. return "calendar"
  21. }
  22. func NewCalendar(pastureId int64, name string, calendarType pasturePb.CalendarType_Kind, startDay, endDay string, count int32) *Calendar {
  23. return &Calendar{
  24. PastureId: pastureId,
  25. Name: name,
  26. Count: count,
  27. CalendarType: calendarType,
  28. StartDay: startDay,
  29. EndDay: endDay,
  30. IsShow: pasturePb.IsShow_Ok,
  31. }
  32. }
  33. var CalendarTypeColorMap = map[pasturePb.CalendarType_Kind]string{
  34. pasturePb.CalendarType_Immunisation: "#00B42A",
  35. pasturePb.CalendarType_PG: "#722ED1",
  36. pasturePb.CalendarType_RnGH: "#722ED1",
  37. pasturePb.CalendarType_Pregnancy_Check: "#F5319D",
  38. pasturePb.CalendarType_WorkOrder: "#5d6d7e",
  39. pasturePb.CalendarType_Disease: "#00B42A",
  40. pasturePb.CalendarType_Calving: "#F5319D",
  41. pasturePb.CalendarType_Weaning: "#F5319D",
  42. pasturePb.CalendarType_Mating: "#F5319D",
  43. pasturePb.CalendarType_DryMilk: "#165DFF",
  44. }
  45. var CalendarTypeEndDaysMap = map[pasturePb.CalendarType_Kind]int{
  46. pasturePb.CalendarType_Immunisation: 6,
  47. pasturePb.CalendarType_PG: 0,
  48. pasturePb.CalendarType_RnGH: 0,
  49. pasturePb.CalendarType_Pregnancy_Check: 6,
  50. pasturePb.CalendarType_WorkOrder: -1,
  51. pasturePb.CalendarType_Disease: -1,
  52. pasturePb.CalendarType_Calving: 14,
  53. pasturePb.CalendarType_Weaning: 6,
  54. pasturePb.CalendarType_Mating: 0,
  55. pasturePb.CalendarType_DryMilk: 14,
  56. }
  57. type CalendarSlice []*Calendar
  58. func (c CalendarSlice) ToPB() []*pasturePb.Calendar {
  59. res := make([]*pasturePb.Calendar, len(c))
  60. for i, v := range c {
  61. res[i] = &pasturePb.Calendar{
  62. Id: int32(v.Id),
  63. Title: fmt.Sprintf("%s - %d", v.Name, v.Count),
  64. GroupId: v.CalendarType,
  65. Count: v.Count,
  66. Start: v.StartDay,
  67. End: v.EndDay,
  68. Color: CalendarTypeColorMap[v.CalendarType],
  69. ExtendedProps: &pasturePb.ExtendedProps{
  70. StartDay: v.StartDay,
  71. Backup: v.Backup,
  72. },
  73. }
  74. }
  75. return res
  76. }
  77. type TodayCompletedData struct {
  78. Count int32
  79. CalendarTypeName string
  80. }