feat: 增加睡眠分析通知功能,支持睡眠质量评估与建议
This commit is contained in:
@@ -16,10 +16,12 @@ import {
|
||||
fetchOxygenSaturation,
|
||||
fetchPersonalHealthData,
|
||||
fetchSmartHRVData,
|
||||
fetchStepCount,
|
||||
saveHeight,
|
||||
saveWeight
|
||||
} from '@/utils/health';
|
||||
import AsyncStorage from '@/utils/kvStore';
|
||||
import { logger } from '@/utils/logger';
|
||||
import { convertHrvToStressIndex } from '@/utils/stress';
|
||||
import dayjs from 'dayjs';
|
||||
import { DailyHealthDataDto, updateDailyHealthData } from './users';
|
||||
@@ -468,8 +470,6 @@ export async function getSyncStatusInfo(): Promise<SyncStatus | null> {
|
||||
* @param waterIntake - 当日饮水量(从应用内部获取,因为 HealthKit 可能不包含应用内记录)
|
||||
*/
|
||||
export async function syncDailyHealthReport(waterIntake?: number): Promise<boolean> {
|
||||
console.log('=== 开始同步每日健康报表 ===');
|
||||
|
||||
try {
|
||||
const today = new Date();
|
||||
const dateStr = dayjs(today).format('YYYY-MM-DD');
|
||||
@@ -483,7 +483,8 @@ export async function syncDailyHealthReport(waterIntake?: number): Promise<boole
|
||||
exerciseMinutesData,
|
||||
standHoursData,
|
||||
oxygenSaturation,
|
||||
hrvData
|
||||
hrvData,
|
||||
stepCount
|
||||
] = await Promise.all([
|
||||
// 卡路里
|
||||
fetchActiveEnergyBurned({
|
||||
@@ -507,7 +508,9 @@ export async function syncDailyHealthReport(waterIntake?: number): Promise<boole
|
||||
endDate: dayjs(today).endOf('day').toISOString()
|
||||
}),
|
||||
// HRV (用于计算压力)
|
||||
fetchSmartHRVData(today)
|
||||
fetchSmartHRVData(today),
|
||||
// 步数
|
||||
fetchStepCount(today)
|
||||
]);
|
||||
|
||||
// 2. 数据处理与计算
|
||||
@@ -555,10 +558,11 @@ export async function syncDailyHealthReport(waterIntake?: number): Promise<boole
|
||||
...(basalEnergy > 0 && { basalMetabolism: Math.round(basalEnergy) }),
|
||||
...(sleepMinutes > 0 && { sleepMinutes }),
|
||||
...(oxygenSaturation !== null && oxygenSaturation > 0 && { bloodOxygen: oxygenSaturation }),
|
||||
...(stressLevel > 0 && { stressLevel })
|
||||
...(stressLevel > 0 && { stressLevel }),
|
||||
...(stepCount > 0 && { steps: Math.round(stepCount) })
|
||||
};
|
||||
|
||||
console.log('准备同步每日健康数据:', healthData);
|
||||
logger.info('准备同步每日健康数据:', healthData);
|
||||
|
||||
// 4. 检查是否需要同步 (与上次同步的数据比较)
|
||||
const lastSyncStatusStr = await AsyncStorage.getItem(DAILY_HEALTH_SYNC_KEY);
|
||||
@@ -576,7 +580,8 @@ export async function syncDailyHealthReport(waterIntake?: number): Promise<boole
|
||||
healthData.basalMetabolism !== lastData.basalMetabolism ||
|
||||
healthData.sleepMinutes !== lastData.sleepMinutes ||
|
||||
healthData.bloodOxygen !== lastData.bloodOxygen ||
|
||||
healthData.stressLevel !== lastData.stressLevel;
|
||||
healthData.stressLevel !== lastData.stressLevel ||
|
||||
healthData.steps !== lastData.steps;
|
||||
|
||||
if (!isDifferent) {
|
||||
console.log('每日健康数据无变化,跳过同步');
|
||||
|
||||
Reference in New Issue
Block a user