wangzhibo
2026-08-30 af6b816e29ebe329c59cfdd368bf41d2a4940946
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.jsbogang.womp.health;
 
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
 
import java.util.List;
 
@Dao
public interface HealthDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void upsertSample(HealthSample sample);
 
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void upsertSleep(SleepSession session);
 
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void upsertCursor(SyncCursor cursor);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to ORDER BY timestamp ASC")
    List<HealthSample> samplesInRange(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to ORDER BY timestamp DESC LIMIT 1")
    HealthSample latestInRange(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND heartRate > 0 ORDER BY timestamp DESC LIMIT 1")
    HealthSample latestHeart(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND bpHigh > 0 ORDER BY timestamp DESC LIMIT 1")
    HealthSample latestBp(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND spo2 > 0 ORDER BY timestamp DESC LIMIT 1")
    HealthSample latestSpo2(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to AND glucose > 0 ORDER BY timestamp DESC LIMIT 1")
    HealthSample latestGlucose(String mac, long from, long to);
 
    @Query("SELECT SUM(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to")
    Integer sumSteps(String mac, long from, long to);
 
    @Query("SELECT MAX(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp < :to")
    Integer maxSteps(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE timestamp = :ts AND deviceMac = :mac LIMIT 1")
    HealthSample find(long ts, String mac);
 
    @Query("SELECT SUM(stepValue) FROM health_sample WHERE deviceMac = :mac AND timestamp >= :from AND timestamp <= :to")
    Integer sumStepsTo(String mac, long from, long to);
 
    @Query("SELECT * FROM health_sample WHERE uploaded = 0 ORDER BY timestamp ASC LIMIT 80")
    List<HealthSample> pendingUpload();
 
    @Query("UPDATE health_sample SET uploaded = 1 WHERE timestamp = :ts AND deviceMac = :mac AND dataType = :dataType")
    void markUploaded(long ts, String mac, String dataType);
 
    @Query("SELECT * FROM sleep_session WHERE deviceMac = :mac AND date = :date LIMIT 1")
    SleepSession sleepOf(String mac, String date);
 
    @Query("SELECT lastPosition FROM sync_cursor WHERE deviceMac = :mac AND dayDate = :dayDate")
    Integer cursorOf(String mac, String dayDate);
}