瀏覽代碼

接口修改

hxd 3 月之前
父節點
當前提交
5a30082467

+ 6 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/wap/DeviceController.java

@@ -94,6 +94,12 @@ public class DeviceController {
     public ApiResult<Boolean> deviceTransfer(@RequestParam("phone") String phone, @RequestParam("devId") String devId) {
         return ApiResult.success(deviceGateway.deviceTransfer(phone, devId));
     }
+
+    @PostMapping("/statusLight")
+    @Operation(summary = "设备指示灯开关")
+    public ApiResult<Boolean> statusLight(@RequestParam("devId") Long devId, @RequestParam("status_light") Integer statusLight) {
+        return ApiResult.success(deviceGateway.statusLight(devId, statusLight));
+    }
 /*
 
     @GetMapping("/checkDevByOpenId")

+ 37 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebRoomController.java

@@ -0,0 +1,37 @@
+package com.hfln.portal.application.controller.web;
+
+
+import cn.hfln.framework.catchlog.CatchAndLog;
+import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.dto.data.room.RoomDto;
+import com.hfln.portal.domain.gateway.DeviceGateway;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@RestController
+@CatchAndLog
+@Tag(name = "web端房间相关")
+@Slf4j
+@RequestMapping("/web/room")
+public class WebRoomController {
+
+    @Autowired
+    private DeviceGateway deviceGateway;
+
+    @GetMapping("/readRoom")
+    @Operation(summary = "读取房间信息")
+    public ApiResult<RoomDto> readRoom(@RequestParam Long devId) {
+        return ApiResult.success(deviceGateway.readRoom(devId));
+    }
+
+    @PostMapping("/saveRoom")
+    @Operation(summary = "房间布局保存")
+    public ApiResult<Boolean> saveRoom(@Valid @RequestBody RoomDto roomDto) {
+        return ApiResult.success(deviceGateway.saveRoom(roomDto));
+    }
+}

+ 6 - 4
portal-service-common/src/main/java/com/hfln/portal/common/request/device/DeviceBandingParams.java

@@ -21,14 +21,14 @@ public class DeviceBandingParams extends BaseVO {
     @Schema(description = "用户Id", required = true)
     private Long userId;
 
-    @Schema(description = "设备名称最多10个字符")
+    @Schema(description = "设备名称最多10个字符")
     @Size(max = 10, message = "设备名称不能超过10个字符")
     private String devName;
 
-    @Schema(description = "监测X长度:xxEnd-xxStart")
+    @Schema(description = "监测X长度: xxEnd-xxStart")
     private BigDecimal length;
 
-    @Schema(description = "监测Y宽度yyEnd-yyStart")
+    @Schema(description = "监测Y宽度yyEnd-yyStart")
     private BigDecimal width;
 
     @Schema(description = "安装高度")
@@ -73,10 +73,12 @@ public class DeviceBandingParams extends BaseVO {
     private BigDecimal yyEnd;
 
 
-    @Schema(description = "雷达监测范围z开始,范围 0-5 cm之内")
+    @Schema(description = "雷达监测范围z开始,范围0-5 cm之内")
     @DecimalMin(value = "0", message = "zzStart不能小于0")
     @DecimalMax(value = "5", message = "zzStart不能大于5")
     private BigDecimal zzStart;
+
+
     @Schema(description = "雷达监测范围z结束,范围:200-300 cm之内")
     @DecimalMin(value = "0", message = "zzEnd不能小于0")
     @DecimalMax(value = "5", message = "zzEnd不能大于5")

+ 1 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/exception/ErrorEnum.java

@@ -53,6 +53,7 @@ public enum ErrorEnum implements ErrorEnumInterface{
     CLIENT_ID_ID_NULL("50003", "设备ID不能为空!"),
     DEVICE_IS_EXIST("50004", "设备已存在!"),
     DEVICE_PARAM_ERROR("50005", "设备参数范围错误!"),
+    STATUS_LIGHT_IS_NOT_EXIST("50006","指示灯状态不合法"),
 
     /**
      * 设备房间相关

+ 5 - 1
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/DeviceGateway.java

@@ -21,7 +21,9 @@ import java.util.List;
 
 public interface DeviceGateway {
 
-
+    /**
+     * 设备相关
+     */
     HomeInfoDTO queryHomeInfo(Long userId);
 
     List<DeviceDTO> queryDeviceList(DeviceListParams request);
@@ -42,6 +44,8 @@ public interface DeviceGateway {
 
     Boolean checkDevByUserId(Long userId, Long devId);
 
+    Boolean statusLight(Long devId, Integer statusLight);
+
 
     /**
      * 房间布局

+ 24 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/DeviceGatewayImpl.java

@@ -416,6 +416,30 @@ public class DeviceGatewayImpl implements DeviceGateway {
     }
 
     @Override
+    public Boolean statusLight(Long devId, Integer statusLight) {
+        //1.校验设备是否存在
+        DevInfo devInfo = devInfoService.getById(devId);
+        if(devInfo == null){
+            throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
+        }
+
+        //2.校验status_light值,只能传 0 与 1
+        if (statusLight == null || statusLight != 0 && statusLight != 1){
+            throw new BizException(ErrorEnum.STATUS_LIGHT_IS_NOT_EXIST.getErrorCode(), ErrorEnum.STATUS_LIGHT_IS_NOT_EXIST.getErrorMessage());
+        }
+
+        //3.更新设备指示灯状态
+        boolean update = devInfoService.update(
+                Wrappers.<DevInfo>lambdaUpdate()
+                        .set(DevInfo::getStatusLight, statusLight)
+                        .eq(DevInfo::getDevId, devId)
+        );
+        return update;
+
+        //TODO 通过mqtt往设备发送消息
+    }
+
+    @Override
     public RoomDto readRoom(Long devId) {
 
         DevRoom devRoom = devRoomService.queryByDevId(devId);