Commit caad2203 by 李小龙

fixBug

parent 50bcb034
...@@ -12,6 +12,7 @@ import com.makeit.module.admin.dto.saas.SaasUserDTOVO; ...@@ -12,6 +12,7 @@ import com.makeit.module.admin.dto.saas.SaasUserDTOVO;
import com.makeit.module.admin.dto.saas.SaasUserQueryDTO; import com.makeit.module.admin.dto.saas.SaasUserQueryDTO;
import com.makeit.service.saas.SaasUserService; import com.makeit.service.saas.SaasUserService;
import com.makeit.module.admin.vo.saas.SaasUserLoginVO; import com.makeit.module.admin.vo.saas.SaasUserLoginVO;
import com.makeit.utils.user.ThreadLocalUserUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -130,5 +131,12 @@ public class SaasUserController { ...@@ -130,5 +131,12 @@ public class SaasUserController {
return ApiResponseUtils.success(saasUserService.getUserVO()); return ApiResponseUtils.success(saasUserService.getUserVO());
} }
@ApiOperation("获取当前登录用户的用户信息2")
@PostMapping("getUserVOFromTH")
public ApiResponseEntity<SaasUserLoginVO> getUserInfo2(){
SaasUserLoginVO saasUser = ThreadLocalUserUtil.getSaasUser();
return ApiResponseUtils.success(saasUser);
}
} }
package com.makeit.dto.platform.alarm; package com.makeit.dto.platform.alarm;
import com.makeit.common.dto.BaseTenantDTO; import com.makeit.common.dto.BaseTenantDTO;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.global.validator.DictEnum; import com.makeit.global.validator.DictEnum;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -47,13 +46,13 @@ public class PlatAlarmConfigDTOVO extends BaseTenantDTO { ...@@ -47,13 +46,13 @@ public class PlatAlarmConfigDTOVO extends BaseTenantDTO {
@ApiModelProperty(value = "规则配置") @ApiModelProperty(value = "规则配置")
private String ruleConfig; private String ruleConfig;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "呼吸异常")
private PlatAlarmConfigRespiratoryDTOVO respiratory; private PlatAlarmConfigRespiratoryDTOVO respiratory;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "心率异常")
private PlatAlarmConfigHeartDTOVO heart; private PlatAlarmConfigHeartDTOVO heart;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "行为异常")
private PlatAlarmConfigBehaviorDTOVO behavior; private PlatAlarmConfigBehaviorDTOVO behavior;
@ApiModelProperty(value = "内容") @ApiModelProperty(value = "内容")
......
...@@ -67,7 +67,7 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -67,7 +67,7 @@ public class BehaviorAlarm implements IAlarm{
} }
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class); PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class);
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();//分钟
duration = duration*60; duration = duration*60;
//todo duration+平均停留时长 //todo duration+平均停留时长
List<String> personStateList = Arrays.asList("1", "2", "3"); List<String> personStateList = Arrays.asList("1", "2", "3");
...@@ -79,9 +79,9 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -79,9 +79,9 @@ public class BehaviorAlarm implements IAlarm{
if(alarmRedisDTO==null){ if(alarmRedisDTO==null){
alarmRedisDTO= new AlarmRedisDTO(); alarmRedisDTO= new AlarmRedisDTO();
} }
//有人
if (personStateList.contains(personState)) { if (personStateList.contains(personState)) {
//第一次进入空间 //第一次进入空间
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
if(startLong == null ){ if(startLong == null ){
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
...@@ -91,34 +91,46 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -91,34 +91,46 @@ public class BehaviorAlarm implements IAlarm{
} }
long count = endLong - startLong; long count = endLong - startLong;
//进入空间时间满足告警时长,判断是否已经告警过了 //进入空间时间满足告警时长,判断是否已经告警过了
if (count >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) { if (count/1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue()); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO);
} }
}else {
//todo 是否有第一次进入记录,有则保存db }else {//没人
// 是否有第一次进入记录,有则保存db
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
if(startLong==null){ if(startLong==null){
return; return;
} }
long count = endLong - alarmRedisDTO.getStartLong(); //保存每次进入空间时长
//save db saveDayDurationRecord(platAlarmCheckDTO,alarmRedisDTO);
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
PlatDayDurationRecord durationRecord = new PlatDayDurationRecord();
durationRecord.setElderIds(platElderList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")));
durationRecord.setDuration(count);
durationRecord.setOriDeviceId(platDevice.getOriDeviceId());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
durationRecord.setDay(dateTimeFormatter.format( LocalDateTime.ofEpochSecond(startLong/1000, 0, ZoneOffset.ofHours(8))));
durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId());
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null);
} }
} }
private void saveDayDurationRecord(PlatAlarmCheckDTO platAlarmCheckDTO, AlarmRedisDTO alarmRedisDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
Date now = new Date();
long endLong = now.getTime();
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - alarmRedisDTO.getStartLong();
//save db
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
PlatDayDurationRecord durationRecord = new PlatDayDurationRecord();
durationRecord.setElderIds(platElderList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")));
durationRecord.setDuration(count);
durationRecord.setOriDeviceId(platDevice.getOriDeviceId());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
durationRecord.setDay(dateTimeFormatter.format( LocalDateTime.ofEpochSecond(startLong /1000, 0, ZoneOffset.ofHours(8))));
durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId());
platDayDurationRecordService.saveOrUpdate(durationRecord);
}
@Override @Override
@Async @Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
......
...@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.enums.DeviceState;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
...@@ -21,7 +23,7 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -21,7 +23,7 @@ public class DeviceCacheUtil implements ApplicationRunner {
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
public List<PlatDevice> getAll() { public List<PlatDevice> getAll() {
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>()); List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue()));
list.stream().forEach(vo -> { list.stream().forEach(vo -> {
put(vo); put(vo);
}); });
...@@ -29,7 +31,11 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -29,7 +31,11 @@ public class DeviceCacheUtil implements ApplicationRunner {
} }
public void put(PlatDevice platDevice) { public void put(PlatDevice platDevice) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX+platDevice.getOriDeviceId(), platDevice); if(StringUtils.equals(platDevice.getStatus(),DeviceState.online.getValue())) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId(), platDevice);
}else {
RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId());
}
} }
public PlatDevice get(String oriDeviceId) { public PlatDevice get(String oriDeviceId) {
......
...@@ -83,6 +83,7 @@ public class PushCallback implements MqttCallback { ...@@ -83,6 +83,7 @@ public class PushCallback implements MqttCallback {
PlatDevice platDevice = deviceCacheUtil.get(deviceId); PlatDevice platDevice = deviceCacheUtil.get(deviceId);
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice); List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) { if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.info("该设备没有告警配置:"+deviceId);
return; return;
} }
for (PlatAlarmConfig config : deviceAlarmConfigList) { for (PlatAlarmConfig config : deviceAlarmConfigList) {
......
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