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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.circulation.domain.BizQuarantineStation;
import com.ruoyi.web.modules.circulation.mapper.BizQuarantineStationMapper;
import com.ruoyi.web.modules.circulation.support.QuarantineStationRules;
import com.ruoyi.web.modules.epidemic.domain.vo.QuarantineStationOptionVo;

/**
 * 实验室检测 — 检疫点（检疫站）校验与下拉数据。
 */
@Component
public class LabDetectionQuarantineStationSupport
{
    @Autowired
    private BizQuarantineStationMapper quarantineStationMapper;

    public void validateQuarantineStationId(Long quarantineStationId)
    {
        if (quarantineStationId == null)
        {
            throw new ServiceException("检疫点不能为空");
        }
        BizQuarantineStation station = quarantineStationMapper.selectBizQuarantineStationById(quarantineStationId);
        if (station == null)
        {
            throw new ServiceException("检疫点不存在或已删除");
        }
        if (station.getOperateStatus() == null
                || station.getOperateStatus() != QuarantineStationRules.OPERATE_STATUS_NORMAL)
        {
            throw new ServiceException("检疫点须为运营状态正常的检疫站");
        }
    }

    public List<QuarantineStationOptionVo> listNormalStationOptions()
    {
        BizQuarantineStation query = new BizQuarantineStation();
        query.setOperateStatus(QuarantineStationRules.OPERATE_STATUS_NORMAL);
        List<BizQuarantineStation> rows = quarantineStationMapper.selectBizQuarantineStationList(query);
        if (rows == null || rows.isEmpty())
        {
            return Collections.emptyList();
        }
        List<QuarantineStationOptionVo> options = new ArrayList<>(rows.size());
        for (BizQuarantineStation row : rows)
        {
            QuarantineStationOptionVo vo = new QuarantineStationOptionVo();
            vo.setId(row.getId());
            vo.setStationName(row.getStationName());
            options.add(vo);
        }
        return options;
    }
}
