package com.ssj.dao.kmt.correctsys.impl;
import com.ssj.dao.kmt.correctsys.CorrectSysQueryDao;
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.correctsys.dto.HomeworkCheckDto;
import com.ssj.service.kmt.correctsys.dto.HomeworkCheckKnowDetailDto;
import com.ssj.service.kmt.correctsys.dto.HomeworkExerciseQuestionsDto;

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.text.SimpleDateFormat;
import java.util.*;


/**
 * @author Mount Liu
 * @date 2019/5/20
 */
@Repository
public class CorrectSysQueryDaoImpl implements CorrectSysQueryDao {

    final static String SUPER_MANAGER = "superManager";

    @Autowired
    private PagingHibernateJdbcDao dao;

    /*@Override
    public Page<Map<String, Object>> findTeacherByPage(Map<String, Object> searchParams, Pageable pageable, int type) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(searchParams);
        int timeType=map.getInteger("timeType");
        sql.append(" SELECT  a.*  from ( ");

        sql.append("select  t.*");
        sql.append(" from tb_lib_manager t");
        sql.append(" left join scon_homework_picture t1");
        if(type==13){
            sql.append(" on t.user_id=t1.know_teacher_id");
        }else {
            sql.append(" on t.user_id=t1.teacher_id");
        }
        sql.append(" where 1 = 1");
        sql.append(" and t.state = 1");

        String role = map.getString("role");
        if(type == 13){
            //匹配知识点老师不包含校区管理员
            sql.append(" and t.type = 13\n");
        }else{
            //超级管理员只显示在线批改老师，不显示校区管理员
            if(StringUtil.isNotBlank(role) && SUPER_MANAGER.equals(role)){
                sql.append(" and t.type =8\n");
            }else{
                sql.append(" and t.type in (8, 11)\n");
            }
        }

        String maxCreateTime = map.getString("maxCreateTime");
        if (StringUtil.isNotBlank(maxCreateTime))  {
            sql.append(" and t.create_time <= ? ");
            queryParams.add(maxCreateTime);
        }
        String parentId = map.getString("parentId");
        if (StringUtil.isNotBlank(parentId)) {
            sql.append(" and (t.parent_id = ? or t.user_id=?) ");
            queryParams.add(parentId);
            queryParams.add(parentId);
        }
        String grade = map.getString("grade");
        if (StringUtil.isNotBlank(grade)) {
            sql.append(" and t.grade regexp ? ");
            queryParams.add(grade);
        }
        String subject = map.getString("subject");
        if (StringUtil.isNotBlank(subject)) {
            sql.append(" and t.course_name regexp ? ");
            queryParams.add(subject);
        }
        String teacherName = map.getString("teacherName");
        if (StringUtil.isNotBlank(teacherName)) {
            sql.append(" and t.name regexp ? ");
            queryParams.add(teacherName);
        }
        String date=map.getString("date");
        if(0!=timeType){
            sql.append(" and t1.create_time regexp ?");
            queryParams.add(date);
        }
        sql.append(" order by t.type desc,t.is_online desc,t.login_time desc,t.is_banned ");
        sql.append(" ) a  GROUP BY  a.id  order by a.type desc,a.is_online desc,a.login_time,a.is_banned");
        return dao.findPage(sql.toString(), queryParams.toArray(), pageable);
    }*/

    /*@Override
    public Page<Map<String, Object>> findTeacherBySubjectAndPage(Map<String, Object> params, Pageable pageable, int type) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(params);
        sql.append("select t.* from (");
        sql.append(this.findTeacherBySubjectPublic("语文", type));
        sql.append(" union all ");
        sql.append(this.findTeacherBySubjectPublic("数学", type));
        sql.append(" union all ");
        sql.append(this.findTeacherBySubjectPublic("英语", type));
        sql.append(" ) t ");
        sql.append(" where 1=1 ");
        //获取所在天或月的数据
        for (int i = 0; i <21; i++) {
            queryParams.add(params.get("date"));
        }
        String maxCreateTime = map.getString("maxCreateTime");
        if (StringUtil.isNotBlank(maxCreateTime)) {
            sql.append(" and t.create_time <= ? ");
            queryParams.add(maxCreateTime);
        }
        //条件:年级
        String grade = map.getString("grade");
        if (StringUtil.isNotBlank(grade)) {
            sql.append(" and t.grade regexp ? ");
            queryParams.add(grade);
        }
        //条件:科目
        String subject = map.getString("subject");
        if (StringUtil.isNotBlank(subject)) {
            sql.append(" and t.subject = ? ");
            queryParams.add(subject);
        }
        //条件:老师
        String teacherName = map.getString("teacherName");
        if (StringUtil.isNotBlank(teacherName)) {
            sql.append(" and t.name regexp ? ");
            queryParams.add(teacherName);
        }
        //校区管理员下的老师
        String parentId = map.getString("parentId");
        //角色
        String role = map.getString("role");
        //如果是匹配知识点老师，则不分角色区分
        if (type == 13) {
            sql.append(" and t.type =13\n");
            sql.append(" and t.parent_id =?\n");
            queryParams.add(parentId);
        } else {
            //超级管理员只显示在线批改老师，不显示校区管理员
            if (StringUtil.isNotBlank(role) && SUPER_MANAGER.equals(role)) {
                sql.append(" and t.type =8\n");
                sql.append(" and t.parent_id =?\n");
                queryParams.add(parentId);
            } else {
                sql.append(" and t.type in (8, 11)\n");
                sql.append(" and (t.parent_id =? or t.user_id=?)\n ");
                queryParams.add(parentId);
                queryParams.add(parentId);
            }
        }
        sql.append(" order by t.wrong_count desc,t.name,t.subject");
        return dao.findPage(sql.toString(), queryParams.toArray(), pageable);
    }*/

    /*private String findTeacherBySubjectPublic(String subject, int type) {
        String sql = "select t.*,\n" +
        "       '??' subject,\n" +
                "       (select count(1) from scon_homework_picture where subject = '??' and teacher_id = t.user_id replace2 and create_time regexp ?) homework_pic_count,\n" +
                "       (select count(distinct homework_id) from scon_homework_picture where subject regexp '??' and teacher_id = t.user_id replace2 and create_time regexp ?) homework_count,\n" +
                "       (select count(1) from scon_homework_picture s1 left join scon_homework_picture_correct s2 on s1.id=s2.homework_picture_id where s2.type = replace1 and s1.subject regexp '??' and s1.teacher_id = t.user_id and ((s1.is_feedback=1 and is_mark in(0,2)) or(s1.is_feedback=0 and is_mark in(1,3))) and s1.create_time regexp ? ) pic_total_count,\n" +
                "       (select count(1) from scon_homework_picture s1 left join scon_homework_picture_correct s2 on s1.id=s2.homework_picture_id where s2.type = replace1 and s1.subject regexp '??' and s1.teacher_id = t.user_id and s2.is_check_error=1 and s2.check_date regexp ? ) wrong_count,\n" +
                "       (select count(1) from scon_homework_picture s1 left join scon_homework_picture_correct s2 on s1.id=s2.homework_picture_id where s2.type = replace1 and s1.subject regexp '??' and s1.teacher_id = t.user_id and s2.is_check_error=1 and s2.create_time regexp ? ) today_wrong_count,\n" +
                "       (select sum(ifNull(s2.correct_nums,0)) from scon_homework_picture s1 left join scon_homework_picture_correct s2 on s1.id=s2.homework_picture_id where s2.type = replace1 and s1.subject regexp '??' and s1.teacher_id =t.user_id and s1.check_date regexp ?) correct_count,\n" +
                "       count(t1.id) attendance_count,\n" +
                "       ifnull(sum(t1.is_attendance),0) is_attendance_count\n" +
                "from tb_lib_manager t\n" +
                "left join (select * from tb_attendance where create_time regexp ?) t1 on t.user_id=t1.user_id\n" +
                "where t.state = 1 and t.course_name regexp '??'\n" +
                "group by t.id\n";
        sql = sql.replace("??", subject);
        sql = sql.replace("replace1", type + "");
        if (type == 13) {
            sql = sql.replace("teacher_id", "know_teacher_id");
            sql = sql.replace("replace2", "and is_know_feedback = 1");
            sql = sql.replace("replace3", "and is_know_feedback = 1");
        }else{
            sql = sql.replace("replace2", "and is_feedback=1 and is_mark in(0,2)");
            sql = sql.replace("replace3", "and is_feedback=1");
        }
        return sql;
    }*/


    @Override
    public Page<Map<String, Object>> findStudentHomeworkByPage(Map<String, Object> params, Pageable pageable, int type) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        String teacherId = params.get("teacherId").toString();
        boolean addUncorrected = params.get("unCorrected_createTime") != null ? true : false;
        boolean addCorrected = params.get("isCorrected_createTime") != null ? true : false;
        sql.append("select t.*," +
                //未质检1，质检中2，已质检3
                "(case when correct_status < 3 then 0 " +
                "       when check_count = 0 then 1 " +
                "       when check_count < feedback_count then 2 " +
                "       else 3 end) check_status " +
                "from (");
        if (addUncorrected) {
            MapGetterTool tool=new MapGetterTool(params);
            String oneDayCreateTime=tool.getString("oneday_createTime");
            String oneday = null;
            if (StringUtil.isNotBlank(oneDayCreateTime)) {
                oneday = oneDayCreateTime;
            }
            /*if(StringUtil.isNotBlank(oneday)){
                params.remove("unCorrected_createTime");
                params.put("unCorrected_createTime",oneday);
            }*/
            sql.append(this.findStudentHomeworkPublicV2(false, params.get("unCorrected_createTime").toString(), teacherId, oneday));

        }
        if (addUncorrected && addCorrected) {
            sql.append(" union all ");
        }
        if (addCorrected) {
            String oneday = null;
            if (params.get("oneday_createTime") != null) {
                oneday = params.get("oneday_createTime").toString();
            }
            /*if(StringUtil.isNotBlank(oneday)){
                params.remove("isCorrected_createTime");
                params.put("isCorrected_createTime",oneday);
            }*/
            sql.append(this.findStudentHomeworkPublicV2(true, params.get("isCorrected_createTime").toString(), teacherId, oneday));

        }
        sql.append(" ) t ");
        sql.append(" where 1=1 ");
        sql.append(" order by t.correct_status, check_status, t.create_time_sort desc, t.end_time_sort");
        String sqlString = sql.toString();
        sqlString = sqlString.replace("replace1", type + "");
        if (type == 13) {
            sqlString = sqlString.replace("teacher_id", "know_teacher_id");
            sqlString = sqlString.replace("replace2", "t1.is_know_feedback =1");
            sqlString = sqlString.replace("replace3",  "and s.is_know_feedback = 0");
        }else{
            sqlString = sqlString.replace("replace2", "t1.is_mark not in (0,2) || t1.is_feedback =1");
            sqlString = sqlString.replace("replace3", "and s.is_delete = 0 and s.is_mark in (0,2) and s.is_feedback = 0");
        }
        return dao.findPage(sqlString, queryParams.toArray(), pageable);
    }

    private String findStudentHomeworkPublicV2(boolean isCorrected, String createTime, String teacherId, String oneday) {
        StringBuilder sql = new StringBuilder();
        sql.append("select t.*,\n" +
                "                (select child_name from tb_lib_vip where t.vip_id = id)    child_name,\n" +
                "                sum(t2.is_check_error)                                     wrong_count,\n" +
                "                sum(case when t2.check_date is not null then 1 else 0 end) check_count,\n" +
                "                count(t1.id)                                               pic_total,\n" +
                "                sum(case when replace2 then 1 else 0 end )                 feedback_count,\n" +
                "                min(t2.start_time)                                         correct_start_time,\n" +
                "                min(t1.create_time)                                        wait_time,\n" +
                "                max(t2.end_time)                                           correct_end_time,\n");
        if (isCorrected) {
            sql.append("3                                                          correct_status,\n" +
                      " t.create_time                                              create_time_sort,\n" +
                       "null                                                       end_time_sort\n");
        } else {
            sql.append("case when sum(case when t2.start_time is not null then 1 else 0 end)>0 then 2 else 1 end    correct_status,\n" +
                       "null                                                                                  create_time_sort,\n" +
                       "min(t2.allot_time)   end_time_sort\n");
        }
        sql.append("from scon_homework t join scon_homework_picture t1 on t.id = t1.homework_id and t1.service_type=1\n" +
                "       left join scon_homework_picture_correct t2 on t1.id = t2.homework_picture_id and t2.type = replace1\n" +
                "         where 1 = 1\n");
        sql.append("and t1.teacher_id = '"+teacherId+"'\n");
        if(StringUtil.isNotBlank(oneday)){
            sql.append("and t.create_time regexp '" + oneday + "'\n");
            sql.append("and t1.create_time regexp '" + oneday + "'\n");
        }
        sql.append("and t.create_time >= '"+createTime+"'\n");
        sql.append("and t1.create_time >= '"+createTime+"'\n");
        if (isCorrected) {
            sql.append("and not exists(\n" +
                    "              select 1\n" +
                    "              from scon_homework_picture s\n" +
                    "              where 1=1 \n"+
                    "                replace3\n" +
                    "                and s.homework_id=t.id\n" +
                    "                and s.teacher_id ='" + teacherId + "'\n" +
                    "                and s.service_type=1\n");
            if(StringUtil.isNotBlank(oneday)){
                sql.append(" and s.create_time regexp '" + oneday + "'");
            }
            sql.append(" and s.create_time>='"+createTime+"')");
        } else {
            sql.append("and exists(\n" +
                    "              select 1\n" +
                    "              from scon_homework_picture s\n" +
                    "             where 1=1 \n"+
                    "                replace3\n" +
                    "                and s.homework_id=t.id\n" +
                    "                and s.teacher_id ='" + teacherId + "'\n" +
                    "                and s.service_type=1\n");
            if(StringUtil.isNotBlank(oneday)){
                sql.append(" and s.create_time regexp '" + oneday + "'");
            }
            sql.append(" and s.create_time>='"+createTime+" ' )");

        }
        sql.append(" group by t.id\n");
        return sql.toString();
    }

    /*private String findStudentHomeworkPublicV1(boolean isCorrected) {
        String sql = "select t.*,\n" +
                "       (select child_name from tb_lib_vip where t.vip_id = id)    child_name,\n" +
                "       sum(t1.is_check_error)                                     wrong_count,\n" +
                "       sum(case when t1.check_date is not null then 1 else 0 end) check_count,\n" +
                "       count(t1.id)                                               pic_total,\n" +
                "       sum(t1.is_feedback)                                        feedback_count\n" +
                "from scon_homework t\n" +
                "         left join scon_homework_picture t1 on t.id = t1.homework_id\n" +
                "where 1 = 1\n" +
                "  and t1.is_delete = 0\n" +
                "  and t1.teacher_id = ?\n" +
                "  and t.create_time >= ?\n";
        if (isCorrected) {
            sql += "and (t1.is_mark = 1 or t1.is_feedback=1)\n";
        } else {
            sql += "and (t1.is_mark != 1 and t1.is_mark != 3 and t1.is_feedback=0)\n";
        }
        sql += "group by t.id\n";
        return sql;
    }*/

    /*private String findStudentHomeworkPublic(boolean isCorrected) {
        String sql = "select t.*, (select child_name from tb_lib_vip where t.vip_id = id) child_name,\n" +
                " if((select count(1) from scon_homework_picture where homework_id=t.id and check_date is not null)>0,1,0) is_check,\n" +
                "       (select count(1) from scon_homework_picture where homework_id=t.id and is_check_error =1 ) wrong_count,\n" +
                " sum(case when t1.check_date is not null then 1 else 0 end) checked, sum(1) total\n" +
                "from scon_homework t\n" +
                "where 1 = 1\n" +
                "  and t.create_time >= ?\n" +
                "  and exists(select 1 from scon_homework_picture where teacher_id = ? and homework_id = t.id)\n";
        if (isCorrected) {
            sql += "and t.correct_time is not null";
        } else {
            sql += "and t.correct_time is null";
        }
        return sql;
    }*/

    /*@Override
    public Page<Map<String, Object>> findTeacherAllotByPage(Map<String, Object> params, Pageable pageable,int type) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryparams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(params);
        selSQL.append("select t.*,\n" +
                "       (select count(1) from scon_homework_picture s1\n" +
                "            where s1.teacher_id = t.user_id\n" +
                "              and s1.create_time >= ?\n" +
                "                   replace3\n" +
                //"                   and exists(select 1 from scon_homework_picture_correct s2 where s1.id = s2.homework_picture_id and s2.allot_time > ? and s2.type = replace1 )" +
                ") as waitCount\n" +
                "    from\n" +
                "       tb_lib_manager t\n" +
                "    where t.is_online = 1\n" +
                "      replace2\n" +
                "      and t.state = 1\n" );
        queryparams.add(map.getString("beginTime"));
        String maxCreateTime = map.getString("maxCreateTime");
        if (StringUtil.isNotBlank(maxCreateTime)) {
            selSQL.append(" and t.create_time <=?");
            queryparams.add(maxCreateTime);
        }

        String name = map.getString("name");
        if (StringUtil.isNotBlank(name)) {
            selSQL.append(" and t.name regexp?");
            queryparams.add(name);
        }
        String subject=map.getString("subject");
        if(StringUtil.isNotBlank(subject)){
            selSQL.append("and t.course_name regexp ?\n");
            queryparams.add(subject);
        }
        String grade=map.getString("grade");
        if(StringUtil.isNotBlank(grade)){
            selSQL.append("and t.grade regexp ?\n");
            queryparams.add(grade);
        }
        String parentId = map.getString("parentId");
        if (StringUtil.isNotBlank(parentId)) {
            selSQL.append("and (t.parent_id = ? or t.user_id= ?)");
            queryparams.add(parentId);
            queryparams.add(parentId);
        }
        selSQL.append(" group by t.id");
        String sql = selSQL.toString();
        //sql = sql.replace("replace1",type+"");
        if(type == 13){
            sql = sql.replace("replace2","and t.type = 13");
            sql = sql.replace("teacher_id","know_teacher_id");
            sql = sql.replace("replace3","and s1.is_know_feedback = 0");
        }else{
            sql = sql.replace("replace2","and t.type in (8, 11)");
            sql = sql.replace("replace3","and s1.is_feedback = 0 and s1.is_mark in (0, 2)");

        }
        return dao.findPage(sql, queryparams.toArray(), pageable);

    }*/

    @Override
    public Map<String, Object> findStudentByVipId(String vipId) {
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Map<String, Object> map = new HashMap<String, Object>();
        selsql.append("select t.img_url,t.child_name,t.school,t.grade,t.sex,t.phone from tb_lib_vip t where t.id=?");
        queryParams.add(vipId);
        List<Map<String, Object>> list = dao.findMap(selsql.toString(), queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);
        }
        return map;

    }


    /*@Override
    public Page<Map<String, Object>> findUnallotHomeworkByPage(Map<String, Object> params, Pageable pageable) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryparams = new ArrayList<>();
        String maxCreateTime=params.get("maxCreateTime").toString();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1); //得到前一天
        Date date = calendar.getTime();
        String startTime=new SimpleDateFormat("yyyy-MM-dd").format(date)+" 00:00:00";
        selSQL.append("select  t1.course_name,t1.grade,t1.child_name,t2.start_time,t2.id from\n" +
                "tb_lib_vip t1, scon_homework t2\n" +
                "where t1.id=t2.vip_id\n" +
                "and t2.id in(select homework_id from scon_homework_picture  where teacher_id is null) \n" +
                "and t2.create_time<=?");
        queryparams.add(maxCreateTime);
        selSQL.append("and t2.start_time>=?");
        queryparams.add(startTime);
        return dao.findPage(selSQL.toString(), queryparams.toArray(), pageable);

    }*/

    /*@Override
    public Page<Map<String, Object>> findUnallotHomeworkByNowPage(Map<String, Object> params, Pageable pageable){
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryparams = new ArrayList<>();
        String maxCreateTime=params.get("maxCreateTime").toString();

        selSQL.append("select  t1.course_name,t1.grade,t1.child_name,t2.start_time,t2.id from\n" +
                "tb_lib_vip t1, scon_homework t2\n" +
                "where t1.id=t2.vip_id\n" +
                "and t2.id in(select homework_id from scon_homework_picture  where teacher_id is null) \n" +
                "and t2.create_time<?");
        queryparams.add(maxCreateTime);
        selSQL.append("and t2.start_time>?");
        String startTime=new SimpleDateFormat("yyyy-MM-dd").format(new Date())+" 00:00:00";
        queryparams.add(startTime);
        selSQL.append("and t2.start_time<?");
        String now=new Date().toString();
        queryparams.add(now);
        return dao.findPage(selSQL.toString(), queryparams.toArray(), pageable);
    }*/

    /*@Override
    public Map<String, Object> findTeacherDetailByTeacherId(String teacherId, int type) {
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Map<String, Object> map = new HashMap<String, Object>();
           selsql.append("select t.*");
           selsql.append(" from tb_lib_manager t where t.user_id=? and t.type = ? ");
           queryParams.add(teacherId);
           queryParams.add(type);
        List<Map<String, Object>> list = dao.findMap( selsql.toString(), queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);

        }
        return map;
    }*/

    @Override
    public Map<String,Object> findTheCount(String teacherId,int type){
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Map<String, Object> map = new HashMap<String, Object>();
        selsql.append(" select sum(case when s2.is_check_error=1 then 1 else 0 end) as wrongCount,");
        selsql.append(" sum(ifNull(s2.operate_nums, 0)) AS totalCount ,  ");
        selsql.append(" sum(ifNull(s2.correct_nums, 0)) as  correct_count ");
        selsql.append(" FROM  scon_homework_picture s1 ");
        selsql.append(" LEFT JOIN scon_homework_picture_correct s2 ON s1.id = s2.homework_picture_id ");
        selsql.append(" where s1.teacher_id=? and s2.type =? and s1.service_type=1");
        queryParams.add(teacherId);
        queryParams.add(type);
        List<Map<String, Object>> list = dao.findMap( selsql.toString(), queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);

        }
        return map;

    }
    @Override
    public Page<Map<String, Object>> findManagerByPage(Map<String, Object> params, Pageable pageable) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(params);
        sql.append("select t.*,\n" +
                "       case when t.type = 12 then (select count(1) from tb_lib_manager where state = 1 and type in(8,13) and parent_id = t.user_id) " +
                "           else (select count(1) +1  from tb_lib_manager where state = 1 and type in(8,11,13) and  parent_id = t.user_id and is_cancelled = 0) end group_count\n" +
                //"       (select count(distinct homework_id) from scon_homework_picture where teacher_id in (select user_id from tb_lib_manager where (parent_id = t.user_id or user_id = t.user_id) ) and is_feedback=1) homework_count,\n" +
                //"       (select count(1) from scon_homework_picture where teacher_id in (select user_id from tb_lib_manager where (parent_id = t.user_id or user_id = t.user_id) ) and is_feedback=1 ) homework_pic_count,\n" +
                //"       (select avg(correction_time) from scon_homework_picture where teacher_id in (select user_id from tb_lib_manager where (parent_id = t.user_id or user_id = t.user_id) ) and is_feedback=1) avgTime,\n" +
                //"       (select avg(IFNULL(judge_level,5)) from tb_teacher_assessment where teacher_id in (select user_id from tb_lib_manager where (parent_id = t.user_id or user_id = t.user_id))  ) avgMark\n" +
                "from tb_lib_manager t\n" +
                "where t.state = 1\n");
        Object role = params.get("role");
        //超级管理员也是校区群管理员
        if (role != null && SUPER_MANAGER.equals(role.toString())) {
            sql.append(" and t.type in (11,12) ");
        } else {
            sql.append(" and t.type = 11 ");
        }
        String maxCreateTime = mapGetterTool.getString("maxCreateTime");
        if (StringUtil.isNotBlank(maxCreateTime)) {
            sql.append(" and t.create_time <= ? ");
            queryParams.add(maxCreateTime);
        }
        String subject=mapGetterTool.getString("subject");
        if(StringUtil.isNotBlank(subject)){
            sql.append(" and t.course_name regexp ?");
            queryParams.add(subject);
        }
        sql.append(" order by t.type desc,t.name ");
        return dao.findPage(sql.toString(), queryParams.toArray(), pageable);
    }

    @Override
    public Map<String, Object> countByManagerId(Map<String, Object> searchParams, String managerId, Boolean isTimely) {
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(searchParams);
        StringBuilder sql = new StringBuilder();
        //实时计算
        if (isTimely) {
            sql.append("select * from\n" +
                    "       (select case when t.parent_id = ? then t.parent_id else t.user_id end group_id,\n" +
                    "       sum(t.is_online) online_count,\n" +
                    "       sum(case when is_online=0 then 1 else 0 end) offline_count,\n" +
                    //"       count(t.id) group_count,\n" +
                    "       sum((select count(1) from scon_homework_picture where service_type=1 and teacher_id =t.user_id and is_feedback=1 and is_mark in(0,2))) homework_pic_count\n");
            queryParams.add(managerId);
            sql.append("from tb_lib_manager t\n");

        } else {
            sql.append("select * from\n" +
                    "       (select case when t.parent_id = ? then t.parent_id else t.user_id end group_id,\n" +
                    "       avg((select avg( t1.correction_time) from scon_homework_picture_correct t1 left join scon_homework_picture t2 on t1.homework_picture_id=t2.id and t2.service_type=1 " +
                    "where t2.teacher_id =t.user_id )) avg_time\n" +
                    "from tb_lib_manager t\n" ) ;
            queryParams.add(managerId);
        }
        sql.append("where 1=1 and t.state = 1\n");

        //超级管理员只统计在线批改老师&匹配知识点老师，不统计校区管理员
        String role = map.getString("role");
        if (StringUtil.isNotBlank(role) && SUPER_MANAGER.equals(role)) {
            sql.append("and t.type in (8,13)\n");
        } else {
            sql.append("and t.type in (8,11,13)\n");
        }
        sql.append("and (t.parent_id = ? or t.user_id = ?)) t\n");
        queryParams.add(managerId);
        queryParams.add(managerId);
        sql.append("group by t.group_id limit 1\n");
        List<Map<String, Object>> list;
           list = dao.findMap(sql.toString(), queryParams.toArray());
           return list.get(0);
    }
    /**
     *报错警告
     */
    @Override
    public Page<Map<String, Object>> getErrorWarning(Map map,Pageable pageable) {
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryparams = new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        String teacherId=mapGetterTool.getString("userId");
        int type=mapGetterTool.getInteger("type");
        selSQL.append("select sc.id,s.`subject`,t.child_name,sc.create_time as check_date,sc.end_time ");
        selSQL.append("from scon_homework_picture s LEFT JOIN tb_lib_vip t ON s.vip_id = t.id ");
        selSQL.append("LEFT JOIN scon_homework_picture_errorcheck sc ON sc.homework_picture_id = s.id ");
        selSQL.append("where sc.checked_user_id = ? and sc.type = ? and sc.end_time is not null and s.service_type=1");
        queryparams.add(teacherId);
        queryparams.add(type);
        if(map.containsKey("date")){
            selSQL.append(" and sc.end_time regexp ?");
            String date=mapGetterTool.getString("date");
            queryparams.add(date);
        }
        selSQL.append(" order by sc.end_time desc");
        String sqlString = selSQL.toString();
        return dao.findPage(sqlString,queryparams.toArray(),pageable);
    }

    @Override
    public Map<String,Object>getErrorCount(Map map){
        StringBuilder selSQL = new StringBuilder();
        List<Object> queryparams = new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        String teacherId=mapGetterTool.getString("userId");
        int type=mapGetterTool.getInteger("type");
        selSQL.append("select count( distinct shpc.id) error_count from scon_homework_picture shp LEFT JOIN scon_homework_picture_errorcheck shpc ON shp.id = shpc.homework_picture_id ");
        selSQL.append("where  shpc.end_time is not null and shpc.checked_user_id = ? and shpc.type = ? and shp.service_type=1 ");
        queryparams.add(teacherId);
        queryparams.add(type);
        if(map.containsKey("date")){
            selSQL.append(" and shpc.end_time regexp ?");
            String date=mapGetterTool.getString("date");
            queryparams.add(date);
        }
        String sqlString = selSQL.toString();
        if(type == 13){
            sqlString = sqlString.replace("teacher_id","know_teacher_id");
        }
        return dao.findMap(sqlString,queryparams.toArray()).get(0);
    }

   @Override
   public Page<Map<String, Object>> findUncorrectHomeworkListByPage(Map<String, Object> params, Pageable pageable, int type) {
       List<Object> queryparams = new ArrayList<>();
       MapGetterTool map = new MapGetterTool(params);
       String userId = map.getString(("userId"));
       String GTE_createTime = map.getString("GTE_createTime");
       String role = map.getString("role");
       String value = map.getString("value");
       int timeType=map.getInteger("timeType");
       String sql = this.uncorrectHomeworkListPublic(true, type,timeType, role,value);
       if (!SUPER_MANAGER.equals(role)) {
           queryparams.add(userId);
           queryparams.add(userId);
       }
       queryparams.add(GTE_createTime);
       queryparams.add(GTE_createTime);
       if(timeType>0){
           String selectTime = map.getString("selectTime");
           queryparams.add(selectTime);
           queryparams.add(selectTime);
       }
       return dao.findPage(sql, queryparams.toArray(), pageable);
    }

    /**
     *
     * @param calculateManagerSub 是否计算管理员及下属的数据
     * @return
     */
    private String  uncorrectHomeworkListPublic(Boolean calculateManagerSub, int type,int timeType, String role, String value) {
        String sql = "select t.*\n" +
                "from (select t.*,\n" +
                "             (select child_name\n" +
                "              from tb_lib_vip where t.vip_id = id)                                              child_name,\n" +
                "             t2.name                                                                            teacher_name,\n" +
                "             t2.user_id                                                                         teacher_id,\n" +
                "             t3.allot_time                                                                      time,\n"+
                "             sum(case when t1.is_mark in (0, 2) and t1.is_feedback=0 and t3.start_time is null then 0 else 1 end) auditing_count\n" +
                "      from scon_homework t\n" +
                "               join scon_homework_picture t1 on t.id = t1.homework_id and t1.service_type=1\n" +
                "               left join tb_lib_manager t2 on t1.replacePlace4 = t2.user_id\n" +
                "               left join scon_homework_picture_correct t3 on t1.id = t3.homework_picture_id and t3.type = replacePlace2\n" +
                "          where 1 = 1\n" +
                "               replacePlace3\n" +
                "               replacePlace1\n" +
                "               and t.create_time >= ?\n" +
                "               and t1.create_time >= ?\n" +
                "               replacePlace6\n" +
                "               and t1.is_delete = 0\n" +
                "          group by t.id,t2.user_id\n" +
                "     ) t\n" +
                "    where t.auditing_count = 0\n" +
                /*"    and t.end_time is not null\n" +*/
                "    replacePlace5\n"  +
                " order by t.end_time ";
        //超级管理员，显示所有的作业数据
        if (timeType > 0) {
            sql = sql.replace("replacePlace6", "and t.create_time regexp ? and t1.create_time regexp ?");
        } else {
            sql = sql.replace("replacePlace6", " ");
        }
        if(SUPER_MANAGER.equals(role)){
            sql = sql.replace("replacePlace1","");
            if (StringUtil.isNotBlank(value)) {
                String replaceSql = "and (t.teacher_name regexp '" + value + "' or t.child_name regexp '" + value + "')";
                sql = sql.replace("replacePlace5", replaceSql);
            }
        }else{
            if(calculateManagerSub){
                sql = sql.replace("replacePlace1","and (t2.user_id = ? or t2.parent_id = ?)");
            }else{
                sql = sql.replace("replacePlace1","and t2.user_id = ?");
            }
        }
        //查询不同角色的批改记录
        sql = sql.replace("replacePlace2", type + "");
        //匹配知识点老师
        if(type == 13){
            sql = sql.replace("replacePlace3", "and t2.type = 13");
            sql = sql.replace("is_feedback", "is_know_feedback");
            sql = sql.replace("replacePlace4", "know_teacher_id");
        }else{
            sql = sql.replace("replacePlace3", "and t2.type in (8, 11)");
            sql = sql.replace("replacePlace4", "teacher_id");
        }
        sql = sql.replace("replacePlace5","");
        return sql;
    }

    @Override
    public List<HomeworkCheckDto> findHomeworkCheckList(String teacherId, String beginTime, String endTime) {
        StringBuilder sb = new StringBuilder();
        sb.append("select t2.child_name, t1.homework_id, t1.subject, t2.grade, date(t1.create_time) date, sum(hpc.is_check_error) error,")
                .append(" sum(case when hpc.check_date is not null then 1 else 0 end) checked, sum(1) total")
                .append(" from (select  hp.homework_id from scon_homework_picture hp where hp.service_type=1 and hp.teacher_id=? and hp.create_time between ? and ? ")
                .append(" group by hp.homework_id having count(if (hp.is_feedback = 1 or hp.is_mark in (1, 3), 1, 0)) = sum(if (hp.is_feedback = 1 or hp.is_mark in (1, 3), 1, 0))) t4")
                .append(" left join scon_homework_picture t1 on t4.homework_id = t1.homework_id and t1.service_type=1" +
                        "   left join tb_lib_vip t2 on t1.vip_id=t2.id ")
                .append(" left join scon_homework_picture_correct hpc on t1.id=hpc.homework_picture_id and hpc.type=8 ")
                .append(" where t1.teacher_id=? ")
                .append(" group by t2.child_name, t1.homework_id, date, t1.subject")
                .append(" order by date");
        List<Object> params = new ArrayList<>();
        params.add(teacherId);
        params.add(beginTime);
        params.add(endTime);
        params.add(teacherId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckDto.class);
    }

    @Override
    public List<HomeworkExerciseQuestionsDto> findHomeworkCorrectedQuestions(String homeworkId) {
        StringBuilder sb = new StringBuilder();
        sb.append(" select t1.homework_picture_id, t2.id question_id, t2.big_question_index, t2.small_question_name small_question_index,")
                .append(" t2.option_answer, t2.answer_json, t1.space_index, t1.type, t1.correct_space_index, t2.book_course_id, t2.num")
                .append(" from kmt_homework_wrong_question t1 left join kmt_exercise_questions t2 on t1.question_id=t2.id")
                .append(" where t1.homework_id=? and t1.is_delete = 0 order by t1.homework_picture_id, t2.num");
        List<Object> params = new ArrayList<>();
        params.add(homeworkId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkExerciseQuestionsDto.class);
    }

    @Override
    public List<HomeworkCheckKnowDetailDto> findHomeworkCorrectedKnowledge(String homeworkId) {
        StringBuilder sb = new StringBuilder();
        sb.append("select distinct t1.homework_picture_id, t1.detail_count, t1.total_count, t1.knowledge_version, t2.grade, t2.how_details_id,  t2.alias how_detail_name, t3.how_id, ")
                .append(" t3.alias how_name, t4.how_details_kd_id, t4.alias how_detail_kd_name, t2.num num1, t3.num num2, t4.num num3 ")
                .append(" from scon_homework_how_details t1")
                .append(" left join zyb_know_how_details_sort t2 on t1.how_detail_id = t2.how_details_id and t2.stat=2 and t1.knowledge_version=t2.type and t1.grade=t2.grade and t1.semester=t2.semester")
                .append(" left join zyb_know_how_details_sort t3 on t2.how_id = t3.how_id and t3.stat = 1 and t2.type=t3.type")
                .append(" left join zyb_know_how_details_sort t4 on t2.how_details_id = t4.how_details_id and t4.stat=3 and t2.type = t4.type")
                .append(" where wrong_question_id is null and t1.homework_id=? order by t1.homework_picture_id, t2.num, t3.num, t4.num");
        List<Object> params = new ArrayList<>();
        params.add(homeworkId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckKnowDetailDto.class);
    }

    /*@Override
    public List<HomeworkCheckKnowDetailDto> findHomeworkCorrectedKnowledgeV1(String homeworkId) {
        StringBuilder sb = new StringBuilder();
        sb.append("select distinct t1.homework_picture_id, t1.detail_count, t1.total_count, t1.knowledge_version, t2.grade, t2.how_details_id,  t2.alias how_detail_name, t3.how_id, ")
                .append(" t3.alias how_name, t4.how_details_kd_id, t4.alias how_detail_kd_name, t2.num num1, t3.num num2, t4.num num3 ")
                .append(" from scon_homework_how_details t1")
                .append(" left join zyb_know_how_details_sort t2 on t1.how_detail_sort_id=t2.id ")
                .append(" left join zyb_know_how_details_sort t3 on t2.how_id = t3.how_id and t3.stat = 1 and t1.knowledge_version=t3.type")
                .append(" left join zyb_know_how_details_sort t4 on t2.how_details_id = t4.how_details_id and t4.stat=3 and t1.knowledge_version = t4.type")
                .append(" where wrong_question_id is null and t1.homework_id=? order by t1.homework_picture_id, t2.num, t3.num, t4.num");
        List<Object> params = new ArrayList<>();
        params.add(homeworkId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckKnowDetailDto.class);
    }*/

    @Override
    public List<HomeworkCheckKnowDetailDto> findHomeworkCorrectedKnowledgeByPictureId(String homeworkPictureId) {
        StringBuilder sb = new StringBuilder();
        sb.append("select distinct t1.homework_picture_id, t1.detail_count, t1.total_count, t1.knowledge_version, t2.grade, t2.how_details_id,  t2.alias how_detail_name, t3.how_id, ")
                .append(" t3.alias how_name, t4.how_details_kd_id, t4.alias how_detail_kd_name, t2.num num1, t3.num num2, t4.num num3")
                .append(" from scon_homework_how_details t1")
                .append(" left join zyb_know_how_details_sort t2 on t1.how_detail_id = t2.how_details_id and t2.stat=2 and t1.knowledge_version=t2.type and t1.grade=t2.grade and t1.semester=t2.semester")
                .append(" left join zyb_know_how_details_sort t3 on t2.how_id = t3.how_id and t3.stat = 1 and t1.knowledge_version=t3.type and t1.grade=t3.grade and t1.semester=t3.semester")
                .append(" left join zyb_know_how_details_sort t4 on t2.how_details_id = t4.how_details_id and t4.stat=3 and t1.knowledge_version = t4.type and t1.grade=t4.grade and t1.semester=t4.semester")
                .append(" where wrong_question_id is null and t1.homework_picture_id=? and t2.how_details_id is not null order by t1.homework_picture_id, t2.num, t3.num, t4.num");
        List<Object> params = new ArrayList<>();
        params.add(homeworkPictureId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckKnowDetailDto.class);
    }

    /*@Override
    public List<HomeworkCheckKnowDetailDto> findHomeworkPictureCorrectedKnowledge(String homeworkPictureId) {
        StringBuilder sb = new StringBuilder();
        sb.append("select distinct t1.homework_picture_id, t1.detail_count, t1.total_count, t1.knowledge_version, t2.grade, t2.how_details_id,  t2.alias how_detail_name, t3.how_id, ")
                .append(" t3.alias how_name, t4.how_details_kd_id, t4.alias how_detail_kd_name, t2.num, t3.num, t4.num ")
                .append(" from scon_homework_how_details t1")
                .append(" left join zyb_know_how_details_sort t2 on t1.how_detail_id = t2.how_details_id and t2.stat=2 and t1.knowledge_version=t2.type")
                .append(" left join zyb_know_how_details_sort t3 on t2.how_id = t3.how_id and t3.stat = 1 and t1.knowledge_version=t3.type")
                .append(" left join zyb_know_how_details_sort t4 on t2.how_details_id = t4.how_details_id and t4.stat=3 and t1.knowledge_version = t4.type")
                .append(" where wrong_question_id is null and t1.homework_picture_id=? order by t1.homework_picture_id, t2.num, t3.num, t4.num");
        List<Object> params = new ArrayList<>();
        params.add(homeworkPictureId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckKnowDetailDto.class);
    }*/

    @Override
    public Map<String, Object> findHomeworkTimeByTeacherId(String teacherId, String beginTime, int type,int timeType) {
        String sql = "";
        List<Object> queryParams = new ArrayList<>();
        sql +=  "       select sum(t2.correction_time) as totalCorrectTime\n" +
                "        from scon_homework_picture t1\n" +
                "                 left join scon_homework_picture_correct t2 on t1.id = t2.homework_picture_id " +
                "   where t2.type = replace1\n" +
                "          and t1.service_type=1\n" +
                "          and replace2\n" +
                "          and t1.is_feedback = 1\n" +
                "          and t2.allot_time is not null\n" +
                "          replace4" ;
        sql = sql.replace("replace1", type + "");
        if (type == 13) {
            sql = sql.replace("replace2", "t1.know_teacher_id = ?");
            sql = sql.replace("is_feedback", "is_know_feedback");
        } else {
            sql = sql.replace("replace2", "t1.teacher_id = ?");
        }
        if(0!=timeType){
         sql= sql.replace("replace4","and t1.create_time regexp ?");
        }else {
          sql=sql.replace("replace4","and t1.create_time >= ?");
        }
        queryParams.add(teacherId);
        queryParams.add(beginTime);
        List<Map<String, Object>> list = dao.findMap(sql, queryParams.toArray());
        return list.get(0);
    }


    @Override
    public Map<String,Object> findLowTeacherSalaryList(Map<String,Object> params,String teacherId) {
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        Map<String, Object> map = new HashMap();
        String correctTime=params.get("oneMonth").toString();
        String grade0=params.get("grade0").toString();
        String grade1=params.get("grade1").toString();
        MapGetterTool mapGetterTool=new MapGetterTool(params);
        selsql.append("SELECT\n" +
               " sum(case when t2.is_needing_know =1  then 1 else 0 END) as autoCorrect,\n" +
               " sum(case when t2.is_needing_know =0  then 1 else 0 END) as manualCorrect\n" +
               "FROM \n" +
               "scon_homework t4 \n" +
               " JOIN scon_homework_picture t2 ON t4.id = t2.homework_id  and t4.grade IN (?,?) \n" +
                " JOIN scon_homework_picture_correct t3 ON t2.id = t3.homework_picture_id \n" +
               "WHERE t2.is_feedback = 1 \n" +
               " AND t2.is_mark IN ( 0, 2 ) \n" +
               " AND t2.teacher_id =? \n" +
                "and t2.service_type=1\n" +
               " AND t3.is_check_error = 0 \n" +
               " AND t3.end_time REGEXP ? \n" +
               " AND t3.type IN ( 8, 11 ) ");
       queryParams.add(grade0);
       queryParams.add(grade1);
       queryParams.add(teacherId);
       queryParams.add(correctTime);
        int whteher=mapGetterTool.getInteger("whether");
        if(1==whteher){
            String time=mapGetterTool.getString("time");
            selsql.append(" and t3.end_time>?");
            queryParams.add(time);
        }
        List<Map<String, Object>> list = dao.findMap(selsql.toString(), queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);

        }
        return map;
    }




    /*@Override
    public Page<Map<String,Object>> findAllTeacherDetail(Map<String,Object> params,Pageable pageable){
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        MapGetterTool mapGetterTool=new MapGetterTool(params);
        String name=mapGetterTool.getString("name");
        selsql.append("select t_photo,name,user_id from tb_lib_manager where state=1 and type in(8,11) and is_banned=0 ");
        if(StringUtil.isNotBlank(name)){
            selsql.append(" and name regexp ?");
            queryParams.add(name);
        }
        return  dao.findPage(selsql.toString(),queryParams.toArray(),pageable);
    }*/


    @Override
    public Map<String, Object> findHomeworkTimeByTeacherIdAndSubject(String teacherId, Map params, int type) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        sql.append("select avg(IFNULL(t2.correction_time, 0)) avg_time\n" +
                "from scon_homework_picture t1\n" +
                "left join scon_homework_picture_correct t2 on t1.id = t2.homework_picture_id and t2.type = replace1\n" +
                "where t1.teacher_id = ? and t2.correction_time!=0 and t1.service_type=1");
        queryParams.add(teacherId);
        MapGetterTool maps = new MapGetterTool(params);
        String subject = maps.getString("subject");
        String beginTime=maps.getString("startTime");
        String endTime=maps.getString("endTime");
        if (StringUtil.isNotBlank(subject)) {
            sql.append(" and t1.subject regexp ? ");
            queryParams.add(subject);
        }
        if (StringUtil.isNotBlank(beginTime)) {
            sql.append("and t2.allot_time>= ? ");
            queryParams.add(beginTime);

        }
        if (StringUtil.isNotBlank(endTime)){
            sql.append(" and t2.allot_time<? ");
            queryParams.add(endTime);
        }
        String sqlString = sql.toString();
        sqlString = sqlString.replace("replace1", type + "");
        if (type == 13) {
            sqlString = sqlString.replace("teacher_id", "know_teacher_id");
            sqlString = sqlString.replace("is_feedback", "is_know_feedback");
        }
        List<Map<String, Object>> list = dao.findMap(sqlString, queryParams.toArray());
        return list.get(0);
    }

    /*@Override
    public Map<String,Object> findJudgeLevelByTeacherId(String teacherId,Map params){
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        MapGetterTool maps=new MapGetterTool(params);
        Map<String,Object> map=new HashMap<>();
        selsql.append("select avg(IFNULL(judge_level,5)) judge from tb_teacher_assessment where type=2  and teacher_id=? ");
        queryParams.add(teacherId);
        String date=maps.getString("date");
        if(StringUtil.isNotBlank(date)){
            selsql.append("and create_time regexp ? ");
            queryParams.add(date);
        }
        List<Map<String,Object>> list=dao.findMap(selsql.toString(),queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);

        }
        return map;

    }*/

    /*@Override
    public Map<String,Object> findJudgeLevelByParentId(Map params){
        StringBuilder selsql = new StringBuilder();
        Map<String,Object> map=new HashMap<>();
        List<Object> queryParams = new ArrayList<Object>();
        String teacherId=params.get("teacherId").toString();
        selsql.append("select avg(judge_level) from tb_teacher_assessment where type=2  and teacher_id in(select user_id from tb_lib_manager where parent_id=? and type=8 and state=1) and create_time>? and create_time<=? ");
        queryParams.add(teacherId);
        String beginTime=params.get("beginTime").toString();
        String endTime=params.get("endTime").toString();
        queryParams.add(beginTime);
        queryParams.add(endTime);
        List<Map<String,Object>> list=dao.findMap(selsql.toString(),queryParams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/
    @Override
    public List<Map<String,Object>> findTeacherJudgeLevelByTeacherId(String teacherId){
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selsql.append("select * from tb_teacher_assessment where type=2 and teacher_id=? order by create_time desc ");
        queryParams.add(teacherId);
        List<Map<String,Object>> list=dao.findMap(selsql.toString(),queryParams.toArray());
        return list;
    }

    @Override
    public Map<String,Object> findRegisterTeacher(){
        StringBuilder sql=new StringBuilder();
        Map<String,Object> map=new HashMap<>();
        List<Object> queryParams = new ArrayList<Object>();
        sql.append("select (select count(distinct user_id) from tb_lib_manager where type in(8,11) and state=1) correctCount,");
        sql.append("(select count(distinct user_id) from tb_lib_manager where type=13 and state=1) matchCount");
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryParams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;


    }
    /*@Override
    public Map<String,Object> findActiveTeacher(String beforeTime){
         StringBuilder sql=new StringBuilder();
         List<Object> queryparams=new ArrayList();
         Map<String,Object> map=new HashMap<>();
         sql.append("select count(distinct user_id) from tb_lib_manager where login_time>? and type in(8,11,13) and state=1 ");
         queryparams.add(beforeTime);
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/

    /*@Override
    public Map<String,Object> findRegisterUser(){
        StringBuilder sql=new StringBuilder();
        List<Object> queryparams=new ArrayList();
        Map<String,Object> map=new HashMap<>();
        sql.append("select count(distinct vip_id) from tb_lib_vip_service where species='S003'and end_time>now()");
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/

    /*@Override
    public Map<String,Object> findActiveUser(String beforeTime){
        StringBuilder sql=new StringBuilder();
        List<Object> queryparams=new ArrayList();
        Map<String,Object> map=new HashMap<>();
        sql.append("select count(distinct vip_id) from scon_homework_picture where create_time>?");
        queryparams.add(beforeTime);
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/

    @Override
    public Page<Map<String, Object>> findHomeworkRecoveryByPage(Map<String, Object> params, Pageable pageable) {
        StringBuilder sql = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(params);
        sql.append("select *\n" +
                "from (select t.*,\n" +
                "             (select child_name from tb_lib_vip where t.vip_id = id) child_name,\n" +
                "             count(t1.id)                                            pic_total,\n" +
                "             8 type\n" +
                "      from scon_homework t\n" +
                "               join scon_homework_picture t1 on t.id = t1.homework_id\n" +
                "      where 1 = 1\n" +
                "        and t1.service_type=1\n" +
                "        and t1.is_delete = 0\n" +
                "        and t1.is_mark in (0,2)\n" +
                "        and t1.create_time >= ?\n" +
                "        and t.create_time >= ?\n" +
                "        and (t1.teacher_id is null or t1.teacher_id = '')\n" +
                "      group by t.id\n" +
                "      union all\n" +
                "      select t.*,\n" +
                "             (select child_name from tb_lib_vip where t.vip_id = id) child_name,\n" +
                "             count(t1.id)                                            pic_total,\n" +
                "             13 type\n" +
                "      from scon_homework t\n" +
                "               join scon_homework_picture t1 on t.id = t1.homework_id\n" +
                "      where 1 = 1\n" +
                "        and t1.service_type=1\n" +
                "        and t1.is_delete = 0\n" +
                "        and t1.is_mark in (0,2)\n" +
                "        and t1.create_time >= ?\n" +
                "        and t.create_time >= ?\n" +
                //显示的匹配知识点作业应该是批改老师已经批改完，但是没有分配匹配知识点老师的
                "        and (t1.know_teacher_id is null or t1.know_teacher_id = '')\n" +
                "        and t1.is_needing_know =1 \n"+
                "        and t1.teacher_id is not null\n" +
                "        and t1.is_feedback = 1\n" +
                "      group by t.id\n" +
                "     ) t ");
        for (int i = 1; i <= 4; i++) {
            queryParams.add(map.getString("GTE_createTime"));
        }
        String maxCreateTime = map.getString("maxCreateTime");
        if (StringUtil.isNotBlank(maxCreateTime)) {
            sql.append("where t.create_time <= ?\n");
            queryParams.add(maxCreateTime);
        }
        sql.append("order by t.create_time desc,t.type\n");
        return dao.findPage(sql.toString(), queryParams.toArray(), pageable);
    }

    @Override
    public long countHomeworkRecovery(String gteCreateTime) {
        String sql = "select t.*\n" +
                "from scon_homework t\n" +
                "         join scon_homework_picture t1 on t.id = t1.homework_id\n" +
                "where 1 = 1\n" +
                "  and t1.service_type=1\n" +
                "  and t1.is_delete = 0\n" +
                "  and t1.is_mark in (0, 2)\n" +
                "  and t1.create_time >= 'replace'\n" +
                "  and t.create_time >= 'replace'\n" +
                "  and (t1.teacher_id is null or t1.teacher_id = '')\n" +
                "group by t.id\n" +
                "union all\n" +
                "select t.*\n" +
                "from scon_homework t\n" +
                "         join scon_homework_picture t1 on t.id = t1.homework_id\n" +
                "where 1 = 1\n" +
                "  and t1.service_type=1\n" +
                "  and t1.is_delete = 0\n" +
                "  and t1.is_mark in (0, 2)\n" +
                "  and t1.create_time >= 'replace'\n" +
                "  and t.create_time >= 'replace'\n" +
                "  and (t1.know_teacher_id is null or t1.know_teacher_id = '')\n" +
                "  and t1.teacher_id is not null\n" +
                "  and t1.is_needing_know =1 \n"+
                "  and t1.teacher_id is not null\n" +
                "  and t1.is_feedback = 1\n" +
                "group by t.id";
        sql = sql.replace("replace", gteCreateTime);
        return dao.count(sql);
    }

    @Override
    public Map<String, Object> countUncorrectHomework(Map<String, Object> params, int type) {
        StringBuilder sqlSb = new StringBuilder();
        List<Object> queryParams = new ArrayList<>();
        Map<String, Object> data = new HashMap<>(16);
        MapGetterTool map = new MapGetterTool(params);
        //在线批改老师
        String teacherId = map.getString("teacherId");
        //校区管理员
        String managerId = map.getString("managerId");
        String beginTime = map.getString("beginTime");
        String selectTime = map.getString("selectTime");
        String endTime=map.getString("endTime");
        int timeType=map.getInteger("timeType");
        String sql = "";
        if(StringUtil.isNotBlank(teacherId)){
            sql = this.uncorrectHomeworkListPublic(false, type, timeType,null, null);
            queryParams.add(teacherId);
            queryParams.add(beginTime);
            queryParams.add(beginTime);
            if (timeType > 0) {
                queryParams.add(selectTime);
                queryParams.add(selectTime);
            }
        }else if(StringUtil.isNotBlank(managerId)){
            sql = this.uncorrectHomeworkListPublic(true, type, timeType,null, null);
            queryParams.add(managerId);
            queryParams.add(managerId);
            queryParams.add(beginTime);
            queryParams.add(beginTime);
            if (timeType > 0) {
                queryParams.add(selectTime);
                queryParams.add(selectTime);
            }
        }
        sqlSb.append("select count(t.id) uncorrected_count, min(t.end_time) end_time,min(t.allot_time) allot_time ,t.id \n" +
                "       from (");
        sqlSb.append(sql);
        sqlSb.append(") t order by t.id");
        List<Map<String, Object>> list = dao.findMap(sqlSb.toString(), queryParams.toArray());
        if (list.size() > 0) {
            data = list.get(0);
        }
        return data;
    }

    @Override
    public Map<String,Object> getTotalCount(Map<String,Object> params, int type){
        Map<String, Object> map = new HashMap<>(16);
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool mapGetterTool = new MapGetterTool(params);
        StringBuilder sql = new StringBuilder();
        String parentId = mapGetterTool.getString("userId");
        String startTime=mapGetterTool.getString("startTime");
        String endTime=mapGetterTool.getString("endTime");
        String role = mapGetterTool.getString("role");
        sql.append("select sum(case when s2.is_feedback = 1  then 1 else 0 end) totalPicCount,\n" +
                "       sum(ifNull(s1.is_check_error,0)) totalWrongCount,\n" +
                "       sum(ifNull(s1.correct_nums,0)) correct_nums,\n"+
                "       sum(s1.correction_time) totalTime\n" +
                "from scon_homework_picture_correct s1\n" +
                "left join scon_homework_picture s2 on s1.homework_picture_id = s2.id and s2.service_type=1\n" +
                "where s1.type=replace1\n" +
                "    and s1.allot_time >=? and s1.allot_time<?\n" +
                "       and s2.replace4 in (\n" +
                "        select user_id from tb_lib_manager s3 where s3.state=1 and s3.type replace2 and s3.parent_id = ? \n" +
                "    UNION ALL     select user_id from tb_lib_manager s3 where s3.state=1 and s3.type replace2 and s3.user_id = ?\n" +
                "    )");
        String sqlString = sql.toString();
        sqlString = sqlString.replace("replace1",type+"");
        if(type == 13){
            sqlString = sqlString.replace("replace2","=13");
            sqlString = sqlString.replace("is_feedback","is_know_feedback");
            sqlString=sqlString.replace("replace4","know_teacher_id");
        }else{
            if(SUPER_MANAGER.equals(role)){
                sqlString = sqlString.replace("replace2","=8");
            }else{
                sqlString = sqlString.replace("replace2","in (8,11)");
            }
            sqlString=sqlString.replace("replace4","teacher_id");
        }
        queryParams.add(startTime);
        queryParams.add(endTime);
        queryParams.add(parentId);
        queryParams.add(parentId);
        List<Map<String, Object>> list = dao.findMap(sqlString, queryParams.toArray());
        if (list.size() > 0) {
            map = list.get(0);
        }
        return map;
    }

    /*@Override
    public List<Map<String,Object>> findAllManagerTeacher(){
        StringBuilder sql=new StringBuilder();
        List<Object> queryParam=new ArrayList<>();
        sql.append("select user_id from tb_lib_manager where state=1 and type in(11,12)");
        return  dao.findMap(sql.toString(),queryParam.toArray());



    }*/

    @Override
    public Map<String, Object> getDayCount(Map<String, Object> params, int type) {
        String sql = "";
        List<Object> queryParam = new ArrayList<>();
        MapGetterTool mapGetterTool = new MapGetterTool(params);
        String teacherId = mapGetterTool.getString("userId");
        String subject=mapGetterTool.getString("subject");
        String beginTime=mapGetterTool.getString("beginTime");
        String endTime=mapGetterTool.getString("endTime");
        //角色
        String role = mapGetterTool.getString("role");
        sql += "select sum(ifNull(t1.correct_nums,0)+ifNull(t1.is_check_error,0))error_count\n" +
                "from scon_homework_picture_correct t1\n" +
                "         left join scon_homework_picture t2 on t1.homework_picture_id = t2.id and t1.type = replace1 and t2.service_type=1\n" +
                "where 1=1\n" +
                "  replace2\n" +
                "  and t1.end_time>? and t1.end_time<=?";
        sql = sql.replace("replace1", type + "");
        if (type == 13) {
            sql = sql.replace("replace2", "and t2.know_teacher_id in (select user_id from tb_lib_manager where state = 1 and parent_id = ? and type = 13 )");
        } else {
            if (SUPER_MANAGER.equals(role)) {
                sql = sql.replace("replace2", "and t2.teacher_id in (select user_id from tb_lib_manager where state = 1 and parent_id = ? and type = 8 )");
            } else {
                sql = sql.replace("replace2", "and t2.teacher_id in (select user_id from tb_lib_manager where state = 1 and  user_id = ?  and type in (8,11)  union all  select user_id from tb_lib_manager where state = 1 and parent_id =?  and type in (8,11))");
                queryParam.add(teacherId);
            }
        }
        queryParam.add(teacherId);
        queryParam.add(beginTime);
        queryParam.add(endTime);
        if(StringUtil.isNotBlank(subject)){
            sql+="  and t2.subject regexp ? ";
            queryParam.add(subject);
        }
        List<Map<String, Object>> list = dao.findMap(sql, queryParam.toArray());
        return list.get(0);
    }



    @Override
    public List<Map<String,Object>> queryAllOnlineTeacherId(){
        StringBuilder sql=new StringBuilder();
        List queryParams=new ArrayList();
        sql.append("select user_id from tb_lib_manager where type in(8,11,13) and is_online=1 and state=1");
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryParams.toArray());
        return list;
    }

    @Override
    public Map<String, Object> findMaxWaitTime(String teacherId, String beginTime, int type,int timeType) {
        String sql = "";
        List<String> params = new ArrayList<>();
        sql += "select max(UNIX_TIMESTAMP(IFNULL(t2.start_time, now())) - UNIX_TIMESTAMP(t2.allot_time)) as maxWaitTime\n" +
                "from scon_homework_picture t1\n" +
                "         join scon_homework_picture_correct t2 on t1.id = t2.homework_picture_id and t2.type = replace1\n" +
                "where 1 = 1\n" +
                "  and t1.service_type=1\n" +
                "  and t2.allot_time is not null\n" +
                "  replace3\n" +
                "  replace2";
        sql = sql.replace("replace1", type + "");
        if(0!=timeType){
            sql =sql.replace("replace3","and t1.create_time regexp ?");
        }else {
            sql =sql.replace("replace3","and t1.create_time >= ?");
        }

        //知识点匹配老师
        if (type == 13) {
            sql = sql.replace("replace2", "and t1.know_teacher_id = ?");
        } else {
            sql = sql.replace("replace2", "and t1.teacher_id = ?");
        }
        params.add(beginTime);
        params.add(teacherId);
        List<Map<String, Object>> list = dao.findMap(sql, params.toArray());
        return list.get(0);
    }

    @Override
    public Map<String,Object> findLastWeekUser(Map params){
        StringBuilder sql=new StringBuilder();
        List<String> queryparams=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        String beginTime=params.get("beginTime").toString();
        String endTime=params.get("endTime").toString();
        sql.append("select count(id) from tb_lib_vip where create_time>=? and create_time<? and derver is not null and derver!='' ");
        queryparams.add(beginTime);
        queryparams.add(endTime);
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }

    /*@Override
    public Map<String,Object> findAllRespeed(String beginTime){
        StringBuilder sql=new StringBuilder();
        List<String> queryparams=new ArrayList<>();
        Map<String,Object> map=new HashMap<>(16);
        sql.append("select(select sum(s) from(select(UNIX_TIMESTAMP(IFNULL(correct_time,now()))-UNIX_TIMESTAMP(allot_time)) as s from scon_homework_picture where allot_time is not null and create_time>? ");
        queryparams.add(beginTime);
        sql.append(") m) allrespeedTime,");
        sql.append("(select count(id) from scon_homework_picture where allot_time is not null and create_time>?) totalCount");
        queryparams.add(beginTime);
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/

    /*@Override
    public  Page<Map<String,Object>> findAllKnowlederTeacher(Map<String,Object> params,Pageable pageable){
        StringBuilder selsql = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        MapGetterTool mapGetterTool=new MapGetterTool(params);
        String name=mapGetterTool.getString("name");
        selsql.append("select t_photo,name,user_id from tb_lib_manager where state=1 and type =13 and is_banned=0 ");
        if(StringUtil.isNotBlank(name)){
            selsql.append(" and name regexp ?");
            queryParams.add(name);
        }
        return  dao.findPage(selsql.toString(),queryParams.toArray(),pageable);

    }*/
    /*@Override
    public Map<String,Object> findKnowTeacherSalary(Map params){
        StringBuilder sql=new StringBuilder();
        List<String> queryparams=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        String teacherId=params.get("teacherId").toString();
        String date=params.get("oneMonth").toString();
        int whether=Integer.parseInt(params.get("whether").toString());
        sql.append("select count(t1.homework_picture_id) count from scon_homework_picture_correct t1 left join scon_homework_picture t2 on t1.homework_picture_id=t2.id\n" +
                "where t1.type=13  and t1.start_time is not null and t1.end_time regexp ? and t2.is_mark in(0,2) and t2. is_know_feedback=1 and t2.is_check_error=0 and t2.know_teacher_id=? ");
        queryparams.add(date);
        queryparams.add(teacherId);
        if(1==whether){
            String time=params.get("time").toString();
            sql.append(" and t2.correct_time>?");
            queryparams.add(time);
        }
        List<Map<String,Object>> list=dao.findMap(sql.toString(),queryparams.toArray());
        if(list.size()>0){
            map=list.get(0);
        }
        return map;
    }*/

    @Override
    public List<HomeworkCheckDto> findKnowHomeworkCheckList(String teacherId, String beginTime, String endTime) {
        StringBuilder sb = new StringBuilder();
        sb.append("select t2.child_name, t1.homework_id, t1.subject, t2.grade, date(t1.create_time) date, sum(hpc.is_check_error) error,")
                .append("       sum(case when hpc.check_date is not null then 1 else 0 end) checked, sum(1) total ")
                .append("        from (select  hp.homework_id from scon_homework_picture hp where hp.service_type=1 and hp.know_teacher_id=? and hp.create_time between ? and ? ")
                .append("              group by hp.homework_id having count(hp.is_needing_know = 1) = sum(hp.is_know_feedback = 1)) t4")
                .append("               left join scon_homework_picture t1 on t4.homework_id = t1.homework_id and t1.service_type=1 " +
                        "                       left join tb_lib_vip t2 on t1.vip_id=t2.id")
                .append("               left join scon_homework_picture_correct hpc on t1.id=hpc.homework_picture_id and hpc.type=13")
                .append("  where t1.know_teacher_id=?")
                .append("        group by t2.child_name, t1.homework_id, date, t1.subject")
                .append("        order by date");
        List<Object> params = new ArrayList<>();
        params.add(teacherId);
        params.add(beginTime);
        params.add(endTime);
        params.add(teacherId);
        return dao.findList(sb.toString(), params.toArray(), HomeworkCheckDto.class);
    }


    @Override
    public Map<String,Object> countOnLine(Map params){
        List<Object> queryParams = new ArrayList<>();
        MapGetterTool map = new MapGetterTool(params);
        StringBuilder sql = new StringBuilder();
        String role = map.getString("role");
        int type=map.getInteger("type");
        String date=map.getString("date");
        String managerId=map.getString("managerId");
        sql.append(" select  sum(t.is_online ) online_count,\n" +
               "    sum(case when t.is_online=0 and t.is_cancelled = 0 then 1 else 0 end) offline_count\n" +
               "    from tb_lib_manager t\n" +
               "    where t.state=1");
        if(13!=type){
          sql.append(" and t.type in(8,11)");
        }else {
             sql.append(" and t.type=13");
        }
        sql.append(" and (t.parent_id = ? or t.user_id = ?) \n");
        queryParams.add(managerId);
        queryParams.add(managerId);
        String subject = map.getString("subject");
        if(StringUtil.isNotBlank(subject)){
            sql.append(" and t.course_name regexp ?\n");
            queryParams.add(subject);
        }
        List<Map<String, Object>> list = dao.findMap(sql.toString(), queryParams.toArray());
        return list.get(0);
    }

    public Page<Map<String,Object>> findBynewSubjectAndType(Map condition){
        StringBuilder sql=new StringBuilder();
        ArrayList<String> arrayList=new ArrayList<>();
        sql.append("select * from tb_lib_manager where type in(8,11)");
      return null;

    }

    @Override
    public Map<String,Object> getManagerDetail(Map map){
        StringBuilder sql=new StringBuilder();
        List<Object> queryParams=new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        String userId=mapGetterTool.getString("userId");
        String role=mapGetterTool.getString("role");
        sql.append("SELECT\n" +
                "     sum(case when t1.attend_type=1 then 1 else 0 end) is_attendance_count,\n" +
                "     count(t1.id)attendance_count\n" +
                "      from kmt_arrange_allot t1\n" +
                "      LEFT JOIN tb_lib_manager t2\n" +
                "                ON t1.teacher_id = t2.user_id\n" +
                "where        t1.STATUS = 1\n" +
                "  AND t2.state = 1\n" +
                "  AND t2.type in(8,11,13)");
        if(StringUtil.isNotBlank(role)&& SUPER_MANAGER.equals(role)){
            sql.append("  and t2.parent_id=?");
            queryParams.add(userId);
        }else {
            sql.append("  and t2.parent_id=? or t2.user_id=?");
            queryParams.add(userId);
            queryParams.add(userId);
        }
        return dao.findMap(sql.toString(),queryParams.toArray()).get(0);
    }

    @Override
    public  Page<Map<String,Object>>findTeacherAllHomework(Map map,Pageable pageable){
        StringBuilder sql=new StringBuilder();
        List<Object> queryParams=new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        String userId=mapGetterTool.getString("teacherId");
        String date=mapGetterTool.getString("date");
        int type=mapGetterTool.getInteger("type");
        sql.append("select distinct t3.homework_id id, t.child_name,t1.subject,t.grade,t3.end_time from tb_lib_vip t left join scon_homework t1 on t.id=t1.vip_id ");
        sql.append(" left join scon_homework_picture  t2  on t1.id=t2.homework_id and t2.service_type=1 " +
                "   left join scon_homework_picture_correct t3 on t2.id=t3.homework_picture_id where t2.teacher_id=? and t3.end_time regexp ?");
        sql.append(" and  t2.is_feedback=1 and t3.type =?  and t3.is_check_error=0 and t2.is_mark in(0,2)");
        queryParams.add(userId);
        queryParams.add(date);
        queryParams.add(type);
      return dao.findPage(sql.toString(),queryParams.toArray(),pageable);
    }

    @Override
    public Page<Map<String,Object>>findAllTeacherSalary(Map map,Pageable pageable){
        StringBuilder sql=new StringBuilder();
        List<Object> queryParams=new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        int type=mapGetterTool.getInteger("type");
        String date=mapGetterTool.getString("oneMonth");
        String name=mapGetterTool.getString("name");
        sql.append("select t1.*,t2.teacher_num from tb_lib_salary_info t1 left join tb_lib_salary_integration t2 on t1.user_id=t2.teacher_id where  t1.month regexp ? and t1.total !='0.00'");
        queryParams.add(date);
        if(StringUtil.isNotBlank(name)){
            sql.append(" and t1.teacher_name regexp ?");
            queryParams.add(name);
        }
        if(1==type){
            sql.append(" and t1.type in(8,11)");
        }else {
            sql.append(" and t1.type =13");
        }
        return dao.findPage(sql.toString(),queryParams.toArray(),pageable);
    }

    /**
     * 匹配知识点老师｛1.超级管理员和校区管理员不同身份进入，查询总的和单个老师的
     *
     * 批改老师｛1.超级管理员和校区管理员不同身份进入，查询总的和单个老师的
     */
    /*@Override
    public  Map<String,Object> queryWaitHomeworkCount(Map map){
        StringBuilder sql=new StringBuilder();
        List<Object> queryParams=new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        int type=mapGetterTool.getInteger("type");
        String teacherId=mapGetterTool.getString("teacherId");
        String beginTime=mapGetterTool.getString("beginTime");
        String role = mapGetterTool.getString("role");
        String managerId=mapGetterTool.getString("managerId");
        int timeType=mapGetterTool.getInteger("timeType");
        sql.append("select  count(distinct t.id)\n" +
                "    from  scon_homework t left join\n" +
                "    scon_homework_picture t1 on t.id=t1.homework_id\n" +
                "    left join tb_lib_manager t2\n" +
                "    on t1.replace=t2.user_id \n" +
                "    left join scon_homework_picture_correct t3\n" +
                "    on t1.id=t3.homework_picture_id \n" +
                "    where t3.start_time is  null " +
                "    and t3.homework_id not in(select homework_id from scon_homework_picture_correct where start_time is not null and create_time>=? )  ");
        queryParams.add(beginTime);
        if(13==type){
            sql.append(" and t3.type=13 ");
            if(null!=managerId){
                sql.append(" and t2.parent_id=?");
                queryParams.add(managerId);
            }else {
                sql.append(" and t2.user_id=?");
                queryParams.add(teacherId);
            }
        }else {
            if(null!=managerId){
                if(SUPER_MANAGER.equals(role)){
                    sql.append(" and t2.parent_id=?");
                    queryParams.add(managerId);
                }else {
                    sql.append(" and (t2.parent_id=? or user_id=?)");
                    queryParams.add(managerId);
                    queryParams.add(managerId);
                }
            }else {
                sql.append(" and t2.user_id=?");
                queryParams.add(teacherId);
            }
            sql.append(" and t3.type in(8,11)");
        }
        if(0==timeType){
            sql.append(" and t.create_time>=?");
            queryParams.add(beginTime);
        }else {
            sql.append(" and t.create_time regexp ?");
            queryParams.add(beginTime);
        }
        String sqlString=sql.toString();
        if(type==13){
            sqlString=sqlString.replace("replace","know_teacher_id");
        }else {
            sqlString=sqlString.replace("replace","teacher_id");
        }
        return dao.findMap(sqlString,queryParams.toArray()).get(0);

    }*/


    @Override
    public  List<String> findGuardanceRate(Map map){

        StringBuilder sql=new StringBuilder();
        List<Object> queryParams=new ArrayList<>();
        MapGetterTool mapGetterTool=new MapGetterTool(map);
        String role=mapGetterTool.getString("role");
        String userId=mapGetterTool.getString("userId");
        String month=mapGetterTool.getString("oneMonth");
        sql.append(" SELECT\n" +
                "    count( t.id ) c\n" +
                " FROM\n" +
                "    kmt_arrange_allot t\n" +
                "        LEFT JOIN tb_lib_manager t1 ON t.teacher_id = t1.user_id\n" +
                "  WHERE\n" +
                "  t1.state = 1\n" +
                "  AND t1.type IN ( 8, 11, 13 )\n" +
                "  AND t1.is_cancelled = 0\n" +
                "  AND t.STATUS = 1\n" +
                "  and t.arrange_date regexp ?");
        queryParams.add(month);
        if (role != null && SUPER_MANAGER.equals(role.toString())) {
            sql.append(" and t1.parent_id=? ");
            queryParams.add(userId);
        } else {
            sql.append(" and (t1.parent_id=? or t1.user_id=?) ");
            queryParams.add(userId);
            queryParams.add(userId);

        }
        sql.append( " GROUP BY\n" +
                "    t.teacher_id\n" +
                "  HAVING\n" +
                "        c >= 20");
      return  dao.findList(sql.toString(),queryParams.toArray(),String.class);
    }

}
