trick9191 8 年 前
コミット
173a98409b

+ 323 - 455
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -1917,29 +1917,21 @@ public class StatisticsService extends BaseService {
        endDate = endDate + " 23:59:59";
        Long id = admin.getId();
        String totalSql = "SELECT " +
                " count(1) AS total " +
                "FROM " +
                " wlyy_consult_team a " +
                "WHERE " +
                " a.czrq <= '"+endDate+"' " +
                " AND a.czrq >= '"+startDate+"' " +
                " AND a.admin_team_code= " +id+
                " AND a.consult IN ( " +
                " SELECT DISTINCT " +
                "  t.id consultId " +
                " FROM " +
                "  "+imDataBaseName+".topics t, " +
                "  "+imDataBaseName+".participants p, " +
                "  "+imDataBaseName+".doctors d, " +
                "  "+imDataBaseName+".sessions s " +
                " WHERE " +
                "  p.participant_id = d.id " +
                " AND t.session_id = p.session_id " +
                " AND t.session_id = s.id " +
                " AND s.type = 1 " +
                " AND t.create_time <= '"+endDate+"' " +
                "  COUNT(1) total " +
                "  FROM " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                "  WHERE " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code =" +id +
                " AND t.create_time >= '"+startDate+"' " +
                ")";
                " AND t.create_time <= '"+endDate+"'";
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        Long totalCount = 0L;
        if(totalList!=null&&totalList.size()>0){
@ -1947,31 +1939,23 @@ public class StatisticsService extends BaseService {
            totalCount = (Long)total.get("total");
        }
        String noReySql = "SELECT " +
                " count(1) AS noRey " +
                "FROM " +
                " wlyy_consult_team a " +
                "WHERE " +
                " a.czrq <= '"+endDate+"' " +
                "AND a.czrq >= '"+startDate+"' " +
                "AND a.admin_team_code= " +id+
                " AND a.consult IN ( " +
                " SELECT DISTINCT " +
                "  t.id consultId " +
                " FROM " +
                "  "+imDataBaseName+".topics t, " +
                "  "+imDataBaseName+".participants p, " +
                "  "+imDataBaseName+".doctors d, " +
                "  "+imDataBaseName+".sessions s " +
                " WHERE " +
                "  p.participant_id = d.id " +
                " AND t.session_id = p.session_id " +
                " AND t.session_id = s.id " +
                " AND s.type = 1 " +
                " AND t. STATUS <> 10  " +
                " AND t.`reply` = 0  " +
                " AND t.create_time <= '"+endDate+"' " +
                "  COUNT(1) noRey " +
                "  FROM " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                "  WHERE " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND t. STATUS <> 10 " +
                " AND t.`reply` = 0 "+
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code =" +id +
                " AND t.create_time >= '"+startDate+"' " +
                ")";
                " AND t.create_time <= '"+endDate+"'";
        List<Map<String,Object>> noReyList = jdbcTemplate.queryForList(noReySql);
        Long noReyCount = 0L;
        if(noReyList!=null&&noReyList.size()>0){
@ -2218,7 +2202,22 @@ public class StatisticsService extends BaseService {
//        startDate = startDate + " 00:00:00";
//        endDate = endDate + " 23:59:59";
        //咨询量
        String consult_sql = "SELECT COUNT(1) AS consultCount FROM wlyy_consult_team t WHERE t.admin_team_code = " + id + " AND t.czrq <='" + endDate + "' AND t.czrq >='" + startDate + "'";
        String consult_sql = "SELECT " +
                "  COUNT(1) consultCount " +
                "  FROM " +
                "  im_new.Topics t, " +
                "  im_new.Participants p, " +
                "  im_new.Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  im_new.Patients s " +
                "  WHERE " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code =" +id+
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"'";
        //获取咨詢數
        Map<String, Object> consultCout = jdbcTemplate.queryForMap(consult_sql);
        if (consultCout.get("consultCount") == null) {
@ -2359,120 +2358,82 @@ public class StatisticsService extends BaseService {
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS noRely " +
                    "  left(t.create_time,10) AS dateNo, COUNT(1) AS noRely  " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '" + endDate + "'" +
                    " AND a.czrq >= '" + startDate + "'" +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t, " +
                    " " + imDataBaseName + ".participants p, " +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    "  "+ imDataBaseName +".Topics t, " +
                    "  "+ imDataBaseName +".Participants p, " +
                    "  "+ imDataBaseName +".Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  "+ imDataBaseName +".Patients s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    "  d.id = p.participant_id " +
                    " AND c.consult = t.id " +
                    " AND c.patient = s.id " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
                    " AND p.session_id = t.session_id " +
                    " AND c.admin_team_code = " +teamCode+
                    " AND t.create_time >= '"+startDate+"' " +
                    " AND t.create_time <= '"+endDate+"' " +
                    " GROUP BY dateNo";
            totalSql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS total " +
                    "  left(t.create_time,10) AS dateNo, COUNT(1) total " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '" + endDate + "'" +
                    " AND a.czrq >= '" + startDate + "'" +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t, " +
                    " " + imDataBaseName + ".participants p, " +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    "  "+ imDataBaseName +".Topics t, " +
                    "  "+ imDataBaseName +".Participants p, " +
                    "  "+ imDataBaseName +".Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  "+ imDataBaseName +".Patients s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
                    "  d.id = p.participant_id " +
                    " AND c.consult = t.id " +
                    " AND c.patient = s.id " +
                    " AND p.session_id = t.session_id " +
                    " AND c.admin_team_code = " +teamCode+
                    " AND t.create_time >= '"+startDate+"' " +
                    " AND t.create_time <= '"+endDate+"' " +
                    " GROUP BY dateNo";
        } else {
            //按月统计
            sql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1" +
                    " ) AS weekOfMonth, " +
                    "  COUNT(1) AS noRely" +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE " +
                    " a.czrq <= '" + endDate + "' " +
                    " AND a.czrq >= '" + startDate + "' " +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t," +
                    " " + imDataBaseName + ".participants p," +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            totalSql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1" +
                    " ) AS weekOfMonth, " +
                    "  COUNT(1) AS total" +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE " +
                    " a.czrq <= '" + endDate + "' " +
                    " AND a.czrq >= '" + startDate + "' " +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t," +
                    " " + imDataBaseName + ".participants p," +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            sql ="SELECT " +
                    "  (DATE_FORMAT(t.create_time, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1) AS weekOfMonth, " +
                    "  COUNT(1) AS noRely " +
                    "  FROM " +
                    "  im_new.Topics t, " +
                    "  im_new.Participants p, " +
                    "  im_new.Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  im_new.Patients s " +
                    "  WHERE " +
                    "  d.id = p.participant_id " +
                    "  AND c.consult = t.id " +
                    "  AND c.patient = s.id " +
                    "  AND p.session_id = t.session_id " +
                    "  AND c.admin_team_code = " +teamCode+
                    "  AND t. STATUS <> 10  " +
                    "  AND t.`reply` = 0  " +
                    "  AND t.create_time >= '"+startDate+"' " +
                    "  AND t.create_time <= '"+endDate+"' " +
                    "  GROUP BY weekOfMonth";
            totalSql ="SELECT " +
                    "  (DATE_FORMAT(t.create_time, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1) AS weekOfMonth, " +
                    "  COUNT(1) AS total " +
                    "  FROM " +
                    "  im_new.Topics t, " +
                    "  im_new.Participants p, " +
                    "  im_new.Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  im_new.Patients s " +
                    "  WHERE " +
                    "  d.id = p.participant_id " +
                    "  AND c.consult = t.id " +
                    "  AND c.patient = s.id " +
                    "  AND p.session_id = t.session_id " +
                    "  AND c.admin_team_code = " +teamCode+
                    "  AND t.create_time >= '"+startDate+"' " +
                    "  AND t.create_time <= '"+endDate+"' " +
                    "  GROUP BY weekOfMonth";
        }
        List<Map<String, Object>> noReyList = jdbcTemplate.queryForList(sql);
@ -2502,124 +2463,86 @@ public class StatisticsService extends BaseService {
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS noRely " +
                    "  left(t.create_time,10) AS dateNo, COUNT(1) AS noRely " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '" + endDate + "'" +
                    " AND a.czrq >= '" + startDate + "'" +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t, " +
                    " " + imDataBaseName + ".participants p, " +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    "  "+ imDataBaseName +".Topics t, " +
                    "  "+ imDataBaseName +".Participants p, " +
                    "  "+ imDataBaseName +".Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  "+ imDataBaseName +".Patients s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    "  d.id = p.participant_id " +
                    " AND c.consult = t.id " +
                    " AND c.patient = s.id " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
                    " AND p.session_id = t.session_id " +
                    " AND d.id ="+doctor +
                    " AND c.admin_team_code = " +teamCode+
                    " AND t.create_time >= '"+startDate+"' " +
                    " AND t.create_time <= '"+endDate+"' " +
                    " GROUP BY dateNo";
            totalSql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS total " +
                    "  left(t.create_time,10) AS dateNo, COUNT(1) total " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '" + endDate + "'" +
                    " AND a.czrq >= '" + startDate + "'" +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t, " +
                    " " + imDataBaseName + ".participants p, " +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    "  "+ imDataBaseName +".Topics t, " +
                    "  "+ imDataBaseName +".Participants p, " +
                    "  "+ imDataBaseName +".Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  "+ imDataBaseName +".Patients s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
                    "  d.id = p.participant_id " +
                    " AND c.consult = t.id " +
                    " AND c.patient = s.id " +
                    " AND p.session_id = t.session_id " +
                    " AND d.id ="+doctor +
                    " AND c.admin_team_code = " +teamCode+
                    " AND t.create_time >= '"+startDate+"' " +
                    " AND t.create_time <= '"+endDate+"' " +
                    " GROUP BY dateNo";
        } else {
            //按月统计
            sql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1" +
                    " ) AS weekOfMonth, " +
                    "  COUNT(1) AS noRely" +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE " +
                    " a.czrq <= '" + endDate + "' " +
                    " AND a.czrq >= '" + startDate + "' " +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t," +
                    " " + imDataBaseName + ".participants p," +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            totalSql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1" +
                    " ) AS weekOfMonth, " +
                    "  COUNT(1) AS total" +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE " +
                    " a.czrq <= '" + endDate + "' " +
                    " AND a.czrq >= '" + startDate + "' " +
                    " AND a.admin_team_code =" + teamCode +
                    " AND a.consult IN (" +
                    " SELECT DISTINCT " +
                    " t.id consultId " +
                    " FROM " +
                    " " + imDataBaseName + ".topics t," +
                    " " + imDataBaseName + ".participants p," +
                    " " + imDataBaseName + ".doctors d, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
                    " AND t.session_id = s.id " +
                    " AND s.type = 1 " +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            sql ="SELECT " +
                    "  (DATE_FORMAT(t.create_time, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1) AS weekOfMonth, " +
                    "  COUNT(1) AS noRely " +
                    "  FROM " +
                    "  im_new.Topics t, " +
                    "  im_new.Participants p, " +
                    "  im_new.Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  im_new.Patients s " +
                    "  WHERE " +
                    "  d.id = p.participant_id " +
                    "  AND c.consult = t.id " +
                    "  AND c.patient = s.id " +
                    "  AND p.session_id = t.session_id " +
                    "  AND c.admin_team_code = " +teamCode+
                    "  AND d.id ="+doctor +
                    "  AND t. STATUS <> 10  " +
                    "  AND t.`reply` = 0  " +
                    "  AND t.create_time >= '"+startDate+"' " +
                    "  AND t.create_time <= '"+endDate+"' " +
                    "  GROUP BY weekOfMonth";
            totalSql ="SELECT " +
                    "  (DATE_FORMAT(t.create_time, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1) AS weekOfMonth, " +
                    "  COUNT(1) AS total " +
                    "  FROM " +
                    "  im_new.Topics t, " +
                    "  im_new.Participants p, " +
                    "  im_new.Doctors d, " +
                    "  Wlyy_Consult_Team c, " +
                    "  im_new.Patients s " +
                    "  WHERE " +
                    "  d.id = p.participant_id " +
                    "  AND c.consult = t.id " +
                    "  AND c.patient = s.id " +
                    "  AND p.session_id = t.session_id " +
                    "  AND d.id ="+doctor +
                    "  AND c.admin_team_code = " +teamCode+
                    "  AND t.create_time >= '"+startDate+"' " +
                    "  AND t.create_time <= '"+endDate+"' " +
                    "  GROUP BY weekOfMonth";
        }
        List<Map<String, Object>> noReyList = jdbcTemplate.queryForList(sql);
@ -2645,44 +2568,40 @@ public class StatisticsService extends BaseService {
        endDate = endDate + " 23:59:59";
        // 未回复咨询总量
        String onReySQL = "SELECT " +
                " t.doctor_code AS doctorCode, " +
                " d.`name`, " +
                " IFNULL(c.total, 0) AS noRely " +
                " IFNULL(c.total,0) AS noRely, " +
                " d.code AS doctorCode, " +
                " d.name  " +
                " FROM " +
                " wlyy_admin_team_member t  " +
                " wlyy_doctor d, " +
                " wlyy_admin_team_member m " +
                "  " +
                " LEFT JOIN ( " +
                " SELECT count(1) AS total ,a.doctor  " +
                " SELECT " +
                "  COUNT(1) total, " +
                "  d.`name`, " +
                "  d.id " +
                " FROM " +
                "  wlyy_consult_team a  " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                " WHERE " +
                "  a.czrq <= '"+endDate+"' " +
                " AND a.czrq >= '"+startDate+"' " +
                " AND a.admin_team_code = " +teamCode+
                " AND a.consult IN ( " +
                "   SELECT DISTINCT " +
                "    t.id consultId " +
                "   FROM " +
                "    "+ imDataBaseName +".topics t, " +
                "    "+ imDataBaseName +".participants p, " +
                "    "+ imDataBaseName +".doctors d, " +
                "    "+ imDataBaseName +".sessions s " +
                "   WHERE " +
                "    p.participant_id = d.id " +
                "   AND t.session_id = p.session_id " +
                "   AND t.session_id = s.id " +
                "   AND s.type = 1 " +
                "   AND t. STATUS <> 10 " +
                "   AND t.`reply` = 0 " +
                "   AND t.create_time <= '"+endDate+"' " +
                "   AND t.create_time >= '"+startDate+"' " +
                "  ) " +
                "  GROUP BY a.doctor " +
                " ) c ON c.doctor = t.doctor_code, " +
                " wlyy_doctor d " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code = " +teamCode+
                " AND t. STATUS <> 10 " +
                " AND t.`reply` = 0 " +
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"' " +
                " GROUP BY " +
                "  id " +
                " ) c ON c.id = m.doctor_code " +
                " WHERE " +
                " t.doctor_code = d.`code` " +
                " AND t.available = 1 " +
                " AND t.team_id = "+teamCode;
                " m.doctor_code = d.`code` " +
                " AND m.team_id = "+teamCode;
        if ("0".equals(sort)) {
            onReySQL = onReySQL + " ORDER BY noRely DESC";
        } else {
@ -2691,42 +2610,38 @@ public class StatisticsService extends BaseService {
        //总咨询量
        String totalSql = "SELECT " +
                " t.doctor_code AS doctorCode, " +
                " d.`name`, " +
                " IFNULL(c.total, 0) AS total " +
                " IFNULL(c.total,0) AS total, " +
                " d.code AS doctorCode, " +
                " d.name  " +
                " FROM " +
                " wlyy_admin_team_member t  " +
                " wlyy_doctor d, " +
                " wlyy_admin_team_member m " +
                "  " +
                " LEFT JOIN ( " +
                " SELECT count(1) AS total ,a.doctor  " +
                " SELECT " +
                "  COUNT(1) total, " +
                "  d.`name`, " +
                "  d.id " +
                " FROM " +
                "  wlyy_consult_team a  " +
                "  "+ imDataBaseName +".Topics t, " +
                "  "+ imDataBaseName +".Participants p, " +
                "  "+ imDataBaseName +".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+ imDataBaseName +".Patients s " +
                " WHERE " +
                "  a.czrq <= '"+endDate+"' " +
                " AND a.czrq >= '"+startDate+"' " +
                " AND a.admin_team_code = " +teamCode+
                " AND a.consult IN ( " +
                "   SELECT DISTINCT " +
                "    t.id consultId " +
                "   FROM " +
                "    "+ imDataBaseName +".topics t, " +
                "    "+ imDataBaseName +".participants p, " +
                "    "+ imDataBaseName +".doctors d, " +
                "    "+ imDataBaseName +".sessions s " +
                "   WHERE " +
                "    p.participant_id = d.id " +
                "   AND t.session_id = p.session_id " +
                "   AND t.session_id = s.id " +
                "   AND s.type = 1 " +
                "   AND t.create_time <= '"+endDate+"' " +
                "   AND t.create_time >= '"+startDate+"' " +
                "  ) " +
                "  GROUP BY a.doctor " +
                " ) c ON c.doctor = t.doctor_code, " +
                " wlyy_doctor d " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code = " +teamCode+
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"' " +
                " GROUP BY " +
                "  id " +
                " ) c ON c.id = m.doctor_code " +
                " WHERE " +
                " t.doctor_code = d.`code` " +
                " AND t.available = 1 " +
                " AND t.team_id = "+teamCode;
                " m.doctor_code = d.`code` " +
                " AND m.team_id = "+teamCode;
        if ("0".equals(sort)) {
            totalSql = totalSql + " ORDER BY total DESC";
        } else {
@ -2735,43 +2650,39 @@ public class StatisticsService extends BaseService {
        //结束咨询
        String endConsultSql = "SELECT " +
                " t.doctor_code AS doctorCode, " +
                " d.`name`, " +
                " IFNULL(c.total, 0) AS endRey " +
                " IFNULL(c.total,0) AS endRey, " +
                " d.code AS doctorCode, " +
                " d.name  " +
                " FROM " +
                " wlyy_admin_team_member t  " +
                " wlyy_doctor d, " +
                " wlyy_admin_team_member m " +
                "  " +
                " LEFT JOIN ( " +
                " SELECT count(1) AS total ,a.doctor  " +
                " SELECT " +
                "  COUNT(1) total, " +
                "  d.`name`, " +
                "  d.id " +
                " FROM " +
                "  wlyy_consult_team a  " +
                "  "+ imDataBaseName +".Topics t, " +
                "  "+ imDataBaseName +".Participants p, " +
                "  "+ imDataBaseName +".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+ imDataBaseName +".Patients s " +
                " WHERE " +
                "  a.czrq <= '"+endDate+"' " +
                " AND a.czrq >= '"+startDate+"' " +
                " AND a.admin_team_code = " +teamCode+
                " AND a.consult IN ( " +
                "   SELECT DISTINCT " +
                "    t.id consultId " +
                "   FROM " +
                "    "+ imDataBaseName +".topics t, " +
                "    "+ imDataBaseName +".participants p, " +
                "    "+ imDataBaseName +".doctors d, " +
                "    "+ imDataBaseName +".sessions s " +
                "   WHERE " +
                "    p.participant_id = d.id " +
                "   AND t.session_id = p.session_id " +
                "   AND t.session_id = s.id " +
                "   AND s.type = 1 " +
                "   AND t. STATUS = 10 " +
                "   AND t.create_time <= '"+endDate+"' " +
                "   AND t.create_time >= '"+startDate+"' " +
                "  ) " +
                "  GROUP BY a.doctor " +
                " ) c ON c.doctor = t.doctor_code, " +
                " wlyy_doctor d " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code = " +teamCode+
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"' " +
                " AND t. STATUS = 10 " +
                " GROUP BY " +
                "  id " +
                " ) c ON c.id = m.doctor_code " +
                " WHERE " +
                " t.doctor_code = d.`code` " +
                " AND t.available = 1 " +
                " AND t.team_id = "+teamCode;
                " m.doctor_code = d.`code` " +
                " AND m.team_id = "+teamCode;
        if ("0".equals(sort)) {
            endConsultSql = endConsultSql + " ORDER BY endRey DESC";
        } else {
@ -2868,122 +2779,79 @@ public class StatisticsService extends BaseService {
        endDate = endDate + " 23:59:59";
        //获取咨询总数
        String couTotalSQL = "SELECT " +
                " c.doctorCode, " +
                " count(1) AS total " +
                "  COUNT(1) total " +
                " FROM " +
                " wlyy_consult_team a, " +
                " ( " +
                " SELECT DISTINCT " +
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " " + imDataBaseName + ".topics t, " +
                " " + imDataBaseName + ".participants p, " +
                " " + imDataBaseName + ".doctors d, " +
                " " + imDataBaseName + ".sessions s " +
                " WHERE " +
                " p.participant_id = d.id " +
                " AND t.session_id = p.session_id " +
                " AND t.session_id = s.id " +
                " AND s.type = 1 " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND d.id='" + doctor + "' " +
                " ) c " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code = " + teamCode +
                " GROUP BY " +
                " c.doctorCode ";
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code ="+teamCode+
                " AND d.id='"+doctor+"'" +
                " AND t.create_time <= '"+endDate+"'";
        //及时回复数
        String reyTotalSql = "SELECT " +
                " c.doctorCode, " +
                " count(1) AS total " +
                " FROM " +
                " wlyy_consult_team a, " +
                " ( " +
                " SELECT DISTINCT " +
                " t.id consultId, " +
                " d.id doctorCode " +
                "  COUNT(1) total " +
                " FROM " +
                " " + imDataBaseName + ".topics t, " +
                " " + imDataBaseName + ".participants p, " +
                " " + imDataBaseName + ".doctors d, " +
                " " + imDataBaseName + ".sessions s " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                " WHERE " +
                " p.participant_id = d.id " +
                " AND t.session_id = p.session_id " +
                " AND t.session_id = s.id " +
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND s.business_type=2  " +
                " AND t.`reply`=1  " +
                " AND t.`reply`=1 " +
                " AND c.admin_team_code ="+teamCode+
                " AND d.id='"+doctor+"'" +
                " AND TIMESTAMPDIFF(SECOND ,t.create_time ,t.reply_time) <86400 AND TIMESTAMPDIFF(SECOND ,t.create_time,t.reply_time) >0 " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND d.id='" + doctor + "' " +
                " ) c " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                " c.doctorCode";
                " AND t.create_time <= '"+endDate+"'";
        //本周或月增量
        String addTotalSql = "SELECT " +
                "  c.doctorCode, " +
                "  count(1) AS total " +
                " COUNT(1) total " +
                " FROM " +
                "  wlyy_consult_team a, " +
                "  ( " +
                "   SELECT DISTINCT " +
                " t.id consultId," +
                " d.id doctorCode " +
                " FROM " +
                "    " + imDataBaseName + ".topics t, " +
                "    " + imDataBaseName + ".participants p, " +
                "    " + imDataBaseName + ".doctors d, " +
                "    " + imDataBaseName + ".sessions s " +
                "   WHERE " +
                "    p.participant_id = d.id " +
                "   AND t.session_id = p.session_id " +
                "   AND t.session_id = s.id " +
                "   AND s.type = 1 " +
                "   AND t.create_time <= '" + endDate + "' " +
                "   AND t.create_time >= '" + startDate + "' " +
                "   AND d.id='" + doctor + "' " +
                "  ) c " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                " WHERE " +
                "  c.consultId = a.consult " +
                " AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                "  c.doctorCode";
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code ="+teamCode+
                " AND d.id='"+doctor+"'" +
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"'";
        //当前未回复咨询数
        String noRelySql = "SELECT " +
                "  c.doctorCode, " +
                "  count(1) AS total " +
                " COUNT(1) total " +
                " FROM " +
                "  wlyy_consult_team a, " +
                "  ( " +
                "   SELECT DISTINCT " +
                "    t.id consultId, " +
                "    d.id doctorCode " +
                "   FROM " +
                "    " + imDataBaseName + ".topics t, " +
                "    " + imDataBaseName + ".participants p, " +
                "    " + imDataBaseName + ".doctors d, " +
                "    " + imDataBaseName + ".sessions s " +
                "   WHERE " +
                "    p.participant_id = d.id " +
                "   AND t.session_id = p.session_id " +
                "   AND t.session_id = s.id " +
                "   AND s.type = 1  " +
                "   AND t. STATUS <> 10  " +
                "   AND t.`reply` = 0  " +
                "   AND t.create_time <= '" + endDate + "' " +
                "   AND t.create_time >= '" + startDate + "' " +
                "   AND d.id='" + doctor + "' " +
                "  ) c " +
                "  "+imDataBaseName+".Topics t, " +
                "  "+imDataBaseName+".Participants p, " +
                "  "+imDataBaseName+".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  "+imDataBaseName+".Patients s " +
                " WHERE " +
                "  c.consultId = a.consult " +
                "  AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                "  c.doctorCode";
                "  d.id = p.participant_id " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND t. STATUS <> 10  " +
                " AND t.`reply` = 0  " +
                " AND c.admin_team_code ="+teamCode+
                " AND d.id='"+doctor+"'" +
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"'";
        JSONObject rs = new JSONObject();
        Long total = 0L;