package com.fs.his.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.fs.his.domain.FsDoctorPrescribeDrug;
import com.fs.his.domain.FsPrescribeDrug;
import com.fs.his.mapper.FsDoctorPrescribeDrugMapper;
import com.fs.his.mapper.FsPrescribeDrugMapper;
import com.fs.his.param.FsDoctorPrescribeListDParam;
import com.fs.his.param.FsDoctorPrescribeVO;
import com.fs.his.vo.FsDoctorPrescribeListDVO;
import com.fs.his.vo.FsPrescribeListDVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.his.mapper.FsDoctorPrescribeMapper;
import com.fs.his.domain.FsDoctorPrescribe;
import com.fs.his.service.IFsDoctorPrescribeService;

/**
 * 医生处方Service业务层处理
 *
 * @author fs
 * @date 2023-08-08
 */
@Service
public class FsDoctorPrescribeServiceImpl implements IFsDoctorPrescribeService
{
    @Autowired
    private FsDoctorPrescribeMapper fsDoctorPrescribeMapper;
    @Autowired
    private FsDoctorPrescribeDrugMapper fsDoctorPrescribeDrugMapper;

    /**
     * 查询医生处方
     *
     * @param prescribeId 医生处方主键
     * @return 医生处方
     */
    @Override
    public FsDoctorPrescribe selectFsDoctorPrescribeByPrescribeId(Long prescribeId)
    {
        return fsDoctorPrescribeMapper.selectFsDoctorPrescribeByPrescribeId(prescribeId);
    }

    /**
     * 查询医生处方列表
     *
     * @param fsDoctorPrescribe 医生处方
     * @return 医生处方
     */
    @Override
    public List<FsDoctorPrescribe> selectFsDoctorPrescribeList(FsDoctorPrescribe fsDoctorPrescribe)
    {
        return fsDoctorPrescribeMapper.selectFsDoctorPrescribeList(fsDoctorPrescribe);
    }

    /**
     * 新增医生处方
     *
     * @param fsDoctorPrescribe 医生处方
     * @return 结果
     */
    @Override
    public int insertFsDoctorPrescribe(FsDoctorPrescribe fsDoctorPrescribe)
    {
        fsDoctorPrescribe.setCreateTime(DateUtils.getNowDate());
        return fsDoctorPrescribeMapper.insertFsDoctorPrescribe(fsDoctorPrescribe);
    }

    /**
     * 修改医生处方
     *
     * @param fsDoctorPrescribe 医生处方
     * @return 结果
     */
    @Override
    public int updateFsDoctorPrescribe(FsDoctorPrescribe fsDoctorPrescribe)
    {
        return fsDoctorPrescribeMapper.updateFsDoctorPrescribe(fsDoctorPrescribe);
    }

    /**
     * 批量删除医生处方
     *
     * @param prescribeIds 需要删除的医生处方主键
     * @return 结果
     */
    @Override
    public int deleteFsDoctorPrescribeByPrescribeIds(Long[] prescribeIds)
    {
        return fsDoctorPrescribeMapper.deleteFsDoctorPrescribeByPrescribeIds(prescribeIds);
    }

    /**
     * 删除医生处方信息
     *
     * @param prescribeId 医生处方主键
     * @return 结果
     */
    @Override
    public int deleteFsDoctorPrescribeByPrescribeId(Long prescribeId)
    {
        return fsDoctorPrescribeMapper.deleteFsDoctorPrescribeByPrescribeId(prescribeId);
    }

    @Override
    public List<FsDoctorPrescribeListDVO> selectFsDoctorPrescribeListDVO(FsDoctorPrescribeListDParam param) {
        List<FsDoctorPrescribeListDVO> list=fsDoctorPrescribeMapper.selectFsDoctorPrescribeListDVO(param);
        for(FsDoctorPrescribeListDVO vo:list) {
            FsDoctorPrescribeDrug map = new FsDoctorPrescribeDrug();
            map.setPrescribeId(vo.getPrescribeId());
            vo.setDrugs(fsDoctorPrescribeDrugMapper.selectFsDoctorPrescribeDrugList(map));
        }
        return list;
    }


    @Override
    public List<FsDoctorPrescribeVO> selectFsDoctorPrescribeListVO(FsDoctorPrescribe fsDoctorPrescribe) {
        return fsDoctorPrescribeMapper.selectFsDoctorPrescribeListVO(fsDoctorPrescribe);
    }
}
