Răsfoiți Sursa

接口调整

hxd 3 luni în urmă
părinte
comite
be74ae9ac7

+ 1 - 2
portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceListParams.java

@@ -5,7 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
-import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
 @EqualsAndHashCode(callSuper = true)
@@ -20,7 +19,7 @@ public class DeviceListParams extends BaseVO {
     @Schema(description = "关键词")
     private String keyWord;
 
-    @Schema(description = "状态 0:在线  1:离线  2:报警")
+    @Schema(description = "状态 不传:默认为全部 0:在线  1:离线  2:报警")
     private Integer status;
 
 

+ 45 - 2
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -28,6 +28,7 @@ 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.customer.util.WxOfficeAccountClient;
 import com.hfln.portal.domain.exception.ErrorEnum;
 import com.hfln.portal.domain.gateway.DeviceGateway;
 import com.hfln.portal.infrastructure.mqtt.MqttClient;
@@ -48,6 +49,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -88,6 +90,12 @@ public class DeviceGatewayImpl implements DeviceGateway {
     @Autowired
     private AlarmEventService alarmEventService;
 
+    @Autowired
+    private WxOfficeAccountClient wxOfficeAccountClient;
+
+    @Autowired
+    private WxRelationService wxRelationService;
+
 
     @Override
     public HomeInfoDTO queryHomeInfo(Long userId) {
@@ -897,6 +905,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
     }
 
     @Override
+    @Transactional
     public Boolean deviceTransfer(DeviceTransferParams param){
 
         //1. 查询设备信息并校验是否存在
@@ -920,9 +929,43 @@ public class DeviceGatewayImpl implements DeviceGateway {
             throw new BizException(ErrorEnum.USER_IS_NOT_EXIST.getErrorCode(), ErrorEnum.USER_IS_NOT_EXIST.getErrorMessage());
         }
 
-        //4.转移设备归属
+        //4.转移当前设备归属
         devInfo.setUserId(userInfo.getUserId());
-        return devInfoService.updateById(devInfo);
+
+        //5.设备分享表修改
+        List<DevShare> devShareList = devShareService.list(
+                Wrappers.<DevShare>lambdaQuery()
+                        .eq(DevShare::getDevId, param.getDevId())
+                        .eq(DevShare::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED)
+        );
+
+        //6. 遍历设备分享表
+        if (!devShareList.isEmpty()) {
+            devShareList.forEach(devShare -> {
+                if (Objects.equals(devShare.getSharerUserId(), userInfo.getUserId())) {
+                    devShare.setIsDeleted(BasePO.DeleteFlag.DELETED);  // 软删除
+                } else {
+                    devShare.setSharerUserId(userInfo.getUserId());  // 更新分享者用户
+                }
+                devShare.setUpdateTime(LocalDateTime.now());  // 更新修改时间
+            });
+            devShareService.updateBatchById(devShareList);  // 批量更新设备分享记录
+        }
+        //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() + ", phoneNo=" + userInfo.getPhone() + "fwhOpenId=" + fwhOpenId);
+        wxOfficeAccountClient.sendMsg(devInfo.getClientId(), devInfo.getDevName(),userInfo.getPhone(), fwhOpenId, "设备转移成功,请前往小程序查看");
+        log.info("发送微信公众号信息完毕");
+        return true;
     }