package com.fs.his.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fs.common.exception.CustomException;
import com.fs.his.param.FsPackageCateUParam;
import com.fs.his.vo.OptionsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.his.mapper.FsPackageCateMapper;
import com.fs.his.domain.FsPackageCate;
import com.fs.his.service.IFsPackageCateService;

/**
 * 套餐包分类Service业务层处理
 *
 * @author fs
 * @date 2024-05-08
 */
@Service
public class FsPackageCateServiceImpl implements IFsPackageCateService
{
    @Autowired
    private FsPackageCateMapper fsPackageCateMapper;

    /**
     * 查询套餐包分类
     *
     * @param cateId 套餐包分类主键
     * @return 套餐包分类
     */
    @Override
    public FsPackageCate selectFsPackageCateByCateId(Long cateId)
    {
        return fsPackageCateMapper.selectFsPackageCateByCateId(cateId);
    }

    /**
     * 查询套餐包分类列表
     *
     * @param fsPackageCate 套餐包分类
     * @return 套餐包分类
     */
    @Override
    public List<FsPackageCate> selectFsPackageCateList(FsPackageCateUParam param)
    {
        return fsPackageCateMapper.selectFsPackageCateList(param);
    }

    /**
     * 新增套餐包分类
     *
     * @param fsPackageCate 套餐包分类
     * @return 结果
     */
    @Override
    public int insertFsPackageCate(FsPackageCate fsPackageCate)
    {
        Long cateCode = fsPackageCate.getCateCode();
        Integer type = fsPackageCate.getType();
        FsPackageCate cate = fsPackageCateMapper.selectFsPackageCateByCateCode(cateCode, type);
        if (cate!=null){
            throw new CustomException("分类标识存在重复");
        }
        return fsPackageCateMapper.insertFsPackageCate(fsPackageCate);
    }

    /**
     * 修改套餐包分类
     *
     * @param fsPackageCate 套餐包分类
     * @return 结果
     */
    @Override
    public int updateFsPackageCate(FsPackageCate fsPackageCate)
    {
        Long cateCode = fsPackageCate.getCateCode();
        Integer type = fsPackageCate.getType();
        FsPackageCate cate = fsPackageCateMapper.selectFsPackageCateByCateCode(cateCode, type);
        if (cate!=null&&cate.getCateId()!=fsPackageCate.getCateId()){
            throw new CustomException("分类标识存在重复");
        }
        return fsPackageCateMapper.updateFsPackageCate(fsPackageCate);
    }

    /**
     * 批量删除套餐包分类
     *
     * @param cateIds 需要删除的套餐包分类主键
     * @return 结果
     */
    @Override
    public int deleteFsPackageCateByCateIds(Long[] cateIds)
    {
        return fsPackageCateMapper.deleteFsPackageCateByCateIds(cateIds);
    }

    /**
     * 删除套餐包分类信息
     *
     * @param cateId 套餐包分类主键
     * @return 结果
     */
    @Override
    public int deleteFsPackageCateByCateId(Long cateId)
    {
        return fsPackageCateMapper.deleteFsPackageCateByCateId(cateId);
    }

    @Override
    public Map selectFsArticleCateAllList() {
        List<OptionsVO> t1 = fsPackageCateMapper.selectFsArticleCateByType(1);
        List<OptionsVO> t2 = fsPackageCateMapper.selectFsArticleCateByType(2);
        HashMap<String, Object> map = new HashMap<>();
        map.put("diseaseType",t1);
        map.put("privateType",t2);
        return map;
    }
}
