|
@@ -6,14 +6,13 @@ import cn.hutool.core.collection.CollUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.care.common.entity.*;
|
|
import com.care.common.entity.*;
|
|
import com.care.common.service.*;
|
|
import com.care.common.service.*;
|
|
|
|
+import com.care.common.util.JsonUtil;
|
|
import com.care.installation.vo.*;
|
|
import com.care.installation.vo.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
@@ -28,8 +27,10 @@ public class RoomService {
|
|
private CareRoomGateService careRoomGateService;
|
|
private CareRoomGateService careRoomGateService;
|
|
@Resource
|
|
@Resource
|
|
private CareRoomRegionService careRoomRegionService;
|
|
private CareRoomRegionService careRoomRegionService;
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private CareDeviceService careDeviceService;
|
|
|
|
+ @Resource
|
|
|
|
+ private MqttPublishService mqttPublishService;
|
|
|
|
|
|
public RoomVO getRoomInfo(String devCode) {
|
|
public RoomVO getRoomInfo(String devCode) {
|
|
QueryWrapper<CareRoom> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<CareRoom> queryWrapper = new QueryWrapper<>();
|
|
@@ -177,9 +178,111 @@ public class RoomService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public Boolean commitRoomInfo(DeviceRoomAllVO vo) {
|
|
public Boolean commitRoomInfo(DeviceRoomAllVO vo) {
|
|
|
|
+ try {
|
|
|
|
+ RoomVO roomVO = vo.getRoomVO();
|
|
|
|
+ RoomSensorVO roomSensorVO = vo.getRoomSensorVO();
|
|
|
|
+ List<RoomGateVO> roomGateVOList = vo.getRoomGateVOList();
|
|
|
|
+ List<RoomRegionVO> roomRegionVOList = vo.getRoomRegionVOList();
|
|
|
|
+ if (roomVO == null || roomSensorVO == null || CollUtil.isEmpty(roomGateVOList)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QueryWrapper<CareDevice> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(CareDevice::getDevCode, roomVO.getRoomId());
|
|
|
|
+ CareDevice careDevice = careDeviceService.getOne(queryWrapper);
|
|
|
|
+ if (careDevice == null) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ mqttPublishService.publish(careDevice, getRoomMqttData(roomVO));
|
|
|
|
+ mqttPublishService.publish(careDevice, getRoomSensorMqttData(roomSensorVO));
|
|
|
|
+ mqttPublishService.publish(careDevice, getRoomGateVOMqttData(roomGateVOList));
|
|
|
|
+ if (CollUtil.isNotEmpty(roomRegionVOList)){
|
|
|
|
+ mqttPublishService.publish(careDevice, getRoomRegionVOMqttData(roomRegionVOList));
|
|
|
|
+ }
|
|
|
|
+ //TODO 返回值
|
|
|
|
+ return true;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
|
|
|
+ private String getRoomMqttData( RoomVO vo) throws Exception {
|
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
|
+ data.put("type","RoomVO");
|
|
|
|
+ Map<String,Object> msg = new HashMap<>();
|
|
|
|
+ msg.put("roomId",vo.getRoomId());
|
|
|
|
+ msg.put("roomX",vo.getX());
|
|
|
|
+ msg.put("roomY",vo.getY());
|
|
|
|
+ msg.put("roomZ",vo.getZ());
|
|
|
|
+ data.put("msg",msg);
|
|
|
|
+ return JsonUtil.toJson(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getRoomSensorMqttData( RoomSensorVO vo) throws Exception {
|
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
|
+ data.put("type","RoomDeviceVO");
|
|
|
|
+ Map<String,Object> msg = new HashMap<>();
|
|
|
|
+ msg.put("roomDeviceId",vo.getRoomId());
|
|
|
|
+ msg.put("roomId",vo.getRoomId());
|
|
|
|
+ msg.put("deviceX",vo.getX());
|
|
|
|
+ msg.put("deviceY",vo.getY());
|
|
|
|
+ msg.put("deviceZ",vo.getZ());
|
|
|
|
|
|
|
|
+ msg.put("deviceAtilt",0);
|
|
|
|
+ msg.put("deviceEtilt",90);
|
|
|
|
+ msg.put("deviceAtiltfov",60);
|
|
|
|
+ msg.put("deviceEtiltfov",60);
|
|
|
|
+ msg.put("deviceMount",0);
|
|
|
|
+ data.put("msg",msg);
|
|
|
|
+ return JsonUtil.toJson(data);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private String getRoomGateVOMqttData(List<RoomGateVO> list) throws Exception {
|
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
|
+ data.put("type","RoomEntrancesVO");
|
|
|
|
+ Map<String,Object> msg = new HashMap<>();
|
|
|
|
+ List<Map<String,Object>> items = new ArrayList<>();
|
|
|
|
+ list.forEach(roomGateVO ->{
|
|
|
|
+ Map<String,Object> item = new HashMap<>();
|
|
|
|
+ item.put("entranceId",roomGateVO.getGid());
|
|
|
|
+ item.put("roomId",roomGateVO.getRoomId());
|
|
|
|
+ item.put("entranceCode",roomGateVO.getGid());
|
|
|
|
+ item.put("entranceType",1);
|
|
|
|
+ item.put("direction",roomGateVO.getDirection());
|
|
|
|
+
|
|
|
|
+ item.put("entranceLength",roomGateVO.getLength());
|
|
|
|
+ item.put("width",roomGateVO.getWidth());
|
|
|
|
+ item.put("hight",roomGateVO.getHight());
|
|
|
|
+ items.add(item);
|
|
|
|
+ });
|
|
|
|
+ msg.put("roomEntranceVOS",items);
|
|
|
|
+ data.put("msg",msg);
|
|
|
|
+ return JsonUtil.toJson(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getRoomRegionVOMqttData(List<RoomRegionVO> list) throws Exception {
|
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
|
+ data.put("type","RoomRegionsVO");
|
|
|
|
+ Map<String,Object> msg = new HashMap<>();
|
|
|
|
+ List<Map<String,Object>> items = new ArrayList<>();
|
|
|
|
+ list.forEach(roomRegionVO ->{
|
|
|
|
+ Map<String,Object> item = new HashMap<>();
|
|
|
|
+ item.put("regionId",roomRegionVO.getRid());
|
|
|
|
+ item.put("roomId",roomRegionVO.getRoomId());
|
|
|
|
+ item.put("regionCode",roomRegionVO.getRid());
|
|
|
|
+ item.put("regionType",roomRegionVO.getCls());
|
|
|
|
+ item.put("positionX",roomRegionVO.getPositionX());
|
|
|
|
+ item.put("positionY",roomRegionVO.getPositionY());
|
|
|
|
+ item.put("scaleX",roomRegionVO.getScaleX());
|
|
|
|
+ item.put("scaleY",roomRegionVO.getScaleY());
|
|
|
|
+ item.put("scaleZ",roomRegionVO.getScaleZ());
|
|
|
|
+ item.put("rotation",roomRegionVO.getRotation());
|
|
|
|
+ items.add(item);
|
|
|
|
+ });
|
|
|
|
+ msg.put("roomRegionVOS",items);
|
|
|
|
+ data.put("msg",msg);
|
|
|
|
+ return JsonUtil.toJson(data);
|
|
|
|
+ }
|
|
}
|
|
}
|