calendar.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package model
  2. import (
  3. "fmt"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type Calendar struct {
  8. Id int64 `json:"id"`
  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(name string, calendarType pasturePb.CalendarType_Kind, count int32) *Calendar {
  22. return &Calendar{
  23. Name: name,
  24. Count: count,
  25. CalendarType: calendarType,
  26. ShowDay: time.Now().Format(LayoutDate2),
  27. IsShow: pasturePb.IsShow_Ok,
  28. }
  29. }
  30. var CalendarTypeColorMap = map[pasturePb.CalendarType_Kind]string{
  31. pasturePb.CalendarType_Immunisation: "#85c1e9",
  32. pasturePb.CalendarType_PG: "#48C9B0",
  33. pasturePb.CalendarType_RnGH: "#d35400",
  34. pasturePb.CalendarType_Pregnancy_Check: "#8E44AD",
  35. pasturePb.CalendarType_WorkOrder: "#5d6d7e",
  36. pasturePb.CalendarType_Treatment: "#c0392b",
  37. }
  38. type CalendarSlice []*Calendar
  39. func (c CalendarSlice) ToPB() []*pasturePb.Calendar {
  40. res := make([]*pasturePb.Calendar, len(c))
  41. for i, v := range c {
  42. res[i] = &pasturePb.Calendar{
  43. Id: int32(v.Id),
  44. Title: fmt.Sprintf("%s - %d", v.Name, v.Count),
  45. GroupId: v.CalendarType,
  46. Count: v.Count,
  47. Start: v.ShowDay,
  48. Color: CalendarTypeColorMap[v.CalendarType],
  49. ExtendedProps: &pasturePb.ExtendedProps{
  50. StartDay: v.ShowDay,
  51. Backup: v.Backup,
  52. },
  53. }
  54. }
  55. return res
  56. }