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


import com.ssj.bean.kmt.kmt.domain.KmtQuestion;
import com.ssj.bean.kmt.kmt.dto.CourseHandoutTemplate;
import com.ssj.bean.kmt.kmt.dto.LessonGroupDTO;
import com.ssj.bean.kmt.kmtsys.domain.KmtSysUser;
import com.ssj.dao.kmt.kmt.dao.KmtQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.framework.core.util.StringUtil;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.service.kmt.dto.KmtSysUserDTO;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.*;


@Repository
public class KmtQueryDaoImpl implements KmtQueryDao{
	
	@Autowired
	private PagingHibernateJdbcDao dao;
	
	
	//查询学员信息列表，返回包含：已上的课数，还有多少天数，和学习计划， 总的学习计划
	@Override
	public List<Map<String, Object>> findStudentByList(String teacherId,String name,String grade) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
//        selSQL.append("  SELECT * from (  SELECT t.*,if(t.user_id IS NULL || t.user_id ='' ,'30', if(DATEDIFF(s.end_time,now())<0  or s.end_time is NULL  ,0 , DATEDIFF(s.end_time,now()))) AS day ,s.end_time, ");
//        selSQL.append(" (SELECT COUNT(1) from kmt_course c where c.state=1 and c.student_id=t.id AND c.teacher_id=? AND CONCAT(c.course_time,' ',c.end_time)<NOW() ) as count, ");
//        selSQL.append(" IF(m.type is NOT null, ");
//        selSQL.append(" IF(m.type=1,  ");
//        selSQL.append(" (SELECT COUNT(DISTINCT(DATE_FORMAT(tt.course_time,'%j'))) FROM `kmt_course` tt where tt.state=1 and tt.student_id=t.id AND tt.course_time <=NOW() ),  ");
//        selSQL.append(" (SELECT COUNT(DISTINCT(DATE_FORMAT(tt.course_time,'%u'))) FROM `kmt_course` tt where tt.state=1 and tt.student_id=t.id AND tt.course_time <=NOW() )  ");
//        selSQL.append(" ),0)as speednum,  ");
//        selSQL.append(" (SELECT COUNT(1) FROM kmt_plan_detail tt where tt.plan_template_id=t.plan_template_id) as plancount  ");
//        selSQL.append(" from kmt_student t  ");
//        selSQL.append(" LEFT JOIN tb_lib_vip_service s ON t.vip_id=s.vip_id    ");
//        selSQL.append(" LEFT JOIN kmt_plan_template m ON t.plan_template_id=m.id  ");
//        selSQL.append(" where t.teacher_id=? AND ((t.user_id IS NOT NULL AND  t.user_id != ''  AND s.stat=1 AND s.species='S003' ) OR (t.user_id is NULL))  ");
//        queryParams.add(teacherId);
//        queryParams.add(teacherId);
//        if(StringUtils.isNotEmpty(name)){
//        	selSQL.append("  and t.`name` LIKE CONCAT(CONCAT('%',?,'%'))  ");
//        	queryParams.add(name);
//        }
//        if(StringUtils.isNotEmpty(grade)){
//      	    selSQL.append(" AND t.grade =? ");
//      	    queryParams.add(grade);
//        }
//        selSQL.append("  ORDER BY t.create_time desc  ) as tmp GROUP BY tmp.id ");
        
        
        
        
        
        selSQL.append("  SELECT * from (");
        selSQL.append(" SELECT t.*,if(s.species ='S010' ,s.course_count, if(DATEDIFF(s.end_time,now())<0  or s.end_time is NULL  ,0 , DATEDIFF(s.end_time,now()))) AS day , ");
        selSQL.append(" s.end_time,  ");
        selSQL.append(" (SELECT COUNT(1) from kmt_course c where c.state=1 and c.vip_id=t.id AND c.teacher_id=?  AND CONCAT(c.course_time,' ',c.end_time)<NOW()) as count, ");
        selSQL.append(" IF(m.type is NOT null,   ");
        selSQL.append(" IF(m.type=1,   ");
        selSQL.append(" (SELECT COUNT(DISTINCT(DATE_FORMAT(tt.course_time,'%j'))) FROM `kmt_course` tt where tt.state=1 and tt.vip_id=t.id AND tt.course_time <=NOW() ),   ");
        selSQL.append(" (SELECT COUNT(DISTINCT(DATE_FORMAT(tt.course_time,'%u'))) FROM `kmt_course` tt where tt.state=1 and tt.vip_id=t.id AND tt.course_time <=NOW())    ");
        selSQL.append(" ),0)as speednum,  ");
        selSQL.append(" (SELECT COUNT(1) FROM kmt_plan_detail tt where tt.plan_template_id=t.plan_template_id) as plancount      ");
        selSQL.append("  from (SELECT t.* FROM tb_lib_vip t LEFT JOIN kmt_course c ON t.id=c.vip_id  WHERE c.teacher_id=? GROUP BY t.id) as t   ");
        selSQL.append(" LEFT JOIN tb_lib_vip_service s ON t.id=s.vip_id    ");
        selSQL.append("  LEFT JOIN kmt_plan_template m ON t.plan_template_id=m.id    ");
        selSQL.append("   where s.stat=1 AND (s.species='S003' or s.species='S010')    ");
        queryParams.add(teacherId);
        queryParams.add(teacherId);
        if(StringUtils.isNotEmpty(name)){
        	selSQL.append("  and t.`name` LIKE CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(name);
        }
        if(StringUtils.isNotEmpty(grade)){
      	    selSQL.append(" AND t.grade =? ");
      	    queryParams.add(grade);
        }
        selSQL.append("  ORDER BY t.create_time desc  ) as tmp GROUP BY tmp.id ");
        
        
        
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findSimpleStudentByList(String teacherId, String name, String grade) {
		StringBuilder sb = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();

		sb.append("select distinct vip.id, vip.grade, vip.child_name, vip.create_time, vip.birthday, vip.tags_character, ")
				.append(" vip.tags_habit from tb_lib_vip vip left join kmt_course kc on vip.id=kc.vip_id")
				.append(" where kc.teacher_id= ? and vip.user_id is not null");
		queryParams.add(teacherId);
		if(StringUtils.isNotEmpty(name)){
			sb.append("  and vip.child_name regexp ?");
			queryParams.add(name);
		}
		if(StringUtils.isNotEmpty(grade)){
			sb.append(" AND vip.grade =? ");
			queryParams.add(grade);
		}

		return dao.findMap(sb.toString(), queryParams.toArray());
	}

	//查询学员信息列表，条件：name ,作业吧，服务有效,还没添加到任何一个老师名下。
	@Override
	public List<Map<String, Object>> findLibVipByList(String name) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.* from tb_lib_vip t  ");
        selSQL.append(" LEFT JOIN tb_lib_vip_service s ON t.id=s.vip_id  	  ");
        selSQL.append(" where t.child_name LIKE CONCAT(CONCAT('%',?,'%'))  AND s.species='S003' AND s.end_time>=NOW() AND t.stat=1 GROUP BY t.id ");
        
        queryParams.add(name);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	//查询知识点，条件：科目，年级，上下学期，教版，知识点名称同步
	@Override
	public  List<Map<String, Object>> findHowByCourseNameByName(String libId,String courseName,String grade,
			String semester ,String type,String name){
	 	StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  d.id,d.how_id , d.before_name,d.after_name,d.type,d.is_hot, d.module , d.img, d.jxmb,d.zdbx,d.ydsl, d.num , ");
        selSQL.append(" d.memorize,d.understanding,d.apply,d.duration,d.two_module ,s.alias as name  ");
        selSQL.append(" ,st.alias as howname,st.course_name,d.how_id as howid,s.num as sortnnm ,d.is_zt as zt    ");
        selSQL.append(" from zyb_know_how_details d      ");
        selSQL.append(" JOIN zyb_know_how_details_sort s ON s.how_details_id = d.id  AND s.stat = 2   ");
        selSQL.append("   JOIN zyb_know_how_details_sort st ON st.how_id = d.how_id   AND st.stat = 1    ");
        selSQL.append(" where  s.lib_id =? and s.course_name=?       ");
        queryParams.add(libId);
        queryParams.add(courseName);
        
        if(StringUtils.isNotEmpty(type)){
        	selSQL.append(" and s.type=? ");
        	selSQL.append(" and st.type=? ");
        	 queryParams.add(type);
        	 queryParams.add(type);
        }
        if(StringUtils.isNotEmpty(grade)){
        	selSQL.append(" AND s.grade=? ");
        	selSQL.append(" AND st.grade=? ");
        	queryParams.add(grade);
        	queryParams.add(grade);
        }
        if(StringUtils.isNotEmpty(semester)){
        	selSQL.append(" AND s.semester=? ");
        	selSQL.append(" AND st.semester=? ");
        	queryParams.add(semester);
        	queryParams.add(semester);
        }
        if(StringUtils.isNotEmpty(name)){
        	selSQL.append(" AND ( d.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))   or  st.alias  LIKE  CONCAT(CONCAT('%',?,'%'))   ) ");
        	queryParams.add(name);
        	queryParams.add(name);
        	queryParams.add(name);
        }
        selSQL.append(" AND d.is_zt=0  GROUP BY d.id   ORDER BY   st.num asc,st.create_time asc ,s.num asc,d.num asc  ");
        return dao.findMap(selSQL.toString(),queryParams.toArray()); 
	 }


	
	//查询知识点，条件：科目，年级，上下学期，教版，知识点名称，专题
	@Override
	public  List<Map<String, Object>> findHowByCourseNameByHowName(String libId,String courseName,String grade,String semester ,String type,String name){
	 	StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  d.id,d.how_id , d.before_name,d.after_name,d.type,d.is_hot, d.module , d.img, d.jxmb,d.zdbx,d.ydsl, d.num , ");
        selSQL.append(" d.memorize,d.understanding,d.apply,d.duration,d.two_module ,s.alias as name  ");
        selSQL.append(" ,st.alias as howname,st.course_name,d.how_id as howid,s.num as sortnnm ,d.is_zt as zt    ");
        selSQL.append(" from zyb_know_how_details d      ");
        selSQL.append(" JOIN zyb_know_how_details_sort s ON s.how_details_id = d.id  AND s.stat = 2   ");
        selSQL.append("   JOIN zyb_know_how_details_sort st ON st.how_id = d.how_id   AND st.stat = 1    ");
        selSQL.append(" where  s.lib_id =? and s.course_name=?       ");
        queryParams.add(libId);
        queryParams.add(courseName);
        
        if(StringUtils.isNotEmpty(type)){
        	selSQL.append(" and s.type=? ");
        	selSQL.append(" and st.type=? ");
        	 queryParams.add(type);
        	 queryParams.add(type);
        }
        if(StringUtils.isNotEmpty(grade)){
        	selSQL.append(" AND s.grade=? ");
        	selSQL.append(" AND st.grade=? ");
        	queryParams.add(grade);
        	queryParams.add(grade);
        }
        if(StringUtils.isNotEmpty(semester)){
        	selSQL.append(" AND s.semester=? ");
        	selSQL.append(" AND st.semester=? ");
        	queryParams.add(semester);
        	queryParams.add(semester);
        }
        if(StringUtils.isNotEmpty(name)){
        	selSQL.append(" AND ( d.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))    or  st.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) ");
        	queryParams.add(name);
        	queryParams.add(name);
        	queryParams.add(name);
        }
        selSQL.append(" AND d.is_zt=1   GROUP BY d.id   ORDER BY  st.num asc,st.create_time asc ,s.num asc, d.num asc ");
        return dao.findMap(selSQL.toString(),queryParams.toArray()); 
	 }
	
	
	

	//查询知识点下的题目，条件:知识点id,选项类型，题目类型，易的条数，中等的条数，难的条数    用union all返回多个集合。
	@Override
	public List<Map<String, Object>> findQuestionByList(String[] howId,
			String optionType, Integer type,Integer easyily,Integer medium,Integer hard,List<String> notQuIds) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=1 and t.state=1  and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(easyily!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(easyily);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        selSQL.append(" UNION ALL ");
        
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=2 and t.state=1 and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(medium!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(medium);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        
        selSQL.append(" UNION ALL ");
        
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=3 and t.state=1 and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(hard!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(hard);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	//查询学员计划进度, 根据学员的计划周期类型
	@Override
	public List<Map<String, Object>> findPlanSpeedByList(String studentId,String type) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM `kmt_course` t where t.state=1 and t.vip_id=? AND t.course_time <=NOW() ");
        if("DAY".equals(type)){
        	selSQL.append("  GROUP BY DATE_FORMAT(t.course_time,'%j')  ");
        }else if("WEEK".equals(type)){
        	selSQL.append("  GROUP BY DATE_FORMAT(t.course_time,'%u') ");
        } 
        queryParams.add(studentId);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	
	//生成知识点下的条件随机题目
	@Override
	public List<Map<String, Object>> findQuestionEasyByList(String[] howId,String[] kbId,String optionType, Integer type, Integer easy, Integer size,List<String> notQuIds) {
		
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE 1=1 and t.state=1 and  t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(kbId!=null && kbId.length>0){
        	selSQL.append(" and k.how_details_kd_id in ( ");
        	selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        	selSQL.append(")");
        }
        
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
        if(easy!=null){
        	selSQL.append(" AND t.easy=? ");
        	queryParams.add(easy);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(size!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(size);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	//查询老师的备课数据
	@Override
	public List<Map<String, Object>> findCourseByList(String teacherId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,s.child_name as `name`,s.grade,s.id as sid,ls.course_name from kmt_course t left join tb_lesson_service ls on t.lesson_service_id=ls.id LEFT JOIN tb_lib_vip s ON t.vip_id=s.id where t.state=1 and t.teacher_id=? ORDER BY t.course_time ASC ");
        queryParams.add(teacherId);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	//查询备课id的数据对应的知识点明细
	@Override
	public List<Map<String, Object>> findCourseKnowDetailByList(String courseKnowId,Integer type) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,h.`name` as hname,d.two_module,d.is_hot,d.jxmb,d.zdbx FROM `kmt_course_know_detail` t LEFT JOIN zyb_know_how_details d ON t.know_id = d.id  LEFT JOIN zyb_know_how h ON d.how_id=h.id where t.course_know_id=? and t.type=? ORDER BY t.num asc ");
        queryParams.add(courseKnowId);
        queryParams.add(type);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	
	//查询备课id的数据对应的全部题目明细
	@Override
	public List<Map<String, Object>> findCourseQuestionDetailByList(String courseKnowId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.mark,t.course_know_id,t.kname,t.is_answer,t.know_id,t.question_id,t.type as qdtype,t.num as qdnum,q.* ,kd.`name` as kdname ,kd.id as kdid,t.ydsl as kydsl from kmt_course_question_detail t LEFT JOIN kmt_question q ON t.question_id=q.id  LEFT JOIN zyb_know_how_details_kd kd ON t.how_details_kd_id=kd.id where t.course_know_id=? ORDER BY t.num asc");
        queryParams.add(courseKnowId);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	
	//查询错题列表
	@Override
	public List<Map<String, Object>> findWrongQuestionByCourseKnowId(String courseKnowId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.* ,t.how_details_id from kmt_img_face_detail t  ");
        selSQL.append(" LEFT JOIN kmt_img_face f ON t.face_id=f.id   ");
        selSQL.append(" left JOIN kmt_question q ON t.question_id=q.id ");
        selSQL.append(" where  q.id is not NULL AND f.course_know_id=? GROUP BY q.id ");
        queryParams.add(courseKnowId);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	

	@Override
	public List<Map<String, Object>> findKnowDetailByIdList(String[] howId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        List<Map<String, Object>> list=null;
        if(howId!=null && howId.length>0){
	        selSQL.append(" SELECT t.*,h.name as hname from zyb_know_how_details t  LEFT JOIN zyb_know_how h ON t.how_id=h.id where t.id in (  ");
	        selSQL.append("'"+StringUtils.join(howId, "','")+"'");
	        selSQL.append(")");
	        selSQL.append(" ORDER BY FIELD(t.id ,");
	        selSQL.append("'"+StringUtils.join(howId, "','")+"' )");
	        
	        list=dao.findMap(selSQL.toString(),queryParams.toArray());
        }
        return list;
	}

	@Override
	public List<Map<String, Object>> findImgByQuList(String faceId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.* from kmt_img_face_detail t LEFT JOIN kmt_question q ON t.question_id=q.id where t.face_id=? ");
        queryParams.add(faceId);
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	
	@Override
	public List<Map<String, Object>> findExamineByQuList(String grade,String courseName,
			String type,Integer page,Integer pageSize,Integer state,String username,String howId,String kdId,String quids,String source) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();

        selSQL.append(" SELECT  t.*,group_concat(DISTINCT(q.how_details_kd_id)) as  how_details_kd_id,group_concat(DISTINCT(q.how_details_id)) as how_details_id,q.num as qnum  ,group_concat(DISTINCT(IF(d.two_module ='积累' OR d.two_module ='词语拓展' ,d.two_module , s.alias)) SEPARATOR '<br/>知识点：') as `name`,group_concat(DISTINCT(ks.alias) SEPARATOR '<br/>考点：')as kname   from kmt_question_know q  ");
        selSQL.append(" LEFT JOIN kmt_question t ON t.id=q.question_id  ");
        selSQL.append(" LEFT JOIN zyb_know_how_details_sort ks ON q.how_details_kd_id = ks.how_details_kd_id and ks.stat = 3 ");
        selSQL.append(" LEFT JOIN zyb_know_how_details d ON d.id=q.how_details_id ");
        selSQL.append(" LEFT JOIN zyb_know_how_details_sort s ON q.how_details_id=s.how_details_id and s.stat=2 ");
        selSQL.append(" where t.state=?  ");
        queryParams.add(state);
        
        if(StringUtils.isNotEmpty(quids)){
        	 String[] quidList=quids.split(",");
        	 String[] quidListTmp=new String[quidList.length];
        	 for (int i = 0; i < quidList.length; i++) {
        		 quidListTmp[i]=quidList[i].trim();
			 }
        	 selSQL.append("  AND t.id in ( ");
        	 selSQL.append("'").append(StringUtils.join(quidListTmp, "','")).append("'");
        	 selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(username)){
         	 selSQL.append("  AND t.adduser=? ");
         	 queryParams.add(username);
        }
        if(StringUtils.isNotEmpty(source)){
       	 	selSQL.append("  AND t.source LIKE  CONCAT(CONCAT('%',?,'')) ");
       	 	queryParams.add(source);
        }
        if(StringUtils.isNotEmpty(howId)){
          	 selSQL.append("  AND q.how_details_id=? ");
          	 queryParams.add(howId);
        }        		
        
        if(StringUtils.isNotEmpty(kdId)){
       	 selSQL.append("  AND q.how_details_kd_id=?  ");
       	 queryParams.add(kdId);
       	 
         if(StringUtils.isNotEmpty(type)){
        	 selSQL.append("  AND ks.type=? ");
       	 	 queryParams.add(type);
         }
     	
        }
        if(StringUtils.isNotEmpty(courseName)){
        	 selSQL.append("  AND s.course_name=? ");
        	 queryParams.add(courseName);
        }
        if(StringUtils.isNotEmpty(grade)){
       	 	selSQL.append("  AND s.grade=? ");
       	 	queryParams.add(grade);
        }
        if(StringUtils.isNotEmpty(type)){
       	 	selSQL.append("  AND s.type=? ");
       	 	queryParams.add(type);
        }

        selSQL.append(" GROUP BY t.id   ORDER BY t.type asc,q.num DESC,t.update_time DESC ,t.create_time desc  ");
        if(page!=null){
        	selSQL.append("  LIMIT "+page+","+pageSize+" ");
        }else{
        	selSQL.append("  LIMIT 0,20 ");
        }
        
        
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}
	
	
	@Override
	public Map<String, Object> findExamineByQuId(String id, Integer type) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();

		selSQL.append(" SELECT t.* ,group_concat(DISTINCT(q.how_details_kd_id)) as  how_details_kd_id,group_concat(DISTINCT(q.how_details_id)) as how_details_id,group_concat(DISTINCT(IF(d.two_module ='积累' OR d.two_module ='词语拓展' ,d.two_module , ds.alias)) SEPARATOR '<br/>知识点：') as `name`,group_concat(DISTINCT(ks.alias) SEPARATOR '<br/>考点：')as kname   from kmt_question_know q  ");
		selSQL.append(" LEFT JOIN kmt_question t ON t.id=q.question_id  ");
		selSQL.append(" left join zyb_know_how_details_sort ks on q.how_details_kd_id = ks.how_details_kd_id and ks.stat = 3 ");
        if (type != null) {
            selSQL.append(" and ks.type = ? ");
            queryParams.add(type);
        }
		selSQL.append(" LEFT JOIN zyb_know_how_details d ON d.id=q.how_details_id ");
        selSQL.append(" left join zyb_know_how_details_sort ds on d.id = ds.how_details_id and ds.stat = 2 ");
        if (type != null) {
            selSQL.append(" and ds.type = ? ");
            queryParams.add(type);
        }
        selSQL.append(" where t.id=?  ");
        queryParams.add(id);
        selSQL.append(" GROUP BY t.id  ");
        List<Map<String,Object>> list=dao.findMap(selSQL.toString(),queryParams.toArray());
        return list!=null && list.size()>0 ?list.get(0):new HashMap<String, Object>();
	}
	
	
	
	

	@Override
	public Map<String, Object> loginImport(String loginName, String password) {
		Map<String, Object> map=null;
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from kmt_sys_user t where t.state AND t.login_name=? AND t.`password` =?  LIMIT 1 ");
        queryParams.add(loginName);
        queryParams.add(password);
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
        if(maplist!=null && maplist.size()>0){
        	map=maplist.get(0);
        }
        return map;
	}
	
	
	@Override
	public void insertLogin(String loginName, String password,String name,String auth,String type ) {
		KmtSysUser user=new KmtSysUser();
		user.setAuth(auth);
		user.setLoginName(loginName);
		user.setName(name);
		user.setPassword(password);
		user.setState(1);
		user.setCreateTime(new Date());
		user.setType(type);
	    dao.batchInsertObject(user);
	}

	@Override
	public List<Map<String, Object>> findUserByNameList(String name) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from tb_user t where t.wx_name LIKE CONCAT(CONCAT('%',?,'%')) ");
        queryParams.add(name);
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	//考点
	@Override
	public List<Map<String, Object>> findQuestionByList(String courseName,Integer page,Integer pageSize) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.* ,IF(d.two_module ='积累' OR d.two_module ='词语拓展' ,d.two_module , d.`name`) as `name`,q.how_id,q.how_details_id,q.how_details_kd_id   FROM `kmt_question` t  LEFT JOIN kmt_question_know q  ON t.id=q.question_id  LEFT JOIN zyb_know_how_details d ON d.id=q.how_details_id where t.state!=2 AND t.course_name=? and (q.how_details_kd_id is null OR  q.how_details_kd_id='')  ORDER BY t.update_time DESC ,t.create_time desc  LIMIT ?,? ");
        queryParams.add(courseName);
        queryParams.add(page);
        queryParams.add(pageSize);
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}

	@Override
	public List<Map<String, Object>> findKbByHowDetailsIdList(String howDetailsId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from zyb_know_how_details_kd t where t.how_details_id=? ORDER BY t.num asc ");
        queryParams.add(howDetailsId);
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}


	@Override
	public List<Map<String, Object>> findKBByList(String libId,String courseName, String grade, String semester, String type) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        
        selSQL.append("SELECT t.* ");
		selSQL.append("from  zyb_know_how_details_kd t \n");
		selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_kd_id = t.id  ");
		selSQL.append("  where  s.lib_id =? and s.course_name=?  and s.stat=3    ");
		 queryParams.add(libId);
		 queryParams.add(courseName);
	        
	      if(StringUtils.isNotEmpty(type)){
	        	selSQL.append(" and s.type=? ");
	        	 queryParams.add(type);
	      }
	      if(StringUtils.isNotEmpty(grade)){
	        	selSQL.append(" AND s.grade=? ");
	        	queryParams.add(grade);
	      }
	      if(StringUtils.isNotEmpty(semester)){
	        	selSQL.append(" AND s.semester=? ");
	        	queryParams.add(semester);
	      }
	      selSQL.append(" ORDER BY t.num asc ");
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	@Override
	public List<Map<String, Object>> previousLesson(String courseHowId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT IFNULL(d.how_id,'') as how_id,IFNULL( d.how_name,'') as  how_name , IFNULL(d.`name`,'') as `name` ,d.know_id  from   ");
		selSQL.append("  kmt_course_know_detail d    ");
		selSQL.append(" where  d.course_know_id =?   GROUP BY know_id   ");
		selSQL.append(" ORDER BY d.how_id ,d.know_id    ");
		queryParams.add(courseHowId);
		List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	@Override
	public List<Map<String, Object>> findKBByList(String[] howId, String grade, String semester, String type) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.id , t.how_details_id, so.alias as `name`, t.create_time,t.how_id, t.ydsl AS kydsl,t.img AS kimg, sr.alias AS hdname ");
        selSQL.append(" FROM zyb_know_how_details_kd t");
        selSQL.append(" LEFT join zyb_know_how_details_sort so on t.id = so.how_details_kd_id and so.stat =3 ");
        selSQL.append(" LEFT join zyb_know_how_details_sort sr on sr.how_details_id = so.how_details_id and sr.stat=2   ");
        
        selSQL.append(" where ");
        selSQL.append("  so.type=? ");
        selSQL.append(" AND so.grade=? ");
        selSQL.append(" AND so.semester=?  ");
        selSQL.append(" AND sr.type=? ");
        selSQL.append(" AND sr.grade=? ");
        selSQL.append(" AND sr.semester=?  ");
        queryParams.add(type);
        queryParams.add(grade);
        queryParams.add(semester);
        queryParams.add(type);
        queryParams.add(grade);
        queryParams.add(semester);
        selSQL.append(" and   so.how_details_id in (");
        selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        selSQL.append(" )  GROUP BY t.id ");
        selSQL.append("  ORDER BY FIELD(t.how_details_id ,");
        selSQL.append("'"+StringUtils.join(howId, "','")+"' ) ,so.num ASC ");
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	
	
	
	@Override
	public List<Map<String, Object>> findQuestionByRandList(String[] howId,String[] kbId,
			String optionType, 
			Integer type,Integer notType,Integer num,List<String> notQuIds) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from ( SELECT t.*,d.`name`,k.how_details_id,d.how_id,h.`name` as hname,kd.id as kdid,kd.`name` as kdname,kd.img as kimg,kd.ydsl as kydsl from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id   ");
        selSQL.append(" LEFT JOIN zyb_know_how_details d ON k.how_details_id=d.id  LEFT JOIN zyb_know_how h ON d.how_id=h.id  LEFT JOIN zyb_know_how_details_kd kd ON kd.id=k.how_details_kd_id ");
        selSQL.append(" where t.state=1 and t.type!=5 ");
        
        if(howId!=null && howId.length>0){
        	selSQL.append(" AND k.how_details_id in ( ");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }

        if(kbId!=null && kbId.length>0){
        	selSQL.append(" AND k.how_details_kd_id in ( ");
        	selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" AND  t.id not in ( ");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
        
        if(notType!=null){
        	selSQL.append("  AND t.type !=? ");
        	queryParams.add(notType);
        }
        
		selSQL.append(" ORDER BY  k.num desc,RAND() ");
		
		if(num!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(num);
		}
		selSQL.append(" ) as tmp  ORDER BY tmp.easy ASC  ");
		
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> findKBByKbIdList(String[] kbId,String hname) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.id,t.how_details_id,t.name,t.create_time,t.how_id,t.ydsl as kydsl ,t.img as kimg,d.jxmb,d.ydsl,d.zdbx,d.`name` as hname,d.is_hot FROM `zyb_know_how_details_kd` t LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id LEFT JOIN zyb_know_how h ON d.how_id=h.id WHERE 1=1 ");
        if(StringUtils.isNotEmpty(hname)){
        	 selSQL.append(" and h.`name`=?  ");
        	 queryParams.add(hname);
        }
        selSQL.append(" and t.id in (   ");
        selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        selSQL.append(" )  ");
        
        selSQL.append(" ORDER BY FIELD(t.id ,");
        selSQL.append("'"+StringUtils.join(kbId, "','")+"' )");       

        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	@Override
	public List<Map<String, Object>> findKBByModularNameList(String[] kbId,String modularName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT distinct t.id,t.how_details_id,t.name,t.create_time,t.how_id,t.ydsl as kydsl,t.img as kimg,d.jxmb,d.ydsl,d.zdbx,d.`name` as hname,d.is_hot FROM `zyb_know_how_details_kd` t LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id ")
				.append(" left join zyb_know_how_details_sort how on t.how_id=how.how_id and how.stat=1")
				.append(" LEFT join zyb_know_how_details_sort de on d.id = de.how_details_id and de.stat =2 ")
				.append(" LEFT join zyb_know_how_details_sort so on t.id = so.how_details_kd_id and so.stat =3 WHERE 1=1 ");
        if(StringUtils.isNotEmpty(modularName)){
        	 selSQL.append(" and d.module=?  ");
        	 queryParams.add(modularName);
        }
        selSQL.append(" and t.id in (   ");
        selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        selSQL.append(" )  ");
        selSQL.append(" order by how.num, de.num, so.num");
       
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	@Override
	public List<Map<String, Object>> findQuestionReview(Integer num,String studentId,String courseName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.* from kmt_course t LEFT JOIN kmt_course_know k ON t.course_know_id=k.id  ");
        selSQL.append(" where  t.vip_id=? AND t.course_know_id is NOT NULL AND k.course_name=?  AND str_to_date(CONCAT(t.course_time,' ',t.end_time),'%Y-%m-%d %H')<= now() ");
        selSQL.append(" ORDER BY CONCAT(t.course_time,' ',t.end_time) DESC ");
        queryParams.add(studentId);
        queryParams.add(courseName);
        selSQL.append("  LIMIT  "+num+",1 ");
        List<Map<String, Object>> maplist=dao.findMap(selSQL.toString(),queryParams.toArray());
		return maplist;
	}
	
	
	
	

	//查询知识点下的题目，条件:知识点id,选项类型，题目类型，易的条数，中等的条数，难的条数    用union all返回多个集合。
	@Override
	public List<Map<String, Object>> findQuestionByChineseList(String[] howId,String[] kbId,
			String optionType, Integer type,Integer easyily,Integer medium,Integer hard,List<String> notQuIds) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  SELECT * from (  SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=1 and t.state=1  and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(kbId!=null && kbId.length>0){
        	selSQL.append(" and k.how_details_kd_id in (");
        	selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(easyily!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(easyily);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        selSQL.append(" UNION ALL ");
        
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=2 and t.state=1 and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(kbId!=null && kbId.length>0){
        	selSQL.append(" and k.how_details_kd_id in (");
        	selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(medium!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(medium);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id  ");
        
        
        selSQL.append(" UNION ALL ");
        
        selSQL.append(" SELECT q.*,tmp.`name`,tmp.how_details_id,tmp.how_id from kmt_question q INNER JOIN (  ");
        selSQL.append(" SELECT t.*,d.`name`,k.how_details_id as how_details_id,k.how_id as how_id  from kmt_question t   ");
        selSQL.append(" LEFT JOIN kmt_question_know k ON t.id=k.question_id LEFT JOIN zyb_know_how_details d ON d.id=k.how_details_id  ");
        selSQL.append(" WHERE  t.easy=3 and t.state=1 and t.type!=5 ");
        if(howId!=null && howId.length>0){
        	selSQL.append(" and k.how_details_id in (");
        	selSQL.append("'"+StringUtils.join(howId, "','")+"'");
        	selSQL.append(")");
        }
        
        if(kbId!=null && kbId.length>0){
        	selSQL.append(" and k.how_details_kd_id in (");
        	selSQL.append("'"+StringUtils.join(kbId, "','")+"'");
        	selSQL.append(")");
        }
        
        
        if(notQuIds!=null && notQuIds.size()>0){
        	String[] notIds=new String[notQuIds.size()];
        	notIds=notQuIds.toArray(notIds);
        	selSQL.append(" and t.id not in (");
        	selSQL.append("'"+StringUtils.join(notIds, "','")+"'");
        	selSQL.append(")");
        }
        
        if(StringUtils.isNotEmpty(optionType)){
        	selSQL.append("  AND t.option_type in ( ");
        	String[] optionTypes=optionType.split(",");
        	selSQL.append("'"+StringUtils.join(optionTypes, "','")+"'");
        	selSQL.append(")");
        }
        if(type!=null){
        	selSQL.append("  AND t.type=? ");
        	queryParams.add(type);
        }
		selSQL.append(" ORDER BY RAND() ");
		if(hard!=null){
			selSQL.append(" LIMIT ?  ");
			queryParams.add(hard);
		}
        selSQL.append(" ) as tmp ON q.parent_id=tmp.id OR q.id=tmp.id   ) as ttmp ORDER BY ttmp.option_type ASC,ttmp.easy ASC  ");
        
        return dao.findMap(selSQL.toString(),queryParams.toArray());
	}

	@Override
	public Integer queryNotExamineCount(Integer state) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("SELECT COUNT(1) as count from kmt_question t where 1=1  ");
		if(state!=null){
			selSQL.append(" and t.state=? ");
			queryParams.add(state);
		}else{
			selSQL.append(" and t.state!=2 ");
		}
	
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	
	@Override
	public Integer queryQuTmpCount() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("SELECT COUNT(1) as count from kmt_question_temp t ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	
	@Override
	public List<Map<String,Object>> queryCountList() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.adduser,  ");
		selSQL.append(" (SELECT COUNT(1) from kmt_question p where p.adduser=t.adduser AND p.state=1 ) as count ,  ");
		selSQL.append(" (SELECT COUNT(1) from kmt_question p where p.adduser=t.adduser AND p.state=3 ) as examine ,  ");
		selSQL.append(" (SELECT COUNT(1) from kmt_question p where p.adduser=t.adduser AND p.state!=2 ) as total   ");
		selSQL.append(" FROM `kmt_question` t  where t.adduser IS NOT null AND t.adduser!=''  GROUP BY t.adduser ORDER BY total DESC   ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}
	
	

	@Override
	public List<Map<String,Object>> findKmtTeacherByPage() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("  SELECT  t.*,u.wx_name,u.photo,u.weixin_photo from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where  t.type=8 and t.state=1 ORDER BY t.create_time DESC   ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public Page<Map<String, Object>> findKmtTeacherByPage(Map<String, Object> params, Pageable pageable){
		StringBuilder sb = new StringBuilder();
		String name = "";
		if (StringUtil.isNotBlank(params.get("name").toString())) {
			name = params.get("name").toString();
		}
		sb.append("select t.*,")
				.append(" (select count(1) from scon_homework_picture where teacher_id = t.user_id and is_delete = 0 and is_feedback=1) feedback_num, ")
				.append(" (select count(1) from scon_homework_picture where teacher_id = t.user_id and is_delete = 0 and is_feedback=0) nofeedback_num ")
				.append(" from tb_lib_manager t where t.type in(8,11) and t.state=1 ");
		if (!"".equals(name)) {
			sb.append(" and t.name like '%").append(name).append("%' ");
		}
		sb.append(" order by t.is_online desc, t.create_time desc ");
		return dao.findPage(sb.toString(), pageable);
	}

	//这里用于查询kmt的login的，type=7 ，type=8 的 用于login  KMT 的
	@Override
	public Map<String,Object> findKmtTeacherByUserId(String userId) {
		StringBuilder selSQL = new StringBuilder();
		Map<String, Object> result = null;
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("  SELECT  t.*,u.wx_name,u.photo,u.weixin_photo , u.wx_account  from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where t.type in (7,8,11) and t.state=1 AND t.user_id=? ");
		queryParams.add(userId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if (list != null && list.size() > 0){
			for (Map<String, Object> map : list){
				if ("8".equals(map.get("type") + "")){
					result = map;
				}
			}
			if (result == null){
				result = list.get(0);
			}
		}
		return result;
	}

    //只查询线上老师
	@Override
	public Map<String,Object> findKmtTeacherByUserIdAndCourse(String userId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  t.*,u.wx_name,u.photo,u.weixin_photo from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where t.type =8  and t.state=1 and t.user_id=? and t.course_name is not null LIMIT 1    ");
		queryParams.add(userId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list!=null && list.size()>0 ?list.get(0):null;
	}
	
    //查询线上老师（course_name 不为空）同时也查询一对一老师
	@Override
	public Map<String,Object> findKmtTeacherByUserIdAndOne(String userId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  t.*,u.wx_name,u.photo,u.weixin_photo from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where (t.type =7 or t.type =8)  and t.state=1 and t.user_id=? and t.course_name is not null LIMIT 1    ");
		queryParams.add(userId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list!=null && list.size()>0 ?list.get(0):null;
	}
	

	@Override
	public Map<String,Object> findOnLineTeacherByRand(String courseName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  t.*,u.wx_name,u.photo,u.weixin_photo from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where t.type =8 and t.state=1 and t.course_name regexp ? ORDER BY RAND() LIMIT 1   ");
		queryParams.add(courseName);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list!=null && list.size()>0 ?list.get(0):null;
	}

	@Override
	public Map<String,Object> findOnLineTeacherByCourseNameAndGradeRand(String courseName,  String grade) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  t.*,u.wx_name,u.photo,u.weixin_photo from tb_lib_manager t LEFT JOIN tb_user u ON t.user_id = u.id where t.type =8 and t.state=1 and t.course_name regexp ? and t.grade regexp ? ORDER BY RAND() LIMIT 1   ");
		queryParams.add(courseName);
		queryParams.add(grade);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list!=null && list.size()>0 ?list.get(0):null;
	}


	@Override
	public List<Map<String, Object>> findTimeAndWeekByVipId(String vipId) {
		StringBuilder sb  = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		sb.append("select min(course_time) course_time,start_time, week from kmt_course where vip_id=? ")
				.append(" and plan_status < 4 group by week,start_time");
		queryParams.add(vipId);
		List<Map<String,Object>> list= dao.findMap(sb.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public List<Map<String, Object>> getTeachCount(String[] teacherIds, int planStatus) {
		StringBuilder sb  = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();

		sb.append("select teacher_id, count(1) count from kmt_course where plan_status >= ").append(planStatus);
		if (teacherIds != null && teacherIds.length > 0){
			sb.append(" and teacher_id in (");
			for (int i = 0; i < teacherIds.length; i++){
				sb.append("'").append(teacherIds[i]).append("',");
			}
			sb.deleteCharAt(sb.length() - 1);
			sb.append(")");
		}
		sb.append(" group by teacher_id");

		List<Map<String,Object>> list= dao.findMap(sb.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public List<Map<String, Object>> getTeachStudentCount(String[] teacherIds) {
		if (teacherIds == null || teacherIds.length == 0) return null;
		StringBuilder sb  = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		sb.append("select teacher_id, count(distinct vip_id) count from kmt_course where teacher_id in (");
		for (int i = 0; i < teacherIds.length; i++){
			sb.append("'").append(teacherIds[i]).append("',");
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append(") group by teacher_id");
		List<Map<String,Object>> list= dao.findMap(sb.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public List<Map<String, Object>> findFeedbackRatioMap(String courseKnowId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT q.easy,COUNT(1) as count from kmt_course_question_detail t  LEFT JOIN kmt_question q ON t.question_id=q.id where 1=1  ");
		if(StringUtils.isNotEmpty(courseKnowId)){
			selSQL.append(" and  t.course_know_id=?  ");
			queryParams.add(courseKnowId);
		}
		selSQL.append(" AND q.easy is NOT NULL GROUP BY q.easy  ORDER BY q.easy asc ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}
	
	@Override
	public List<Map<String, Object>> findFeedbackRatioVipMap() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT c.vip_id,q.easy,COUNT(1) as count,  ");
		selSQL.append(" 	(SELECT COUNT(1) as walcount from kmt_img_face_detail tt  ");
		selSQL.append(" 	LEFT JOIN kmt_img_face ff ON tt.face_id=ff.id  ");
		selSQL.append(" LEFT JOIN kmt_question qq ON tt.question_id=qq.id where 1=1 ");
		selSQL.append("	AND  qq.easy= q.easy  AND ff.vip_id=c.vip_id ) as walcount ");
		selSQL.append(" from kmt_course_question_detail t   ");
		selSQL.append(" LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id  ");
		selSQL.append(" LEFT JOIN kmt_question q ON t.question_id=q.id where    ");
		selSQL.append("  q.easy is NOT NULL  and c.vip_id is not NULL GROUP BY   c.vip_id, q.easy  ORDER BY c.vip_id,q.easy asc  ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}
	

	@Override
	public List<Map<String, Object>> findFeedbackWrongRatioMap(String courseId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT q.easy,COUNT(1) as count from kmt_img_face_detail t LEFT JOIN kmt_img_face f ON t.face_id=f.id LEFT JOIN kmt_question q ON t.question_id=q.id where 1=1  ");
		if(StringUtils.isNotEmpty(courseId)){
			selSQL.append(" AND  f.course_id=?   ");
			queryParams.add(courseId);
		}
		selSQL.append(" AND q.easy is NOT NULL GROUP BY q.easy ORDER BY q.easy asc");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}
	
	
	@Override
	public Integer findHowDetailsIdByAllCount(String zuoybKnowHowDetailId,String vipId,String courseKnowId) {
		Integer count=0;
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT k.how_details_id,COUNT(1) as count FROM `kmt_course_question_detail` t   ");
		selSQL.append(" LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id   ");
		selSQL.append(" LEFT JOIN (SELECT * from kmt_question_know where how_details_id=?) as k ON t.question_id=k.question_id  ");
		selSQL.append(" where c.vip_id=? AND k.how_details_id=? AND t.course_know_id=? ");
		selSQL.append(" GROUP BY k.how_details_id  ");
		queryParams.add(zuoybKnowHowDetailId);
		queryParams.add(vipId);
		queryParams.add(zuoybKnowHowDetailId);
		queryParams.add(courseKnowId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return count;
	}
	
	
	@Override
	public Integer findHowDetailsIdByWrongCount(String zuoybKnowHowDetailId,String vipId,String courseId) {
		Integer count=0;
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT k.how_details_id,COUNT(1) as count from kmt_img_face_detail t    ");
		selSQL.append(" LEFT JOIN kmt_img_face f ON t.face_id=f.id  ");
		selSQL.append(" LEFT JOIN kmt_course c ON f.course_know_id=c.course_know_id  ");
		selSQL.append(" LEFT JOIN (SELECT * from kmt_question_know where how_details_id=?) as k ON t.question_id=k.question_id  ");
		selSQL.append(" where t.question_id is NOT null AND t.question_id !=''  ");
		selSQL.append(" AND c.vip_id=?  AND k.how_details_id=? AND f.course_id=?  ");
		selSQL.append(" GROUP BY k.how_details_id ");
		queryParams.add(zuoybKnowHowDetailId);
		queryParams.add(vipId);
		queryParams.add(zuoybKnowHowDetailId);
		queryParams.add(courseId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return count;
	}
	
	@Override
	public Integer countFeedBackNum() {
		Integer count=0;
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT count(DISTINCT(t.vip_id)) as count from kmt_course t where t.course_know_id is not NULL   ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return count;
	}

	@Override
	public Map<String,List<Map<String, Object>>> findAllModularLatListMap(String vipId) {
		Map<String,List<Map<String, Object>>> reqmp=new HashMap<String, List<Map<String,Object>>>();
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT course_name,tmp.module as name ,SUM(count) as count  from ( ");
			selSQL.append(" SELECT h.course_name,d.module ,COUNT(DISTINCT(d.id)) as count FROM `kmt_course_question_detail`  t  ");
			selSQL.append(" LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id  ");
			selSQL.append(" LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id ");
			selSQL.append(" LEFT JOIN zyb_know_how h ON h.id=d.how_id ");
			selSQL.append("  where  h.course_name is NOT NULL AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(c.create_time)     ");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND c.vip_id=? ");
				queryParams.add(vipId);
			}
			selSQL.append("  GROUP BY h.course_name,d.module   ");
			selSQL.append(" UNION ");
			selSQL.append("  SELECT h.course_name,d.module, COUNT(DISTINCT(d.id)) as count  from zyb_student_work_how_details t    ");
			selSQL.append(" LEFT JOIN zyb_student_work w ON t.student_work_id=w.id ");
			selSQL.append("	LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id ");
			selSQL.append(" LEFT JOIN zyb_know_how h ON h.id=d.how_id 	");
			selSQL.append(" where h.course_name is NOT NULL AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(t.create_time)");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND w.vip_id=? ");
				queryParams.add(vipId);
			}
			selSQL.append("  GROUP BY h.course_name, d.module  ");
		selSQL.append("  ) as tmp GROUP BY tmp.module ORDER BY field(course_name,'语文','数学','英语') ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		for (Map<String, Object> map : list) {
			if(reqmp.containsKey(map.get("course_name").toString())){
				reqmp.get(map.get("course_name").toString()).add(map);
			}else{
				List<Map<String, Object>> ls=new ArrayList<Map<String,Object>>();
				ls.add(map);
				reqmp.put(map.get("course_name").toString(),ls);
			}
		}
		return reqmp;
	}

	@Override
	public  Map<String,List<Map<String, Object>>> findWrongModularLatListMap(String vipId) {
		Map<String,List<Map<String, Object>>> reqmp=new HashMap<String, List<Map<String,Object>>>();
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT course_name,tmp.module ,SUM(count) as count  from (   ");
	        selSQL.append(" SELECT  h.course_name,d.module, COUNT(DISTINCT(d.id)) as count from kmt_img_face_detail t     ");
	        selSQL.append("	LEFT JOIN kmt_img_face f ON t.face_id=f.id  ");
	        selSQL.append("	LEFT JOIN kmt_course c ON f.course_know_id=c.course_know_id   ");
	        selSQL.append("	LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id  ");
	        selSQL.append("	LEFT JOIN zyb_know_how h ON h.id=d.how_id  ");
	        selSQL.append("		where h.course_name is NOT NULL AND  DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(c.create_time)    ");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND c.vip_id=? ");
				queryParams.add(vipId);
			}
	        selSQL.append("	GROUP BY h.course_name,d.module     ");
	        selSQL.append("	UNION  ");
	        selSQL.append("		SELECT h.course_name,d.module, COUNT(DISTINCT(d.id)) as count  from zyb_student_work_img t    ");
	        selSQL.append("	LEFT JOIN zyb_student_work w ON t.object_id=w.id  ");
	        selSQL.append("	LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id  ");
	        selSQL.append("	LEFT JOIN zyb_know_how h ON h.id=d.how_id  ");
	        selSQL.append("	where  w.id is NOT NULL AND h.course_name is NOT NULL AND  DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(t.create_time)    ");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND w.vip_id=? ");
				queryParams.add(vipId);
			}
	        selSQL.append(" GROUP BY h.course_name, d.module  ");
        selSQL.append("  ) as tmp GROUP BY tmp.module ORDER BY field(course_name,'语文','数学','英语');   ");
        List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
        for (Map<String, Object> map : list) {
			if(reqmp.containsKey(map.get("course_name").toString())){
				reqmp.get(map.get("course_name").toString()).add(map);
			}else{
				List<Map<String, Object>> ls=new ArrayList<Map<String,Object>>();
				ls.add(map);
				reqmp.put(map.get("course_name").toString(),ls);
			}
		}
		return reqmp;
	}

	@Override
	public Map<String,List<Map<String, Object>>> findAllSkillLatListMap(String vipId) {
		Map<String,List<Map<String, Object>>> reqmp=new HashMap<String, List<Map<String,Object>>>();
		Map<String,Map<String, Integer>> tmpMap=new HashMap<String, Map<String,Integer>>();
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.course_name , q.skill from kmt_course_question_detail t    ");
	        selSQL.append(" LEFT JOIN kmt_question q ON t.question_id=q.id   ");
	        selSQL.append("	LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id ");
	        selSQL.append("	where q.skill is NOT null AND q.skill !='' AND q.course_name IS not NULL AND  DATE_SUB(CURDATE(), INTERVAL 90 DAY) <= DATE(c.create_time)    ");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND  c.vip_id=? ");
				queryParams.add(vipId);
			}
        List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
        for (Map<String, Object> map : list) {
			if(tmpMap.containsKey(map.get("course_name").toString())){
				String skill=map.get("skill").toString();
				String[] skills=skill.split(";");
				for (String sk : skills) {
					if(tmpMap.get(map.get("course_name").toString()).containsKey(sk)){
						tmpMap.get(map.get("course_name").toString()).put(sk,tmpMap.get(map.get("course_name").toString()).get(sk)+1);
					}else{
						tmpMap.get(map.get("course_name").toString()).put(sk,1);
					}
				}
			}else{
				tmpMap.put(map.get("course_name").toString(), new HashMap<String, Integer>());
				String skill=map.get("skill").toString();
				String[] skills=skill.split(";");
				for (String sk : skills) {
					if(tmpMap.get(map.get("course_name").toString()).containsKey(sk)){
						tmpMap.get(map.get("course_name").toString()).put(sk,tmpMap.get(map.get("course_name").toString()).get(sk)+1);
					}else{
						tmpMap.get(map.get("course_name").toString()).put(sk,1);
					}
				}
			}
		}
       Set<String> keyMap=tmpMap.keySet();
       for (String ckey : keyMap) {
    	   if(reqmp.containsKey(ckey)){
    		   Map<String, Integer>  map=tmpMap.get(ckey);
    		   Set<String> tmpkeyMap=map.keySet();
    		   for (String tmpkey : tmpkeyMap) {
    			   Map<String, Object> tmp=new HashMap<String, Object>();
    			   tmp.put("name", tmpkey);
    			   tmp.put("count", map.get(tmpkey));
    			   reqmp.get(ckey).add(tmp);
    		   }
    	   }else{
    		   reqmp.put(ckey, new ArrayList<Map<String,Object>>());
    		   Map<String, Integer>  map=tmpMap.get(ckey);
    		   Set<String> tmpkeyMap=map.keySet();
    		   for (String tmpkey : tmpkeyMap) {
    			   Map<String, Object> tmp=new HashMap<String, Object>();
    			   tmp.put("name", tmpkey);
    			   tmp.put("count", map.get(tmpkey));
    			   reqmp.get(ckey).add(tmp);
    		   }
    	   }
       }
	   return reqmp;
	}

	@Override
	public Map<String,List<Map<String, Object>>> findWrongSkillLatListMap(String vipId) {
		Map<String,List<Map<String, Object>>> reqmp=new HashMap<String, List<Map<String,Object>>>();
		Map<String,Map<String, Integer>> tmpMap=new HashMap<String, Map<String,Integer>>();
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT q.course_name , q.skill from kmt_img_face_detail t   ");
	        selSQL.append(" LEFT JOIN kmt_question q ON t.question_id=q.id     ");
	        selSQL.append("	LEFT JOIN kmt_img_face f ON t.face_id=f.id ");
	        selSQL.append("	LEFT JOIN kmt_course c ON f.course_know_id=c.course_know_id   ");
	        selSQL.append("	where q.skill is NOT null AND q.skill !='' AND q.course_name IS not NULL AND  DATE_SUB(CURDATE(), INTERVAL 90 DAY) <= DATE(c.create_time)    ");
			if(StringUtils.isNotEmpty(vipId)){
				selSQL.append(" AND  c.vip_id=? ");
				queryParams.add(vipId);
			}
        List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
        for (Map<String, Object> map : list) {
			if(tmpMap.containsKey(map.get("course_name").toString())){
				String skill=map.get("skill").toString();
				String[] skills=skill.split(";");
				for (String sk : skills) {
					if(tmpMap.get(map.get("course_name").toString()).containsKey(sk)){
						tmpMap.get(map.get("course_name").toString()).put(sk,tmpMap.get(map.get("course_name").toString()).get(sk)+1);
					}else{
						tmpMap.get(map.get("course_name").toString()).put(sk,1);
					}
				}
			}else{
				tmpMap.put(map.get("course_name").toString(), new HashMap<String, Integer>());
				String skill=map.get("skill").toString();
				String[] skills=skill.split(";");
				for (String sk : skills) {
					if(tmpMap.get(map.get("course_name").toString()).containsKey(sk)){
						tmpMap.get(map.get("course_name").toString()).put(sk,tmpMap.get(map.get("course_name").toString()).get(sk)+1);
					}else{
						tmpMap.get(map.get("course_name").toString()).put(sk,1);
					}
				}
			}
		}
       Set<String> keyMap=tmpMap.keySet();
       for (String ckey : keyMap) {
    	   if(reqmp.containsKey(ckey)){
    		   Map<String, Integer>  map=tmpMap.get(ckey);
    		   Set<String> tmpkeyMap=map.keySet();
    		   for (String tmpkey : tmpkeyMap) {
    			   Map<String, Object> tmp=new HashMap<String, Object>();
    			   tmp.put("name", tmpkey);
    			   tmp.put("count", map.get(tmpkey));
    			   reqmp.get(ckey).add(tmp);
    		   }
    	   }else{
    		   reqmp.put(ckey, new ArrayList<Map<String,Object>>());
    		   Map<String, Integer>  map=tmpMap.get(ckey);
    		   Set<String> tmpkeyMap=map.keySet();
    		   for (String tmpkey : tmpkeyMap) {
    			   Map<String, Object> tmp=new HashMap<String, Object>();
    			   tmp.put("name", tmpkey);
    			   tmp.put("count", map.get(tmpkey));
    			   reqmp.get(ckey).add(tmp);
    		   }
    	   }
       }
       return reqmp;
	}


	/**
	 * 查询所有老师的评价，算平均值
	 * @return
	 */
	@Override
	public List<Map<String, Object>> findAllTeacherPraise () {
		StringBuilder sb = new StringBuilder();
		sb.append("select teacher_id, AVG(parent_judge_lever) praise from kmt_course  WHERE parent_judge_lever is not null   group by teacher_id");
		return dao.findMap(sb.toString(), null);
	}


	@Override
	public Integer queryKdQuCount(String kdId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT count(1) as count FROM `kmt_question_know` t LEFT JOIN kmt_question q ON t.question_id=q.id  where q.state=1 AND t.how_details_kd_id=? ");
		queryParams.add(kdId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	@Override
	public Integer queryHowDetailsQuCount(String howDetailsId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT count(distinct q.id) as count FROM `kmt_question_know` t LEFT JOIN kmt_question q ON t.question_id=q.id where q.state=1 AND t.how_details_id=? ");
		queryParams.add(howDetailsId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	
	
	
	@Override
	public  List<Map<String, Object>> findHowByHowName(String courseName,String grade,String semester ,String howName){
	 	StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT d.*,t.`name` as howname,t.course_name,t.id as howid,s.num as sortnnm from zyb_know_how_details_sort s   ");
        selSQL.append(" LEFT JOIN zyb_know_how_details d ON s.how_details_id=d.id  ");
        selSQL.append(" LEFT JOIN zyb_know_how t ON d.how_id=t.id  ");
        selSQL.append(" where t.`name`=?      ");
        queryParams.add(howName);
       
        if(StringUtils.isNotEmpty(grade)){
        	selSQL.append(" AND s.grade=? ");
        	queryParams.add(grade);
        }
        if(StringUtils.isNotEmpty(semester)){
        	selSQL.append(" AND s.semester=? ");
        	queryParams.add(semester);
        }
        selSQL.append("  ORDER BY s.num asc ");
        return dao.findMap(selSQL.toString(),queryParams.toArray()); 
	 }


	@Override
	public List<Map<String, Object>> get121KnowModuleData(String vipId, String subject, String beginTime, String endTime) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT d.module ,COUNT(DISTINCT(d.id)) as count FROM `kmt_course_question_detail`  t  ")
			.append(" LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id   LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id  ")
			.append(" LEFT JOIN zyb_know_how h ON h.id=d.how_id   where  h.course_name='").append(subject)
				.append("' AND c.create_time between '")
			.append(beginTime).append("' and '").append(endTime).append("'");
		if (!StringUtil.isEmpty(vipId)){
			sb.append(" and c.vip_id='").append(vipId).append("'");
		}
		sb.append(" GROUP BY d.module");

		return dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> get121WrongKnowModuleData(String vipId, String subject, String beginTime, String endTime) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT d.module, COUNT(DISTINCT(d.id)) as count from kmt_img_face_detail t")
			.append(" LEFT JOIN kmt_img_face f ON t.face_id=f.id  LEFT JOIN kmt_course c ON f.course_know_id=c.course_know_id ")
			.append(" LEFT JOIN zyb_know_how_details d ON t.how_details_id=d.id  LEFT JOIN zyb_know_how h ON h.id=d.how_id")
			.append(" where h.course_name='").append(subject).append("' and c.create_time between '").append(beginTime).append("' and '").append(endTime).append("'");
		if (!StringUtil.isEmpty(vipId)){
			sb.append(" and c.vip_id='").append(vipId).append("'");
		}
		sb.append(" GROUP BY d.module");

		return dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> get121SkillData(String vipId, String subject, String beginTime, String endTime) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT q.skill module from kmt_course_question_detail t  LEFT JOIN kmt_question q ON t.question_id=q.id ")
				.append(" LEFT JOIN kmt_course c ON t.course_know_id=c.course_know_id where q.skill is NOT null ")
				.append(" AND q.skill !='' AND q.course_name='").append(subject).append("' AND  c.create_time between '")
				.append(beginTime).append("' and '").append(endTime).append("'");
		if (!StringUtil.isEmpty(vipId)){
			sb.append("  and c.vip_id='").append(vipId).append("'");
		}
		return dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> get121SkillWrongData(String vipId, String subject, String beginTime, String endTime) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT q.skill module from kmt_img_face_detail t LEFT JOIN kmt_question q ON t.question_id=q.id")
				.append(" LEFT JOIN kmt_img_face f ON t.face_id=f.id LEFT JOIN kmt_course c ON f.course_know_id=c.course_know_id ")
				.append(" where q.skill is NOT null AND q.skill !='' AND q.course_name='").append(subject).append("' AND  c.create_time between '")
				.append(beginTime).append("' and '").append(endTime).append("'");
		if (!StringUtil.isEmpty(vipId)){
			sb.append(" and c.vip_id='").append(vipId).append("'");
		}
		return dao.findMap(sb.toString(), null);
	}


	@Override
	public Integer countAddUserNum(String addUserId, Integer state) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("SELECT COUNT(1) as count from kmt_question t where t.adduser_id=?  AND t.state=?  ");
		queryParams.add(addUserId);
		queryParams.add(state);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	@Override
	public Integer countAddUserBySettlementNum(String addUserId, Integer settlement) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("SELECT COUNT(DISTINCT(t.question_id)) as count from kmt_question_extract t where t.sys_user_id=?   ");
		queryParams.add(addUserId);
		if(settlement!=null){
			selSQL.append(" AND t.settlement=?  ");
			queryParams.add(settlement);
		}
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}

	@Override
	public List<Map<String, Object>> findMathByNum() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.question_id,GROUP_CONCAT(t.id) as tid,GROUP_CONCAT(h.num) as hnum,   ");
        selSQL.append(" GROUP_CONCAT(d.num) as dnum,GROUP_CONCAT(kd.num) as kdnum from kmt_question_know t   ");
        selSQL.append(" LEFT JOIN zyb_know_how h ON t.how_id=h.id  ");
        selSQL.append(" LEFT JOIN zyb_know_how_details d on t.how_details_id=d.id   ");
        selSQL.append(" LEFT JOIN zyb_know_how_details_kd kd ON t.how_details_kd_id=kd.id");
        selSQL.append(" where t.course_name='数学' ");
        selSQL.append(" AND t.question_id is NOT NULL AND t.how_id is NOT NULL AND t.how_details_id is NOT NULL AND t.how_details_kd_id is NOT NULL ");
        selSQL.append(" AND kd.num is NOT NULL ");
        selSQL.append(" GROUP BY t.question_id HAVING kdnum LIKE '%,%' ");
        return dao.findMap(selSQL.toString(),queryParams.toArray()); 
	}

	@Override
	public List<Map<String, Object>> findCourseKnowIdMap(String courseKnowId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  how_details_id ,count(1) as total from  kmt_course_question_detail  ");
		queryParams.add(courseKnowId);
		selSQL.append(" where course_know_id =? AND  how_details_id is not null  GROUP BY how_details_id ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public List<Map<String, Object>> findLoadAllQuestionBySorl(String id,Integer page,Integer pageSize) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  t.*,group_concat(DISTINCT(q.how_details_kd_id)) as  how_details_kd_id,group_concat(DISTINCT(q.how_details_id)) as how_details_id, ");
		selSQL.append(" q.num as qnum  , ");
		selSQL.append(" group_concat(DISTINCT(IF(d.two_module ='积累' OR d.two_module ='词语拓展' ,d.two_module , d.`name`)) SEPARATOR '  知识点：') as dname, ");
		selSQL.append(" group_concat(DISTINCT(k.`name`) SEPARATOR '   考点：')as kname  , ");
		selSQL.append(" group_concat(DISTINCT(s.grade))as sgrade , ");
		selSQL.append(" group_concat(DISTINCT(s.type))as stype ");
		selSQL.append(" from kmt_question_know q  ");
		selSQL.append(" LEFT JOIN kmt_question t ON t.id=q.question_id   ");
		selSQL.append(" LEFT JOIN zyb_know_how_details_kd k ON q.how_details_kd_id=k.id ");
		selSQL.append(" LEFT JOIN zyb_know_how_details d ON d.id=q.how_details_id ");
		selSQL.append(" LEFT JOIN zyb_know_how_details_sort s ON q.how_details_id=s.how_details_id  ");
		selSQL.append(" where  ");
		selSQL.append(" t.id in (  ");
		if(StringUtils.isNotEmpty(id)){
			selSQL.append("'"+id+"'");
		}else{
			selSQL.append(" SELECT * from ( SELECT id from kmt_question t ORDER BY t.create_time asc LIMIT "+((page-1)*pageSize)+","+pageSize+") as tmpt  ");
		}
		selSQL.append(" ) ");
		selSQL.append(" GROUP BY t.id ; ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public Integer countAICount() {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append("SELECT COUNT(1) as count  from kmt_question t where t.source LIKE 'AI生成题目导入:%' ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}

	@Override
	public List<Map<String, Object>> findAIExport(Integer state) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.course_name,k.how_id,k.how_details_id,k.how_details_kd_id,t.question, ");
		selSQL.append(" t.option_content,t.option_answer,t.option_type,t.easy,t.skill,t.id,t.remarks,t.source,k.tags,t.parent_id ");
		selSQL.append("  from kmt_question_know k LEFT JOIN kmt_question t ON k.question_id=t.id ");
		selSQL.append(" where 1=1 ");
		if(state!=null){
			selSQL.append(" and t.state=? ");
			queryParams.add(state);
		}
		selSQL.append("  ORDER BY t.source ASC,t.create_time asc  ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public List<Map<String, Object>> findParentQuestionByHowId(String howDetailsId, String howDetailsKdId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT tq.* from kmt_question tq where tq.id IN ( ");
		selSQL.append(" SELECT DISTINCT(q.parent_id) from kmt_question_know t  ");
		selSQL.append(" LEFT JOIN kmt_question q ON t.question_id=q.id ");
		selSQL.append(" where  q.parent_id is NOT NULL AND q.parent_id <> ''  ");
		if(StringUtils.isNotEmpty(howDetailsId)){
			selSQL.append(" AND t.how_details_id = ? ");
			queryParams.add(howDetailsId);
		}
		if(StringUtils.isNotEmpty(howDetailsKdId)){
			selSQL.append(" AND t.how_details_kd_id = ? ");
			queryParams.add(howDetailsKdId);
		}
		selSQL.append("  ) ORDER BY tq.create_time DESC ");
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		return list;
	}

	@Override
	public Integer countQuestionByParentId(String parentId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT COUNT(1) as count from kmt_question t where t.parent_id=? ");
		queryParams.add(parentId);
		List<Map<String,Object>> list= dao.findMap(selSQL.toString(),queryParams.toArray());
		if(list!=null && list.size()>0){
			return Integer.parseInt(list.get(0).get("count").toString());
		}
		return 0;
	}
	
	
	@Override
	public void insertKmtQuestion(KmtQuestion kmtQuestion) {
		StringBuilder selSQL = new StringBuilder();
		selSQL.append(" INSERT INTO `kmt_question` ( ");
		selSQL.append(" `id`, `course_name`, `parent_id`, `question`, `option_content`, ");
		selSQL.append(" `option_answer`, `option_type`, `type`, `easy`, `explain_text`,  ");
		selSQL.append(" `analysis`, `thinking`, `suggest`, `create_time`, `update_time`,  ");
		selSQL.append(" `state`, `source`, `checkuser`, `skill`, `remarks`,  ");
		selSQL.append(" `min_option_type`, `num`, `tag`, `adduser`, `adduser_id`  ");
		selSQL.append(" ) ");
		selSQL.append(" VALUES ( ");
		selSQL.append(" ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ");
		selSQL.append(" ) ");
		Query query =dao.createSQLQuery(selSQL.toString());
		query.setString(0,kmtQuestion.getId());
		query.setString(1,kmtQuestion.getCourseName());
		query.setString(2,kmtQuestion.getParentId());
		query.setString(3,kmtQuestion.getQuestion());
		query.setString(4,kmtQuestion.getOptionContent());
		query.setString(5,kmtQuestion.getOptionAnswer());
		query.setString(6,kmtQuestion.getOptionType());
		query.setString(7,kmtQuestion.getType());
		query.setInteger(8,kmtQuestion.getEasy());
		query.setString(9,kmtQuestion.getExplainText());
		query.setString(10,kmtQuestion.getAnalysis());
		query.setString(11,kmtQuestion.getThinking());
		query.setString(12,kmtQuestion.getSuggest());
		query.setDate(13,kmtQuestion.getCreateTime());
		query.setDate(14,kmtQuestion.getUpdateTime());
		query.setInteger(15,kmtQuestion.getState());
		query.setString(16,kmtQuestion.getSource());
		query.setString(17,kmtQuestion.getCheckuser());
		query.setString(18,kmtQuestion.getSkill());
		query.setString(19,kmtQuestion.getRemarks());
		query.setString(20,kmtQuestion.getMinOptionType());
		query.setInteger(21,kmtQuestion.getNum()!=null?kmtQuestion.getNum():0);
		query.setString(22,kmtQuestion.getTag());
		query.setString(23,kmtQuestion.getAdduser());
		query.setString(24,kmtQuestion.getAdduserId());
		query.executeUpdate();
	}

	@Override
	public List<CourseHandoutTemplate> findCourseHandoutTemplateList(String teacherId, String courseName, String courseHandoutTemplateName) {
		String sql = "select id, name, create_time, course_know_id, topic, course_name " +
				"from kmt_course_know_template " +
				"where teacher_id = '" + teacherId + "' " +
				"and course_name = '" + courseName + "' " +
				"and name like '%" + courseHandoutTemplateName + "%' " +
				"order by create_time desc";
		return dao.findList(sql, CourseHandoutTemplate.class);
	}
	
	
	@Override
	public List<String> findKmtAiRecordByFileName() {
		String sql = "SELECT DISTINCT(t.file_name) FROM `kmt_ai_record` t ORDER BY t.create_time DESC ";
		return dao.findList(sql, String.class);
	}

	@Override
	public List<LessonGroupDTO> findLessonGroupList(String teacherId, String courseTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR_OF_DAY, -12);
        Date time = calendar.getTime();
        String timeStr = DateUtil.format_yyyyMMddHHmmss(time);

        String sql =
				"select ssj_lesson_group.id                lesson_group_id,\n" +
						"       ssj_lesson_group.group_name,\n" +
						"       kmt_course.start_time,\n" +
						"       kmt_course.end_time,\n" +
						"       !isnull(kmt_course.course_know_id) prepared,\n" +
						"       kmt_course.group_course_id,\n" +
						"       tb_lesson_service.course_name,\n" +
						"       group_concat(tb_lib_vip.img_url) student_img_url_str\n" +
						"from ssj_lesson_group,\n" +
						"     tb_lesson_service,\n" +
						"     kmt_course,\n" +
						"     tb_lib_vip\n" +
						"where ssj_lesson_group.id = tb_lesson_service.lesson_group_id\n" +
						"  and tb_lesson_service.id = kmt_course.lesson_service_id\n" +
						"  and tb_lesson_service.status = 1\n" +
						"  and kmt_course.vip_id = tb_lib_vip.id\n" +
						"  and ssj_lesson_group.teacher_id = '" + teacherId + "'\n" +
						"  and date(kmt_course.course_time) = '" + courseTime + "'\n" +
						"  and ssj_lesson_group.create_time <= '" + timeStr + "'\n" +
						"group by ssj_lesson_group.id\n";

		return dao.findList(sql, LessonGroupDTO.class);
	}

	@Override
	public List<Map<String, Object>> findLessonGroupStudentList(String groupCourseId, String timeStr) {
		String sql =
				"select tb_lib_vip.child_name, tb_lib_vip.img_url\n" +
				"from tb_lib_vip,\n" +
				"     tb_lesson_service,\n" +
				"     ssj_lesson_group,\n" +
				"     kmt_course\n" +
				"where tb_lib_vip.id = tb_lesson_service.vip_id\n" +
				"  and tb_lesson_service.status = 1\n" +
				"  and kmt_course.lesson_service_id = tb_lesson_service.id\n" +
				"  and kmt_course.group_course_id = ?\n" +
				"  and tb_lesson_service.lesson_group_id = ssj_lesson_group.id\n" +
				"  and ssj_lesson_group.create_time <= '" + timeStr + "'\n";

		return dao.findMap(sql, Collections.singletonList(groupCourseId).toArray());
	}

	@Override
	public List<Map<String, Object>> finishHandout(String lessonGroupId) {
		StringBuffer selSql = new StringBuffer();
		List<Object> queryParams = new ArrayList<Object>();
		selSql.append("select v.id,v.child_name,v.img_url from kmt_course k LEFT JOIN tb_lesson_service t ON k.lesson_service_id = t.id ");
		selSql.append("LEFT JOIN ssj_lesson_group g ON t.lesson_group_id = g.id ");
		selSql.append("LEFT JOIN tb_lib_vip v ON t.vip_id = v.id ");
		selSql.append("where k.is_group = 1 and k.plan_status < 5 and k.sign_in_off !=0 and g.id = ? and k.num = g.current_count");
		queryParams.add(lessonGroupId);
		return dao.findMap(selSql.toString(), queryParams.toArray());
	}

    @Override
    public List<KmtSysUserDTO> getDistributeCondition(String type) {
		String sql =
				"select id user_id, name, login_name\n" +
				"from kmt_sys_user\n" +
				"where state = 1\n" +
				"  and type = ? ";

        return dao.findList(sql, Collections.singleton(type).toArray(), KmtSysUserDTO.class);
    }

    public Page<Map<String,Object>> findTbLibTeacherByPage(Map<String,Object> params,Pageable pageable){
		StringBuilder sql = new StringBuilder();
		sql.append("select t.* from  tb_lib_manager t\n" +
				"left join tb_lib_manager_audit t1 on t1.lib_manager_id=t.id \n" +
				"and t1.status=0");
		return dao.findPage(sql.toString(), pageable);
	}
}
