diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java index fcc373e..6d06c19 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceTypeServiceImpl.java @@ -107,6 +107,13 @@ public class DeviceTypeServiceImpl extends ServiceImpl typeName = deviceTypeMapper.selectList(new QueryWrapper().eq("type_name", resources.getTypeName())); + if (CollectionUtil.isNotEmpty(typeName)) { + throw new RuntimeException("设备类型名称已存在,无法新增!!!"); + } + LoginUser loginUser = LoginHelper.getLoginUser(); resources.setCustomerId(loginUser.getUserId()); resources.setOwnerCustomerId(loginUser.getUserId()); @@ -141,11 +148,23 @@ public class DeviceTypeServiceImpl extends ServiceImpl devices = deviceMapper.selectList(new QueryWrapper() + .eq("device_type", deviceTypeGrants.getDeviceTypeId())); + if (CollectionUtil.isNotEmpty(devices)) { + throw new RuntimeException("该设备类型已绑定设备,无法修改!!!"); + } + + // 校验设备类型名称 + DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper().eq("type_name", resources.getTypeName())); + if (dt != null && !dt.getId().equals(deviceType.getId())) { + throw new RuntimeException("设备类型名称已存在,无法修改!!!"); + } + if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) { throw new RuntimeException("无权修改该设备类型"); } - // if (deviceMapper.countByTypeId(resources.getId()) > 0) - // throw new RuntimeException("该设备类型已被使用,无法删除"); + BeanUtil.copyProperties(resources, deviceType); deviceTypeMapper.updateById(deviceType); }