package com.ssj.dao.kmt.kmt.dao.impl;

import com.ssj.dao.kmt.kmt.dao.KmtKnowledgeQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.service.kmt.dto.KnowHowDetailsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @author yrf
 * @date 2019/1/21 11:22
 */
@Repository
public class KmtKnowledgeQueryDaoImpl implements KmtKnowledgeQueryDao {

    @Autowired
    private PagingHibernateJdbcDao pagingHibernateJdbcDao;

    @Override
    public List<KnowHowDetailsDTO> findByQuestionId(String questionId) {
        String sql = "select zyb_know_how_details.id, zyb_know_how_details.name\n" +
                "from zyb_know_how_details,\n" +
                "     kmt_exercise_question_know,\n" +
                "     kmt_exercise_questions\n" +
                "where zyb_know_how_details.id = kmt_exercise_question_know.how_details_id\n" +
                "  and kmt_exercise_question_know.question_id = kmt_exercise_questions.id\n" +
                "  and kmt_exercise_questions.id = ? ";

        return pagingHibernateJdbcDao.findList(sql, Collections.singleton(questionId).toArray(), KnowHowDetailsDTO.class);
    }
}
