Parcourir la source

设备导入、保存增加产品校验

xucaiqin il y a 2 ans
Parent
commit
f5d1a2e79e

+ 4 - 4
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotDeviceController.java

@@ -38,7 +38,7 @@ public class IotDeviceController {
      */
     @PostMapping("/list")
     public Result<Object> list(@RequestBody @Validated DevicePage devicePage) {
-        return Result.ok(iotDeviceService.pageQuery(devicePage));
+        return Result.ok(iotDeviceService.pageQuery(devicePage),"查询成功");
     }
 
     /**
@@ -49,7 +49,7 @@ public class IotDeviceController {
      */
     @PostMapping("/save")
     public Result<Object> save(@RequestBody @Validated IotDevicePara iotDevicePara) {
-        return Result.ok(iotDeviceService.save(iotDevicePara));
+        return Result.ok(iotDeviceService.save(iotDevicePara),"保存成功");
     }
 
     /**
@@ -60,7 +60,7 @@ public class IotDeviceController {
      */
     @GetMapping("/detail")
     public Result<Object> detail(@NotNull(message = "id不能为空") @Validated Long id) {
-        return Result.ok(iotDeviceService.detail(id));
+        return Result.ok(iotDeviceService.detail(id),"查询成功");
     }
 
     /**
@@ -71,7 +71,7 @@ public class IotDeviceController {
      */
     @GetMapping("/modDetail")
     public Result<Object> modDetail(@NotNull(message = "id不能为空") @Validated Long id) {
-        return Result.ok(iotDeviceService.detail(id));
+        return Result.ok(iotDeviceService.detail(id),"查询成功");
     }
 
     /**

+ 0 - 7
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotDevicePara.java

@@ -1,12 +1,8 @@
 package com.middle.platform.manage.biz.domain.req;
 
-import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Getter;
 import lombok.Setter;
 
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-
 /**
  * 设备表
  *
@@ -17,8 +13,6 @@ import java.time.LocalDateTime;
 @Setter
 public class IotDevicePara {
 
-
-
     /**
      * 所属产品
      */
@@ -34,7 +28,6 @@ public class IotDevicePara {
      */
     private String sn;
 
-
     /**
      * 备注名称
      */

+ 15 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotDeviceService.java

@@ -80,6 +80,8 @@ public class IotDeviceService {
     public Object save(IotDevicePara iotDevicePara) {
         //校验sn
         checkDeviceSn(iotDevicePara.getSn());
+        //校验产品
+        checkProduct(iotDevicePara.getProductId());
         IotDevice iotDevice = new IotDevice();
         iotDevice.setProductId(iotDevicePara.getProductId());
         iotDevice.setName(iotDevicePara.getName());
@@ -244,4 +246,17 @@ public class IotDeviceService {
             throw new BusinessException("当前设备【" + iotDevice.getSn() + "】已存在");
         }
     }
+
+    /**
+     * 校验产品
+     *
+     * @param productId 产品id
+     */
+    private void checkProduct(Long productId) {
+        IotProduct iotProduct = iotProductMapper.selectOne(new LambdaQueryWrapper<IotProduct>()
+                .eq(IotProduct::getId, productId).eq(IotProduct::getDelFlag, Global.UN_DEL).last("limit 1"));
+        if (Objects.isNull(iotProduct)) {
+            throw new BusinessException("当前产品不存在");
+        }
+    }
 }