package com.fs.hospital.service.impl;

import java.util.List;

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

/**
 * 检查Service业务层处理
 *
 * @author fs
 * @date 2024-03-26
 */
@Service
public class HospitalInspectItemServiceImpl implements IHospitalInspectItemService
{
    @Autowired
    private HospitalInspectItemMapper hospitalInspectItemMapper;

    /**
     * 查询检查
     *
     * @param inspectId 检查主键
     * @return 检查
     */
    @Override
    public HospitalInspectItem selectHospitalInspectItemByInspectId(Long inspectId)
    {
        return hospitalInspectItemMapper.selectHospitalInspectItemByInspectId(inspectId);
    }

    /**
     * 查询检查列表
     *
     * @param hospitalInspectItem 检查
     * @return 检查
     */
    @Override
    public List<HospitalInspectItem> selectHospitalInspectItemList(HospitalInspectItem hospitalInspectItem)
    {
        return hospitalInspectItemMapper.selectHospitalInspectItemList(hospitalInspectItem);
    }

    /**
     * 新增检查
     *
     * @param hospitalInspectItem 检查
     * @return 结果
     */
    @Override
    public int insertHospitalInspectItem(HospitalInspectItem hospitalInspectItem)
    {
        HospitalInspectItem item = hospitalInspectItemMapper.selectHospitalInspectItemByCode(hospitalInspectItem.getInspectCode());
        if (item!=null){
            throw new CustomException("已经存在该编号");
        }
        return hospitalInspectItemMapper.insertHospitalInspectItem(hospitalInspectItem);
    }

    /**
     * 修改检查
     *
     * @param hospitalInspectItem 检查
     * @return 结果
     */
    @Override
    public int updateHospitalInspectItem(HospitalInspectItem hospitalInspectItem)
    {
        HospitalInspectItem item = hospitalInspectItemMapper.selectHospitalInspectItemByCode(hospitalInspectItem.getInspectCode());
        if (item!=null&&item.getInspectId()!=hospitalInspectItem.getInspectId()){
            throw new CustomException("已经存在该编号");
        }

        return hospitalInspectItemMapper.updateHospitalInspectItem(hospitalInspectItem);
    }

    /**
     * 批量删除检查
     *
     * @param inspectIds 需要删除的检查主键
     * @return 结果
     */
    @Override
    public int deleteHospitalInspectItemByInspectIds(Long[] inspectIds)
    {
        return hospitalInspectItemMapper.deleteHospitalInspectItemByInspectIds(inspectIds);
    }

    /**
     * 删除检查信息
     *
     * @param inspectId 检查主键
     * @return 结果
     */
    @Override
    public int deleteHospitalInspectItemByInspectId(Long inspectId)
    {
        return hospitalInspectItemMapper.deleteHospitalInspectItemByInspectId(inspectId);
    }
}
