|
@@ -38,6 +38,7 @@ import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
import com.hfln.portal.domain.gateway.DeviceGateway;
|
|
|
import com.hfln.portal.infrastructure.mqtt.MqttClient;
|
|
|
import com.hfln.portal.infrastructure.mqtt.MqttSend;
|
|
|
+import com.hfln.portal.infrastructure.mqtt.MqttSubHandle;
|
|
|
import com.hfln.portal.infrastructure.oss.OssClient;
|
|
|
import com.hfln.portal.infrastructure.oss.OssUtils;
|
|
|
import com.hfln.portal.infrastructure.po.*;
|
|
@@ -126,6 +127,9 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
@Autowired
|
|
|
private org.springframework.data.redis.core.RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MqttSubHandle mqttSubHandle;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public HomeInfoDTO queryHomeInfo(Long userId) {
|
|
@@ -385,6 +389,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean handleEvent(Long eventListId) {
|
|
|
|
|
|
//1.查询事件信息
|
|
@@ -1134,10 +1139,10 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean deviceTransfer(DeviceTransferParams param){
|
|
|
|
|
|
- //1. 查询设备信息并校验是否存在
|
|
|
+ // 1.查询设备信息并校验是否存在
|
|
|
DevInfo devInfo = devInfoService.getOne(
|
|
|
Wrappers.<DevInfo>lambdaQuery()
|
|
|
.eq(DevInfo::getDevId, param.getDevId())
|
|
@@ -1147,28 +1152,28 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //2.校验用户权限
|
|
|
+ // 2.校验用户权限
|
|
|
if(!Objects.equals(param.getUserId(), devInfo.getUserId())){
|
|
|
throw new BizException(ErrorEnum.USER_NO_PERMISSION.getErrorCode(), ErrorEnum.USER_NO_PERMISSION.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //3.根据手机号查询转移对象是否注册
|
|
|
+ // 3.根据手机号查询转移对象是否注册
|
|
|
UserInfo userInfo = userService.queryByPhone(param.getPhone());
|
|
|
if (userInfo == null){
|
|
|
throw new BizException(ErrorEnum.USER_IS_NOT_EXIST.getErrorCode(), ErrorEnum.USER_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
- //4.转移当前设备归属
|
|
|
+ // 4.转移当前设备归属
|
|
|
devInfo.setUserId(userInfo.getUserId());
|
|
|
|
|
|
- //5.设备分享表修改
|
|
|
+ // 5.设备分享表修改
|
|
|
List<DevShare> devShareList = devShareService.list(
|
|
|
Wrappers.<DevShare>lambdaQuery()
|
|
|
.eq(DevShare::getDevId, param.getDevId())
|
|
|
.eq(DevShare::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED)
|
|
|
);
|
|
|
|
|
|
- //6. 遍历设备分享表
|
|
|
+ // 6.遍历设备分享表
|
|
|
if (!devShareList.isEmpty()) {
|
|
|
devShareList.forEach(devShare -> {
|
|
|
if (Objects.equals(devShare.getSharerUserId(), userInfo.getUserId())) {
|
|
@@ -1180,20 +1185,22 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
});
|
|
|
devShareService.updateBatchById(devShareList); // 批量更新设备分享记录
|
|
|
}
|
|
|
- //7. 更新设备信息(设备归属转移)
|
|
|
+ // 7.更新设备信息(设备归属转移)
|
|
|
devInfo.setUpdateTime(LocalDateTime.now()); // 更新修改时间
|
|
|
devInfoService.updateById(devInfo); // 更新设备信息
|
|
|
|
|
|
- //8.服务号推送告知转移对象
|
|
|
- List<WxRelation> wxRelations = wxRelationService.queryByUnionId(userInfo.getUnionId());
|
|
|
- String fwhOpenId = "";
|
|
|
- if (wxRelations != null && !wxRelations.isEmpty()) {
|
|
|
- fwhOpenId = wxRelations.get(0).getFwhOpenId();
|
|
|
- }
|
|
|
- log.info("mqttutil--当前useropenid=" + userInfo.getOpenid() + ", fwhopenId=" + fwhOpenId);
|
|
|
- log.info("发送微信公众号信息:devName=" + devInfo.getDevName() + ", phoneNumber=" + userInfo.getPhone() + ", fwhOpenId=" + fwhOpenId);
|
|
|
- wxOfficeAccountClient.sendMsg(devInfo.getClientId(), devInfo.getDevName(),userInfo.getPhone(), fwhOpenId, "设备转移成功,请前往小程序查看");
|
|
|
- log.info("发送微信公众号信息完毕");
|
|
|
+ // 8.服务号推送告知转移对象
|
|
|
+ mqttSubHandle.pushDeviceTransferMsg(devInfo, userInfo);
|
|
|
+
|
|
|
+ // 9.记录操作日志
|
|
|
+ String logContent = String.format(
|
|
|
+ "用户 %d 将设备 %s(ID=%s)转移给用户 %d",
|
|
|
+ param.getUserId(), // 转移前用户id
|
|
|
+ devInfo.getDevName(), // 转移的设备名称
|
|
|
+ devInfo.getDevId(), // 转移的设备id
|
|
|
+ userInfo.getUserId() // 转移后的用户id
|
|
|
+ );
|
|
|
+ logService.saveLog(OprLogType.DEVICE_TRANSFER.getCode(), logContent );
|
|
|
return true;
|
|
|
}
|
|
|
|