package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.entity.QuestionDetail;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.QuestionDetailServiceImpl;
import com.diagbot.util.EntityUtil;
import com.diagbot.util.ListUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 标签业务层
 * @author: zhoutg
 * @time: 2018/8/6 9:11
 */
@Component
public class QuestionDetailFacade extends QuestionDetailServiceImpl {


    /**
     * 根据id获取标签明细
     *
     * @param questionId 标签id
     * @return 标签内容
     */
    public List<QuestionDetail> getByQuestionId(Long questionId) {
        List<QuestionDetail> questionDetailList = new ArrayList<>();
        if (questionId == null) {
            return questionDetailList;
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        queryWrapper.eq("question_id", questionId);
        queryWrapper.orderByAsc("order_no");
        questionDetailList = this.list(queryWrapper);
        return questionDetailList;
    }

    /**
     * 根据id获取标签明细
     *
     * @param questionIds 标签ids
     * @return 标签内容
     */
    public Map<Long, List<QuestionDetail>> getByQuestionIds(List<Long> questionIds) {
        Map<Long, List<QuestionDetail>> map = new LinkedHashMap<>();
        if (ListUtil.isEmpty(questionIds)) {
            return map;
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        queryWrapper.in("question_id", questionIds);
        queryWrapper.orderByAsc("question_id", "order_no");
        List<QuestionDetail> questionDetailList = this.list(queryWrapper);
        if (ListUtil.isNotEmpty(questionDetailList)) {
            map = EntityUtil.makeEntityListMap(questionDetailList, "questionId");
        }
        return map;
    }
}
