|
@@ -0,0 +1,185 @@
|
|
|
+package com.care.installation.service;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.care.common.entity.*;
|
|
|
+import com.care.common.service.*;
|
|
|
+import com.care.installation.vo.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class RoomService {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CareRoomService careRoomService;
|
|
|
+ @Resource
|
|
|
+ private CareRoomSensorService careRoomSensorService;
|
|
|
+ @Resource
|
|
|
+ private CareRoomGateService careRoomGateService;
|
|
|
+ @Resource
|
|
|
+ private CareRoomRegionService careRoomRegionService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public RoomVO getRoomInfo(String devCode) {
|
|
|
+ QueryWrapper<CareRoom> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoom::getRoomId,devCode);
|
|
|
+ CareRoom careRoom = this.careRoomService.getOne(queryWrapper);
|
|
|
+ if (careRoom != null){
|
|
|
+ RoomVO roomVO = new RoomVO();
|
|
|
+ BeanUtil.copyProperties(careRoom,roomVO);
|
|
|
+ return roomVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean saveRoom(RoomVO vo) {
|
|
|
+ CareRoom careRoom = new CareRoom();
|
|
|
+ BeanUtil.copyProperties(vo,careRoom);
|
|
|
+ if (careRoom.getId() != null) { //修改
|
|
|
+ careRoom.setModifyTime(new Date());
|
|
|
+ return this.careRoomService.updateById(careRoom);
|
|
|
+ } else { //新增
|
|
|
+ careRoom.setCreateTime(new Date());
|
|
|
+ return this.careRoomService.save(careRoom);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public RoomSensorVO getRoomSensorInfo(String devCode) {
|
|
|
+ QueryWrapper<CareRoomSensor> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoomSensor::getRoomId,devCode);
|
|
|
+ CareRoomSensor careRoomSensor = this.careRoomSensorService.getOne(queryWrapper);
|
|
|
+ if (careRoomSensor != null){
|
|
|
+ RoomSensorVO roomSensorVO = new RoomSensorVO();
|
|
|
+ BeanUtil.copyProperties(careRoomSensor,roomSensorVO);
|
|
|
+ return roomSensorVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean saveRoomSensor(RoomSensorVO vo) {
|
|
|
+ CareRoomSensor careRoomSensor = new CareRoomSensor();
|
|
|
+ BeanUtil.copyProperties(vo,careRoomSensor);
|
|
|
+ if (careRoomSensor.getId() != null) { //修改
|
|
|
+ careRoomSensor.setModifyTime(new Date());
|
|
|
+ return this.careRoomSensorService.updateById(careRoomSensor);
|
|
|
+ } else { //新增
|
|
|
+ careRoomSensor.setCreateTime(new Date());
|
|
|
+ return this.careRoomSensorService.save(careRoomSensor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<RoomGateVO> listRoomGateInfo(String devCode) {
|
|
|
+ QueryWrapper<CareRoomGate> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoomGate::getRoomId,devCode).orderByAsc(CareRoomGate::getGid);
|
|
|
+ List<CareRoomGate> careRoomGateList = this.careRoomGateService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(careRoomGateList)){
|
|
|
+ List<RoomGateVO> roomGateVOList = new ArrayList<>();
|
|
|
+ careRoomGateList.forEach(item ->{
|
|
|
+ RoomGateVO roomGateVO = new RoomGateVO();
|
|
|
+ BeanUtil.copyProperties(item,roomGateVO);
|
|
|
+ roomGateVOList.add(roomGateVO);
|
|
|
+ });
|
|
|
+ return roomGateVOList;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public RoomGateVO getRoomGateInfo(String devCode,Integer gid) {
|
|
|
+ QueryWrapper<CareRoomGate> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoomGate::getRoomId,devCode).eq(CareRoomGate::getGid,gid);
|
|
|
+ CareRoomGate careRoomGate = this.careRoomGateService.getOne(queryWrapper);
|
|
|
+ if (careRoomGate != null) {
|
|
|
+ RoomGateVO roomGateVO = new RoomGateVO();
|
|
|
+ BeanUtil.copyProperties(careRoomGate,roomGateVO);
|
|
|
+ return roomGateVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean saveRoomGate(RoomGateVO vo) {
|
|
|
+ CareRoomGate careRoomGate = new CareRoomGate();
|
|
|
+ BeanUtil.copyProperties(vo,careRoomGate);
|
|
|
+ if (careRoomGate.getId() != null) { //修改
|
|
|
+ careRoomGate.setModifyTime(new Date());
|
|
|
+ return this.careRoomGateService.updateById(careRoomGate);
|
|
|
+ } else { //新增
|
|
|
+ careRoomGate.setCreateTime(new Date());
|
|
|
+ return this.careRoomGateService.save(careRoomGate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean delRoomGate(String devCode,Integer gid) {
|
|
|
+ QueryWrapper<CareRoomGate> removeWrapper = new QueryWrapper<>();
|
|
|
+ removeWrapper.lambda().eq(CareRoomGate::getRoomId,devCode).eq(CareRoomGate::getGid,gid);
|
|
|
+ return this.careRoomGateService.remove(removeWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<RoomRegionVO> listRoomRegionInfo(String devCode) {
|
|
|
+ QueryWrapper<CareRoomRegion> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoomRegion::getRoomId,devCode).orderByAsc(CareRoomRegion::getRid);
|
|
|
+ List<CareRoomRegion> careRoomRegionList = this.careRoomRegionService.list(queryWrapper);
|
|
|
+ if (CollUtil.isNotEmpty(careRoomRegionList)){
|
|
|
+ List<RoomRegionVO> roomRegionVOList = new ArrayList<>();
|
|
|
+ careRoomRegionList.forEach(item ->{
|
|
|
+ RoomRegionVO roomRegionVO = new RoomRegionVO();
|
|
|
+ BeanUtil.copyProperties(item,roomRegionVO);
|
|
|
+ roomRegionVOList.add(roomRegionVO);
|
|
|
+ });
|
|
|
+ return roomRegionVOList;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public RoomRegionVO getRoomRegionInfo(String devCode,Integer rid) {
|
|
|
+ QueryWrapper<CareRoomRegion> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(CareRoomRegion::getRoomId,devCode).eq(CareRoomRegion::getRid,rid);
|
|
|
+ CareRoomRegion careRoomRegion = this.careRoomRegionService.getOne(queryWrapper);
|
|
|
+ if (careRoomRegion != null) {
|
|
|
+ RoomRegionVO roomRegionVO = new RoomRegionVO();
|
|
|
+ BeanUtil.copyProperties(careRoomRegion,roomRegionVO);
|
|
|
+ return roomRegionVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean saveRoomRegion(RoomRegionVO vo) {
|
|
|
+ CareRoomRegion careRoomRegion = new CareRoomRegion();
|
|
|
+ BeanUtil.copyProperties(vo,careRoomRegion);
|
|
|
+ if (careRoomRegion.getId() != null) { //修改
|
|
|
+ careRoomRegion.setModifyTime(new Date());
|
|
|
+ return this.careRoomRegionService.updateById(careRoomRegion);
|
|
|
+ } else { //新增
|
|
|
+ careRoomRegion.setCreateTime(new Date());
|
|
|
+ return this.careRoomRegionService.save(careRoomRegion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean delRoomRegion(String devCode,Integer rid) {
|
|
|
+ QueryWrapper<CareRoomRegion> removeWrapper = new QueryWrapper<>();
|
|
|
+ removeWrapper.lambda().eq(CareRoomRegion::getRoomId,devCode).eq(CareRoomRegion::getRid,rid);
|
|
|
+ return this.careRoomRegionService.remove(removeWrapper);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 发送Mqtt消息给dmp
|
|
|
+ * @param vo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean commitRoomInfo(DeviceRoomAllVO vo) {
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|