package com.ssj.dao.weixin.zuoyb.dao.impl;


import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
import com.ssj.bean.weixin.zyb.domain.ZuoybKnowHow;
import com.ssj.bean.weixin.zyb.domain.ZuoybKnowHowDetails;
import com.ssj.bean.weixin.zyb.domain.ZuoybWeek;
import com.ssj.dao.weixin.zuoyb.dao.ZuoybQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.framework.core.util.MapGetterTool;
import com.ssj.framework.core.util.StringUtil;
import com.ssj.service.kmt.dto.KnowHowDTO;
import com.ssj.service.kmt.dto.KnowHowDetailsDTO;
import com.ssj.service.kmt.dto.TestPointDTO;
import com.ssj.service.kmt.request.KnowledgeRequest;
import org.apache.commons.lang3.StringUtils;
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.*;
import java.util.stream.Collectors;

/** 
 * @author  ZhangCaibao 
 * @version 2017年7月4日 下午1:17:16 
 * 类说明 
 */
@Repository
public class ZuoybQueryDaoImpl  implements ZuoybQueryDao{
	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> getZuoybCourseist(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT  z.id , z.course_name,z.course_hour ,z.lib_id, z.num , ");
	        selSQL.append("  MAX( CASE  WHEN  k.days =1 THEN k.id   END ) as monday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =2 THEN k.id   END ) as tuesday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =3 THEN k.id   END )as wednesday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =4 THEN k.id   END ) as thursday, ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =5 THEN k.id   END ) as friday, ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =6 THEN k.id   END ) as saturday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =7 THEN k.id   END ) as sunday ");
	        selSQL.append(" from zyb_course  z LEFT JOIN   zyb_week k on  z.id = k.zyb_course_id ");
	        selSQL.append(" where z.lib_id = ? ");
	        queryParams.add(searchParams.get("EQ_libId"));
	        if (searchParams.get("course_name") != null && !searchParams.get("course_name").equals("")) {
	        	selSQL.append(" and   z.course_name LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("course_name"));
	        }
	        selSQL.append(" GROUP BY z.id ,z.course_name,z.course_hour ");
	        selSQL.append(" ORDER BY  z.course_hour  asc  ,z.num asc , z.create_time asc ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public void insertZuoybWeekList(List<ZuoybWeek> list) {
		dao.batchInsert(list);
	}

	@Override
	public Page<Map<String, Object>> getZybList(
			Map<String, Object> searchParams, Pageable pageable) {
	        StringBuilder selSQL = new StringBuilder();
			List<Object> queryParams = new ArrayList<Object>();
			 selSQL.append("   SELECT   t.* ,u.wx_name  ,u.photo , IFNULL(z.teacher_id,'1') as xz from   tb_lib_staffing   t LEFT JOIN  tb_user  u  ");
		        selSQL.append("  on t.user_id  = u.id  ");
		        selSQL.append(" LEFT JOIN  zyb_week_teacher z  on  z.teacher_id = t.user_id  and z.zyb_week_id = ? ");
		        queryParams.add(searchParams.get("weekId"));
		        selSQL.append("  where  t.lib_id ='SSJ-SSJ-SR'   ");
		        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
		        	selSQL.append(" and  ( u.wx_name LIKE  CONCAT(CONCAT('%',?,'%'))  or   t.name LIKE  CONCAT(CONCAT('%',?,'%')) ) ");
		        	queryParams.add(searchParams.get("name"));
		        	queryParams.add(searchParams.get("name"));
		        }
		        if (searchParams.get("type") != null && searchParams.get("type").equals("1")) {
		        	selSQL.append(" and z.teacher_id is not null ");
		        }
		        if (searchParams.get("type") != null && searchParams.get("type").equals("2")) {
		        	selSQL.append(" and z.teacher_id is  null ");
		        }
		        selSQL.append("   order by   t.create_time desc   ");
		        
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> getTeacherIdList(String teacherId ,Integer day) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  z.id ,c.course_hour,z.teacher_id from  zyb_week  z  LEFT JOIN   zyb_course  c  on   ");
        selSQL.append(" c.id =  z.zyb_course_id  where  z.teacher_id = ?  and z.days = ? ");
        selSQL.append(" ORDER BY  z.days asc   ");
        queryParams.add(teacherId);
        queryParams.add(day);
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> findTeacherIdForPage(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
		 List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append("   select  t.zyb_course_id,t.course_hour,v.school , v.child_name,t.vip_id, v.id as v_id, v.img_url , v.user_id as v_user_id , k.type as k_type , 	k.id as k_student_push_id  ");
	        selSQL.append("  from  tb_lib_vip_service t  LEFT  join   tb_lib_vip v  ");
	        selSQL.append(" on t.vip_id =  v.id        ");
	        selSQL.append("   LEFT join  zyb_student_push k  ON k.vip_id = t.vip_id  AND k.lib_id = t.lib_id       ");
	        selSQL.append("   and TO_DAYS( k.push_time)  =  TO_DAYS(?)     ");
	        selSQL.append("  WHERE  t.lib_id = ? and t.species = 'S003' ");
	        queryParams.add(searchParams.get("date"));
	        queryParams.add(searchParams.get("libId"));
	        if (searchParams.get("courseHour") != null && !searchParams.get("courseHour").equals("")) {
	        	selSQL.append(" and t.course_hour = ?  ");
	        	queryParams.add(searchParams.get("courseHour"));
	        }
	        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
	        	selSQL.append(" and k.type = ?  ");
	        	queryParams.add(searchParams.get("type"));
	        }
	        selSQL.append("  ORDER BY  t.create_time  desc   ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public List<Map<String,Object>> getLibIdAndVipIdList(String libId,String vipId)  {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT c.course_name,c.course_hour,c.details ,s.id as s_id  from    zyb_course  c  ");
        selSQL.append(" LEFT JOIN tb_lib_vip_service  s  on  s.lib_id = c.lib_id   and  c.course_hour = s.course_hour   and s.vip_id = ?   ");
        selSQL.append(" and s.species ='S003' and s.stat =1  ");
        selSQL.append(" where  c.lib_id = ?  ");
        selSQL.append(" GROUP BY  c.course_hour  ");
        selSQL.append(" ORDER BY  c.course_hour asc   ");
        queryParams.add(vipId);
        queryParams.add(libId);
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getWorkList(String libId, String vipId,
			String date,String courseHour) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  s.parent_name,s.child_name,max(s.child_stat) ,s.num, s.stat, t.matching ,k.course_name from     zyb_student_work k   JOIN  zyb_student_work_details  s  ");
        selSQL.append(" 	on s.student_work_id = k.id   ");
        selSQL.append("        LEFT join   zyb_scoring_content  t  on s.scoring_content_id =  t.id    ");
        selSQL.append("      	where  k.vip_id = ? and k.lib_id = ?  and   TO_DAYS(k.scoring_time)  =  TO_DAYS(?)  ");
        selSQL.append("  AND  (s.num > 100 or s.num  = 5)   and k.course_hour = ? ");
        selSQL.append("      GROUP BY  s.parent_name ,k.course_name  ");
        selSQL.append("      ORDER BY   	s.num ASC ,t.create_time asc   ");
        queryParams.add(vipId);
        queryParams.add(libId);
        queryParams.add(date);
        queryParams.add(courseHour);
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}
	@Override
	public List<Map<String, Object>> workPercentage(String libId, String vipId,
			String date,String courseHour) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  s.parent_name,s.child_name,s.child_stat,s.num, s.stat, k.course_name   ");
		selSQL.append(" from     zyb_student_work k   JOIN  zyb_student_work_details  s 	on s.student_work_id = k.id   ");
		selSQL.append("      	where  k.vip_id = ? and k.lib_id = ?  and   TO_DAYS(k.scoring_time)  =  TO_DAYS(?)  ");
		selSQL.append("  AND ( s.num <9 or s.num =102 ) and k.course_hour = ? ");
		selSQL.append("      ORDER BY     k.scoring_time asc ,	s.num ASC  ");
		queryParams.add(vipId);
		queryParams.add(libId);
		queryParams.add(date);
		queryParams.add(courseHour);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}
	@Override
	public List<Map<String, Object>> getWorkList(String libId, String vipId,
			String date) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  s.parent_name,s.child_name,max(s.child_stat) ,s.num, s.stat, t.matching ,k.course_name from     zyb_student_work k   JOIN  zyb_student_work_details  s  ");
		selSQL.append(" 	on s.student_work_id = k.id   ");
		selSQL.append("        LEFT join   zyb_scoring_content  t  on s.scoring_content_id =  t.id    ");
		selSQL.append("      	where  k.vip_id = ? and k.lib_id = ?  and   TO_DAYS(s.scoring_time)  =  TO_DAYS(?)  ");
		selSQL.append("  AND s.num > 100 or s.num  = 5    ");
		selSQL.append("      GROUP BY  s.parent_name  ");
		selSQL.append("      ORDER BY   	s.num ASC ,t.create_time asc   ");
		queryParams.add(vipId);
		queryParams.add(libId);
		queryParams.add(date);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> zuoybSRList(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT  z.course_hour ,z.lib_id, j.league_name, ");
	        selSQL.append("  MAX( CASE  WHEN  k.days =1 THEN k.id   END ) as monday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =2 THEN k.id   END ) as tuesday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =3 THEN k.id   END )as wednesday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =4 THEN k.id   END ) as thursday, ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =5 THEN k.id   END ) as friday, ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =6 THEN k.id   END ) as saturday,  ");
	        selSQL.append(" MAX( CASE  WHEN  k.days =7 THEN k.id   END ) as sunday ");
	        selSQL.append(" from zyb_course  z LEFT JOIN   zyb_week k on  z.id = k.zyb_course_id ");
	        selSQL.append("  LEFT JOIN  tb_lib_join j on z.lib_id = j.id  ");
	        selSQL.append("  where j.type >= 1  ");
	        if (searchParams.get("EQ_libId") != null && !searchParams.get("EQ_libId").equals("")) {
	        	selSQL.append(" and    z.lib_id = ? ");
	        	queryParams.add(searchParams.get("EQ_libId"));
	        }
	        if (searchParams.get("orgCodeStr") != null && !searchParams.get("orgCodeStr").equals("")) {
	        	selSQL.append(" and  j.org_code in ( ");
	        	selSQL.append(searchParams.get("orgCodeStr"));
	        	selSQL.append(" ) ");
	        }
	        selSQL.append(" GROUP BY  z.course_hour,z.lib_id  ");
	        selSQL.append(" ORDER BY  z.lib_id asc ,z.course_hour  asc  ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> selectZybSRList(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		 selSQL.append("   SELECT DISTINCT  t.* ,u.wx_name  ,u.photo , IFNULL(z.teacher_id,'1') as xz from   tb_lib_staffing   t LEFT JOIN  tb_user  u  ");
	        selSQL.append("  on t.user_id  = u.id  ");
	        selSQL.append(" LEFT JOIN  zyb_week_teacher z  on  z.teacher_id = t.user_id  and z.lib_id =?  and  z.days=?  and  z.course_hour=?  ");
	        queryParams.add(searchParams.get("libId"));
	        queryParams.add(searchParams.get("days"));
	        queryParams.add(searchParams.get("courseHour"));
	        selSQL.append("  where  t.lib_id ='SSJ-SSJ-SR'  ");
	        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
	        	selSQL.append(" and  ( u.wx_name LIKE  CONCAT(CONCAT('%',?,'%'))  or   t.name LIKE  CONCAT(CONCAT('%',?,'%')) ) ");
	        	queryParams.add(searchParams.get("name"));
	        	queryParams.add(searchParams.get("name"));
	        }
	        if (searchParams.get("type") != null && searchParams.get("type").equals("1")) {
	        	selSQL.append(" and z.teacher_id is not null ");
	        }
	        if (searchParams.get("type") != null && searchParams.get("type").equals("2")) {
	        	selSQL.append(" and z.teacher_id is  null ");
	        }
	        selSQL.append("   order by   t.create_time desc   ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> zuoybStudentPushList(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		 selSQL.append("   SELECT  v.* from   tb_lib_vip_service  l  ");
	        selSQL.append(" LEFT JOIN  tb_lib_vip  v on l.vip_id  = v.id  ");
	        selSQL.append(" where   l.species ='S003' and  l.stat =1 and  l.lib_id = ?   ");
	        queryParams.add(searchParams.get("EQ_libId"));
	        if (searchParams.get("child_name") != null && !searchParams.get("child_name").equals("")) {
	        	selSQL.append(" and   v.child_name LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("child_name"));
	        }
	        if (searchParams.get("parent_name") != null && !searchParams.get("parent_name").equals("")) {
	        	selSQL.append(" and   v.parent_name LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("parent_name"));
			}  
	        selSQL.append("   GROUP BY l.vip_id   ");
	        selSQL.append("  order by  l.create_time  desc   ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> getXqTopicCount(String vipId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT IFNULL(ROUND((a.zt_count-a.ct_count)/a.zt_count*100,1),0) as per ,(a.zt_count-a.ct_count)as zq_count , a.ct_count from  (  ");
        selSQL.append(" SELECT ifnull(sum(CASE  s.num WHEN 6 THEN  s.child_name else 0 END  ),0) as  zt_count,  ");
        selSQL.append("  ifnull(sum(CASE  s.num WHEN 5 THEN  s.child_name else 0 END  ),0) as  ct_count   ");
        selSQL.append("  from   zyb_student_work  k  LEFT JOIN  zyb_student_work_details  s   ");
        selSQL.append("  on k.id = s.student_work_id   ");
        selSQL.append("  where s.num in (5,6)  and k.vip_id=?  and k.stat = 3   ");
        selSQL.append("  and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(s.scoring_time)   ) as a  ");
        queryParams.add(vipId);
        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 List<Map<String, Object>> getXqWeekReport(String vipId,String startTime, String endTime) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT date(k.scoring_time) as scoring_time ,s.parent_name,s.child_name,s.child_stat,s.num, s.stat, k.course_name   ");
        selSQL.append(" from     zyb_student_work k   JOIN  zyb_student_work_details  s 	on s.student_work_id = k.id    ");
        selSQL.append("  where  k.stat = 3 and     ");
        selSQL.append("  s.num <9 and s.num >3  and k.vip_id=?   ");
        selSQL.append("  and  TO_DAYS(k.scoring_time)  >= TO_DAYS(?) and   TO_DAYS(k.scoring_time)  < TO_DAYS(?) ");
        //selSQL.append("  and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(k.scoring_time)    ");
        selSQL.append("  ORDER BY  k.scoring_time asc    ");
        queryParams.add(vipId);
        queryParams.add(startTime);
        queryParams.add(endTime);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getStudentWork(String pushId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT  h.parent_name,h.child_name,h.num   ");
        selSQL.append(" from     zyb_student_work  k  JOIN  zyb_student_work_details  h  on k.id = h.student_work_id   ");
        selSQL.append("  where k.student_push_id =?     ");
        selSQL.append("  and h.num  in ('111','5','6')   ");
        queryParams.add(pushId);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<Map<String, Object>> getZuoybStudentPushList(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		 selSQL.append("   SELECT  s.id ,s.vip_id ,s.lib_id ,s.push_time,s.teacher_id ,s.total,DATE_FORMAT(s.push_time,'%m月%d日') AS date_time,s.type ,s.img from  zyb_student_push  s ");
	        selSQL.append(" where  (s.type =2 or ( TO_DAYS(s.push_time) = TO_DAYS(now())))  and s.vip_id =? ");
	        queryParams.add(searchParams.get("vipId"));
	        selSQL.append("  ORDER BY  s.push_time desc    ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Map<String, Object> getTeacherAndPhoto(String vipId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT IFNULL(e.`name`,u.wx_name) as `name` ,p.type , u.photo  from  tb_lib_manager  e JOIN  tb_user  u on e.user_id = u.id  ");
        selSQL.append(" join zyb_student_push  p  on p.teacher_id = e.user_id  ");
        selSQL.append("  where p.vip_id =? and TO_DAYS(p.push_time) = TO_DAYS(NOW()) and e.state=1 LIMIT 1  ");
        queryParams.add(vipId);
        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>> getKonwDetail(Map<String, Object> params) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("SELECT t.course_name,t.id,t.`name`,t.num,t.module,t.create_time as how_create_time, ");
        selSQL.append(" t11.before_name,t11.after_name,t11.type,t11.is_hot, t11.module as t11_module, t11.img,");
        selSQL.append(" t11.`name` as detail_name,t11.memorize,t11.understanding,t11.apply,t11.duration,t11.id as detail_id,t11.two_module,  \n");
        selSQL.append(" t11.jxmb,t11.zdbx,t11.ydsl, t11.num as detail_num , t11.create_time as detail_create_time,");
        selSQL.append(" s.id as s_id ,s.semester,s.type as s_type,s.grade,s.num as s_num,s.grade_num ,s.create_time as s_create_time ");
        selSQL.append("from  zyb_know_how t \n");
        selSQL.append("left join zyb_know_how_details t11 on t.id = t11.how_id\n");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_id = t11.id  ");
        selSQL.append("where t.lib_id = ? \n");
        queryParams.add(params.get("EQ_libId"));
        if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
        	selSQL.append("and t.course_name = ? \n");
        	queryParams.add(params.get("EQ_courseName"));
        }
        if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(params.get("EQ_grade"));
        }
        if(params.get("grade") != null && !params.get("grade").equals("")){
        	selSQL.append("and s.grade = ? \n");
        	queryParams.add(params.get("grade"));
        }
        if(params.get("banben") != null && !params.get("banben").equals("")){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(params.get("banben"));
        }
        if(params.get("semester") != null && !params.get("semester").equals("")){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(params.get("semester"));
        }
        if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
        	selSQL.append("and t.name LIKE  CONCAT(CONCAT('%',?,'%')) \n");
        	queryParams.add(params.get("LIKE_name"));
        }
        
        selSQL.append("order by t.course_name,t.num ,t.create_time , t.id,t11.num ,t11.id   ");
      //   selSQL.append(" and t.is_zt =1   ");
      //   selSQL.append("order by t.course_name,t.name ,t.create_time ,t11.num ,t11.id   ");
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getRecentWorkBg(String vipId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" select course_name ,count(1) as coursecount,SUM(time_cost) as timecount  from  zyb_student_work ");
		selSQL.append(" 	where  ");
		selSQL.append("       TO_DAYS(NOW()) -TO_DAYS(scoring_time) BETWEEN 1 and  7    ");
		selSQL.append("    and vip_id=? and type =1 and stat=3  ");
		selSQL.append("  GROUP BY course_name  ");
		queryParams.add(vipId);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> Last7days(String vipId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  sum(time_cost) as used_time  ,DATE_FORMAT(date(scoring_time),'%m.%d') as date_time     from zyb_student_work  ");
		selSQL.append(" 	where vip_id=?  ");
		selSQL.append("    and    TO_DAYS(NOW()) -TO_DAYS(scoring_time) BETWEEN 1 and  7   and type =1 and stat =3  ");
		selSQL.append("   GROUP BY  date(scoring_time)  ");
		selSQL.append("  ORDER BY  date_time desc  ");
		queryParams.add(vipId);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> Lastproblem7days(String vipId) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
			selSQL.append(" SELECT  `subject` as course_name ,count(1) as coursecount from  scon_problem_picture   ");
			selSQL.append(" where  is_feedback=1  and TO_DAYS(NOW()) -TO_DAYS(create_time) BETWEEN 1 and  7  ");
			selSQL.append(" and vip_id =? ");
			selSQL.append(" GROUP BY `subject`   ");
			queryParams.add(vipId);
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Map<String, Object> getTeacherPraise(String teacherId) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" select count(*) as answernum,sum(z.`level`)/(count(*)*5) as praise from zyb_student_push z ");
        selSQL.append(" where z.teacher_id =? ");
        queryParams.add(teacherId);
        List<Map<String, Object>> list = dao.findMap(selSQL.toString(), queryParams.toArray());
		return list!=null && list.size()>0 ? list.get(0) :null;
	}

	@Override
	public Page<Map<String, Object>> getVipIdByLibId4Page(String libId,String teacherId, Pageable pageable) {
		StringBuilder sb = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		sb.append(" SELECT tmp1.*,v.*,s.tags_character,s.tags_habit from ( ");
			sb.append(" SELECT tmp.vip_id,group_concat(DISTINCT(species)) as species ,group_concat(DISTINCT(type)) as type from ( ");
				sb.append(" SELECT t.vip_id,'' as species, '' as type from kmt_student t where t.teacher_id=?  ");
				sb.append(" UNION ");
				sb.append(" SELECT  t.vip_id ,t.species,t.type from tb_lib_vip_service t where t.stat=1 AND t.species='S003'  and t.lib_id=? ");
			sb.append(" ) as tmp GROUP BY vip_id   ");
		sb.append(" ) as tmp1 LEFT JOIN tb_lib_vip v ON tmp1.vip_id=v.id LEFT JOIN kmt_student s ON v.id=s.vip_id ");
		sb.append("  where  s.state=1  ");
		queryParams.add(teacherId);
		queryParams.add(libId);
		sb.append("  ORDER BY   ");
		sb.append(" case ");
		sb.append(" when tmp1.species='' then 1 ");
		sb.append(" when tmp1.species='S001,S003' then 2 ");
		sb.append(" when tmp1.species='S003,S001' then 3 ");
		sb.append(" when tmp1.species='S003' then 4 ");
		sb.append(" when tmp1.species='S001' then 5 ");
		sb.append(" end ");
		sb.append(" ,v.activate_time asc ");
		return dao.findPage(sb.toString(), queryParams.toArray(), pageable);
	}
	
	@Override
	public Page<Map<String, Object>> searchStudentList(String libId,String masterId,String keyword, Pageable pageable) {
		StringBuilder sb = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		sb.append(" SELECT tmp1.*,v.*,s.tags_character,s.tags_habit from ( ");
			sb.append(" SELECT tmp.vip_id,group_concat(DISTINCT(species)) as species ,group_concat(DISTINCT(type)) as type from ( ");
				sb.append(" SELECT t.vip_id,'' as species, '' as type from tb_lib_vip_bind t where t.master_id=?  ");
				sb.append(" UNION ");
				sb.append(" SELECT  t.vip_id ,t.species,t.type from tb_lib_vip_service t where t.stat=1  and t.lib_id=? ");
			sb.append(" ) as tmp GROUP BY vip_id   ");
		sb.append(" ) as tmp1 LEFT JOIN tb_lib_vip v ON tmp1.vip_id=v.id LEFT JOIN kmt_student s ON v.id=s.vip_id ");
		//sb.append("  where v.child_name is not null AND s.state=1  ");
		sb.append("  where  s.state=1  ");
		queryParams.add(masterId);
		queryParams.add(libId);
		if(StringUtils.isNotEmpty(keyword)){
			sb.append("  AND  v.child_name CONCAT(CONCAT('%',?,'%')) ");
			queryParams.add(keyword);
		}
		sb.append("  ORDER BY   ");
		sb.append(" case ");
		sb.append(" when tmp1.species='' then 1 ");
		sb.append(" when tmp1.species='S001,S003' then 2 ");
		sb.append(" when tmp1.species='S003,S001' then 3 ");
		sb.append(" when tmp1.species='S003' then 4 ");
		sb.append(" when tmp1.species='S001' then 5 ");
		sb.append(" end ");
		sb.append(" ,v.activate_time asc ");
		return dao.findPage(sb.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> getKonwKdDetail(Map<String, Object> params) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("SELECT DISTINCT t.course_name,t.id,t.`name`,t.num, t.create_time as how_create_time, ");
        selSQL.append("  t11.module as t11_module, ");
        selSQL.append(" t11.`name` as detail_name,t11.id as detail_id,t11.two_module, t11.ydsl, t11.create_time as detail_create_time, ");
        selSQL.append(" t11.num as detail_num ,k.id as k_id ,k.`name` as k_name ,k.ydsl as k_ydsl ,k.img as k_img ,k.num as k_num ,k.level as k_level , k.label as k_label ,k.create_time as k_create_time ");
        selSQL.append("from  zyb_know_how t ");
        selSQL.append("left join zyb_know_how_details t11 on t.id = t11.how_id ");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_id = t11.id  ");
        selSQL.append("LEFT JOIN zyb_know_how_details_kd k on k.how_details_id = t11.id    ");
        selSQL.append("where t.lib_id = ? \n");
        queryParams.add(params.get("EQ_libId"));
        if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
        	selSQL.append("and t.course_name = ? \n");
        	queryParams.add(params.get("EQ_courseName"));
        }
        if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(params.get("EQ_grade"));
        }
        if(params.get("banben") != null && !params.get("banben").equals("")){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(params.get("banben"));
        }
        if(params.get("semester") != null && !params.get("semester").equals("")){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(params.get("semester"));
        }
        if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
        	selSQL.append("and t.name  LIKE  CONCAT(CONCAT('%',?,'%')) \n");
        	queryParams.add(params.get("LIKE_name"));
        }
        
        selSQL.append("order by t.course_name,t.num ,t.id,t11.num ,t11.id ,k.num   ");
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	/**
	 * 查询小塾反馈详情
	 * @param objectIds
	 * @return
	 */
	public List<Map<String, Object>> getFeedbackDetailForConch (String[] objectIds){
		if (objectIds == null || objectIds.length == 0) return null;
		StringBuilder sb = new StringBuilder();
		sb.append("select img, work_num, list_num, line_num, column_num from zyb_student_work_img where object_id in (");
		StringBuilder sbId  = new StringBuilder();
		for (String id : objectIds){
			sbId.append("'").append(id).append("',");
		}
		sbId.deleteCharAt(sbId.length() - 1);
		sb.append(sbId.toString()).append(") group by img, work_num, list_num, line_num, column_num order by work_num, list_num, line_num, column_num");
		List<Map<String, Object>> list = dao.findMap(sb.toString(), null);
		return list;
	}

	@Override
	public Page<Map<String, Object>> getZuoybKnowHow(
			Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		StringBuilder selSQL1 = new StringBuilder();
	        
	        selSQL1.append("SELECT 	  ");
	        selSQL1.append(" t.`id`,t.`course_name`,t.`create_time`,t.`lib_id`,	t.`name`,  ");
	        selSQL1.append("	t.`num`,t.`module`,t.`is_zt`  ");
	        selSQL.append(" from  zyb_know_how t \n");
	        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_id = t.id  ");
	        selSQL.append("where t.lib_id = ? \n");
	        queryParams.add(params.get("EQ_libId"));
	        int i=0;
	        int j= 0;
	        if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
	        	selSQL.append("and t.course_name = ? \n");
	        	queryParams.add(params.get("EQ_courseName"));
	        	
	        }
		if(params.get("LIKE_id") != null && !params.get("LIKE_id").equals("")){
			selSQL.append("and t.id = ? \n");
			queryParams.add(params.get("LIKE_id"));
		}
	        if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
	        	selSQL.append("and s.grade_num = ? \n");
	        	queryParams.add(params.get("EQ_grade"));
	        	i++;
	        }
	        if(params.get("banben") != null && !params.get("banben").equals("")){
	        	selSQL.append("and s.type = ? \n");
	        	queryParams.add(params.get("banben"));
	        	
	        	i++;
	        	j++;
	        }
	        if(params.get("semester") != null && !params.get("semester").equals("")){
	        	selSQL.append("and s.semester = ? \n");
	        	queryParams.add(params.get("semester"));
	        	i++;
	        }
		if (params.get("beginDate") != null && !params.get("beginDate").equals("")) {
			selSQL.append(" and TO_DAYS(t.create_time) >=TO_DAYS(?) ");
			queryParams.add(params.get("beginDate"));
		}
		if (params.get("endDate") != null && !params.get("endDate").equals("")) {
			selSQL.append(" and TO_DAYS(t.create_time) <=TO_DAYS(?) ");
			queryParams.add(params.get("endDate"));
		}
		if(i>0){
			if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
				selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
				queryParams.add(params.get("LIKE_name"));
				queryParams.add(params.get("LIKE_name"));

			}
		}else{
			if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
				selSQL.append("and   t.name  LIKE  CONCAT(CONCAT('%',?,'%')) \n");
				queryParams.add(params.get("LIKE_name"));
			}
		}
	        
	        if(i>0){
	        	selSQL.append("and s.stat =1 \n");
	        }
	        selSQL.append(" GROUP BY t.id   ");
	        if(j>0){
	        	
	        	selSQL.append("order by t.course_name,s.num , t.num,t.create_time  ");
	        }else{
	        	selSQL.append("order by t.course_name,t.num ,t.create_time , s.num ");
	        }
	        if(j>0){
	        	selSQL1 = new StringBuilder();
	        	selSQL1.append("SELECT 	  ");
		        selSQL1.append(" t.`id`,t.`course_name`,t.`create_time`,t.`lib_id`,	s.`alias` as `name`,  ");
		        selSQL1.append("	s.`num`,t.`module`,t.`is_zt`  ");
	        }
	        selSQL1.append(selSQL);
		return dao.findPage(selSQL1.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> findKnowHowByPage(Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<>();
		selSQL.append("SELECT t.*,t1.alias ");
		selSQL.append(" from  zyb_know_how t ");
		selSQL.append("LEFT JOIN zyb_know_how_details_sort t1 on t1.how_id = t.id  ");
		selSQL.append("where t1.stat = 1 ");
		//科目
		if (StringUtil.isNotBlank((String)params.get("courseName"))) {
			selSQL.append("and t1.course_name = ? ");
			queryParams.add(params.get("courseName"));
		}
		//年级
		if (StringUtil.isNotBlank((String)params.get("grade"))) {
			selSQL.append("and t1.grade = ? ");
			queryParams.add(params.get("grade"));
		}
		//上下册
		if (params.get("semester") != null) {
			selSQL.append("and t1.semester = ? ");
			queryParams.add(params.get("semester"));
		}
		//版本
		if (params.get("banben") != null) {
			selSQL.append("and t1.type = ? ");
			queryParams.add(params.get("banben"));
		}
		selSQL.append("order by t1.num,t.num,t.create_time  ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> findKnowHowDetailByPage(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<>();
		selSQL.append("select t.how_details_id,t.alias,t.how_id,t1.alias how_name");
		selSQL.append(" from zyb_know_how_details_sort t ");
		selSQL.append(" left join (select * from zyb_know_how_details_sort where stat=1 and type=?) t1 on t.how_id = t1.how_id ");
		selSQL.append(" where t.stat=2 and t.type=? ");
		queryParams.add(searchParams.get("banben"));
		queryParams.add(searchParams.get("banben"));
		if (StringUtil.isNotBlank((String) searchParams.get("LIKE_name"))) {
			selSQL.append("and t.alias LIKE CONCAT(CONCAT('%',?,'%')) ");
			queryParams.add(searchParams.get("LIKE_name"));
		}
		selSQL.append(" order by t.num,t.create_time ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> getZuoybKnowHowDetails(
			Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		StringBuilder selSQL1 = new StringBuilder();
		
	        selSQL1.append("SELECT t.`id`, t.`how_id`, t.`create_time`, t.`lib_id`, t.`name`, t.`num`, t.`before_name`,  ");
	        selSQL1.append(" t.`after_name`, t.`type`, t.`is_hot`, t.`memorize`, t.`understanding`,  ");
	        selSQL1.append(" t.`apply`, t.`duration`, t.`two_module`, t.`module`, t.`jxmb`, t.`zdbx`, t.`ydsl`, t.`img`, t.`is_zt`  ");
	        selSQL.append("from  zyb_know_how_details t \n");
	        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_id = t.id  ");
	        selSQL.append("where t.lib_id = ? \n");
	        queryParams.add(params.get("EQ_libId"));
	        if(params.get("EQ_howId") != null && !params.get("EQ_howId").equals("")){
	        	selSQL.append(" and t.how_id  =?  \n");
	        	queryParams.add(params.get("EQ_howId"));
	        }
		if(params.get("LIKE_id") != null && !params.get("LIKE_id").equals("")){
			selSQL.append(" and t.id  =?  \n");
			queryParams.add(params.get("LIKE_id"));
		}
	        int i=0;
	        int j=0;
	        if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
	        	selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
	        	queryParams.add(params.get("LIKE_name"));
	        	queryParams.add(params.get("LIKE_name"));
	        	i++;
	        }
	        if(params.get("LIKE_module") != null && !params.get("LIKE_module").equals("")){
	        	selSQL.append(" and t.module LIKE  CONCAT(CONCAT('%',?,'%')) \n");
	        	queryParams.add(params.get("LIKE_module"));
	        }
	        if(params.get("banben") != null && !params.get("banben").equals("")){
	        	selSQL.append("and s.type = ? \n");
	        	queryParams.add(params.get("banben"));
	        	i++;
	        	j++;
	        }
	        if(params.get("semester") != null && !params.get("semester").equals("")){
	        	selSQL.append("and s.semester = ? \n");
	        	queryParams.add(params.get("semester"));
	        	i++;
	        }
	        if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
	        	selSQL.append("and s.grade_num = ? \n");
	        	queryParams.add(params.get("EQ_grade"));
	        	i++;
	        }
	        if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
	        	selSQL.append("and s.course_name = ? \n");
	        	queryParams.add(params.get("EQ_courseName"));
	        	i++;
	        }
	        if(i>0){
	        	selSQL.append("and s.stat=2 \n");
	        }
	        selSQL.append(" GROUP BY t.id   ");
	        selSQL.append("order by t.num ,t.create_time,s.num  ");
	        
	        if(j>0){
	        	selSQL1 = new StringBuilder();
	    		
		        selSQL1.append("SELECT t.`id`, t.`how_id`, t.`create_time`, t.`lib_id`, s.alias as  `name`, s.`num`, t.`before_name`, ");
		        selSQL1.append(" t.`after_name`, t.`type`, t.`is_hot`, t.`memorize`, t.`understanding`,   ");
		        selSQL1.append(" t.`apply`, t.`duration`, t.`two_module`, t.`module`, t.`jxmb`, t.`zdbx`, t.`ydsl`, t.`img`, t.`is_zt`  ");
	        }
	        selSQL1.append(selSQL);
		return dao.findPage(selSQL1.toString(), queryParams.toArray(), pageable);
	}
	@Override
	public Page<Map<String, Object>> getZuoybKnowHowDetailsKd(
			Map<String, Object> params, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		StringBuilder selSQL1 = new StringBuilder();
		
		selSQL1.append("SELECT t.`id`, t.`how_details_id`, t.`name`, t.`create_time`, t.`how_id`, t.`ydsl`, t.`img`, t.`num`, t.`label`, t.`level` ");
		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 1=1 \n");
		//queryParams.add(params.get("EQ_libId"));
		if(params.get("EQ_howId") != null && !params.get("EQ_howId").equals("")){
			selSQL.append(" and t.how_id  =?  \n");
			queryParams.add(params.get("EQ_howId"));
		}
		if(params.get("LIKE_id") != null && !params.get("LIKE_id").equals("")){
			selSQL.append(" and t.id  =?  \n");
			queryParams.add(params.get("LIKE_id"));
		}
		if(params.get("EQ_howDetailsId") != null && !params.get("EQ_howDetailsId").equals("")){
			selSQL.append(" and  t.how_details_id  =?  \n");
			queryParams.add(params.get("EQ_howDetailsId"));
		}
		
		int i=0;
		int j=0;
		if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
			selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
			queryParams.add(params.get("LIKE_name"));
			queryParams.add(params.get("LIKE_name"));
			i++;
		}
		if(params.get("banben") != null && !params.get("banben").equals("")){
			selSQL.append("and s.type = ? \n");
			queryParams.add(params.get("banben"));
			i++;
			j++;
		}
		if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(params.get("EQ_grade"));
        	i++;
        }
		if(params.get("semester") != null && !params.get("semester").equals("")){
			selSQL.append("and s.semester = ? \n");
			queryParams.add(params.get("semester"));
			i++;
		}
		/*if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
			selSQL.append("and s.course_name = ? \n");
			queryParams.add(params.get("EQ_courseName"));
			i++;
		}*/
		if(i>0){
			selSQL.append("and s.stat=3 \n");
		}
		selSQL.append(" GROUP BY t.id   ");
		selSQL.append("order by t.num ,t.create_time,s.num  ");
		if(j>0){
			selSQL1 = new StringBuilder();
			selSQL1.append("SELECT t.`id`, t.`how_details_id`,  s.alias as  `name` , t.`create_time`, t.`how_id`, t.`ydsl`, t.`img`, s.`num`, t.`label`, t.`level` ");
			
		}
		selSQL1.append(selSQL);
		return dao.findPage(selSQL1.toString(), queryParams.toArray(), pageable);
	}

	@Override
	 public Page<Map<String, Object>> getKonwTBDetail(Map<String, Object> params, Pageable sp) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("SELECT DISTINCT  ");
        selSQL.append(" t11.before_name,t11.after_name,t11.type,t11.is_hot, t11.module, ");
        selSQL.append(" t11.`name` ,t11.memorize,t11.understanding,t11.apply,t11.duration,t11.id ,  \n");
        selSQL.append(" t11.jxmb,t11.zdbx,t11.ydsl, t11.num  ");
        selSQL.append("from   \n");
        selSQL.append("  zyb_know_how_details t11  ");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_id = t11.id  ");
        if(params.size()>0){
        	selSQL.append("where 1=1 \n");
        }
        if(params.get("EQ_courseName") != null && !params.get("EQ_courseName").equals("")){
        	selSQL.append("and s.course_name = ? \n");
        	queryParams.add(params.get("EQ_courseName"));
        }
        if(params.get("EQ_grade") != null && !params.get("EQ_grade").equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(params.get("EQ_grade"));
        }
        if(params.get("banben") != null && !params.get("banben").equals("")){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(params.get("banben"));
        }
        if(params.get("semester") != null && !params.get("semester").equals("")){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(params.get("semester"));
        }
        if(params.get("LIKE_name") != null && !params.get("LIKE_name").equals("")){
        	selSQL.append("and t11.name LIKE  CONCAT(CONCAT('%',?,'%'))  \n");
        	queryParams.add(params.get("LIKE_name"));
        }
        if(params.get("LIKE_module") != null && !params.get("LIKE_module").equals("")){
        	selSQL.append("and t11.module LIKE  CONCAT(CONCAT('%',?,'%'))  \n");
        	queryParams.add(params.get("LIKE_module"));
        }
        
        selSQL.append("order by s.course_name,t11.num    ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), sp);
	}



	@Override
	public List<Map<String, Object>> getHomeworkKnowModuleData(String vipId, String subject,  String beginTime, String endTime, int type) {
		StringBuilder sb = new StringBuilder ();
		sb.append("SELECT d.module, COUNT(DISTINCT(d.id)) as count  from zyb_student_work_how_details t  ")
			.append(" LEFT JOIN zyb_student_work w ON t.student_work_id=w.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("'")
			.append(" and t.create_time between '").append(beginTime).append("' and '").append(endTime).append("'");
		if (type > 0){
			sb.append(" and t.type=").append(type);
		}
		if (!StringUtil.isEmpty(vipId)){
			sb.append("  and w.vip_id='").append(vipId).append("'");
		}
		sb.append(" GROUP BY d.module");
		return  dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> getHomeworkKnowModuleDataV1(String vipId, String subject,  String beginTime, String endTime, int type) {
		StringBuilder sb = new StringBuilder ();
		sb.append("SELECT d.module, COUNT(DISTINCT(d.id)) as count  from zyb_student_work_how_details t  ")
				.append(" LEFT JOIN scon_homework w ON t.student_work_id=w.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("'")
				.append(" and t.create_time between '").append(beginTime).append("' and '").append(endTime).append("'");
		if (type > 0){
			sb.append(" and t.type=").append(type);
		}
		if (!StringUtil.isEmpty(vipId)){
			sb.append("  and w.vip_id='").append(vipId).append("'");
		}
		sb.append(" GROUP BY d.module");
		return  dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> getHomeworkKnowModuleDataWrongV1(String vipId, String subject,  String beginTime, String endTime, int type) {
		StringBuilder sb = new StringBuilder ();
		sb.append("SELECT t.module, COUNT(DISTINCT(t.id)) as count  from scon_homework_how_details t ")
				.append(" LEFT JOIN scon_homework w ON t.homework_id=w.id where w.subject='").append(subject).append("'")
				.append(" and w.create_time between '").append(beginTime).append("' and '").append(endTime).append("'");
		if (type > 0){
			sb.append(" and t.work_detail_type=").append(type);
		}
		if (!StringUtil.isEmpty(vipId)){
			sb.append("  and w.vip_id='").append(vipId).append("'");
		}
		sb.append(" GROUP BY t.module");
		return  dao.findMap(sb.toString(), null);
	}


	@Override
	public List<Map<String, Object>> getKnowPointGrasp(String vipId, String subject, String beginTime, String endTime, int type) {
		StringBuilder sb = new StringBuilder();
		sb.append("select count(t1.id) count,  t2.id, t2.name, t2.memorize, t2.understanding, t2.apply, t2.ydsl from zyb_student_work_how_details t1")
				.append(" left join zyb_know_how_details t2 on t1.how_details_id=t2.id left join zyb_know_how t3 on t2.how_id=t3.id")
				.append(" left join scon_homework t4 on t1.student_work_id=t4.id where t3.course_name='").append(subject)
				.append("' and t4.vip_id='").append(vipId).append("' and t4.create_time BETWEEN '").append(beginTime).append("' and '")
				.append(endTime).append("'");
		sb.append(" group by t2.id, t2.name, t2.memorize, t2.understanding, t2.apply, t2.ydsl");
		return dao.findMap(sb.toString(), null);
	}

	@Override
	public List<Map<String, Object>> getWrongKnowPointGrasp(String vipId, String subject, String beginTime, String endTime, int type) {
		StringBuilder sb = new StringBuilder();
		sb.append("select count(t1.id) count,  t2.id, t2.name, t2.memorize, t2.understanding, t2.apply, t2.ydsl from scon_homework_how_details t1")
				.append(" left join zyb_know_how_details t2 on t1.how_details_id=t2.id left join zyb_know_how t3 on t2.how_id=t3.id")
				.append(" left join scon_homework t4 on t1.homework_id=t4.id where t3.course_name='").append(subject)
				.append("' and t4.vip_id='").append(vipId).append("' and t4.create_time BETWEEN '").append(beginTime).append("' and '")
				.append(endTime).append("'");
		sb.append(" group by t2.id, t2.name, t2.memorize, t2.understanding, t2.apply, t2.ydsl");
		return dao.findMap(sb.toString(), null);
	}

	@Override
	public Page<Map<String, Object>> findWrongTopicDate(String vipId, String subject, boolean isCorrect, Pageable pageable) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select t.date, t.id work_id, min(t.file_key) picture from (")
				.append(" select distinct date(t1.create_time) date, t2.id, t4.file_key from zyb_student_work_img t1 left join zyb_student_work t2")
				.append(" on t1.object_id=t2.id  left join scon_work_image_revise t3 on t2.id=t3.work_id left join scon_homework_picture t4")
				.append(" on t2.id = t4.zyb_work_id where");
		if (isCorrect){
			sb.append(" t3.image_url is not null and");
		} else {
			sb.append(" t3.image_url is null and ");
		}
		sb.append(" t2.course_name='").append(subject).append("' and t2.vip_id='").append(vipId).append("'")
				.append(" ) t group by t.date, t.id order by t.date desc");
		return dao.findPage(sb.toString(), pageable);
	}

	@Override
	public List<ZuoybKnowHow> findlatestHow(String libId, String courseName,
			String grade, Integer banben, Integer semester,String howName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
	        
	        selSQL.append("SELECT t.`id`, t.`course_name`, t.`create_time`, t.`lib_id`,s.alias as  `name`, t.`num`, t.`module`, t.`is_zt` ");
	        selSQL.append("from  zyb_know_how t \n");
	        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_id = t.id  ");
	        selSQL.append("where t.lib_id = ? \n");
	        queryParams.add(libId);
	        int i=0;
	        if(courseName != null && !courseName.equals("")){
	        	selSQL.append("and t.course_name = ? \n");
	        	queryParams.add(courseName);
	        	
	        }
	        if(grade != null && !grade.equals("")){
	        	selSQL.append("and s.grade = ? \n");
	        	queryParams.add(grade);
	        	i++;
	        }
	        if(banben != null && banben>0){
	        	selSQL.append("and s.type = ? \n");
	        	queryParams.add(banben);
	        	
	        	i++;
	        }
	        if(semester != null && semester>0){
	        	selSQL.append("and s.semester = ? \n");
	        	queryParams.add(semester);
	        	
	        	i++;
	        }
	        if(howName != null && !howName.equals("")){
	        	selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
	        	queryParams.add(howName);
	        	queryParams.add(howName);
	        	i++;
	        }
	        
	        if(i>0){
	        	selSQL.append("and s.stat =1 \n");
	        }
	        selSQL.append(" GROUP BY t.id   ");
	        selSQL.append("order by t.course_name,t.num ,t.create_time , t.id ,s.num ");
		return dao.findList(selSQL.toString(), queryParams.toArray(), ZuoybKnowHow.class);
	}

	@Override
	public List<ZuoybKnowHowDetails> findlatestHowDetails(String libId,
			String howId, String courseName, String grade, Integer banben,
			Integer semester, String howDetailsName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        
        selSQL.append("SELECT t.`id`, t.`how_id`, t.`create_time`, t.`lib_id`, s.alias as  `name`, t.`num`, t.`before_name`, ");
        selSQL.append("t.`after_name`, t.`type`, t.`is_hot`, t.`memorize`, t.`understanding`,  ");
        selSQL.append("t.`apply`, t.`duration`, t.`two_module`, t.`module`, t.`jxmb`, t.`zdbx`, t.`ydsl`, t.`img`, t.`is_zt` ");
        selSQL.append("from  zyb_know_how_details t \n");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_id = t.id  ");
        selSQL.append("where t.lib_id = ? \n");
        queryParams.add(libId);
        if(howId != null && !howId.equals("")){
        	selSQL.append(" and t.how_id  =?  \n");
        	queryParams.add(howId);
        }
        int i=0;
        if(howDetailsName != null && !howDetailsName.equals("")){
        	selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
        	queryParams.add(howDetailsName);
        	queryParams.add(howDetailsName);
        	i++;
        }
        if(courseName != null && !courseName.equals("")){
        	selSQL.append("and t.course_name = ? \n");
        	queryParams.add(courseName);
        	
        }
        if(grade != null && !grade.equals("")){
        	selSQL.append("and s.grade = ? \n");
        	queryParams.add(grade);
        	i++;
        }
        if(banben != null && banben>0){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(banben);
        	
        	i++;
        }
        if(semester != null && semester>0){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(semester);
        	
        	i++;
        }
        if(i>0){
        	selSQL.append("and s.stat=2 \n");
        }
        selSQL.append(" GROUP BY t.id   ");
        selSQL.append("order by t.num ,t.create_time,s.num  ");
        
		return dao.findList(selSQL.toString(), queryParams.toArray(), ZuoybKnowHowDetails.class);
	}

	@Override
	public List<ZuoybKnowHow> findlatestHowIds(String libId, String courseName,
			String grade, Integer banben, Integer semester, String howName,
			List<String> ids) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
	        
	        selSQL.append("SELECT t.`id`, t.`course_name`, t.`create_time`, t.`lib_id`,s.alias as  `name`, t.`num`, t.`module`, t.`is_zt` ");
	        selSQL.append("from  zyb_know_how t \n");
	        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_id = t.id  ");
	        selSQL.append("where t.lib_id = ? \n");
	        queryParams.add(libId);
	        int i=0;
	        if(courseName != null && !courseName.equals("")){
	        	selSQL.append("and t.course_name = ? \n");
	        	queryParams.add(courseName);
	        	
	        }
	        if(ids.size()>0){
	        	selSQL.append(" and t.id  in ( ");
	        	for (int j = 0; i < ids.size(); j++) {
	        		selSQL.append(" ? ");
	        		if(ids.size()-1>j){
	        			selSQL.append(" , ");
	        		}
	            	queryParams.add(ids.get(j));
				}
	        	selSQL.append(" ) ");
	        }
	        if(grade != null && !grade.equals("")){
	        	selSQL.append("and s.grade = ? \n");
	        	queryParams.add(grade);
	        	i++;
	        }
	        if(banben != null && banben>0){
	        	selSQL.append("and s.type = ? \n");
	        	queryParams.add(banben);
	        	
	        	i++;
	        }
	        if(semester != null && semester>0){
	        	selSQL.append("and s.semester = ? \n");
	        	queryParams.add(semester);
	        	
	        	i++;
	        }
	        if(howName != null && !howName.equals("")){
	        	selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
	        	queryParams.add(howName);
	        	queryParams.add(howName);
	        	i++;
	        }
	        
	        if(i>0){
	        	selSQL.append("and s.stat =1 \n");
	        }
	        selSQL.append(" GROUP BY t.id   ");
	        selSQL.append("order by t.course_name,t.num ,t.create_time , t.id ,s.num ");
		return dao.findList(selSQL.toString(), queryParams.toArray(), ZuoybKnowHow.class);
	}

	@Override
	public List<Map<String, Object>> getKonwVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        
        selSQL.append("SELECT t.`id`, t.`course_name`, date_format(t.create_time,'%Y-%m-%d %H:%i') as  `create_time` , t.`lib_id`,s.alias as  `name`, t.`num`, t.`module`, t.`is_zt`  ");
        selSQL.append(" ,s.id as s_id ,s.type as s_type,s.grade ,s.grade_num ,s.semester,s.num as s_num ,s.alias ,date_format(s.create_time,'%Y-%m-%d %H:%i')  as s_create_time ");
        selSQL.append("from  zyb_know_how t \n");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_id = t.id  and s.stat =1 ");
        selSQL.append("where t.lib_id = ? \n");
        queryParams.add(libId);
        int j=0;
        if(courseName != null && !courseName.equals("")){
        	selSQL.append("and t.course_name = ? \n");
        	queryParams.add(courseName);
        	
        }
        if(grade != null && !grade.equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(grade);
        }
        if(banben != null && banben>0){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(banben);
        	j++;
        	
        }
        if(semester != null && semester>0){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(semester);
        }
        if(howName != null && !howName.equals("")){
        	selSQL.append("and  ( t.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
        	queryParams.add(howName);
        	queryParams.add(howName);
        }
        if(j>0){
        	selSQL.append("order by t.course_name,s.num ,t.create_time , t.num ");
        }else{
        	selSQL.append("order by t.course_name,t.num ,t.create_time , s.num ");
        	
        }
        
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getKonwDetailVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howDetailsName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		int j =0;
		if(banben != null && banben>0){
			j++;
		}
		selSQL.append(" SELECT t.course_name,t.id, ");
		if(j==0){
			selSQL.append("t.`name`,t.num,t.module, date_format(t.`create_time`,'%Y-%m-%d %H:%i') as  t_create_time, ");
		}else{
			selSQL.append(" s1.alias as `name`,s1.num,s1.module, date_format(s1.`create_time`,'%Y-%m-%d %H:%i') as  t_create_time, ");
		}

        selSQL.append(" t11.before_name,t11.after_name,t11.type,t11.is_hot, t11.module as t11_module, t11.img,");
        selSQL.append(" t11.`name` as detail_name,t11.memorize,t11.understanding,t11.apply,t11.duration,t11.id as detail_id,t11.two_module, t11.attr_type ,   \n");
        selSQL.append(" t11.jxmb,t11.zdbx,t11.ydsl, t11.num as detail_num ,date_format(t11.`create_time`,'%Y-%m-%d %H:%i') as  detail_create_time, ");
        selSQL.append(" s.id as s_id ,s.semester,s.type as s_type,s.grade,s.num as s_num,s.grade_num ,s.alias ,date_format(s.`create_time`,'%Y-%m-%d %H:%i') as  s_create_time , ");

		selSQL.append(" s.jxmb as s_jxmb,s.zdbx as s_zdbx,s.ydsl as s_ydsl,s.module as s_module ,s.two_module as s_two_module,s.memorize as s_memorize ,s.understanding as s_understanding ,s.apply as s_apply ,s.attr_type as s_attr_type ");
        selSQL.append("from   zyb_know_how_details t11 \n");
        selSQL.append("left join zyb_know_how t on t.id = t11.how_id\n");
        selSQL.append(" JOIN zyb_know_how_details_sort s on s.how_details_id = t11.id  and s.stat =2 ");
		if(j>0){
			selSQL.append("   JOIN zyb_know_how_details_sort s1 on s1.how_id = t.id  and s1.stat =1    ");
		}
        selSQL.append("where t11.lib_id = ? \n");
        queryParams.add(libId);

        if(howDetailsName != null && !howDetailsName.equals("")){
        	selSQL.append("and  ( t11.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
        	queryParams.add(howDetailsName);
        	queryParams.add(howDetailsName);
        }
        if(courseName != null && !courseName.equals("")){
        	selSQL.append("and s.course_name = ? \n");
        	queryParams.add(courseName);
        	
        }
        if(grade != null && !grade.equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(grade);
        }
        if(banben != null && banben>0){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(banben);
			selSQL.append("and s1.type = ? \n");
			queryParams.add(banben);
        	j++;
        }
        if(semester != null && semester>0){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(semester);
        }
        if(j==0){
        	selSQL.append("order by t.course_name,t.num ,t.create_time , t.id,t11.num ,t11.id   ");
        }else{
        	selSQL.append("order by t.course_name,s1.num ,t.create_time , t.id,s.num ,t11.num   ");
        }
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<Map<String, Object>> getKonwDetailKdVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howDetailsKdName) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
		int j=0;
		if(banben != null && banben>0){
			j++;
		}
		selSQL.append("SELECT t.course_name,  t.id, ");
		if(j>0){
			selSQL.append(" s1.alias as `name`,s1.num,s1.module, date_format(s1.`create_time`,'%Y-%m-%d %H:%i') as  t_create_time, ");
			selSQL.append(" s2.alias as detail_name,t11.memorize,t11.understanding,t11.apply,t11.duration,t11.id as detail_id,s2.two_module,  ");
			selSQL.append(" s2.jxmb,s2.zdbx,s2.ydsl, s2.num as detail_num ,date_format(s2.`create_time`,'%Y-%m-%d %H:%i') as  detail_create_time,  ");

		}else{
			selSQL.append(" t.`name`,t.num,t.module, date_format(t.`create_time`,'%Y-%m-%d %H:%i') as  t_create_time,  ");

			selSQL.append(" t11.before_name,t11.after_name,t11.type,t11.is_hot, t11.module as t11_module, t11.img,");
			selSQL.append(" t11.`name` as detail_name,t11.memorize,t11.understanding,t11.apply,t11.duration,t11.id as detail_id,t11.two_module,  ");
			selSQL.append(" t11.jxmb,t11.zdbx,t11.ydsl, t11.num as detail_num ,date_format(t11.`create_time`,'%Y-%m-%d %H:%i') as  detail_create_time,  ");
		}




        selSQL.append(" s.id as s_id ,s.semester,s.type as s_type,s.grade,s.num as s_num,s.grade_num ,s.alias , date_format(s.`create_time`,'%Y-%m-%d %H:%i') as  s_create_time , ");
        selSQL.append(" d.id as d_id ,d.`name` as d_name ,d.num as d_num ,d.ydsl as d_ydsl ,d.img as d_img ,d.label as d_label,     d.`level` as d_level ,date_format(d.`create_time`,'%Y-%m-%d %H:%i') as  d_create_time  ");
        selSQL.append("from   zyb_know_how_details_kd  d  JOIN  zyb_know_how_details t11   on d.how_details_id = t11.id   ");
        selSQL.append("left join zyb_know_how t on t.id = t11.how_id  ");
        selSQL.append("LEFT JOIN zyb_know_how_details_sort s on s.how_details_kd_id = d.id   and s.stat =3 ");

        if(j>0){
			selSQL.append("   JOIN zyb_know_how_details_sort s1 on s1.how_id = t.id  and s1.stat =1    ");
			selSQL.append("   JOIN zyb_know_how_details_sort s2 on s2.how_details_id = t11.id  and s2.stat =2    ");
		}
        selSQL.append("where t11.lib_id = ?  ");
        queryParams.add(libId);

        if(howDetailsKdName != null && !howDetailsKdName.equals("")){
        	selSQL.append("and  ( d.name  LIKE  CONCAT(CONCAT('%',?,'%'))  or  s.alias  LIKE  CONCAT(CONCAT('%',?,'%'))  ) \n");
        	queryParams.add(howDetailsKdName);
        	queryParams.add(howDetailsKdName);
        }
        if(courseName != null && !courseName.equals("")){
        	selSQL.append("and s.course_name = ? \n");
        	queryParams.add(courseName);
        	
        }
        if(grade != null && !grade.equals("")){
        	selSQL.append("and s.grade_num = ? \n");
        	queryParams.add(grade);
        }
        if(banben != null && banben>0){
        	selSQL.append("and s.type = ? \n");
        	queryParams.add(banben);
			selSQL.append("and s1.type = ? \n");
			queryParams.add(banben);
			selSQL.append("and s2.type = ? \n");
			queryParams.add(banben);
        	j++;
        }
        if(semester != null && semester>0){
        	selSQL.append("and s.semester = ? \n");
        	queryParams.add(semester);
        }
        if(j>0){
        	
        	selSQL.append("order by t.course_name,s1.num ,t.create_time , t.id,s2.num ,t11.id ,d.num ,d.create_time ,s.num  ");
        }else{
        	selSQL.append("order by t.course_name,t.num ,t.create_time , t.id,t11.num ,t11.id ,s.num ,d.create_time ,d.num  ");
        }
        return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public List<KnowHowDTO> findHowListWithDetailsByCondition(KnowledgeRequest request) {
		StringBuilder sql = new StringBuilder();
		List<Object> params = new ArrayList<>();

		sql.append("select t1.how_id         know_how_id, ");
		sql.append("       if(t3.is_zt = 1, concat('专题：', t1.alias), t1.alias)          know_how_name, ");
		sql.append("       t2.how_details_id know_how_details_id, ");
		sql.append("       t2.alias          know_how_details_name, ");
		sql.append("       t4.how_details_kd_id how_details_kd_id, ");
		sql.append("       t4.alias know_how_details_kd_name ");
		sql.append("from zyb_know_how_details_sort t1 ");
		sql.append("       left join zyb_know_how_details_sort t2 on t1.how_id = t2.how_id  and t2.stat = 2 ");
		sql.append("       and t2.grade = ? ");
		sql.append("       and t2.course_name = ? ");
		sql.append("       and t2.type = ? ");
		sql.append("       and t2.semester = ? ");
		sql.append("       and t2.lib_id = 'SSJ' ");
		sql.append("       join zyb_know_how_details t3 on t2.how_details_id = t3.id ");
		//与前端定义不一致,减一解决，笑脸
		boolean isNeedZtCondition = false;
		Integer type = request.getModuleType();
		if (!request.getSubject().equals("数学")){
			if(request.getModuleType() != null){
				isNeedZtCondition = true;
				sql.append("  and t3.is_zt = ? ");
				if (type != null && type > 0){
					type = type - 1;
				}
			}
		}
		sql.append("       left join zyb_know_how_details_sort t4 on t2.how_details_id = t4.how_details_id and t4.stat = 3 ");
		sql.append("  	   and t4.grade = ? ");
		sql.append("  	   and t4.course_name = ? ");
		sql.append("  	   and t4.type = ? ");
		sql.append("  	   and t4.semester = ? ");
		sql.append("  	   and t4.lib_id = 'SSJ' ");
		sql.append("where t1.stat = 1 ");
		sql.append("  and t1.grade = ? ");
		sql.append("  and t1.course_name = ? ");
		sql.append("  and t1.type = ? ");
		sql.append("  and t1.semester = ? ");
		sql.append("  and t1.lib_id = 'SSJ' ");

		params.add(request.getGrade());
		params.add(request.getSubject());
		params.add(request.getVersionType());
		params.add(request.getSemester());
		if (isNeedZtCondition) {
			params.add(type);
		}
		params.add(request.getGrade());
		params.add(request.getSubject());
		params.add(request.getVersionType());
		params.add(request.getSemester());
		params.add(request.getGrade());
		params.add(request.getSubject());
		params.add(request.getVersionType());
		params.add(request.getSemester());
		String searchKey = request.getSearchKey();
		sql.append(" order by");

		if (StringUtils.isNotBlank(searchKey)) {
			sql.append(" if(t1.alias REGEXP ? or t2.alias REGEXP ?, 0, 1), ");
			params.add(request.getSearchKey());
			params.add(request.getSearchKey());
		}
		sql.append(" t3.is_zt, t1.num, t1.create_time, t2.num, t3.num, t4.num ");

		List<Map<String, Object>> mapList = dao.findMap(sql.toString(), params.toArray());
		Map<String, List<Map<String, Object>>> knwHowMap = mapList.stream().collect(Collectors.groupingBy(temp -> String.valueOf(temp.get("know_how_id")), LinkedHashMap::new, Collectors.toList()));
		List<KnowHowDTO> knowHowDTOList = new ArrayList<>(knwHowMap.size());
		knwHowMap.forEach((knowHowId, value) -> {
			KnowHowDTO knowHowDTO = new KnowHowDTO();
			knowHowDTO.setId(knowHowId);
			knowHowDTO.setName(String.valueOf(value.get(0).get("know_how_name")));

			LinkedHashMap<String, List<Map<String, Object>>> knowHowDetailsMap = value.stream().collect(Collectors.groupingBy(temp -> String.valueOf(temp.get("know_how_details_id")), LinkedHashMap::new, Collectors.toList()));
			List<KnowHowDetailsDTO> knowHowDetailsDTOList = new ArrayList<>(value.size());
			knowHowDetailsMap.forEach((knowHowDetailId, value2) -> {
				if (knowHowDetailId != null) {
					KnowHowDetailsDTO knowHowDetailsDTO = new KnowHowDetailsDTO();
					knowHowDetailsDTO.setId(knowHowDetailId);
					knowHowDetailsDTO.setName(String.valueOf(value2.get(0).get("know_how_details_name")));

					List<TestPointDTO> testPointDTOList = new ArrayList<>();
					value2.forEach(temp4kd -> {
						Object howDetailsKdId = temp4kd.get("how_details_kd_id");
						if (howDetailsKdId != null) {
							TestPointDTO testPointDTO = new TestPointDTO();
							testPointDTO.setId(String.valueOf(howDetailsKdId));
							testPointDTO.setName(String.valueOf(temp4kd.get("know_how_details_kd_name")));

							testPointDTOList.add(testPointDTO);
						}
					});
					knowHowDetailsDTO.setPoints(testPointDTOList);
					knowHowDetailsDTOList.add(knowHowDetailsDTO);
				}
			});

			knowHowDTO.setDetails(knowHowDetailsDTOList);
			knowHowDTOList.add(knowHowDTO);
		});

		return knowHowDTOList;
	}

	@Override
	public List<KnowHowDetailsDTO> findDetailsListWithKd(List<String> detailIdList, Integer versionType) {
		StringBuilder detailId = new StringBuilder();
		detailIdList.forEach(it -> detailId.append("'").append(it).append("',"));
		detailId.deleteCharAt(detailId.length() - 1);

		StringBuilder sb = new StringBuilder();
		sb.append(" select kd.how_details_kd_id kd_id, kd.alias kd_name, detail.how_details_id detail_id, detail.alias detail_name from zyb_know_how_details_sort detail")
				.append(" left join zyb_know_how_details_sort kd on kd.how_details_id=detail.how_details_id and kd.stat=3 and kd.type=?")
				.append(" where detail.type=? and detail.stat=2 and detail.how_details_id in (").append(detailId.toString()).append(")");
		List<Object> params = new ArrayList<>();
		params.add(versionType);
		params.add(versionType);

		List<Map<String, Object>> mapList = dao.findMap(sb.toString(), params.toArray());
		Map<String, List<Map<String, Object>>> listMap = mapList.stream().collect(Collectors.groupingBy(temp -> String.valueOf(temp.get("detail_id")), LinkedHashMap::new, Collectors.toList()));
		List<KnowHowDetailsDTO> knowHowDetailsDTOList = new ArrayList<>(listMap.size());
		listMap.forEach((key, value) -> {
			KnowHowDetailsDTO knowHowDetailsDTO = new KnowHowDetailsDTO();
			knowHowDetailsDTO.setId(key);
			knowHowDetailsDTO.setName(String.valueOf(value.get(0).get("detail_name")));

			List<TestPointDTO> testPointDTOList = new ArrayList<>(value.size());
			value.forEach(map -> {
				if (StringUtils.isNotBlank((String)map.get("kd_id"))){
					TestPointDTO testPointDTO = new TestPointDTO();
					testPointDTO.setId(String.valueOf(map.get("kd_id")));
					testPointDTO.setName(String.valueOf(map.get("kd_name")));
					testPointDTOList.add(testPointDTO);
				}
			});

			knowHowDetailsDTO.setPoints(testPointDTOList);
			knowHowDetailsDTOList.add(knowHowDetailsDTO);
		});

		return knowHowDetailsDTOList;
	}

	@Override
	public List<KnowHowDetailsDTO> findDetailsListWithKd(List<String> detailIdList, int versionType, String grade, String subject, int semester) {
		StringBuilder detailId = new StringBuilder();
		detailIdList.forEach(it -> detailId.append("'").append(it).append("',"));
		detailId.deleteCharAt(detailId.length() - 1);

		StringBuilder sb = new StringBuilder();
		sb.append(" select kd.how_details_kd_id kd_id, kd.alias kd_name, detail.how_details_id detail_id, detail.alias detail_name from zyb_know_how_details_sort detail")
				.append(" left join zyb_know_how_details_sort kd on kd.how_details_id=detail.how_details_id and kd.stat=3 and kd.type=? and kd.semester=? and kd.grade=? and kd.course_name=?")
				.append(" where detail.type=? and detail.stat=2 and detail.semester=? and detail.grade=? and detail.course_name=? and detail.how_details_id in (").append(detailId.toString()).append(")");
		List<Object> params = new ArrayList<>();
		params.add(versionType);
		params.add(semester);
		params.add(grade);
		params.add(subject);
		params.add(versionType);
		params.add(semester);
		params.add(grade);
		params.add(subject);

		List<Map<String, Object>> mapList = dao.findMap(sb.toString(), params.toArray());
		Map<String, List<Map<String, Object>>> listMap = mapList.stream().collect(Collectors.groupingBy(temp -> String.valueOf(temp.get("detail_id")), LinkedHashMap::new, Collectors.toList()));
		List<KnowHowDetailsDTO> knowHowDetailsDTOList = new ArrayList<>(listMap.size());
		listMap.forEach((key, value) -> {
			KnowHowDetailsDTO knowHowDetailsDTO = new KnowHowDetailsDTO();
			knowHowDetailsDTO.setId(key);
			knowHowDetailsDTO.setName(String.valueOf(value.get(0).get("detail_name")));

			List<TestPointDTO> testPointDTOList = new ArrayList<>(value.size());
			value.forEach(map -> {
				if (StringUtils.isNotBlank((String)map.get("kd_id"))){
					TestPointDTO testPointDTO = new TestPointDTO();
					testPointDTO.setId(String.valueOf(map.get("kd_id")));
					testPointDTO.setName(String.valueOf(map.get("kd_name")));
					testPointDTOList.add(testPointDTO);
				}
			});

			knowHowDetailsDTO.setPoints(testPointDTOList);
			knowHowDetailsDTOList.add(knowHowDetailsDTO);
		});

		return knowHowDetailsDTOList;
	}

	@Override
	public Page<Map<String, Object>> getZuoybKnowSort(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT  s.*, ");
	        selSQL.append(" ( select t.alias  from  zyb_know_how_details_sort t where   s.how_id =t.how_id     ");
	        selSQL.append("  and s.type = t.type  and  t.stat =1   limit 1   ");
	        selSQL.append("  ) as howname  ");
	        selSQL.append(" FROM  ");
	        selSQL.append(" zyb_know_how_details_sort  s ");
	        selSQL.append(" where s.how_details_id = ?  and  lib_id =? AND s.stat = 2  ");
	        queryParams.add(searchParams.get("EQ_howDetailsId"));
	       // queryParams.add(searchParams.get("EQ_howId"));
	        queryParams.add(searchParams.get("EQ_libId"));
	        if (searchParams.get("LIKE_alias") != null && !searchParams.get("LIKE_alias").equals("")) {
	        	selSQL.append(" and   s.alias LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("LIKE_alias"));
	        }
		if (searchParams.get("LIKE_id") != null && !searchParams.get("LIKE_id").equals("")) {
			selSQL.append(" and  s.id =? ");
			queryParams.add(searchParams.get("LIKE_id"));
		}
	        if (searchParams.get("EQ_grade") != null && !searchParams.get("EQ_grade").equals("")) {
	        	selSQL.append(" and   s.grade_num =? ");
	        	queryParams.add(searchParams.get("EQ_grade"));
	        }
	        if (searchParams.get("EQ_semester") != null && !searchParams.get("EQ_semester").equals("")) {
	        	selSQL.append(" and   s.semester =? ");
	        	queryParams.add(searchParams.get("EQ_semester"));
	        }
	        if (searchParams.get("EQ_banben") != null && !searchParams.get("EQ_banben").equals("")) {
	        	selSQL.append(" and   s.type =? ");
	        	queryParams.add(searchParams.get("EQ_banben"));
	        }
	        selSQL.append(" ORDER BY s.grade_num asc ,s.semester asc, s.num  asc  , s.create_time asc ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}
	@Override
	public Page<Map<String, Object>> getZuoybKnowKdSort(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT  s.*, ");
		selSQL.append(" ( select t.alias  from  zyb_know_how_details_sort t where   s.how_id =t.how_id     ");
		selSQL.append("  and s.type = t.type  and  t.stat =1  limit 1  ");
		selSQL.append("  ) as howname ,  ");
		selSQL.append(" ( select t.alias  from  zyb_know_how_details_sort t where   s.how_details_id =t.how_details_id     ");
		selSQL.append("  and s.type = t.type  and  t.stat =2  limit 1   ");
		selSQL.append("  ) as howdetilasname,  ");
		selSQL.append(" ( select t.alias  from  zyb_know_how_details_sort t where   s.before_how_details_kd_id =t.id     ");
		selSQL.append("    ");
		selSQL.append("  ) as beforekdname  ");
		selSQL.append(" FROM  ");
		selSQL.append(" zyb_know_how_details_sort  s ");
		selSQL.append(" where   lib_id =? AND s.stat = 3  ");
		queryParams.add(searchParams.get("EQ_libId"));
		if (searchParams.get("LIKE_id") != null && !searchParams.get("LIKE_id").equals("")) {
			selSQL.append(" and   s.id = ? ");
			queryParams.add(searchParams.get("LIKE_id"));
		}
		if (searchParams.get("EQ_howDetailsKdId") != null && !searchParams.get("EQ_howDetailsKdId").equals("")) {
			selSQL.append(" and   s.how_details_kd_id = ? ");
			queryParams.add(searchParams.get("EQ_howDetailsKdId"));
		}
		if (searchParams.get("LIKE_alias") != null && !searchParams.get("LIKE_alias").equals("")) {
			selSQL.append(" and   s.alias LIKE  CONCAT(CONCAT('%',?,'%')) ");
			queryParams.add(searchParams.get("LIKE_alias"));
		}
		if (searchParams.get("EQ_grade") != null && !searchParams.get("EQ_grade").equals("")) {
			selSQL.append(" and   s.grade_num =? ");
			queryParams.add(searchParams.get("EQ_grade"));
		}
		if (searchParams.get("EQ_semester") != null && !searchParams.get("EQ_semester").equals("")) {
			selSQL.append(" and   s.semester =? ");
			queryParams.add(searchParams.get("EQ_semester"));
		}
		if(searchParams.get("EQ_courseName") != null && !searchParams.get("EQ_courseName").equals("")){
			selSQL.append("and s.course_name = ? \n");
			queryParams.add(searchParams.get("EQ_courseName"));
		}
		if (searchParams.get("EQ_banben") != null && !searchParams.get("EQ_banben").equals("")) {
			selSQL.append(" and   s.type =? ");
			queryParams.add(searchParams.get("EQ_banben"));
		}
		selSQL.append(" ORDER BY s.grade_num asc ,s.semester asc,  s.num  asc  , s.create_time asc ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<TestPointDTO> findPointsByDetailId(String detailId, int versionType, String grade, int semester) {
		StringBuilder sb = new StringBuilder();
		sb.append("select how_details_kd_id id, alias name from zyb_know_how_details_sort where how_details_id=? and stat=3 and type=? and grade=? and semester=? order by num");
		List<Object> params = new ArrayList<>();
		params.add(detailId);
		params.add(versionType);
		params.add(grade);
		params.add(semester);
		return dao.findList(sb.toString(), params.toArray(), TestPointDTO.class);
	}

	@Override
	public Page<Map<String,Object>> findByVipID(String vipId, Pageable pageable){
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<>();
		selSQL.append("select\n" +
				"  push_time,\n" +
				"  type,\n" +
				"  vip_id,\n" +
				"  suggest,\n" +
				"  submit_time\n" +
				"from zyb_student_push\n" +
				"where type in (2, 5, 6) and vip_id = ? and exists(select 1\n" +
				"                             from scon_homework_picture\n" +
				"                             where scon_homework_picture.vip_id =\n" +
				"                                   zyb_student_push.vip_id\n" +
				"                                   and is_delete = 0\n" +
				"                                   and to_days(create_time) = to_days(push_time))\n" +
				"order by push_time desc");
		queryParams.add(vipId);
		return dao.findPage(selSQL.toString(),queryParams.toArray(),pageable);

	}

    @Override
    public List<Map<String, Object>> findAllLib(Map map) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        MapGetterTool mapGetterTool = new MapGetterTool(map);
        String cityName = mapGetterTool.getString("cityName");
        String libName = mapGetterTool.getString("libName");
        selSQL.append("select  distinct league_city from tb_lib_join where league_city!='' and league_city is not null ");
        if (StringUtil.isNotBlank(cityName)) {
            selSQL.append(" and league_name regexp ? ");
            queryParams.add(cityName);
        }
        if (StringUtil.isNotBlank(libName)) {
            selSQL.append(" and league_name regexp ? ");
            queryParams.add(libName);
        }
        return dao.findMap(selSQL.toString(), queryParams.toArray());
    }

	@Override
    public List<TbLibJoin> findAllCity(Map map) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        MapGetterTool mapGetterTool = new MapGetterTool(map);
        String city = mapGetterTool.getString("city");
        String cityName = mapGetterTool.getString("cityName");
        String libName = mapGetterTool.getString("libName");
        selSQL.append("select * from tb_lib_join where 1=1  ");
        if (StringUtil.isNotBlank(city)) {
            selSQL.append(" and league_city regexp ? ");
            queryParams.add(city);
        }
        if (StringUtil.isNotBlank(cityName)) {
            selSQL.append(" and league_name regexp ? ");
            queryParams.add(cityName);
        }
        if (StringUtil.isNotBlank(libName)) {
            selSQL.append(" and league_name regexp ? ");
            queryParams.add(libName);
        }
        return dao.findList(selSQL.toString(), queryParams.toArray(), TbLibJoin.class);
    }
}