package com.diagbot.facade;

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

import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.HospitalDeptInfoDTO;
import com.diagbot.entity.HospitalDept;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.HospitalDeptServiceImpl;
import com.diagbot.util.BeanUtil;
import com.diagbot.vo.HospitalDeptInfoVO;

/**
 * @author rgb
 * @Description
 * @time 2018年12月11日上午11:32:13
 */
@Component
public class HospitalDeptFacade extends HospitalDeptServiceImpl {

    /**
     * 获取科室信息
     *
     * @param hospitalDeptInfoVO
     * @return
     */
    public HospitalDeptInfoDTO getHospitalDeptInfo(HospitalDeptInfoVO hospitalDeptInfoVO) {
        HospitalDeptInfoDTO hospitalDeptInfoDTO = new HospitalDeptInfoDTO();
        QueryWrapper<HospitalDept> hospitalDeptQueryWrapper = new QueryWrapper<>();
        hospitalDeptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("hospital_code",hospitalDeptInfoVO.getHospitalCode())
                .eq("code",hospitalDeptInfoVO.getDeptCode());
        HospitalDept hospitalDept = this.getOne(hospitalDeptQueryWrapper);
        BeanUtil.copyProperties(hospitalDept,hospitalDeptInfoDTO);
        return hospitalDeptInfoDTO;
    }
    
    /**
     * 根据ids获取科室信息map
     * @param ids 科室ids
     * @return 科室信息
     */
    public Map<Long, HospitalDept> hospitalDeptInfoMapByIds(List<Long> ids) {
    	Map<Long, HospitalDept> hospitalDeptMap = this.listByIds(ids).stream().filter(i -> i.getIsDeleted().equals("N") && i.getStatus() == 1).collect(Collectors.toMap(HospitalDept::getId, i -> i));
        return hospitalDeptMap;
    }
    
}
