diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java index 25cef9e..11b9d48 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java @@ -81,6 +81,9 @@ public class AsDeviceController extends BaseController if(!asDeviceService.checkSNUnique(asDevice)){ return error("新增车辆'" + asDevice.getDeviceName() + "'失败,SN已存在"); } + if(!asDeviceService.checkMACUnique(asDevice)){ + return error("新增车辆'" + asDevice.getDeviceName() + "'失败,MAC已存在"); + } return toAjax(asDeviceService.insertAsDevice(asDevice)); } @@ -95,6 +98,9 @@ public class AsDeviceController extends BaseController if(!asDeviceService.checkSNUnique(asDevice)){ return error("修改车辆'" + asDevice.getDeviceName() + "'失败,SN已存在"); } + if(!asDeviceService.checkMACUnique(asDevice)){ + return error("修改车辆'" + asDevice.getDeviceName() + "'失败,MAC已存在"); + } return toAjax(asDeviceService.updateAsDevice(asDevice)); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java index fbb4790..bb15580 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/AsDeviceMapper.java @@ -109,4 +109,6 @@ public interface AsDeviceMapper extends BaseMapper AsDevice checkSNUnique(String sn); + + AsDevice checkMACUnique(String mac); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java index 92f4111..7a16b95 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java @@ -251,6 +251,11 @@ public interface IAsDeviceService extends IService */ boolean checkSNUnique(AsDevice asDevice); + /** + * 判断是否重复 + */ + boolean checkMACUnique(AsDevice asDevice); + // /** // * 是否靠近运营区边界 // */ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 4b154d0..28f78fe 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -1412,6 +1412,20 @@ public class AsDeviceServiceImpl extends ServiceImpl i return UserConstants.UNIQUE; } + /** + * 检查SN是否唯一 + */ + @Override + public boolean checkMACUnique(AsDevice asDevice) { + Long deviceId = StringUtils.isNull(asDevice.getDeviceId()) ? -1L : asDevice.getDeviceId(); + AsDevice info = asDeviceMapper.checkMACUnique(asDevice.getMac()); + if (StringUtils.isNotNull(info) && info.getDeviceId().longValue() != deviceId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + /** * 判断是否靠近边界 diff --git a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml index 39f3614..d10f1d0 100644 --- a/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/AsDeviceMapper.xml @@ -131,6 +131,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select device_id, sn, device_name from et_device where sn = #{sn} limit 1 + + insert into et_device