indicators_details.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. const DefaultFocusIndicators = "all_cow,output_number,input_number,fatten_cattle_number,sales_volume"
  4. type IndicatorsDetails struct {
  5. Id int `json:"id"`
  6. Kind string `json:"kind"`
  7. Name string `json:"name"`
  8. CategoryType pasturePb.IndicatorType_Kind `json:"categoryType"`
  9. CategoryName string `json:"categoryName"`
  10. Unit string `json:"unit"`
  11. Zh string `json:"zh"`
  12. CreatedAt int64 `json:"createdAt"`
  13. UpdatedAt int64 `json:"updatedAt"`
  14. }
  15. func (IndicatorsDetails) TableName() string {
  16. return "indicators_details"
  17. }
  18. type IndicatorsDetailsSlice []*IndicatorsDetails
  19. func (i IndicatorsDetailsSlice) ToPB(userFocusIndicators []string) []*pasturePb.FocusIndicatorsSetData {
  20. res := make([]*pasturePb.FocusIndicatorsSetData, len(i))
  21. for k, v := range i {
  22. isShow := pasturePb.IsShow_No
  23. for _, useIndicators := range userFocusIndicators {
  24. if useIndicators == v.Kind {
  25. isShow = pasturePb.IsShow_Ok
  26. }
  27. }
  28. res[k] = &pasturePb.FocusIndicatorsSetData{
  29. Name: v.Name,
  30. Kind: v.Kind,
  31. IndicatorTypeKind: v.CategoryType,
  32. IndicatorTypeName: v.CategoryName,
  33. IsShow: isShow,
  34. }
  35. }
  36. return res
  37. }