界面和细节优化

This commit is contained in:
kerwincui
2022-06-08 01:58:26 +08:00
parent 267d60fb1a
commit 40d6a49bfc
12 changed files with 500 additions and 138 deletions

View File

@@ -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);
}
/**

View File

@@ -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);
/**
* 更新设备状态

View File

@@ -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;

View File

@@ -29,6 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="firmwareName != null and firmwareName != ''"> and firmware_name like concat('%', #{firmwareName}, '%')</if>
<if test="productName != null and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
<if test="tenantId != null and tenantId != ''"> and tenant_id = #{tenantId}</if>
<if test="productId != null"> and product_id = #{productId}</if>
</where>
order by create_time desc
</select>