Commit 7c9b43e5 by 李小龙

整理代码

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