Commit 5bb04d98 by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 41fca5ac 9d66f86f
......@@ -134,7 +134,8 @@ public class OffBedAlarm implements IAlarm {
boolean over = (Math.abs(Duration.between(LocalDateTime.now(), startTime).toMillis())) / 1000 >= duration * 60;
if (over) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(localDateLong - firstOffBedLong));
log.info("离床告警离床时间在范围前,发送预警");
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("离床告警离床时间在范围前,发送预警,配置:{}", config);
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
return;
}
......@@ -145,7 +146,8 @@ public class OffBedAlarm implements IAlarm {
boolean isInRange = LocalDateTime.now().isAfter(startTime) && LocalDateTime.now().isBefore(endTime);
if (isOffBedValid && isInRange && isOverTime) {
platAlarmCheckDTO.setAbnormalValue(String.valueOf(localDateLong - firstOffBedLong));
log.info("离床告警离床时间在范围时间内(小于范围结束时间-持续分钟)");
platAlarmCheckDTO.setPlatAlarmConfig(config);
log.info("离床告警离床时间在范围时间内(小于范围结束时间-持续分钟),配置:{}", config);
noticeAlarm(alarmRedisDTO, platAlarmCheckDTO, deviceId);
return;
}
......
......@@ -38,6 +38,7 @@ import com.makeit.entity.saas.PlatTenant;
import com.makeit.entity.saas.SaasPidManage;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.device.PlatDeviceEnum;
import com.makeit.enums.report.DeviceNameEnum;
import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
......@@ -381,7 +382,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
for (PlatDeviceOther platDeviceOther : platDeviceOtherList) {
BeanUtils.copyProperties(dto, platDeviceOther,"id");
platDeviceOther.setDeviceId(id);
platDeviceOther.setAttribute(JSON.toJSONString(getDeviceBaseAttrDTO(db.getOriDeviceId())));
platDeviceOther.setAttribute(JSON.toJSONString(getDeviceBaseAttrDTO(db)));
platDeviceOther.setOriDeviceId(db.getOriDeviceId());
platDeviceOtherService.saveOrUpdate(platDeviceOther);
}
......@@ -939,9 +940,16 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
@Override
@TenantIdIgnore
@Transactional(rollbackFor = Exception.class)
public void syncIotProperties(String deviceId) {
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = getDeviceBaseAttrDTO(deviceId);
PlatDevice device = getOne(new QueryWrapper<PlatDevice>().lambda()
.eq(PlatDevice::getOriDeviceId, deviceId));
if (device == null) {
log.warn("iot属性同步,设备不存在,设备id:{}", deviceId);
return;
}
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = getDeviceBaseAttrDTO(device);
String attr = JSON.toJSONString(platDeviceBaseAttrDTO);
platDeviceOtherService.update(new UpdateWrapper<PlatDeviceOther>().lambda()
.set(PlatDeviceOther::getAttribute, attr)
......@@ -955,10 +963,22 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
}
private PlatDeviceBaseAttrDTO getDeviceBaseAttrDTO(String deviceId) {
String propertiesName = "radarMount,radarMode,radarHight,radarDistance,radarAngle,radarDelay,radarSence,radarSPL";
private PlatDeviceBaseAttrDTO getDeviceBaseAttrDTO(PlatDevice platDevice) {
String category = platDevice.getCategory();
if (!(PlatDeviceEnum.CategoryEnum.FALL.getValue().equals(category) || PlatDeviceEnum.CategoryEnum.SPACE.getValue().equals(category))) {
return new PlatDeviceBaseAttrDTO();
}
String propertiesName = "";
// 跌倒
if (PlatDeviceEnum.CategoryEnum.FALL.getValue().equals(category)) {
propertiesName = "radarMount,radarHight,radarSence,radarSPL";
}
// 空间人体
if (PlatDeviceEnum.CategoryEnum.SPACE.getValue().equals(category)) {
propertiesName = "radarMount,radarMode,radarDistance,radarAngle,radarDelay";
}
PlatDeviceAttrWechatDTO dto = new PlatDeviceAttrWechatDTO();
dto.setDeviceId(deviceId);
dto.setDeviceId(platDevice.getOriDeviceId());
dto.setReadProperties(propertiesName);
List<DeviceProperties> data = this.readDeviceProperties(dto);
Map<String, Object> attrMap = data.stream().filter(p -> !Objects.isNull(p.getValue())).collect(Collectors.toMap(DeviceProperties::getProperty, DeviceProperties::getValue));
......
......@@ -18,7 +18,9 @@ import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil;
import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
......@@ -35,6 +37,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
......@@ -117,13 +120,33 @@ public class PushCallback implements MqttCallback {
* IOT端设备属性修改后同步
* @param device
*/
@TenantIdIgnore
@Async
public void syncProperties(DeviceInfo device) {
if (!WRITE_PROPERTY.equals(device.getMessageType())) {
if (!(WRITE_PROPERTY.equals(device.getMessageType()) || WRITE_PROPERTY_REPLY.equals(device.getMessageType()))) {
return;
}
// 记录修改的属性
String key = DEVICE_WRITE_PROPERTY_KEY + device.getDeviceId();
if (WRITE_PROPERTY.equals(device.getMessageType())) {
JSONObject properties = device.getProperties();
String value = properties.keySet().stream().findFirst().orElse("value");
RedisUtil.set(key, value, 10, TimeUnit.SECONDS);
}
// 收到修改属性回复
if (WRITE_PROPERTY_REPLY.equals(device.getMessageType())) {
String value = RedisUtil.get(key);
if (StringUtils.isBlank(value)) {
return;
}
//platDeviceService.syncIotProperties(device.getDeviceId());
JSONObject properties = device.getProperties();
int success = properties.getIntValue(value);
if (success != 0) {
return;
}
CompletableFuture.runAsync(() -> {
platDeviceService.syncIotProperties(device.getDeviceId());
RedisUtil.delete(key);
}); // 要加线程池
}
}
/**
......
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