calendar.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ShowDay string `json:"showDay"`
  13. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  14. Backup string `json:"backup"`
  15. CreatedAt int64 `json:"createdAt"`
  16. UpdatedAt int64 `json:"updatedAt"`
  17. }
  18. func (w *Calendar) TableName() string {
  19. return "calendar"
  20. }
  21. func NewCalendar(pastureId int64, name string, calendarType pasturePb.CalendarType_Kind, showDay string, count int32) *Calendar {
  22. return &Calendar{
  23. PastureId: pastureId,
  24. Name: name,
  25. Count: count,
  26. CalendarType: calendarType,
  27. ShowDay: showDay,
  28. IsShow: pasturePb.IsShow_Ok,
  29. }
  30. }
  31. var CalendarTypeColorMap = map[pasturePb.CalendarType_Kind]string{
  32. pasturePb.CalendarType_Immunisation: "#85c1e9",
  33. pasturePb.CalendarType_PG: "#48C9B0",
  34. pasturePb.CalendarType_RnGH: "#d35400",
  35. pasturePb.CalendarType_Pregnancy_Check: "#8E44AD",
  36. pasturePb.CalendarType_WorkOrder: "#5d6d7e",
  37. pasturePb.CalendarType_Treatment: "#c0392b",
  38. }
  39. type CalendarSlice []*Calendar
  40. func (c CalendarSlice) ToPB() []*pasturePb.Calendar {
  41. res := make([]*pasturePb.Calendar, len(c))
  42. for i, v := range c {
  43. res[i] = &pasturePb.Calendar{
  44. Id: int32(v.Id),
  45. Title: fmt.Sprintf("%s - %d", v.Name, v.Count),
  46. GroupId: v.CalendarType,
  47. Count: v.Count,
  48. Start: v.ShowDay,
  49. Color: CalendarTypeColorMap[v.CalendarType],
  50. ExtendedProps: &pasturePb.ExtendedProps{
  51. StartDay: v.ShowDay,
  52. Backup: v.Backup,
  53. },
  54. }
  55. }
  56. return res
  57. }