diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceController.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceController.java index 70b7fb03..2005d025 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceController.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceController.java @@ -150,7 +150,7 @@ public class DeviceController extends BaseController @ApiOperation("修改设备") public AjaxResult edit(@RequestBody Device device) { - return toAjax(deviceService.updateDevice(device)); + return deviceService.updateDevice(device); } /** diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceService.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceService.java index e2191c23..94b7b5ba 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceService.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceService.java @@ -1,5 +1,6 @@ package com.ruoyi.iot.service; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.iot.domain.Device; import com.ruoyi.iot.model.*; import com.ruoyi.iot.model.ThingsModels.ThingsModelShadow; @@ -129,7 +130,7 @@ public interface IDeviceService * @param device 设备 * @return 结果 */ - public int updateDevice(Device device); + public AjaxResult updateDevice(Device device); /** * 更新设备状态 diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java index f911b4d9..3d740f58 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java @@ -3,8 +3,10 @@ package com.ruoyi.iot.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; @@ -447,6 +449,12 @@ public class DeviceServiceImpl implements IDeviceService { @Override @Transactional(rollbackFor = Exception.class) public Device insertDevice(Device device) { + // 设备编号唯一检查 + Device existDevice=deviceMapper.selectDeviceBySerialNumber(device.getSerialNumber()); + if(existDevice!=null){ + log.error("设备编号:"+device.getSerialNumber()+"已经存在了,新增设备失败"); + return device; + } SysUser sysUser = getLoginUser().getUser(); //添加设备 device.setCreateTime(DateUtils.getNowDate()); @@ -492,6 +500,12 @@ public class DeviceServiceImpl implements IDeviceService { */ @Override public int insertDeviceAuto(String serialNumber,Long userId,Long productId) { + // 设备编号唯一检查 + Device existDevice=deviceMapper.selectDeviceBySerialNumber(serialNumber); + if(existDevice!=null){ + log.error("设备编号:"+serialNumber+"已经存在了,新增设备失败"); + return 0; + } Device device = new Device(); int random = (int) (Math.random() * (9000)) + 1000; device.setDeviceName("设备" + random); @@ -599,7 +613,16 @@ public class DeviceServiceImpl implements IDeviceService { * @return 结果 */ @Override - public int updateDevice(Device device) { + public AjaxResult updateDevice(Device device) { + // 设备编号唯一检查 + Device oldDevice=deviceMapper.selectDeviceByDeviceId(device.getDeviceId()); + if(!oldDevice.getSerialNumber().equals(device.getSerialNumber())){ + Device existDevice=deviceMapper.selectDeviceBySerialNumber(device.getSerialNumber()); + if(existDevice!=null){ + log.error("设备编号:"+device.getSerialNumber()+" 已经存在,新增设备失败"); + return AjaxResult.success("设备编号:"+device.getSerialNumber()+" 已经存在,修改失败",0); + } + } device.setUpdateTime(DateUtils.getNowDate()); // 未激活状态,可以修改产品以及物模型值 if (device.getStatus() == 1) { @@ -608,7 +631,8 @@ public class DeviceServiceImpl implements IDeviceService { device.setProductId(null); device.setProductName(null); } - return deviceMapper.updateDevice(device); + deviceMapper.updateDevice(device); + return AjaxResult.success("修改成功",1); } /** @@ -617,7 +641,9 @@ public class DeviceServiceImpl implements IDeviceService { */ @Override public String generationDeviceNum() { - String number= "D"+toolService.getStringRandom(15); + // 设备编号:D + userId + 15位随机字母和数字 + SysUser user = getLoginUser().getUser(); + String number= "D"+user.getUserId().toString()+toolService.getStringRandom(10); int count= deviceMapper.getDeviceNumCount(number); if(count==0) { return number; diff --git a/springboot/wumei-iot/src/main/resources/mapper/iot/FirmwareMapper.xml b/springboot/wumei-iot/src/main/resources/mapper/iot/FirmwareMapper.xml index 894699b6..a6cdaca6 100644 --- a/springboot/wumei-iot/src/main/resources/mapper/iot/FirmwareMapper.xml +++ b/springboot/wumei-iot/src/main/resources/mapper/iot/FirmwareMapper.xml @@ -29,6 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and firmware_name like concat('%', #{firmwareName}, '%') and product_name like concat('%', #{productName}, '%') and tenant_id = #{tenantId} + and product_id = #{productId} order by create_time desc diff --git a/vue/src/views/iot/device/device-edit.vue b/vue/src/views/iot/device/device-edit.vue index 44884f4d..4441d9d4 100644 --- a/vue/src/views/iot/device/device-edit.vue +++ b/vue/src/views/iot/device/device-edit.vue @@ -139,7 +139,7 @@ - +