package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type IndicatorsData struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CategoryType pasturePb.IndicatorType_Kind `json:"categoryType"` CategoryName string `json:"categoryName"` Date string `json:"date"` Kind string `json:"kind"` Value string `json:"value"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (d *IndicatorsData) TableName() string { return "indicators_data" } type IndicatorsDataSlice []*IndicatorsData func (i IndicatorsDataSlice) ToPB(detailsMap map[string]*IndicatorsDetails) *IndicatorComparison { res := &IndicatorComparison{ Headers: make([]string, 0), List: make(map[string][]string), Notes: make(map[string]map[string]string), } dateMap := make(map[string]bool) for _, v := range i { if len(res.Headers) == 0 { res.Headers = []string{"指标名称", "单位"} } if !dateMap[v.Date] { dateMap[v.Date] = true res.Headers = append(res.Headers, v.Date) } details, ok := detailsMap[v.Kind] if ok { if res.List[v.Kind] == nil { res.List[v.Kind] = make([]string, 0) res.List[v.Kind] = append(res.List[v.Kind], details.Name, details.Unit) } res.List[v.Kind] = append(res.List[v.Kind], v.Value) if res.Notes[v.Kind] == nil { res.Notes[v.Kind] = make(map[string]string) } res.Notes[v.Kind]["zh"] = details.Zh } } return res } type IndicatorsComparisonResponse struct { Code int32 `json:"code"` Msg string `json:"msg"` Data *IndicatorComparison `json:"data"` } type IndicatorComparison struct { Headers []string `json:"headers"` List map[string][]string `json:"list"` Notes map[string]map[string]string `json:"notes"` }