package com.fs.store.service.impl;

import com.fs.common.exception.CustomException;
import com.fs.common.utils.DateUtils;
import com.fs.store.domain.FsDisease;
import com.fs.store.mapper.FsDiseaseMapper;
import com.fs.store.param.FsDiseaseListUParam;
import com.fs.store.service.IFsDiseaseService;
import com.fs.store.vo.FsDiseaseListUVO;
import com.fs.store.vo.FsDiseaseListVO;
import com.fs.store.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 FsDiseaseServiceImpl implements IFsDiseaseService
{
    @Autowired
    private FsDiseaseMapper fsDiseaseMapper;

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

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

    /**
     * 新增疾病
     *
     * @param fsDisease 疾病
     * @return 结果
     */
    @Override
    public int insertFsDisease(FsDisease fsDisease)
    {
        FsDisease 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(FsDisease fsDisease)
    {
        FsDisease 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(FsDisease 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);
    }
}
