Commit f3e2ab89 by 杨伟程
parents 70a07a6f e904c2bc
Showing with 146 additions and 58 deletions
...@@ -11,6 +11,7 @@ import com.makeit.entity.platform.device.PlatDevice; ...@@ -11,6 +11,7 @@ import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.SaasOperationLogService; import com.makeit.service.saas.SaasOperationLogService;
import com.makeit.vo.platform.device.PlatDeviceListVO;
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;
...@@ -31,7 +32,7 @@ public class SaasDeviceController { ...@@ -31,7 +32,7 @@ public class SaasDeviceController {
@ApiOperation("列表") @ApiOperation("列表")
@PostMapping("page") @PostMapping("page")
@TenantIdIgnore @TenantIdIgnore
public ApiResponseEntity<PageVO<PlatDevice>> page(@RequestBody PageReqDTO<PlatDevice> pageReqDTO) { public ApiResponseEntity<PageVO<PlatDeviceListVO>> page(@RequestBody PageReqDTO<PlatDevice> pageReqDTO) {
return ApiResponseUtils.success(platDeviceService.pageSaas(pageReqDTO)); return ApiResponseUtils.success(platDeviceService.pageSaas(pageReqDTO));
} }
......
...@@ -50,6 +50,8 @@ public class PlatAuthorizationInterceptor implements HandlerInterceptor { ...@@ -50,6 +50,8 @@ public class PlatAuthorizationInterceptor implements HandlerInterceptor {
Set<String> codeSet = new HashSet<>(); Set<String> codeSet = new HashSet<>();
if(userLoginVO!= null && CollectionUtils.isNotEmpty(userLoginVO.getButtonCodeList())) { if(userLoginVO!= null && CollectionUtils.isNotEmpty(userLoginVO.getButtonCodeList())) {
codeSet = new HashSet<>(userLoginVO.getButtonCodeList()); codeSet = new HashSet<>(userLoginVO.getButtonCodeList());
}else {
return true;
} }
for (String e : annotation.code()) { for (String e : annotation.code()) {
......
...@@ -22,7 +22,7 @@ public class PlatAlarmConfigHeartDTOVO { ...@@ -22,7 +22,7 @@ public class PlatAlarmConfigHeartDTOVO {
private Integer heartRateStart; private Integer heartRateStart;
@ApiModelProperty("心率正常范围结束") @ApiModelProperty("心率正常范围结束")
private Integer heartRateEnd; private Integer heartRateeEnd;
@ApiModelProperty("异常持续时间") @ApiModelProperty("异常持续时间")
private Integer duration; private Integer duration;
......
package com.makeit.dto.platform.auth;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PlatOrgSplitDTO {
@ApiModelProperty(value = "部门树id")
private String orgId;
@ApiModelProperty(value = "城市组织id")
private String cityOrgId;
@ApiModelProperty(value = "区组织id")
private String districtOrgId;
@ApiModelProperty(value = "街道组织id")
private String streetOrgId;
@ApiModelProperty(value = "组织路径")
private String orgPath;
}
...@@ -76,7 +76,7 @@ public class BehaviorAlarm implements IAlarm { ...@@ -76,7 +76,7 @@ public class BehaviorAlarm implements IAlarm {
Integer duration = ruleConfig.getDuration();//分钟 Integer duration = ruleConfig.getDuration();//分钟
PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(platDevice.getOriDeviceId()); PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(platDevice.getOriDeviceId());
if (platDayDurationRecord == null) { if (platDayDurationRecord == null) {
log.error("行为告警未找到行为异常平均时长,设备id:" + platDevice.getId()); log.error("行为告警未找到行为异常平均时长,设备plat_id:" + platDevice.getId());
return; return;
} }
Long duration1 = platDayDurationRecord.getDuration(); Long duration1 = platDayDurationRecord.getDuration();
...@@ -99,13 +99,13 @@ public class BehaviorAlarm implements IAlarm { ...@@ -99,13 +99,13 @@ public class BehaviorAlarm implements IAlarm {
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
log.error("空间雷达上报进入房间,设备id:" + platDevice.getId()); log.error("空间雷达上报进入房间,设备plat_id:" + platDevice.getId());
return; return;
} }
long count = endLong - startLong; long count = endLong - startLong;
//进入空间时间满足告警时长,判断是否已经告警过了 //进入空间时间满足告警时长,判断是否已经告警过了
if (count / 1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) { if (count / 1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
log.error("空间雷达发出告警,设备id:" + platDevice.getId()); log.error("空间雷达发出告警,设备plat_id:" + platDevice.getId());
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue()); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
......
...@@ -85,14 +85,14 @@ public class BreathAlarm implements IAlarm { ...@@ -85,14 +85,14 @@ public class BreathAlarm implements IAlarm {
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId,alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId,alarmRedisDTO);
log.error("发现长者呼吸异常,设备id:"+deviceId); log.error("发现长者呼吸异常,设备plat_id:"+deviceId);
return; return;
} }
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong; long count = endLong - startLong;
if (count/1000 >= duration) { if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) { if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.error("呼吸已告警,设备id:" + platDevice.getId()); log.error("呼吸已告警,设备plat_id:" + platDevice.getId());
return; return;
} }
fillRemark(platAlarmCheckDTO, br, start, end); fillRemark(platAlarmCheckDTO, br, start, end);
......
...@@ -66,7 +66,7 @@ public class FallAlarm implements IAlarm { ...@@ -66,7 +66,7 @@ public class FallAlarm implements IAlarm {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) { if (CollectionUtils.isEmpty(platElderList)) {
log.error("跌倒设备未关联长者,设备id:" + platDevice.getId()); log.error("跌倒设备未关联长者,设备plat_id:" + platDevice.getId());
return; return;
} }
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom(); PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
......
...@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder; ...@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.enums.CommonEnum; import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.exception.BusinessException;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO; import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
...@@ -55,7 +56,7 @@ public class HeartAlarm implements IAlarm { ...@@ -55,7 +56,7 @@ public class HeartAlarm implements IAlarm {
int hr = (int) properties.get("hr"); int hr = (int) properties.get("hr");
PlatAlarmConfigHeartDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigHeartDTOVO.class); PlatAlarmConfigHeartDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigHeartDTOVO.class);
Integer start = ruleConfig.getHeartRateStart(); Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd(); Integer end = ruleConfig.getHeartRateeEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
Date now = new Date(); Date now = new Date();
long endLong = now.getTime(); long endLong = now.getTime();
...@@ -75,7 +76,7 @@ public class HeartAlarm implements IAlarm { ...@@ -75,7 +76,7 @@ public class HeartAlarm implements IAlarm {
alarmRedisDTO.setStart(now); alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong); alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId,alarmRedisDTO); RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId,alarmRedisDTO);
log.error("发现长者心率异常,设备id:"+deviceId); log.error("发现长者心率异常,设备iot_id:"+deviceId);
return; return;
} }
Long startLong = alarmRedisDTO.getStartLong(); Long startLong = alarmRedisDTO.getStartLong();
...@@ -84,7 +85,7 @@ public class HeartAlarm implements IAlarm { ...@@ -84,7 +85,7 @@ public class HeartAlarm implements IAlarm {
//todo 如果每台服务器都能收到上报消息 加redis锁 //todo 如果每台服务器都能收到上报消息 加redis锁
//RLock lock = RedisLockUtil.lock(RedisConst.LOCK_ALARM + deviceId); //RLock lock = RedisLockUtil.lock(RedisConst.LOCK_ALARM + deviceId);
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) { if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.error("心率已告警,设备id:" + platDevice.getId()); log.error("心率已告警,设备plat_id:" + platDevice.getId());
return; return;
} }
fillRemark(platAlarmCheckDTO, hr, start, end); fillRemark(platAlarmCheckDTO, hr, start, end);
...@@ -116,8 +117,7 @@ public class HeartAlarm implements IAlarm { ...@@ -116,8 +117,7 @@ public class HeartAlarm implements IAlarm {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice(); PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) { if (CollectionUtils.isEmpty(platElderList)) {
log.error("心率设备未关联长者,设备id:" + platAlarmCheckDTO.getPlatDevice().getId()); throw new BusinessException("心率设备未关联长者,设备plat_id:" + platAlarmCheckDTO.getPlatDevice().getId());
return;
} }
for (PlatElder platElder : platElderList) { for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>(); List<String> param = new ArrayList<>();
...@@ -128,7 +128,7 @@ public class HeartAlarm implements IAlarm { ...@@ -128,7 +128,7 @@ public class HeartAlarm implements IAlarm {
platAlarmRecord.setElderIds(platElder.getId()); platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName()); platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord); platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
log.error("长者心率异常,发出告警,设备id:"+platDevice.getId()+", 长者名称:"+platElder.getName()); log.error("长者心率异常,发出告警,设备plat_id:"+platDevice.getId()+", 长者名称:"+platElder.getName());
} }
} }
} }
...@@ -381,7 +381,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -381,7 +381,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
.eq(BaseBusEntity::getTenantId,tenantId) .eq(BaseBusEntity::getTenantId,tenantId)
; ;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper); List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
platAlarmCheckDTO.setPlatElderList(list); if(CollectionUtils.isNotEmpty(list)) {
platAlarmCheckDTO.setPlatElderList(list);
return;
}
} }
String roomId = platRoomBedDevice.getRoomId(); String roomId = platRoomBedDevice.getRoomId();
......
...@@ -4,6 +4,7 @@ package com.makeit.service.platform.auth; ...@@ -4,6 +4,7 @@ package com.makeit.service.platform.auth;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO; import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.vo.platform.auth.PlatOrgQueryDTO; import com.makeit.vo.platform.auth.PlatOrgQueryDTO;
...@@ -98,4 +99,11 @@ public interface PlatOrgService extends IService<PlatOrg> { ...@@ -98,4 +99,11 @@ public interface PlatOrgService extends IService<PlatOrg> {
List<PlatOrg> createOrgTree(List<PlatOrg> orgList); List<PlatOrg> createOrgTree(List<PlatOrg> orgList);
List<PlatOrg> belongToScopeList(PlatOrg param); List<PlatOrg> belongToScopeList(PlatOrg param);
/**
* 获取orgId 的 城市|区|街道 id
* @param orgId
* @return
*/
PlatOrgSplitDTO getOrgSplitVO(String orgId);
} }
...@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO; import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatRoleOrg; import com.makeit.entity.platform.auth.PlatRoleOrg;
import com.makeit.entity.platform.auth.PlatUserRole; import com.makeit.entity.platform.auth.PlatUserRole;
...@@ -46,6 +47,7 @@ import java.util.List; ...@@ -46,6 +47,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -607,4 +609,29 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg> ...@@ -607,4 +609,29 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
platAlarmConfigService.copyForOrg(platOrg); platAlarmConfigService.copyForOrg(platOrg);
} }
@Override
public PlatOrgSplitDTO getOrgSplitVO(String orgId) {
PlatOrgSplitDTO platOrgSplitDTO = new PlatOrgSplitDTO();
platOrgSplitDTO.setOrgId(orgId);
PlatOrg platOrg = getById(orgId);
if (platOrg == null) {
return platOrgSplitDTO;
}
String orgPath = platOrg.getPath();
if (StringUtils.isBlank(orgPath)) {
return platOrgSplitDTO;
}
List<BiConsumer<PlatOrgSplitDTO, String>> list = Arrays.asList(
PlatOrgSplitDTO::setCityOrgId,
PlatOrgSplitDTO::setDistrictOrgId,
PlatOrgSplitDTO::setStreetOrgId
);
String[] split = orgPath.split(",");
for (int i = 1; i < split.length; i++) {
BiConsumer<PlatOrgSplitDTO, String> e = list.get(i - 1);
e.accept(platOrgSplitDTO, split[i]);
}
return platOrgSplitDTO;
}
} }
...@@ -443,7 +443,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> ...@@ -443,7 +443,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
String button = SysEnum.MenuTypeEnum.BUTTON.getValue(); String button = SysEnum.MenuTypeEnum.BUTTON.getValue();
menuList.forEach(e -> { menuList.forEach(e -> {
if (menu.equals(e.getCategory()) || button.equals(e.getCategory())) { if ( button.equals(e.getCategory())) {
buttonList.add(e); buttonList.add(e);
} }
......
...@@ -42,7 +42,7 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -42,7 +42,7 @@ public interface PlatDeviceService extends IService<PlatDevice> {
* @param pageReqDTO * @param pageReqDTO
* @return * @return
*/ */
PageVO<PlatDevice> pageSaas(PageReqDTO<PlatDevice> pageReqDTO); PageVO<PlatDeviceListVO> pageSaas(PageReqDTO<PlatDevice> pageReqDTO);
/** /**
* 设备信息 * 设备信息
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseTenantDTO;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
...@@ -25,6 +26,7 @@ import com.makeit.module.iot.service.IotDevicePropertiesOperateService; ...@@ -25,6 +26,7 @@ import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.device.PlatDeviceOtherService; import com.makeit.service.platform.device.PlatDeviceOtherService;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.DeviceCacheUtil; import com.makeit.utils.DeviceCacheUtil;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.PageUtil; import com.makeit.utils.data.convert.PageUtil;
...@@ -60,6 +62,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -60,6 +62,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private DeviceCacheUtil deviceCacheUtil; private DeviceCacheUtil deviceCacheUtil;
@Autowired @Autowired
private IotDevicePropertiesOperateService devicePropertiesOperateService; private IotDevicePropertiesOperateService devicePropertiesOperateService;
@Autowired
private PlatTenantService platTenantService;
@Override @Override
public PageVO<PlatDeviceListVO> page(PageReqDTO<PlatDeviceQueryDTO> pageReqDTO) { public PageVO<PlatDeviceListVO> page(PageReqDTO<PlatDeviceQueryDTO> pageReqDTO) {
...@@ -195,12 +199,17 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -195,12 +199,17 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
} }
@Override @Override
public PageVO<PlatDevice> pageSaas(PageReqDTO<PlatDevice> pageReqDTO) { public PageVO<PlatDeviceListVO> pageSaas(PageReqDTO<PlatDevice> pageReqDTO) {
PlatDevice param = pageReqDTO.getData(); PlatDevice param = pageReqDTO.getData();
Page<PlatDevice> page = PageUtil.toMpPage(pageReqDTO); Page<PlatDevice> page = PageUtil.toMpPage(pageReqDTO);
LambdaQueryWrapper<PlatDevice> lambdaQueryWrapper = getLambdaQueryWrapper(param); LambdaQueryWrapper<PlatDevice> lambdaQueryWrapper = getLambdaQueryWrapper(param);
Page<PlatDevice> devicePage = page(page, lambdaQueryWrapper); Page<PlatDevice> devicePage = page(page, lambdaQueryWrapper);
return PageUtil.toPageVO(devicePage); List<PlatDevice> records = devicePage.getRecords();
List<PlatDeviceListVO> platDeviceListVOS = BeanDtoVoUtils.listVo(records, PlatDeviceListVO.class);
JoinUtil.join(platDeviceListVOS,platTenantService, BaseTenantDTO::getTenantId,BaseEntity::getId,(d,o)->{
d.setTenantName(o.getName());
});
return PageUtil.toPageVO(platDeviceListVOS,devicePage);
} }
@Override @Override
......
...@@ -2,10 +2,12 @@ package com.makeit.utils; ...@@ -2,10 +2,12 @@ package com.makeit.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.entity.saas.PlatTenant;
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.module.iot.enums.DeviceState;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -21,6 +23,8 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -21,6 +23,8 @@ public class DeviceCacheUtil implements ApplicationRunner {
@Autowired @Autowired
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
@Autowired
private PlatTenantService platTenantService;
public List<PlatDevice> getAll() { public List<PlatDevice> getAll() {
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue())); List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue()));
...@@ -31,19 +35,20 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -31,19 +35,20 @@ public class DeviceCacheUtil implements ApplicationRunner {
} }
public void put(PlatDevice platDevice) { public void put(PlatDevice platDevice) {
PlatTenant platTenant = platTenantService.getById(platDevice.getTenantId());
if(StringUtils.equals(platDevice.getStatus(),DeviceState.online.getValue())) { if(StringUtils.equals(platDevice.getStatus(),DeviceState.online.getValue())) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId(), platDevice); RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId()+":"+platTenant.getIotOrgId(), platDevice);
}else { }else {
RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId()); RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId()+":"+platTenant.getIotOrgId());
} }
} }
public PlatDevice get(String oriDeviceId) { public PlatDevice get(String oriDeviceIdAndIotOrgId) {
PlatDevice platDevice = RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceId); PlatDevice platDevice = RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceIdAndIotOrgId);
if(platDevice==null){ if(platDevice==null){
getAll(); getAll();
} }
return RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceId); return RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceIdAndIotOrgId);
} }
public void putAll(Collection<PlatDevice> platDeviceList) { public void putAll(Collection<PlatDevice> platDeviceList) {
platDeviceList.forEach(vo -> { platDeviceList.forEach(vo -> {
......
...@@ -74,4 +74,7 @@ public class PlatDeviceListVO extends BaseTenantDTO { ...@@ -74,4 +74,7 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private LocalDateTime endDate; private LocalDateTime endDate;
private String tenantName;
} }
...@@ -7,6 +7,7 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig; ...@@ -7,6 +7,7 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.vo.DeviceInfo; import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.module.iot.vo.HeaderInfo;
import com.makeit.service.platform.alarm.alarmStrategy.IAlarm; import com.makeit.service.platform.alarm.alarmStrategy.IAlarm;
import com.makeit.utils.AlarmConfigCacheUtil; import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil; import com.makeit.utils.DeviceCacheUtil;
...@@ -79,43 +80,49 @@ public class PushCallback implements MqttCallback { ...@@ -79,43 +80,49 @@ public class PushCallback implements MqttCallback {
@TenantIdIgnore @TenantIdIgnore
@Async @Async
public void checkAlarm(DeviceInfo device) { public void checkAlarm(DeviceInfo device) {
StopWatch stopWatch = new StopWatch(); HeaderInfo headers = device.getHeaders();
stopWatch.start("checkAlarm-1"); List<HeaderInfo.Bind> bindings = headers.getBindings();
String deviceId = device.getDeviceId(); for (HeaderInfo.Bind binding : bindings) {
String iot_tenantId = binding.getId();
JSONObject properties = device.getProperties(); StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
//iot设备id String deviceId = device.getDeviceId();
PlatDevice platDevice = deviceCacheUtil.get(deviceId);
if(platDevice==null){ JSONObject properties = device.getProperties();
logger.error("设备信息异常,设备iot-id:"+deviceId);
return; //iot设备id
} PlatDevice platDevice = deviceCacheUtil.get(deviceId+":"+iot_tenantId);
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice); if(platDevice==null){
deviceAlarmConfigList.removeIf(Objects::isNull); logger.error("获取设备信息异常,设备iot-id:"+deviceId);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) { return;
logger.error("该设备没有告警配置:"+deviceId); }
return; List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
} deviceAlarmConfigList.removeIf(Objects::isNull);
for (PlatAlarmConfig config : deviceAlarmConfigList) { if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
String alarmType = config.getAlarmType(); logger.error("该设备没有告警配置,设备iot-id:"+deviceId);
return;
PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO(); }
//告警配置 for (PlatAlarmConfig config : deviceAlarmConfigList) {
platAlarmCheckDTO.setPlatAlarmConfig(config); String alarmType = config.getAlarmType();
//设备信息
platAlarmCheckDTO.setPlatDevice(platDevice); PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO();
//iot上报数据 //告警配置
platAlarmCheckDTO.setProperties(properties); platAlarmCheckDTO.setPlatAlarmConfig(config);
//设备信息
for (IAlarm alarm : alarmList) { platAlarmCheckDTO.setPlatDevice(platDevice);
if (alarm.support(alarmType)) { //iot上报数据
alarm.checkConfig(platAlarmCheckDTO); platAlarmCheckDTO.setProperties(properties);
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.checkConfig(platAlarmCheckDTO);
}
} }
} }
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
} }
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