Commit 68eb3096 by 杨伟程
parents 9050c3cd 925f7211
......@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom;
import lombok.Data;
......@@ -32,7 +31,5 @@ public class PlatAlarmCheckDTO {
//异常值
private String abnormalValue;
private PlatRegionSetting platRegionSetting;
}
......@@ -194,5 +194,8 @@ public class PlatElder extends BaseBusEntity {
@ApiModelProperty(value = "退住时间")
private LocalDateTime checkOutTime;
@TableField(exist = false)
private String regionName;
}
package com.makeit.enums.saas;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum ModelManageTypeEnum {
SLEEP("sleep","睡眠"),
DISEASE("disease","呼吸心率");
private String code;
private String value;
}
......@@ -8,6 +8,7 @@ import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.dto.platform.alarm.PlatAlarmRecordQueryDTO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.vo.platform.alarm.PlatAlarmRecordVO;
/**
......@@ -55,7 +56,7 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> {
*/
void noticeDeviceAlarm(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord);
PlatAlarmRecord convertToPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO);
PlatAlarmRecord convertToPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO, PlatElder platElder);
void getElderListByDeviceId(PlatAlarmCheckDTO platAlarmCheckDTO);
......
......@@ -2,7 +2,6 @@ package com.makeit.service.platform.alarm.alarmStrategy;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSONObject;
import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.dto.platform.alarm.PlatAlarmConfigBehaviorDTOVO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
......@@ -10,7 +9,6 @@ import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
......@@ -33,7 +31,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Component
@Slf4j
......@@ -66,7 +63,7 @@ public class BehaviorAlarm implements IAlarm {
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String deviceId = platDevice.getId();
if (StringUtils.isBlank(ruleConfigStr)) {
log.error("行为告警配置未配置,告警配置id:" + config.getId());
return;
......@@ -74,7 +71,7 @@ public class BehaviorAlarm implements IAlarm {
String personState = Convert.toStr(properties.get("personState"));
PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class);
Integer duration = ruleConfig.getAverageDuration();//分钟
PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(platDevice.getOriDeviceId());
PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(deviceId);
// if (platDayDurationRecord == null) {
// log.error("行为告警未找到行为异常平均时长,设备plat_id:" + platDevice.getId());
// return;
......@@ -148,7 +145,7 @@ public class BehaviorAlarm implements IAlarm {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
PlatRegionSetting platRegionSetting = platAlarmCheckDTO.getPlatRegionSetting();
Date now = new Date();
long endLong = now.getTime();
long count = endLong - alarmRedisDTO.getStartLong();
......@@ -158,23 +155,26 @@ public class BehaviorAlarm implements IAlarm {
log.error("未关联长者,设备id:"+platDevice.getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
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());
durationRecord.setDay(alarmRedisDTO.getStart());
durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId());
durationRecord.setRoomId(platRoom.getId());
durationRecord.setDeviceId(platDevice.getId());
if (platRegionSetting != null) {
durationRecord.setRegionName(platRegionSetting.getRegionName());
if(CollectionUtils.isNotEmpty(platElderList)){
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platElderList = platAlarmCheckDTO.getPlatElderList();
}
for (PlatElder platElder : platElderList) {
PlatDayDurationRecord durationRecord = new PlatDayDurationRecord();
durationRecord.setElderIds(platElder.getId());
durationRecord.setRegionName(platElder.getRegionName());
durationRecord.setDuration(count);
durationRecord.setOriDeviceId(platDevice.getOriDeviceId());
durationRecord.setDay(alarmRedisDTO.getStart());
durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId());
durationRecord.setRoomId(platElder.getRoomId());
durationRecord.setDeviceId(platDevice.getId());
platDayDurationRecordService.saveOrUpdate(durationRecord);
}
platDayDurationRecordService.saveOrUpdate(durationRecord);
}
@Override
......@@ -202,7 +202,7 @@ public class BehaviorAlarm implements IAlarm {
param.add(platElder.getName());
param.add(platRoom.getName());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO,platElder);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
......
......@@ -84,7 +84,7 @@ public class BreathAlarm implements IAlarm {
Integer duration = ruleConfig.getDuration();
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String deviceId = platDevice.getId();
String personState = Convert.toStr(properties.get("personState"));
//呼吸率
......@@ -163,7 +163,7 @@ public class BreathAlarm implements IAlarm {
param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO,platElder);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
......
......@@ -44,7 +44,7 @@ public class FallAlarm implements IAlarm {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String deviceId = platDevice.getId();
String personState = Convert.toStr(properties.get("personState"));
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_FALL_ID + deviceId);
if(alarmRedisDTO==null){
......@@ -54,7 +54,7 @@ public class FallAlarm implements IAlarm {
}
if (StringUtils.equals(personState, CommonEnum.YES.getValue())) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(),CommonEnum.YES.getValue())){
log.error("长者跌倒,已告警过,设备iot_id:"+deviceId);
log.error("长者跌倒,已告警过,设备plat_id:"+deviceId);
return;
}
notice(platAlarmCheckDTO);
......@@ -83,7 +83,7 @@ public class FallAlarm implements IAlarm {
param.add(platElder.getName());
param.add(platRoom.getName());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO,platElder);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
......
......@@ -71,7 +71,7 @@ public class HeartAlarm implements IAlarm {
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String deviceId = platDevice.getId();
Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateeEnd();
Integer duration = ruleConfig.getDuration();
......@@ -144,7 +144,7 @@ public class HeartAlarm implements IAlarm {
param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO,platElder);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
......
......@@ -39,7 +39,6 @@ import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.utils.user.common.CommonUserUtil;
import com.makeit.utils.user.common.CommonUserVO;
import com.makeit.utils.user.wechat.WechatUserInfo;
import com.makeit.utils.user.wechat.WechatUserUtil;
import com.makeit.vo.platform.alarm.PlatAlarmRecordVO;
import lombok.extern.slf4j.Slf4j;
......@@ -112,11 +111,12 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
*/
@Override
public PageVO<PlatAlarmRecordVO> childrenPage(PageReqDTO<PlatAlarmRecordQueryDTO> dto) {
WechatUserInfo userVO = WechatUserUtil.getUserVO();
String elderId = userVO.getElderId();
if (StringUtils.isBlank(elderId)) {
PlatElderChildrenInfo platElderChildrenInfo = platElderChildrenInfoService.getById(WechatUserUtil.getUserId());
log.info("子女端账号:"+platElderChildrenInfo.toString());
if (platElderChildrenInfo == null) {
return new PageVO<>();
}
String elderId = platElderChildrenInfo.getElderId();
String[] split = elderId.split(",");
PlatAlarmRecordQueryDTO data = dto.getData();
data.setElderIdList(Arrays.asList(split));
......@@ -269,7 +269,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
} else {
String notifyUser = alarmConfig.getNotifyUser();
if(StringUtils.isBlank(notifyUser)){
throw new BusinessException("告警内部人员未配置,告警配置id:"+alarmConfig.getId());
log.error("告警内部人员未配置,告警配置id:"+alarmConfig.getId());
return;
}
String[] userArray = notifyUser.split(",");
List<PlatUser> platUsers = platUserService.listByIds(Arrays.asList(userArray));
......@@ -277,7 +278,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
}
platUserList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(platUserList)) {
throw new BusinessException("通知工作人员时,找不到人员数据;" + "orgId:" + alarmConfig.getOrgId() + ",tenantId:" + alarmConfig.getTenantId() + "alarmConfigId:" + alarmConfig.getId());
log.error("通知工作人员时,找不到人员数据;" + "orgId:" + alarmConfig.getOrgId() + ",tenantId:" + alarmConfig.getTenantId() + "alarmConfigId:" + alarmConfig.getId());
return;
}
List<SendTypeEnum> notifyChannelList = Arrays.asList(SendTypeEnum.SMS, SendTypeEnum.VOICE_SMS, SendTypeEnum.MAIL);
Set<String> phoneSet = platUserList.stream().map(PlatUser::getMobile).collect(Collectors.toSet());
......@@ -321,13 +323,12 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
}
@Override
public PlatAlarmRecord convertToPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
public PlatAlarmRecord convertToPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO,PlatElder platElder) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
List<String> param = platAlarmCheckDTO.getParam();
List<PlatElder> elderList = platAlarmCheckDTO.getPlatElderList();
PlatRegionSetting platRegionSetting = platAlarmCheckDTO.getPlatRegionSetting();
PlatAlarmRecord platAlarmRecord = new PlatAlarmRecord();
platAlarmRecord.setAlarmId(config.getId());
......@@ -341,13 +342,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
platAlarmRecord.setNotifyUser(config.getNotifyUser());
platAlarmRecord.setDeviceId(platDevice.getId());
platAlarmRecord.setElderIds(elderList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")));
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setTenantId(config.getTenantId());
platAlarmRecord.setRemark(platAlarmCheckDTO.getRemark());
platAlarmRecord.setAbnormalValue(platAlarmCheckDTO.getAbnormalValue());
if(platRegionSetting!=null) {
platAlarmRecord.setRegionName(platRegionSetting.getRegionName());
}
platAlarmRecord.setRegionName(platElder.getRegionName());
return platAlarmRecord;
}
......@@ -364,47 +363,64 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
roomBedDeviceLambdaQueryWrapper.eq(PlatRoomBedDevice::getDeviceId, platDevice.getId())
.eq(BaseBusEntity::getTenantId,tenantId)
;
PlatRoomBedDevice platRoomBedDevice = platRoomBedDeviceService.getOne(roomBedDeviceLambdaQueryWrapper, false);
if(platRoomBedDevice==null){
throw new BusinessException("设备没绑定房间:"+platDevice.getId());
//todo 要支持 设备绑定多个空间
List<PlatRoomBedDevice> platRoomBedDeviceList = platRoomBedDeviceService.list(roomBedDeviceLambdaQueryWrapper);
if(CollectionUtils.isEmpty(platRoomBedDeviceList)){
log.error("设备没绑定房间:"+platDevice.getId());
return;
}
if(StringUtils.isNotBlank(platRoomBedDevice.getRoomId())) {
PlatRoom platRoom = platRoomService.getById(platRoomBedDevice.getRoomId());
platAlarmCheckDTO.setPlatRoom(platRoom);
LambdaQueryWrapper<PlatRegionSetting> platRegionSettingLambdaQueryWrapper = new LambdaQueryWrapper<>();
platRegionSettingLambdaQueryWrapper.eq(PlatRegionSetting::getRoomId, platRoom.getId())
.eq(PlatRegionSetting::getDeviceId, platDevice.getId())
.eq(BaseBusEntity::getTenantId,tenantId)
;
//区域设置
PlatRegionSetting platRegionSetting = platRegionSettingService.getOne(platRegionSettingLambdaQueryWrapper, false);
platAlarmCheckDTO.setPlatRegionSetting(platRegionSetting);
}
String bedId = platRoomBedDevice.getBedId();
if (StringUtils.isNotBlank(bedId)) {
LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>();
elderLambdaQueryWrapper.eq(PlatElder::getBedId, bedId)
.eq(BaseBusEntity::getTenantId,tenantId)
;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
if(CollectionUtils.isNotEmpty(list)) {
platAlarmCheckDTO.setPlatElderList(list);
return;
platRoomBedDeviceList.forEach(platRoomBedDevice -> {
//获取区域
String regionName = null;
if(StringUtils.isNotBlank(platRoomBedDevice.getRoomId())) {
PlatRoom platRoom = platRoomService.getById(platRoomBedDevice.getRoomId());
platAlarmCheckDTO.setPlatRoom(platRoom);
LambdaQueryWrapper<PlatRegionSetting> platRegionSettingLambdaQueryWrapper = new LambdaQueryWrapper<>();
platRegionSettingLambdaQueryWrapper.eq(PlatRegionSetting::getRoomId, platRoom.getId())
.eq(PlatRegionSetting::getDeviceId, platDevice.getId())
.eq(BaseBusEntity::getTenantId,tenantId)
;
//区域设置
PlatRegionSetting platRegionSetting = platRegionSettingService.getOne(platRegionSettingLambdaQueryWrapper, false);
if(platRegionSetting != null){
regionName = platRegionSetting.getRegionName();
}
}
//获取床位长者
String bedId = platRoomBedDevice.getBedId();
if (StringUtils.isNotBlank(bedId)) {
LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>();
elderLambdaQueryWrapper.eq(PlatElder::getBedId, bedId)
.eq(BaseBusEntity::getTenantId,tenantId)
;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
if(CollectionUtils.isNotEmpty(list)) {
for (PlatElder platElder : list) {
platElder.setRegionName(regionName);
}
platAlarmCheckDTO.setPlatElderList(list);
return;
}
}
}
//获取房间长者
String roomId = platRoomBedDevice.getRoomId();
if (StringUtils.isNotBlank(roomId)) {
LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>();
elderLambdaQueryWrapper.eq(PlatElder::getRoomId, roomId)
.eq(BaseBusEntity::getTenantId,tenantId)
;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
for (PlatElder platElder : list) {
platElder.setRegionName(regionName);
}
platAlarmCheckDTO.setPlatElderList(list);
}
}
);
String roomId = platRoomBedDevice.getRoomId();
if (StringUtils.isNotBlank(roomId)) {
LambdaQueryWrapper<PlatElder> elderLambdaQueryWrapper = new LambdaQueryWrapper<>();
elderLambdaQueryWrapper.eq(PlatElder::getRoomId, roomId)
.eq(BaseBusEntity::getTenantId,tenantId)
;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
platAlarmCheckDTO.setPlatElderList(list);
}
}
private String replaceParam(String oriContent,List<String> param) {
......
......@@ -319,7 +319,6 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
LambdaUpdateWrapper<PlatSpace> platSpaceLambdaUpdateWrapper = Wrappers.lambdaUpdate(PlatSpace.class)
.set(PlatSpace::getAttribute, dto.getType())
.eq(PlatSpace::getOrgId, dto.getId())
.set(PlatSpace::getParentId,dto.getParentId())
;
platSpaceService.update(platSpaceLambdaUpdateWrapper);
}
......@@ -405,7 +404,7 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
public List<PlatOrg> belongToOrgTree(PlatOrg param) {
PlatUserVO userVOCanNull = PlatUserUtil.getUserVOCanNull();
String isTenant = userVOCanNull.getIsTenant();
//如果是租户账号 则有所有权限
//如果是租户账号 则有所有权限 返回最顶级
if (StringUtils.equals(isTenant, CommonEnum.YES.getValue())) {
List<PlatOrg> orgList = this.list(new LambdaQueryWrapper<PlatOrg>()
.eq(StringUtils.isNotEmpty(param.getType()), PlatOrg::getType, param.getType())
......@@ -414,7 +413,7 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
return getOrgTree(orgList, Collections.singletonList(TenantIdUtil.getTenantId()));
}
//平台账号
//平台账号 查询权限范围 生成不一定连续的树结构
Set<String> orgIdList = getOrgIdListByUserId(userVOCanNull.getId());
List<PlatOrg> orgList = this.list(new LambdaQueryWrapper<PlatOrg>()
.eq(StringUtils.isNotEmpty(param.getType()), PlatOrg::getType, param.getType())
......
......@@ -155,6 +155,7 @@ public class PlatRegionSettingServiceImpl extends ServiceImpl<PlatRegionSettingM
platRegionSetting.setToward(dto.getToward());
platRegionSetting.setRegionName(dto.getRegionName());
platRegionSetting.setRegionRange(dto.getRegionRange());
platRegionSetting.setRoomRange(dto.getRoomRange());
platRegionSetting.setDeviceId(dto.getDeviceId());
platRegionSetting.setRoomId(dto.getRoomId());
platRegionSetting.setBackground(dto.getBackground());
......
......@@ -111,7 +111,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
//上级空间
PlatSpace parentSpace = this.getById(dto.getParentId());
if (parentSpace!=null && parentSpace.getParentPath().contains(dto.getId())) {
if (parentSpace!=null && parentSpace.getParentPath()!=null && parentSpace.getParentPath().contains(dto.getId())) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_DEL);
}
......
......@@ -14,10 +14,13 @@ import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.entity.saas.analysis.SaasModelManage;
import com.makeit.entity.saas.analysis.SaasSleepAnalysisModel;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.platform.alarm.PlatAlarmRecordEnum;
import com.makeit.enums.platform.auth.PlatOrgEnum;
import com.makeit.enums.platform.space.PlatBedStatusEnum;
import com.makeit.enums.saas.ModelManageTypeEnum;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.elder.PlatElderRealTimeService;
......@@ -26,6 +29,8 @@ import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.service.platform.workstation.WorkStationService;
import com.makeit.service.saas.SaasModelManageService;
import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.data.convert.PageUtil;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.sql.join.JoinUtil;
......@@ -63,6 +68,10 @@ public class WorkStationServiceImpl implements WorkStationService {
private PlatOrgService platOrgService;
@Autowired
private PlatElderRealTimeService platElderRealTimeService;
@Autowired
private SaasModelManageService saasModelManageService;
@Autowired
private SaasSleepAnalysisModelService saasSleepAnalysisModelService;
@Override
public WorkStationInstitutionStatisticsVO institutionStatistics(WorkStationQueryDTO dto) {
......@@ -207,12 +216,24 @@ public class WorkStationServiceImpl implements WorkStationService {
e.setPathName(StreamUtil.join(l, Objects::nonNull, PlatSpace::getName, "-"));
});
//查询睡眠质量分析模型
// SaasModelManage modelManage = saasModelManageService.getOne(new QueryWrapper<SaasModelManage>().lambda()
// .eq(SaasModelManage::getModelType, ModelManageTypeEnum.SLEEP.getCode())
// .last(" limit 1"));
// Integer turnedComparison = 0;
// if(modelManage != null){
// SaasSleepAnalysisModel model = saasSleepAnalysisModelService.view(modelManage.getModelId());
// if(model != null && model.getTurnedComparison() != null){
// turnedComparison = Integer.valueOf(model.getTurnedComparison());
// }
// }
for (WorkStationInstitutionRoomVO vo : roomVOList) {
vo.setPathName(vo.getPathName() + "-" + vo.getRoomName());
if (bedMap.get(vo.getRoomId()) != null) {
List<WorkStationInstitutionBedVO> roomBedVos = bedMap.get(vo.getRoomId());
//获取告警类型及老人状态
roomBedVos.forEach(r -> {
for(WorkStationInstitutionBedVO r : roomBedVos){
if (StringUtil.isNotEmpty(r.getElderId()) ) {
if(elderAlarmTypeMap.containsKey(r.getElderId())){
r.setAlarmTypeMap(elderAlarmTypeMap.get(r.getElderId()));
......@@ -223,10 +244,20 @@ public class WorkStationServiceImpl implements WorkStationService {
platElderIdDTO.setElderId(r.getElderId());
platElderIdDTO.setDeviceId(r.getDeviceId());
PlatElderRealTimeNowVO nowStatus = platElderRealTimeService.nowStatus(platElderIdDTO);
//离床:雷达状态上报无人
//翻身:雷达上报的数据符合IOT平台睡眠质量分析模型中配置的翻身规则
//睡眠:雷达上报的数据符合IOT平台睡眠质量分析模型中的入睡时间,状态变更为睡眠
//静息:雷达上报有人,且非睡眠
// if("0".equals(nowStatus.getStatus())){
// r.setElderStatus(nowStatus.getStatus());
// }else if(nowStatus.getBodyMove()!=null && nowStatus.getBodyMove() > turnedComparison){
//
// }
r.setElderStatus(nowStatus.getStatus());
}
}
});
}
vo.setList(roomBedVos);
}
}
......
......@@ -39,7 +39,7 @@ public class DayDurationUtil implements ApplicationRunner {
if(CollectionUtils.isEmpty(platDayDurationRecords)){
return;
}
Map<String, List<PlatDayDurationRecord>> deviceIdMap = platDayDurationRecords.stream().collect(Collectors.groupingBy(PlatDayDurationRecord::getOriDeviceId));
Map<String, List<PlatDayDurationRecord>> deviceIdMap = platDayDurationRecords.stream().collect(Collectors.groupingBy(PlatDayDurationRecord::getDeviceId));
deviceIdMap.entrySet().stream().map(vo -> {
List<PlatDayDurationRecord> value = vo.getValue();
int size = value.size();
......@@ -52,16 +52,16 @@ public class DayDurationUtil implements ApplicationRunner {
}
public void put(PlatDayDurationRecord platDayDurationRecord) {
RedisUtil.set(RedisConst.ELDER_DAY_DURATION_PREFIX + platDayDurationRecord.getOriDeviceId(), platDayDurationRecord);
RedisUtil.set(RedisConst.ELDER_DAY_DURATION_PREFIX + platDayDurationRecord.getDeviceId(), platDayDurationRecord);
}
public PlatDayDurationRecord get(String oriDeviceId) {
PlatDayDurationRecord platDayDurationRecord = RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
public PlatDayDurationRecord get(String platDeviceId) {
PlatDayDurationRecord platDayDurationRecord = RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + platDeviceId);
if(platDayDurationRecord==null){
//getAll();
}
return RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
return RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + platDeviceId);
}
/**
......
......@@ -29,7 +29,7 @@
</sql>
<select id="getDayMaxDurationList" resultType="com.makeit.entity.platform.alarm.PlatDayDurationRecord">
select
pddr.ori_device_id,
pddr.device_id,
pddr.day,
max(pddr.duration) as duration
from plat_day_duration_record pddr
......@@ -47,7 +47,7 @@
</foreach>
</if>
</where>
group by pddr.ori_device_id, pddr.day
group by pddr.device_id, pddr.day
order by duration
</select>
</mapper>
......@@ -83,44 +83,48 @@ public class PushCallback implements MqttCallback {
HeaderInfo headers = device.getHeaders();
List<HeaderInfo.Bind> bindings = headers.getBindings();
for (HeaderInfo.Bind binding : bindings) {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
JSONObject properties = device.getProperties();
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId+":"+iot_tenantId);
if(platDevice==null){
logger.error("获取设备信息异常,设备iot-id:"+deviceId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.error("该设备没有告警配置,设备iot-id:"+deviceId);
return;
}
for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType();
PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO();
//告警配置
platAlarmCheckDTO.setPlatAlarmConfig(config);
//设备信息
platAlarmCheckDTO.setPlatDevice(platDevice);
//iot上报数据
platAlarmCheckDTO.setProperties(properties);
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.checkConfig(platAlarmCheckDTO);
try {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
JSONObject properties = device.getProperties();
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId + ":" + iot_tenantId);
if (platDevice == null) {
logger.error("获取设备信息异常,设备iot-id,iot_tenantId:" + deviceId+","+iot_tenantId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.error("该设备没有告警配置,设备iot-id,iot_tenantId:" + deviceId+","+iot_tenantId);
return;
}
for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType();
PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO();
//告警配置
platAlarmCheckDTO.setPlatAlarmConfig(config);
//设备信息
platAlarmCheckDTO.setPlatDevice(platDevice);
//iot上报数据
platAlarmCheckDTO.setProperties(properties);
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.checkConfig(platAlarmCheckDTO);
}
}
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}catch (Exception e){
logger.error("告警异常pushCallback:",e);
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}
......
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