package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.QuestionUsualDTO;
import com.diagbot.entity.DeptInfo;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.QuestionUsualServiceImpl;
import com.diagbot.util.ListUtil;
import com.diagbot.vo.QuestionUsualVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @author: wangyu
 * @time: 2018/11/22 16:16
 */
@Component
public class QuestionUsualFacade extends QuestionUsualServiceImpl {
    @Autowired
    DeptInfoFacade deptInfoFacade;

    /**
     * 获取常用标签
     *
     * @param questionUsualVO
     * @return
     */
    public List<QuestionUsualDTO> getQuestionUsual(QuestionUsualVO questionUsualVO) {
        List<QuestionUsualDTO> questionUsualDTOList = this.getQuestionUsualName(questionUsualVO);
        if(ListUtil.isEmpty(questionUsualDTOList)){
            QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("name","全科");
            DeptInfo deptInfo = deptInfoFacade.getOne(queryWrapper);
            questionUsualVO.setDeptId(deptInfo.getId());
            questionUsualDTOList = this.getQuestionUsualName(questionUsualVO);
        }
        return questionUsualDTOList;
    }
}
