|
@@ -88,7 +88,7 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) FocusIndicators(ctx context.Context, dimension string) (*pasturePb.IndexFocusIndicatorsResponse, error) {
|
|
|
+func (s *StoreEntry) FocusIndicatorsList(ctx context.Context, dimension string) (*pasturePb.IndexFocusIndicatorsResponse, error) {
|
|
|
userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
@@ -96,7 +96,7 @@ func (s *StoreEntry) FocusIndicators(ctx context.Context, dimension string) (*pa
|
|
|
|
|
|
userFocusIndicators := userModel.SystemUser.IndicatorsKinds
|
|
|
if len(userFocusIndicators) <= 0 {
|
|
|
- userFocusIndicators = "all_cow,output_number,input_number,fatten_cattle_number,sales_volume"
|
|
|
+ userFocusIndicators = model.DefaultFocusIndicators
|
|
|
}
|
|
|
userFocusIndicatorsList := strings.Split(userFocusIndicators, ",")
|
|
|
indicatorsDataList := make([]*model.IndicatorsData, 0)
|
|
@@ -121,7 +121,7 @@ func (s *StoreEntry) FocusIndicators(ctx context.Context, dimension string) (*pa
|
|
|
if err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
- data := make([]*pasturePb.FocusData, 0)
|
|
|
+ focusIndicatorsList := make([]*pasturePb.FocusIndicators, 0)
|
|
|
for _, v := range indicatorsDataList {
|
|
|
indicatorsDetails, ok := indicatorsDetailsMap[v.Kind]
|
|
|
if !ok {
|
|
@@ -145,7 +145,7 @@ func (s *StoreEntry) FocusIndicators(ctx context.Context, dimension string) (*pa
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- data = append(data, &pasturePb.FocusData{
|
|
|
+ focusIndicatorsList = append(focusIndicatorsList, &pasturePb.FocusIndicators{
|
|
|
Kind: indicatorsDetails.Kind,
|
|
|
Name: indicatorsDetails.Name,
|
|
|
Value: v.Value,
|
|
@@ -155,9 +155,32 @@ func (s *StoreEntry) FocusIndicators(ctx context.Context, dimension string) (*pa
|
|
|
OnYear: onYear,
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ indicatorsDetailsList, _ := s.FindIndicatorsDetailsList(ctx)
|
|
|
+
|
|
|
return &pasturePb.IndexFocusIndicatorsResponse{
|
|
|
Code: http.StatusOK,
|
|
|
Msg: "ok",
|
|
|
- Data: data,
|
|
|
+ Data: &pasturePb.FocusData{
|
|
|
+ FocusIndicators: focusIndicatorsList,
|
|
|
+ IndicatorsSet: model.IndicatorsDetailsSlice(indicatorsDetailsList).ToPB(userFocusIndicatorsList),
|
|
|
+ },
|
|
|
}, err
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) FocusIndicatorsSet(ctx context.Context, req *pasturePb.IndexFocusIndicatorsSetRequest) error {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(req.IndicatorsKind) <= 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ userFocusIndicators := strings.Join(req.IndicatorsKind, ",")
|
|
|
+ if err = s.DB.Model(new(model.SystemUser)).Where("id = ?", userModel.SystemUser.Id).Update("indicators_kinds", userFocusIndicators).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|