Commit aa91ee4a by lzy

Merge branch 'dev' of git.xmmakeit.com:huangjiay/iot-platform-server into dev

parents 6d393f63 7c9b43e5
package com.makeit.service.platform.alarm.alarmStrategy;
public interface AlarmStrategy {
}
...@@ -756,7 +756,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> ...@@ -756,7 +756,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
private void setRoleList(PlatPersonDTOVO dto) { private void setRoleList(PlatPersonDTOVO dto) {
platUserRoleService.remove(new QueryWrapper<PlatUserRole>().lambda() platUserRoleService.remove(new QueryWrapper<PlatUserRole>().lambda()
.eq(PlatUserRole::getUserId, dto.getId())); .eq(PlatUserRole::getUserId, dto.getId()));
if (dto.getRoleList() != null) { if (dto.getRoleIdList() != null) {
List<PlatUserRole> userRoleList = StreamUtil.map(dto.getRoleIdList(), e -> { List<PlatUserRole> userRoleList = StreamUtil.map(dto.getRoleIdList(), e -> {
PlatUserRole tntUserRole = new PlatUserRole(); PlatUserRole tntUserRole = new PlatUserRole();
tntUserRole.setUserId(dto.getId()); tntUserRole.setUserId(dto.getId());
......
...@@ -32,8 +32,6 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; ...@@ -32,8 +32,6 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback; import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -108,7 +106,7 @@ public class PushCallback implements MqttCallback { ...@@ -108,7 +106,7 @@ public class PushCallback implements MqttCallback {
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) { if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
return; return;
} }
RedissonClient redissonClient = RedisUtil.getClient(); //RedissonClient redissonClient = RedisUtil.getClient();
for (PlatAlarmConfig config : deviceAlarmConfigList) { for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType(); String alarmType = config.getAlarmType();
String ruleConfigStr = config.getRuleConfig(); String ruleConfigStr = config.getRuleConfig();
...@@ -132,24 +130,21 @@ public class PushCallback implements MqttCallback { ...@@ -132,24 +130,21 @@ public class PushCallback implements MqttCallback {
Integer start = ruleConfig.getRespiratoryRateStart(); Integer start = ruleConfig.getRespiratoryRateStart();
Integer end = ruleConfig.getRespiratoryRateEnd(); Integer end = ruleConfig.getRespiratoryRateEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
long endLong = new Date().getTime();
//计数 //计数
RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId); Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
if (!atomicLong.isExists()) { if (StringUtils.equals(personState, "0")|| startLong == null) {
atomicLong.set(0); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
}
if (StringUtils.equals(personState, "0")) {
atomicLong.set(0);
continue; continue;
} }
long count = endLong - startLong;
if (br > end || br < start) { if (br > end || br < start) {
long count = atomicLong.incrementAndGet();
if (count >= duration) { if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createRespiratoryPlatAlarmRecord(platDevice, config); PlatAlarmRecord platAlarmRecord = createRespiratoryPlatAlarmRecord(platDevice, config);
atomicLong.set(0); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
} }
} else { } else {
atomicLong.set(0); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
} }
} }
//心率 //心率
...@@ -161,24 +156,23 @@ public class PushCallback implements MqttCallback { ...@@ -161,24 +156,23 @@ public class PushCallback implements MqttCallback {
Integer start = ruleConfig.getHeartRateStart(); Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd(); Integer end = ruleConfig.getHeartRateEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId); long endLong = new Date().getTime();
if (!atomicLong.isExists()) { //计数
atomicLong.set(0); Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
} if (StringUtils.equals(personState, "0")|| startLong == null) {
if (StringUtils.equals(personState, "0")) { RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
atomicLong.set(0);
continue; continue;
} }
long count = endLong - startLong;
if (hr > end || hr < start) { if (hr > end || hr < start) {
long count = atomicLong.incrementAndGet();
if (count >= duration) { if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createHeartPlatAlarmRecord(platDevice, config); PlatAlarmRecord platAlarmRecord = createHeartPlatAlarmRecord(platDevice, config);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
} }
} else { } else {
atomicLong.set(0); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
} }
} }
RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId);
//行为 //行为
if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue())) { if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue())) {
String personState = (String) properties.get("personState"); String personState = (String) properties.get("personState");
...@@ -189,18 +183,21 @@ public class PushCallback implements MqttCallback { ...@@ -189,18 +183,21 @@ public class PushCallback implements MqttCallback {
List<String> personStateList = Arrays.asList("1", "2", "3"); List<String> personStateList = Arrays.asList("1", "2", "3");
//有人 //有人
//计数 //计数
long endLong = new Date().getTime();
if (!atomicLong.isExists()) { Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
atomicLong.set(0);
}
if (personStateList.contains(personState)) { if (personStateList.contains(personState)) {
long count = atomicLong.incrementAndGet(); long count = endLong - startLong;
if(startLong == null ){
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong);
continue;
}
if (count >= duration) { if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createBehaviorPlatAlarmRecord(platDevice, config); PlatAlarmRecord platAlarmRecord = createBehaviorPlatAlarmRecord(platDevice, config);
atomicLong.set(0); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,startLong);
} }
}else { }else {
atomicLong.set(0); //
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null);
} }
} }
// else { //没人 更新停留时长 // else { //没人 更新停留时长
...@@ -337,5 +334,10 @@ public class PushCallback implements MqttCallback { ...@@ -337,5 +334,10 @@ public class PushCallback implements MqttCallback {
} }
return result; return result;
} }
public static void main(String[] args) {
Date date = new Date();
System.out.println(date.toInstant());
}
} }
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