indicators_data.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type IndicatorsData struct {
  4. Id int64 `json:"id"`
  5. PastureId int64 `json:"pastureId"`
  6. CategoryType pasturePb.IndicatorType_Kind `json:"categoryType"`
  7. CategoryName string `json:"categoryName"`
  8. Date string `json:"date"`
  9. Kind string `json:"kind"`
  10. Value string `json:"value"`
  11. CreatedAt int64 `json:"createdAt"`
  12. UpdatedAt int64 `json:"updatedAt"`
  13. }
  14. func (d *IndicatorsData) TableName() string {
  15. return "indicators_data"
  16. }
  17. type IndicatorsDataSlice []*IndicatorsData
  18. func (i IndicatorsDataSlice) ToPB(detailsMap map[string]*IndicatorsDetails) *IndicatorComparison {
  19. res := &IndicatorComparison{
  20. Headers: make([]string, 0),
  21. List: make(map[string][]string),
  22. Notes: make(map[string]map[string]string),
  23. }
  24. dateMap := make(map[string]bool)
  25. for _, v := range i {
  26. if len(res.Headers) == 0 {
  27. res.Headers = []string{"指标名称", "单位"}
  28. }
  29. if !dateMap[v.Date] {
  30. dateMap[v.Date] = true
  31. res.Headers = append(res.Headers, v.Date)
  32. }
  33. details, ok := detailsMap[v.Kind]
  34. if ok {
  35. if res.List[v.Kind] == nil {
  36. res.List[v.Kind] = make([]string, 0)
  37. res.List[v.Kind] = append(res.List[v.Kind], details.Name, details.Unit)
  38. }
  39. res.List[v.Kind] = append(res.List[v.Kind], v.Value)
  40. if res.Notes[v.Kind] == nil {
  41. res.Notes[v.Kind] = make(map[string]string)
  42. }
  43. res.Notes[v.Kind]["zh"] = details.Zh
  44. }
  45. }
  46. return res
  47. }
  48. type IndicatorsComparisonResponse struct {
  49. Code int32 `json:"code"`
  50. Msg string `json:"msg"`
  51. Data *IndicatorComparison `json:"data"`
  52. }
  53. type IndicatorComparison struct {
  54. Headers []string `json:"headers"`
  55. List map[string][]string `json:"list"`
  56. Notes map[string]map[string]string `json:"notes"`
  57. }