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