package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.DeptInfoDTO;
import com.diagbot.entity.DeptInfo;
import com.diagbot.entity.HospitalDept;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.DeptInfoServiceImpl;
import com.diagbot.util.BeanUtil;
import com.diagbot.vo.DeptInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author: wangyu
 * @time: 2018/11/19 19:21
 */
@Component
public class DeptInfoFacade extends DeptInfoServiceImpl {

    @Autowired
    HospitalDeptFacade hospitalDeptFacade;
    /**
     * 获取科室信息
     *
     * @param deptInfoVO
     * @return
     */
    public DeptInfoDTO getDeptInfo(DeptInfoVO deptInfoVO) {
        QueryWrapper<HospitalDept> hospitalDeptQueryWrapper = new QueryWrapper<>();
        hospitalDeptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("hospital_code",deptInfoVO.getHospitalCode())
                .eq("code",deptInfoVO.getDeptCode());
        HospitalDept hospitalDept = hospitalDeptFacade.getOne(hospitalDeptQueryWrapper);
        QueryWrapper<DeptInfo> deptInfoDTOQueryWrapper = new QueryWrapper<>();
        deptInfoDTOQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("id",hospitalDept.getDeptId());
        DeptInfo deptInfo = this.getOne(deptInfoDTOQueryWrapper);
        DeptInfoDTO deptInfoDTO = new DeptInfoDTO();
        BeanUtil.copyProperties(deptInfo,deptInfoDTO);
        return deptInfoDTO;
    }
}
