优化目标达成逻辑 3214/target/2 3216/1 3216/head
authorCaisking <Casiking@zhihuishixun.com>
Tue, 24 Feb 2026 02:56:35 +0000 (10:56 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Tue, 24 Feb 2026 02:56:35 +0000 (10:56 +0800)
code/sdk/application/wearable/fd272/service/msg_center/src/msg_center_customer.cpp

index d5b3010..cd5c49a 100644 (file)
@@ -77,9 +77,9 @@
  #include "sleep/include/SleepModel.h"
  #include "health/health_service/health_service.h"
  #include "player/include/PlayersModelC.h"
- #include "system/include/SystemLogModelC.h"
- 
- #include "bloodoxygen/include/BloodOxygenModel.h"
+#include "system/include/SystemLogModelC.h"
+
+#include "bloodoxygen/include/BloodOxygenModel.h"
  #include "heartrate/include/HeartModel.h"
  #include "saveele/include/SaveEleModel.h"
  #include "respiratorytraining/include/RespiratoryTrainingModel.h"
@@ -1041,7 +1041,7 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
      static uint8_t goal_type=0;
      void MsgCenterNotifystepProc(const Topic topic, Request* req)
      {
-         //unused(req);
+         (void)topic;
          if (req->msgId == TOPIC_EVENT_STEPDATA_UPDATE)
          {
              
@@ -1050,7 +1050,6 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
                  return;
              }
              // 计步数据累加
-             
              OHOS::GoalModel::GetInstance().show_data_step_refresh();
              OHOS::GoalModel::GetInstance().show_data_calories_refresh();
              OHOS::GoalModel::GetInstance().show_data_distance_refresh();
@@ -1059,75 +1058,63 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
              {
                  GraphicService::GetInstance()->PostGraphicEvent(
                  std::bind(&OHOS::GoalView::GoalViewrefresh,  OHOS::GoalView::GetInstance() ));
- 
-             // OHOS::GoalView::GetInstance()->GoalViewrefresh();
              }
              if(OHOS::GoalotherView::GetInstance())
              {
-                 //OHOS::GoalotherView::GetInstance()->GoalViewrefresh();
                  GraphicService::GetInstance()->PostGraphicEvent(
                  std::bind(&OHOS::GoalotherView::GoalViewrefresh,  OHOS::GoalotherView::GetInstance() ));
              }
  
-             if(OHOS::GoalModel::GetInstance().getstepvalue()>=100)
-             {
+             /* 运动过程中不弹目标达成,避免打扰用户;使用 runtime 训练状态(0 未训练/结束,1 训练中) */
+             if (uapi_dev_runtime_get_train_status() != 0) {
+                 return;
+             }
  
-                 goal_type=GOAL_STEP;
-                 if(get_Is_show_flag(goal_type))
-                 {   
-                     if(OHOS::GoalModel::GetInstance().get_step_goal_show())
-                     {
-                         CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW,(uint8_t *)&goal_type,1);
-                     }
+             /* 同时只弹一个:本轮只发布第一个达成的目标,顺序:步数 -> 距离 -> 燃脂 -> 站立 -> 卡路里 */
+             bool published = false;
+             if (!published && OHOS::GoalModel::GetInstance().getstepvalue() >= 100)
+             {
+                 goal_type = GOAL_STEP;
+                 if (get_Is_show_flag(goal_type) && OHOS::GoalModel::GetInstance().get_step_goal_show())
+                 {
+                     CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW, (uint8_t *)&goal_type, 1);
+                     published = true;
                  }
              }
- 
-             if(OHOS::GoalModel::GetInstance().is_goal_DISTANCE_done())
+             if (!published && OHOS::GoalModel::GetInstance().is_goal_DISTANCE_done())
              {
-                 goal_type=GOAL_DISTANCE;
-                 if(get_Is_show_flag(goal_type))
-                 {   
-                     if(OHOS::GoalModel::GetInstance().get_other_goal_show())
-                     {
-                         CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW,(uint8_t *)&goal_type,1);
-                     }
-                 
+                 goal_type = GOAL_DISTANCE;
+                 if (get_Is_show_flag(goal_type) && OHOS::GoalModel::GetInstance().get_other_goal_show())
+                 {
+                     CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW, (uint8_t *)&goal_type, 1);
+                     published = true;
                  }
              }
- 
-             if(OHOS::GoalModel::GetInstance().is_goal_fatburning_done())
+             if (!published && OHOS::GoalModel::GetInstance().is_goal_fatburning_done())
              {
-                 goal_type=GOAL_FAT;
-                 if(get_Is_show_flag(goal_type))
-                 {   
-                     if(OHOS::GoalModel::GetInstance().get_other_goal_show())
-                     {
-                         CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW,(uint8_t *)&goal_type,1);
-                     }
+                 goal_type = GOAL_FAT;
+                 if (get_Is_show_flag(goal_type) && OHOS::GoalModel::GetInstance().get_other_goal_show())
+                 {
+                     CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW, (uint8_t *)&goal_type, 1);
+                     published = true;
                  }
              }
- 
-             if(OHOS::GoalModel::GetInstance().is_goal_stand_done())
+             if (!published && OHOS::GoalModel::GetInstance().is_goal_stand_done())
              {
-                 goal_type=GOAL_STAND;
-                 if(get_Is_show_flag(goal_type))
-                 {   
-                     if(OHOS::GoalModel::GetInstance().get_other_goal_show())
-                     {
-                         CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW,(uint8_t *)&goal_type,1);
-                     }
+                 goal_type = GOAL_STAND;
+                 if (get_Is_show_flag(goal_type) && OHOS::GoalModel::GetInstance().get_other_goal_show())
+                 {
+                     CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW, (uint8_t *)&goal_type, 1);
+                     published = true;
                  }
              }
- 
-             if(OHOS::GoalModel::GetInstance().is_goal_calories_done())
+             if (!published && OHOS::GoalModel::GetInstance().is_goal_calories_done())
              {
-                 goal_type=GOAL_CALOREIE;
-                 if(get_Is_show_flag(goal_type))
-                 {   
-                 if(OHOS::GoalModel::GetInstance().get_other_goal_show())
-                     {
-                         CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW,(uint8_t *)&goal_type,1);
-                     }
+                 goal_type = GOAL_CALOREIE;
+                 if (get_Is_show_flag(goal_type) && OHOS::GoalModel::GetInstance().get_other_goal_show())
+                 {
+                     CustomEventPublish(TOPIC_EVENT_GOAL_SHOW_VIEW, (uint8_t *)&goal_type, 1);
+                     published = true;
                  }
              }
              #endif
@@ -1329,6 +1316,11 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
  void MsgCenterNotifyGoalShowViewProc(const Topic topic, Request* req)
  {
     unused(req);
+    /* 同时只弹一个:若当前已在显示目标达成弹窗,则不再叠加 */
+    if (NotificationManager::GetInstance()->GetShowingNotifyId() == static_cast<uint16_t>(TOPIC_EVENT_GOAL_SHOW_VIEW))
+    {
+        return;
+    }
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyGoalShowViewProc目标达成 !");
     if (CheckPriority(topic)) 
     {