Bladeren bron

修改设备接口新增

xucaiqin 1 jaar geleden
bovenliggende
commit
ee98c5a92b

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

@@ -52,7 +52,16 @@ public class IotDeviceController {
     public Result<Object> save(@RequestBody @Validated IotDevicePara iotDevicePara) {
         return Result.ok(iotDeviceService.save(iotDevicePara), "保存成功");
     }
-
+    /**
+     * 修改设备
+     *
+     * @param iotDevicePara
+     * @return
+     */
+    @PostMapping("/update")
+    public Result<Object> update(@RequestBody @Validated IotDevicePara iotDevicePara) {
+        return Result.ok(iotDeviceService.update(iotDevicePara), "修改成功");
+    }
     /**
      * 设备详情
      *

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

@@ -15,6 +15,7 @@ import lombok.Setter;
 @Getter
 @Setter
 public class IotDevicePara {
+    private Long id;
 
     /**
      * 所属产品

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

@@ -104,6 +104,32 @@ public class IotDeviceService {
         return true;
     }
 
+    /**
+     * 修改设备
+     *
+     * @param iotDevicePara
+     * @return
+     */
+    public Object update(IotDevicePara iotDevicePara) {
+        if (Objects.isNull(iotDevicePara.getId())) {
+            throw new BusinessException("id不能为空");
+        }
+        //校验sn
+        checkDeviceSn(iotDevicePara.getSn());
+        //校验产品
+        checkProduct(iotDevicePara.getProductId());
+
+        IotDevice iotDevice = new IotDevice();
+        iotDevice.setId(iotDevicePara.getId());
+        iotDevice.setProductId(iotDevicePara.getProductId());
+        iotDevice.setName(iotDevicePara.getName());
+        iotDevice.setSn(iotDevicePara.getSn());
+        iotDevice.setSubtitle(iotDevicePara.getSubtitle());
+        iotDevice.setRemark(iotDevicePara.getRemark());
+        iotDeviceMapper.updateById(iotDevice);
+        return true;
+    }
+
     /**
      * 删除设备
      *
@@ -208,9 +234,7 @@ public class IotDeviceService {
         }
         //产品编码转换
         for (DeviceImportExcelVo deviceImportExcelVo : list) {
-            IotProduct iotProduct = iotProductMapper.selectOne(new LambdaQueryWrapper<IotProduct>()
-                    .eq(IotProduct::getCode, deviceImportExcelVo.getCode())
-                    .eq(IotProduct::getDelFlag, Global.UN_DEL).last("limit 1"));
+            IotProduct iotProduct = iotProductMapper.selectOne(new LambdaQueryWrapper<IotProduct>().eq(IotProduct::getCode, deviceImportExcelVo.getCode()).eq(IotProduct::getDelFlag, Global.UN_DEL).last("limit 1"));
             if (Objects.isNull(iotProduct)) {
                 throw new BusinessException("产品编码[" + deviceImportExcelVo.getCode() + "]产品不存在");
             }
@@ -257,8 +281,7 @@ public class IotDeviceService {
      * @param sn
      */
     private void checkDeviceSn(String sn) {
-        IotDevice iotDevice = iotDeviceMapper.selectOne(new LambdaQueryWrapper<IotDevice>()
-                .eq(IotDevice::getSn, sn).eq(IotDevice::getDelFlag, Global.UN_DEL).last("limit 1"));
+        IotDevice iotDevice = iotDeviceMapper.selectOne(new LambdaQueryWrapper<IotDevice>().eq(IotDevice::getSn, sn).eq(IotDevice::getDelFlag, Global.UN_DEL).last("limit 1"));
         if (Objects.nonNull(iotDevice)) {
             throw new BusinessException("当前设备【" + iotDevice.getSn() + "】已存在");
         }
@@ -270,10 +293,11 @@ public class IotDeviceService {
      * @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"));
+        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("当前产品不存在");
         }
     }
+
+
 }