|
@@ -7,12 +7,10 @@ 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.UserConstants;
|
|
|
import com.hfln.portal.common.constant.mqtt.topic.TopicConstants;
|
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
|
import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
-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.RegionDTO;
|
|
@@ -26,7 +24,6 @@ import com.hfln.portal.common.request.event.AlarmPlanDelReq;
|
|
|
import com.hfln.portal.common.request.room.RoomParam;
|
|
|
import com.hfln.portal.common.request.room.SubRegionInfo;
|
|
|
import com.hfln.portal.common.request.share.*;
|
|
|
-import com.hfln.portal.common.vo.PageRecord;
|
|
|
import com.hfln.portal.domain.customer.OprLogType;
|
|
|
import com.hfln.portal.domain.customer.OssBusiType;
|
|
|
import com.hfln.portal.domain.customer.util.DevPosFixUtil;
|
|
@@ -280,24 +277,8 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public DeviceDTO deviceBind(DeviceBandingParams request) {
|
|
|
- // 1.参数范围大小校验
|
|
|
- if (request.getXxEnd().compareTo(request.getXxStart()) <= 0 || request.getYyEnd().compareTo(request.getYyStart()) <= 0) {
|
|
|
- throw new BizException(ErrorEnum.DEVICE_PARAM_ERROR.getErrorCode(), ErrorEnum.DEVICE_PARAM_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- List<BigDecimal> validAngles = Arrays.asList(
|
|
|
- BigDecimal.ZERO,
|
|
|
- BigDecimal.valueOf(90),
|
|
|
- BigDecimal.valueOf(180),
|
|
|
- BigDecimal.valueOf(270)
|
|
|
- );
|
|
|
- boolean valid = validAngles.stream()
|
|
|
- .anyMatch(angle -> angle.compareTo(request.getNorthAngle()) == 0);
|
|
|
- if (!valid) {
|
|
|
- throw new BizException(ErrorEnum.DEVICE_PARAM_ERROR.getErrorCode(), ErrorEnum.DEVICE_PARAM_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
|
|
|
- // 2. 检查设备是否存在
|
|
|
+ // 1. 检查设备是否存在
|
|
|
DevInfo devInfo = devInfoService.getOne(
|
|
|
Wrappers.<DevInfo>lambdaQuery()
|
|
|
.eq(DevInfo::getClientId, request.getClientId())
|
|
@@ -309,14 +290,15 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
throw new BizException(ErrorEnum.DEVICE_IS_BINDING.getErrorCode(), ErrorEnum.DEVICE_IS_BINDING.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- // 3. 更新设备信息到数据库
|
|
|
- boolean updateResult = devInfoService.updateDevice(devInfo.getClientId(), request);
|
|
|
- if (!updateResult) {
|
|
|
- log.warn("更新设备信息失败,clientId:{}", devInfo.getClientId());
|
|
|
- }
|
|
|
+ // 2. 绑定设备信息到写入数据库
|
|
|
+ devInfo.setUserId(request.getUserId());
|
|
|
+ devInfo.setDevName(request.getDevName());
|
|
|
+ devInfo.setMountPlain(request.getMountPlain());
|
|
|
+ devInfo.setInstallPosition(request.getInstallPosition());
|
|
|
+ devInfo.setActiveTime(LocalDateTime.now());
|
|
|
+ devInfoService.updateById(devInfo);
|
|
|
|
|
|
- //4.通过MQTT把信息参数发送到设备
|
|
|
- mqttSend.sendDeviceParamsToMqtt(devInfo.getClientId(), request);
|
|
|
+ logService.saveLog(OprLogType.BIND_DEVICE.getCode(), String.format("用户 %d 绑定设备 %s", request.getUserId(), request.getClientId()));
|
|
|
|
|
|
//5.返回绑定结果和设备主键id
|
|
|
DeviceDTO result = new DeviceDTO();
|
|
@@ -344,28 +326,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 填充PageRecord
|
|
|
- private PageRecord<EventListDTO> getEventListDTOPageRecord(Page<EventList> eventPage, List<EventListDTO> targets) {
|
|
|
- int totalPages = (int) Math.ceil((double) eventPage.getTotal() / eventPage.getSize());
|
|
|
- PageRecord<EventListDTO> pageRecord = new PageRecord<>();
|
|
|
- pageRecord.setRows(targets);
|
|
|
- pageRecord.setTotal(eventPage.getTotal());
|
|
|
- pageRecord.setPageNum((int) eventPage.getCurrent());
|
|
|
- pageRecord.setPageSize((int) eventPage.getSize());
|
|
|
- pageRecord.setOutTotalPageNum(eventPage.getCurrent() > totalPages);
|
|
|
- pageRecord.setTotalPageNum(totalPages);
|
|
|
- return pageRecord;
|
|
|
- }
|
|
|
|
|
|
- // 实体转换方法
|
|
|
- private List<EventListDTO> convertToTargetVO(List<EventList> records) {
|
|
|
- return records.stream().map(event -> {
|
|
|
- EventListDTO vo = new EventListDTO();
|
|
|
- // 使用BeanUtils简化属性拷贝
|
|
|
- BeanUtils.copyProperties(event, vo);
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- }
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -482,29 +443,14 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
}
|
|
|
|
|
|
//3.更新数据
|
|
|
- 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()));
|
|
|
|
|
|
- boolean updated = devInfoService.updateById(devInfo);
|
|
|
+ boolean updated = devInfoService.updateDevice(devInfo.getClientId(), params);
|
|
|
if (!updated) {
|
|
|
log.warn("更新设备信息失败,clientId:{}", devInfo.getClientId());
|
|
|
throw new BizException(ErrorEnum.DEVICE_UPDATE_FAIL.getErrorCode(), ErrorEnum.DEVICE_UPDATE_FAIL.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- logService.saveLog(OprLogType.UPDATE_DEVICE.getCode(), devInfo);
|
|
|
+ logService.saveLog(OprLogType.UPDATE_DEVICE.getCode(), params);
|
|
|
|
|
|
//4.通过MQTT把信息参数发送到设备
|
|
|
mqttSend.sendDeviceParamsToMqtt(devInfo.getClientId(), params);
|