yeg
2026-08-27 a4f06a9095a2eab0bb48b406c4609be6e70b8854
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDetectionCabinetServiceImpl.java
@@ -12,6 +12,7 @@
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;
@@ -26,6 +27,8 @@
    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;
@@ -73,7 +76,39 @@
    }
    /**
     * 新增检测柜,统一基础字段格式并校验 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 影响行数
@@ -83,15 +118,23 @@
    {
        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)
        {
@@ -204,6 +247,10 @@
    @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())
@@ -238,7 +285,8 @@
    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)