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 @@
-
+
@@ -148,7 +148,7 @@
@@ -200,7 +200,7 @@ export default {
data() {
return {
// 打开设备配置对话框
- openSummary:false,
+ openSummary: false,
// 是否加载完成
isLoaded: false,
// 生成设备编码是否禁用
@@ -219,7 +219,7 @@ export default {
firmwareVersion: 1.0,
},
// 设备摘要
- summary:[],
+ summary: [],
// 图片地址
imageUrl: require('@/assets/images/product.jpg'),
// 地址
@@ -279,7 +279,7 @@ export default {
getDevice(deviceId) {
getDevice(deviceId).then(response => {
this.form = response.data;
- this.summary=JSON.parse(this.form.summary);
+ this.summary = JSON.parse(this.form.summary);
// 禁用状态
if (this.form.status == 2) {
this.deviceStatus = 1;
@@ -350,19 +350,25 @@ export default {
this.setDeviceStatus();
console.log(this.form);
updateDevice(this.form).then(response => {
- this.$modal.alertSuccess("修改成功");
- this.open = false;
- this.loadMap();
+ if (response.data == 0) {
+ this.$modal.alertError(response.msg);
+ } else {
+ this.$modal.alertSuccess("修改成功");
+ this.loadMap();
+ }
});
} else {
addDevice(this.form).then(response => {
- this.$modal.alertSuccess("新增成功, 可以烧录sdk到设备了");
- this.open = false;
this.form = response.data;
- if (this.form.status == 2) {
- this.deviceStatus = 1;
+ if (this.form.deviceId == null || this.form.deviceId == 0) {
+ this.$modal.alertError("设备编号已经存在,添加设备失败");
+ } else {
+ if (this.form.status == 2) {
+ this.deviceStatus = 1;
+ }
+ this.$modal.alertSuccess("新增成功, 可以烧录sdk到设备了");
+ this.loadMap();
}
- this.loadMap();
});
}
}
diff --git a/vue/src/views/iot/device/index.vue b/vue/src/views/iot/device/index.vue
index 35139520..b3d75e6c 100644
--- a/vue/src/views/iot/device/index.vue
+++ b/vue/src/views/iot/device/index.vue
@@ -230,6 +230,8 @@ export default {
open: false,
// 激活时间范围
daterangeActiveTime: [],
+ // 根路径
+ baseUrl: process.env.VUE_APP_BASE_API,
// 查询参数
queryParams: {
pageNum: 1,
diff --git a/vue/src/views/iot/product/product-alert.vue b/vue/src/views/iot/product/product-alert.vue
index 47c41f86..a35d1cd5 100644
--- a/vue/src/views/iot/product/product-alert.vue
+++ b/vue/src/views/iot/product/product-alert.vue
@@ -67,8 +67,9 @@
+
-
+
@@ -89,124 +90,118 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 删除
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 删除
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 生成表达式
-
-
-
-
-
-
- 自定义表达式
-
-
-
-
-
-
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 生成表达式
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ 自定义表达式
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 删除
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 删除
+
+
+