|
@@ -13,14 +13,14 @@ import com.hfln.portal.common.dto.data.event.AlarmEventDTO;
|
|
|
import com.hfln.portal.common.dto.data.event.EventListDTO;
|
|
|
import com.hfln.portal.common.dto.data.home.HomeInfoDTO;
|
|
|
import com.hfln.portal.common.dto.data.oss.OssFileDTO;
|
|
|
-import com.hfln.portal.common.dto.data.room.RegionInfo;
|
|
|
-import com.hfln.portal.common.dto.data.room.RoomDto;
|
|
|
+import com.hfln.portal.common.dto.data.room.RegionDTO;
|
|
|
+import com.hfln.portal.common.dto.data.room.RoomDTO;
|
|
|
+import com.hfln.portal.common.dto.data.room.SubRegionDTO;
|
|
|
import com.hfln.portal.common.dto.data.share.ShareDto;
|
|
|
-import com.hfln.portal.common.request.device.DeviceBandingParams;
|
|
|
-import com.hfln.portal.common.request.device.DeviceListParams;
|
|
|
-import com.hfln.portal.common.request.device.DeviceLocationParams;
|
|
|
-import com.hfln.portal.common.request.device.DeviceTransferParams;
|
|
|
+import com.hfln.portal.common.request.device.*;
|
|
|
import com.hfln.portal.common.request.event.EventListParams;
|
|
|
+import com.hfln.portal.common.request.room.RoomParam;
|
|
|
+import com.hfln.portal.common.request.room.SubRegionInfo;
|
|
|
import com.hfln.portal.common.request.share.ShareConfirmParam;
|
|
|
import com.hfln.portal.common.request.share.ShareParam;
|
|
|
import com.hfln.portal.common.request.share.updateShareParam;
|
|
@@ -47,7 +47,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -259,17 +258,11 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
Map<String, BigDecimal> z_cm = new HashMap<>();
|
|
|
z_cm.put("z_cm", request.getHeight());
|
|
|
|
|
|
- //构建呼吸灯
|
|
|
- int indicatorLed = 0;
|
|
|
- if (request.getStatusLight() == 0){
|
|
|
- indicatorLed = 1;
|
|
|
- }
|
|
|
|
|
|
//发送最终消息
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("ext_region", baseParent);
|
|
|
jsonObject.put("sensor_location", z_cm);
|
|
|
- jsonObject.put("indicator_led", indicatorLed);
|
|
|
|
|
|
try {
|
|
|
mqttClient.sendMessage(topic, jsonObject.toJSONString());
|
|
@@ -344,37 +337,35 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean updateDevice(DeviceBandingParams request) {
|
|
|
- // 1. 安全获取长度和宽度,提供默认值
|
|
|
- BigDecimal length = Optional.ofNullable(request.getLength()).orElse(BigDecimal.ZERO);
|
|
|
- BigDecimal width = Optional.ofNullable(request.getWidth()).orElse(BigDecimal.ZERO);
|
|
|
-
|
|
|
- // 2. 计算半长半宽
|
|
|
- BigDecimal halfLength = length.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
|
|
|
- BigDecimal halfWidth = width.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
- // 3. 设置默认值
|
|
|
- setIfNull(request::getXxStart, () -> halfLength, request::setXxStart);
|
|
|
- setIfNull(request::getXxEnd, () -> halfLength, request::setXxEnd);
|
|
|
- setIfNull(request::getYyStart, () -> halfWidth, request::setYyStart);
|
|
|
- setIfNull(request::getYyEnd, () -> halfWidth, request::setYyEnd);
|
|
|
-
|
|
|
-
|
|
|
- Boolean flag = devInfoService.updateDevice(request.getClientId(), request);
|
|
|
+ public Boolean updateDevice(UpdateDeviceParams params) {
|
|
|
+ //1.校验设备是否存在
|
|
|
DevInfo devInfo = devInfoService.getOne(
|
|
|
Wrappers.<DevInfo>lambdaQuery()
|
|
|
- .eq(DevInfo::getClientId, request.getClientId()));
|
|
|
+ .eq(DevInfo::getClientId, params.getClientId()));
|
|
|
+ if (Objects.isNull(devInfo)){
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- //检查parts.length >= 2确保数组有足够元素,提供默认值"2.0"
|
|
|
- String result = Optional.ofNullable(devInfo.getSoftware())
|
|
|
- .filter(s -> s.contains("."))
|
|
|
- .map(s -> s.split("\\."))
|
|
|
- .filter(parts -> parts.length >= 2)
|
|
|
- .map(parts -> parts[0] + "." + parts[1])
|
|
|
- .orElse("2.0");
|
|
|
+ //2..更新数据
|
|
|
+ devInfo.setDevName(params.getDevName());
|
|
|
+ devInfo.setHeight(params.getHeight());
|
|
|
+ devInfo.setWifiName(params.getWifiName());
|
|
|
+ devInfo.setWifiPassword(params.getWifiPassword());
|
|
|
+ devInfo.setNorthAngle(params.getNorthAngle());
|
|
|
+ devInfo.setMountPlain(params.getMountPlain());
|
|
|
+ devInfo.setInstallPosition(params.getInstallPosition());
|
|
|
+ devInfo.setXxStart(params.getXxStart());
|
|
|
+ devInfo.setXxEnd(params.getXxEnd());
|
|
|
+ devInfo.setYyStart(params.getYyStart());
|
|
|
+ devInfo.setYyEnd(params.getYyEnd());
|
|
|
+ devInfo.setZzStart(params.getZzStart());
|
|
|
+ devInfo.setZzEnd(params.getZzEnd());
|
|
|
+ devInfo.setLength(params.getXxEnd().subtract(params.getXxStart()));
|
|
|
+ devInfo.setWidth(params.getYyEnd().subtract(params.getYyStart()));
|
|
|
|
|
|
- //todo mqttHandler.handleDeviceUpdateMessage(result, request);
|
|
|
- return flag;
|
|
|
+ boolean updated = devInfoService.updateById(devInfo);
|
|
|
+ return updated;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -477,35 +468,105 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public RoomDto readRoom(Long devId) {
|
|
|
+ public RoomDTO readRoom(Long devId) {
|
|
|
|
|
|
DevRoom devRoom = devRoomService.queryByDevId(devId);
|
|
|
if (devRoom == null) {
|
|
|
throw new BizException(ErrorEnum.ROOM_IS_NOT_EXIST.getErrorCode(), ErrorEnum.ROOM_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- RoomDto dto = new RoomDto();
|
|
|
+ RoomDTO dto = new RoomDTO();
|
|
|
dto.setRoomId(devRoom.getRoomId());
|
|
|
dto.setDevId(devRoom.getDevId());
|
|
|
+
|
|
|
+ //处理furnitures
|
|
|
if (StringUtils.hasText(devRoom.getFurnitures())) {
|
|
|
- dto.setFurnitures(JSONArray.parseArray(devRoom.getFurnitures(), RegionInfo.class));
|
|
|
+ List<RegionDTO> regionDTOs = JSONArray.parseArray(devRoom.getFurnitures(), RegionDTO.class);
|
|
|
+ dto.setFurnitures(regionDTOs);
|
|
|
}
|
|
|
+ //处理subRegions
|
|
|
if (StringUtils.hasText(devRoom.getSubRegions())) {
|
|
|
- dto.setSubRegions(JSONArray.parseArray(devRoom.getSubRegions(), RegionInfo.class));
|
|
|
- }
|
|
|
+ List<SubRegionDTO> subRegionDTOs = JSONArray.parseArray(devRoom.getSubRegions(), SubRegionDTO.class);
|
|
|
+ dto.setSubRegions(subRegionDTOs);
|
|
|
+ }
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean saveRoom(RoomDto roomDto) {
|
|
|
+ public Boolean saveRoom(RoomParam param) {
|
|
|
+
|
|
|
+ //查询设备信息
|
|
|
+ DevInfo devInfo = devInfoService.getById(param.getDevId());
|
|
|
|
|
|
// 更新dev_room表
|
|
|
- devRoomService.saveOrUpdate(roomDto);
|
|
|
+ devRoomService.saveOrUpdate(param);
|
|
|
+
|
|
|
+ //发送家具信息到算法
|
|
|
+ String topic = String.format(TopicConstants.TOPIC_DAS_SET_FURNITURE_PARAM, devInfo.getClientId());
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("dev_id", devInfo.getClientId());
|
|
|
+ if (mqttClient != null) {
|
|
|
+ try{
|
|
|
+ mqttClient.sendMessage(topic, msg.toJSONString());
|
|
|
+ log.info("Message sent successfully to topic: {}", topic); // 记录消息发送成功的日志
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("Failed to send message to topic: {}", topic, e); // 记录发送失败的错误日志
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("MQTT client is not available, message not sent to topic: {}", topic); // 记录客户端不可用的警告日志
|
|
|
+ }
|
|
|
|
|
|
- // todo 发送 屏蔽区域的数据到mqtt
|
|
|
- if (CollectionUtils.isNotEmpty(roomDto.getSubRegions())) {
|
|
|
- // todo 组装数据发送mqtt
|
|
|
+ //发送屏蔽子区域信息到算法
|
|
|
+ String subTopic = String.format(TopicConstants.TOPIC_DAS_SET_SUB_REGION_PARAM, devInfo.getClientId());
|
|
|
+ JSONObject subRegionMsg = new JSONObject();
|
|
|
+ msg.put("dev_id", devInfo.getClientId());
|
|
|
+ if (mqttClient != null) {
|
|
|
+ try{
|
|
|
+ mqttClient.sendMessage(subTopic, subRegionMsg.toJSONString());
|
|
|
+ log.info("Message sent successfully to topic: {}", subTopic); // 记录消息发送成功的日志
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("Failed to send message to topic: {}", subTopic, e); // 记录发送失败的错误日志
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("MQTT client is not available, message not sent to topic: {}", subTopic); // 记录客户端不可用的警告日志
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送子区域信息到设备
|
|
|
+ List<SubRegionInfo> subRegions = param.getSubRegions();
|
|
|
+ if (subRegions != null && !subRegions.isEmpty()) {
|
|
|
+ JSONArray extSubRegions = new JSONArray();
|
|
|
+ for (SubRegionInfo region : subRegions) {
|
|
|
+ JSONObject base = new JSONObject();
|
|
|
+ base.put("x_cm_start", region.getStartXx());
|
|
|
+ base.put("x_cm_stop", region.getStopXx());
|
|
|
+ base.put("y_cm_start", region.getStartYy());
|
|
|
+ base.put("y_cm_stop", region.getStopYy());
|
|
|
+ base.put("presence_enter_duration", region.getPresenceEnterDuration());
|
|
|
+ base.put("presence_exit_duration", region.getPresenceExitDuration());
|
|
|
+ base.put("track_presence", region.getTrackPresence());
|
|
|
+ base.put("exclude_falling", region.getExcludeFalling());
|
|
|
+
|
|
|
+ JSONObject regionJson = new JSONObject();
|
|
|
+ regionJson.put("base", base);
|
|
|
+ regionJson.put("z_cm_start", region.getStartZz());
|
|
|
+ regionJson.put("z_cm_stop", region.getStopZz());
|
|
|
+ regionJson.put("is_low_snr", region.getIsLowSnr());
|
|
|
+ regionJson.put("is_door", region.getIsDoor());
|
|
|
+
|
|
|
+ extSubRegions.add(regionJson);
|
|
|
+ }
|
|
|
+ JSONObject infoMsg = new JSONObject();
|
|
|
+ subRegionMsg.put("ext_sub_regions", extSubRegions);
|
|
|
+
|
|
|
+ String topicDev = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
|
|
|
+ try {
|
|
|
+ mqttClient.sendMessage(topicDev, infoMsg.toJSONString());
|
|
|
+ log.info("SubRegions message sent successfully to topic: {}", topicDev);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Failed to send subRegions message to topic: {}", topicDev, e);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|