package com.fs.hospital.service.impl;

import java.util.List;

import com.fs.common.exception.CustomException;
import com.fs.hospital.domain.HospitalInspectItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.hospital.mapper.HospitalExamItemMapper;
import com.fs.hospital.domain.HospitalExamItem;
import com.fs.hospital.service.IHospitalExamItemService;

/**
 * 检验项目Service业务层处理
 *
 * @author fs
 * @date 2024-03-26
 */
@Service
public class HospitalExamItemServiceImpl implements IHospitalExamItemService
{
    @Autowired
    private HospitalExamItemMapper hospitalExamItemMapper;

    /**
     * 查询检验项目
     *
     * @param examId 检验项目主键
     * @return 检验项目
     */
    @Override
    public HospitalExamItem selectHospitalExamItemByExamId(Long examId)
    {
        return hospitalExamItemMapper.selectHospitalExamItemByExamId(examId);
    }

    /**
     * 查询检验项目列表
     *
     * @param hospitalExamItem 检验项目
     * @return 检验项目
     */
    @Override
    public List<HospitalExamItem> selectHospitalExamItemList(HospitalExamItem hospitalExamItem)
    {
        return hospitalExamItemMapper.selectHospitalExamItemList(hospitalExamItem);
    }

    /**
     * 新增检验项目
     *
     * @param hospitalExamItem 检验项目
     * @return 结果
     */
    @Override
    public int insertHospitalExamItem(HospitalExamItem hospitalExamItem)
    {
        HospitalExamItem item = hospitalExamItemMapper.selectHospitalExamItemByCode(hospitalExamItem.getExamCode());
        if (item!=null){
            throw new CustomException("已经存在该编号");
        }
        return hospitalExamItemMapper.insertHospitalExamItem(hospitalExamItem);
    }

    /**
     * 修改检验项目
     *
     * @param hospitalExamItem 检验项目
     * @return 结果
     */
    @Override
    public int updateHospitalExamItem(HospitalExamItem hospitalExamItem)
    {
        HospitalExamItem item = hospitalExamItemMapper.selectHospitalExamItemByCode(hospitalExamItem.getExamCode());
        if (item!=null&&item.getExamId()!=hospitalExamItem.getExamId()){
            throw new CustomException("已经存在该编号");
        }
        return hospitalExamItemMapper.updateHospitalExamItem(hospitalExamItem);
    }

    /**
     * 批量删除检验项目
     *
     * @param examIds 需要删除的检验项目主键
     * @return 结果
     */
    @Override
    public int deleteHospitalExamItemByExamIds(Long[] examIds)
    {
        return hospitalExamItemMapper.deleteHospitalExamItemByExamIds(examIds);
    }

    /**
     * 删除检验项目信息
     *
     * @param examId 检验项目主键
     * @return 结果
     */
    @Override
    public int deleteHospitalExamItemByExamId(Long examId)
    {
        return hospitalExamItemMapper.deleteHospitalExamItemByExamId(examId);
    }
}
