소스 검색

腕表模块

ct 3 일 전
부모
커밋
11129179b9
65개의 변경된 파일3853개의 추가작업 그리고 462개의 파일을 삭제
  1. 2 2
      fs-doctor-app/src/main/resources/application.yml
  2. 48 0
      fs-service/src/main/java/com/fs/his/domain/FsThirdDeviceData.java
  3. 147 0
      fs-service/src/main/java/com/fs/his/mapper/FsThirdDeviceDataMapper.java
  4. 80 0
      fs-service/src/main/java/com/fs/his/service/IFsThirdDeviceDataService.java
  5. 435 0
      fs-service/src/main/java/com/fs/his/service/impl/FsThirdDeviceDataServiceImpl.java
  6. 544 0
      fs-service/src/main/java/com/fs/watch/calculation/SleepScoreCalculator.java
  7. 4 0
      fs-service/src/main/java/com/fs/watch/domain/DeviceFamily.java
  8. 68 0
      fs-service/src/main/java/com/fs/watch/domain/SleepStatistics.java
  9. 6 0
      fs-service/src/main/java/com/fs/watch/domain/WatchFsUser.java
  10. 25 0
      fs-service/src/main/java/com/fs/watch/domain/WatchUser.java
  11. 3 0
      fs-service/src/main/java/com/fs/watch/domain/vo/AppFsUserVo.java
  12. 27 0
      fs-service/src/main/java/com/fs/watch/domain/vo/DailySleepStatusVo.java
  13. 12 0
      fs-service/src/main/java/com/fs/watch/domain/vo/WatchSportDataByDateAndThirdDeviceVo.java
  14. 10 0
      fs-service/src/main/java/com/fs/watch/domain/vo/WatchSportRecordVo.java
  15. 17 0
      fs-service/src/main/java/com/fs/watch/param/WatchUserByDeviceIdParam.java
  16. 2 1
      fs-service/src/main/java/com/fs/watch/service/WatchBasicInfoService.java
  17. 6 4
      fs-service/src/main/java/com/fs/watch/service/WatchBloodGlucoseDataService.java
  18. 2 0
      fs-service/src/main/java/com/fs/watch/service/WatchBloodPressureDataService.java
  19. 4 3
      fs-service/src/main/java/com/fs/watch/service/WatchDataService.java
  20. 4 2
      fs-service/src/main/java/com/fs/watch/service/WatchHeartRateDataService.java
  21. 1 1
      fs-service/src/main/java/com/fs/watch/service/WatchSleepDataService.java
  22. 2 2
      fs-service/src/main/java/com/fs/watch/service/WatchSpo2DataService.java
  23. 3 3
      fs-service/src/main/java/com/fs/watch/service/WatchSportDataService.java
  24. 4 4
      fs-service/src/main/java/com/fs/watch/service/WatchThirdBpDataService.java
  25. 4 4
      fs-service/src/main/java/com/fs/watch/service/WatchThirdUaDataService.java
  26. 6 1
      fs-service/src/main/java/com/fs/watch/service/WatchUserService.java
  27. 137 49
      fs-service/src/main/java/com/fs/watch/service/impl/WatchBasicInfoServiceImpl.java
  28. 107 19
      fs-service/src/main/java/com/fs/watch/service/impl/WatchBloodGlucoseDataServiceImpl.java
  29. 38 1
      fs-service/src/main/java/com/fs/watch/service/impl/WatchBloodPressureDataServiceImpl.java
  30. 311 113
      fs-service/src/main/java/com/fs/watch/service/impl/WatchDataServiceImpl.java
  31. 1 1
      fs-service/src/main/java/com/fs/watch/service/impl/WatchDeviceInfoServiceImpl.java
  32. 46 8
      fs-service/src/main/java/com/fs/watch/service/impl/WatchHeartRateDataServiceImpl.java
  33. 71 25
      fs-service/src/main/java/com/fs/watch/service/impl/WatchSleepDataServiceImpl.java
  34. 68 23
      fs-service/src/main/java/com/fs/watch/service/impl/WatchSpo2DataServiceImpl.java
  35. 184 43
      fs-service/src/main/java/com/fs/watch/service/impl/WatchSportDataServiceImpl.java
  36. 76 17
      fs-service/src/main/java/com/fs/watch/service/impl/WatchThirdBpDataServiceImpl.java
  37. 62 13
      fs-service/src/main/java/com/fs/watch/service/impl/WatchThirdUaDataServiceImpl.java
  38. 240 20
      fs-service/src/main/java/com/fs/watch/service/impl/WatchUserServiceImpl.java
  39. 1 2
      fs-service/src/main/java/com/fs/watch/utils/MyDateTimeUtils.java
  40. 12 10
      fs-service/src/main/resources/application-dev.yml
  41. 315 0
      fs-service/src/main/resources/mapper/his/FsThirdDeviceDataMapper.xml
  42. 4 0
      fs-service/src/main/resources/mapper/watch/WatchAlarmDataMapper.xml
  43. 74 0
      fs-service/src/main/resources/mapper/watch/WatchAudioLogMsgMapper.xml
  44. 14 0
      fs-service/src/main/resources/mapper/watch/WatchBloodPressureDataMapper.xml
  45. 1 0
      fs-service/src/main/resources/mapper/watch/WatchDeviceDayMapper.xml
  46. 4 6
      fs-service/src/main/resources/mapper/watch/WatchDeviceInfoClicMapper.xml
  47. 35 0
      fs-service/src/main/resources/mapper/watch/WatchDeviceInfoMapper.xml
  48. 107 0
      fs-service/src/main/resources/mapper/watch/WatchDeviceWeekMapper.xml
  49. 3 0
      fs-service/src/main/resources/mapper/watch/WatchDoctorMapper.xml
  50. 12 0
      fs-service/src/main/resources/mapper/watch/WatchHeartRateDataMapper.xml
  51. 99 0
      fs-service/src/main/resources/mapper/watch/WatchSosCallLogsMapper.xml
  52. 11 0
      fs-service/src/main/resources/mapper/watch/WatchSpo2DataMapper.xml
  53. 62 4
      fs-service/src/main/resources/mapper/watch/WatchUserMapper.xml
  54. 213 61
      fs-watch/src/main/java/com/fs/app/controller/WatchController.java
  55. 68 12
      fs-watch/src/main/java/com/fs/app/controller/WatchUserController.java
  56. 1 0
      fs-watch/src/main/java/com/fs/watch/controller/DeviceMaterialsController.java
  57. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchBloodGlucoseDataController.java
  58. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchBloodPressureDataController.java
  59. 2 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchDeviceInfoController.java
  60. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchHeartRateDataController.java
  61. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchSleepDataController.java
  62. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchSpo2DataController.java
  63. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchSportDataController.java
  64. 1 1
      fs-watch/src/main/java/com/fs/watch/controller/WatchThirdUaDataController.java
  65. 1 0
      fs-watch/src/main/java/com/fs/watch/scheduled/HealthDataTask.java

+ 2 - 2
fs-doctor-app/src/main/resources/application.yml

@@ -5,5 +5,5 @@ server:
 # Spring配置
 spring:
   profiles:
-#    active: dev
-    active: dev-yjb
+    active: dev
+#    active: dev-yjb

+ 48 - 0
fs-service/src/main/java/com/fs/his/domain/FsThirdDeviceData.java

@@ -0,0 +1,48 @@
+package com.fs.his.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fs.common.annotation.Excel;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 三方设备健康数据对象 fs_third_device_data
+ *
+ * @author fs
+ * @date 2026-03-19
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class FsThirdDeviceData extends BaseEntity{
+
+    /** 记录id */
+    @TableId
+    private Long id;
+
+    /** 用户id */
+    @Excel(name = "用户id")
+    private Long userId;
+
+    /** 记录类型 0:血压 1:血糖 2:心率  3尿酸 4血氧 */
+    @Excel(name = "记录类型 0:血压 1:血糖 2:心率  3尿酸 4血氧 5步数 6运动 7睡眠")
+    private Integer recordType;
+
+    /** 记录数值 */
+    @Excel(name = "记录数值")
+    private String recordValue;
+
+    /** 记录数值 */
+    @Excel(name = "设备id")
+    private String deviceId;
+
+    /** 设备类型 0小护士设备 1手表 */
+    @Excel(name = "设备类型 0小护士设备 1手表")
+    private Integer deviceType;
+
+    /** 状态 */
+    @Excel(name = "状态")
+    private Integer status;
+
+
+}

+ 147 - 0
fs-service/src/main/java/com/fs/his/mapper/FsThirdDeviceDataMapper.java

@@ -0,0 +1,147 @@
+package com.fs.his.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.watch.domain.vo.WatchSportRecordVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 三方设备健康数据Mapper接口
+ * 
+ * @author fs
+ * @date 2026-03-19
+ */
+public interface FsThirdDeviceDataMapper extends BaseMapper<FsThirdDeviceData>{
+    /**
+     * 查询三方设备健康数据
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 三方设备健康数据
+     */
+    FsThirdDeviceData selectFsThirdDeviceDataById(Long id);
+
+    /**
+     * 查询三方设备健康数据列表
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 三方设备健康数据集合
+     */
+    List<FsThirdDeviceData> selectFsThirdDeviceDataList(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 新增三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    int insertFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 修改三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    int updateFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 删除三方设备健康数据
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 结果
+     */
+    int deleteFsThirdDeviceDataById(Long id);
+
+    /**
+     * 批量删除三方设备健康数据
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    int deleteFsThirdDeviceDataByIds(Long[] ids);
+
+//    Map<String, Integer> countMaxAndMinBpByDate(String currentStartDate, String currentEndDate, String deviceId);
+
+    void insertFsThirdDeviceDataList(@Param("list") List<FsThirdDeviceData> fsThirdDeviceData);
+
+    List<FsThirdDeviceData> getLastData(@Param("userId")Long userId,@Param("deviceType") Integer deviceType,@Param("deviceId") String deviceId);
+
+    /**
+     * 血压
+     * @param startTime
+     * @param endTime
+     * @param deviceId
+     * @return
+     */
+    Map<String, Integer> countMaxAndMinBpByDate(@Param("startTime") String startTime, @Param("endTime") String endTime,
+                                                @Param("deviceId") String deviceId);
+
+    List<FsThirdDeviceData> queryBgByDate(@Param("startTime")String startTime,@Param("endTime") String endTime,
+                                              @Param("deviceId")String deviceId);
+
+    Map<String, Integer> countMaxAndAvgBpByDate(@Param("startTime")String startTime, @Param("endTime") String endTime,
+                                                @Param("deviceId")String deviceId);
+
+    FsThirdDeviceData getFirstDataByDeviceId(@Param("deviceId")String deviceId);
+
+    List<FsThirdDeviceData> queryByMonth(@Param("deviceId")String deviceId, @Param("monthStr")String monthStr,
+                                           @Param("recordType")Integer recordType);
+
+    FsThirdDeviceData getLatest(@Param("deviceId")String deviceId,
+                                @Param("recordType")Integer recordType);
+
+    List<FsThirdDeviceData> selectListByDateAndDeviceIdAndRecordType(@Param("startTime")Date startTime,
+                                                                     @Param("endTime") Date endTime,
+                                                                     @Param("deviceId")String deviceId,
+                                                                     @Param("recordType")Integer recordType,
+                                                                     @Param("status")Integer status);
+
+    List<Map<String, Object>> countByDateAndDeviceIdAndRecordType(@Param("startTime")Date startTime,
+                                                                  @Param("endTime") Date endTime,
+                                                                  @Param("deviceId")String deviceId,
+                                                                  @Param("recordType")Integer recordType,
+                                                                  @Param("status")Integer status);
+
+    int countPageByDateAndDeviceIdAndRecordType(@Param("startTime")Date startTime,
+                                                @Param("endTime") Date endTime,
+                                                @Param("deviceId")String deviceId,
+                                                @Param("recordType")Integer recordType,
+                                                @Param("status")Integer status);
+
+    List<FsThirdDeviceData> queryPageByDateAndDeviceIdAndRecordType(@Param("startTime")Date startTime,
+                                                                    @Param("endTime") Date endTime,
+                                                                    @Param("deviceId")String deviceId,
+                                                                    @Param("recordType")Integer recordType,
+                                                                    @Param("status")Integer status,
+                                                                    @Param("num")Integer num,
+                                                                    @Param("size")Integer size
+                                                                    );
+
+    Float countAvgBpByDate(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("deviceId") String deviceId);
+
+    WatchSportRecordVo getOtherData(@Param("startTime")Date startTime,
+                                    @Param("endTime") Date endTime,
+                                    @Param("deviceId")String deviceId,
+                                    @Param("recordType")Integer recordType,
+                                    @Param("status")Integer status);
+
+    List<WatchSportRecordVo> queryActivityRecord(@Param("startTime")Date startTime,
+                                                 @Param("endTime") Date endTime,
+                                                 @Param("deviceId")String deviceId,
+                                                 @Param("recordType")Integer recordType,
+                                                 @Param("status")Integer status);
+
+    WatchSportRecordVo getOtherDataOther(@Param("startTime")Date startTime,
+                                         @Param("endTime") Date endTime,
+                                         @Param("deviceId")String deviceId,
+                                         @Param("recordType")Integer recordType);
+
+    List<FsThirdDeviceData> selectListByDateAndDeviceIdAndRecordTypeOther(@Param("startTime")Date startTime,
+                                                                          @Param("endTime") Date endTime,
+                                                                          @Param("deviceId")String deviceId,
+                                                                          @Param("recordType")Integer recordType);
+}

+ 80 - 0
fs-service/src/main/java/com/fs/his/service/IFsThirdDeviceDataService.java

@@ -0,0 +1,80 @@
+package com.fs.his.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.watch.domain.vo.WatchSportDataByDateVo;
+import com.fs.watch.domain.vo.WatchSportDetailDataVo;
+import com.fs.watch.domain.vo.WatchSportRecordVo;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 三方设备健康数据Service接口
+ * 
+ * @author fs
+ * @date 2026-03-19
+ */
+public interface IFsThirdDeviceDataService extends IService<FsThirdDeviceData>{
+    /**
+     * 查询三方设备健康数据
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 三方设备健康数据
+     */
+    FsThirdDeviceData selectFsThirdDeviceDataById(Long id);
+
+    /**
+     * 查询三方设备健康数据列表
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 三方设备健康数据集合
+     */
+    List<FsThirdDeviceData> selectFsThirdDeviceDataList(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 新增三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    int insertFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 修改三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    int updateFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData);
+
+    /**
+     * 批量删除三方设备健康数据
+     * 
+     * @param ids 需要删除的三方设备健康数据主键集合
+     * @return 结果
+     */
+    int deleteFsThirdDeviceDataByIds(Long[] ids);
+
+    /**
+     * 删除三方设备健康数据信息
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 结果
+     */
+    int deleteFsThirdDeviceDataById(Long id);
+
+    void insertFsThirdDeviceDataList(List<FsThirdDeviceData> fsThirdDeviceData);
+
+    List<FsThirdDeviceData> getLastData(Long userId,Integer deviceType,String deviceId);
+
+    List<WatchSportDataByDateVo> sportDataByDate(Date startTime, Date endTime, String deviceId);
+
+    WatchSportDetailDataVo dataByType(String deviceId, String type);
+
+    public WatchSportRecordVo getOtherData(Date startTime,
+                                           Date endTime,
+                                           String deviceId,
+                                           Integer recordType,
+                                           Integer status);
+}

+ 435 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsThirdDeviceDataServiceImpl.java

@@ -0,0 +1,435 @@
+package com.fs.his.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
+import com.fs.his.service.IFsThirdDeviceDataService;
+import com.fs.watch.domain.vo.WatchSportDataByDateAndThirdDeviceVo;
+import com.fs.watch.domain.vo.WatchSportDataByDateVo;
+import com.fs.watch.domain.vo.WatchSportDetailDataVo;
+import com.fs.watch.domain.vo.WatchSportRecordVo;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 三方设备健康数据Service业务层处理
+ * 
+ * @author fs
+ * @date 2026-03-19
+ */
+@Service
+public class FsThirdDeviceDataServiceImpl extends ServiceImpl<FsThirdDeviceDataMapper, FsThirdDeviceData> implements IFsThirdDeviceDataService {
+
+    /**
+     * 查询三方设备健康数据
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 三方设备健康数据
+     */
+    @Override
+    public FsThirdDeviceData selectFsThirdDeviceDataById(Long id)
+    {
+        return baseMapper.selectFsThirdDeviceDataById(id);
+    }
+
+    /**
+     * 查询三方设备健康数据列表
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 三方设备健康数据
+     */
+    @Override
+    public List<FsThirdDeviceData> selectFsThirdDeviceDataList(FsThirdDeviceData fsThirdDeviceData)
+    {
+        return baseMapper.selectFsThirdDeviceDataList(fsThirdDeviceData);
+    }
+
+    /**
+     * 新增三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    @Override
+    public int insertFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData)
+    {
+        fsThirdDeviceData.setCreateTime(DateUtils.getNowDate());
+        return baseMapper.insertFsThirdDeviceData(fsThirdDeviceData);
+    }
+
+    /**
+     * 修改三方设备健康数据
+     * 
+     * @param fsThirdDeviceData 三方设备健康数据
+     * @return 结果
+     */
+    @Override
+    public int updateFsThirdDeviceData(FsThirdDeviceData fsThirdDeviceData)
+    {
+        return baseMapper.updateFsThirdDeviceData(fsThirdDeviceData);
+    }
+
+    /**
+     * 批量删除三方设备健康数据
+     * 
+     * @param ids 需要删除的三方设备健康数据主键
+     * @return 结果
+     */
+    @Override
+    public int deleteFsThirdDeviceDataByIds(Long[] ids)
+    {
+        return baseMapper.deleteFsThirdDeviceDataByIds(ids);
+    }
+
+    /**
+     * 删除三方设备健康数据信息
+     * 
+     * @param id 三方设备健康数据主键
+     * @return 结果
+     */
+    @Override
+    public int deleteFsThirdDeviceDataById(Long id)
+    {
+        return baseMapper.deleteFsThirdDeviceDataById(id);
+    }
+
+    @Override
+    public void insertFsThirdDeviceDataList(List<FsThirdDeviceData> fsThirdDeviceData) {
+        baseMapper.insertFsThirdDeviceDataList(fsThirdDeviceData);
+    }
+
+    @Override
+    public List<FsThirdDeviceData> getLastData(Long userId,Integer deviceType,String deviceId) {
+        return baseMapper.getLastData(userId,deviceType,deviceId);
+    }
+
+    /**
+     * 查询运动
+     * @param startTime
+     * @param endTime
+     * @param deviceId
+     * @return
+     */
+    @Override
+    public List<WatchSportDataByDateVo> sportDataByDate(Date startTime, Date endTime, String deviceId) {
+        //活动
+        ArrayList<FsThirdDeviceData> activity = new ArrayList<>();
+        List<FsThirdDeviceData> activity1 = baseMapper.selectListByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId,5,null);
+        activity.addAll(activity1);
+//        activity.addAll(activity2);
+        //解析成活动数据
+        if(!activity.isEmpty()){
+            ArrayList<WatchSportDataByDateAndThirdDeviceVo> vos = new ArrayList<>();
+            for (FsThirdDeviceData fsThirdDeviceData : activity) {
+                String recordValue = fsThirdDeviceData.getRecordValue();
+                if (StringUtils.isNotBlank(recordValue)) {
+                    WatchSportDataByDateAndThirdDeviceVo data = new WatchSportDataByDateAndThirdDeviceVo();
+                    JSONObject jsonObject = JSONObject.parseObject(recordValue);
+                    data.setDeviceId(jsonObject.getString("deviceId"));
+                    data.setStep(Integer.valueOf(jsonObject.get("steps").toString()));
+                    data.setDistance(Float.parseFloat(jsonObject.get("distance").toString())*1000);
+                    data.setCalorie(Float.valueOf(jsonObject.get("calories").toString()));
+//                    data.setType(getActivityType(Integer.valueOf(jsonObject.get("sportType").toString())));
+                    data.setState(0);
+                    data.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                    vos.add(data);
+
+                }
+            }
+            // 计算时间差(以毫秒为单位)
+            long timeDifferenceInMillis = endTime.getTime() - startTime.getTime();
+
+            // 判断是一天还是一周
+            if (timeDifferenceInMillis > 24 * 60 * 60 * 1000) {
+                // 一周的数据(按天统计)
+                return getWeekData(vos, LocalDateTime.ofInstant(startTime.toInstant(), ZoneId.systemDefault()),
+                        LocalDateTime.ofInstant(endTime.toInstant(), ZoneId.systemDefault()));
+            } else {
+                // 一天的数据(按小时统计)
+                return getDayData(vos);
+            }
+        }
+        return null;
+
+    }
+
+    @Override
+    public WatchSportDetailDataVo dataByType(String deviceId, String type) {
+        if (StringUtils.isNotBlank(deviceId)) {
+            //详情
+            WatchSportDetailDataVo vo = new WatchSportDetailDataVo();
+            ArrayList<WatchSportDataByDateVo> list = new ArrayList<>();
+            //1.总计 距离 次数
+            WatchSportRecordVo recordVo = null; //总计只有一条数据
+            List<FsThirdDeviceData> otherDetail = null;
+            if ("其他运动".equals(type)) {
+                //游泳", "登山", "骑行", "跑步", "球类", "健走", "走路"
+                //25,17,1,9,21,5,13
+                recordVo = baseMapper.getOtherDataOther(null, null, deviceId, 6);
+                otherDetail = baseMapper.selectListByDateAndDeviceIdAndRecordTypeOther(null, null, deviceId, 6);
+            } else {
+                Integer sportType = getSportType(type);
+                //步数
+                recordVo = baseMapper.getOtherData(null, null, deviceId, 6, sportType);
+                //2.详情
+                otherDetail = baseMapper.selectListByDateAndDeviceIdAndRecordType(null, null, deviceId, 6, sportType);
+            }
+            long otherTime = 0L;
+            if (otherDetail != null && !otherDetail.isEmpty()) {
+                for (FsThirdDeviceData fsThirdDeviceData : otherDetail) {
+                    String recordValue = fsThirdDeviceData.getRecordValue();
+                    if (StringUtils.isNotBlank(recordValue)) {
+                        JSONObject jsonObject = JSONObject.parseObject(recordValue);
+                        float distance = Float.parseFloat(jsonObject.get("distance").toString());
+                        Float calories = Float.valueOf(jsonObject.get("calories").toString());
+                        String createTime = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", fsThirdDeviceData.getCreateTime());
+                        float duration = Float.parseFloat(jsonObject.get("duration").toString());
+                        otherTime = otherTime + Long.parseLong(jsonObject.get("duration").toString());
+
+                        //详情
+                        WatchSportDataByDateVo watchSportDataByDateVo = new WatchSportDataByDateVo();
+                        watchSportDataByDateVo.setCreateTime(createTime);
+                        watchSportDataByDateVo.setCalorie(calories);
+                        watchSportDataByDateVo.setDistance(distance);
+                        watchSportDataByDateVo.setTime(duration);
+                        watchSportDataByDateVo.setSpeed((float) Math.round((distance)/(duration/3600)));
+                        list.add(watchSportDataByDateVo);
+                    }
+                }
+            }
+            if (recordVo != null) {
+                vo.setDistanceTotal(recordVo.getDistance()); //换算公里 保留两位
+                vo.setCountTotal(recordVo.getCount());
+                //1.2时长
+                BigDecimal timeInMinutes = new BigDecimal(otherTime)
+                        .divide(new BigDecimal(3600), 2, RoundingMode.HALF_UP);
+                vo.setTimeTotal(Float.valueOf(timeInMinutes+""));
+            }
+            vo.setList(list);
+            return vo;
+        }
+        return null;
+    }
+
+    private String getActivityType(Integer sportType) {
+        if (sportType == null) {
+            return null;
+        }
+        switch (sportType) {
+            case 1:
+                return "骑行";
+            case 5:
+                return "户外跑/健走";
+            case 9:
+                return "室内跑";
+            case 13:
+                return "步行";
+            case 17:
+                return "爬山";
+            case 21:
+                return "篮球";
+            case 25:
+                return "游泳";
+            case 29:
+                return "羽毛球";
+            case 33:
+                return "足球";
+            case 37:
+                return "椭圆机";
+            case 41:
+                return "瑜伽";
+            case 45:
+                return "乒乓球";
+            case 49:
+                return "跳绳";
+            case 53:
+                return "划船机";
+            case 65:
+                return "自由训练";
+            case 69:
+                return "网球";
+            case 85:
+                return "自由运动";
+            case 89:
+                return "力量训练";
+            case 105:
+                return "舞蹈";
+            case 109:
+                return "呼啦圈";
+            case 113:
+                return "高尔夫";
+            default:
+                return null;
+        }
+    }
+
+    private Integer getSportType(String activityType) {
+        //游泳", "登山", "骑行", "跑步", "球类", "健走", "走路" 25,17,1,9,21,5,13
+        if (activityType == null || activityType.isEmpty()) {
+            return null;
+        }
+        switch (activityType) {
+            case "骑行":
+                return 1;
+            case "健步走":
+                return 5;
+            case "跑步":
+                return 9;
+            case "走路":
+                return 13;
+            case "登山":
+                return 17;
+            case "球类":
+                return 21;
+            case "游泳":
+                return 25;
+            case "羽毛球":
+                return 29;
+            case "足球":
+                return 33;
+            case "椭圆机":
+                return 37;
+            case "瑜伽":
+                return 41;
+            case "乒乓球":
+                return 45;
+            case "跳绳":
+                return 49;
+            case "划船机":
+                return 53;
+            case "自由训练":
+                return 65;
+            case "网球":
+                return 69;
+            case "自由运动":
+                return 85;
+            case "力量训练":
+                return 89;
+            case "舞蹈":
+                return 105;
+            case "呼啦圈":
+                return 109;
+            case "高尔夫":
+                return 113;
+            default:
+                return null;
+
+        }
+    }
+
+    private List<WatchSportDataByDateVo> getWeekData(List<WatchSportDataByDateAndThirdDeviceVo> activity, LocalDateTime startTime, LocalDateTime endTime) {
+        // 按天分组
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        Map<LocalDate, List<WatchSportDataByDateAndThirdDeviceVo>> groupedByDate = activity.stream()
+                .collect(Collectors.groupingBy(data -> {
+                    LocalDateTime dateTime = LocalDateTime.parse(data.getCreateTime(), dateTimeFormatter);
+                    return dateTime.toLocalDate();
+                }));
+
+        // 确定一周的起始日期(周一)
+        LocalDate startOfWeek = startTime.toLocalDate().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+        // 初始化结果列表,确保返回7天的数据
+        List<WatchSportDataByDateVo> result = new ArrayList<>();
+        for (int i = 0; i < 7; i++) {
+            LocalDate currentDate = startOfWeek.plusDays(i);
+//            LocalDate currentDate = startDate.plusDays(i);
+            List<WatchSportDataByDateAndThirdDeviceVo> dayData = groupedByDate.getOrDefault(currentDate, Collections.emptyList());
+
+            // 汇总每天数据
+            float totalDistance = (float) dayData.stream()
+                    .mapToDouble(data -> Optional.ofNullable(data.getDistance()).orElse(0f)).sum();
+            float totalCalorie = (float) dayData.stream()
+                    .mapToDouble(data -> Optional.ofNullable(data.getCalorie()).orElse(0f)).sum();
+            float totalTime = (float) dayData.stream()
+                    .mapToDouble(data -> Optional.ofNullable(data.getDuration()).orElse(0f)).sum();
+
+
+            // 创建统计对象
+            WatchSportDataByDateVo vo = new WatchSportDataByDateVo();
+            Float distance = Math.round(totalDistance/1000 * 100) / 100f;
+            vo.setDistance(distance); //换算公里
+            vo.setCalorie(Math.round(totalCalorie * 100) / 100f);
+            Float time = Math.round(totalTime * 100) / 100f;
+            if (time <=0){
+                time = 24*60*60f;
+            }
+            vo.setTime(time); //秒
+            float avgSpeed = time > 0 ? distance / (totalTime/3600) : 0;
+            vo.setSpeed(Math.round(avgSpeed * 100) / 100f);
+            result.add(vo);
+        }
+        return result;
+    }
+
+    private List<WatchSportDataByDateVo> getDayData(List<WatchSportDataByDateAndThirdDeviceVo> activity) {
+        // 提前分配24小时结果数组
+        WatchSportDataByDateVo[] result = new WatchSportDataByDateVo[24];
+        for (int i = 0; i < 24; i++) {
+            result[i] = new WatchSportDataByDateVo(); // 初始化每小时的默认值
+            result[i].setDistance(0f);
+            result[i].setCalorie(0f);
+            result[i].setTime(0f); // 默认总时间为0秒
+            result[i].setSpeed(0f);
+        }
+
+        // 定义时间解析器
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        // 按小时分组并直接统计
+        for (WatchSportDataByDateAndThirdDeviceVo data : activity) {
+            // 解析 createTime 的小时
+            LocalDateTime dateTime = LocalDateTime.parse(data.getCreateTime(), formatter);
+            int hour = dateTime.getHour();
+
+            // 获取对应小时的统计对象
+            WatchSportDataByDateVo vo = result[hour];
+
+            // 累加距离和卡路里
+            float dis = vo.getDistance() + ((Optional.ofNullable(data.getDistance()).orElse(0f)) / 1000);
+            float cal = vo.getCalorie() + Optional.ofNullable(data.getCalorie()).orElse(0f);
+            float time = vo.getTime() + Optional.ofNullable(data.getDuration()).orElse(0f);
+            vo.setDistance(Math.round(dis * 100) / 100f); //换算公里
+            vo.setCalorie(Math.round(cal * 100) / 100f);
+            // 假设每条记录表示1分钟运动///todo
+//            vo.setTime(vo.getTime() + 1f / 60); // 累加时间,单位为小时
+            if (time <= 0) {
+                time = 3600;
+            }
+            vo.setTime(time); // 累加时间,单位秒
+        }
+
+
+        // 计算每小时的平均速度
+        for (WatchSportDataByDateVo vo : result) {
+            if (vo.getTime() > 0) {
+                vo.setSpeed(Math.round((vo.getDistance() / (vo.getTime()/3600)) * 100) / 100f); // 平均速度 = 距离 / 时间
+            }
+        }
+        return Arrays.asList(result);
+    }
+
+    @Override
+    public WatchSportRecordVo getOtherData(Date startTime,
+                                    Date endTime,
+                                    String deviceId,
+                                    Integer recordType,
+                                    Integer status){
+        return baseMapper.getOtherData(startTime,endTime,deviceId,recordType,status);
+
+    }
+
+
+}

+ 544 - 0
fs-service/src/main/java/com/fs/watch/calculation/SleepScoreCalculator.java

@@ -0,0 +1,544 @@
+package com.fs.watch.calculation;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fs.common.utils.DateUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
+import com.fs.watch.domain.SleepSection;
+import com.fs.watch.domain.SleepStatistics;
+import com.fs.watch.domain.vo.AppWatchSleepDataVo;
+import com.fs.watch.domain.vo.DailySleepStatusVo;
+import com.fs.watch.enums.WatchSleepStatusEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.Future;
+
+/**
+ * 睡眠评分计算工具类
+ */
+@Slf4j
+@Component
+public class SleepScoreCalculator {
+
+    // 类型常量
+    private static final int TYPE_DEEP_SLEEP = 3;      // 深睡
+    private static final int TYPE_LIGHT_SLEEP = 4;     // 浅睡
+    private static final int TYPE_AWAKE = 6;           // 清醒
+    private static final int TYPE_REM = 7;             // 快速眼动
+    @Autowired
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;  // 现在可以注入了
+
+    @Autowired
+    private FsThirdDeviceDataMapper sleepDataMapper;
+
+    /**
+     * 计算睡眠评分
+     * @param sleepRecords 睡眠记录列表
+     * @return 睡眠评分(0-100分)
+     */
+    public static int calculateSleepScore(List<FsThirdDeviceData> sleepRecords) {
+        if (sleepRecords == null || sleepRecords.isEmpty()) {
+            return 0;
+        }
+
+        long totalDuration = 0;      // 总睡眠时长(毫秒)
+        long deepSleepDuration = 0;   // 深睡时长(毫秒)
+        long lightSleepDuration = 0;  // 浅睡时长(毫秒)
+        long awakeDuration = 0;       // 清醒时长(毫秒)
+        int awakeCount = 0;           // 清醒次数
+
+        for (FsThirdDeviceData record : sleepRecords) {
+            String recordValue = record.getRecordValue();
+            if (recordValue == null || recordValue.isEmpty()) {
+                continue;
+            }
+
+            try {
+                JSONObject json = JSONObject.parseObject(recordValue);
+                Long startTime = json.getLong("startTime");
+                Long endTime = json.getLong("endTime");
+                Integer status = json.getInteger("status");
+
+                if (startTime == null || endTime == null || status == null) {
+                    continue;
+                }
+
+                long duration = endTime - startTime;
+                totalDuration += duration;
+
+                switch (status) {
+                    case 1: // 深睡
+                        deepSleepDuration += duration;
+                        break;
+                    case 2: // 浅睡
+                        lightSleepDuration += duration;
+                        break;
+                    case 3: // 清醒
+                        awakeDuration += duration;
+                        awakeCount++;
+                        break;
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        // 计算各维度得分
+        int durationScore = calculateDurationScore(totalDuration);
+        int deepSleepRatioScore = calculateDeepSleepRatioScore(deepSleepDuration, totalDuration);
+        int lightSleepRatioScore = calculateLightSleepRatioScore(lightSleepDuration, totalDuration);
+        int awakeScore = calculateAwakeScore(awakeDuration, awakeCount, totalDuration);
+
+        // 总分 = 时长分*30% + 深睡比例分*35% + 浅睡比例分*15% + 清醒分*20%
+        int totalScore = (int)(durationScore * 0.30
+                + deepSleepRatioScore * 0.35
+                + lightSleepRatioScore * 0.15
+                + awakeScore * 0.20);
+
+        return Math.min(100, Math.max(0, totalScore));
+    }
+
+    /**
+     * 计算详细的睡眠统计数据
+     * @param sleepRecords 睡眠记录列表
+     * @return 睡眠统计信息
+     */
+    public static SleepStatistics calculateDetailedStatistics(List<FsThirdDeviceData> sleepRecords) {
+        SleepStatistics statistics = new SleepStatistics();
+
+        if (sleepRecords == null || sleepRecords.isEmpty()) {
+            return statistics;
+        }
+
+        long totalDuration = 0;
+        long deepSleepDuration = 0;
+        long lightSleepDuration = 0;
+        long awakeDuration = 0;
+        long remDuration = 0;
+        int deepSleepCount = 0;
+        int lightSleepCount = 0;
+        int awakeCount = 0;
+        int remCount = 0;
+
+        List<SleepSection> sleepSectionList = new ArrayList<>();
+        for (FsThirdDeviceData record : sleepRecords) {
+            String recordValue = record.getRecordValue();
+            if (recordValue == null || recordValue.isEmpty()) {
+                continue;
+            }
+
+            try {
+                JSONObject json = JSONObject.parseObject(recordValue);
+                Long startTime = json.getLong("startTime");
+                Long endTime = json.getLong("endTime");
+                Integer status = json.getInteger("status");
+
+                if (startTime == null || endTime == null || status == null) {
+                    continue;
+                }
+
+                long duration = endTime - startTime;
+                totalDuration += duration;
+
+                // 创建睡眠区间
+                SleepSection section = new SleepSection();
+                // 将时间戳转换为指定格式
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                section.setStart(sdf.format(new Date(startTime)));
+                section.setEnd(sdf.format(new Date(endTime)));
+
+                // status 转换为 type
+                // status: 1深睡, 2浅睡, 3清醒
+                // type: 3深睡, 4浅睡, 6清醒, 7快速眼动
+                Integer type = convertStatusToType(status);
+                section.setType(type);
+                sleepSectionList.add(section);
+
+                switch (status) {
+                    case 1: // 深睡
+                        deepSleepDuration += duration;
+                        deepSleepCount++;
+                        break;
+                    case 2: // 浅睡
+                        lightSleepDuration += duration;
+                        lightSleepCount++;
+                        break;
+                    case 3: // 清醒
+                        awakeDuration += duration;
+                        awakeCount++;
+                        break;
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        // 设置统计数据
+        statistics.setTotalDuration(totalDuration);
+        statistics.setTotalSleepHours(totalDuration / 3600000.0);
+        statistics.setDeepSleepDuration(deepSleepDuration);
+        statistics.setDeepSleepHours(deepSleepDuration / 3600000.0);
+        statistics.setDeepSleepCount(deepSleepCount);
+        statistics.setLightSleepDuration(lightSleepDuration);
+        statistics.setLightSleepHours(lightSleepDuration / 3600000.0);
+        statistics.setLightSleepCount(lightSleepCount);
+        statistics.setAwakeDuration(awakeDuration);
+        statistics.setAwakeHours(awakeDuration / 3600000.0);
+        statistics.setAwakeCount(awakeCount);
+        statistics.setRemDuration(remDuration);
+        statistics.setRemHours(remDuration / 3600000.0);
+        statistics.setRemCount(remCount);
+        statistics.setSleepSection(sleepSectionList);
+
+        if (totalDuration > 0) {
+            statistics.setDeepSleepRatio((double) deepSleepDuration / totalDuration);
+            statistics.setLightSleepRatio((double) lightSleepDuration / totalDuration);
+            statistics.setAwakeRatio((double) awakeDuration / totalDuration);
+            statistics.setRemRatio((double) remDuration / totalDuration);
+        }
+
+        return statistics;
+    }
+
+    /**
+     * 将 status 转换为 type
+     * @param status 1:深睡 2:浅睡 3:清醒
+     * @return type 3:深睡 4:浅睡 6:清醒 7:快速眼动
+     */
+    private static Integer convertStatusToType(Integer status) {
+        if (status == null) {
+            return 6; // 默认清醒
+        }
+        switch (status) {
+            case 1:
+                return TYPE_DEEP_SLEEP;  // 深睡
+            case 2:
+                return TYPE_LIGHT_SLEEP; // 浅睡
+            case 3:
+                return TYPE_AWAKE;       // 清醒
+            default:
+                return TYPE_AWAKE;
+        }
+    }
+
+
+    /**
+     * 睡眠时长评分(满分100分)
+     * 标准:成人建议7-8小时
+     */
+    private static int calculateDurationScore(long totalDurationMs) {
+        double hours = totalDurationMs / 3600000.0;
+
+        if (hours >= 7 && hours <= 8) {
+            return 100;
+        } else if (hours >= 6 && hours < 7) {
+            return 80;
+        } else if (hours >= 8 && hours <= 9) {
+            return 85;
+        } else if (hours >= 5 && hours < 6) {
+            return 60;
+        } else if (hours > 9 && hours <= 10) {
+            return 70;
+        } else if (hours >= 4 && hours < 5) {
+            return 40;
+        } else if (hours > 10) {
+            return 50;
+        } else {
+            return 20;
+        }
+    }
+
+    /**
+     * 深睡比例评分(满分100分)
+     * 标准:深睡应占总睡眠时长的20-25%
+     */
+    private static int calculateDeepSleepRatioScore(long deepSleepDuration, long totalDuration) {
+        if (totalDuration <= 0) {
+            return 0;
+        }
+
+        double ratio = (double) deepSleepDuration / totalDuration;
+
+        if (ratio >= 0.20 && ratio <= 0.25) {
+            return 100;
+        } else if (ratio >= 0.15 && ratio < 0.20) {
+            return 80;
+        } else if (ratio > 0.25 && ratio <= 0.30) {
+            return 85;
+        } else if (ratio >= 0.10 && ratio < 0.15) {
+            return 60;
+        } else if (ratio > 0.30 && ratio <= 0.35) {
+            return 70;
+        } else if (ratio >= 0.05 && ratio < 0.10) {
+            return 40;
+        } else {
+            return 20;
+        }
+    }
+
+    /**
+     * 浅睡比例评分(满分100分)
+     * 标准:浅睡应占总睡眠时长的50-60%
+     */
+    private static int calculateLightSleepRatioScore(long lightSleepDuration, long totalDuration) {
+        if (totalDuration <= 0) {
+            return 0;
+        }
+
+        double ratio = (double) lightSleepDuration / totalDuration;
+
+        if (ratio >= 0.50 && ratio <= 0.60) {
+            return 100;
+        } else if (ratio >= 0.40 && ratio < 0.50) {
+            return 80;
+        } else if (ratio > 0.60 && ratio <= 0.70) {
+            return 85;
+        } else if (ratio >= 0.30 && ratio < 0.40) {
+            return 60;
+        } else if (ratio > 0.70 && ratio <= 0.80) {
+            return 70;
+        } else {
+            return 40;
+        }
+    }
+
+    /**
+     * 清醒评分(满分100分)
+     * 评估清醒时长和清醒次数
+     */
+    private static int calculateAwakeScore(long awakeDuration, int awakeCount, long totalDuration) {
+        if (totalDuration <= 0) {
+            return 0;
+        }
+
+        double awakeRatio = (double) awakeDuration / totalDuration;
+
+        // 清醒时长评分
+        int durationScore;
+        if (awakeRatio <= 0.05) {
+            durationScore = 100;
+        } else if (awakeRatio <= 0.10) {
+            durationScore = 80;
+        } else if (awakeRatio <= 0.15) {
+            durationScore = 60;
+        } else if (awakeRatio <= 0.20) {
+            durationScore = 40;
+        } else {
+            durationScore = 20;
+        }
+
+        // 清醒次数评分
+        int countScore;
+        if (awakeCount <= 2) {
+            countScore = 100;
+        } else if (awakeCount <= 4) {
+            countScore = 80;
+        } else if (awakeCount <= 6) {
+            countScore = 60;
+        } else if (awakeCount <= 8) {
+            countScore = 40;
+        } else {
+            countScore = 20;
+        }
+
+        return (int)(durationScore * 0.6 + countScore * 0.4);
+    }
+
+    /**
+     * 获取睡眠状态评估结果
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param deviceId 设备ID
+     * @return 睡眠状态描述
+     */
+    public String getSleepStatus(Date startTime, Date endTime, String deviceId
+                                 ) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        // 构造日期列表
+        List<String> dateList = new ArrayList<>();
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(startTime);
+        while (!calendar.getTime().after(endTime)) {
+            dateList.add(sdf.format(calendar.getTime()));
+            calendar.add(Calendar.DATE, 1);
+        }
+
+        int taskCount = dateList.size();
+        ExecutorCompletionService<WatchSleepStatusEnum> completionService =
+                new ExecutorCompletionService<>(threadPoolTaskExecutor);
+
+        // 提交任务
+        for (String date : dateList) {
+            completionService.submit(() -> {
+                AppWatchSleepDataVo sleepVo = queryByDateAndDeviceIdAndState(date, deviceId);
+                return getSleepEnum(sleepVo);
+            });
+        }
+
+        try {
+            for (int i = 0; i < taskCount; i++) {
+                Future<WatchSleepStatusEnum> future = completionService.take();
+                WatchSleepStatusEnum result = future.get();
+                if (!WatchSleepStatusEnum.NORMAL.equals(result)) {
+                    return result.getDesc();
+                }
+            }
+        } catch (Exception e) {
+            log.error("判断睡眠状态异常:{}", e.getMessage(), e);
+        }
+        return WatchSleepStatusEnum.NORMAL.getDesc();
+    }
+
+    /**
+     * 根据日期和设备ID查询睡眠数据
+     * @param date 日期(yyyy-MM-dd格式)
+     * @param deviceId 设备ID
+     * @return 睡眠数据VO
+     */
+    private AppWatchSleepDataVo queryByDateAndDeviceIdAndState(String date, String deviceId) {
+        try {
+            // 解析日期范围
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Date startDate = sdf.parse(date);
+            Date endDate = DateUtils.addMilliseconds(
+                    DateUtils.addDays(startDate, 1),
+                    -1
+            );
+
+            // 查询当天的所有睡眠记录
+            List<FsThirdDeviceData> sleepRecords = sleepDataMapper.selectListByDateAndDeviceIdAndRecordType(
+                    startDate, endDate, deviceId, 7, null);
+
+            if (sleepRecords == null || sleepRecords.isEmpty()) {
+                return null;
+            }
+
+            // 计算详细统计信息
+            SleepStatistics statistics = calculateDetailedStatistics(sleepRecords);
+
+            // 转换为 AppWatchSleepDataVo
+            AppWatchSleepDataVo sleepVo = new AppWatchSleepDataVo();
+
+            // 总睡眠时间(分钟)
+            if (statistics.getTotalSleepHours() != null) {
+                sleepVo.setSleepTime((int) (statistics.getTotalSleepHours() * 60));
+            }
+
+            // 深睡时间(分钟)
+            if (statistics.getDeepSleepHours() != null) {
+                sleepVo.setDeepSleep((int) (statistics.getDeepSleepHours() * 60));
+            }
+
+            // 浅睡时间(分钟)
+            if (statistics.getLightSleepHours() != null) {
+                sleepVo.setLightSleep((int) (statistics.getLightSleepHours() * 60));
+            }
+
+            // 清醒次数
+            sleepVo.setWeakTime(statistics.getAwakeCount());
+
+            // 夜间睡眠次数(深睡次数 + 浅睡次数)
+            sleepVo.setSleepCount(statistics.getDeepSleepCount() + statistics.getLightSleepCount());
+
+            // 深睡比例(百分比)
+            if (statistics.getDeepSleepRatio() != null) {
+                sleepVo.setDeepScale((int) (statistics.getDeepSleepRatio() * 100));
+            }
+
+            // 浅睡比例(百分比)
+            if (statistics.getLightSleepRatio() != null) {
+                sleepVo.setLightScale((int) (statistics.getLightSleepRatio() * 100));
+            }
+
+            // 快速眼动比例(百分比)
+            if (statistics.getRemRatio() != null) {
+                sleepVo.setEyemoveScale((int) (statistics.getRemRatio() * 100));
+            }
+
+            return sleepVo;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 根据睡眠数据获取睡眠状态枚举
+     * @param sleepVo 睡眠数据VO
+     * @return 睡眠状态枚举
+     */
+    private WatchSleepStatusEnum getSleepEnum(AppWatchSleepDataVo sleepVo) {
+        WatchSleepStatusEnum sleepEnum = WatchSleepStatusEnum.NORMAL;
+        if (sleepVo != null) {
+            Integer sleepTime = sleepVo.getSleepTime();  // 总睡眠时间(分钟)
+            Integer deepSleep = sleepVo.getDeepSleep(); // 深睡时间(分钟)
+
+            if (sleepTime != null && sleepTime > 0) {
+                // 睡眠剥夺:总睡眠时间少于5小时(300分钟)
+                if (sleepTime < 300) {
+                    return WatchSleepStatusEnum.DEPRIVATION;
+                }
+                // OSA高风险:深睡比例低于15%
+                if (deepSleep != null) {
+                    double deepSleepRatio = (double) deepSleep / sleepTime;
+                    if (deepSleepRatio < 0.15) {
+                        return WatchSleepStatusEnum.OSA;
+                    }
+                }
+            }
+        }
+        return sleepEnum;
+    }
+
+    /**
+     * 批量获取多日睡眠状态(用于趋势分析)
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param deviceId 设备ID
+     * @return 每日睡眠状态列表
+     */
+    public List<DailySleepStatusVo> getDailySleepStatusList(Date startTime, Date endTime,
+                                                            String deviceId) {
+        List<DailySleepStatusVo> resultList = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(startTime);
+
+        while (!calendar.getTime().after(endTime)) {
+            String dateStr = sdf.format(calendar.getTime());
+            DailySleepStatusVo dailyStatus = new DailySleepStatusVo();
+            dailyStatus.setDate(dateStr);
+
+            try {
+                AppWatchSleepDataVo sleepVo = queryByDateAndDeviceIdAndState(dateStr, deviceId);
+                WatchSleepStatusEnum statusEnum = getSleepEnum(sleepVo);
+                dailyStatus.setStatus(statusEnum.getDesc());
+                dailyStatus.setStatusValue(statusEnum.getValue());
+
+                if (sleepVo != null) {
+                    dailyStatus.setSleepTime(sleepVo.getSleepTime());
+                    dailyStatus.setDeepSleep(sleepVo.getDeepSleep());
+                    dailyStatus.setDeepScale(sleepVo.getDeepScale());
+                }
+            } catch (Exception e) {
+                log.error("查询日期 {} 睡眠状态异常:{}", dateStr, e.getMessage());
+                dailyStatus.setStatus("查询失败");
+            }
+
+            resultList.add(dailyStatus);
+            calendar.add(Calendar.DATE, 1);
+        }
+
+        return resultList;
+    }
+}

+ 4 - 0
fs-service/src/main/java/com/fs/watch/domain/DeviceFamily.java

@@ -8,6 +8,10 @@ public class DeviceFamily {
     private String name;
     //设备id
     private String deviceId;
+    //小护士设备
+    private String xhsDeviceId;
+    //小护士手表
+    private String newXhsDeviceId;
     //关系
     private String relationship;
 }

+ 68 - 0
fs-service/src/main/java/com/fs/watch/domain/SleepStatistics.java

@@ -0,0 +1,68 @@
+package com.fs.watch.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 睡眠统计信息
+ */
+@Data
+public class SleepStatistics {
+    /** 总睡眠时长(小时) */
+    private Double totalSleepHours;
+
+    /** 总睡眠时长(毫秒) */
+    private Long totalDuration;
+
+    /** 深睡时长(小时) */
+    private Double deepSleepHours;
+
+    /** 深睡时长(毫秒) */
+    private Long deepSleepDuration;
+
+    /** 深睡次数 */
+    private Integer deepSleepCount;
+
+    /** 浅睡时长(小时) */
+    private Double lightSleepHours;
+
+    /** 浅睡时长(毫秒) */
+    private Long lightSleepDuration;
+
+    /** 浅睡次数 */
+    private Integer lightSleepCount;
+
+    /** 清醒时长(小时) */
+    private Double awakeHours;
+
+    /** 清醒时长(毫秒) */
+    private Long awakeDuration;
+
+    /** 清醒次数 */
+    private Integer awakeCount;
+
+    /** 快速眼动时长(小时) */
+    private Double remHours;
+
+    /** 快速眼动时长(毫秒) */
+    private Long remDuration;
+
+    /** 快速眼动次数 */
+    private Integer remCount;
+
+    /** 深睡比例(0-1) */
+    private Double deepSleepRatio;
+
+    /** 浅睡比例(0-1) */
+    private Double lightSleepRatio;
+
+    /** 清醒比例(0-1) */
+    private Double awakeRatio;
+
+    /** 快速眼动比例(0-1) */
+    private Double remRatio;
+
+    /** 睡眠区间列表(用于图表展示) */
+    private List<SleepSection> sleepSection;
+}

+ 6 - 0
fs-service/src/main/java/com/fs/watch/domain/WatchFsUser.java

@@ -177,4 +177,10 @@ public class WatchFsUser extends BaseEntity {
      */
     private String monitorDataTypeOrder;
 
+    //小护士设备id
+    private String xhsDeviceId;
+
+    //小护士手表设备id
+    private String newXhsDeviceId;
+
 }

+ 25 - 0
fs-service/src/main/java/com/fs/watch/domain/WatchUser.java

@@ -87,6 +87,15 @@ public class WatchUser implements Serializable {
 
 
 
+    //小护士设备id
+    private String xhsDeviceId;
+
+
+    //小护士手表设备id
+    private String newXhsDeviceId;
+
+
+
     public String getTargetActivity() {
         return targetActivity;
     }
@@ -223,5 +232,21 @@ public class WatchUser implements Serializable {
     public void setNickName(String nickName) {
         this.nickName = nickName;
     }
+    public String getXhsDeviceId() {
+        return xhsDeviceId;
+    }
+
+    public void setXhsDeviceId(String xhsDeviceId) {
+        this.xhsDeviceId = xhsDeviceId;
+    }
+
+
+    public String getNewXhsDeviceId() {
+        return newXhsDeviceId;
+    }
+
+    public void setNewXhsDeviceId(String newXhsDeviceId) {
+        this.newXhsDeviceId = newXhsDeviceId;
+    }
 }
 

+ 3 - 0
fs-service/src/main/java/com/fs/watch/domain/vo/AppFsUserVo.java

@@ -123,4 +123,7 @@ public class AppFsUserVo {
     @Excel(name = "既往病史")
     private String previousMedicalHistory;
 
+    //小护士设备id
+    private String xhsDeviceId;
+
 }

+ 27 - 0
fs-service/src/main/java/com/fs/watch/domain/vo/DailySleepStatusVo.java

@@ -0,0 +1,27 @@
+package com.fs.watch.domain.vo;
+
+import lombok.Data;
+
+/**
+ * 每日睡眠状态VO
+ */
+@Data
+public class DailySleepStatusVo {
+    /** 日期(yyyy-MM-dd) */
+    private String date;
+
+    /** 睡眠状态描述 */
+    private String status;
+
+    /** 睡眠状态值 */
+    private Integer statusValue;
+
+    /** 总睡眠时间(分钟) */
+    private Integer sleepTime;
+
+    /** 深睡时间(分钟) */
+    private Integer deepSleep;
+
+    /** 深睡比例(百分比) */
+    private Integer deepScale;
+}

+ 12 - 0
fs-service/src/main/java/com/fs/watch/domain/vo/WatchSportDataByDateAndThirdDeviceVo.java

@@ -0,0 +1,12 @@
+package com.fs.watch.domain.vo;
+
+import com.fs.watch.domain.WatchSportData;
+import lombok.Data;
+
+@Data
+public class WatchSportDataByDateAndThirdDeviceVo extends WatchSportData {
+    /**
+     * 时长(秒)
+     */
+    private Float duration;
+}

+ 10 - 0
fs-service/src/main/java/com/fs/watch/domain/vo/WatchSportRecordVo.java

@@ -23,4 +23,14 @@ public class WatchSportRecordVo {
      */
     private Float time;
 
+    /**
+     * 步数
+     */
+    private Long step;
+
+    /**
+     * 卡路里
+     */
+    private Float calorie;
+
 }

+ 17 - 0
fs-service/src/main/java/com/fs/watch/param/WatchUserByDeviceIdParam.java

@@ -0,0 +1,17 @@
+package com.fs.watch.param;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class WatchUserByDeviceIdParam {
+    private List<WatchUserByDeviceIdTemp> params;
+    private Boolean isFamily;
+
+    @Data
+    public static class WatchUserByDeviceIdTemp {
+        private String deviceId;
+        private Integer deviceType;
+    }
+}

+ 2 - 1
fs-service/src/main/java/com/fs/watch/service/WatchBasicInfoService.java

@@ -46,5 +46,6 @@ public interface WatchBasicInfoService{
 
     List<GnssVo> queryGnssByDate(String starTime, String endTime, String deviceId);
 
-    AppFsUserHealthReportVo getAppFsUserHealthReportVo(Date startTime, Date endTime, String deviceId,Long watchUserId,Boolean isFamily,Integer isRefresh);
+    AppFsUserHealthReportVo getAppFsUserHealthReportVo(Date startTime, Date endTime, String deviceId,Long watchUserId
+            ,Boolean isFamily,Integer isRefresh,Integer deviceType);
 }

+ 6 - 4
fs-service/src/main/java/com/fs/watch/service/WatchBloodGlucoseDataService.java

@@ -17,13 +17,15 @@ public interface WatchBloodGlucoseDataService{
 
     List<WatchBloodGlucoseData> queryByDateAndDeviceId(String date, String deviceId);
 
-    List<WatchBloodGlucoseData> queryBgByDate(Date startTime, Date endTime, String deviceId, Integer status);
+    List<WatchBloodGlucoseData> queryBgByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType);
 
-    List<Map<String,Object>> countBgByDate(Date startTime, Date endTime, String deviceId);
+    List<Map<String,Object>> countBgByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
     WatchBloodGlucoseData getLatest(String deviceId);
 
-    int countBgPageByDate(Date startTime, Date endTime, String deviceId,Integer status);
+    int countBgPageByDate(Date startTime, Date endTime, String deviceId,Integer status,Integer deviceType);
 
-    List<WatchBloodGlucoseData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer num, Integer size);
+    List<WatchBloodGlucoseData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer num, Integer size,Integer deviceType);
+
+    Integer getStatus(Double num);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/watch/service/WatchBloodPressureDataService.java

@@ -28,4 +28,6 @@ public interface WatchBloodPressureDataService{
     int countBpPageByDate(Date startTime, Date endTime, String deviceId, Integer status);
 
     List<WatchBloodPressureData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size);
+
+    Integer getStatus(int sbp, int dbp);
 }

+ 4 - 3
fs-service/src/main/java/com/fs/watch/service/WatchDataService.java

@@ -5,13 +5,14 @@ import com.fs.watch.domain.vo.AppInfoVo;
 import com.fs.watch.domain.vo.FsMonitorDataVo;
 import com.fs.watch.domain.vo.QueryPageMonthVo;
 import com.fs.watch.domain.vo.WatchLastHealthDataVo;
+import com.fs.watch.param.WatchUserByDeviceIdParam;
 
 import java.util.List;
 
 public interface WatchDataService {
-    List<FsMonitorDataVo> queryIndexWatchData(List<String> types, String deviceId,String userId);
+    List<FsMonitorDataVo> queryIndexWatchData(List<String> types, String deviceId,String userId,Integer deviceType);
 
-    List<AppInfoVo> getUserByDeviceId(String deviceIds, Boolean isFamily,Long userId);
+    List<AppInfoVo> getUserByDeviceId(WatchUserByDeviceIdParam watchUserByDeviceIdParam, Long userId);
 
     Boolean power(String deviceId, Boolean isLcdgesture, Boolean isLocation, Boolean isPower, Boolean isHeartHealth);
 
@@ -21,7 +22,7 @@ public interface WatchDataService {
 
     Boolean setDeviceMode(String deviceId, Boolean isLocation, Integer interval, Boolean isPower);
 
-    QueryPageMonthVo queryMonthByDeviceId(String deviceId, Integer pageSize, Integer pageNum);
+    QueryPageMonthVo queryMonthByDeviceId(String deviceId, Integer pageSize, Integer pageNum,Integer deviceType);
 
     List<WatchLastHealthDataVo> queryLastWatchData(String deviceId);
 

+ 4 - 2
fs-service/src/main/java/com/fs/watch/service/WatchHeartRateDataService.java

@@ -20,7 +20,7 @@ public interface WatchHeartRateDataService{
 
     WatchHeartRateDataVo queryByDate(String date, String deviceId);
 
-    WatchHeartRateDataVo list(Date startTime, Date endTime, String deviceId);
+    WatchHeartRateDataVo list(Date startTime, Date endTime, String deviceId, Integer deviceType);
 
     WatchHeartRateData getLatest(String deviceId);
 
@@ -29,5 +29,7 @@ public interface WatchHeartRateDataService{
     List<WatchHeartRateData> queryHeartPageByDate(Date startTime, Date endTime, String deviceId, Integer pageNum,
                                                   Integer pageSize);
 
-    List<Map<String, Object>> countHeartByDate(Date startTime, Date endTime, String deviceId);
+    List<Map<String, Object>> countHeartByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
+
+    Integer getStatus(int maxBpm, int minBpm);
 }

+ 1 - 1
fs-service/src/main/java/com/fs/watch/service/WatchSleepDataService.java

@@ -21,7 +21,7 @@ public interface WatchSleepDataService{
 
     AppWatchSleepDataVo queryByDateAndDeviceIdAndState(String date, String deviceId);
 
-    AppWatchSleepDataVo list(Date startTime, Date endTime, String deviceId);
+    AppWatchSleepDataVo list(Date startTime, Date endTime, String deviceId, Integer deviceType);
 
 
     WatchSleepData getLast(String deviceId);

+ 2 - 2
fs-service/src/main/java/com/fs/watch/service/WatchSpo2DataService.java

@@ -19,11 +19,11 @@ public interface WatchSpo2DataService{
 
     List<WatchSpo2DataVo> queryByDateAndDeviceIdAndState(String date, String deviceId);
 
-    WatchSpo2DataQueryVo querySpByDate(Date startTime, Date endTime, String deviceId);
+    WatchSpo2DataQueryVo querySpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
     Integer getStatus(int maxOxy, int minOxy);
 
-    List<Map<String,Object>> countSpByDate(Date startTime, Date endTime, String deviceId);
+    List<Map<String,Object>> countSpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
     WatchSpo2DataVo getLatest(String deviceId);
 

+ 3 - 3
fs-service/src/main/java/com/fs/watch/service/WatchSportDataService.java

@@ -23,15 +23,15 @@ public interface WatchSportDataService{
 
     List<WatchSportListVo> queryPageByDataAndDeviceId(Date startTime, Date endTime, String deviceId,Integer pageSize, Integer pageNum);
 
-    List<WatchSportRecordVo> queryRecord(String deviceId);
+    List<WatchSportRecordVo> queryRecord(String deviceId,Integer deviceType);
 
-    WatchSportIndexVo sportData(String userId,String deviceId,Boolean isFamily);
+    WatchSportIndexVo sportData(String userId,String deviceId,Boolean isFamily,Integer deviceType);
 
     List<WatchSportDataByDateVo> sportDataByDate(Date startTime, Date endTime, String deviceId);
 
     WatchSportDetailDataVo dataByType(String deviceId, String type);
 
-    AppFsUserHealthVo getUserHealthInfoByDeviceId(String deviceId,Date startTime, Date endTime,Long userId);
+    AppFsUserHealthVo getUserHealthInfoByDeviceId(String deviceId,Date startTime, Date endTime,Long userId,Integer deviceType);
 
     WatchStepStatusEnum getWeekStatus(String deviceId, String startTime, String endTime);
 }

+ 4 - 4
fs-service/src/main/java/com/fs/watch/service/WatchThirdBpDataService.java

@@ -23,15 +23,15 @@ public interface WatchThirdBpDataService{
 
     List<WatchThirdBpData> queryByDateAndDeviceId(String date, String deviceId);
 
-    List<WatchThirdBpData> queryBpByDate(String startTime, String endTime, String deviceId, Integer status);
+    List<WatchThirdBpData> queryBpByDate(String startTime, String endTime, String deviceId, Integer status,Integer deviceType);
 
     WatchThirdBpData getLatest(String deviceId);
 
     Integer getStatus(int sbp, int dbp);
 
-    List<Map<String, Object>> countBpByDate(Date startTime, Date endTime, String deviceId);
+    List<Map<String, Object>> countBpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
-    int countBpPageByDate(Date startTime, Date endTime, String deviceId, Integer status);
+    int countBpPageByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType);
 
-    List<WatchThirdBpData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size);
+    List<WatchThirdBpData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size,Integer deviceType);
 }

+ 4 - 4
fs-service/src/main/java/com/fs/watch/service/WatchThirdUaDataService.java

@@ -22,12 +22,12 @@ public interface WatchThirdUaDataService{
 
     List<WatchThirdUaData> queryByDateAndDeviceId(String date, String deviceId);
 
-    List<WatchThirdUaData> list(Date startTime, Date endTime, String deviceId);
+    List<WatchThirdUaData> list(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
-    List<Map<String, Object>> countUaByDate(Date startTime, Date endTime, String deviceId);
+    List<Map<String, Object>> countUaByDate(Date startTime, Date endTime, String deviceId,Integer deviceType);
 
     List<WatchThirdUaData> queryListByDate(Date startTime, Date endTime, String deviceId, Integer pageNum,
-                                                Integer pageSize,Integer status);
+                                                Integer pageSize,Integer status,Integer deviceType);
 
-    int countTotalDate(Date startTime, Date endTime, String deviceId,Integer status);
+    int countTotalDate(Date startTime, Date endTime, String deviceId,Integer status,Integer deviceType);
 }

+ 6 - 1
fs-service/src/main/java/com/fs/watch/service/WatchUserService.java

@@ -10,6 +10,7 @@ import com.fs.watch.domain.vo.WatchUserAndHealthVo;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -40,7 +41,7 @@ public interface WatchUserService {
      * @param deviceId
      * @return
      */
-    AppFsUserVo getUserInfoByDeviceId(String deviceId,Boolean isFamily,Long watchUserId);
+    AppFsUserVo getUserInfoByDeviceId(String deviceId,Boolean isFamily,Long watchUserId,Integer deviceType);
 
     /**
      * 通过ID查询单条数据
@@ -95,4 +96,8 @@ public interface WatchUserService {
     List<WatchUserAndHealthVo> listByDeviceIdNotNull();
 
     FsHealthTongue getLastTongueByDeviceId(String deviceId);
+
+    R editXHSDevice(HashMap<String, String> param);
+
+    R removeXHSDevice(String userId, String xhsDeviceId,String newXhsDeviceId);
 }

+ 137 - 49
fs-service/src/main/java/com/fs/watch/service/impl/WatchBasicInfoServiceImpl.java

@@ -11,15 +11,18 @@ import com.fs.fastgptApi.param.ChatParam;
 import com.fs.fastgptApi.result.ChatDetailTStreamFResult;
 import com.fs.fastgptApi.result.KnowledgeBaseResult;
 import com.fs.fastgptApi.service.ChatService;
+import com.fs.his.domain.FsThirdDeviceData;
 import com.fs.his.mapper.FsHealthPulseMapper;
 import com.fs.his.mapper.FsHealthSurfaceMapper;
 import com.fs.his.mapper.FsHealthTongueMapper;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.his.param.FsHealthPulseListUParam;
 import com.fs.his.param.FsHealthSurfaceListUParam;
 import com.fs.his.param.FsHealthTongueListUParam;
 import com.fs.his.vo.FsHealthPulseListVO;
 import com.fs.his.vo.FsHealthSurfaceListVO;
 import com.fs.his.vo.FsHealthTongueListUVO;
+import com.fs.watch.calculation.SleepScoreCalculator;
 import com.fs.watch.domain.*;
 import com.fs.watch.domain.vo.*;
 import com.fs.watch.enums.*;
@@ -88,6 +91,8 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
     private FsHealthPulseMapper fsHealthPulseMapper;
     @Autowired
     InterestAiChatSessionMapper interestAiChatSessionMapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
     private static final ObjectMapper objectMapper = new ObjectMapper();
 
 
@@ -241,7 +246,8 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
     public AppFsUserHealthReportVo getAppFsUserHealthReportVo(Date startTime, Date endTime, String deviceId,
                                                               Long watchUserId,
                                                               Boolean isFamily,
-                                                              Integer isRefresh) {
+                                                              Integer isRefresh,
+                                                              Integer deviceType) {
         AppFsUserHealthReportVo res = new AppFsUserHealthReportVo();
         //查询用户和指定ai医生的会话
         Integer sessionId = interestAiChatSessionMapper.selectSessionIdByUserAndRole(watchUserId, 140);
@@ -271,10 +277,10 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
         }
         //获取ai解析
         CompletableFuture<Void> aiSuggestionFuture = CompletableFuture.runAsync(() -> {
-            getAiSuggestion(startTime, endTime, deviceId, watchUserId, isFamily, res);
+            getAiSuggestion(startTime, endTime, deviceId, watchUserId, isFamily, res,deviceType);
         });
         CompletableFuture<Void> totalScoreFuture = null;
-        if (StringUtils.isNotBlank(deviceId)) {
+        if (StringUtils.isNotBlank(deviceId) && (deviceType == null || deviceType == 0)) {
             //获取异常数据及分析
             totalScoreFuture = CompletableFuture.runAsync(() -> {
                 getTotalScoreAndNormalData(startTime, endTime, deviceId, res);
@@ -400,7 +406,18 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
     }
 
 
-    private void getAiSuggestion(Date startTime, Date endTime, String deviceId, Long watchUserId, Boolean isFamily, AppFsUserHealthReportVo res) {
+    /**
+     *
+     * @param startTime
+     * @param endTime
+     * @param deviceId
+     * @param watchUserId
+     * @param isFamily
+     * @param res
+     * @param deviceType 0腕表1小护士2新表
+     */
+    private void getAiSuggestion(Date startTime, Date endTime, String deviceId, Long watchUserId, Boolean isFamily,
+                                 AppFsUserHealthReportVo res,Integer deviceType) {
         String aiSuggestion = "";
         ChatParam param = new ChatParam();
         param.setStream(false);
@@ -417,7 +434,7 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
         str.append(DateUtils.dateTimeNow("MM月dd日"));
         //1.身高体重
         if (watchUserId != null) {
-            AppFsUserVo userVo = userService.getUserInfoByDeviceId(deviceId, isFamily, watchUserId);
+            AppFsUserVo userVo = userService.getUserInfoByDeviceId(deviceId, isFamily, watchUserId,deviceType);
             if (userVo != null && userVo.getHeight() != null && userVo.getWeight() != null) {
                 str.append("【身高 ").append(userVo.getHeight()).append("cm 体重 ").append(userVo.getWeight()).append("kg】");
             }
@@ -462,20 +479,20 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
 
             if (StringUtils.isNotBlank(deviceId)) {
                 //2.计算每天步数总和
-                calculateStep(deviceId, start, end, spotStr, dateToStr);
+                calculateStep(deviceId, start, end, spotStr, dateToStr,deviceType);
                 //3.血压
-                calculateBp(deviceId, start, end, bpStr, dateToStr);
+                calculateBp(deviceId, start, end, bpStr, dateToStr,deviceType);
 
 
                 //4.血糖
-                calculateBg(deviceId, start, end, bgStr, dateToStr);
+                calculateBg(deviceId, start, end, bgStr, dateToStr,deviceType);
                 //5.心率
-                calculateHr(deviceId, start, end, hrStr, dateToStr);
+                calculateHr(deviceId, start, end, hrStr, dateToStr,deviceType);
                 //6.血氧
-                calculateSpo2(deviceId, start, end, spo2Str, dateToStr);
+                calculateSpo2(deviceId, start, end, spo2Str, dateToStr,deviceType);
 
                 //7.睡眠
-                calculateSleep(deviceId, DateUtils.parseDateToStr("yyyy-MM-dd", currentStartDate), sleepStr, dateToStr);
+                calculateSleep(deviceId, DateUtils.parseDateToStr("yyyy-MM-dd", currentStartDate), sleepStr, dateToStr,deviceType);
             }
             if (watchUserId != null) {
                 //8.舌诊
@@ -666,29 +683,50 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param sleepStr
      * @param dateToStr
      */
-    private void calculateSleep(String deviceId, String date, StringBuilder sleepStr, String dateToStr) {
-        WatchSleepDataVo vo = watchSleepDataService.getSleepSection(date, deviceId);
-        if (vo != null) {
-            if (StringUtils.isNotBlank(vo.getStartTime())) {
-                sleepStr.append(dateToStr).append(" ").append(vo.getStartTime()).append("入睡,");
-            } else {
-                return;
-            }
-            if (StringUtils.isNotBlank(vo.getEndTime())) {
-                sleepStr.append(vo.getEndTime()).append("醒来,");
-            }
-            if (vo.getSleepTime() != null) {
-                sleepStr.append("深睡 ").append(vo.getSleepTime()).append(" 分钟,");
-            }
-            if (vo.getLightSleep() != null) {
-                sleepStr.append("浅睡 ").append(vo.getLightSleep()).append(" 分钟,");
-            }
-            if (vo.getEyemoveSleep() != null) {
-                sleepStr.append("快速眼动 ").append(vo.getEyemoveSleep()).append(" 分钟,");
+    private void calculateSleep(String deviceId, String date, StringBuilder sleepStr, String dateToStr,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            WatchSleepDataVo vo = watchSleepDataService.getSleepSection(date, deviceId);
+            if (vo != null) {
+                if (StringUtils.isNotBlank(vo.getStartTime())) {
+                    sleepStr.append(dateToStr).append(" ").append(vo.getStartTime()).append("入睡,");
+                } else {
+                    return;
+                }
+                if (StringUtils.isNotBlank(vo.getEndTime())) {
+                    sleepStr.append(vo.getEndTime()).append("醒来,");
+                }
+                if (vo.getSleepTime() != null) {
+                    sleepStr.append("深睡 ").append(vo.getSleepTime()).append(" 分钟,");
+                }
+                if (vo.getLightSleep() != null) {
+                    sleepStr.append("浅睡 ").append(vo.getLightSleep()).append(" 分钟,");
+                }
+                if (vo.getEyemoveSleep() != null) {
+                    sleepStr.append("快速眼动 ").append(vo.getEyemoveSleep()).append(" 分钟,");
+                }
+                if (vo.getWeakSleep() != null) {
+                    sleepStr.append("清醒 ").append(vo.getWeakSleep()).append(" 分钟,");
+                }
             }
-            if (vo.getWeakSleep() != null) {
-                sleepStr.append("清醒 ").append(vo.getWeakSleep()).append(" 分钟,");
+        } else {
+            Date dateTemp = DateUtils.dateTime("yyyy-MM-dd", date);
+            Date dayStartTime = DateUtils.truncate(dateTemp, Calendar.DATE);
+            Date dayEndTime =  DateUtils.addMilliseconds(
+                    DateUtils.addDays(DateUtils.truncate(dateTemp, Calendar.DATE), 1),
+                    -1
+            );
+            List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(dayStartTime, dayEndTime, deviceId, 7, null);
+            if (list != null && !list.isEmpty()) {
+                SleepStatistics sleepStatistics = SleepScoreCalculator.calculateDetailedStatistics(list);
+                sleepStr.append(dateToStr).append(" ").append(list.get(0).getCreateTime()).append("入睡,");
+                if (list.size() > 1) {
+                    sleepStr.append(list.get(list.size()-1).getCreateTime()).append("醒来,");
+                }
+                sleepStr.append("深睡 ").append(sleepStatistics.getDeepSleepHours()*60).append(" 分钟,");
+                sleepStr.append("浅睡 ").append(sleepStatistics.getLightSleepHours()*60).append(" 分钟,");
+                sleepStr.append("清醒 ").append(sleepStatistics.getAwakeHours()*60).append(" 分钟,");
             }
+
         }
     }
 
@@ -702,8 +740,15 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param spo2Str
      * @param dateToStr
      */
-    private void calculateSpo2(String deviceId, String currentStartDate, String currentEndDate, StringBuilder spo2Str, String dateToStr) {
-        Float value = watchSpo2DataMapper.countAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+    private void calculateSpo2(String deviceId, String currentStartDate, String currentEndDate, StringBuilder spo2Str,
+                               String dateToStr,Integer deviceType) {
+        Float value = null;
+        if (deviceType == null || deviceType == 1) {
+            value = watchSpo2DataMapper.countAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+
+        } else {
+            value = fsThirdDeviceDataMapper.countAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+        }
         if (value != null) {
             spo2Str.append(dateToStr).append(" ").append(value).append("% ");
         }
@@ -718,8 +763,14 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param hrStr
      * @param dateToStr
      */
-    private void calculateHr(String deviceId, String currentStartDate, String currentEndDate, StringBuilder hrStr, String dateToStr) {
-        Map<String, Integer> map = watchHeartRateDataMapper.countMaxAndAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+    private void calculateHr(String deviceId, String currentStartDate, String currentEndDate, StringBuilder hrStr,
+                             String dateToStr,Integer deviceType) {
+        Map<String, Integer> map = null;
+        if (deviceType == null || deviceType == 0) {
+            map = watchHeartRateDataMapper.countMaxAndAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+        } else {
+            map = fsThirdDeviceDataMapper.countMaxAndAvgBpByDate(currentStartDate, currentEndDate, deviceId);
+        }
         if (map != null && map.get("avgBpm") != null && map.get("maxBpm") != null) {
             hrStr.append(dateToStr).append(" 平均").append(map.get("avgBpm")).append(" 最高 ").append(map.get("maxBpm")).append(" ");
         }
@@ -733,13 +784,24 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param currentEndDate
      * @param bgStr
      */
-    private void calculateBg(String deviceId, String currentStartDate, String currentEndDate, StringBuilder bgStr, String dateToStr) {
-        List<WatchBloodGlucoseData> bgData = watchBloodGlucoseDataMapper.queryBgByDate(currentStartDate, currentEndDate, deviceId, null);
+    private void calculateBg(String deviceId, String currentStartDate, String currentEndDate, StringBuilder bgStr,
+                             String dateToStr,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            List<WatchBloodGlucoseData> bgData = watchBloodGlucoseDataMapper.queryBgByDate(currentStartDate, currentEndDate, deviceId, null);
+
+            if (bgData != null && !bgData.isEmpty()) {
+                WatchBloodGlucoseData watchBloodGlucoseData = bgData.get(bgData.size() - 1);
+                bgStr.append(dateToStr).append(" ").append(watchBloodGlucoseData.getBloodGlucose()).append("mmol/L ");
+            }
+        } else {
+            List<FsThirdDeviceData> bgData = fsThirdDeviceDataMapper.queryBgByDate(currentStartDate, currentEndDate, deviceId);
 
-        if (bgData != null && !bgData.isEmpty()) {
-            WatchBloodGlucoseData watchBloodGlucoseData = bgData.get(bgData.size() - 1);
-            bgStr.append(dateToStr).append(" ").append(watchBloodGlucoseData.getBloodGlucose()).append("mmol/L ");
+            if (bgData != null && !bgData.isEmpty()) {
+                FsThirdDeviceData fsThirdDeviceData = bgData.get(bgData.size() - 1);
+                bgStr.append(dateToStr).append(" ").append(fsThirdDeviceData.getRecordValue()).append("mmol/L ");
+            }
         }
+
     }
 
     /**
@@ -750,11 +812,21 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param currentEndDate
      * @param bpStr
      */
-    private void calculateBp(String deviceId, String currentStartDate, String currentEndDate, StringBuilder bpStr, String dateToStr) {
-        Map<String, Integer> map = watchBloodPressureDataMapper.countMaxAndMinBpByDate(currentStartDate, currentEndDate, deviceId);
+    private void calculateBp(String deviceId, String currentStartDate, String currentEndDate, StringBuilder bpStr
+            , String dateToStr,Integer deviceType) {
+        Map<String, Integer> map = new HashMap<>();
+        if(deviceType == null || deviceType == 0){
+            //原腕表
+            map = watchBloodPressureDataMapper.countMaxAndMinBpByDate(currentStartDate, currentEndDate, deviceId);
+        } else {
+            //小护士
+            map = fsThirdDeviceDataMapper.countMaxAndMinBpByDate(currentStartDate, currentEndDate, deviceId);
+        }
         if (map != null && map.get("max") != null && map.get("min") != null) {
             bpStr.append(dateToStr).append(" 高压 ").append(map.get("max")).append(" 低压 ").append(map.get("min")).append(" ");
         }
+
+
     }
 
     /**
@@ -765,12 +837,28 @@ public class WatchBasicInfoServiceImpl implements WatchBasicInfoService {
      * @param currentEndDate
      * @param spotStr
      */
-    private void calculateStep(String deviceId, String currentStartDate, String currentEndDate, StringBuilder spotStr, String dateToStr) {
-        List<WatchSportData> list = sportDataMapper.getByType(currentStartDate, currentEndDate, deviceId, null);
-        int dailyStep = 0;
-        if (list != null && !list.isEmpty()) {
-            for (WatchSportData data : list) {
-                dailyStep += data.getStep() == null ? 0 : data.getStep();
+    private void calculateStep(String deviceId, String currentStartDate, String currentEndDate, StringBuilder spotStr,
+                               String dateToStr,Integer deviceType) {
+        long dailyStep = 0;
+        if (deviceType == null || deviceType == 0) {
+            List<WatchSportData> list = sportDataMapper.getByType(currentStartDate, currentEndDate, deviceId, null);
+            if (list != null && !list.isEmpty()) {
+                for (WatchSportData data : list) {
+                    dailyStep += data.getStep() == null ? 0 : data.getStep();
+                }
+            }
+
+        } else {
+            //小护士设备
+            WatchSportRecordVo otherData1 = fsThirdDeviceDataMapper.getOtherData(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", currentStartDate),
+                    DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", currentEndDate), deviceId, 5, null);
+            WatchSportRecordVo otherData2 = fsThirdDeviceDataMapper.getOtherData(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", currentStartDate),
+                    DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", currentEndDate), deviceId, 6, null);
+            if (otherData1 != null){
+                dailyStep = dailyStep + (otherData1.getStep() == null?0:otherData1.getStep());
+            }
+            if (otherData2 != null){
+                dailyStep = dailyStep + (otherData2.getStep() == null?0:otherData2.getStep());
             }
         }
         if (dailyStep > 0) {

+ 107 - 19
fs-service/src/main/java/com/fs/watch/service/impl/WatchBloodGlucoseDataServiceImpl.java

@@ -2,6 +2,8 @@ package com.fs.watch.service.impl;
 
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.domain.WatchBloodGlucoseData;
 import com.fs.watch.domain.WatchDeviceInfo;
 import com.fs.watch.enums.WatchBgStatusEnum;
@@ -30,6 +32,8 @@ public class WatchBloodGlucoseDataServiceImpl implements WatchBloodGlucoseDataSe
     private WatchThirdBpDataService watchThirdBpDataService;
     @Autowired
     private WatchDeviceInfoMapper watchDeviceInfoMapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
 
 
     @Override
@@ -75,27 +79,56 @@ public class WatchBloodGlucoseDataServiceImpl implements WatchBloodGlucoseDataSe
     }
 
     @Override
-    public List<WatchBloodGlucoseData> queryBgByDate(Date startTime, Date endTime, String deviceId, Integer status) {
+    public List<WatchBloodGlucoseData> queryBgByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType) {
         if (StringUtils.isNotBlank(deviceId)) {
-            List<WatchBloodGlucoseData> data = mapper.queryBgByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId,
-                    status);
-            return data;
+            if (deviceType == null || deviceType == 0) {
+                return mapper.queryBgByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId,
+                        status);
+            } else {
+                List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 1, status);
+                if (list != null && !list.isEmpty()) {
+                    List<WatchBloodGlucoseData> voList= new ArrayList<>();
+                    list.forEach(fsThirdDeviceData -> {
+                        WatchBloodGlucoseData data = new WatchBloodGlucoseData();
+                        data.setDeviceId(fsThirdDeviceData.getDeviceId());
+                        String recordValue = fsThirdDeviceData.getRecordValue();
+                        if (recordValue != null) {
+                            // 移除所有双引号
+                            recordValue = recordValue.replace("\"", "");
+                            // 或者只移除首尾的引号和可能的空格
+                            recordValue = recordValue.replaceAll("^[\"']+|[\"']+$", "");
+                        }
+                        data.setBloodGlucose(Float.valueOf(recordValue));
+                        data.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                        data.setStatus(fsThirdDeviceData.getStatus());
+                        voList.add(data);
+                    });
+                    return voList;
+                }
+            }
+
         }
         return null;
     }
 
 
     @Override
-    public List<Map<String, Object>> countBgByDate(Date startTime, Date endTime, String deviceId) {
+    public List<Map<String, Object>> countBgByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
         //返回对象
         List<Map<String, Object>> res = null;
-        res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        if (deviceType == null || deviceType == 0) {
+            res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        } else {
+            res = fsThirdDeviceDataMapper.countByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 1,null);
+        }
+
+
 
         return res;
     }
@@ -106,20 +139,75 @@ public class WatchBloodGlucoseDataServiceImpl implements WatchBloodGlucoseDataSe
     }
 
     @Override
-    public int countBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status) {
-        return mapper.countBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                deviceId, status);
+    public int countBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            return mapper.countBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                    deviceId, status);
+        } else {
+            return fsThirdDeviceDataMapper.countPageByDateAndDeviceIdAndRecordType(startTime,endTime,deviceId,1,status);
+        }
+
     }
 
     @Override
-    public List<WatchBloodGlucoseData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size) {
-        if (StringUtils.isNotBlank(deviceId)) {
-            return mapper.queryBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId, status, num, size);
+    public List<WatchBloodGlucoseData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            if (StringUtils.isNotBlank(deviceId)) {
+                return mapper.queryBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId, status, num, size);
+            } else {
+                return null;
+            }
         } else {
-            return null;
+            List<WatchBloodGlucoseData> voList= new ArrayList<>();
+            List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.queryPageByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 1,status, num, size);
+            if (list != null && !list.isEmpty()) {
+                list.forEach(fsThirdDeviceData -> {
+                    WatchBloodGlucoseData data = new WatchBloodGlucoseData();
+                    data.setDeviceId(fsThirdDeviceData.getDeviceId());
+                    String recordValue = fsThirdDeviceData.getRecordValue();
+                    if (recordValue != null) {
+                        // 移除所有双引号
+                        recordValue = recordValue.replace("\"", "");
+                        // 或者只移除首尾的引号和可能的空格
+                        recordValue = recordValue.replaceAll("^[\"']+|[\"']+$", "");
+                    }
+                    data.setBloodGlucose(Float.valueOf(recordValue));
+                    data.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                    data.setStatus(fsThirdDeviceData.getStatus());
+                    voList.add(data);
+                });
+
+            }
+            return voList;
         }
+
     }
+
+    /**
+     * 高风险:血糖值大于等于 7.0 mmol/L,返回 1。
+     * 一般:血糖值在 6.0 mmol/L 和 7.0 mmol/L 之间,返回 3。
+     * 良好:血糖值在 5.0 mmol/L 和 6.0 mmol/L 之间,返回 4。
+     * 正常:血糖值在 3.9 mmol/L和 4.0 mmol/L 之间,,返回 5。
+     * 不良:血糖值小于 3.9 mmol/L 之间,返回 2。
+     * 获得血糖状态
+     *
+     * @param num
+     * @return 状态码
+     */
+    @Override
+    public Integer getStatus(Double num) {
+        if (num >= 7.0) {
+            return WatchBgStatusEnum.HYPERGLYCEMIA.getValue(); // 高风险(糖尿病)
+        } else if (num >= 6.1) {
+            return WatchBgStatusEnum.HIGHER.getValue(); // 一般(糖尿病前期)
+        } else if (num >= 3.9) {
+            return WatchBgStatusEnum.NORMAL.getValue(); // 良好正常
+        } else {
+            return WatchBgStatusEnum.HYPOGLYCEMIA.getValue(); //不良 (低血糖)
+        }
+    }
+
 }

+ 38 - 1
fs-service/src/main/java/com/fs/watch/service/impl/WatchBloodPressureDataServiceImpl.java

@@ -89,7 +89,7 @@ public class WatchBloodPressureDataServiceImpl implements WatchBloodPressureData
                     DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
                     DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
                     deviceId,
-                    status);
+                    status,0);
             if (!watchThirdBpDatas.isEmpty()){
                 return watchThirdBpDatas;
             } else {
@@ -157,4 +157,41 @@ public class WatchBloodPressureDataServiceImpl implements WatchBloodPressureData
             return null;
         }
     }
+
+    /**
+     * 重度: 收缩压 > 180 mmHg 或 舒张压 > 110 mmHg 1
+     * 中度: 收缩压在 160-179 mmHg 之间 或 舒张压在 100-109 mmHg 之间 2
+     * 轻度: 收缩压在 140-159 mmHg 之间 或 舒张压在 90-99 mmHg 之间 3
+     * 正常高值: 收缩压在 130-139 mmHg 之间 或 舒张压在 85-89 mmHg 之间 4
+     * 偏低: 收缩压 < 90 mmHg 或 舒张压 < 60 mmHg 5
+     * 正常: 收缩压在 90-139 mmHg 之间 且 舒张压在 60-89 mmHg 之间 6
+     * @param sbp
+     * @param dbp
+     * @return
+     */
+    @Override
+    public Integer getStatus(int sbp, int dbp) {
+        int status;
+//        if (sbp > 180 || dbp > 110) {
+//            status = 1; // 重度
+//        } else if (sbp >= 160 || dbp >= 100) {
+//            status = 2; // 中度
+//        } else if (sbp >= 140 || dbp >= 90) {
+//            status = 3; // 轻度
+//        } else if (sbp >= 130 || dbp >= 85) {
+//            status = 4; // 正常高值
+//        } else if (sbp < 90 || dbp < 60) {
+//            status = 5; // 偏低
+//        } else {
+//            status = 6; // 正常
+//        }
+        if (sbp >= 140 || dbp >=90 ) {
+            status = WatchBpStatusEnum.HYPERTENSION.getValue(); // 重度(高血压)
+        } else if (sbp >= 90 || dbp >= 60) {
+            status = WatchBpStatusEnum.NORMAL.getValue(); // 正常范围
+        } else {
+            status = WatchBpStatusEnum.HYPOTENSION.getValue(); // 低血压
+        }
+        return status;
+    }
 }

+ 311 - 113
fs-service/src/main/java/com/fs/watch/service/impl/WatchDataServiceImpl.java

@@ -6,11 +6,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.his.domain.FsHealthTongue;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.his.utils.PhoneUtil;
+import com.fs.watch.calculation.SleepScoreCalculator;
 import com.fs.watch.domain.*;
 import com.fs.watch.domain.vo.*;
 import com.fs.watch.enums.*;
 import com.fs.watch.mapper.*;
+import com.fs.watch.param.WatchUserByDeviceIdParam;
 import com.fs.watch.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -71,9 +75,11 @@ public class WatchDataServiceImpl implements WatchDataService {
     private WatchSpo2DataService watchSpo2DataService;
     @Autowired
     private WatchFatigueDataService watchFatigueDataService;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
 
     @Override
-    public List<FsMonitorDataVo> queryIndexWatchData(List<String> types, String deviceId,String userId) {
+    public List<FsMonitorDataVo> queryIndexWatchData(List<String> types, String deviceId,String userId,Integer deviceType) {
         //返回对象
         List<FsMonitorDataVo> vos = new ArrayList<>();
         for (String typeStr : types) {
@@ -88,43 +94,90 @@ public class WatchDataServiceImpl implements WatchDataService {
             int type = Integer.parseInt(typeStr);
             switch (type) {
                 case 1:  //血糖
-                    WatchBloodGlucoseData bgData = watchBloodGlucoseDataService.getLatest(deviceId);
-                    if (bgData != null) {
+                    if (deviceId == null || deviceType == 0) {
+                        WatchBloodGlucoseData bgData = watchBloodGlucoseDataService.getLatest(deviceId);
+                        if (bgData != null) {
 //                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
-                        vo.setDate(bgData.getCreateTime());
-                        vo.setData(bgData.getBloodGlucose().toString());
+                            vo.setDate(bgData.getCreateTime());
+                            vo.setData(bgData.getBloodGlucose().toString());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
-                        vo.setData("");
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId,1);
+                        if (data != null) {
+//                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
+                            vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,data.getCreateTime()));
+                            vo.setData(data.getRecordValue());
+                        } else {
+                            vo.setData("");
+                        }
                     }
+
+
                     vos.add(vo);
                     break;
                 case 2:  //血压
-                    WatchThirdBpData bpData = watchBloodPressureDataService.getLatest(deviceId);
-                    if (bpData != null) {
+                    if (deviceId == null || deviceType == 0) {
+                        WatchThirdBpData bpData = watchBloodPressureDataService.getLatest(deviceId);
+                        if (bpData != null) {
 //                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bpData.getCreateTime()));
-                        vo.setDate(bpData.getCreateTime());
-                        vo.setData(bpData.getDbp() + "/" + bpData.getSbp().toString());
+                            vo.setDate(bpData.getCreateTime());
+                            vo.setData(bpData.getDbp() + "/" + bpData.getSbp().toString());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
-                        vo.setData("");
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId,0);
+                        if (data != null) {
+//                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
+                            vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,data.getCreateTime()));
+                            String recordValue = data.getRecordValue();
+                            if (StringUtils.isNotBlank(recordValue)) {
+                                JSONObject jsonObject = JSONObject.parseObject(recordValue);
+                                String sdb = jsonObject.get("sdb").toString();
+                                String dbp = jsonObject.get("dbp").toString();
+                                vo.setData(dbp + "/" + sdb );
+                            } else {
+                                vo.setData("");
+                            }
+                        } else {
+                            vo.setData("");
+                        }
                     }
+
                     vos.add(vo);
                     break;
                 case 3:  //心率
-                    WatchHeartRateData hrData = watchHeartRateDataService.getLatest(deviceId);
-                    if (hrData != null) {
+                    if (deviceId == null || deviceType == 0) {
+                        WatchHeartRateData hrData = watchHeartRateDataService.getLatest(deviceId);
+                        if (hrData != null) {
 //                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,hrData.getCreateTime()));
-                        vo.setDate(hrData.getCreateTime());
-                        vo.setData(hrData.getAvgBpm().toString());
+                            vo.setDate(hrData.getCreateTime());
+                            vo.setData(hrData.getAvgBpm().toString());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
-                        vo.setData("");
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId,2);
+                        if (data != null) {
+//                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
+                            vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,data.getCreateTime()));
+                            vo.setData(data.getRecordValue());
+                        } else {
+                            vo.setData("");
+                        }
                     }
+
+
                     vos.add(vo);
                     break;
                 case 4:  //血氧
-                    WatchSpo2DataVo spo2DataVo = watchSpo2DataService.getLatest(deviceId);
-                    if (spo2DataVo != null) {
-                        vo.setDate(spo2DataVo.getCreateTime());
-                        vo.setData(spo2DataVo.getAvgBoxy().toString());
+                    if (deviceId == null || deviceType == 0) {
+                        WatchSpo2DataVo spo2DataVo = watchSpo2DataService.getLatest(deviceId);
+                        if (spo2DataVo != null) {
+                            vo.setDate(spo2DataVo.getCreateTime());
+                            vo.setData(spo2DataVo.getAvgBoxy().toString());
 
 //                    WatchContinuousSpo2Data continuousSpo2Data = watchContinuousSpo2DataService.getLastByDeviceId(deviceId);
 //                    if (continuousSpo2Data != null) {
@@ -150,75 +203,159 @@ public class WatchDataServiceImpl implements WatchDataService {
 //                        } else {
 //                            vo.setData("");
 //                        }
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
-                        vo.setData("");
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId,4);
+                        if (data != null) {
+//                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
+                            vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,data.getCreateTime()));
+                            vo.setData(data.getRecordValue());
+                        } else {
+                            vo.setData("");
+                        }
                     }
+
+
                     vos.add(vo);
                     break;
                 case 5:  //体温
-                    WatchTemperatureData temperatureData = watchTemperatureDataService.getLatest(deviceId);
-                    if (temperatureData != null) {
+                    if (deviceId == null || deviceType == 0) {
+                        WatchTemperatureData temperatureData = watchTemperatureDataService.getLatest(deviceId);
+                        if (temperatureData != null) {
 //                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,temperatureData.getCreateTime()));
-                        vo.setDate(temperatureData.getCreateTime());
-                        vo.setData(temperatureData.getEstTemp().toString());
+                            vo.setDate(temperatureData.getCreateTime());
+                            vo.setData(temperatureData.getEstTemp().toString());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
                         vo.setData("");
                     }
+
+
                     vos.add(vo);
                     break;
                 case 6:  //呼吸 todo
-                    vo.setDate(DateUtils.dateTimeNow());
-                    vo.setData(120 + "");
+                    if (deviceId == null || deviceType == 0) {
+                        vo.setDate(DateUtils.dateTimeNow());
+                        vo.setData(120 + "");
+                    } else {
+                        vo.setDate(DateUtils.dateTimeNow());
+                        vo.setData(120 + "");
+
+                    }
+
                     vos.add(vo);
                     break;
                 case 7:  //血脂 todo
-                    vo.setData("");
+                    if (deviceId == null || deviceType == 0) {
+                        vo.setData("");
+                    } else {
+                        vo.setData("");
+                    }
+
+
+
                     vos.add(vo);
                     break;
                 case 8:  //尿酸
-                    WatchThirdUaData uaData = watchThirdUaDataService.getLatest(deviceId);
-                    if (uaData != null) {
-                        vo.setDate(uaData.getCreateTime());
-                        vo.setData(WatchUaStatusEnum.toType(
-                                watchThirdUaDataService.getStatus(deviceId,uaData.getVal(),Long.parseLong(userId),0)
-                        ).getDesc());
+                    if (deviceId == null || deviceType == 0) {
+                        WatchThirdUaData uaData = watchThirdUaDataService.getLatest(deviceId);
+                        if (uaData != null) {
+                            vo.setDate(uaData.getCreateTime());
+                            vo.setData(WatchUaStatusEnum.toType(
+                                    watchThirdUaDataService.getStatus(deviceId,uaData.getVal(),Long.parseLong(userId),0)
+                            ).getDesc());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
-                        vo.setData("");
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId,3);
+                        if (data != null) {
+//                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bgData.getCreateTime()));
+                            vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,data.getCreateTime()));
+                            vo.setData(data.getRecordValue());
+                        } else {
+                            vo.setData("");
+                        }
                     }
+
+
+
+
                     vos.add(vo);
                     break;
                 case 9:  //血管硬化 todo
-                    vo.setData("");
+                    if (deviceId == null || deviceType == 0) {
+                        vo.setData("");
+                    } else {
+                        vo.setData("");
+                    }
+
+
+
+
                     vos.add(vo);
                     break;
                 case 10:  //血酮
-                    WatchThirdBkData bkData = watchThirdBkDataService.getLatest(deviceId);
-                    if (bkData != null) {
+                    if (deviceId == null || deviceType == 0) {
+                        WatchThirdBkData bkData = watchThirdBkDataService.getLatest(deviceId);
+                        if (bkData != null) {
 //                        vo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bkData.getCreateTime()));
-                        vo.setDate(bkData.getCreateTime());
+                            vo.setDate(bkData.getCreateTime());
 //                        list.add(bkData.getVal().toString());
-                        Integer status = bkData.getStatus();
-                        vo.setData(status == 0 ? "正常" : "异常");
+                            Integer status = bkData.getStatus();
+                            vo.setData(status == 0 ? "正常" : "异常");
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
                         vo.setData("");
                     }
+
+
+
                     vos.add(vo);
                     break;
                 case 11:  //睡眠 todo 未确定返回数据
-                    //查询最新日期
-                    WatchSleepData data = watchSleepDataService.getLast(deviceId);
-                    if (data != null) {
-                        String date = data.getCreateTime().split(" ")[0];
-                        WatchSleepDataVo sleepSection = watchSleepDataService.getSleepSection(date, deviceId);
-                        if (sleepSection != null) {
-                            vo.setDate(date);
-                            Integer score = sleepSection.getScore();
-                            vo.setData(score==null?"":score.toString());
+                    if (deviceId == null || deviceType == 0) {
+                        //查询最新日期
+                        WatchSleepData data = watchSleepDataService.getLast(deviceId);
+                        if (data != null) {
+                            String date = data.getCreateTime().split(" ")[0];
+                            WatchSleepDataVo sleepSection = watchSleepDataService.getSleepSection(date, deviceId);
+                            if (sleepSection != null) {
+                                vo.setDate(date);
+                                Integer score = sleepSection.getScore();
+                                vo.setData(score==null?"":score.toString());
+                                vos.add(vo);
+                                break;
+                            }
+                        }
+                        vo.setData("");
+                    } else {
+                        FsThirdDeviceData data = fsThirdDeviceDataMapper.getLatest(deviceId, 7);
+                        if (data != null) {
+                            Date endTime = data.getCreateTime();
+                            vo.setDate(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", endTime));
+                            Date starTime = DateUtils.truncate(endTime, Calendar.DATE);
+                            List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(starTime, endTime, deviceId, 7, null);
+                            // 计算睡眠评分
+                            int score = 0;
+//                            SleepStatistics statistics = null;
+                            if (list != null && !list.isEmpty()) {
+                                // 计算详细统计信息
+//                                statistics = SleepScoreCalculator.calculateDetailedStatistics(list);
+                                score = SleepScoreCalculator.calculateSleepScore(list);
+                            }
+                            vo.setData(String.valueOf(score));
                             vos.add(vo);
                             break;
                         }
+                        vo.setData("");
                     }
-                    vo.setData("");
                     vos.add(vo);
                     break;
 //                case 12:  //房颤 todo 未确定返回数据
@@ -236,13 +373,19 @@ public class WatchDataServiceImpl implements WatchDataService {
                     vos.add(vo);
                     break;
                 case 13:  //压力
-                    WatchFatigueData fatigue = watchFatigueDataService.getLastByDeviceId(deviceId);
-                    if (fatigue != null){
-                        vo.setDate(fatigue.getCreateTime());
-                        vo.setData(WatchFatigueStatusEnum.toType(fatigue.getStatus()).getDesc());
+                    if (deviceId == null || deviceType == 0) {
+                        WatchFatigueData fatigue = watchFatigueDataService.getLastByDeviceId(deviceId);
+                        if (fatigue != null){
+                            vo.setDate(fatigue.getCreateTime());
+                            vo.setData(WatchFatigueStatusEnum.toType(fatigue.getStatus()).getDesc());
+                        } else {
+                            vo.setData("");
+                        }
                     } else {
                         vo.setData("");
                     }
+
+
                     vos.add(vo);
                     break;
                 default:
@@ -253,12 +396,21 @@ public class WatchDataServiceImpl implements WatchDataService {
     }
 
     @Override
-    public List<AppInfoVo> getUserByDeviceId(String deviceIds, Boolean isFamily,Long userId) {
-        List<String> list = Arrays.asList(deviceIds.split(","));
-        WatchFsUser user = null;
-        if (list != null && list.size() > 0) {
-            //设备绑定用户名
-            user = userService.selectWatchFsUserByDeviceIdAndUserId(list.get(0), userId,isFamily?1:0);
+    public List<AppInfoVo> getUserByDeviceId(WatchUserByDeviceIdParam watchUserByDeviceIdParam, Long userId) {
+        List<WatchUserByDeviceIdParam.WatchUserByDeviceIdTemp> params = watchUserByDeviceIdParam.getParams();
+        Boolean isFamily = watchUserByDeviceIdParam.getIsFamily();
+        List<AppInfoVo> vos = new ArrayList<>();
+        for (WatchUserByDeviceIdParam.WatchUserByDeviceIdTemp temp : params) {
+            WatchFsUser user = null;
+            String deviceId = temp.getDeviceId();
+            Integer deviceType = temp.getDeviceType();
+            if (deviceType == null || deviceType == 0) {
+                user = userService.selectWatchFsUserByDeviceIdAndUserId(deviceId, userId, isFamily ? 1 : 0);
+            } else if (deviceType == 1) {
+                user = userService.selectWatchFsUserByDeviceIdAndUserId(deviceId, userId, isFamily ? 3 : 2);
+            }else if (deviceType == 2){
+                user = userService.selectWatchFsUserByDeviceIdAndUserId(deviceId, userId, isFamily ? 5: 4);
+            }
             if (user != null) {
                 //处理电话
                 String phone = user.getPhone();
@@ -270,34 +422,38 @@ public class WatchDataServiceImpl implements WatchDataService {
             }
 
             if (!isFamily && user == null) {
-                return null;
+                continue;
             }
-            List<AppInfoVo> vos = new ArrayList<>();
-            for (String deviceId : list) {
-                AppInfoVo appInfoVo = new AppInfoVo();
-                appInfoVo.setUser(user);
-                //设备型号
-                WatchDeviceData data = watchDeviceDataMapper.getByDeviceId(deviceId);
+
+            AppInfoVo appInfoVo = new AppInfoVo();
+            appInfoVo.setUser(user);
+            //设备型号
+            WatchDeviceData data = null;
+            Map<String, Object> statusData = null;
+            if (deviceType == null || deviceType == 0) {
+                data = watchDeviceDataMapper.getByDeviceId(deviceId);
                 if (data != null) {
                     appInfoVo.setBle(data.getBle());
                 } else {
                     appInfoVo.setBle("H102C");
                 }
                 //获取设备状态
-                Map<String, Object> statusData = deviceInfoService.getInfo(deviceId);
+                statusData = deviceInfoService.getInfo(deviceId);
                 if (statusData == null) {
                     appInfoVo.setStatus(3);
                 } else if (statusData.get("status") != null) {
                     appInfoVo.setStatus(Integer.parseInt(statusData.get("status").toString()));
                 }
-                vos.add(appInfoVo);
-
-
+            } else if (deviceType == 1) {
+                appInfoVo.setBle("小护士设备:" + deviceId);
+                appInfoVo.setStatus(3);
+            } else if (deviceType == 2) {
+                appInfoVo.setBle("小护士手表:" + deviceId);
+                appInfoVo.setStatus(3);
             }
-            return vos;
-        } else {
-            return null;
+            vos.add(appInfoVo);
         }
+        return vos;
 
     }
 
@@ -459,19 +615,28 @@ public class WatchDataServiceImpl implements WatchDataService {
     }
 
     @Override
-    public QueryPageMonthVo queryMonthByDeviceId(String deviceId, Integer pageSize, Integer pageNum) {
+    public QueryPageMonthVo queryMonthByDeviceId(String deviceId, Integer pageSize, Integer pageNum,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
-        //从watch_device_data有数据开始
-        WatchDeviceData lastByDeviceId = watchDeviceDataMapper.getByDeviceId(deviceId);
-        if (lastByDeviceId == null) {
-            return null;
+        Date createTime = null;
+        List<String> monthList = null;
+        if (deviceType == null || deviceType == 0) {
+            //从watch_device_data有数据开始
+            WatchDeviceData lastByDeviceId = watchDeviceDataMapper.getByDeviceId(deviceId);
+            if (lastByDeviceId == null) {
+                return null;
+            }
+            // 获取设备创建时间
+            createTime = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",lastByDeviceId.getCreateTime());
+        } else {
+            FsThirdDeviceData firstDataByDeviceId = fsThirdDeviceDataMapper.getFirstDataByDeviceId(deviceId);
+            if (firstDataByDeviceId == null) {
+                return null;
+            }
+            createTime = firstDataByDeviceId.getCreateTime();
         }
 
-        List<String> monthList = null;
-        // 获取设备创建时间
-        Date createTime = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",lastByDeviceId.getCreateTime());
 
         // 获取当前时间
         Calendar current = Calendar.getInstance();
@@ -491,7 +656,7 @@ public class WatchDataServiceImpl implements WatchDataService {
 
             //有数据才添加
             //
-            Boolean flag = isHavingData(deviceId, monthStr);
+            Boolean flag = isHavingData(deviceId, monthStr,deviceType);
             if (flag){
                 // 获取当前日期并格式化为yyyy-MM,并存入列表
                 monthList.add(dateFormat.format(calendar.getTime()));
@@ -510,36 +675,69 @@ public class WatchDataServiceImpl implements WatchDataService {
         return vo;
     }
 
-    private  Boolean isHavingData(String deviceId, String monthStr) {
+    private  Boolean isHavingData(String deviceId, String monthStr,Integer deviceType) {
         boolean flag = false;
-        List<WatchThirdBpData> bpList = watchThirdBpDataMapper.queryByMonth(deviceId, monthStr);
-        if (bpList != null && !bpList.isEmpty()) {
-            flag = true;
-            return flag;
-        }
-        //血氧
-        List<WatchContinuousSpo2Data> spo2DataList = watchContinuousSpo2DataMapper.queryByMonth(deviceId, monthStr);
-        if (spo2DataList != null && !spo2DataList.isEmpty()) {
-            flag = true;
-            return flag;
-        }
-        //心率
-        List<WatchHeartRateData> hrList = watchHeartRateDataMapper.queryByMonth(deviceId, monthStr);
-        if (hrList != null && !hrList.isEmpty()) {
-            flag = true;
-            return flag;
-        }
-        //睡眠
-        List<WatchSleepData> sleepList = watchSleepDataMapper.queryByMonth(deviceId, monthStr);
-        if (sleepList != null && !sleepList.isEmpty()) {
-            flag = true;
-            return flag;
-        }
-        //血糖
-        List<WatchBloodGlucoseData> bgList = watchBloodGlucoseDataMapper.queryByMonth(deviceId, monthStr);
-        if (bgList != null && !bgList.isEmpty()) {
-            flag = true;
-            return flag;
+        if (deviceType == null ||  deviceType == 0) {
+            List<WatchThirdBpData> bpList = watchThirdBpDataMapper.queryByMonth(deviceId, monthStr);
+            if (bpList != null && !bpList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //血氧
+            List<WatchContinuousSpo2Data> spo2DataList = watchContinuousSpo2DataMapper.queryByMonth(deviceId, monthStr);
+            if (spo2DataList != null && !spo2DataList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //心率
+            List<WatchHeartRateData> hrList = watchHeartRateDataMapper.queryByMonth(deviceId, monthStr);
+            if (hrList != null && !hrList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //睡眠
+            List<WatchSleepData> sleepList = watchSleepDataMapper.queryByMonth(deviceId, monthStr);
+            if (sleepList != null && !sleepList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //血糖
+            List<WatchBloodGlucoseData> bgList = watchBloodGlucoseDataMapper.queryByMonth(deviceId, monthStr);
+            if (bgList != null && !bgList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+
+        } else {
+            List<FsThirdDeviceData> bpList = fsThirdDeviceDataMapper.queryByMonth(deviceId, monthStr,0);
+            if (bpList != null && !bpList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //血氧
+//            List<WatchContinuousSpo2Data> spo2DataList = fsThirdDeviceDataMapper.querySpo2ByMonth(deviceId, monthStr);
+//            if (spo2DataList != null && !spo2DataList.isEmpty()) {
+//                flag = true;
+//                return flag;
+//            }
+            //心率
+            List<FsThirdDeviceData> hrList = fsThirdDeviceDataMapper.queryByMonth(deviceId, monthStr,2);
+            if (hrList != null && !hrList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
+            //睡眠
+//            List<WatchSleepData> sleepList = fsThirdDeviceDataMapper.querySleepByMonth(deviceId, monthStr);
+//            if (sleepList != null && !sleepList.isEmpty()) {
+//                flag = true;
+//                return flag;
+//            }
+            //血糖
+            List<FsThirdDeviceData> bgList = fsThirdDeviceDataMapper.queryByMonth(deviceId, monthStr,1);
+            if (bgList != null && !bgList.isEmpty()) {
+                flag = true;
+                return flag;
+            }
         }
         return flag;
     }

+ 1 - 1
fs-service/src/main/java/com/fs/watch/service/impl/WatchDeviceInfoServiceImpl.java

@@ -473,7 +473,7 @@ public class WatchDeviceInfoServiceImpl implements WatchDeviceInfoService {
     private void queryCompanyUserInfo(WatchDeviceInfoVo watchDeviceInfoVo) {
         String companyUserId = watchDeviceInfoVo.getCompanyUserId();
         if (StringUtils.isNotBlank(companyUserId)) {
-            watchDeviceInfoVo.setCompanyUserName(companyUserService.selectCompanyUserNameUserById(Long.valueOf(companyUserId)));
+            watchDeviceInfoVo.setCompanyUserName(companyUserService.selectCompanyUserByStrIds(companyUserId));
         }
     }
 

+ 46 - 8
fs-service/src/main/java/com/fs/watch/service/impl/WatchHeartRateDataServiceImpl.java

@@ -2,6 +2,8 @@ package com.fs.watch.service.impl;
 
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.domain.WatchDeviceInfo;
 import com.fs.watch.domain.WatchHeartRateData;
 import com.fs.watch.domain.vo.WatchHeartRateDataVo;
@@ -27,6 +29,8 @@ public class WatchHeartRateDataServiceImpl implements WatchHeartRateDataService
     private WatchHeartRateDataMapper mapper;
     @Autowired
     private WatchDeviceInfoMapper watchDeviceInfoMapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
 
     @Override
     public Boolean insert(WatchHeartRateData watchHeartRateData) {
@@ -70,7 +74,7 @@ public class WatchHeartRateDataServiceImpl implements WatchHeartRateDataService
         Integer max = 0;
         Integer min = 0;
         Integer avg = 0;
-        if (list.size() > 0) {
+        if (!list.isEmpty()) {
             max = list.stream().max(Comparator.comparingInt(WatchHeartRateData::getMaxBpm)).get().getMaxBpm();
             min = list.stream().min(Comparator.comparingInt(WatchHeartRateData::getMinBpm)).get().getMinBpm();
             //计算平均值
@@ -90,11 +94,29 @@ public class WatchHeartRateDataServiceImpl implements WatchHeartRateDataService
     }
 
     @Override
-    public WatchHeartRateDataVo list(Date startTime, Date endTime, String deviceId) {
+    public WatchHeartRateDataVo list(Date startTime, Date endTime, String deviceId, Integer deviceType) {
         if (StringUtils.isNotBlank(deviceId)) {
-            List<WatchHeartRateData> data = mapper.list(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId);
+            List<WatchHeartRateData> data = new ArrayList<>();
+            if (deviceType == null || deviceType == 0){
+                data = mapper.list(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId);
+
+            } else {
+                List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 2, null);
+                if (list != null && !list.isEmpty()) {
+                    for (FsThirdDeviceData item : list) {
+                        WatchHeartRateData watchHeartRateData = new WatchHeartRateData();
+                        watchHeartRateData.setDeviceId(item.getDeviceId());
+                        watchHeartRateData.setMaxBpm(Integer.valueOf(item.getRecordValue()));
+                        watchHeartRateData.setMinBpm(Integer.valueOf(item.getRecordValue()));
+                        watchHeartRateData.setAvgBpm(Integer.valueOf(item.getRecordValue()));
+                        watchHeartRateData.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",item.getCreateTime()));
+                        watchHeartRateData.setStatus(item.getStatus());
+                        data.add(watchHeartRateData);
+                    }
+                }
+            }
             return getWatchHeartRateDataVo(data);
         }
         return null;
@@ -126,15 +148,31 @@ public class WatchHeartRateDataServiceImpl implements WatchHeartRateDataService
 
 
     @Override
-    public List<Map<String, Object>> countHeartByDate(Date startTime, Date endTime, String deviceId) {
+    public List<Map<String, Object>> countHeartByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
         //返回对象
         List<Map<String, Object>> res = null;
-        res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        if (deviceType == null || deviceType == 0){
+            res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        } else {
+            res = fsThirdDeviceDataMapper.countByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 2, null);
+        }
+
 
         return res;
     }
+
+    @Override
+    public Integer getStatus(int maxBpm, int minBpm) {
+        if (maxBpm > 100) {
+            return WatchHrStatusEnum.FAST.getValue();
+        } else if (minBpm < 60) {
+            return WatchHrStatusEnum.LOW.getValue();
+        } else {
+            return WatchHrStatusEnum.NORMAL.getValue();
+        }
+    }
 }

+ 71 - 25
fs-service/src/main/java/com/fs/watch/service/impl/WatchSleepDataServiceImpl.java

@@ -5,7 +5,10 @@ import com.alibaba.fastjson.JSONObject;
 import com.fs.common.config.WatchConfig;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.calculation.SleepPreprocessor;
+import com.fs.watch.calculation.SleepScoreCalculator;
 import com.fs.watch.domain.*;
 import com.fs.watch.domain.vo.AppWatchSleepDataVo;
 import com.fs.watch.domain.vo.WatchSleepDataVo;
@@ -57,6 +60,9 @@ public class WatchSleepDataServiceImpl implements WatchSleepDataService {
     @Autowired
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
+
 
     private static final MyHttpUtils httpUtils = new MyHttpUtils();
 
@@ -285,7 +291,7 @@ public class WatchSleepDataServiceImpl implements WatchSleepDataService {
     }
 
     @Override
-    public AppWatchSleepDataVo list(Date startTime, Date endTime, String deviceId) {
+    public AppWatchSleepDataVo list(Date startTime, Date endTime, String deviceId, Integer deviceType) {
         //返回对象
         AppWatchSleepDataVo vo = new AppWatchSleepDataVo();
         // 使用 Calendar 类来循环增加日期
@@ -310,33 +316,73 @@ public class WatchSleepDataServiceImpl implements WatchSleepDataService {
         List<WatchSleepDataVo> watchSleepDataVos = new ArrayList<>();
         while (calendar.getTime().before(endTime) || calendar.getTime().equals(endTime)) {
             Date currentDate = calendar.getTime();
+            if (deviceType == null || deviceType == 0) {
 //                log.info(currentDate);
-            WatchSleepDataVo watchSleepDataVo = getSleepSection(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, currentDate), deviceId);
-
-            if (watchSleepDataVo != null && watchSleepDataVo.getSleepSection() !=null && watchSleepDataVo.getSleepSection().size() > 0) {
-                watchSleepDataVo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, currentDate));
-                watchSleepDataVos.add(watchSleepDataVo);
-                AppWatchSleepDataVo appWatchSleepDataVo = parserResult(deviceId, watchSleepDataVo);
-                //统计图对象
-                sleepSection.addAll(appWatchSleepDataVo.getSleepSection());
-                //深睡时间
-                sSleep = sSleep + appWatchSleepDataVo.getDeepSleep();
-                //浅睡时间
-                lightSleep =lightSleep+ appWatchSleepDataVo.getLightSleep();
-                //清醒时间
-                weakSleep =weakSleep+ appWatchSleepDataVo.getWeakSleep();
-                //快速眼动时间
-                eyemoveSleep =eyemoveSleep+ appWatchSleepDataVo.getEyemoveSleep();
-                //清醒次数
-                weakTime = weakTime + appWatchSleepDataVo.getWeakTime();
-                //夜间睡眠时间(深睡+浅睡)
-                sleepCount=sleepCount+appWatchSleepDataVo.getSleepCount();
-
-                timeTotal = timeTotal + appWatchSleepDataVo.getSleepTime();
-
-                //呼吸质量 得分(百分制)
+                WatchSleepDataVo watchSleepDataVo = getSleepSection(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, currentDate), deviceId);
+                if (watchSleepDataVo != null && watchSleepDataVo.getSleepSection() !=null && !watchSleepDataVo.getSleepSection().isEmpty()) {
+                    watchSleepDataVo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, currentDate));
+                    watchSleepDataVos.add(watchSleepDataVo);
+                    AppWatchSleepDataVo appWatchSleepDataVo = parserResult(deviceId, watchSleepDataVo);
+                    //统计图对象
+                    sleepSection.addAll(appWatchSleepDataVo.getSleepSection());
+                    //深睡时间
+                    sSleep = sSleep + appWatchSleepDataVo.getDeepSleep();
+                    //浅睡时间
+                    lightSleep =lightSleep+ appWatchSleepDataVo.getLightSleep();
+                    //清醒时间
+                    weakSleep =weakSleep+ appWatchSleepDataVo.getWeakSleep();
+                    //快速眼动时间
+                    eyemoveSleep =eyemoveSleep+ appWatchSleepDataVo.getEyemoveSleep();
+                    //清醒次数
+                    weakTime = weakTime + appWatchSleepDataVo.getWeakTime();
+                    //夜间睡眠时间(深睡+浅睡)
+                    sleepCount=sleepCount+appWatchSleepDataVo.getSleepCount();
+
+                    timeTotal = timeTotal + appWatchSleepDataVo.getSleepTime();
+
+                }
+            } else {
+                Date dayStartTime = DateUtils.truncate(currentDate, Calendar.DATE);
+                Date dayEndTime =  DateUtils.addMilliseconds(
+                        DateUtils.addDays(DateUtils.truncate(currentDate, Calendar.DATE), 1),
+                        -1
+                );
+                List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(dayStartTime, dayEndTime, deviceId, 7, null);
+                if (list != null && !list.isEmpty()) {
+                    SleepStatistics sleepStatistics = SleepScoreCalculator.calculateDetailedStatistics(list);
+                    List<SleepSection> sleepSection1 = sleepStatistics.getSleepSection();
+                    //统计图对象
+                    sleepSection.addAll(sleepSection1);
+                    //深睡时间
+                    sSleep = sSleep + sleepStatistics.getDeepSleepHours().longValue()*60;
+                    //浅睡时间
+                    lightSleep =lightSleep+ sleepStatistics.getLightSleepHours().longValue()*60;
+                    //清醒时间
+                    weakSleep = (long) (weakSleep+ (sleepStatistics.getAwakeDuration() / (1000.0 * 60)));
+                    //没有快速眼动时间
+                    //清醒次数
+                    weakTime = weakTime + sleepStatistics.getAwakeCount();
+                    //夜间睡眠时间(深睡+浅睡)
+                    sleepCount=sleepCount+(sleepStatistics.getDeepSleepCount() + sleepStatistics.getLightSleepCount());
+
+                    timeTotal = timeTotal + sleepStatistics.getTotalSleepHours().longValue()*60;
+                    WatchSleepDataVo watchSleepDataVo = new WatchSleepDataVo();
+                    watchSleepDataVo.setDeviceId(deviceId);
+                    watchSleepDataVo.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, currentDate));
+                    watchSleepDataVo.setStartTime(sleepSection1.get(0).getStart());
+                    watchSleepDataVo.setEndTime(sleepSection1.get(sleepSection1.size()-1).getEnd());
+                    watchSleepDataVo.setDeepSleep(sleepStatistics.getDeepSleepHours().intValue() * 60);
+                    watchSleepDataVo.setLightSleep(sleepStatistics.getLightSleepHours().intValue() * 60);
+                    watchSleepDataVo.setWeakSleep((int) (sleepStatistics.getAwakeDuration() / (1000.0 * 60)));
+                    watchSleepDataVo.setEyemoveSleep(sleepStatistics.getRemHours().intValue() * 60);
+//                    watchSleepDataVo.setScore(score); // 需要从某处获取睡眠得分
+                    watchSleepDataVo.setSleepTime(sleepStatistics.getTotalSleepHours().intValue() * 60);
+                    watchSleepDataVo.setSleepSection(sleepSection1);
+                    watchSleepDataVos.add(watchSleepDataVo);
+                }
             }
 
+
             // 增加一天
             calendar.add(Calendar.DAY_OF_MONTH, 1);
         }

+ 68 - 23
fs-service/src/main/java/com/fs/watch/service/impl/WatchSpo2DataServiceImpl.java

@@ -2,6 +2,8 @@ package com.fs.watch.service.impl;
 
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.domain.WatchContinuousSpo2Data;
 import com.fs.watch.domain.WatchDeviceInfo;
 import com.fs.watch.domain.WatchSpo2Data;
@@ -35,6 +37,9 @@ public class WatchSpo2DataServiceImpl implements WatchSpo2DataService {
     @Autowired
     private WatchDeviceInfoMapper watchDeviceInfoMapper;
 
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
+
 
     @Override
     public Boolean insert(WatchSpo2Data watchSpo2Data) {
@@ -66,41 +71,76 @@ public class WatchSpo2DataServiceImpl implements WatchSpo2DataService {
     }
 
     @Override
-    public WatchSpo2DataQueryVo querySpByDate(Date startTime, Date endTime, String deviceId) {
+    public WatchSpo2DataQueryVo querySpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isNotBlank(deviceId)) {
-            List<WatchSpo2DataVo> spo2DataVos = mapper.querySpByDate(DateUtils.parseDateToStr(
-                    DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId);
+            WatchSpo2DataQueryVo watchSpo2DataQueryVo = new WatchSpo2DataQueryVo();
+            if (deviceType == null || deviceType == 0){
+                List<WatchSpo2DataVo> spo2DataVos = mapper.querySpByDate(DateUtils.parseDateToStr(
+                                DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId);
 //            List<WatchContinuousSpo2Data> datas = continuousSpo2DataService.querySpByDate(DateUtils.parseDateToStr(
 //                    DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
 //                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
 //                    deviceId);
 //            //数据处理
 //            ArrayList<WatchSpo2DataVo> spo2DataVos = getWatchSpo2DataVos(deviceId, datas);
-            WatchSpo2DataQueryVo watchSpo2DataQueryVo = new WatchSpo2DataQueryVo();
-            watchSpo2DataQueryVo.setList(spo2DataVos);
-            Integer max = 0;
-            Integer min = 0;
-            double avg = 0.;
+                watchSpo2DataQueryVo.setList(spo2DataVos);
+                Integer max = 0;
+                Integer min = 0;
+                double avg = 0.;
 //
-            if (!spo2DataVos.isEmpty()){
-                max = spo2DataVos.stream().map(WatchSpo2DataVo::getMaxBoxy).max(Integer::compareTo).get();
-                min = spo2DataVos.stream().map(WatchSpo2DataVo::getMinBoxy).min(Integer::compareTo).get();
-                avg = spo2DataVos.stream().map(WatchSpo2DataVo::getAvgBoxy).min(Double::compareTo).get();
+                if (!spo2DataVos.isEmpty()){
+                    max = spo2DataVos.stream().map(WatchSpo2DataVo::getMaxBoxy).max(Integer::compareTo).get();
+                    min = spo2DataVos.stream().map(WatchSpo2DataVo::getMinBoxy).min(Integer::compareTo).get();
+                    avg = spo2DataVos.stream().map(WatchSpo2DataVo::getAvgBoxy).min(Double::compareTo).get();
 //                OptionalDouble  averageValue = spo2DataVos.stream().filter(temp->temp.getAvgBoxy()!=null).mapToDouble(WatchSpo2DataVo::getAvgBoxy)
 //                        .average();
-                // 如果平均值存在,将其转换为 int 类型并输出
+                    // 如果平均值存在,将其转换为 int 类型并输出
 //                if (averageValue.isPresent()) {
 ////                    avg = (int) averageValue.getAsDouble();  // 将 double 转换为 int
 //                    avg = averageValue.getAsDouble();  // 将 double 转换为 int
 //                    avg = Math.round(avg * 100.0) / 100.0;
 //                }
-            }
+                }
 
-            watchSpo2DataQueryVo.setMax(max);
-            watchSpo2DataQueryVo.setMin(min);
-            watchSpo2DataQueryVo.setAvg(avg);
+                watchSpo2DataQueryVo.setMax(max);
+                watchSpo2DataQueryVo.setMin(min);
+                watchSpo2DataQueryVo.setAvg(avg);
+
+            } else {
+                List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(startTime,endTime,deviceId,4,null);
+                if (list != null && !list.isEmpty()) {
+                    int max = 0;
+                    int min = 0;
+                    double avg = 0.;
+                    int sum = 0;
+                    List<WatchSpo2DataVo> listVos = new ArrayList<>();
+                    for (FsThirdDeviceData fsThirdDeviceData : list) {
+                        WatchSpo2DataVo vo = new WatchSpo2DataVo();
+                        vo.setDeviceId(fsThirdDeviceData.getDeviceId());
+                        int num = Integer.parseInt(fsThirdDeviceData.getRecordValue());
+                        vo.setMinBoxy(num);
+                        vo.setMaxBoxy(num);
+                        vo.setAvgBoxy(Double.valueOf(num));
+                        vo.setStatus(getStatus(num,num));
+                        listVos.add(vo);
+                        max = Math.max(num, max);
+                        min = Math.min(num, min);
+                        sum += num;
+                    }
+                    if (sum > 0){
+                        avg = (double) sum / listVos.size();
+                    }
+                    watchSpo2DataQueryVo.setMin(min);
+                    watchSpo2DataQueryVo.setMax(max);
+                    watchSpo2DataQueryVo.setAvg(avg);
+                    watchSpo2DataQueryVo.setList(listVos);
+                } else {
+                    return null;
+                }
+
+            }
             return watchSpo2DataQueryVo;
         }
         return null;
@@ -168,20 +208,25 @@ public class WatchSpo2DataServiceImpl implements WatchSpo2DataService {
     }
 
     @Override
-    public List<Map<String, Object>> countSpByDate(Date startTime, Date endTime, String deviceId) {
+    public List<Map<String, Object>> countSpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
-//        res = mapper.countSpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+        if (deviceType == null || deviceType == 0) {
+            //        res = mapper.countSpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
 //                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),deviceId);
-        return mapper.countSpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),deviceId);
+            return mapper.countSpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),deviceId);
 //        List<WatchContinuousSpo2Data> list = continuousSpo2DataService.querySpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
 //                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
 //        if (list != null && list.size() > 0) {
 //            return getStatusCount(list);
 //        }
 //        return null;
+        } else {
+           return fsThirdDeviceDataMapper.countByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 4,null);
+        }
+
     }
 
     private List<Map<String, Integer>> getStatusCount(List<WatchContinuousSpo2Data> list) {

+ 184 - 43
fs-service/src/main/java/com/fs/watch/service/impl/WatchSportDataServiceImpl.java

@@ -5,6 +5,8 @@ import com.fs.common.utils.StringUtils;
 import com.fs.his.mapper.FsHealthPulseMapper;
 import com.fs.his.mapper.FsHealthSurfaceMapper;
 import com.fs.his.mapper.FsHealthTongueMapper;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
+import com.fs.watch.calculation.SleepScoreCalculator;
 import com.fs.watch.domain.WatchFsUser;
 import com.fs.watch.domain.WatchSportData;
 import com.fs.watch.domain.vo.*;
@@ -53,6 +55,10 @@ public class WatchSportDataServiceImpl implements WatchSportDataService {
     private FsHealthSurfaceMapper fsHealthSurfaceMapper;
     @Autowired
     private FsHealthPulseMapper fsHealthPulseMapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
+    @Autowired
+    private SleepScoreCalculator sleepScoreCalculator;
 
 
     @Override
@@ -263,26 +269,95 @@ public class WatchSportDataServiceImpl implements WatchSportDataService {
     }
 
     @Override
-    public List<WatchSportRecordVo> queryRecord(String deviceId) {
+    public List<WatchSportRecordVo> queryRecord(String deviceId,Integer deviceType) {
+        String s = DateUtils.dateTimeNow("yyyy-MM-dd");
+        Date startTime = DateUtils.parseDate(s + " 00:00:00");
+        Date endTime = DateUtils.parseDate(s + " 23:59:59");
         if (StringUtils.isNotBlank(deviceId)) {
-            String s = DateUtils.dateTimeNow("yyyy-MM-dd");
-            Date startTime = DateUtils.parseDate(s + " 00:00:00");
-            Date endTime = DateUtils.parseDate(s + " 23:59:59");
-            List<WatchSportRecordVo> res = mapper.queryRecord(startTime, endTime, deviceId, null);
-            List<String> types = new ArrayList<>(Arrays.asList("游泳", "登山", "骑行", "跑步", "球类", "健走", "走路"));
-//            //其他运动
-            WatchSportRecordVo vo = mapper.getOtherData(null, null, deviceId, types);
+            WatchSportRecordVo vo =  new WatchSportRecordVo();
+            List<WatchSportRecordVo> res = new ArrayList<>();
+            if (deviceType == null || deviceType == 0) {
+                res = mapper.queryRecord(startTime, endTime, deviceId, null);
+                List<String> types = new ArrayList<>(Arrays.asList("游泳", "登山", "骑行", "跑步", "球类", "健走", "走路"));
+            //其他运动
+                vo = mapper.getOtherData(null, null, deviceId, types);
+                //计算时长
+//            mapper.getByTypeAndDeviceIdAndDate(deviceId,typ)
+            } else {
+                vo = fsThirdDeviceDataMapper.getOtherDataOther(startTime, endTime, deviceId, 6);
+                List<WatchSportRecordVo> list = fsThirdDeviceDataMapper.queryActivityRecord(startTime, endTime, deviceId, 6, null);
+                if (list != null && !list.isEmpty()) {
+                    for (WatchSportRecordVo data : list) {
+                        String sportType = data.getType();
+                        if (StringUtils.isNotBlank(sportType)) {
+                            data.setType(getActivityType(Integer.parseInt(sportType)));
+                            res.add(data);
+                        }
+                    }
+                }
+
+            }
             vo.setType("其他运动");
             res.add(vo);
-            //计算时长
-//            mapper.getByTypeAndDeviceIdAndDate(deviceId,typ)
             return res;
         }
         return null;
     }
 
+    private String getActivityType(Integer sportType) {
+        if (sportType == null) {
+            return null;
+        }
+        switch (sportType) {
+            case 1:
+                return "骑行";
+            case 5:
+                return "健步走";
+            case 9:
+                return "跑步";
+            case 13:
+                return "走路";
+            case 17:
+                return "登山";
+            case 21:
+                return "球类";
+            case 25:
+                return "游泳";
+            case 29:
+                return "羽毛球";
+            case 33:
+                return "足球";
+            case 37:
+                return "椭圆机";
+            case 41:
+                return "瑜伽";
+            case 45:
+                return "乒乓球";
+            case 49:
+                return "跳绳";
+            case 53:
+                return "划船机";
+            case 65:
+                return "自由训练";
+            case 69:
+                return "网球";
+            case 85:
+                return "自由运动";
+            case 89:
+                return "力量训练";
+            case 105:
+                return "舞蹈";
+            case 109:
+                return "呼啦圈";
+            case 113:
+                return "高尔夫";
+            default:
+                return null;
+        }
+    }
+
     @Override
-    public WatchSportIndexVo sportData(String userId, String deviceId,Boolean isFamily) {
+    public WatchSportIndexVo sportData(String userId, String deviceId,Boolean isFamily,Integer deviceType) {
         WatchSportIndexVo vo = new WatchSportIndexVo();
         if (isFamily != null && isFamily) {
             WatchFamilyUserVo watchFamilyUserVo = familyUserService.selectWatchFamilyUserByDeviceId(deviceId, null);
@@ -305,18 +380,56 @@ public class WatchSportDataServiceImpl implements WatchSportDataService {
 
         //2.查询当日完成
         //2.1卡路里,步数
-        WatchSportData map = mapper.sumStepAndCalorie(deviceId);
-        if (map != null) {
-            vo.setStep(map.getStep().toString());
-            vo.setCalorie(String.format("%.2f", map.getCalorie()));
+        if (deviceType == null || deviceType == 0) {
+            WatchSportData map = mapper.sumStepAndCalorie(deviceId);
+            if (map != null) {
+                vo.setStep(map.getStep().toString());
+                vo.setCalorie(String.format("%.2f", map.getCalorie()));
+            }
+            //2.2 时长
+            Long sportTime = getSportTime(deviceId, null, "today");
+            //2.2.1 活动
+            Long activityTime = getActivityTime(deviceId);//分钟
+            //2.2.2 锻炼
+            vo.setSport(sportTime == null ? "0" : sportTime.toString());
+            vo.setActivity(activityTime == null ? "0" : new BigDecimal(activityTime).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP) + "");
+        } else {
+            Date starTime = DateUtils.truncate(new Date(), Calendar.DATE);
+            Date endTime = DateUtils.getNowDate();
+            //步数
+            WatchSportRecordVo map1 = fsThirdDeviceDataMapper.getOtherData(starTime,endTime,deviceId,5,null);
+            //运动
+            WatchSportRecordVo map2 = fsThirdDeviceDataMapper.getOtherData(starTime,endTime,deviceId,6,null);
+            long stepTotal = 0L;
+            float calorieTotal = 0f;
+            vo.setActivity("0");
+            vo.setSport("0");
+            if (map1 != null) {
+                stepTotal = stepTotal + (map1.getStep()==null?0:map1.getStep());
+                if (map1.getCalorie()!=null && map1.getCalorie()>0) {
+                    calorieTotal = map1.getCalorie();
+                }
+                Float time = map1.getTime();
+                if (time != null) {
+                    vo.setActivity(String.valueOf(time));
+                }
+
+            }
+            if (map2 != null) {
+                stepTotal = stepTotal + (map2.getStep()==null?0:map2.getStep());
+                Float time = map2.getTime();
+                if (time != null) {
+                    vo.setSport(String.valueOf(time*60));
+                }
+
+            }
+            //2.2.2 锻炼
+            vo.setStep(String.valueOf(stepTotal));
+            vo.setCalorie(String.valueOf(calorieTotal));
+
         }
-        //2.2 时长
-        Long sportTime = getSportTime(deviceId, null, "today");
-        //2.2.1 活动
-        Long activityTime = getActivityTime(deviceId);//分钟
-        //2.2.2 锻炼
-        vo.setSport(sportTime == null ? "0" : sportTime.toString());
-        vo.setActivity(activityTime == null ? "0" : new BigDecimal(activityTime).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP) + "");
+
+
         return vo;
     }
 
@@ -499,34 +612,61 @@ public class WatchSportDataServiceImpl implements WatchSportDataService {
     }
 
     @Override
-    public AppFsUserHealthVo getUserHealthInfoByDeviceId(String deviceId,Date startTime, Date endTime,Long userId) {
+    public AppFsUserHealthVo getUserHealthInfoByDeviceId(String deviceId,Date startTime, Date endTime,Long userId,Integer deviceType) {
         AppFsUserHealthVo vo = new AppFsUserHealthVo();
         // 格式化时间
-        String startDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime);
-        String endDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime);
+        String startDate = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startTime);
+        String endDate = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", endTime);
         CompletableFuture<String>  sleepFuture = null;
         CompletableFuture<Void>  sportFuture = null;
         if (StringUtils.isNotBlank(deviceId)){
             // 异步任务 1:睡眠状态
-            sleepFuture = CompletableFuture.supplyAsync(() ->
-                    sleepDataService.getSleepStatus(startTime, endTime, deviceId)
-            );
-
-
-            // 异步任务 2:运动数据
-            sportFuture = CompletableFuture.runAsync(() -> {
-                List<WatchSportData> list = mapper.getByType(startDate, endDate, deviceId, null);
-                int step = 0;
-                float calorie = 0;
-                if (list != null && !list.isEmpty()) {
-                    for (WatchSportData data : list) {
-                        step += data.getStep() == null ? 0 : data.getStep();
-                        calorie += data.getCalorie() == null ? 0 : data.getCalorie();
+            if (deviceType == null || deviceType == 0){
+                sleepFuture = CompletableFuture.supplyAsync(() ->
+                        sleepDataService.getSleepStatus(startTime, endTime, deviceId)
+                );
+
+
+                // 异步任务 2:运动数据
+                sportFuture = CompletableFuture.runAsync(() -> {
+                    List<WatchSportData> list = mapper.getByType(startDate, endDate, deviceId, null);
+                    int step = 0;
+                    float calorie = 0;
+                    if (list != null && !list.isEmpty()) {
+                        for (WatchSportData data : list) {
+                            step += data.getStep() == null ? 0 : data.getStep();
+                            calorie += data.getCalorie() == null ? 0 : data.getCalorie();
+                        }
                     }
-                }
-                vo.setStep(step);
-                vo.setCalorie((int) calorie);
-            });
+                    vo.setStep(step);
+                    vo.setCalorie((int) calorie);
+                });
+            } else {
+                sleepFuture = CompletableFuture.supplyAsync(() ->
+                        sleepScoreCalculator.getSleepStatus(startTime, endTime, deviceId)
+                );
+
+
+                // 异步任务 2:运动数据
+                sportFuture = CompletableFuture.runAsync(() -> {
+//                    List<WatchSportData> list = mapper.getByType(startDate, endDate, deviceId, null);
+                    WatchSportRecordVo otherData1 = fsThirdDeviceDataMapper.getOtherData(startTime, endTime, deviceId, 5, null);
+                    WatchSportRecordVo otherData2 = fsThirdDeviceDataMapper.getOtherData(startTime, endTime, deviceId, 6, null);
+                    int step = 0;
+                    float calorie = 0;
+                    if (otherData1 != null) {
+                        step += otherData1.getStep() == null ? 0 : Integer.parseInt(otherData1.getStep().toString());
+                        calorie += otherData1.getCalorie() == null ? 0 : otherData1.getCalorie();
+                    }
+                    if (otherData2 != null) {
+                        step += otherData2.getStep() == null ? 0 : Integer.parseInt(otherData2.getStep().toString());
+                        calorie += otherData2.getCalorie() == null ? 0 : otherData2.getCalorie();
+                    }
+                    vo.setStep(step);
+                    vo.setCalorie((int) calorie);
+                });
+            }
+
 
 
         }
@@ -554,6 +694,7 @@ public class WatchSportDataServiceImpl implements WatchSportDataService {
         if(StringUtils.isNotBlank(deviceId)){
             // 等待所有任务完成
             CompletableFuture.allOf(sleepFuture, sportFuture,tongueFuture,surfaceFuture,pulseFuture).join();
+
             try {
                 vo.setSleepStatus(sleepFuture.get());
             } catch (Exception e) {

+ 76 - 17
fs-service/src/main/java/com/fs/watch/service/impl/WatchThirdBpDataServiceImpl.java

@@ -1,7 +1,10 @@
 package com.fs.watch.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.domain.WatchThirdBpData;
 import com.fs.watch.mapper.WatchThirdBpDataMapper;
 import com.fs.watch.service.WatchThirdBpDataService;
@@ -9,10 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
 * @author Administrator
@@ -24,6 +24,8 @@ import java.util.Map;
 public class WatchThirdBpDataServiceImpl implements WatchThirdBpDataService {
     @Autowired
     private WatchThirdBpDataMapper mapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
 
     /**
      * 新增数据
@@ -64,8 +66,32 @@ public class WatchThirdBpDataServiceImpl implements WatchThirdBpDataService {
     }
 
     @Override
-    public List<WatchThirdBpData> queryBpByDate(String startTime, String endTime, String deviceId, Integer status) {
-        return mapper.queryBpByDate(startTime,endTime,deviceId,status);
+    public List<WatchThirdBpData> queryBpByDate(String startTime, String endTime, String deviceId, Integer status,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            return mapper.queryBpByDate(startTime,endTime,deviceId,status);
+        } else {
+            List<WatchThirdBpData> voList = new ArrayList<>();
+            List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",startTime), DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",endTime), deviceId, 0, status);
+
+            if (list != null && !list.isEmpty()) {
+                for (FsThirdDeviceData fsThirdDeviceData : list) {
+                    WatchThirdBpData watchThirdBpData = new WatchThirdBpData();
+                    watchThirdBpData.setDeviceId(fsThirdDeviceData.getDeviceId());
+                    String recordValue = fsThirdDeviceData.getRecordValue();
+                    if (StringUtils.isNotBlank(recordValue)) {
+                        JSONObject jsonObject = JSONObject.parseObject(recordValue);
+                        watchThirdBpData.setSbp(Integer.valueOf(jsonObject.get("sdb").toString()));
+                        watchThirdBpData.setDbp(Integer.valueOf(jsonObject.get("dbp").toString()));
+                        watchThirdBpData.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                        watchThirdBpData.setStatus(fsThirdDeviceData.getStatus());
+                        voList.add(watchThirdBpData);
+                    }
+
+                }
+            }
+            return voList;
+        }
+
     }
 
 
@@ -110,31 +136,64 @@ public class WatchThirdBpDataServiceImpl implements WatchThirdBpDataService {
     }
 
     @Override
-    public List<Map<String, Object>> countBpByDate(Date startTime, Date endTime, String deviceId) {
+    public List<Map<String, Object>> countBpByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
         //返回对象
         List<Map<String, Object>>  res = null;
-        res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),deviceId);
+        if (deviceType == null || deviceType == 0) {
+            res = mapper.countBpByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),deviceId);
+        } else {
+            res = fsThirdDeviceDataMapper.countByDateAndDeviceIdAndRecordType(startTime,endTime,deviceId,0,null);
+        }
+
 
         return res;
     }
 
     @Override
-    public int countBpPageByDate(Date startTime, Date endTime, String deviceId, Integer status) {
-        return mapper.countBpPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                deviceId,status);
+    public int countBpPageByDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType) {
+        if (deviceType == null || deviceType == 0) {
+            return mapper.countBpPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                    deviceId,status);
+        } else {
+            return fsThirdDeviceDataMapper.countPageByDateAndDeviceIdAndRecordType(startTime,endTime,deviceId,0,status);
+        }
+
     }
 
     @Override
-    public List<WatchThirdBpData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size) {
+    public List<WatchThirdBpData> queryBgPageByDate(Date startTime, Date endTime, String deviceId, Integer status, Integer num, Integer size,Integer deviceType) {
         if (StringUtils.isNotBlank(deviceId)) {
-            return mapper.queryBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId,status,num,size);
+            if (deviceType == null || deviceType == 0) {
+                return mapper.queryBgPageByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId,status,num,size);
+            } else {
+                List<WatchThirdBpData> voList = new ArrayList<>();
+                List<FsThirdDeviceData> list = fsThirdDeviceDataMapper.queryPageByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 0, status, num, size);
+                if (list != null && !list.isEmpty()) {
+                    for (FsThirdDeviceData fsThirdDeviceData : list) {
+                        WatchThirdBpData vo = new WatchThirdBpData();
+                        vo.setDeviceId(fsThirdDeviceData.getDeviceId());
+                        String recordValue = fsThirdDeviceData.getRecordValue();
+                        if (StringUtils.isNotBlank(recordValue)) {
+                            JSONObject jsonObject = JSONObject.parseObject(recordValue);
+                            vo.setDbp(Integer.valueOf(jsonObject.get("dbp").toString()));
+                            vo.setSbp(Integer.valueOf(jsonObject.get("sdb").toString()));
+                            vo.setStatus(fsThirdDeviceData.getStatus());
+                            vo.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+
+                        }
+                        voList.add(vo);
+                    }
+                }
+                return voList;
+            }
+
         } else {
             return null;
         }

+ 62 - 13
fs-service/src/main/java/com/fs/watch/service/impl/WatchThirdUaDataServiceImpl.java

@@ -2,6 +2,8 @@ package com.fs.watch.service.impl;
 
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.mapper.FsThirdDeviceDataMapper;
 import com.fs.watch.domain.WatchDeviceInfo;
 import com.fs.watch.domain.WatchFsUser;
 import com.fs.watch.domain.WatchThirdUaData;
@@ -31,6 +33,8 @@ public class WatchThirdUaDataServiceImpl implements WatchThirdUaDataService {
     private WatchUserService userService;
     @Autowired
     private WatchDeviceInfoMapper watchDeviceInfoMapper;
+    @Autowired
+    private FsThirdDeviceDataMapper fsThirdDeviceDataMapper;
 
     @Override
     public Boolean insert(WatchThirdUaData watchThirdUaData) {
@@ -115,38 +119,83 @@ public class WatchThirdUaDataServiceImpl implements WatchThirdUaDataService {
     }
 
     @Override
-    public List<WatchThirdUaData> list(Date startTime, Date endTime, String deviceId) {
-        return mapper.list(startTime, endTime, deviceId);
+    public List<WatchThirdUaData> list(Date startTime, Date endTime, String deviceId,Integer deviceType) {
+        List<WatchThirdUaData> list = new ArrayList<>();
+        if(deviceType==null || deviceType==0){
+            list = mapper.list(startTime, endTime, deviceId);
+        } else {
+            List<FsThirdDeviceData> fsThirdDeviceDataList = fsThirdDeviceDataMapper.selectListByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 3, null);
+            if (fsThirdDeviceDataList != null && !fsThirdDeviceDataList.isEmpty()) {
+                for (FsThirdDeviceData fsThirdDeviceData : fsThirdDeviceDataList) {
+
+                    WatchThirdUaData watchThirdUaData = new WatchThirdUaData();
+                    watchThirdUaData.setDeviceId(fsThirdDeviceData.getDeviceId());
+                    watchThirdUaData.setVal(Integer.valueOf(fsThirdDeviceData.getRecordValue()));
+                    watchThirdUaData.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                    watchThirdUaData.setStatus(fsThirdDeviceData.getStatus());
+                    list.add(watchThirdUaData);
+                }
+            }
+        }
+        return list;
     }
 
     @Override
-    public List<Map<String, Object>> countUaByDate(Date startTime, Date endTime, String deviceId) {
+    public List<Map<String, Object>> countUaByDate(Date startTime, Date endTime, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
         //返回对象
         List<Map<String, Object>> res = null;
-        res = mapper.countUaByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        if (deviceType==null || deviceType==0) {
+            res = mapper.countUaByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), deviceId);
+        } else {
+            res = fsThirdDeviceDataMapper.countByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 3, null);
+
+        }
 
         return res;
     }
 
     @Override
-    public List<WatchThirdUaData> queryListByDate(Date startTime, Date endTime, String deviceId, Integer pageNum, Integer pageSize, Integer status) {
+    public List<WatchThirdUaData> queryListByDate(Date startTime, Date endTime, String deviceId, Integer pageNum, Integer pageSize, Integer status,Integer deviceType) {
         if (StringUtils.isNotBlank(deviceId)) {
-            return mapper.queryListByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                    deviceId, pageNum, pageSize, status);
+            if (deviceType==null || deviceType==0) {
+                return mapper.queryListByDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                        DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                        deviceId, pageNum, pageSize, status);
+            } else {
+                List<WatchThirdUaData> voList = new ArrayList<>();
+                List<FsThirdDeviceData> fsThirdDeviceDataList = fsThirdDeviceDataMapper
+                        .queryPageByDateAndDeviceIdAndRecordType(startTime, endTime, deviceId, 3, status,pageNum,pageSize);
+                if (fsThirdDeviceDataList != null && !fsThirdDeviceDataList.isEmpty()) {
+                    for (FsThirdDeviceData fsThirdDeviceData : fsThirdDeviceDataList) {
+                        WatchThirdUaData watchThirdUaData = new WatchThirdUaData();
+                        watchThirdUaData.setDeviceId(fsThirdDeviceData.getDeviceId());
+                        watchThirdUaData.setVal(Integer.valueOf(fsThirdDeviceData.getRecordValue()));
+                        watchThirdUaData.setCreateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",fsThirdDeviceData.getCreateTime()));
+                        watchThirdUaData.setStatus(fsThirdDeviceData.getStatus());
+                        voList.add(watchThirdUaData);
+                    }
+                }
+                return voList;
+            }
+
         } else {
             return null;
         }
     }
 
     @Override
-    public int countTotalDate(Date startTime, Date endTime, String deviceId, Integer status) {
-        return mapper.countTotalDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
-                DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
-                deviceId, status);
+    public int countTotalDate(Date startTime, Date endTime, String deviceId, Integer status,Integer deviceType) {
+        if (deviceType==null || deviceType==0) {
+            return mapper.countTotalDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
+                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
+                    deviceId, status);
+        } else {
+            return fsThirdDeviceDataMapper.countPageByDateAndDeviceIdAndRecordType(startTime,endTime,deviceId,3,status);
+        }
+
     }
 }

+ 240 - 20
fs-service/src/main/java/com/fs/watch/service/impl/WatchUserServiceImpl.java

@@ -25,10 +25,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.Period;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -192,6 +189,8 @@ public class WatchUserServiceImpl implements WatchUserService {
         watchUser.setTargetStep(watchFsUser.getTargetStep());
         watchUser.setTargetCalorie(watchFsUser.getTargetCalorie());
         watchUser.setDeviceId(watchFsUser.getDeviceId());
+        watchUser.setXhsDeviceId(watchFsUser.getXhsDeviceId());
+        watchUser.setNewXhsDeviceId(watchFsUser.getNewXhsDeviceId());
         watchUser.setOtherDevice(watchFsUser.getOtherDevice());
         watchUser.setMonitorDataTypeOrder(watchFsUser.getMonitorDataTypeOrder());
         watchUser.setCreateTime(watchFsUser.getCreateTime());
@@ -306,17 +305,41 @@ public class WatchUserServiceImpl implements WatchUserService {
             List<DeviceFamily> deviceFamilies = JSON.parseArray(otherDevice, DeviceFamily.class);
             if (deviceFamilies != null && !deviceFamilies.isEmpty()) {
                 for (DeviceFamily deviceFamily : deviceFamilies) {
-                    WatchInfoVo vo = new WatchInfoVo();
-                    BeanUtils.copyProperties(deviceFamily, vo);
-                    //查询设备名字
-                    WatchDeviceData deviceData = watchDeviceDataService.getByDeviceId(deviceFamily.getDeviceId());
-                    if (deviceData != null) {
-                        vo.setBle(deviceData.getBle());
+                    String deviceId = deviceFamily.getDeviceId();
+                    if (StringUtils.isNotBlank(deviceId)) {
+                        WatchInfoVo vo = new WatchInfoVo();
+                        BeanUtils.copyProperties(deviceFamily, vo);
+                        //查询设备名字
+                        WatchDeviceData deviceData = watchDeviceDataService.getByDeviceId(deviceId);
+                        if (deviceData != null) {
+                            vo.setBle(deviceData.getBle());
+                        }
+                        //设备状态
+                        Integer status = deviceInfoService.getStatus(deviceId);
+                        vo.setStatus(status != null ? status : -1);
+                        vo.setDeviceId(deviceId);
+                        res.add(vo);
                     }
-                    //设备状态
-                    Integer status = deviceInfoService.getStatus(deviceFamily.getDeviceId());
-                    vo.setStatus(status != null ? status : -1);
-                    res.add(vo);
+                    String xhsDeviceId = deviceFamily.getXhsDeviceId();
+                    if (StringUtils.isNotBlank(xhsDeviceId)) {
+                        WatchInfoVo vo = new WatchInfoVo();
+                        BeanUtils.copyProperties(deviceFamily, vo);
+                        vo.setDeviceId(xhsDeviceId);
+                        vo.setBle("小护士设备:" + xhsDeviceId);
+                        vo.setStatus(3);
+                        res.add(vo);
+                    }
+
+                    String newXhsDeviceId = deviceFamily.getNewXhsDeviceId();
+                    if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                        WatchInfoVo vo = new WatchInfoVo();
+                        BeanUtils.copyProperties(deviceFamily, vo);
+                        vo.setDeviceId(newXhsDeviceId);
+                        vo.setBle("小护士手表:" + deviceFamily.getNewXhsDeviceId());
+                        vo.setStatus(3);
+                        res.add(vo);
+                    }
+
                 }
             }
             //自己
@@ -329,7 +352,7 @@ public class WatchUserServiceImpl implements WatchUserService {
                         vo.setName("自己");
                         vo.setRelationship("自己");
 
-                        vo.setDeviceId(deviceId);
+                        vo.setDeviceId(deId);
                         WatchDeviceData deviceData = watchDeviceDataService.getByDeviceId(deId);
                         if (deviceData != null) {
                             vo.setBle(deviceData.getBle());
@@ -340,14 +363,47 @@ public class WatchUserServiceImpl implements WatchUserService {
                         res.add(vo);
                     }
                 }
-            } else {
+            }
+            String xhsDeviceId = user.getXhsDeviceId();
+            if (StringUtils.isNotBlank(xhsDeviceId)) {
+                List<String> xhsDeviceIdList = Arrays.asList(xhsDeviceId.split(","));
+                if (!xhsDeviceIdList.isEmpty()) {
+                    for (String deId : xhsDeviceIdList) {
+                        WatchInfoVo vo = new WatchInfoVo();
+                        vo.setName("自己");
+                        vo.setRelationship("自己");
+
+                        vo.setDeviceId(deId);
+                        vo.setBle("小护士设备:" + deId);
+                        vo.setStatus(3);
+                        res.add(vo);
+                    }
+                }
+            }
+
+            String newXhsDeviceId = user.getNewXhsDeviceId();
+            if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                List<String> newXhsDeviceIdList = Arrays.asList(newXhsDeviceId.split(","));
+                if (!newXhsDeviceIdList.isEmpty()) {
+                    for (String deId : newXhsDeviceIdList) {
+                        WatchInfoVo vo = new WatchInfoVo();
+                        vo.setName("自己");
+                        vo.setRelationship("自己");
+
+                        vo.setDeviceId(deId);
+                        vo.setBle("小护士手表:" + deId);
+                        vo.setStatus(3);
+                        res.add(vo);
+                    }
+                }
+            }
+            if (res.isEmpty()) {
                 WatchInfoVo vo = new WatchInfoVo();
                 vo.setName("自己");
                 vo.setRelationship("自己");
                 //设备状态
                 res.add(vo);
             }
-
         }
         return res;
     }
@@ -362,12 +418,168 @@ public class WatchUserServiceImpl implements WatchUserService {
         return watchUserMapper.getLastTongueByDeviceId(deviceId);
     }
 
+    @Override
+    public R editXHSDevice(HashMap<String, String> param) {
+        String userId = param.get("userId");
+        String xhsDeviceId = param.get("xhsDeviceId");
+        String newXhsDeviceId = param.get("newXhsDeviceId");
+        //查询设备是否已经绑定自己
+        long userIdL = Long.parseLong(userId);
+        //1.编辑绑定设备 ,更新用户表
+        WatchFsUser watchFsUser = selectWatchFsUserById(userIdL);
+        if (watchFsUser == null) {
+            WatchUser watchUser = new WatchUser();
+            watchUser.setUserId(userIdL);
+            if (StringUtils.isNotBlank(xhsDeviceId)) {
+                watchUser.setXhsDeviceId(xhsDeviceId);
+            }
+            if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                watchUser.setNewXhsDeviceId(newXhsDeviceId);
+            }
+            insert(watchUser);
+        } else {
+            if (StringUtils.isNotBlank(xhsDeviceId)) {
+                String deviceId = watchFsUser.getXhsDeviceId();
+                if (StringUtils.isBlank(deviceId)) {
+                    watchFsUser.setXhsDeviceId(xhsDeviceId);
+                } else {
+                    watchFsUser.setXhsDeviceId(deviceId + "," + xhsDeviceId);
+                }
+            }
+            if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                String deviceId = watchFsUser.getNewXhsDeviceId();
+                if (StringUtils.isBlank(deviceId)) {
+                    watchFsUser.setNewXhsDeviceId(newXhsDeviceId);
+                } else {
+                    watchFsUser.setNewXhsDeviceId(deviceId + "," + newXhsDeviceId);
+                }
+            }
+
+            WatchUser watchUser = setWatchUser(watchFsUser);
+            //查询是否含有腕表用户信息
+            updateWatchUser(watchUser);
+        }
+
+
+        //3.添加设备设置信息
+        if (StringUtils.isNotBlank(xhsDeviceId)) {
+            WatchDeviceSetup temp = deviceSetupService.selectDeviceSetupByDeviceId(xhsDeviceId);
+            if (temp == null) {
+                WatchDeviceSetup deviceSetup = new WatchDeviceSetup();
+                deviceSetup.setDeviceId(xhsDeviceId);
+                deviceSetup.setSmartDoctor(0);
+                deviceSetup.setSedentary(JSONUtil.toJsonStr(new DeviceSedentary()));
+                deviceSetup.setFallcheck(0);
+                deviceSetup.setHeartHealth(0);
+                deviceSetup.setHralarm(JSONUtil.toJsonStr(new DeviceHralarm()));
+                deviceSetup.setSpo2alarm(JSONUtil.toJsonStr(new DeviceSpo2alarm()));
+                deviceSetup.setAlarmClock(JSONUtil.toJsonStr(new DeviceAlarmClock()));
+                deviceSetup.setPower(JSONUtil.toJsonStr(new DevicePower()));
+                deviceSetup.setPhonebook(JSONUtil.toJsonStr(new DevicePhonebooks()));
+                deviceSetup.setTime(JSONUtil.toJsonStr(new DeviceTime()));
+                deviceSetup.setLcdgesture(JSONUtil.toJsonStr(new DeviceLcdgesture()));
+                deviceSetup.setUnit(JSONUtil.toJsonStr(new DeviceUnit()));
+                deviceSetup.setMode(JSONUtil.toJsonStr(new DeviceMode()));
+                deviceSetup.setVersion("1.1.0");
+                deviceSetupService.insertDeviceSetup(deviceSetup);
+            }
+        }
+
+        if (StringUtils.isNotBlank(newXhsDeviceId)) {
+            WatchDeviceSetup temp = deviceSetupService.selectDeviceSetupByDeviceId(newXhsDeviceId);
+            if (temp == null) {
+                WatchDeviceSetup deviceSetup = new WatchDeviceSetup();
+                deviceSetup.setDeviceId(newXhsDeviceId);
+                deviceSetup.setSmartDoctor(0);
+                deviceSetup.setSedentary(JSONUtil.toJsonStr(new DeviceSedentary()));
+                deviceSetup.setFallcheck(0);
+                deviceSetup.setHeartHealth(0);
+                deviceSetup.setHralarm(JSONUtil.toJsonStr(new DeviceHralarm()));
+                deviceSetup.setSpo2alarm(JSONUtil.toJsonStr(new DeviceSpo2alarm()));
+                deviceSetup.setAlarmClock(JSONUtil.toJsonStr(new DeviceAlarmClock()));
+                deviceSetup.setPower(JSONUtil.toJsonStr(new DevicePower()));
+                deviceSetup.setPhonebook(JSONUtil.toJsonStr(new DevicePhonebooks()));
+                deviceSetup.setTime(JSONUtil.toJsonStr(new DeviceTime()));
+                deviceSetup.setLcdgesture(JSONUtil.toJsonStr(new DeviceLcdgesture()));
+                deviceSetup.setUnit(JSONUtil.toJsonStr(new DeviceUnit()));
+                deviceSetup.setMode(JSONUtil.toJsonStr(new DeviceMode()));
+                deviceSetup.setVersion("1.1.0");
+                deviceSetupService.insertDeviceSetup(deviceSetup);
+            }
+        }
+        return R.ok("绑定成功!");
+    }
+
+    @Override
+    public R removeXHSDevice(String userId, String xhsDeviceId,String newXhsDeviceId) {
+        //1.编辑绑定设备 ,更新用户表
+        if (StringUtils.isNotBlank(xhsDeviceId) || StringUtils.isNotBlank(newXhsDeviceId)) {
+            Long userIdL = Long.valueOf(userId);
+            //1.1判断该设备是否已经绑定
+            WatchFsUser user = null;
+            if (StringUtils.isNotBlank(xhsDeviceId)) {
+                user = selectWatchFsUserByDeviceIdAndUserId(xhsDeviceId, userIdL, 2);
+            } else if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                user = selectWatchFsUserByDeviceIdAndUserId(newXhsDeviceId, userIdL, 4);
+            }
+
+            if (user == null) {
+                return R.error("该用户未绑定设备:"+xhsDeviceId);
+            }
+            //1.2 解除绑定设备
+            //查询是否有该设备
+            if (StringUtils.isNotBlank(xhsDeviceId)) {
+                String deviceIds = user.getXhsDeviceId();
+
+                List<String> list = Arrays.asList(deviceIds.split(","));
+                if (!list.isEmpty()) {
+                    if (list.contains(xhsDeviceId)) {
+                        list = list.stream().filter(s -> !(xhsDeviceId.equals(s))).collect(Collectors.toList());
+                        StringBuilder newDeviceIds = new StringBuilder();
+                        for (int i = 0; i < list.size(); i++) {
+                            if (i == 0) {
+                                newDeviceIds.append(list.get(i));
+                            } else {
+                                newDeviceIds.append(",").append(list.get(i));
+                            }
+                        }
+                        user.setXhsDeviceId(newDeviceIds.toString());
+                    }
+                }
+            } else if (StringUtils.isNotBlank(newXhsDeviceId)) {
+                String deviceIds = user.getNewXhsDeviceId();
+
+                List<String> list = Arrays.asList(deviceIds.split(","));
+                if (!list.isEmpty()) {
+                    if (list.contains(newXhsDeviceId)) {
+                        list = list.stream().filter(s -> !(newXhsDeviceId.equals(s))).collect(Collectors.toList());
+                        StringBuilder newDeviceIds = new StringBuilder();
+                        for (int i = 0; i < list.size(); i++) {
+                            if (i == 0) {
+                                newDeviceIds.append(list.get(i));
+                            } else {
+                                newDeviceIds.append(",").append(list.get(i));
+                            }
+                        }
+                        user.setNewXhsDeviceId(newDeviceIds.toString());
+                    }
+                }
+            }
+            WatchUser watchUser = new WatchUser();
+            BeanUtils.copyProperties(user, watchUser);
+            updateWatchUser(watchUser);
+            return R.ok("解绑成功!");
+        } else {
+            return R.error("无解绑设备,解绑失败!");
+        }
+    }
+
     /**
      * 查询腕表用户信息
      *
      * @param deviceId
      * @param userId
-     * @param type     0:user 1:familyUser
+     * @param type     0:user 1:familyUser 2:xshUser 3:xhsFamilyUser  4:newXshUser 5:newXhsFamilyUser
      * @return
      */
     @Override
@@ -391,7 +603,7 @@ public class WatchUserServiceImpl implements WatchUserService {
     }
 
     @Override
-    public AppFsUserVo getUserInfoByDeviceId(String deviceId, Boolean isFamily, Long watchUserId) {
+    public AppFsUserVo getUserInfoByDeviceId(String deviceId, Boolean isFamily, Long watchUserId,Integer deviceType) {
         AppFsUserVo appFsUserVo = new AppFsUserVo();
         if (StringUtils.isBlank(deviceId)) {
             //查询原有用户信息
@@ -409,7 +621,15 @@ public class WatchUserServiceImpl implements WatchUserService {
                 }
             } else {
                 //根据设备id获取用户信息
-                WatchFsUser user = selectWatchFsUserByDeviceIdAndUserId(deviceId, watchUserId, 0);
+                WatchFsUser user = null;
+                if (deviceType == null || deviceType == 0) {
+                    user = selectWatchFsUserByDeviceIdAndUserId(deviceId, watchUserId, 0);
+                } else if (deviceType == 1) {
+                    user = selectWatchFsUserByDeviceIdAndUserId(deviceId, watchUserId, 2);
+                } else if (deviceType == 2) {
+                    user = selectWatchFsUserByDeviceIdAndUserId(deviceId, watchUserId, 4);
+                }
+
                 if (user != null) {
                     BeanUtils.copyProperties(user, appFsUserVo);
                     if (user.getBirthday() != null) {

+ 1 - 2
fs-service/src/main/java/com/fs/watch/utils/MyDateTimeUtils.java

@@ -1,15 +1,14 @@
 package com.fs.watch.utils;
 
 
-
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.time.Duration;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.TimeZone;
-import java.time.ZoneId;
 
 public class MyDateTimeUtils {
 

+ 12 - 10
fs-service/src/main/resources/application-dev.yml

@@ -27,16 +27,18 @@ spring:
                 # #连接池最大阻塞等待时间(使用负值表示没有限制)
                 max-wait: -1ms
     datasource:
-#        clickhouse:
-#            type: com.alibaba.druid.pool.DruidDataSource
-#            driverClassName: com.clickhouse.jdbc.ClickHouseDriver
-#            url: jdbc:clickhouse://1.14.104.71:8123/sop_test?compress=0&use_server_time_zone=true&use_client_time_zone=false&timezone=Asia/Shanghai
-#            username: default
-#            password: rt2024
-#            initialSize: 10
-#            maxActive: 100
-#            minIdle: 10
-#            maxWait: 6000
+        clickhouse:
+            type: com.alibaba.druid.pool.DruidDataSource
+            driverClassName: ru.yandex.clickhouse.ClickHouseDriver
+            #            url: jdbc:clickhouse://114.117.201.250:8123/watch
+            #            url: jdbc:clickhouse://cc-2vc8zzo26w0l7m2l6.public.clickhouse.ads.aliyuncs.com:8123/watch
+            url: jdbc:clickhouse://1.14.104.71:8123/watch?compress=0&use_server_time_zone=true&use_client_time_zone=false&timezone=Asia/Shanghai
+            username: default
+            password: rt2024
+            initialSize: 10
+            maxActive: 100
+            minIdle: 10
+            maxWait: 6000
         mysql:
             type: com.alibaba.druid.pool.DruidDataSource
             driverClassName: com.mysql.cj.jdbc.Driver

+ 315 - 0
fs-service/src/main/resources/mapper/his/FsThirdDeviceDataMapper.xml

@@ -0,0 +1,315 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.his.mapper.FsThirdDeviceDataMapper">
+    
+    <resultMap type="FsThirdDeviceData" id="FsThirdDeviceDataResult">
+        <result property="id"    column="id"    />
+        <result property="userId"    column="user_id"    />
+        <result property="recordType"    column="record_type"    />
+        <result property="recordValue"    column="record_value"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="deviceId"    column="device_id"    />
+        <result property="deviceType"    column="device_type"    />
+        <result property="status"    column="status"    />
+    </resultMap>
+
+    <sql id="selectFsThirdDeviceDataVo">
+        select id, user_id, record_type, record_value, create_time,device_id,device_type,`status` from fs_third_device_data
+    </sql>
+
+    <select id="selectFsThirdDeviceDataList" parameterType="FsThirdDeviceData" resultMap="FsThirdDeviceDataResult">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        <where>  
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="recordType != null "> and record_type = #{recordType}</if>
+            <if test="recordValue != null  and recordValue != ''"> and record_value = #{recordValue}</if>
+            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
+            <if test="deviceType != null  and deviceType != ''"> and device_type = #{deviceType}</if>
+            <if test="status != null  "> and `status` = #{status}</if>
+        </where>
+    </select>
+    
+    <select id="selectFsThirdDeviceDataById" parameterType="Long" resultMap="FsThirdDeviceDataResult">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where id = #{id}
+    </select>
+    <select id="getLastData" resultType="com.fs.his.domain.FsThirdDeviceData">
+        SELECT record_type,
+               record_value,
+               create_time,
+               device_id,
+               device_type
+        FROM (
+                 SELECT *,
+                        ROW_NUMBER() OVER (PARTITION BY record_type ORDER BY create_time DESC) as rn
+                 FROM fs_third_device_data
+                 WHERE user_id = #{userId} AND device_type = #{deviceType} AND device_id = #{deviceId}
+             ) t
+        WHERE rn = 1
+        ORDER BY record_type;
+    </select>
+    <select id="countMaxAndMinBpByDate" resultType="java.util.Map">
+        SELECT
+            MAX(JSON_UNQUOTE(JSON_EXTRACT(record_value, '$.sdb'))) AS `max`,
+            MIN(JSON_UNQUOTE(JSON_EXTRACT(record_value, '$.dbp'))) AS `min`
+        FROM
+            fs_third_device_data
+        WHERE
+            device_id = #{deviceId}
+          AND record_type = 0  -- 只查询血压记录
+          AND create_time BETWEEN #{startTime} AND #{endTime}
+        GROUP BY
+            device_id;
+    </select>
+    <select id="queryBgByDate" resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        WHERE  record_type = 1 AND
+        device_id = #{deviceId}
+        AND create_time BETWEEN #{startTime} AND #{endTime}
+        ORDER BY
+        create_time ASC
+    </select>
+    <select id="countMaxAndAvgBpByDate" resultType="java.util.Map">
+        SELECT
+            MAX(record_value) AS maxBpm,
+            AVG(record_value) AS avgBpm
+        FROM
+            fs_third_device_data
+        WHERE
+            record_type = 2
+          AND device_id = #{deviceId} AND
+            create_time BETWEEN #{startTime} AND #{endTime}
+        GROUP BY
+            device_id
+    </select>
+    <select id="getFirstDataByDeviceId" resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where device_id = #{deviceId} order by create_time asc limit 1
+    </select>
+    <select id="queryByMonth" resultType="com.fs.his.domain.FsThirdDeviceData">
+        SELECT *
+        FROM fs_third_device_data
+        WHERE device_id like #{deviceId} and toYYYYMM(create_time) = #{monthStr} and record_type = #{recordType}
+    </select>
+    <select id="getLatest" resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where device_id = #{deviceId} and record_type = #{recordType} order by create_time desc limit 1
+    </select>
+    <select id="selectListByDateAndDeviceIdAndRecordType" resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where
+        device_id = #{deviceId}
+        and record_type = #{recordType}
+        <if test="startTime != null">
+            and create_time >= #{startTime}
+        </if>
+
+        <if test="endTime != null">
+            and create_time &lt;= #{endTime}
+        </if>
+
+        <if test="status != null">
+            AND record_value->>'$.sportType' = #{status}
+        </if>
+        order by create_time asc
+    </select>
+    <select id="countByDateAndDeviceIdAndRecordType" resultType="java.util.Map">
+        select `status`,
+               COUNT(*) AS `count` from fs_third_device_data where device_id = #{deviceId}
+                                             and record_type = #{recordType}
+                                             and create_time >= #{startTime}
+                                             and create_time &lt;= #{endTime}
+                                                             <if test="status != null">
+                                                                 and `status` = #{status}
+                                                             </if>
+        group by `status`
+
+    </select>
+    <select id="countPageByDateAndDeviceIdAndRecordType" resultType="java.lang.Integer">
+        select count(*) from fs_third_device_data
+                        where
+        device_id = #{deviceId}
+        and record_type = #{recordType}
+        and create_time >= #{startTime}
+        and create_time &lt;= #{endTime}
+        <if test="status != null">
+            and `status` = #{status}
+        </if>
+
+    </select>
+    <select id="queryPageByDateAndDeviceIdAndRecordType" resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where
+        device_id = #{deviceId}
+        and record_type = #{recordType}
+        and create_time >= #{startTime}
+        and create_time &lt;= #{endTime}
+        <if test="status != null">
+            and `status` = #{status}
+        </if>
+        order by create_time asc LIMIT #{num},#{size}
+    </select>
+    <select id="countAvgBpByDate" resultType="java.lang.Float">
+        SELECT
+            AVG(CAST(record_value AS DECIMAL(10,2))) AS avg_value
+        FROM
+            fs_third_device_data
+        WHERE
+            create_time BETWEEN #{startTime} AND #{endTime}
+          AND device_id = #{deviceId}
+          AND record_type = 4
+        GROUP BY
+            device_id
+    </select>
+    <select id="getOtherData" resultType="com.fs.watch.domain.vo.WatchSportRecordVo">
+        SELECT
+        COUNT(*) AS `count`,
+        SUM(COALESCE(CAST(record_value->>'$.distance' AS DECIMAL(10, 2)), 0)) AS distance,
+        ROUND(SUM(COALESCE(CAST(record_value->>'$.duration' AS DECIMAL(10, 2)), 0)) / 3600, 2) AS `time`,
+        SUM(COALESCE(CAST(record_value->>'$.steps' AS SIGNED), 0)) AS `step`,
+        SUM(COALESCE(CAST(record_value->>'$.calories' AS DECIMAL(10, 2)), 0)) AS calorie
+        FROM `fs_third_device_data`
+        WHERE
+        device_id = #{deviceId}
+        AND record_type = #{recordType}
+        <if test="startTime != null">
+            AND create_time >= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND create_time &lt;= #{endTime}
+        </if>
+        <if test="status != null">
+            AND record_value->>'$.sportType' = #{status}
+        </if>
+    </select>
+    <select id="queryActivityRecord" resultType="com.fs.watch.domain.vo.WatchSportRecordVo">
+        SELECT
+        record_value->>'$.sportType' AS `type`,
+        COUNT(*) AS `count`,
+        SUM(COALESCE(CAST(record_value->>'$.distance' AS DECIMAL(10, 2)), 0)) AS distance
+        FROM `fs_third_device_data`
+        WHERE
+        device_id = #{deviceId}
+        AND record_type = #{recordType}
+        <if test="startTime != null">
+            AND create_time >= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND create_time &lt;= #{endTime}
+        </if>
+        <if test="status != null">
+            AND `status` = #{status}
+        </if>
+        GROUP BY record_value->>'$.sportType'
+        ORDER BY `type`
+    </select>
+    <select id="getOtherDataOther" resultType="com.fs.watch.domain.vo.WatchSportRecordVo">
+        SELECT
+        COUNT(*) AS `count`,
+        SUM(COALESCE(CAST(record_value->>'$.distance' AS DECIMAL(10, 2)), 0)) AS distance,
+        ROUND(SUM(COALESCE(CAST(record_value->>'$.duration' AS DECIMAL(10, 2)), 0)) / 3600, 2) AS `time`,
+        SUM(COALESCE(CAST(record_value->>'$.steps' AS SIGNED), 0)) AS `step`,
+        SUM(COALESCE(CAST(record_value->>'$.calories' AS DECIMAL(10, 2)), 0)) AS calorie
+        FROM `fs_third_device_data`
+        WHERE
+        device_id = #{deviceId}
+        AND record_type = #{recordType}
+        <if test="startTime != null">
+            AND create_time >= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND create_time &lt;= #{endTime}
+        </if>
+
+            AND record_value->>'$.sportType' not in (25,17,1,9,21,5,13)
+
+    </select>
+    <select id="selectListByDateAndDeviceIdAndRecordTypeOther"
+            resultType="com.fs.his.domain.FsThirdDeviceData">
+        <include refid="selectFsThirdDeviceDataVo"/>
+        where
+        device_id = #{deviceId}
+        and record_type = #{recordType}
+        <if test="startTime != null">
+            and create_time >= #{startTime}
+        </if>
+
+        <if test="endTime != null">
+            and create_time &lt;= #{endTime}
+        </if>
+        AND record_value->>'$.sportType' not in (25,17,1,9,21,5,13)
+        order by create_time asc
+    </select>
+
+
+    <insert id="insertFsThirdDeviceData" parameterType="FsThirdDeviceData" useGeneratedKeys="true" keyProperty="id">
+        insert into fs_third_device_data
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="userId != null">user_id,</if>
+            <if test="recordType != null">record_type,</if>
+            <if test="recordValue != null and recordValue != ''">record_value,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="deviceId != null">device_id,</if>
+            <if test="deviceType != null">device_type,</if>
+            <if test="status != null">`status`,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="userId != null">#{userId},</if>
+            <if test="recordType != null">#{recordType},</if>
+            <if test="recordValue != null and recordValue != ''">#{recordValue},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="deviceId != null">#{deviceId},</if>
+            <if test="deviceType != null">#{deviceType},</if>
+            <if test="status != null">#{status},</if>
+         </trim>
+    </insert>
+    <insert id="insertFsThirdDeviceDataList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO fs_third_device_data (
+        user_id,
+        record_type,
+        record_value,
+        create_time,
+        device_id,
+        device_type,
+        `status`
+        ) VALUES
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.userId},
+            #{item.recordType},
+            #{item.recordValue},
+            #{item.createTime},
+            #{item.deviceId},
+            #{item.deviceType},
+            #{item.status}
+            )
+        </foreach>
+    </insert>
+
+    <update id="updateFsThirdDeviceData" parameterType="FsThirdDeviceData">
+        update fs_third_device_data
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="userId != null">user_id = #{userId},</if>
+            <if test="recordType != null">record_type = #{recordType},</if>
+            <if test="recordValue != null and recordValue != ''">record_value = #{recordValue},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="deviceId != null">device_id = #{deviceId},</if>
+            <if test="deviceType != null">device_type = #{deviceType},</if>
+            <if test="status != null">`status` = #{status},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteFsThirdDeviceDataById" parameterType="Long">
+        delete from fs_third_device_data where id = #{id}
+    </delete>
+
+    <delete id="deleteFsThirdDeviceDataByIds" parameterType="String">
+        delete from fs_third_device_data where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>

+ 4 - 0
fs-service/src/main/resources/mapper/watch/WatchAlarmDataMapper.xml

@@ -149,6 +149,10 @@
         WHERE device_id
         like #{deviceId}
     </update>
+    <update id="setLocation">
+        ALTER TABLE watch.watch_alarm_data UPDATE location = #{data.location}
+            WHERE id = #{data.id}
+    </update>
 
     <!-- 分页查询 -->
     <select id="queryPageByStatus" resultMap="BaseResultMap">

+ 74 - 0
fs-service/src/main/resources/mapper/watch/WatchAudioLogMsgMapper.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.watch.mapper.WatchAudioMsgLogMapper">
+
+    <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchAudioMsgLog">
+        <result property="id" column="id" jdbcType="OTHER" typeHandler="com.fs.watch.handler.UUIDTypeHandler"/>
+        <result property="deviceId" column="device_id" jdbcType="VARCHAR"/>
+        <result property="fileUrl" column="file_url" jdbcType="VARCHAR"/>
+        <result property="type" column="type" jdbcType="INTEGER"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="msg" column="msg" jdbcType="VARCHAR"/>
+        <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id, device_id, file_url, `type`,`status`, msg, create_time
+    </sql>
+
+    <!-- 单条插入 -->
+    <insert id="insert" parameterType="com.fs.watch.domain.WatchAudioMsgLog" useGeneratedKeys="false">
+        INSERT INTO watch.watch_audio_msg_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="data.id != null">
+                id,
+            </if>
+            <if test="data.deviceId != null">
+                device_id,
+            </if>
+            <if test="data.fileUrl != null">
+                file_url,
+            </if>
+            <if test="data.type != null">
+                `type`,
+            </if>
+            <if test="data.status != null">
+                `status`,
+            </if>
+            <if test="data.msg != null">
+                msg,
+            </if>
+            <if test="data.createTime != null">
+                create_time,
+            </if>
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            <if test="data.id != null">
+                #{data.id, typeHandler=com.fs.watch.handler.UUIDTypeHandler},
+            </if>
+            <if test="data.deviceId != null">
+                #{data.deviceId},
+            </if>
+            <if test="data.fileUrl != null">
+                #{data.fileUrl},
+            </if>
+            <if test="data.type != null">
+                #{data.type},
+            </if>
+            <if test="data.status != null">
+                #{data.status},
+            </if>
+            <if test="data.msg != null">
+                #{data.msg},
+            </if>
+            <if test="data.createTime != null">
+                #{data.createTime},
+            </if>
+        </trim>
+    </insert>
+
+
+
+</mapper>

+ 14 - 0
fs-service/src/main/resources/mapper/watch/WatchBloodPressureDataMapper.xml

@@ -107,6 +107,20 @@
             status
     </select>
 
+    <select id="countMaxAndMinBpByDate" resultType="java.util.Map">
+        SELECT
+            max(sbp) as `max`,
+            min(dbp) as `min`
+        FROM
+            watch_blood_pressure_data
+        WHERE
+           device_id = #{deviceId} AND
+            create_time BETWEEN #{startTime} AND #{endTime}
+
+        GROUP BY
+            device_id
+    </select>
+
     <select id="getLatest" resultMap="BaseResultMap">
         SELECT
         <include refid="Base_Column_List"/>

+ 1 - 0
fs-service/src/main/resources/mapper/watch/WatchDeviceDayMapper.xml

@@ -51,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND device_id = #{deviceId}
         GROUP BY
             sleep_status
+        HAVING `status` IS NOT NULL
     </select>
 
     <insert id="insertWatchDeviceDay" parameterType="WatchDeviceDay" useGeneratedKeys="true" keyProperty="id">

+ 4 - 6
fs-service/src/main/resources/mapper/watch/WatchDeviceInfoClicMapper.xml

@@ -179,13 +179,11 @@
 
     <select id="selectListByIccList" resultType="com.fs.watch.domain.WatchDeviceInfoClic">
         select * from watch.watch_device_info where
-        sim1_iccid
+            sim1_iccid
         in
-        <foreach item="item" collection="iccidList"  separator="," open="(" close=")" >
-            #{item}
-        </foreach>
+         <foreach item="item" collection="iccidList"  separator="," open="(" close=")" >
+           #{item}
+         </foreach>
     </select>
-
-
 </mapper>
 

+ 35 - 0
fs-service/src/main/resources/mapper/watch/WatchDeviceInfoMapper.xml

@@ -289,4 +289,39 @@
         where i.is_del = 0 and
               (f.family_user_id = #{userId} or i.user_id = #{userId} )
     </select>
+    <select id="selectByUserId" resultType="com.fs.watch.domain.WatchDeviceInfo">
+        select a.*
+        from `watch_device_info` a
+        where user_id = #{userId}
+    </select>
+
+    <select id="selectCompanyNameByList" resultType="com.fs.watch.domain.vo.WatchDeviceInfoVo">
+        SELECT a.*,IF(a.`status`=0,"OFFLINE",IF(a.`status` = 1,"ONLINE",IF(a.`status` = 3,"UNACTIVE",IF(a.`status` = 4,"DISABLE","NOT EXIST")))) as status_out,
+        IF(a.`life_status`=0,"空置",IF(a.`life_status` = 1,"已送出","已激活")) as  lifeStatusOut,
+        GROUP_CONCAT(DISTINCT c.company_name) AS company_name,
+        GROUP_CONCAT(DISTINCT cu.nick_name) AS company_user_name,
+        GROUP_CONCAT(DISTINCT fd.doctor_name) AS doctor_name,
+        GROUP_CONCAT(DISTINCT fu2.nick_name) AS family_user_name,
+        GROUP_CONCAT(DISTINCT c.company_id) AS company_id,
+        GROUP_CONCAT(DISTINCT cu.user_id) AS company_user_id,
+        GROUP_CONCAT(DISTINCT fd.doctor_id) AS doctor_id,
+        GROUP_CONCAT(DISTINCT fu2.user_id) AS family_user_id
+        FROM `watch_device_info` a
+        LEFT JOIN watch_company wc ON wc.device_id = a.device_id
+        LEFT JOIN watch_company_user wcu ON wcu.device_id = a.device_id
+        LEFT JOIN watch_doctor wd ON wd.device_id = a.device_id
+        LEFT JOIN watch_family wf ON wf.device_id = a.device_id
+        LEFT JOIN fs_user fu ON fu.user_id = a.user_id
+        LEFT JOIN company c ON c.company_id = wc.company_id
+        LEFT JOIN fs_doctor fd ON fd.doctor_id = wd.doctor_id
+        LEFT JOIN company_user cu ON cu.user_id = wcu.company_user_id
+        LEFT JOIN fs_user fu2 ON fu2.user_id =  wf.family_user_id
+        where
+            a.device_number in
+            <foreach item="item" index="index" collection="deviceIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+            and a.is_del = 0
+        GROUP BY a.device_id
+    </select>
 </mapper>

+ 107 - 0
fs-service/src/main/resources/mapper/watch/WatchDeviceWeekMapper.xml

@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.watch.mapper.WatchDeviceWeekMapper">
+
+    <resultMap type="WatchDeviceWeek" id="WatchDeviceWeekResult">
+        <result property="id"    column="id"    />
+        <result property="deviceId"    column="device_id"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="listJson"    column="list_json"    />
+        <result property="title"    column="title"    />
+        <result property="desc"    column="desc"    />
+        <result property="score"    column="score"    />
+        <result property="aiSuggestion"    column="ai_suggestion"    />
+        <result property="userId"    column="user_id"    />
+
+    </resultMap>
+
+    <sql id="selectWatchDeviceWeekVo">
+        select id, device_id, create_time, list_json, title, `desc`, score, ai_suggestion,user_id from watch_device_week
+    </sql>
+
+    <select id="selectWatchDeviceWeekList" parameterType="WatchDeviceWeek" resultMap="WatchDeviceWeekResult">
+        <include refid="selectWatchDeviceWeekVo"/>
+        <where>
+            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
+            <if test="listJson != null  and listJson != ''"> and list_json = #{listJson}</if>
+            <if test="title != null  and title != ''"> and title = #{title}</if>
+            <if test="desc != null  and desc != ''"> and desc = #{desc}</if>
+            <if test="score != null "> and score = #{score}</if>
+            <if test="aiSuggestion != null  and aiSuggestion != ''"> and ai_suggestion = #{aiSuggestion}</if>
+            <if test="createTime != null "> and create_time = #{createTime}</if>
+            <if test="userId != null "> and user_id = #{userId}</if>
+
+        </where>
+    </select>
+
+    <select id="selectWatchDeviceWeekById" parameterType="Long" resultMap="WatchDeviceWeekResult">
+        <include refid="selectWatchDeviceWeekVo"/>
+        where id = #{id}
+    </select>
+
+    <select id="getByDeviceIdAndTime" resultType="com.fs.watch.domain.WatchDeviceWeek">
+        <include refid="selectWatchDeviceWeekVo"/>
+         where device_id like #{deviceId} and create_time = #{createTime}
+    </select>
+
+    <select id="getByUserIdAndTime" resultType="com.fs.watch.domain.WatchDeviceWeek">
+        <include refid="selectWatchDeviceWeekVo"/>
+        where user_id = #{userId} and create_time = #{createTime} and device_id like #{userId}
+         order by id desc limit 1
+    </select>
+
+    <insert id="insertWatchDeviceWeek" parameterType="WatchDeviceWeek" useGeneratedKeys="true" keyProperty="id">
+        insert into watch_device_week
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="deviceId != null and deviceId != ''">device_id,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="listJson != null">list_json,</if>
+            <if test="title != null">title,</if>
+            <if test="desc != null">`desc`,</if>
+            <if test="score != null">score,</if>
+            <if test="aiSuggestion != null">ai_suggestion,</if>
+            <if test="userId != null">user_id,</if>
+
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="listJson != null">#{listJson},</if>
+            <if test="title != null">#{title},</if>
+            <if test="desc != null">#{desc},</if>
+            <if test="score != null">#{score},</if>
+            <if test="aiSuggestion != null">#{aiSuggestion},</if>
+            <if test="userId != null">#{userId},</if>
+
+         </trim>
+    </insert>
+
+    <update id="updateWatchDeviceWeek" parameterType="WatchDeviceWeek">
+        update watch_device_week
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="listJson != null">list_json = #{listJson},</if>
+            <if test="title != null">title = #{title},</if>
+            <if test="desc != null">`desc` = #{desc},</if>
+            <if test="score != null">score = #{score},</if>
+            <if test="aiSuggestion != null">ai_suggestion = #{aiSuggestion},</if>
+            <if test="userId != null">user_id = #{userId},</if>
+
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteWatchDeviceWeekById" parameterType="Long">
+        delete from watch_device_week where id = #{id}
+    </delete>
+
+    <delete id="deleteWatchDeviceWeekByIds" parameterType="String">
+        delete from watch_device_week where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>

+ 3 - 0
fs-service/src/main/resources/mapper/watch/WatchDoctorMapper.xml

@@ -26,6 +26,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectWatchDoctorVo"/>
         where id = #{id}
     </select>
+    <select id="selectDoctorByDeviceId" resultType="com.fs.watch.domain.WatchDoctor">
+        select * from watch_doctor where device_id = #{deviceId} LIMIT 1
+    </select>
 
     <insert id="insertWatchDoctor" parameterType="WatchDoctor">
         insert into watch_doctor

+ 12 - 0
fs-service/src/main/resources/mapper/watch/WatchHeartRateDataMapper.xml

@@ -155,4 +155,16 @@
         FROM watch.watch_heart_rate_data
         WHERE device_id like #{deviceId} and toYYYYMM(create_time) = #{monthStr}
     </select>
+    <select id="countMaxAndAvgBpByDate" resultType="java.util.Map">
+        SELECT
+            MAX(max_bpm) AS maxBpm,
+            AVG(avg_bpm) AS avgBpm
+        FROM
+            watch_heart_rate_data
+        WHERE
+            create_time BETWEEN #{startTime} AND #{endTime}
+          AND device_id = #{deviceId}
+        GROUP BY
+            device_id
+    </select>
 </mapper>

+ 99 - 0
fs-service/src/main/resources/mapper/watch/WatchSosCallLogsMapper.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.watch.mapper.WatchSosCallLogsMapper">
+
+    <resultMap type="com.fs.watch.domain.WatchSosCallLogs" id="BaseResultMap">
+        <result property="id" column="id" jdbcType="OTHER" typeHandler="com.fs.watch.handler.UUIDTypeHandler"/>
+        <result property="deviceId" column="device_id" jdbcType="VARCHAR"/>
+        <result property="alarmTime" column="alarm_time" jdbcType="VARCHAR"/>
+        <result property="lat" column="lat" jdbcType="VARCHAR"/>
+        <result property="lon" column="lon" jdbcType="VARCHAR"/>
+        <result property="callLogs" column="call_logs" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 查询列列表 -->
+    <sql id="Base_Column_List">
+        id, device_id, alarm_time, lat, lon, call_logs
+    </sql>
+
+    <!-- 根据创建时间查询 -->
+    <select id="queryByAlarmTime" parameterType="String" resultType="Integer">
+        SELECT COUNT(*)
+        FROM watch_sos_call_logs
+        WHERE alarm_time = #{alarmTime}
+    </select>
+
+    <select id="getByDeviceIdAndTime" resultMap="BaseResultMap">
+        select * from watch_sos_call_logs where device_id like #{deviceId}
+                                         and alarm_time = #{alarmTime}
+    </select>
+
+    <select id="getByDeviceIdAndTimeOne" resultMap="BaseResultMap">
+        SELECT *
+        FROM watch_sos_call_logs
+        WHERE device_id LIKE #{deviceId}
+        ORDER BY abs(toUnixTimestamp(alarm_time) - #{alarmTime})
+        LIMIT 1
+    </select>
+
+    <!-- 插入数据 -->
+    <update id="insert" parameterType="com.fs.watch.domain.WatchSosCallLogs">
+        INSERT INTO watch_sos_call_logs
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="data.id != null">
+                id,
+            </if>
+            <if test="data.deviceId != null">
+                device_id,
+            </if>
+            <if test="data.alarmTime != null">
+                alarm_time,
+            </if>
+            <if test="data.lat != null">
+                lat,
+            </if>
+            <if test="data.lon != null">
+                lon,
+            </if>
+            <if test="data.callLogs != null">
+                call_logs,
+            </if>
+
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            <if test="data.id != null">
+                #{data.id},
+            </if>
+            <if test="data.deviceId != null">
+                #{data.deviceId},
+            </if>
+            <if test="data.alarmTime != null">
+                #{data.alarmTime},
+            </if>
+            <if test="data.lat != null">
+                #{data.lat},
+            </if>
+            <if test="data.lon != null">
+                #{data.lon},
+            </if>
+            <if test="data.callLogs != null">
+                #{data.callLogs},
+            </if>
+        </trim>
+    </update>
+    <update id="batchInsertData" parameterType="java.util.List">
+        INSERT INTO watch_sos_call_logs (device_id, alarm_time, lat, lon, call_logs)
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+            #{item.deviceId},
+            #{item.alarmTime},
+            #{item.lat},
+            #{item.lon},
+            #{item.callLogs}
+            )
+        </foreach>
+    </update>
+
+</mapper>
+

+ 11 - 0
fs-service/src/main/resources/mapper/watch/WatchSpo2DataMapper.xml

@@ -139,4 +139,15 @@
           AND create_time BETWEEN #{startTime} AND #{endTime}
         ORDER BY create_time ASC LIMIT #{num},#{size}
     </select>
+    <select id="countAvgBpByDate" resultType="java.lang.Float">
+        SELECT
+            avg(max_boxy)
+        FROM
+            watch_spo2_data
+        WHERE
+            create_time BETWEEN #{startTime} AND #{endTime}
+          AND device_id = #{deviceId}
+        GROUP BY
+            device_id
+    </select>
 </mapper>

+ 62 - 4
fs-service/src/main/resources/mapper/watch/WatchUserMapper.xml

@@ -20,6 +20,8 @@
         <result property="updateTime" column="update_time"/>
         <result property="isDel" column="is_del" jdbcType="INTEGER"/>
         <result property="nickName" column="nick_name" jdbcType="VARCHAR"/>
+        <result property="xhsDeviceId" column="xhs_device_id" jdbcType="VARCHAR"/>
+        <result property="newXhsDeviceId" column="new_xhs_device_id" jdbcType="VARCHAR"/>
     </resultMap>
 
 
@@ -27,7 +29,9 @@
     <select id="selectWatchFsUserById" resultType="com.fs.watch.domain.WatchFsUser">
         select u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,
                wu.nick_name,
-               wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,wu.target_calorie,wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,wu.monitor_data_type_order
+               wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,wu.target_calorie,
+               wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,wu.monitor_data_type_order,
+               wu.xhs_device_id,wu.new_xhs_device_id
         from watch_user wu
         LEFT JOIN fs_user u ON wu.user_id = u.user_id
         where wu.user_id = #{userId}
@@ -36,7 +40,8 @@
     <!--查询指定行数据-->
     <select id="queryAllByLimit" resultMap="WatchUserMap">
         select
-        user_id,sex,birthday,w_company_id,height,weight,target_step,target_calorie,device_id,other_device,monitor_data_type_order,create_time,update_time,is_del,nick_name
+        user_id,sex,birthday,w_company_id,height,weight,target_step,target_calorie,device_id,other_device,
+        monitor_data_type_order,create_time,update_time,is_del,nick_name,xhs_device_id,new_xhs_device_id
         from watch_user
         <where>
             <if test="userId != null">
@@ -138,6 +143,9 @@
             <if test="nickName != null and nickName != ''">
                 and nick_name = #{nickName}
             </if>
+            <if test="xhsDeviceId != null and xhsDeviceId != ''">
+                and xhs_device_id = #{xhsDeviceId}
+            </if>
         </where>
     </select>
 
@@ -145,7 +153,9 @@
         <if test="type==0">
             SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
             wu.nick_name,
-            wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,wu.target_calorie,wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,wu.monitor_data_type_order
+            wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,
+            wu.target_calorie,wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,
+            wu.monitor_data_type_order,wu.xhs_device_id
             FROM watch_user wu
             left join fs_user u on wu.user_id = u.user_id
             WHERE wu.device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
@@ -154,7 +164,47 @@
         <if test="type==1">
             SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
             wu.nick_name,
-            wu.sex,wu.birthday,wu.height,wu.weight,wu.target_step,wu.target_calorie,wu.target_activity,wu.target_sport,wu.device_id,wu.monitor_data_type_order
+            wu.sex,wu.birthday,wu.height,wu.weight,wu.target_step,wu.target_calorie,wu.target_activity,
+            wu.target_sport,wu.device_id,wu.monitor_data_type_order
+            FROM watch_family_user wu
+            left join fs_user u on u.user_id = #{userId}
+            WHERE wu.device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
+        </if>
+        <if test="type==2">
+            SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
+            wu.nick_name,
+            wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,wu.target_calorie,
+            wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,wu.monitor_data_type_order,
+            wu.xhs_device_id
+            FROM watch_user wu
+            left join fs_user u on wu.user_id = u.user_id
+            WHERE wu.xhs_device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
+            AND  wu.user_id = #{userId}
+        </if>
+        <if test="type==3">
+            SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
+            wu.nick_name,
+            wu.sex,wu.birthday,wu.height,wu.weight,wu.target_step,wu.target_calorie,
+            wu.target_activity,wu.target_sport,wu.device_id as xhs_device_id,wu.monitor_data_type_order
+            FROM watch_family_user wu
+            left join fs_user u on u.user_id = #{userId}
+            WHERE wu.device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
+        </if>
+        <if test="type==4">
+            SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
+            wu.nick_name,
+            wu.sex,wu.birthday,wu.w_company_id,wu.height,wu.weight,wu.target_step,wu.target_calorie,
+            wu.target_activity,wu.target_sport,wu.device_id,wu.other_device,wu.monitor_data_type_order,wu.new_xhs_device_id
+            FROM watch_user wu
+            left join fs_user u on wu.user_id = u.user_id
+            WHERE wu.new_xhs_device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
+            AND  wu.user_id = #{userId}
+        </if>
+        <if test="type==5">
+            SELECT u.user_id, u.avatar, u.password, u.sex, u.status, u.remark,u.phone,
+            wu.nick_name,
+            wu.sex,wu.birthday,wu.height,wu.weight,wu.target_step,wu.target_calorie,
+            wu.target_activity,wu.target_sport,wu.device_id as new_xhs_device_id,wu.monitor_data_type_order
             FROM watch_family_user wu
             left join fs_user u on u.user_id = #{userId}
             WHERE wu.device_id LIKE concat('%',#{deviceId},'%') AND wu.is_del = 0
@@ -206,6 +256,7 @@
             <if test="createTime != null">create_time,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="isDel != null">is_del,</if>
+            <if test="xhsDeviceId != null">xhs_device_id,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
 
@@ -225,6 +276,7 @@
             <if test="createTime != null">#{createTime},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="isDel != null">#{isDel},</if>
+            <if test="xhsDeviceId != null">#{xhsDeviceId},</if>
         </trim>
     </insert>
 
@@ -282,6 +334,12 @@
             <if test="nickName != null and nickName != ''">
                 nick_name = #{nickName},
             </if>
+            <if test="xhsDeviceId != null">
+                xhs_device_id = #{xhsDeviceId},
+            </if>
+            <if test="newXhsDeviceId != null">
+                new_xhs_device_id = #{newXhsDeviceId},
+            </if>
         </set>
         where user_id = #{userId}
     </update>

+ 213 - 61
fs-watch/src/main/java/com/fs/app/controller/WatchController.java

@@ -10,9 +10,12 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.domain.FsThirdDeviceData;
+import com.fs.his.service.IFsThirdDeviceDataService;
 import com.fs.watch.domain.*;
 import com.fs.watch.domain.vo.*;
 import com.fs.watch.param.WatchDataQueryParam;
+import com.fs.watch.param.WatchUserByDeviceIdParam;
 import com.fs.watch.service.*;
 import com.fs.watch.utils.GeocodingUtils;
 import io.swagger.annotations.Api;
@@ -20,10 +23,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -91,6 +91,8 @@ public class WatchController extends AppBaseController {
     private WatchSportDataService watchSportDataService;
     @Autowired
     private WatchFatigueDataService watchFatigueDataService;
+    @Autowired
+    private IFsThirdDeviceDataService fsThirdDeviceDataService;
 
     /**
      * 活动详情统计
@@ -103,17 +105,36 @@ public class WatchController extends AppBaseController {
     public R sportDataByDate(
             @RequestParam(value = "startTime") Date startTime,
             @RequestParam(value = "endTime") Date endTime,
-            @RequestParam(value = "deviceId") String deviceId) {
-        List<WatchSportDataByDateVo> data = watchSportDataService.sportDataByDate(startTime, endTime, deviceId);
+            @RequestParam(value = "deviceId") String deviceId,
+            @RequestParam(value = "deviceType",required = false) Integer deviceType) {
+        List<WatchSportDataByDateVo> data = new ArrayList<>();
+        Float activityTime = null;
+        if (deviceType == null || deviceType == 0) {
+            data = watchSportDataService.sportDataByDate(startTime, endTime, deviceId);
+        } else {
+            data = fsThirdDeviceDataService.sportDataByDate(startTime, endTime, deviceId);
+            WatchSportRecordVo otherData = fsThirdDeviceDataService.getOtherData(startTime, endTime, deviceId, 6, null);
+            if (otherData != null && otherData.getTime() != null) {
+                activityTime = otherData.getTime()*60*60;
+            }
+        }
+
         Float distanceTotal = 0f;
         Float calorieTotal = 0f;
         Float timeTotal = 0f;
-        for (WatchSportDataByDateVo vo : data) {
-            distanceTotal = vo.getDistance() + distanceTotal;
-            calorieTotal = vo.getCalorie() + calorieTotal;
-            timeTotal = vo.getTime() + timeTotal;
+        Float speedTotal = 0f;
+        if (data != null && !data.isEmpty()) {
+            for (WatchSportDataByDateVo vo : data) {
+                distanceTotal = vo.getDistance() + distanceTotal;
+                calorieTotal = vo.getCalorie() + calorieTotal;
+                timeTotal = vo.getTime() + timeTotal;
+            }
+            speedTotal = Math.round((distanceTotal / (timeTotal/60/60)) * 100) / 100f;
         }
-        Float speedTotal = Math.round((distanceTotal / (timeTotal/60/60)) * 100) / 100f;
+        if (deviceType != null && deviceType != 0) {
+            timeTotal = activityTime == null?0f:activityTime;
+        }
+
         return R.ok().put("data",data)
                 .put("distanceTotal",distanceTotal)
                 .put("calorieTotal",calorieTotal)
@@ -131,6 +152,7 @@ public class WatchController extends AppBaseController {
     @GetMapping("/sport/dataByType")
     public AjaxResult dataByType(@RequestParam(value = "deviceId") String deviceId,
                                  @RequestParam(value = "type")String type,
+                                 @RequestParam(value = "deviceType",required = false)Integer deviceType,
                                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                  @RequestParam(value = "pageSize", required = false) Integer pageSize
     ) {
@@ -140,7 +162,13 @@ public class WatchController extends AppBaseController {
         if (pageSize == null || pageSize < 1) {
             pageSize = 10;  // 默认页面大小
         }
-        WatchSportDetailDataVo vo = watchSportDataService.dataByType(deviceId, type);
+        WatchSportDetailDataVo vo =  null;
+        if (deviceType == null || deviceType == 0) {
+            vo = watchSportDataService.dataByType(deviceId, type);
+        } else {
+            vo = fsThirdDeviceDataService.dataByType(deviceId, type);
+        }
+
         if (vo != null) {
             List<WatchSportDataByDateVo> list = vo.getList();
             if (list!=null && !list.isEmpty()) {
@@ -162,9 +190,11 @@ public class WatchController extends AppBaseController {
      */
     @Login
     @GetMapping("/sport/data")
-    public AjaxResult sportData(@RequestParam(value = "deviceId") String deviceId,@RequestParam(value = "isFamily",required = false) Boolean isFamily) {
+    public AjaxResult sportData(@RequestParam(value = "deviceId") String deviceId,
+                                @RequestParam(value = "isFamily",required = false) Boolean isFamily,
+                                @RequestParam(value = "deviceType",required = false) Integer deviceType) {
         String userId = getUserId();
-        return AjaxResult.success(watchSportDataService.sportData(userId,deviceId,isFamily));
+        return AjaxResult.success(watchSportDataService.sportData(userId,deviceId,isFamily,deviceType));
     }
 
     /**
@@ -174,8 +204,9 @@ public class WatchController extends AppBaseController {
      */
     @Login
     @GetMapping("/sport/queryRecord")
-    public AjaxResult queryRecord(@RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(watchSportDataService.queryRecord(deviceId));
+    public AjaxResult queryRecord(@RequestParam(value = "deviceId") String deviceId,
+                                  @RequestParam(value = "deviceType",required = false) Integer deviceType) {
+        return AjaxResult.success(watchSportDataService.queryRecord(deviceId,deviceType));
     }
 
 
@@ -194,7 +225,8 @@ public class WatchController extends AppBaseController {
                                            @RequestParam(value = "deviceId") String deviceId,
                                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                            @RequestParam(value = "pageSize", required = false) Integer pageSize,
-                                           @RequestParam(value = "status", required = false) Integer status
+                                           @RequestParam(value = "status", required = false) Integer status,
+                                           @RequestParam(value = "deviceType") Integer deviceType
     ) {
         if (pageNum == null || pageNum < 1) {
             pageNum = 1;
@@ -204,11 +236,11 @@ public class WatchController extends AppBaseController {
         }
 
         // 获取总记录数
-        int total = this.watchThirdUaDataService.countTotalDate(startTime, endTime, deviceId,status);
+        int total = this.watchThirdUaDataService.countTotalDate(startTime, endTime, deviceId,status,deviceType);
 
         // 获取分页数据
         List<WatchThirdUaData> list = this.watchThirdUaDataService.queryListByDate
-                (startTime, endTime, deviceId, ((pageNum - 1) * pageSize), pageSize,status
+                (startTime, endTime, deviceId, ((pageNum - 1) * pageSize), pageSize,status,deviceType
                 );
 
         // 返回包含数据的TableDataInfo对象
@@ -228,8 +260,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/ua/count")
     public AjaxResult countUaByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchThirdUaDataService.countUaByDate(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchThirdUaDataService.countUaByDate(startTime, endTime, deviceId,deviceType));
     }
 
 
@@ -244,8 +277,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/ua/list")
     public AjaxResult queryUaByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchThirdUaDataService.list(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchThirdUaDataService.list(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -288,8 +322,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/heart/rate/list")
     public AjaxResult queryHeartByDate(@RequestParam(value = "startTime") Date startTime,
                                        @RequestParam(value = "endTime") Date endTime,
-                                       @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchHeartRateDataService.list(startTime, endTime, deviceId));
+                                       @RequestParam(value = "deviceId") String deviceId,
+                                       @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchHeartRateDataService.list(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -304,8 +339,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/heart/rate/count")
     public AjaxResult countHeartByDate(@RequestParam(value = "startTime") Date startTime,
                                        @RequestParam(value = "endTime") Date endTime,
-                                       @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchHeartRateDataService.countHeartByDate(startTime, endTime, deviceId));
+                                       @RequestParam(value = "deviceId") String deviceId,
+                                       @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchHeartRateDataService.countHeartByDate(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -355,8 +391,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/sleep/list")
     public AjaxResult querySleepByDate(@RequestParam(value = "startTime") Date startTime,
                                        @RequestParam(value = "endTime") Date endTime,
-                                       @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchSleepDataService.list(startTime, endTime, deviceId));
+                                       @RequestParam(value = "deviceId") String deviceId,
+                                       @RequestParam(value = "deviceType",required = false) Integer deviceType) {
+        return AjaxResult.success(this.watchSleepDataService.list(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -373,12 +410,13 @@ public class WatchController extends AppBaseController {
     public AjaxResult queryBpByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
                                     @RequestParam(value = "deviceId") String deviceId,
-                                    @RequestParam(value = "status", required = false) Integer status) {
+                                    @RequestParam(value = "status", required = false) Integer status,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
         return AjaxResult.success(this.watchThirdBpDataService.queryBpByDate(
                 DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
                 DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
                 deviceId,
-                status));
+                status,deviceType));
     }
 
     /**
@@ -393,8 +431,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/bp/count")
     public AjaxResult countBpByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchThirdBpDataService.countBpByDate(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchThirdBpDataService.countBpByDate(startTime, endTime, deviceId,deviceType));
     }
 
 
@@ -413,7 +452,8 @@ public class WatchController extends AppBaseController {
                                            @RequestParam(value = "deviceId") String deviceId,
                                            @RequestParam(value = "status", required = false) Integer status,
                                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
-                                           @RequestParam(value = "pageSize", required = false) Integer pageSize) {
+                                           @RequestParam(value = "pageSize", required = false) Integer pageSize,
+                                           @RequestParam(value = "deviceType") Integer deviceType) {
         if (pageNum == null || pageNum < 1) {
             pageNum = 1;
         }
@@ -423,11 +463,11 @@ public class WatchController extends AppBaseController {
 
         // 获取总记录数
 //        int total = this.watchBloodPressureDataService.countBpPageByDate(startTime, endTime, deviceId, status);
-        int total = this.watchThirdBpDataService.countBpPageByDate(startTime, endTime, deviceId, status);
+        int total = this.watchThirdBpDataService.countBpPageByDate(startTime, endTime, deviceId, status,deviceType);
 
         // 获取分页数据
 //        List<WatchBloodPressureData> list = this.watchBloodPressureDataService.queryBgPageByDate(startTime, endTime, deviceId, status, ((pageNum - 1) * pageSize), pageSize);
-        List<WatchThirdBpData> list = this.watchThirdBpDataService.queryBgPageByDate(startTime, endTime, deviceId, status, ((pageNum - 1) * pageSize), pageSize);
+        List<WatchThirdBpData> list = this.watchThirdBpDataService.queryBgPageByDate(startTime, endTime, deviceId, status, ((pageNum - 1) * pageSize), pageSize,deviceType);
 
         // 返回包含数据的TableDataInfo对象
         return new TableDataInfo(list, total);
@@ -446,8 +486,9 @@ public class WatchController extends AppBaseController {
     public AjaxResult queryBgByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
                                     @RequestParam(value = "deviceId") String deviceId,
-                                    @RequestParam(value = "status", required = false) Integer status) {
-        return AjaxResult.success(this.watchBloodGlucoseDataService.queryBgByDate(startTime, endTime, deviceId, status));
+                                    @RequestParam(value = "status", required = false) Integer status,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchBloodGlucoseDataService.queryBgByDate(startTime, endTime, deviceId, status,deviceType));
     }
 
 
@@ -466,7 +507,8 @@ public class WatchController extends AppBaseController {
                                            @RequestParam(value = "deviceId") String deviceId,
                                            @RequestParam(value = "status", required = false) Integer status,
                                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
-                                           @RequestParam(value = "pageSize", required = false) Integer pageSize) {
+                                           @RequestParam(value = "pageSize", required = false) Integer pageSize,
+                                           @RequestParam(value = "deviceType") Integer deviceType) {
         if (pageNum == null || pageNum < 1) {
             pageNum = 1;
         }
@@ -475,11 +517,11 @@ public class WatchController extends AppBaseController {
         }
 
         // 获取总记录数
-        int total = this.watchBloodGlucoseDataService.countBgPageByDate(startTime, endTime, deviceId, status);
+        int total = watchBloodGlucoseDataService.countBgPageByDate(startTime, endTime, deviceId, status,deviceType);
 
         // 获取分页数据
-        List<WatchBloodGlucoseData> list = this.watchBloodGlucoseDataService.queryBgPageByDate
-                (startTime, endTime, deviceId, status, ((pageNum - 1) * pageSize), pageSize
+        List<WatchBloodGlucoseData> list = watchBloodGlucoseDataService.queryBgPageByDate
+                (startTime, endTime, deviceId, status, ((pageNum - 1) * pageSize), pageSize,deviceType
                 );
 
         // 返回包含数据的TableDataInfo对象
@@ -499,8 +541,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/bg/count")
     public AjaxResult countBgByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchBloodGlucoseDataService.countBgByDate(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchBloodGlucoseDataService.countBgByDate(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -515,8 +558,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/sp/list")
     public AjaxResult querySpByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchSpo2DataService.querySpByDate(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchSpo2DataService.querySpByDate(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -565,8 +609,9 @@ public class WatchController extends AppBaseController {
     @GetMapping("/sp/count")
     public AjaxResult countSpByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
-                                    @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchSpo2DataService.countSpByDate(startTime, endTime, deviceId));
+                                    @RequestParam(value = "deviceId") String deviceId,
+                                    @RequestParam(value = "deviceType") Integer deviceType) {
+        return AjaxResult.success(this.watchSpo2DataService.countSpByDate(startTime, endTime, deviceId,deviceType));
     }
 
     /**
@@ -710,13 +755,13 @@ public class WatchController extends AppBaseController {
      */
     @GetMapping("/queryIndexWatchData")
     @Login
-    public AjaxResult queryIndexWatchData(String type, String deviceId) {
+    public AjaxResult queryIndexWatchData(String type, String deviceId,Integer deviceType) {
         if (StringUtils.isBlank(type)) {
             return null;
         }
         String userId = getUserId();
         List<String> types = Arrays.stream(type.split(",")).collect(Collectors.toList());
-        return AjaxResult.success(this.watchDataService.queryIndexWatchData(types, deviceId,userId));
+        return AjaxResult.success(this.watchDataService.queryIndexWatchData(types, deviceId,userId,deviceType));
     }
 
     /**
@@ -779,13 +824,14 @@ public class WatchController extends AppBaseController {
     @GetMapping("/queryMonthByDeviceId")
     public TableDataInfo queryMonthByDeviceId(@RequestParam(value = "deviceId") String deviceId,
                                               @RequestParam("pageSize") Integer pageSize,
-                                              @RequestParam("pageNum") Integer pageNum
+                                              @RequestParam("pageNum") Integer pageNum,
+                                              @RequestParam("deviceType") Integer deviceType
     ) {
         if (StringUtils.isBlank(deviceId)) {
             return null;
         }
         TableDataInfo tableDataInfo = new TableDataInfo();
-        QueryPageMonthVo vo = this.watchDataService.queryMonthByDeviceId(deviceId, pageSize, pageNum);
+        QueryPageMonthVo vo = this.watchDataService.queryMonthByDeviceId(deviceId, pageSize, pageNum,deviceType);
         tableDataInfo.setTotal(vo.getTotal());
         tableDataInfo.setRows(vo.getMonth());
         return tableDataInfo;
@@ -1277,16 +1323,16 @@ public class WatchController extends AppBaseController {
     /**
      * 首页绑定-设备信息
      */
-    @GetMapping("/getInfoByDeviceIds")
+    @PostMapping("/getInfoByDeviceIds")
     @Login
     @ApiOperation("首页绑定-设备信息")
-    public AjaxResult getUserByDeviceId(@RequestParam("deviceIds") String deviceIds,
-                                        @RequestParam(value = "isFamily") Boolean isFamily) {
-        if (StringUtils.isBlank(deviceIds)) {
+    public AjaxResult getUserByDeviceId(@RequestBody WatchUserByDeviceIdParam watchUserByDeviceIdParam) {
+        List<WatchUserByDeviceIdParam.WatchUserByDeviceIdTemp> params = watchUserByDeviceIdParam.getParams();
+        if (params == null || params.isEmpty()) {
             return null;
         }
         String userId = getUserId();
-        return AjaxResult.success(watchDataService.getUserByDeviceId(deviceIds, isFamily,Long.valueOf(userId)));
+        return AjaxResult.success(watchDataService.getUserByDeviceId(watchUserByDeviceIdParam,Long.valueOf(userId)));
     }
 
     /**
@@ -1344,14 +1390,16 @@ public class WatchController extends AppBaseController {
                                         @RequestParam(value = "deviceId",required = false) String deviceId,
                                         @RequestParam(value = "isFamily",required = false) Boolean isFamily,
                                         @RequestParam(value = "userId",required = false) Long userId,
-                                        @RequestParam(value = "isRefresh",required = false) Integer isRefresh) {
+                                        @RequestParam(value = "isRefresh",required = false) Integer isRefresh,
+                                        @RequestParam(value = "deviceType",required = false) Integer deviceType) {
         if (userId == null){
             userId = Long.valueOf(getUserId());
         }
         if (isFamily == null){
             isFamily = Boolean.FALSE;
         }
-        return AjaxResult.success(watchBasicInfoService.getAppFsUserHealthReportVo(startTime,endTime, deviceId,userId,isFamily,isRefresh));
+        return AjaxResult.success(watchBasicInfoService.getAppFsUserHealthReportVo(startTime,endTime,
+                deviceId,userId,isFamily,isRefresh,deviceType));
     }
 
     /**
@@ -1411,11 +1459,115 @@ public class WatchController extends AppBaseController {
     public AjaxResult getUserHealthInfoByDeviceId(@RequestParam(value = "startTime") Date startTime,
                                                   @RequestParam(value = "endTime") Date endTime,
                                                   @RequestParam(value = "deviceId",required = false) String deviceId,
-                                                  @RequestParam(value = "userId",required = false) Long userId) {
+                                                  @RequestParam(value = "userId",required = false) Long userId,
+                                                  @RequestParam(value = "deviceType") Integer deviceType) {
         if (userId == null){
             userId = Long.valueOf(getUserId());
         }
-        return AjaxResult.success(watchSportDataService.getUserHealthInfoByDeviceId(deviceId,startTime,endTime,userId));
+        return AjaxResult.success(watchSportDataService.getUserHealthInfoByDeviceId(deviceId,startTime,endTime,userId,deviceType));
+    }
+
+    /**
+     * 新增三方设备健康数据
+     */
+    @Login
+    @PostMapping("/xhsDataAdd")
+    public R add(@RequestBody FsThirdDeviceData fsThirdDeviceData)
+    {
+        Long userId = Long.valueOf(getUserId());
+        fsThirdDeviceData.setUserId(userId);
+        setStatus(fsThirdDeviceData);
+        fsThirdDeviceDataService.insertFsThirdDeviceData(fsThirdDeviceData);
+        return R.ok();
+    }
+
+    /**
+     * 新增三方设备健康数据
+     */
+    @Login
+    @PostMapping("/xhsDataAddList")
+    public R add(@RequestBody List<FsThirdDeviceData> fsThirdDeviceData)
+    {
+
+        if (fsThirdDeviceData == null || fsThirdDeviceData.isEmpty()){
+            return R.error("没有所需要记录的数据!");
+        }
+        Long userId = Long.valueOf(getUserId());
+        for (FsThirdDeviceData deviceData : fsThirdDeviceData) {
+            deviceData.setUserId(userId);
+            if (deviceData.getCreateTime() == null){
+                deviceData.setCreateTime(new Date());
+            }
+            setStatus(deviceData);
+
+        }
+        fsThirdDeviceDataService.insertFsThirdDeviceDataList(fsThirdDeviceData);
+        return R.ok();
+    }
+
+    private void setStatus(FsThirdDeviceData deviceData) {
+        String recordValue = deviceData.getRecordValue();
+        Integer recordType = deviceData.getRecordType();
+        Long userId = deviceData.getUserId();
+        if (StringUtils.isNotBlank(recordValue)){
+            switch (recordType) {
+                //血压
+                case 0:
+                    if (StringUtils.isNotBlank(recordValue)){
+                        JSONObject record = JSONObject.parseObject(recordValue);
+                        deviceData.setStatus(watchBloodPressureDataService.getStatus(Integer.parseInt(record.get("sdb").toString()),
+                                Integer.valueOf(record.get("dbp").toString())));
+                    }
+                    break;
+                //血糖
+                case 1:
+                    deviceData.setStatus(watchBloodGlucoseDataService.getStatus(Double.valueOf(recordValue)));
+                    break;
+                //心率
+                case 2:
+                    deviceData.setStatus(watchHeartRateDataService.getStatus(Integer.parseInt(recordValue),Integer.parseInt(recordValue)));
+                    break;
+                //尿酸
+                case 3:
+                    Integer deviceType = deviceData.getDeviceType();
+                    deviceData.setStatus(watchThirdUaDataService.getStatus(deviceData.getDeviceId(),Integer.parseInt(recordValue), userId, deviceType ==0?0:(deviceType ==1?2:4)));
+                    break;
+                //血氧
+                case 4:
+                    deviceData.setStatus(watchSpo2DataService.getStatus(Integer.parseInt(recordValue),Integer.parseInt(recordValue)));
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+    /**
+     * 查询三方设备健康数据列表
+     */
+    @Login
+    @GetMapping("/xhsDataList")
+    public R list(FsThirdDeviceData fsThirdDeviceData)
+    {
+        String userId = getUserId();
+        fsThirdDeviceData.setUserId(Long.valueOf(userId));
+        startPage();
+        List<FsThirdDeviceData> list = fsThirdDeviceDataService.selectFsThirdDeviceDataList(fsThirdDeviceData);
+        return R.ok().put("data", list);
+    }
+
+
+    /**
+     * 查询三方设备最新数据
+     * deviceType 1小护士设备 2手表
+     */
+    @Login
+    @GetMapping("/getLastData")
+    public R getLastData(@RequestParam("deviceType") Integer deviceType,@RequestParam("deviceId")String deviceId)
+    {
+        String userId = getUserId();
+        List<FsThirdDeviceData> list = fsThirdDeviceDataService.getLastData(Long.valueOf(userId),deviceType,deviceId);
+        return R.ok().put("data", list);
     }
 
 

+ 68 - 12
fs-watch/src/main/java/com/fs/app/controller/WatchUserController.java

@@ -26,9 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
@@ -218,6 +216,32 @@ public class WatchUserController extends AppBaseController {
                         });
 
                     }
+                    // 小护士设备
+                    String xhsDeviceIds = deviceFamily.getXhsDeviceId();
+                    if (StringUtils.isNotBlank(xhsDeviceIds)) {
+                        Arrays.asList(xhsDeviceIds.split(",")).forEach(deviceId->{
+                            //查询该设备是否已存在家人信息
+                            WatchFamilyUser familyUser = watchFamilyUserService.selectWatchFamilyUserByDeviceId(deviceId,null);
+                            if (familyUser == null) {
+                                WatchFamilyUser watchFamilyUser = new WatchFamilyUser();
+                                watchFamilyUser.setDeviceId(deviceId);
+                                watchFamilyUserService.insertWatchFamilyUser(watchFamilyUser);
+                            }
+                        });
+                    }
+                    // 小护士手表
+                    String newXhsDeviceIds = deviceFamily.getNewXhsDeviceId();
+                    if (StringUtils.isNotBlank(newXhsDeviceIds)) {
+                        Arrays.asList(newXhsDeviceIds.split(",")).forEach(deviceId->{
+                            //查询该设备是否已存在家人信息
+                            WatchFamilyUser familyUser = watchFamilyUserService.selectWatchFamilyUserByDeviceId(deviceId,null);
+                            if (familyUser == null) {
+                                WatchFamilyUser watchFamilyUser = new WatchFamilyUser();
+                                watchFamilyUser.setDeviceId(deviceId);
+                                watchFamilyUserService.insertWatchFamilyUser(watchFamilyUser);
+                            }
+                        });
+                    }
                 }
             }
 
@@ -232,14 +256,16 @@ public class WatchUserController extends AppBaseController {
         if (StringUtils.isNoneBlank(deviceIdsStr)) {
             List<String> deviceIds = Arrays.asList(deviceIdsStr.split(","));
             for (String deviceId : deviceIds) {
-                //补全用户信息
-                userInfo.setDeviceid(deviceId);
-                Integer sex = userById.getSex();
-                if (sex != null) {
-                    userInfo.setgender(sex);
+                if (!deviceId.contains(":")){
+                    //补全用户信息
+                    userInfo.setDeviceid(deviceId);
+                    Integer sex = userById.getSex();
+                    if (sex != null) {
+                        userInfo.setgender(sex);
+                    }
+                    //下发设置到设备
+                    deviceSetUpService.setDeviceUserInfo(userInfo);
                 }
-                //下发设置到设备
-                deviceSetUpService.setDeviceUserInfo(userInfo);
             }
         }
 
@@ -324,6 +350,21 @@ public class WatchUserController extends AppBaseController {
         return userService.editDevice(userId, param.getImei(), param.getModel(), param.getBle(), param.getVersion());
     }
 
+    @Login
+    @ApiOperation("绑定小护士设备(自己)")
+    @PostMapping("/editXHSDevice")
+    public R editXHSDevice(@RequestBody HashMap<String,String> param) {
+        //1.获取当前登录用户信息
+        String userId = getUserId();
+        String xhsDeviceId = param.get("xhsDeviceId");
+        String newXhsDeviceId = param.get("newXhsDeviceId");
+        if (StringUtils.isBlank(xhsDeviceId) && StringUtils.isBlank(newXhsDeviceId)) {
+            return R.error("未获取设备!");
+        }
+        param.put("userId", userId);
+        return userService.editXHSDevice(param);
+    }
+
     @Login
     @ApiOperation("解除绑定设备")
     @GetMapping("/removeDevice")
@@ -338,18 +379,32 @@ public class WatchUserController extends AppBaseController {
         }
     }
 
+    @Login
+    @ApiOperation("小护士解除绑定设备(自己)")
+    @GetMapping("/removeXHSDevice")
+    public R removeXHSDevice(@RequestParam(value = "xhsDeviceId",required = false) String xhsDeviceId,
+                             @RequestParam(value = "newXhsDeviceId",required = false) String newXhsDeviceId,
+                             HttpServletRequest request) {
+        //1.获取当前登录用户信息
+        String userId = getUserId();
+        return userService.removeXHSDevice(userId, xhsDeviceId,newXhsDeviceId);
+    }
+
     /**
      * 健康报告-个人信息
+     * param:deviceType 0腕表1小护士2新表
      */
     @GetMapping("/getUserByDeviceId")
     @ApiOperation("健康报告-个人信息")
     public AjaxResult getUserByDeviceId(@RequestParam(value = "deviceId",required = false) String deviceId,
                                         @RequestParam("isFamily") Boolean isFamily,
-                                        @RequestParam(value = "userId",required = false) Long userId) {
+                                        @RequestParam(value = "userId",required = false) Long userId,
+                                        @RequestParam(value = "deviceType",required = false) Integer deviceType
+                                        ) {
         if (userId == null){
             userId = Long.valueOf(getUserId());
         }
-        AppFsUserVo userInfoByDeviceId = userService.getUserInfoByDeviceId(deviceId, isFamily, userId);
+        AppFsUserVo userInfoByDeviceId = userService.getUserInfoByDeviceId(deviceId, isFamily, userId,deviceType);
         FsUserAdditionalData fsUserAdditionalData = fsUserAdditionalDataService.selectUserByUserId(userId);
         if (fsUserAdditionalData != null){
             userInfoByDeviceId.setAge(Integer.parseInt(fsUserAdditionalData.getAge()));
@@ -361,5 +416,6 @@ public class WatchUserController extends AppBaseController {
         return AjaxResult.success(userInfoByDeviceId);
     }
 
+
 }
 

+ 1 - 0
fs-watch/src/main/java/com/fs/watch/controller/DeviceMaterialsController.java

@@ -5,6 +5,7 @@ import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.company.service.ICompanyRoleService;
 import com.fs.company.service.ICompanyService;

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchBloodGlucoseDataController.java

@@ -48,6 +48,6 @@ public class WatchBloodGlucoseDataController {
                                     @RequestParam(value = "endTime") Date endTime,
                                     @RequestParam(value = "deviceId") String deviceId,
                                     @RequestParam(value = "status", required = false) Integer status) {
-        return AjaxResult.success(this.watchBloodGlucoseDataService.queryBgByDate(startTime, endTime, deviceId, status));
+        return AjaxResult.success(this.watchBloodGlucoseDataService.queryBgByDate(startTime, endTime, deviceId, status,0));
     }
 }

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchBloodPressureDataController.java

@@ -59,6 +59,6 @@ public class WatchBloodPressureDataController {
                 DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTime),
                 DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime),
                 deviceId,
-                status));
+                status,0));
     }
 }

+ 2 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchDeviceInfoController.java

@@ -414,7 +414,8 @@ public class WatchDeviceInfoController extends BaseController {
                                         @RequestParam(value = "userId",required = false) Long userId,
                                         @RequestParam(value = "isRefresh",required = false) Integer isRefresh)
     {
-        return AjaxResult.success(watchBasicInfoService.getAppFsUserHealthReportVo(startTime, endTime, deviceId, null, false,isRefresh==null?1:isRefresh));
+        return AjaxResult.success(watchBasicInfoService.getAppFsUserHealthReportVo(startTime, endTime, deviceId,
+                null, false,isRefresh==null?1:isRefresh,0));
 
     }
 

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchHeartRateDataController.java

@@ -109,6 +109,6 @@ public class WatchHeartRateDataController extends BaseController {
     public AjaxResult queryHeartByDate(@RequestParam(value = "startTime") Date startTime,
                                        @RequestParam(value = "endTime") Date endTime,
                                        @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchHeartRateDataService.list(startTime, endTime, deviceId));
+        return AjaxResult.success(this.watchHeartRateDataService.list(startTime, endTime, deviceId,0));
     }
 }

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchSleepDataController.java

@@ -90,6 +90,6 @@ public class WatchSleepDataController {
     public AjaxResult querySleepByDate(@RequestParam(value = "startTime") Date startTime,
                                        @RequestParam(value = "endTime") Date endTime,
                                        @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchSleepDataService.list(startTime, endTime, deviceId));
+        return AjaxResult.success(this.watchSleepDataService.list(startTime, endTime, deviceId,null));
     }
 }

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchSpo2DataController.java

@@ -45,6 +45,6 @@ public class WatchSpo2DataController {
     public AjaxResult querySpByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
                                     @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchSpo2DataService.querySpByDate(startTime, endTime, deviceId));
+        return AjaxResult.success(this.watchSpo2DataService.querySpByDate(startTime, endTime, deviceId,0));
     }
 }

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchSportDataController.java

@@ -88,6 +88,6 @@ public class WatchSportDataController extends BaseController {
         if (com.fs.common.utils.StringUtils.isBlank(deviceId)) {
             return null;
         }
-        return AjaxResult.success(watchSportDataService.getUserHealthInfoByDeviceId(deviceId,startTime,endTime,userId));
+        return AjaxResult.success(watchSportDataService.getUserHealthInfoByDeviceId(deviceId,startTime,endTime,userId,0));
     }
 }

+ 1 - 1
fs-watch/src/main/java/com/fs/watch/controller/WatchThirdUaDataController.java

@@ -44,7 +44,7 @@ public class WatchThirdUaDataController {
     public AjaxResult queryUaByDate(@RequestParam(value = "startTime") Date startTime,
                                     @RequestParam(value = "endTime") Date endTime,
                                     @RequestParam(value = "deviceId") String deviceId) {
-        return AjaxResult.success(this.watchThirdUaDataService.list(startTime, endTime, deviceId));
+        return AjaxResult.success(this.watchThirdUaDataService.list(startTime, endTime, deviceId,0));
     }
 
 }

+ 1 - 0
fs-watch/src/main/java/com/fs/watch/scheduled/HealthDataTask.java

@@ -11,6 +11,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+
 import java.util.List;
 
 @Component