package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.entity.InquiryDetail;
import com.diagbot.service.impl.InquiryDetailServiceImpl;
import com.diagbot.util.ListUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author rengb
 * @Description
 * @time 2018年11月23日下午2:08:08
 */
@Component
public class InquiryDetailFacade extends InquiryDetailServiceImpl {

    /**
     * 批量保存问诊明细
     *
     * @param inquiryDetailList
     */
    public void saveInquiryDetails(List<InquiryDetail> inquiryDetailList) {
        if (ListUtil.isNotEmpty(inquiryDetailList)) {
            baseMapper.saveInquiryDetails(inquiryDetailList);
        }
    }

    /**
     * 根据问诊记录id删除问诊记录明细
     *
     * @param inquiryId
     */
    public void removeByInquiryId(Long inquiryId) {
        QueryWrapper<InquiryDetail> queryWrapper = new QueryWrapper<InquiryDetail>();
        queryWrapper.eq("inquiry_id", inquiryId);
        this.remove(queryWrapper);
    }

    /**
     * 根据病历id获取病历明细
     *
     * @param inquiryId
     * @return
     */
    public List<InquiryDetail> getListByInquryId(Long inquiryId) {
        QueryWrapper<InquiryDetail> queryWrapper = new QueryWrapper<InquiryDetail>();
        queryWrapper.eq("is_deleted", "N");
        queryWrapper.eq("inquiry_id", inquiryId);
        return this.list(queryWrapper);
    }

    /**
     * 根据病历id集合获取病历明细
     *
     * @param inquiryIds
     * @return
     */
    public Map<Long, List<InquiryDetail>> getDetailsByInquryIds(List<Long> inquiryIds) {
        QueryWrapper<InquiryDetail> queryWrapper = new QueryWrapper<InquiryDetail>();
        queryWrapper.eq("is_deleted", "N").in("inquiry_id", inquiryIds);
        List<InquiryDetail> inquiryDetails = this.list(queryWrapper);
        return inquiryDetails.stream().collect(Collectors.groupingBy(InquiryDetail::getInquiryId));
    }


}
