修改首页睡眠数据查询逻辑

This commit is contained in:
feng
2026-01-07 14:50:32 +08:00
parent 66b90d1c14
commit 33470b1a04
2 changed files with 9 additions and 1 deletions
@@ -22,6 +22,14 @@ public interface WatchMapper {
@Select("select length(nm.status) minutes,DATE_FORMAT(n.data_date,'%Y-%m-%d') dataDate from watch_data_sleep_new_minute nm left join watch_data_sleep_new n on nm.sleep_id = n.id where n.id = ( select id from watch_data_sleep_new WHERE bind_user_id = #{id} order by data_date desc limit 1) and nm.STATUS not like '%55%' limit 1") @Select("select length(nm.status) minutes,DATE_FORMAT(n.data_date,'%Y-%m-%d') dataDate from watch_data_sleep_new_minute nm left join watch_data_sleep_new n on nm.sleep_id = n.id where n.id = ( select id from watch_data_sleep_new WHERE bind_user_id = #{id} order by data_date desc limit 1) and nm.STATUS not like '%55%' limit 1")
WatchDataDTO getDataSleep(@Param("id") String id); WatchDataDTO getDataSleep(@Param("id") String id);
/**
* 查询最新的长睡睡眠时间和时长
* @param id 用户ID
* @return
*/
@Select("SELECT long_duration_total minutes, data_date dataDate FROM watch_stat_user_info_day_sleep WHERE user_id = #{id} and long_duration_total > 0 ORDER BY data_date DESC LIMIT 1;")
WatchDataDTO getDataSleepNew(@Param("id") String id);
@Select("SELECT AVG(TIMESTAMPDIFF(MINUTE, d.fall_asleep_time, d.wake_up_time)) AS aveMinute FROM watch_data_sleep_new_day d LEFT JOIN watch_data_sleep_new n ON d.sleep_id = n.id WHERE n.id IN (SELECT id FROM watch_data_sleep_new WHERE bind_user_id = #{id})") @Select("SELECT AVG(TIMESTAMPDIFF(MINUTE, d.fall_asleep_time, d.wake_up_time)) AS aveMinute FROM watch_data_sleep_new_day d LEFT JOIN watch_data_sleep_new n ON d.sleep_id = n.id WHERE n.id IN (SELECT id FROM watch_data_sleep_new WHERE bind_user_id = #{id})")
Double getAverageSleep(@Param("id") String id); Double getAverageSleep(@Param("id") String id);
@@ -323,7 +323,7 @@ public class WatchServiceImpl implements IWatchService {
} }
switch (itemVo.getWdType()) { switch (itemVo.getWdType()) {
case "sleep": case "sleep":
return watchMapper::getDataSleep; return watchMapper::getDataSleepNew;
case "steps": case "steps":
return watchMapper::getDataSteps; return watchMapper::getDataSteps;
case "heart_rate": case "heart_rate":