package com.fs.store.service.impl;

import com.fs.common.exception.CustomException;
import com.fs.common.utils.DateUtils;
import com.fs.store.domain.FsDepartment;
import com.fs.store.mapper.FsDepartmentMapper;
import com.fs.store.service.IFsDepartmentService;
import com.fs.his.vo.OptionsVO;
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 FsDepartmentServiceImpl implements IFsDepartmentService
{
    @Autowired
    private FsDepartmentMapper fsDepartmentMapper;

    /**
     * 查询科室
     *
     * @param deptId 科室主键
     * @return 科室
     */
    @Override
    public FsDepartment selectFsDepartmentByDeptId(Long deptId)
    {
        return fsDepartmentMapper.selectFsDepartmentByDeptId(deptId);
    }

    /**
     * 查询科室列表
     *
     * @param fsDepartment 科室
     * @return 科室
     */
    @Override
    public List<FsDepartment> selectFsDepartmentList(FsDepartment fsDepartment)
    {
        return fsDepartmentMapper.selectFsDepartmentList(fsDepartment);
    }

    /**
     * 新增科室
     *
     * @param fsDepartment 科室
     * @return 结果
     */
    @Override
    public int insertFsDepartment(FsDepartment fsDepartment)
    {

        FsDepartment fsDepartment1 = fsDepartmentMapper.selectFsDepartmentByDeptCode(fsDepartment.getDeptCode());

        if (fsDepartment1!=null){
            throw new CustomException("科室编码重复",565);
        }
        fsDepartment.setCreateTime(DateUtils.getNowDate());
        return fsDepartmentMapper.insertFsDepartment(fsDepartment);
    }

    /**
     * 修改科室
     *
     * @param fsDepartment 科室
     * @return 结果
     */
    @Override
    public int updateFsDepartment(FsDepartment fsDepartment)
    {
        FsDepartment fsDepartment1 = fsDepartmentMapper.selectFsDepartmentByDeptCode(fsDepartment.getDeptCode());
        if (fsDepartment1!=null&&fsDepartment1.getDeptId()!=fsDepartment.getDeptId()){
            throw new CustomException("科室编码重复",565);
        }
        fsDepartment.setUpdateTime(DateUtils.getNowDate());
        return fsDepartmentMapper.updateFsDepartment(fsDepartment);
    }

    /**
     * 批量删除科室
     *
     * @param deptIds 需要删除的科室主键
     * @return 结果
     */
    @Override
    public int deleteFsDepartmentByDeptIds(Long[] deptIds)
    {
        return fsDepartmentMapper.deleteFsDepartmentByDeptIds(deptIds);
    }

    /**
     * 删除科室信息
     *
     * @param deptId 科室主键
     * @return 结果
     */
    @Override
    public int deleteFsDepartmentByDeptId(Long deptId)
    {
        return fsDepartmentMapper.deleteFsDepartmentByDeptId(deptId);
    }

    @Override
    public List<OptionsVO> selectFsDiseaseOptionsVO() {
        return fsDepartmentMapper.selectFsDiseaseOptionsVO();
    }
}
