package com.ruoyi.web.modules.diagnosis.support;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;

/**
 * 批量操作 ID 解析（逗号分隔字符串）。
 */
public final class MedicalResourceBatchIds
{
    private MedicalResourceBatchIds()
    {
    }

    public static Long[] parse(String ids)
    {
        if (StringUtils.isEmpty(ids))
        {
            return new Long[0];
        }
        String[] parts = ids.split(",");
        List<Long> cleaned = new ArrayList<>();
        for (String part : parts)
        {
            String trimmed = part.trim();
            if (StringUtils.isEmpty(trimmed))
            {
                continue;
            }
            try
            {
                cleaned.add(Long.valueOf(trimmed));
            }
            catch (NumberFormatException ex)
            {
                throw new ServiceException("ID 格式无效：" + trimmed);
            }
        }
        return cleaned.toArray(new Long[0]);
    }
}
