package com.fs.hisStore.service.impl;

import com.fs.common.exception.CustomException;
import com.fs.common.utils.DateUtils;
import com.fs.hisStore.domain.FsDiseaseScrm;
import com.fs.hisStore.mapper.FsDiseaseScrmMapper;
import com.fs.hisStore.param.FsDiseaseListUParam;
import com.fs.hisStore.service.IFsDiseaseScrmService;
import com.fs.hisStore.vo.FsDiseaseListUVO;
import com.fs.hisStore.vo.FsDiseaseListVO;
import com.fs.hisStore.vo.FsDiseaseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 疾病Service业务层处理
 *
 * @author fs
 * @date 2023-06-01
 */
@Service
public class FsDiseaseScrmServiceImpl implements IFsDiseaseScrmService
{
    @Autowired
    private FsDiseaseScrmMapper fsDiseaseMapper;

    /**
     * 查询疾病
     *
     * @param diseaseId 疾病主键
     * @return 疾病
     */
    @Override
    public FsDiseaseScrm selectFsDiseaseByDiseaseId(Long diseaseId)
    {
        return fsDiseaseMapper.selectFsDiseaseByDiseaseId(diseaseId);
    }

    /**
     * 查询疾病列表
     *
     * @param fsDisease 疾病
     * @return 疾病
     */
    @Override
    public List<FsDiseaseScrm> selectFsDiseaseList(FsDiseaseScrm fsDisease)
    {
        return fsDiseaseMapper.selectFsDiseaseList(fsDisease);
    }

    /**
     * 新增疾病
     *
     * @param fsDisease 疾病
     * @return 结果
     */
    @Override
    public int insertFsDisease(FsDiseaseScrm fsDisease)
    {
        FsDiseaseScrm fsDisease1 = fsDiseaseMapper.selectFsDiseaseBydiseaseCode(fsDisease.getDiseaseCode());
        if (fsDisease1!=null){
            throw new CustomException("疾病编码已存在",566);
        }

        fsDisease.setCreateTime(DateUtils.getNowDate());
        return fsDiseaseMapper.insertFsDisease(fsDisease);
    }

    /**
     * 修改疾病
     *
     * @param fsDisease 疾病
     * @return 结果
     */
    @Override
    public int updateFsDisease(FsDiseaseScrm fsDisease)
    {
        FsDiseaseScrm fsDisease1 = fsDiseaseMapper.selectFsDiseaseBydiseaseCode(fsDisease.getDiseaseCode());
        if (fsDisease1.getDiseaseId()!=fsDisease.getDiseaseId()){
            throw new CustomException("疾病编码已存在",566);
        }


        return fsDiseaseMapper.updateFsDisease(fsDisease);
    }

    /**
     * 批量删除疾病
     *
     * @param diseaseIds 需要删除的疾病主键
     * @return 结果
     */
    @Override
    public int deleteFsDiseaseByDiseaseIds(Long[] diseaseIds)
    {
        return fsDiseaseMapper.deleteFsDiseaseByDiseaseIds(diseaseIds);
    }

    /**
     * 删除疾病信息
     *
     * @param diseaseId 疾病主键
     * @return 结果
     */
    @Override
    public int deleteFsDiseaseByDiseaseId(Long diseaseId)
    {
        return fsDiseaseMapper.deleteFsDiseaseByDiseaseId(diseaseId);
    }

    @Override
    public List<FsDiseaseListVO> selectFsDiseaseListVO(FsDiseaseScrm fsDisease) {

        return fsDiseaseMapper.selectFsDiseaseListVO(fsDisease);
    }



    @Override
    public FsDiseaseVO selectFsDiseaseVOByDiseaseId(Long diseaseId) {
        return fsDiseaseMapper.selectFsDiseaseVOById(diseaseId);
    }

    @Override
    public List<FsDiseaseListUVO> selectFsDiseaseListUVO(FsDiseaseListUParam param) {
        return fsDiseaseMapper.selectFsDiseaseListUVO(param);
    }
}
