|
@@ -1,35 +1,56 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
import cn.hfln.framework.extension.BizException;
|
|
|
+import cn.hfln.framework.mqtt.template.MqttTemplate;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.hfln.portal.common.constant.mqtt.topic.TopicConstants;
|
|
|
import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
+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.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.event.EventListParams;
|
|
|
+import com.hfln.portal.common.request.share.ShareConfirmParam;
|
|
|
+import com.hfln.portal.common.request.share.ShareParam;
|
|
|
+import com.hfln.portal.common.response.device.WcTimesQueryRes;
|
|
|
import com.hfln.portal.common.vo.PageRecord;
|
|
|
+import com.hfln.portal.domain.customer.OssBusiType;
|
|
|
+import com.hfln.portal.domain.customer.util.DevPosFixUtil;
|
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
import com.hfln.portal.domain.gateway.DeviceGateway;
|
|
|
-import com.hfln.portal.infrastructure.po.DevGroup;
|
|
|
-import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
-import com.hfln.portal.infrastructure.po.DevShare;
|
|
|
-import com.hfln.portal.infrastructure.po.EventList;
|
|
|
+import com.hfln.portal.infrastructure.oss.OssClient;
|
|
|
+import com.hfln.portal.infrastructure.oss.OssUtils;
|
|
|
+import com.hfln.portal.infrastructure.po.*;
|
|
|
import com.hfln.portal.infrastructure.service.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+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;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
@@ -48,17 +69,44 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
@Autowired
|
|
|
private EventService eventService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OssFileService ossFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DevRoomService devRoomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MqttTemplate mqttTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OssClient ossClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlarmEventService alarmEventService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public HomeInfoDTO queryHomeInfo(Long userId) {
|
|
|
HomeInfoDTO homeInfoDTO = new HomeInfoDTO();
|
|
|
- //todo 添加轮播图相关信息
|
|
|
- homeInfoDTO.setCarouselImage(null);
|
|
|
+ // 添加轮播图相关信息
|
|
|
+ List<OssFileDTO> fileDTOS = new ArrayList<>();
|
|
|
+ List<TblOssFile> files = ossFileService.queryFile(OssBusiType.CAROUSEL.getCode(), null);
|
|
|
+ if (CollectionUtils.isNotEmpty(files)) {
|
|
|
+ for (TblOssFile file : files) {
|
|
|
+ OssFileDTO dto = new OssFileDTO();
|
|
|
+ BeanUtils.copyProperties(file, dto);
|
|
|
+ fileDTOS.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ homeInfoDTO.setFileList(fileDTOS);
|
|
|
/*
|
|
|
查询设备详情
|
|
|
*/
|
|
|
// 查询当前OpenId被分享的设备
|
|
|
- Optional<List<String>> sharedDevIds = devShareService.queryDeviceIdByUserId(userId);
|
|
|
+ Optional<List<Long>> sharedDevIds = devShareService.queryDeviceIdByUserId(userId);
|
|
|
|
|
|
List<DeviceDTO> deviceDTOs = new ArrayList<>();
|
|
|
List<DevInfo> devInfos = devInfoService.queryDeviceList(userId, null, null, sharedDevIds.orElse(Collections.emptyList()));
|
|
@@ -90,7 +138,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
@Override
|
|
|
public List<DeviceDTO> queryDeviceList(DeviceListParams request) {
|
|
|
|
|
|
- Optional<List<String>> sharedDevIds = devShareService.queryDeviceIdByUserId(request.getUserId());
|
|
|
+ Optional<List<Long>> sharedDevIds = devShareService.queryDeviceIdByUserId(request.getUserId());
|
|
|
|
|
|
List<DeviceDTO> deviceDTOs = new ArrayList<>();
|
|
|
List<DevInfo> devInfos = devInfoService.queryDeviceList(request.getUserId(), request.getKeyWord(),
|
|
@@ -152,7 +200,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
}
|
|
|
|
|
|
// 3. 更新设备信息
|
|
|
- return devInfoService.updateDevice(devInfo.getDevInfoId(), request);
|
|
|
+ return devInfoService.updateDevice(devInfo.getDevId(), request);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -247,7 +295,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
.map(parts -> parts[0] + "." + parts[1])
|
|
|
.orElse("2.0");
|
|
|
|
|
|
- //mqttHandler.handleDeviceUpdateMessage(result, request);
|
|
|
+ //todo mqttHandler.handleDeviceUpdateMessage(result, request);
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
@@ -283,6 +331,345 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
if (params.getXValue() == null && params.getYValue() == null) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ updateWrapper.eq(DevInfo::getDevId, params.getDeviceId());
|
|
|
+ updateWrapper.eq(DevInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
|
|
|
+
|
|
|
return devInfoService.update(updateWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean checkDevByUserId(Long userId, Long devId) {
|
|
|
+
|
|
|
+ DevInfo devInfo = devInfoService.getOne(
|
|
|
+ Wrappers.<DevInfo>lambdaQuery()
|
|
|
+ .eq(DevInfo::getDevId, devId)
|
|
|
+ .eq(DevInfo::getUserId, userId)
|
|
|
+ .eq(DevInfo::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED)
|
|
|
+ );
|
|
|
+ if (Objects.nonNull(devInfo)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ DevShare devShare = devShareService.queryByUserIdAndDevId(userId, devId);
|
|
|
+ if (devShare != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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();
|
|
|
+ dto.setRoomId(devRoom.getRoomId());
|
|
|
+ dto.setDevId(devRoom.getDevId());
|
|
|
+ if (StringUtils.hasText(devRoom.getFurnitures())) {
|
|
|
+ dto.setFurnitures(JSONArray.parseArray(devRoom.getFurnitures(), RegionInfo.class));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(devRoom.getSubRegions())) {
|
|
|
+ dto.setSubRegions(JSONArray.parseArray(devRoom.getSubRegions(), RegionInfo.class));
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean saveRoom(RoomDto roomDto) {
|
|
|
+
|
|
|
+ // 更新dev_room表
|
|
|
+ devRoomService.saveOrUpdate(roomDto);
|
|
|
+
|
|
|
+ // todo 发送 屏蔽区域的数据到mqtt
|
|
|
+ if (CollectionUtils.isNotEmpty(roomDto.getSubRegions())) {
|
|
|
+ // todo 组装数据发送mqtt
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean devShare(ShareParam shareParam) {
|
|
|
+
|
|
|
+
|
|
|
+ List<UserInfo> userInfos = userService.queryByPhone(shareParam.getSharedPhone());
|
|
|
+ if (userInfos == null || userInfos.size() < 1) {
|
|
|
+ throw new BizException(ErrorEnum.MOBILE_NOT_SIGN.getErrorCode(), ErrorEnum.MOBILE_NOT_SIGN.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DevShare> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(DevShare::getDevId, shareParam.getDevId());
|
|
|
+ queryWrapper.eq(DevShare::getSharerUserId, shareParam.getSharerUserId());
|
|
|
+ queryWrapper.eq(DevShare::getSharedUserId, userInfos.get(0).getUserId());
|
|
|
+ queryWrapper.in(DevShare::getState, Arrays.asList(0, 1));
|
|
|
+ List<DevShare> list = devShareService.list(queryWrapper);
|
|
|
+
|
|
|
+ if (list != null && list.size() > 1) {
|
|
|
+ throw new BizException(ErrorEnum.SHARE_IS_NOT_REPEAT.getErrorCode(), ErrorEnum.SHARE_IS_NOT_REPEAT.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ DevShare devShare = new DevShare();
|
|
|
+
|
|
|
+ devShare.setDevId(shareParam.getDevId());
|
|
|
+ devShare.setSharerUserId(shareParam.getSharerUserId());
|
|
|
+ devShare.setSharerPhone(shareParam.getSharerPhone());
|
|
|
+ devShare.setSharedPhone(shareParam.getSharedPhone());
|
|
|
+ devShare.setSharedUserId(userInfos.get(0).getUserId());
|
|
|
+ devShare.setState(0);
|
|
|
+ devShareService.save(devShare);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean shareByUrl(ShareParam shareParam) {
|
|
|
+
|
|
|
+ DevShare notDealShare = devShareService.queryNotDeal(shareParam.getSharerUserId(), shareParam.getSharedUserId(), shareParam.getDevId());
|
|
|
+ if (notDealShare != null) {
|
|
|
+ throw new BizException(ErrorEnum.EXIST_NOT_DEAL_SHARE.getErrorCode(), ErrorEnum.EXIST_NOT_DEAL_SHARE.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ DevShare devShare = new DevShare();
|
|
|
+ BeanUtils.copyProperties(shareParam, devShare);
|
|
|
+ if (StringUtils.isEmpty(shareParam.getSharerPhone())) {
|
|
|
+ UserInfo shareUser = userService.queryById(shareParam.getSharerUserId());
|
|
|
+ if (shareUser == null) {
|
|
|
+ throw new BizException(ErrorEnum.SHARER_IS_NOT_EXIST.getErrorCode(), ErrorEnum.SHARER_IS_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ devShare.setSharerPhone(shareUser.getPhone());
|
|
|
+ }
|
|
|
+
|
|
|
+ devShare.setState(1);
|
|
|
+ devShareService.save(devShare);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ShareDto> queryShare(Long userId) {
|
|
|
+
|
|
|
+ List<DevShare> shares = devShareService.queryBySharedUserId(userId);
|
|
|
+ if (CollectionUtils.isEmpty(shares)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ShareDto> res = new ArrayList<>();
|
|
|
+ for (DevShare share : shares) {
|
|
|
+ ShareDto dto = new ShareDto();
|
|
|
+ BeanUtils.copyProperties(share, dto);
|
|
|
+ res.add(dto);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void shareConfirm(ShareConfirmParam shareConfirmParam) {
|
|
|
+
|
|
|
+ DevShare devShare = devShareService.queryBySharedUserIdAndDevId(shareConfirmParam.getSharedUserId(), shareConfirmParam.getDevId());
|
|
|
+ if (devShare == null) {
|
|
|
+ throw new BizException(ErrorEnum.SHARE_INFO_NOT_EXIST.getErrorCode(), ErrorEnum.SHARE_INFO_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (devShare.getState() == null || devShare.getState() != 0) {
|
|
|
+ throw new BizException(ErrorEnum.SHARE_INFO_ALREADY_DEAL.getErrorCode(), ErrorEnum.SHARE_INFO_ALREADY_DEAL.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ devShare.setState(shareConfirmParam.getState());
|
|
|
+ devShareService.updateById(devShare);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getVersion(String clientId) {
|
|
|
+
|
|
|
+ String topic = String.format(TopicConstants.TOPIC_DEV_GET_VERSION, clientId);
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("dev_id", clientId);
|
|
|
+
|
|
|
+ mqttTemplate.send(topic, msg.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reboot(String clientId) {
|
|
|
+
|
|
|
+ String topic = String.format(TopicConstants.TOPIC_DEV_REBOOT, clientId);
|
|
|
+
|
|
|
+ mqttTemplate.send(topic, "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateOTA(String clientId) {
|
|
|
+
|
|
|
+ String topic = String.format(TopicConstants.TOPIC_DEV_UPDATEOTA, clientId);
|
|
|
+
|
|
|
+ mqttTemplate.send(topic, "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void fixPost(String clientId, int poseIndex) {
|
|
|
+
|
|
|
+ Byte pose;
|
|
|
+ switch (poseIndex) {
|
|
|
+ case 0:
|
|
|
+ pose = 4;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ pose = 5;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ pose = 0;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ pose = 7;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ pose = -1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ DevPosFixUtil.setFixPost(pose, clientId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void stopFixPost(String clientId) {
|
|
|
+
|
|
|
+ DevPosFixUtil.delFixPost(clientId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getInfo(String clientId) {
|
|
|
+
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("dev_id", clientId);
|
|
|
+
|
|
|
+ mqttTemplate.send(TopicConstants.TOPIC_DEV_GET_INFO, msg.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getParam(String clientId) {
|
|
|
+
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("dev_id", clientId);
|
|
|
+
|
|
|
+ mqttTemplate.send(TopicConstants.TOPIC_DEV_GET_PARAM, msg.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadFloorPlan(MultipartFile file, String groupUuid) throws IOException {
|
|
|
+
|
|
|
+ // 校验文件非空
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_IS_EMPTY.getErrorCode(), ErrorEnum.FILE_IS_EMPTY.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验文件类型
|
|
|
+ String contentType = file.getContentType();
|
|
|
+ if (contentType == null || (!contentType.equalsIgnoreCase("image/png") && !contentType.equalsIgnoreCase("image/jpeg"))) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_ONLY_PNG_JPG.getErrorCode(), ErrorEnum.FILE_ONLY_PNG_JPG.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验文件头
|
|
|
+ byte[] fileHeader = new byte[8];
|
|
|
+ try (InputStream is = file.getInputStream()) {
|
|
|
+ int readBytes = is.read(fileHeader);
|
|
|
+ if (readBytes < 8) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_NOT_COMPLETE.getErrorCode(), ErrorEnum.FILE_NOT_COMPLETE.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean isPng = checkPngMagicNumber(fileHeader);
|
|
|
+ boolean isJpeg = checkJpegMagicNumber(fileHeader);
|
|
|
+
|
|
|
+ if (!isPng && !isJpeg) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_ONLY_PNG_JPG02.getErrorCode(), ErrorEnum.FILE_ONLY_PNG_JPG02.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ String objectName = OssUtils.getObjectName(OssBusiType.FLOORPLAN.getCode(), file.getName());
|
|
|
+ ossClient.upload(file.getInputStream(), OssUtils.BUCKET_NAME, objectName);
|
|
|
+
|
|
|
+ TblOssFile ossFile = ossFileService.queryOneFile(OssBusiType.FLOORPLAN.getCode(), groupUuid);
|
|
|
+ if (ossFile == null) {
|
|
|
+ TblOssFile newFile = new TblOssFile();
|
|
|
+ newFile.setBusiType(OssBusiType.FLOORPLAN.getCode());
|
|
|
+ newFile.setBusiKey(groupUuid);
|
|
|
+ newFile.setFileName(file.getName());
|
|
|
+ newFile.setOssUrl(OssUtils.BUCKET_NAME+objectName);
|
|
|
+ ossFileService.save(newFile);
|
|
|
+ } else {
|
|
|
+ if (ossFile.getIsDeleted() == BasePO.DeleteFlag.NOT_DELETED) {
|
|
|
+ // 删除原文件
|
|
|
+ ossClient.delete(ossFile.getOssUrl());
|
|
|
+ }
|
|
|
+ ossFile.setBusiType(OssBusiType.FLOORPLAN.getCode());
|
|
|
+ ossFile.setBusiKey(groupUuid);
|
|
|
+ ossFile.setFileName(file.getName());
|
|
|
+ ossFile.setOssUrl(OssUtils.BUCKET_NAME+objectName);
|
|
|
+ ossFileService.updateById(ossFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFloorPlan(String groupUuid) {
|
|
|
+
|
|
|
+ List<TblOssFile> tblOssFiles = ossFileService.queryFile(OssBusiType.FLOORPLAN.getCode(), groupUuid);
|
|
|
+ if (CollectionUtils.isEmpty(tblOssFiles)) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_EXIST_MULTIPLE.getErrorCode(), ErrorEnum.FILE_EXIST_MULTIPLE.getErrorMessage());
|
|
|
+ }
|
|
|
+ TblOssFile tblOssFile = tblOssFiles.get(0);
|
|
|
+ if (tblOssFile == null || tblOssFile.getIsDeleted() == BasePO.DeleteFlag.DELETED) {
|
|
|
+ throw new BizException(ErrorEnum.FILE_DEL_OR_NOT_EXIST.getErrorCode(), ErrorEnum.FILE_DEL_OR_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return ossClient.getDownloadUrl(tblOssFile.getOssUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WcTimesQueryRes getWcTimes(Long devId, String time) {
|
|
|
+
|
|
|
+ LocalDate inputDate = LocalDate.parse(time);
|
|
|
+ LocalDate previousDate = inputDate.minusDays(1);
|
|
|
+ List<AlarmEvent> list = alarmEventService.list(new LambdaQueryWrapper<AlarmEvent>().eq(AlarmEvent::getDevId, devId).ge(AlarmEvent::getCreateTime, previousDate).lt(AlarmEvent::getCreateTime, inputDate));
|
|
|
+ WcTimesQueryRes res = new WcTimesQueryRes();
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+
|
|
|
+ res.setStayTimes(null);
|
|
|
+ res.setCount(0);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ List<AlarmEventDTO> dtoList = new ArrayList<>();
|
|
|
+ for (AlarmEvent alarmEvent : list) {
|
|
|
+ AlarmEventDTO dto = new AlarmEventDTO();
|
|
|
+ BeanUtils.copyProperties(alarmEvent, dto);
|
|
|
+ dtoList.add(dto);
|
|
|
+ }
|
|
|
+ res.setStayTimes(dtoList);
|
|
|
+ res.setCount(list.size());
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验 PNG 文件头(89 50 4E 47 0D 0A 1A 0A)
|
|
|
+ public static boolean checkPngMagicNumber(byte[] header) {
|
|
|
+ byte[] pngSignature = {(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
|
|
+ if (header.length < pngSignature.length) return false;
|
|
|
+ for (int i = 0; i < pngSignature.length; i++) {
|
|
|
+ if ((header[i] & 0xFF) != (pngSignature[i] & 0xFF)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验 JPEG 文件头(FF D8)
|
|
|
+ public static boolean checkJpegMagicNumber(byte[] header) {
|
|
|
+ return header.length >= 2 &&
|
|
|
+ (header[0] & 0xFF) == 0xFF &&
|
|
|
+ (header[1] & 0xFF) == 0xD8;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|