Commit 9f1f7f07 by 汪志阳

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

parents e4a85af3 3909acb0
...@@ -42,6 +42,10 @@ public class PlatDeviceBaseAttrDTO { ...@@ -42,6 +42,10 @@ public class PlatDeviceBaseAttrDTO {
private DeviceAttrRange radarAngle; private DeviceAttrRange radarAngle;
@ApiModelProperty(value = "雷达检测延迟时间 单位S ,范围:0-32768") @ApiModelProperty(value = "雷达检测延迟时间 单位S ,范围:0-32768")
private Integer radarDelay; private Integer radarDelay;
@ApiModelProperty(value = "雷达安装场景 0:客厅;1:卧室;2:卫生间")
private Integer radarSence;
@ApiModelProperty(value = "雷达灵敏度 0:灵敏;1:标准;2:鲁棒")
private Integer radarSPL;
@Data @Data
......
package com.makeit.service.platform.device; package com.makeit.service.platform.device;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.dto.BaseIdDTO; import com.makeit.common.dto.BaseIdDTO;
...@@ -94,5 +93,5 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -94,5 +93,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void devicePushLog(MultipartFile multipartFile, String deviceId) throws IOException; void devicePushLog(MultipartFile multipartFile, String deviceId) throws IOException;
void receiveIotProperties(String deviceId, JSONObject iotProperties); void syncIotProperties(String deviceId);
} }
...@@ -69,6 +69,7 @@ import com.makeit.shengwang.agora.service.ShengwangService; ...@@ -69,6 +69,7 @@ import com.makeit.shengwang.agora.service.ShengwangService;
import com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO; import com.makeit.shengwang.agora.vo.PlatAlarmCallDeviceVO;
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.JsonUtil;
import com.makeit.utils.data.convert.PageUtil; import com.makeit.utils.data.convert.PageUtil;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
...@@ -380,6 +381,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -380,6 +381,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
for (PlatDeviceOther platDeviceOther : platDeviceOtherList) { for (PlatDeviceOther platDeviceOther : platDeviceOtherList) {
BeanUtils.copyProperties(dto, platDeviceOther,"id"); BeanUtils.copyProperties(dto, platDeviceOther,"id");
platDeviceOther.setDeviceId(id); platDeviceOther.setDeviceId(id);
platDeviceOther.setAttribute(JSON.toJSONString(getDeviceBaseAttrDTO(db.getOriDeviceId())));
platDeviceOther.setOriDeviceId(db.getOriDeviceId()); platDeviceOther.setOriDeviceId(db.getOriDeviceId());
platDeviceOtherService.saveOrUpdate(platDeviceOther); platDeviceOtherService.saveOrUpdate(platDeviceOther);
} }
...@@ -836,11 +838,11 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -836,11 +838,11 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
public void active(BaseIdDTO dto) { public void active(BaseIdDTO dto) {
PlatDevice platDevice = getById(dto.getId()); PlatDevice platDevice = getById(dto.getId());
Map<String, Object> resMap = new HashMap<>(); Map<String, Object> resMap = new HashMap<>();
resMap.put("appid",shengwangProperties.getAppId()); /* resMap.put("appid",shengwangProperties.getAppId());
String AttrResult = devicePropertiesOperateService.deviceWriteAttr(platDevice.getOriDeviceId(), resMap); String AttrResult = devicePropertiesOperateService.deviceWriteAttr(platDevice.getOriDeviceId(), resMap);
if (StringUtils.isNotEmpty(AttrResult)) { if (StringUtils.isNotEmpty(AttrResult)) {
throw new RuntimeException(AttrResult); throw new RuntimeException(AttrResult);
} }*/
SaasPidManage saasPidManage = saasPidManageService.getOne(new QueryWrapper<SaasPidManage>().lambda() SaasPidManage saasPidManage = saasPidManageService.getOne(new QueryWrapper<SaasPidManage>().lambda()
.eq(SaasPidManage::getStatus, "1") .eq(SaasPidManage::getStatus, "1")
.orderByAsc(BaseEntity::getCreateDate) .orderByAsc(BaseEntity::getCreateDate)
...@@ -931,45 +933,9 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -931,45 +933,9 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
} }
@Override @Override
@TenantIdIgnore
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void receiveIotProperties(String deviceId, JSONObject iotProperties) { public void syncIotProperties(String deviceId) {
PlatDeviceOther deviceOther = platDeviceOtherService.getOne(new QueryWrapper<PlatDeviceOther>().lambda() PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = getDeviceBaseAttrDTO(deviceId);
.eq(PlatDeviceOther::getOriDeviceId, deviceId)
.last("limit 1"));
if (deviceOther == null) {
log.warn("iot修改属性回复,设备其他信息不存在,设备id:{}", deviceId);
return;
}
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = JSON.parseObject(deviceOther.getAttribute(), PlatDeviceBaseAttrDTO.class);
if (platDeviceBaseAttrDTO == null) {
platDeviceBaseAttrDTO = new PlatDeviceBaseAttrDTO();
}
PlatDeviceBaseAttrDTO iotAttr = iotProperties.toJavaObject(PlatDeviceBaseAttrDTO.class);
if (iotAttr.getRadarMode() != null && !Objects.equals(platDeviceBaseAttrDTO.getRadarMode(), iotAttr.getRadarMode())) {
platDeviceBaseAttrDTO.setRadarMode(iotAttr.getRadarMode());
}
if (iotAttr.getRadarMount() != null && !Objects.equals(platDeviceBaseAttrDTO.getRadarMount(), iotAttr.getRadarMount())) {
platDeviceBaseAttrDTO.setRadarMount(iotAttr.getRadarMount());
}
if (iotAttr.getRadarHight() != null && !Objects.equals(platDeviceBaseAttrDTO.getRadarHight(), iotAttr.getRadarHight())) {
platDeviceBaseAttrDTO.setRadarHight(iotAttr.getRadarHight());
}
if (iotAttr.getRadarDelay() != null && !Objects.equals(platDeviceBaseAttrDTO.getRadarDelay(), iotAttr.getRadarDelay())) {
platDeviceBaseAttrDTO.setRadarDelay(iotAttr.getRadarDelay());
}
PlatDeviceBaseAttrDTO.DeviceAttrRange radarDistance = platDeviceBaseAttrDTO.getRadarDistance();
if (iotAttr.getRadarDistance() != null && !Objects.equals(radarDistance, iotAttr.getRadarDistance())) {
if (radarDistance != null && radarDistance.getMax() != null && radarDistance.getMin() != null) {
platDeviceBaseAttrDTO.setRadarDistance(iotAttr.getRadarDistance());
}
}
PlatDeviceBaseAttrDTO.DeviceAttrRange radarAngle = platDeviceBaseAttrDTO.getRadarAngle();
if (iotAttr.getRadarAngle() != null && !Objects.equals(radarAngle, iotAttr.getRadarAngle())) {
if (radarAngle != null && radarAngle.getMax() != null && radarAngle.getMin() != null) {
platDeviceBaseAttrDTO.setRadarAngle(iotAttr.getRadarAngle());
}
}
String attr = JSON.toJSONString(platDeviceBaseAttrDTO); String attr = JSON.toJSONString(platDeviceBaseAttrDTO);
platDeviceOtherService.update(new UpdateWrapper<PlatDeviceOther>().lambda() platDeviceOtherService.update(new UpdateWrapper<PlatDeviceOther>().lambda()
.set(PlatDeviceOther::getAttribute, attr) .set(PlatDeviceOther::getAttribute, attr)
...@@ -983,4 +949,15 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -983,4 +949,15 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
} }
} }
private PlatDeviceBaseAttrDTO getDeviceBaseAttrDTO(String deviceId) {
String propertiesName = "radarMount,radarMode,radarHight,radarDistance,radarAngle,radarDelay,radarSence,radarSPL";
PlatDeviceAttrWechatDTO dto = new PlatDeviceAttrWechatDTO();
dto.setDeviceId(deviceId);
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));
PlatDeviceBaseAttrDTO platDeviceBaseAttrDTO = JsonUtil.mapToBean(attrMap, PlatDeviceBaseAttrDTO.class);
return platDeviceBaseAttrDTO;
}
} }
...@@ -232,7 +232,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -232,7 +232,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
boolean spaceNoPersonFlag = false; boolean spaceNoPersonFlag = false;
for (PlatDevice device : spaceDeviceList) { for (PlatDevice device : spaceDeviceList) {
// 无人
Set<String> dataSet = redisTemplate.opsForZSet().rangeByScore(DEVICE_SPACE_TEMP_DATA + platDevice.getOriDeviceId(), currentSecond - 10, currentSecond); Set<String> dataSet = redisTemplate.opsForZSet().rangeByScore(DEVICE_SPACE_TEMP_DATA + platDevice.getOriDeviceId(), currentSecond - 10, currentSecond);
if (CollectionUtils.isEmpty(dataSet)) { if (CollectionUtils.isEmpty(dataSet)) {
log.info("空间设备当前没有上报数据直接返回"); log.info("空间设备当前没有上报数据直接返回");
...@@ -279,7 +278,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -279,7 +278,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
} }
boolean fallNoPersonFlag = false; boolean fallNoPersonFlag = false;
for (PlatDevice device : fallDeviceList) { for (PlatDevice device : fallDeviceList) {
// 无人
Set<String> dataSet = redisTemplate.opsForZSet().rangeByScore(DEVICE_FALL_TEMP_DATA + platDevice.getOriDeviceId(), currentSecond - 10, currentSecond); Set<String> dataSet = redisTemplate.opsForZSet().rangeByScore(DEVICE_FALL_TEMP_DATA + platDevice.getOriDeviceId(), currentSecond - 10, currentSecond);
if (CollectionUtils.isEmpty(dataSet)) { if (CollectionUtils.isEmpty(dataSet)) {
log.info("跌倒设备当前没有上报数据直接返回"); log.info("跌倒设备当前没有上报数据直接返回");
......
...@@ -18,7 +18,6 @@ import com.makeit.service.platform.device.PlatDeviceService; ...@@ -18,7 +18,6 @@ import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.SaasSleepAnalysisModelService; import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.AlarmConfigCacheUtil; import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil; import com.makeit.utils.DeviceCacheUtil;
import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback; import org.eclipse.paho.client.mqttv3.MqttCallback;
...@@ -36,7 +35,6 @@ import javax.annotation.Resource; ...@@ -36,7 +35,6 @@ import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -119,26 +117,13 @@ public class PushCallback implements MqttCallback { ...@@ -119,26 +117,13 @@ public class PushCallback implements MqttCallback {
* IOT端设备属性修改后同步 * IOT端设备属性修改后同步
* @param device * @param device
*/ */
@TenantIdIgnore
@Async
public void syncProperties(DeviceInfo device) { public void syncProperties(DeviceInfo device) {
if (!(WRITE_PROPERTY.equals(device.getMessageType()) || WRITE_PROPERTY_REPLY.equals(device.getMessageType()))) { if (!WRITE_PROPERTY.equals(device.getMessageType())) {
return; return;
} }
// 记录修改的属性 platDeviceService.syncIotProperties(device.getDeviceId());
String key = DEVICE_WRITE_PROPERTY_KEY + device.getDeviceId();
if (WRITE_PROPERTY.equals(device.getMessageType())) {
RedisUtil.set(key, device.getProperties(), 10, TimeUnit.SECONDS);
}
// 收到修改属性回复
if (WRITE_PROPERTY_REPLY.equals(device.getMessageType())) {
JSONObject properties = RedisUtil.get(key);
if (properties == null) {
return;
}
CompletableFuture.runAsync(() -> {
platDeviceService.receiveIotProperties(device.getDeviceId(), properties);
RedisUtil.delete(key);
});
}
} }
/** /**
...@@ -153,7 +138,7 @@ public class PushCallback implements MqttCallback { ...@@ -153,7 +138,7 @@ public class PushCallback implements MqttCallback {
List<HeaderInfo.Bind> bindings = headers.getBindings(); List<HeaderInfo.Bind> bindings = headers.getBindings();
Long timestamp = device.getTimestamp(); Long timestamp = device.getTimestamp();
long currentSecond = timestamp / 1000; long currentSecond = System.currentTimeMillis() / 1000;
// 先通过产品名称判断 // 先通过产品名称判断
if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("呼吸")) { if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("呼吸")) {
cacheBrDeviceData(device, currentSecond); cacheBrDeviceData(device, currentSecond);
...@@ -235,7 +220,7 @@ public class PushCallback implements MqttCallback { ...@@ -235,7 +220,7 @@ public class PushCallback implements MqttCallback {
long maxSize = 10L; long maxSize = 10L;
String key = deviceSpaceTempData + device.getDeviceId(); String key = deviceSpaceTempData + device.getDeviceId();
redisTemplate.opsForZSet().add(key,JSON.toJSONString(device),currentSecond); redisTemplate.opsForZSet().add(key,JSON.toJSONString(device),currentSecond);
redisTemplate.expire(key,maxSize + 1,TimeUnit.MINUTES); redisTemplate.expire(key,60,TimeUnit.SECONDS);
} }
private void cacheBrDeviceData(DeviceInfo device, long currentSecond) { private void cacheBrDeviceData(DeviceInfo device, long currentSecond) {
...@@ -243,7 +228,7 @@ public class PushCallback implements MqttCallback { ...@@ -243,7 +228,7 @@ public class PushCallback implements MqttCallback {
String key = DEVICE_BR_ANALYSIS + device.getDeviceId(); String key = DEVICE_BR_ANALYSIS + device.getDeviceId();
long duration = getSleepTimeActionDuration(); long duration = getSleepTimeActionDuration();
redisTemplate.opsForZSet().add(key,JSON.toJSONString(device),currentSecond); redisTemplate.opsForZSet().add(key,JSON.toJSONString(device),currentSecond);
redisTemplate.expire(key,duration + 3,TimeUnit.MINUTES); redisTemplate.expire(key,duration + 180,TimeUnit.SECONDS);
} }
private Long getSleepTimeActionDuration() { private Long getSleepTimeActionDuration() {
......
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