package model import ( "fmt" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type Calendar struct { Id int64 `json:"id"` Name string `json:"name"` CalendarType pasturePb.CalendarType_Kind `json:"calendarType"` Count int32 `json:"count"` ShowDay string `json:"showDay"` IsShow pasturePb.IsShow_Kind `json:"isShow"` Backup string `json:"backup"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (w *Calendar) TableName() string { return "calendar" } func NewCalendar(name string, calendarType pasturePb.CalendarType_Kind, count int32) *Calendar { return &Calendar{ Name: name, Count: count, CalendarType: calendarType, ShowDay: time.Now().Format(LayoutDate2), IsShow: pasturePb.IsShow_Ok, } } var CalendarTypeColorMap = map[pasturePb.CalendarType_Kind]string{ pasturePb.CalendarType_Immunisation: "#85c1e9", pasturePb.CalendarType_PG: "#48C9B0", pasturePb.CalendarType_RnGH: "#d35400", pasturePb.CalendarType_Pregnancy_Check: "#8E44AD", pasturePb.CalendarType_WorkOrder: "#5d6d7e", pasturePb.CalendarType_Treatment: "#c0392b", } type CalendarSlice []*Calendar func (c CalendarSlice) ToPB() []*pasturePb.Calendar { res := make([]*pasturePb.Calendar, len(c)) for i, v := range c { res[i] = &pasturePb.Calendar{ Id: int32(v.Id), Title: fmt.Sprintf("%s - %d", v.Name, v.Count), GroupId: v.CalendarType, Count: v.Count, Start: v.ShowDay, Color: CalendarTypeColorMap[v.CalendarType], ExtendedProps: &pasturePb.ExtendedProps{ StartDay: v.ShowDay, Backup: v.Backup, }, } } return res }