| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.system.domain.TDetectionCabinet; |
| | | import com.ruoyi.system.domain.vo.DiscoveredCabinetVo; |
| | | import com.ruoyi.system.mapper.TDetectionCabinetMapper; |
| | | import com.ruoyi.system.service.ITDetectionCabinetService; |
| | | |
| | |
| | | private static final String NORMAL = "0"; |
| | | private static final String DISABLED = "1"; |
| | | private static final String TESTING = "1"; |
| | | private static final String ACTIVE = "ACTIVE"; |
| | | private static final String DISCOVERED = "DISCOVERED"; |
| | | |
| | | private final TDetectionCabinetMapper detectionCabinetMapper; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 新增检测柜,统一基础字段格式并校验 IP、设备编码和 MAC 地址后初始化运行状态。 |
| | | * 复用已持久化检测柜事实供原选择设备弹窗展示,不生成模拟设备。 |
| | | * 测试占用状态由已持久化通道工作状态聚合;测试归属留待后续绑定闭环确认。 |
| | | * |
| | | * @return 可供选择的检测柜设备摘要 |
| | | */ |
| | | @Override |
| | | public List<DiscoveredCabinetVo> selectDiscoveredCabinetList() |
| | | { |
| | | return detectionCabinetMapper.selectDiscoveredCabinetList().stream() |
| | | .map(cabinet -> { |
| | | boolean active = ACTIVE.equals(cabinet.getObservedWorkStatus()); |
| | | return new DiscoveredCabinetVo( |
| | | cabinet.getCabinetCode(), |
| | | cabinet.getIpAddress(), |
| | | cabinet.getMacAddress(), |
| | | cabinet.getCabinetName(), |
| | | cabinet.getManufacturer(), |
| | | cabinet.getModel(), |
| | | cabinet.getChannelCount(), |
| | | isOnline(cabinet.getOnlineStatus()) ? "在线" : "离线", |
| | | active ? "测试中" : "空闲", |
| | | active ? "待确认" : "-"); |
| | | }) |
| | | .toList(); |
| | | } |
| | | |
| | | private boolean isOnline(String onlineStatus) |
| | | { |
| | | return NORMAL.equals(onlineStatus) || "ONLINE".equalsIgnoreCase(onlineStatus); |
| | | } |
| | | |
| | | /** |
| | | * 将操作员选择的发现候选设备登记为检测柜,并保留其适配器和通道身份。 |
| | | * |
| | | * @param detectionCabinet 检测柜信息 |
| | | * @return 影响行数 |
| | |
| | | { |
| | | normalizeBasicFields(detectionCabinet); |
| | | validateIpAddress(detectionCabinet.getIpAddress()); |
| | | TDetectionCabinet candidate = detectionCabinetMapper.selectByCabinetCode(detectionCabinet.getCabinetCode()); |
| | | if (candidate == null) |
| | | { |
| | | throw new ServiceException("请先选择发现候选设备"); |
| | | } |
| | | if (!DISCOVERED.equals(candidate.getRegistrationStatus())) |
| | | { |
| | | throw new ServiceException("设备编码已存在"); |
| | | } |
| | | detectionCabinet.setCabinetId(candidate.getCabinetId()); |
| | | validateUniqueFields(detectionCabinet); |
| | | detectionCabinet.setOnlineStatus(NORMAL); |
| | | detectionCabinet.setTestStatus(NORMAL); |
| | | detectionCabinet.setCurrentTest(null); |
| | | detectionCabinet.setStatus(NORMAL); |
| | | detectionCabinet.setDelFlag(NORMAL); |
| | | try |
| | | { |
| | | return detectionCabinetMapper.insertDetectionCabinet(detectionCabinet); |
| | | int rows = detectionCabinetMapper.registerDiscoveredCabinet(detectionCabinet); |
| | | if (rows == 0) throw new ServiceException("发现候选设备状态已变化,请重新选择"); |
| | | return rows; |
| | | } |
| | | catch (DuplicateKeyException exception) |
| | | { |
| | |
| | | @Override |
| | | public boolean checkMacAddressUnique(TDetectionCabinet detectionCabinet) |
| | | { |
| | | if (StringUtils.isBlank(detectionCabinet.getMacAddress())) |
| | | { |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | Long cabinetId = StringUtils.isNull(detectionCabinet.getCabinetId()) ? -1L : detectionCabinet.getCabinetId(); |
| | | TDetectionCabinet info = detectionCabinetMapper.selectByMacAddress(detectionCabinet.getMacAddress()); |
| | | if (StringUtils.isNotNull(info) && info.getCabinetId().longValue() != cabinetId.longValue()) |
| | |
| | | |
| | | private String normalizeMacAddress(String macAddress) |
| | | { |
| | | return StringUtils.trim(macAddress).replace('-', ':').toUpperCase(Locale.ROOT); |
| | | String normalized = StringUtils.trim(macAddress); |
| | | return StringUtils.isBlank(normalized) ? null : normalized.replace('-', ':').toUpperCase(Locale.ROOT); |
| | | } |
| | | |
| | | private void validateIpAddress(String ipAddress) |