Commit f0889f06 by 汪志阳

fix:睡眠定时任务代码优化

parent 614a22a4
...@@ -2,6 +2,8 @@ package com.makeit.module.iot.vo.analysis; ...@@ -2,6 +2,8 @@ package com.makeit.module.iot.vo.analysis;
import lombok.Data; import lombok.Data;
import java.util.TreeMap;
/** /**
* @author wangzy * @author wangzy
* @description * @description
...@@ -13,4 +15,9 @@ public class SleepCountDTO { ...@@ -13,4 +15,9 @@ public class SleepCountDTO {
private Integer totalActionCount; private Integer totalActionCount;
private Integer totalTurnedCount; private Integer totalTurnedCount;
private TreeMap<String, TreeMap<String, AnalysisVO>> daySleepMap;
private TreeMap<String, TreeMap<String, AnalysisVO>> restSleepMap;
} }
...@@ -14,7 +14,7 @@ public class SleepTimeDTO { ...@@ -14,7 +14,7 @@ public class SleepTimeDTO {
/** /**
* 入睡 * 睡眠:入睡时间>3小时
*/ */
private List<SleepTimeAnalysisVO> sleepList; private List<SleepTimeAnalysisVO> sleepList;
...@@ -47,7 +47,7 @@ public class SleepTimeDTO { ...@@ -47,7 +47,7 @@ public class SleepTimeDTO {
/** /**
* 睡眠:深度睡眠和浅度睡眠>3小时 * 入睡
*/ */
private List<SleepTimeAnalysisVO> daySleepList; private List<SleepTimeAnalysisVO> daySleepList;
} }
...@@ -52,16 +52,6 @@ public class PlatElderSleepController { ...@@ -52,16 +52,6 @@ public class PlatElderSleepController {
private HuiNengService huiNengService; private HuiNengService huiNengService;
@ApiOperation("测试")
@PostMapping("test1")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<Void> test1() {
platElderSleepService.test1();
return ApiResponseUtils.success();
}
@ApiOperation("测试") @ApiOperation("测试")
@PostMapping("test2") @PostMapping("test2")
@AuthIgnore @AuthIgnore
......
...@@ -8,7 +8,7 @@ import lombok.Getter; ...@@ -8,7 +8,7 @@ import lombok.Getter;
public enum SleepTypeEnum { public enum SleepTypeEnum {
/** /**
* 睡眠类型 1 睡眠 2 小憩,3:深度睡眠,4:中度睡眠,5:浅度睡眠, 6:清醒,7:离床 * 睡眠类型 1 睡眠 (入睡时间大于3小时)2 小憩,3:深度睡眠,4:中度睡眠,5:浅度睡眠, 6:清醒,7:起床 8:入睡
*/ */
SLEEP_DEEP("sleepDeep", "深度睡眠", 3), SLEEP_DEEP("sleepDeep", "深度睡眠", 3),
SLEEP_MODERATE("sleepModerate", "中度睡眠", 4), SLEEP_MODERATE("sleepModerate", "中度睡眠", 4),
...@@ -16,7 +16,8 @@ public enum SleepTypeEnum { ...@@ -16,7 +16,8 @@ public enum SleepTypeEnum {
SOBER("sober", "清醒", 6), SOBER("sober", "清醒", 6),
GETUP("getup", "起床", 7), GETUP("getup", "起床", 7),
SLEEP("sleep", "睡觉", 1), SLEEP("sleep", "睡觉", 1),
RESTING("resting", "小憩", 2); RESTING("resting", "小憩", 2),
DAY_SLEEP("day_sleep","睡眠",8);
private final String code; private final String code;
private final String value; private final String value;
......
...@@ -19,10 +19,7 @@ public interface PlatElderSleepService extends IService<PlatElderSleep> { ...@@ -19,10 +19,7 @@ public interface PlatElderSleepService extends IService<PlatElderSleep> {
List<ElderSleepAnalysisVO> elderSleepSleepAnalysisTask(Integer month, Integer day); List<ElderSleepAnalysisVO> elderSleepSleepAnalysisTask(Integer month, Integer day);
void test1();
String calculateScores(long daySleepTime, long dayRestTime, long deepTime, long soberTime, long lightTime, String calculateScores(long daySleepTime, long dayRestTime, long deepTime, long soberTime, long lightTime,
SaasSleepEvaluateStandardReport evaluateStandardReport); SaasSleepEvaluateStandardReport evaluateStandardReport);
List<PlatElderSleep> mergeWakeUpList(List<PlatElderSleep> elderSleepList, int riseRepeatThreshold);
} }
package com.makeit.iotapi; package com.makeit.iotapi;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO; import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElderSleep;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.admin.vo.plat.PlatTenantVO; import com.makeit.module.admin.vo.plat.PlatTenantVO;
import com.makeit.module.iot.service.IotOrgService; import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.service.IotProductDeviceService; import com.makeit.module.iot.service.IotProductDeviceService;
...@@ -127,27 +122,4 @@ public class IotDeviceInfoContentFall { ...@@ -127,27 +122,4 @@ public class IotDeviceInfoContentFall {
System.out.println(list); System.out.println(list);
} }
@Test
@TenantIdIgnore
@AuthIgnore
void mergeElderSleepList() {
List<PlatElderSleep> sleepList = platElderSleepService.list(Wrappers.<PlatElderSleep>lambdaQuery()
.eq(PlatElderSleep::getHappenDate, "2024-01-01").eq(PlatElderSleep::getElderId, "1712648603580764161"));
logger.info("ori sleep data :{}", JSONUtil.toJsonStr(sleepList));
List<PlatElderSleep> platElderSleeps = recursion(sleepList, sleepList.size() / 2, 3);
logger.info("end sleep data :{}", JSONUtil.toJsonStr(platElderSleeps));
List<PlatElderSleep> list = platElderSleepService.mergeWakeUpList(sleepList, 3);
System.out.println(list);
}
private List<PlatElderSleep> recursion(List<PlatElderSleep> elderSleepList, int count, int riseRepeatThreshold) {
List<PlatElderSleep> platElderSleeps = platElderSleepService.mergeWakeUpList(elderSleepList, riseRepeatThreshold);
if (count == 0) {
return platElderSleeps;
} else {
count--;
return recursion(platElderSleeps, count, riseRepeatThreshold);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment