chenweida il y a 8 ans
Parent
commit
c2a022d438
26 fichiers modifiés avec 1820 ajouts et 1295 suppressions
  1. 2 2
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/mycache/CachePool.java
  2. 0 16
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/AgentAppointmentJob.java
  3. 2 2
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/AllSignExpenseStatusJob.java
  4. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ChangeSignJob.java
  5. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ConsultTotalJob.java
  6. 31 28
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentDayAllQuotaJob.java
  7. 4 4
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/NoReyConsultJob.java
  8. 2 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/PatientDeviceJob.java
  9. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeHospitalJob.java
  10. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeTeamJob.java
  11. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeTownJob.java
  12. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignInJob.java
  13. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignJob.java
  14. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignOutJob.java
  15. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignReasonJob.java
  16. 4 4
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ReyConsultJob.java
  17. 4 4
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ReyTimeConsultJob.java
  18. 3 3
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/SignExpenseStatusJob.java
  19. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/SwitchSignJob.java
  20. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/UnPaySignJob.java
  21. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/UnSignJob.java
  22. 1 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WaitSignJob.java
  23. 2 1
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WechatCountJob.java
  24. 32 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/job/Constant.java
  25. 1652 1190
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  26. 69 27
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

+ 2 - 2
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/mycache/CachePool.java

@ -51,9 +51,9 @@ public class CachePool {
        if(model==null){
            model=new CacheModel();
            String sql=" select id,code,idcard,hospital,admin_team_code,expenses_status,patient,server_type from wlyy_sign_family a " +
                    " where status in(1,2) and a.type =2  and expenses_status=1 and a.expenses_time< '"+date+ Constant.quota_date_last+"'" ;
                    " where status in(1,2) and a.type =2  and expenses_status=1 and a.expenses_time< '"+date+ Constant.quota_date_last+"' and a.expenses_time >'"+Constant.getStartTime()+"'" ;
            String sqlCount="select count(id) from wlyy_sign_family a " +
                    " where  status in(1,2) and a.type =2 and expenses_status=1 and a.expenses_time< '"+date+ Constant.quota_date_last+"'";
                    " where  status in(1,2) and a.type =2 and expenses_status=1 and a.expenses_time< '"+date+ Constant.quota_date_last+"'  and a.expenses_time >'"+Constant.getStartTime()+"'" ;
            //抽取數據 分页抽取
            List<SignFamily> signFamiliesTemp= SpringUtil.getBean(DBExtract.class).extractByPage(SignFamily.class,sql,sqlCount,true);
            model.setSql(sql);

+ 0 - 16
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/AgentAppointmentJob.java

@ -107,22 +107,6 @@ public class AgentAppointmentJob implements Job {
            e.printStackTrace();
        }
    }
    private String saveContent(List<PatientHealthGuidance> patientHealthGuidances, Long qkCount, Long orgCount, Long townCount, Long cityCount, boolean isAll, StringBuffer errorContent, Long errorCount,String sql) {
        StringBuffer string=new StringBuffer("统计"+yesterday+" 的健康指导数据完成 ,数据库查询到健康指导数目:"+patientHealthGuidances.size());
        string.append(",sql语句:"+sql);
        string.append(",过滤的脏数据数目:"+errorCount);
        string.append(",统计到市的数据总数:"+cityCount);
        string.append(",统计到区的数据总数:"+townCount);
        string.append(",统计到机构的数据总数:"+orgCount);
        string.append(",统计到团队的数据总数:"+qkCount);
        string.append(",是否统计成功:"+isAll);
        if(!isAll){
            string.append(",失败原因:"+errorContent);
        }
        return string.toString();
    }
    public String getYesterday() {
        return yesterday;
    }

+ 2 - 2
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/AllSignExpenseStatusJob.java

@ -92,8 +92,8 @@ public class AllSignExpenseStatusJob implements Job{
            CacheModel cacheModel=cachePool.getSignFamilysWithExpenseStatus1ByDate(date);
            List<SignFamily> signFamilies_1=cacheModel.getSignFamilies();
            //抽取第二种条件的语句
            String sql=" select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and (expenses_status !=1 or expenses_status is null)";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2  and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"'and (expenses_status !=1 or expenses_status is null)  ";
            String sql=" select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and (expenses_status !=1 or expenses_status is null) and a.apply_date>'"+Constant.getStartTime()+"'";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2  and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"'and (expenses_status !=1 or expenses_status is null)  and a.apply_date>'"+Constant.getStartTime()+"' ";
            List<SignFamily> signFamilies_2= dbExtract.extractByPage(SignFamily.class,sql,sqlCount,true);
            //抽取的语句
            sql="select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"'";

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ChangeSignJob.java

@ -88,7 +88,7 @@ public class ChangeSignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            //找出今天的已改簽信息
            String sql=" select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and  a.patient_apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.expenses_status=1 ";
            String sql=" select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and  a.patient_apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.expenses_status=1 and  a.patient_apply_date>'"+Constant.getStartTime()+"'";
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ConsultTotalJob.java

@ -83,7 +83,7 @@ public class ConsultTotalJob implements Job {
            quartzJobLog.setJobStartTime(new Date());
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql=" select admin_team_code,id from wlyy_consult_team a where a.czrq< '"+yesterday+ Constant.quota_date_last+"'";
            String sql=" select admin_team_code,id from wlyy_consult_team a where a.czrq< '"+yesterday+ Constant.quota_date_last+"' and a.czrq >'"+Constant.getStartTime()+"'";
            //抽取數據
            List<ConsultTeam> consultTeams= dbExtract.extract(ConsultTeam.class,sql);
            //過濾數據

+ 31 - 28
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentDayAllQuotaJob.java

@ -39,6 +39,7 @@ import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -147,8 +148,8 @@ public class CurrentDayAllQuotaJob implements Job {
        quartzJobLog.setJobStartTime(new Date());
        allContent = new StringBuffer();
        //找出今天的签约信息 yesterday,now
        String sql = " select id,code,idcard,hospital,admin_team_code,expenses_status,patient from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '" + tomorrow + "' and a.expenses_status=1 ";
        String sqlCount = " select count(id) from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '" + tomorrow + "' and a.expenses_status=1 ";
        String sql = " select id,code,idcard,hospital,admin_team_code,expenses_status,patient from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '" + tomorrow + "' and a.expenses_time >'"+Constant.getStartTime()+"' and a.expenses_status=1 ";
        String sqlCount = " select count(id) from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '" + tomorrow + "' and a.expenses_time >'"+Constant.getStartTime()+"' and a.expenses_status=1 ";
        //抽取數據
        List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extractByPage(SignFamily.class, sql, sqlCount, true);
@ -211,7 +212,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_37() {
        String quotaId = "37";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.old_admin_team_id!=fr.admin_team_id and fr.apply_date<'"+tomorrow+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.old_admin_team_id!=fr.admin_team_id and fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "'";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -267,7 +268,7 @@ public class CurrentDayAllQuotaJob implements Job {
                }
                if ((1 + 1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "' and a.consult in (" + sb.toString() + ")";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -275,7 +276,7 @@ public class CurrentDayAllQuotaJob implements Job {
                } else {
                    //判断是不是最后的一段
                    if (consultIdMaps.size() == (i + 1)) {
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'and a.consult in (" + sb.toString() + ")";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -284,9 +285,9 @@ public class CurrentDayAllQuotaJob implements Job {
            }
            String sql = "";
            if (consultIdMaps.size() > 0) {
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'and a.consult in (" + sb.toString() + ")";
            } else {
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult ='noRey' ";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'and a.consult ='noRey' ";
            }
            System.out.println("consultTeams num:" + consultTeams.size());
@ -319,7 +320,7 @@ public class CurrentDayAllQuotaJob implements Job {
                }
                if ((1 + 1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "' and a.consult in (" + sb.toString() + ")";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -327,7 +328,7 @@ public class CurrentDayAllQuotaJob implements Job {
                } else {
                    //判断是不是最后的一段
                    if (consultIdMaps.size() == (i + 1)) {
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "' and a.consult in (" + sb.toString() + ")";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -381,7 +382,7 @@ public class CurrentDayAllQuotaJob implements Job {
                }
                if ((1 + 1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                    String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "' and a.consult in (" + sb.toString() + ")";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -389,7 +390,7 @@ public class CurrentDayAllQuotaJob implements Job {
                } else {
                    //判断是不是最后的一段
                    if (consultIdMaps.size() == (i + 1)) {
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                        String sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'and a.consult in (" + sb.toString() + ")";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -399,9 +400,9 @@ public class CurrentDayAllQuotaJob implements Job {
            String sql = "";
            //找出今天的咨询信息
            if (consultIdMaps.size() > 0) {
                sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult in (" + sb.toString() + ")";
                sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'and a.consult in (" + sb.toString() + ")";
            } else {
                sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and a.consult ='Rey' ";
                sql = "select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "' and a.consult ='Rey' ";
            } //抽取數據
            List<ConsultTeamDto> consultTeamDtos = getConsultTeams(ims, consultTeams);
@ -559,7 +560,8 @@ public class CurrentDayAllQuotaJob implements Job {
                    " AND sf.type = 2 " +
                    " AND sf. STATUS IN (1, 2) " +
                    " AND p.openid is not null  " +
                    " AND p.openid_time <'" + tomorrow + "' ";
                    " AND p.openid_time <'" + tomorrow + "' " +
                    " AND p.openid_time >'" + Constant.getStartTime() + "' ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -591,7 +593,8 @@ public class CurrentDayAllQuotaJob implements Job {
                    " AND sf.type = 2 " +
                    " AND pd.del=0 " +
                    " AND sf. STATUS IN (1, 2) " +
                    " AND pd.czrq <' " + tomorrow + "' ";
                    " AND pd.czrq <' " + tomorrow + "'" +
                    " AND pd.czrq >'"+Constant.getStartTime()+"' ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -812,7 +815,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId = "2";
        try {
            //找出今天的解约信息
            String sql = " select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and a.status in(-3,-4) and  a.apply_unsign_date< '" + tomorrow + "' ";
            String sql = " select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and a.status in(-3,-4) and  a.apply_unsign_date< '" + tomorrow + "' and a.apply_unsign_date >'"+Constant.getStartTime()+"' ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -963,10 +966,10 @@ public class CurrentDayAllQuotaJob implements Job {
        allContent.append("----------8-----------");
    }
    private void computequota_9() {
    private void computequota_9() throws ParseException {
        String quotaId = "9";
        //找出今天的待签约信息
        String sql = " select id,code,idcard,hospital,admin_team_code,doctor,doctor_health from wlyy_sign_family a where   a.type =2  and a.status=0 and  a.patient_apply_date< '" + tomorrow + "'  ";
        String sql = " select id,code,idcard,hospital,admin_team_code,doctor,doctor_health from wlyy_sign_family a where   a.type =2  and a.status=0 and  a.patient_apply_date< '" + tomorrow + "' and a.patient_apply_date >'"+Constant.getStartTime()+"'  ";
        try {
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
@ -988,7 +991,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId = "10";
        try {
            //找出今天的已改簽信息
            String sql = " select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and   a.patient_apply_date< '" + tomorrow + "' and a.expenses_status=1 ";
            String sql = " select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and   a.patient_apply_date< '" + tomorrow + "' and a.patient_apply_date >'"+Constant.getStartTime()+"' and a.expenses_status=1 ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1009,7 +1012,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId = "25";
        try {
            //找出总的咨询信息
            String sql = " select * from wlyy_consult_team a where a.czrq< '" + tomorrow + "'";
            String sql = " select * from wlyy_consult_team a where a.czrq< '" + tomorrow + "' and  a.czrq> '" + Constant.getStartTime() + "'";
            //抽取數據
            List<ConsultTeam> consultTeams = SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class, sql);
            //過濾數據
@ -1030,7 +1033,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId = "26";
        try {
            //找出今天统计未缴费签约总数
            String sql = "select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and  a.status>0  and  a.apply_date< '" + tomorrow + "' and a.expenses_status=0 ";
            String sql = "select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and  a.status>0  and  a.apply_date< '" + tomorrow + "' and  a.apply_date> '" + Constant.getStartTime() + "'  and a.expenses_status=0 ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1130,7 +1133,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_29() {
        String quotaId = "29";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+tomorrow+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "'";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1150,7 +1153,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_30() {
        String quotaId = "30";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+tomorrow+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "'";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1172,7 +1175,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_31() {
        String quotaId = "31";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)" ;
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)" ;
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1192,7 +1195,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_32() {
         String quotaId = "32";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "'and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1212,7 +1215,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_33() {
        String quotaId = "33";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) ";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1232,7 +1235,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_34() {
        String quotaId = "34";
        try {
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
@ -1252,7 +1255,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_35() {
        String quotaId = "35";
        try {
            String sql=" select fr.sign_code code,fr.old_hospital hospital,fr.old_admin_team_id admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+ tomorrow+"' and fr.admin_team_id!=fr.old_admin_team_id  and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 ";
            String sql=" select fr.sign_code code,fr.old_hospital hospital,fr.old_admin_team_id admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+ tomorrow+"' and  fr.apply_date> '" + Constant.getStartTime() + "' and fr.admin_team_id!=fr.old_admin_team_id  and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 ";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據

+ 4 - 4
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/NoReyConsultJob.java

@ -104,7 +104,7 @@ public class NoReyConsultJob implements Job {
                }
                if ((1+1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ") and a.czrq>'"+Constant.getStartTime()+"'";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -112,7 +112,7 @@ public class NoReyConsultJob implements Job {
                }else{
                    //判断是不是最后的一段
                    if(consultIdMaps.size()==(i+1)){
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ") and a.czrq>'"+Constant.getStartTime()+"'";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -122,9 +122,9 @@ public class NoReyConsultJob implements Job {
            String sql = "";
            if (consultIdMaps.size() > 0) {
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")  and a.czrq>'"+Constant.getStartTime()+"'";
            } else {
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult ='noRey' ";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult ='noRey' and a.czrq>'"+Constant.getStartTime()+"'";
            }
            //過濾數據
            FilterModel etlModels = consultDataFilter.filter(consultTeams, sql, yesterday);

+ 2 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/PatientDeviceJob.java

@ -98,7 +98,8 @@ public class PatientDeviceJob implements Job {
                    " AND sf.type = 2 " +
                    " AND pd.del=0 " +
                    " AND sf. STATUS IN (1, 2) " +
                    " AND pd.czrq <' "+yesterday+ Constant.quota_date_last+"' ";
                    " AND pd.czrq <' "+yesterday+ Constant.quota_date_last+"'" +
                    " AND pd.czrq >'"+Constant.getStartTime()+"' ";
            //抽取數據
             List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeHospitalJob.java

@ -87,7 +87,7 @@ public class RenewSignChangeHospitalJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"' and fr.apply_date >'"+Constant.getStartTime()+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeTeamJob.java

@ -86,7 +86,7 @@ public class RenewSignChangeTeamJob implements Job {
            quartzJobLog.setJobStartTime(new Date());
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)" ;
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"' and fr.apply_date >'"+Constant.getStartTime()+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital=fr.old_hospital and LEFT(fr.hospital,6)=LEFT(fr.old_hospital,6)" ;
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignChangeTownJob.java

@ -87,7 +87,7 @@ public class RenewSignChangeTownJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) ";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+ Constant.quota_date_last+"'  and fr.apply_date >'"+Constant.getStartTime()+"' and fr.admin_team_id!=fr.old_admin_team_id and fr.hospital!=fr.old_hospital and LEFT(fr.hospital,6)!=LEFT(fr.old_hospital,6) ";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignInJob.java

@ -86,7 +86,7 @@ public class RenewSignInJob implements Job {
            quartzJobLog.setJobStartTime(new Date());
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+Constant.quota_date_last+"' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+yesterday+Constant.quota_date_last+"'  and fr.apply_date >'"+Constant.getStartTime()+"' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignJob.java

@ -87,7 +87,7 @@ public class RenewSignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'  and fr.apply_date >'"+Constant.getStartTime()+"'";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignOutJob.java

@ -86,7 +86,7 @@ public class RenewSignOutJob implements Job {
            quartzJobLog.setJobStartTime(new Date());
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql=" select fr.sign_code code,fr.old_hospital hospital,fr.old_admin_team_id admin_team_code from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+ yesterday + Constant.quota_date_last+"' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 ";
            String sql=" select fr.sign_code code,fr.old_hospital hospital,fr.old_admin_team_id admin_team_code from wlyy_sign_family_renew_log fr where  fr.`status`>0  and  fr.apply_date<'"+ yesterday + Constant.quota_date_last+"'  and fr.apply_date >'"+Constant.getStartTime()+"' and fr.admin_team_id!=fr.old_admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 ";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/RenewSignReasonJob.java

@ -89,7 +89,7 @@ public class RenewSignReasonJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id,fr.renew_change_reason from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id,fr.renew_change_reason from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'  and fr.apply_date >'"+Constant.getStartTime()+"'";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 4 - 4
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ReyConsultJob.java

@ -106,7 +106,7 @@ public class ReyConsultJob implements Job {
                }
                if ((1+1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult in (" + sb.toString() + ")";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -114,7 +114,7 @@ public class ReyConsultJob implements Job {
                }else{
                    //判断是不是最后的剩下一端不能被100整除的
                    if(consultIdMaps.size()==(i+1)){
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult in (" + sb.toString() + ")";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -124,9 +124,9 @@ public class ReyConsultJob implements Job {
            String sql ="";
            if(consultIdMaps.size()>0){
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in ("+sb.toString()+")";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult in ("+sb.toString()+")";
            }else{
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult ='noRey' ";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult ='noRey' ";
            } //抽取數據
            System.out.println("consultTeams num"+consultTeams.size());

+ 4 - 4
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/ReyTimeConsultJob.java

@ -118,7 +118,7 @@ public class ReyTimeConsultJob implements Job {
                }
                if ((1+1) % 100 == 0) {
                    //每隔100统计一次
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                    String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"'and a.consult in (" + sb.toString() + ")";
                    //抽取數據
                    List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                    consultTeams.addAll(consultTeamsTemp);
@ -126,7 +126,7 @@ public class ReyTimeConsultJob implements Job {
                }else{
                    //判断是不是最后的剩下一端不能被100整除的
                    if(consultIdMaps.size()==(i+1)){
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in (" + sb.toString() + ")";
                        String sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult in (" + sb.toString() + ")";
                        //抽取數據
                        List<ConsultTeam> consultTeamsTemp = dbExtract.extract(ConsultTeam.class, sql);
                        consultTeams.addAll(consultTeamsTemp);
@ -136,9 +136,9 @@ public class ReyTimeConsultJob implements Job {
            String sql ="";
            if(consultIdMaps.size()>0){
                sql = " select admin_team_code,id,consult from wlyy_consult_team a, where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult in ("+sb.toString()+")";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a, where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult in ("+sb.toString()+")";
            }else{
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.consult ='noRey' ";
                sql = " select admin_team_code,id,consult from wlyy_consult_team a where  a.czrq< '" + yesterday + Constant.quota_date_last + "' and a.czrq >'"+Constant.getStartTime()+"' and a.consult ='noRey' ";
            }
            //将两个数据库的结果集合并,避免跨库查询

+ 3 - 3
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/SignExpenseStatusJob.java

@ -90,12 +90,12 @@ public class SignExpenseStatusJob implements Job{
            CacheModel cacheModel=cachePool.getSignFamilysWithExpenseStatus1ByDate(date);
            List<SignFamily> signFamilies_1=cacheModel.getSignFamilies();
            //抽取第二种条件的语句
            String sql=" select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and (expenses_status !=1 or expenses_status is null)";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"'and (expenses_status !=1 or expenses_status is null)  ";
            String sql=" select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and a.apply_date >'"+Constant.getStartTime()+"'and (expenses_status !=1 or expenses_status is null)";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and a.apply_date >'"+Constant.getStartTime()+"'and (expenses_status !=1 or expenses_status is null)  ";
            List<SignFamily> signFamilies_2= dbExtract.extractByPage(SignFamily.class,sql,sqlCount,true);
            signFamilies_2.addAll(signFamilies_1);
            //抽取的语句
            sql="select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"'";
            sql="select code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.apply_date< '"+date+ Constant.quota_date_last+"' and a.apply_date >'"+Constant.getStartTime()+"'";
            //清洗數據
            FilterModel etlModels= signDataFilter.filter(signFamilies_2, SignDataFilter.level2Expenses,sql,date);
            //统计数据

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/SwitchSignJob.java

@ -83,7 +83,7 @@ public class SwitchSignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.old_admin_team_id!=fr.admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'";
            String sql="select fr.sign_code code,fr.hospital,fr.admin_team_id from wlyy_sign_family_renew_log fr where fr.`status`>0  and fr.old_admin_team_id!=fr.admin_team_id and LENGTH(fr.hospital)=10 and LENGTH(fr.old_hospital)=10 and fr.apply_date<'"+yesterday+Constant.quota_date_last+"' and fr.apply_date >'"+Constant.getStartTime()+"'";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/UnPaySignJob.java

@ -85,7 +85,7 @@ public class UnPaySignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            //找出今天未缴费签约信息
            String sql="select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and  a.status>0  and a.apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.expenses_status=0 ";
            String sql="select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and  a.status>0  and a.apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.apply_date >'"+Constant.getStartTime()+"' and a.expenses_status=0 ";
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/UnSignJob.java

@ -88,7 +88,7 @@ public class UnSignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            //找出今天的解约信息
            String sql=" select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status in(-3,-4) and a.apply_unsign_date< '"+yesterday+ Constant.quota_date_last+"'";
            String sql=" select code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status in(-3,-4) and a.apply_unsign_date< '"+yesterday+ Constant.quota_date_last+"' and a.apply_unsign_date >'"+Constant.getStartTime()+"'";
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據

+ 1 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WaitSignJob.java

@ -88,7 +88,7 @@ public class WaitSignJob implements Job {
            quartzJobLog.setJobId(wlyyJobConfig.getId());
            quartzJobLog.setJobName(wlyyJobConfig.getJobName());
            //找出今天的待签约信息
            String sql=" select code,idcard,hospital,admin_team_code,doctor,doctor_health from wlyy_sign_family a where  a.type =2  and a.status=0 and  a.patient_apply_date< '"+yesterday+ Constant.quota_date_last+"'  ";
            String sql=" select code,idcard,hospital,admin_team_code,doctor,doctor_health from wlyy_sign_family a where  a.type =2  and a.status=0 and  a.patient_apply_date< '"+yesterday+ Constant.quota_date_last+"'  and a.patient_apply_date >'"+Constant.getStartTime()+"'  ";
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據

+ 2 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WechatCountJob.java

@ -97,7 +97,8 @@ public class WechatCountJob implements Job {
                    " AND sf.type = 2 " +
                    " AND sf. STATUS IN (1, 2) " +
                    " AND p.openid is not null  " +
                    " AND p.openid_time <'" +yesterday+ Constant.quota_date_last+"' ";
                    " AND p.openid_time <'" +yesterday+ Constant.quota_date_last+"'" +
                    " AND a.openid_time >'"+Constant.getStartTime()+"' ";
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);

+ 32 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/Constant.java

@ -1,5 +1,9 @@
package com.yihu.wlyy.job;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * Created by Administrator on 2016.08.18.
 * 常量类
@ -188,5 +192,33 @@ public class Constant {
        }
        return "";
    }
    public static String getStartTime() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date();
        String todayString = simpleDateFormat.format(today);
        String startDateString = (1900 + today.getYear()) + "-07-01";
        Date startDate = simpleDateFormat.parse(startDateString);
        if (simpleDateFormat.parse(todayString).after(startDate)) {
            return (1900 + today.getYear()) + "-06-30";
        } else {
            return (1900 + today.getYear() - 1) + "-06-30";
        }
    }
    public static String getStartYear() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date();
        String todayString = simpleDateFormat.format(today);
        String startDateString = (1900 + today.getYear()) + "-07-01";
        Date startDate = simpleDateFormat.parse(startDateString);
        if (simpleDateFormat.parse(todayString).after(startDate)) {
            return (1900 + today.getYear()) + "";
        } else {
            return (1900 + today.getYear() - 1) + "";
        }
    }
}

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

@ -5,6 +5,7 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
import com.yihu.wlyy.repository.address.CityDao;
import com.yihu.wlyy.repository.address.TownDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
@ -16,10 +17,12 @@ import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MapListUtils;
import com.yihu.wlyy.util.SystemConf;
import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.stereotype.Service;
@ -64,7 +67,7 @@ public class StatisticsService extends BaseService {
        try {
            date = redisTemplate.opsForValue().get("quota:date");
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -99,13 +102,13 @@ public class StatisticsService extends BaseService {
    /**
     * 查询截止某个日期累计量
     *
     * @param endDate 截止日期
     * @param area    区域或机构代码
     * @param level   级别
     * @param level2_type   level2_type的类型
     * @param endDate     截止日期
     * @param area        区域或机构代码
     * @param level       级别
     * @param level2_type level2_type的类型
     * @return
     */
    public long getTotalAmount(String endDate, String area, int level, String index,String level2_type) {
    public long getTotalAmount(String startDate, String endDate, String area, int level, String index, String level2_type) {
        int todayAmount = 0;
        // 查询语句
@ -118,6 +121,10 @@ public class StatisticsService extends BaseService {
                "   and level1_type = ? and del = '1'" +
                "   and quota_date <= ? ";
        if (StringUtils.isNoneEmpty(startDate)) {
            sql += " and quota_date > '" + startDate + "'";
        }
        if (level == 4) {
            // 市级别
            sql += " and city = ? ";
@ -131,8 +138,8 @@ public class StatisticsService extends BaseService {
            sql += " and qkdoctor_code = ?";
        }
        if(StringUtils.isNoneEmpty(level2_type)){
            sql+=" and level2_type = '"+level2_type+"'";
        if (StringUtils.isNoneEmpty(level2_type)) {
            sql += " and level2_type = '" + level2_type + "'";
        }
        Map<String, Object> result = jdbcTemplate.queryForMap(sql, new Object[]{level, endDate, area});
@ -142,7 +149,7 @@ public class StatisticsService extends BaseService {
            String val = "";
            try {
                val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            }catch (Exception e){
            } catch (Exception e) {
                e.printStackTrace();
                val = "";
            }
@ -204,7 +211,7 @@ public class StatisticsService extends BaseService {
            String val = "";
            try {
                val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            }catch (Exception e){
            } catch (Exception e) {
                e.printStackTrace();
                val = "";
            }
@ -231,7 +238,7 @@ public class StatisticsService extends BaseService {
     * @param level   级别
     * @return
     */
    public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel,String level2_type) throws Exception {
    public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel, String level2_type, String year) throws Exception {
        String areaField = "";
        String lowLevelField = "";
        String lowLevelName = "";
@ -283,13 +290,17 @@ public class StatisticsService extends BaseService {
                "     quato_code = '" + index + "' " +
                "   and level1_type = ? and del = '1'" +
                "   and quota_date <= ? " +
                "   and " + areaField + " = ? " ;
                "   and " + areaField + " = ? ";
        if(org.apache.commons.lang3.StringUtils.isNoneEmpty(level2_type)){
            sql+=" and level2_type = '"+level2_type+"'";
        if (org.apache.commons.lang3.StringUtils.isNoneEmpty(level2_type)) {
            sql += " and level2_type = '" + level2_type + "'";
        }
        //如果year有值 就按照年度来查询 即2017年 就是大于2017-06-30
        if (!org.springframework.util.StringUtils.isEmpty(year)) {
            sql += " and quota_date > '" + year + "-06-30' ";
        }
        sql+=   " group by " + lowLevelField ;//+ "," + lowLevelName;更具名称group by会有问题
        sql += " group by " + lowLevelField;//+ "," + lowLevelName;更具名称group by会有问题
        if (sort == 1) {
            sql += " order by amount desc";
@ -376,7 +387,7 @@ public class StatisticsService extends BaseService {
                    String val = "";
                    try {
                        val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code + ":" + getQuotaTimeStamp());
                    }catch (Exception e){
                    } catch (Exception e) {
                        e.printStackTrace();
                        val = "";
                    }
@ -392,26 +403,26 @@ public class StatisticsService extends BaseService {
                    String redisNum = "";
                    try {
                        redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
                    }catch (Exception e){
                    } catch (Exception e) {
                        redisNum = "";
                    }
                    if (StringUtils.isEmpty(redisNum)) {
                        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Calendar.getInstance().get(Calendar.YEAR));
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                            map.put("rateString",map.get("amount")+"/"+peopleNum.getNum());
                            map.put("rateString", map.get("amount") + "/" + peopleNum.getNum());
                        }
                    } else {
                        JSONObject peopleNum = new JSONObject(redisNum);
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
                            map.put("rateString",map.get("amount")+"/"+ peopleNum.getInt("num"));
                            map.put("rateString", map.get("amount") + "/" + peopleNum.getInt("num"));
                        }
                    }
                }
            }
            if (level==2){
            if (level == 2) {
                statisticsAllService.translateTeamLeaderName(resultList);
            }
@ -500,8 +511,8 @@ public class StatisticsService extends BaseService {
                "   and quota_date >= ? " +
                "   and quota_date <= ? " +
                "   and " + areaField + " = ? " +
                " group by " + lowLevelField ;
                //+ "," + lowLevelName; 加上名称group by会影响下面流程 团队如果改名字 数据会被覆盖
                " group by " + lowLevelField;
        //+ "," + lowLevelName; 加上名称group by会影响下面流程 团队如果改名字 数据会被覆盖
        if (sort == 1) {
            sql += " order by amount desc";
@ -586,7 +597,7 @@ public class StatisticsService extends BaseService {
                    String val = "";
                    try {
                        val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code + ":" + getQuotaTimeStamp());
                    }catch (Exception e){
                    } catch (Exception e) {
                        e.printStackTrace();
                        val = "";
                    }
@ -631,13 +642,13 @@ public class StatisticsService extends BaseService {
     * @param index     指标
     * @return
     */
    public JSONArray getDateIncrementDetail(String startDate, String endDate, int interval, String area, int level, String index,String level2_type) throws Exception {
    public JSONArray getDateIncrementDetail(String startDate, String endDate, int interval, String area, int level, String index, String level2_type) throws Exception {
        if (interval == 1) {
            return dateStatistics(startDate, endDate, area, level, index,level2_type);
            return dateStatistics(startDate, endDate, area, level, index, level2_type);
        } else if (interval == 2) {
            return weekStatistics(startDate, endDate, area, level, index,level2_type);
            return weekStatistics(startDate, endDate, area, level, index, level2_type);
        } else if (interval == 3) {
            return monthStatistics(startDate, endDate, area, level, index,level2_type);
            return monthStatistics(startDate, endDate, area, level, index, level2_type);
        }
        return new JSONArray();
@ -653,7 +664,7 @@ public class StatisticsService extends BaseService {
     * @param index
     * @return
     */
    private JSONArray dateStatistics(String startDate, String endDate, String area, int level, String index,String level2_type) {
    private JSONArray dateStatistics(String startDate, String endDate, String area, int level, String index, String level2_type) {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String areaField = "";
        String sql = "";
@ -715,7 +726,7 @@ public class StatisticsService extends BaseService {
                String val = "";
                try {
                    val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                }catch (Exception e){
                } catch (Exception e) {
                    e.printStackTrace();
                    val = "";
                }
@ -743,11 +754,11 @@ public class StatisticsService extends BaseService {
                "   and level1_type = '" + level + "' and del = '1' " +
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + endDate + "' " +
                "   and " + areaField + " = '" + area + "' " ;
                if(StringUtils.isNotBlank(level2_type)){
                     sql=sql + " and level2_type ='"+level2_type+"' ";
                }
                sql=sql + "   group by quota_date ";
                "   and " + areaField + " = '" + area + "' ";
        if (StringUtils.isNotBlank(level2_type)) {
            sql = sql + " and level2_type ='" + level2_type + "' ";
        }
        sql = sql + "   group by quota_date ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
@ -793,7 +804,7 @@ public class StatisticsService extends BaseService {
     * @param index
     * @return
     */
    private JSONArray weekStatistics(String startDate, String endDate, String area, int level, String index,String level2_type) throws Exception {
    private JSONArray weekStatistics(String startDate, String endDate, String area, int level, String index, String level2_type) throws Exception {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String areaField = "";
        String sql = "";
@ -889,7 +900,7 @@ public class StatisticsService extends BaseService {
                String val = "";
                try {
                    val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                }catch (Exception e){
                } catch (Exception e) {
                    e.printStackTrace();
                    val = "";
                }
@ -920,11 +931,11 @@ public class StatisticsService extends BaseService {
                "   and level1_type = '" + level + "' and del = '1' " +
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + endDate + "' " +
                "   and " + areaField + " = '" + area + "' " ;
                if(StringUtils.isNotBlank(level2_type)){
                    sql=sql + " and level2_type ='"+level2_type+"' ";
                }
                sql=sql + "   group by quota_date ";
                "   and " + areaField + " = '" + area + "' ";
        if (StringUtils.isNotBlank(level2_type)) {
            sql = sql + " and level2_type ='" + level2_type + "' ";
        }
        sql = sql + "   group by quota_date ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
@ -1002,7 +1013,7 @@ public class StatisticsService extends BaseService {
     * @return
     * @throws Exception
     */
    private JSONArray monthStatistics(String startDate, String endDate, String area, int level, String index,String level2_type) throws Exception {
    private JSONArray monthStatistics(String startDate, String endDate, String area, int level, String index, String level2_type) throws Exception {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String areaField = "";
        String sql = "";
@ -1095,7 +1106,7 @@ public class StatisticsService extends BaseService {
                String val = "";
                try {
                    val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                }catch (Exception e){
                } catch (Exception e) {
                    e.printStackTrace();
                    val = "";
                }
@ -1127,10 +1138,10 @@ public class StatisticsService extends BaseService {
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + endDate + "' " +
                "   and " + areaField + " = '" + area + "' ";
                if(StringUtils.isNotBlank(level2_type)){
                    sql=sql + " and level2_type ='"+level2_type+"' ";
                }
                sql=sql + "   group by quota_date ";
        if (StringUtils.isNotBlank(level2_type)) {
            sql = sql + " and level2_type ='" + level2_type + "' ";
        }
        sql = sql + "   group by quota_date ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
@ -1194,55 +1205,56 @@ public class StatisticsService extends BaseService {
    /**
     * 统计回复和未回复
     *
     * @param level
     * @param code
     * @return
     * @throws Exception
     */
    public JSONObject getConsultingStatistics(int level ,String code)throws Exception{
    public JSONObject getConsultingStatistics(int level, String code) throws Exception {
        //获取总数
        String sqlTotal =  getConsultingStatisticsSQL(level,code,1);
        String sqlTotal = getConsultingStatisticsSQL(level, code, 1);
        //获取已经回复
        String sqlReply =  getConsultingStatisticsSQL(level,code,2);
        String sqlReply = getConsultingStatisticsSQL(level, code, 2);
        //获取未回复
        String sqlnoReply =  getConsultingStatisticsSQL(level,code,3);
        String sqlnoReply = getConsultingStatisticsSQL(level, code, 3);
        JSONObject result = new JSONObject();
        Long total =  jdbcTemplate.queryForObject(sqlTotal,Long.class);
        Long reply =  jdbcTemplate.queryForObject(sqlReply,Long.class);
        Long noReply =  jdbcTemplate.queryForObject(sqlnoReply,Long.class);
        if(total == null||total == 0){
            result.put("total","0");
            result.put("replyCount","0");
            result.put("noReplyCount","0");
            result.put("replyRatio","0.00%");
            result.put("noReplyRatio","0.00%");
        }else{
            double rr = (double)reply/total*100;
            double nrr = (double)noReply/total*100;
            DecimalFormat df  = new DecimalFormat("###.00");
            result.put("total",total);
            result.put("replyCount",reply);
            result.put("noReplyCount",noReply);
            if(reply==0){
                result.put("replyRatio","0.00%");
            }else{
                result.put("replyRatio",df.format(rr)+"%");
            }
            if(noReply==0){
                result.put("noReplyRatio","0.00%");
            }else{
                result.put("noReplyRatio",df.format(nrr)+"%");
        Long total = jdbcTemplate.queryForObject(sqlTotal, Long.class);
        Long reply = jdbcTemplate.queryForObject(sqlReply, Long.class);
        Long noReply = jdbcTemplate.queryForObject(sqlnoReply, Long.class);
        if (total == null || total == 0) {
            result.put("total", "0");
            result.put("replyCount", "0");
            result.put("noReplyCount", "0");
            result.put("replyRatio", "0.00%");
            result.put("noReplyRatio", "0.00%");
        } else {
            double rr = (double) reply / total * 100;
            double nrr = (double) noReply / total * 100;
            DecimalFormat df = new DecimalFormat("###.00");
            result.put("total", total);
            result.put("replyCount", reply);
            result.put("noReplyCount", noReply);
            if (reply == 0) {
                result.put("replyRatio", "0.00%");
            } else {
                result.put("replyRatio", df.format(rr) + "%");
            }
            if (noReply == 0) {
                result.put("noReplyRatio", "0.00%");
            } else {
                result.put("noReplyRatio", df.format(nrr) + "%");
            }
        }
        return result;
    }
    public String getConsultingStatisticsSQL(int level,String code,int type){
    public String getConsultingStatisticsSQL(int level, String code, int type) {
        StringBuffer sql = new StringBuffer("SELECT count(1) " +
                "FROM ichat.topics t,ichat.participants p," +
@ -1253,27 +1265,27 @@ public class StatisticsService extends BaseService {
                " WHERE t1.id = m1.team_id AND d1.CODE = m1.doctor_code ");
        if (level == 4) {
            // 市级别
            sql.append(" AND d1.city = "+code);
            sql.append(" AND d1.city = " + code);
        } else if (level == 3) {
            // 区、城镇级别
            sql.append(" AND d1.town = "+code);
            sql.append(" AND d1.town = " + code);
        } else if (level == 2) {
            // 机构级别
            sql.append(" AND d1.hospital = "+code);
            sql.append(" AND d1.hospital = " + code);
        } else if (level == 1) {
            // 机构团队级别
            sql.append(" AND t1.id = "+code);
            sql.append(" AND t1.id = " + code);
        }
        sql.append(" GROUP BY T1.`name`,d1. CODE) dt " +
                "WHERE p.participant_id = dt.`CODE` AND p.session_id = t.session_id " +
                "AND t.create_time >= DATE_SUB(NOW(),INTERVAL -1 DAY) ");
        if(type == 1){
        if (type == 1) {
            //计算总数
        }else if(type == 2){
        } else if (type == 2) {
            //计算及时回复
            sql.append(" AND t.reply = 1 ");
        }else if(type == 3 ){
        } else if (type == 3) {
            //计算未回复
            sql.append(" AND t.reply = 0 ");
        }
@ -1282,222 +1294,225 @@ public class StatisticsService extends BaseService {
    /**
     * 统计微信绑定率
     *
     * @return
     */
    public JSONObject getBindingRate(){
    public JSONObject getBindingRate() {
        JSONObject result = new JSONObject();
        Long bindCout = jdbcTemplate.queryForObject(getBindingCountSQL(),Long.class);
        Long signCout = jdbcTemplate.queryForObject(getSignCountSQL(),Long.class);
        Long bindCout = jdbcTemplate.queryForObject(getBindingCountSQL(), Long.class);
        Long signCout = jdbcTemplate.queryForObject(getSignCountSQL(), Long.class);
        if((bindCout != null || bindCout != 0) && (signCout != null&&signCout != 0)){
            double rate = (double)bindCout/signCout*100;
            DecimalFormat df  = new DecimalFormat("###.00");
            result.put("bindRate",df.format(rate)+"%");
        }else{
            result.put("bindRate","0.00%");
        if ((bindCout != null || bindCout != 0) && (signCout != null && signCout != 0)) {
            double rate = (double) bindCout / signCout * 100;
            DecimalFormat df = new DecimalFormat("###.00");
            result.put("bindRate", df.format(rate) + "%");
        } else {
            result.put("bindRate", "0.00%");
        }
        return result;
    }
    /**
     * 获取绑定人数SQL
     *
     * @return
     */
    public String getBindingCountSQL(){
    public String getBindingCountSQL() {
        StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM wlyy_patient t WHERE t.openid IS NOT NULL");
        return sql.toString();
    }
    /**
     * 获取签约数SQL
     eturn
     * eturn
     */
    public String getSignCountSQL(){
    public String getSignCountSQL() {
        StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM wlyy_sign_family f WHERE f.type='2' AND f.`status`>0 AND f.expenses_status='1' ");
        return sql.toString();
    }
    /**
     * 统计回复和未回复
     *
     * @param level
     * @return
     * @throws Exception
     */
    public JSONObject getConsultingStatisticsList(int level,String area,String lowLevel)throws Exception{
    public JSONObject getConsultingStatisticsList(int level, String area, String lowLevel) throws Exception {
        JSONObject result = new JSONObject();
        //级别为市级,统计区级统计区和机构
        if(level == 4){
        if (level == 4) {
            if(StringUtils.isBlank(lowLevel)){
            if (StringUtils.isBlank(lowLevel)) {
                String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
                if(StringUtils.isBlank(timeKey)){
                if (StringUtils.isBlank(timeKey)) {
                    return null;
                }
                //及时回复数
                String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":3:"+timeKey);
                if(StringUtils.isBlank(relyVal)){
                String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(relyVal)) {
                    return null;
                }
                JSONArray rely = new JSONArray(relyVal);
                //咨询总数
                String relyTotal = redisTemplate.opsForValue().get("quota:25:"+level+":"+area+":3:"+timeKey);
                if(StringUtils.isBlank(relyTotal)){
                String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(relyTotal)) {
                    return null;
                }
                JSONArray total = new JSONArray(relyTotal);
                //未回复数
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":3:"+timeKey);
                if(StringUtils.isBlank(onRelyTotal)){
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(onRelyTotal)) {
                    return null;
                }
                JSONArray onRely = new JSONArray(onRelyTotal);
                result.put("resultList",getCoutList(rely,total,onRely));
            }else{
                result.put("resultList", getCoutList(rely, total, onRely));
            } else {
                String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
                if(StringUtils.isBlank(timeKey)){
                if (StringUtils.isBlank(timeKey)) {
                    return null;
                }
                //及时回复数
                String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":2:"+timeKey);
                if(StringUtils.isBlank(relyVal)){
                String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(relyVal)) {
                    return null;
                }
                JSONArray rely = new JSONArray(relyVal);
                //咨询总数
                String relyTotal = redisTemplate.opsForValue().get("quota:25:"+level+":"+area+":2:"+timeKey);
                if(StringUtils.isBlank(relyTotal)){
                String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(relyTotal)) {
                    return null;
                }
                JSONArray total = new JSONArray(relyTotal);
                //未回复数
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":2:"+timeKey);
                if(StringUtils.isBlank(onRelyTotal)){
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(onRelyTotal)) {
                    return null;
                }
                JSONArray onRely = new JSONArray(onRelyTotal);
                result.put("resultList",getCoutList(rely,total,onRely));
                result.put("resultList", getCoutList(rely, total, onRely));
            }
        }else if(level == 3){//区级底下的机构
        } else if (level == 3) {//区级底下的机构
            //quota:23:4:350200:2:1492939333191
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            if(StringUtils.isBlank(timeKey)){
            if (StringUtils.isBlank(timeKey)) {
                return null;
            }
            //及时回复数
            String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":2:"+timeKey);
            if(StringUtils.isBlank(relyVal)){
            String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(relyVal)) {
                return null;
            }
            JSONArray rely = new JSONArray(relyVal);
            //咨询总数
            String relyTotal = redisTemplate.opsForValue().get("quota:25:"+level+":"+area+":2:"+timeKey);
            if(StringUtils.isBlank(relyTotal)){
            String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(relyTotal)) {
                return null;
            }
            JSONArray total = new JSONArray(relyTotal);
            //未回复数
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":2:"+timeKey);
            if(StringUtils.isBlank(noRelyTotal)){
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(noRelyTotal)) {
                return null;
            }
            JSONArray noRely = new JSONArray(noRelyTotal);
            result.put("resultList",getCoutList(rely,total,noRely));
            result.put("resultList", getCoutList(rely, total, noRely));
        }else if(level == 2){//机构级别统计,统计所有团队
        } else if (level == 2) {//机构级别统计,统计所有团队
            //quota:23:4:350200:2:1492939333191
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            if(StringUtils.isBlank(timeKey)){
            if (StringUtils.isBlank(timeKey)) {
                return null;
            }
            //及时回复数
            String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":1:"+timeKey);
            if(StringUtils.isBlank(relyVal)){
            String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(relyVal)) {
                return null;
            }
            JSONArray rely = new JSONArray(relyVal);
            //咨询总数
            String relyTotal = redisTemplate.opsForValue().get("quota:25:"+level+":"+area+":1:"+timeKey);
            if(StringUtils.isBlank(relyTotal)){
            String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(relyTotal)) {
                return null;
            }
            JSONArray total = new JSONArray(relyTotal);
            //未回复数
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":1:"+timeKey);
            if(StringUtils.isBlank(noRelyTotal)){
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(noRelyTotal)) {
                return null;
            }
            JSONArray noRely = new JSONArray(noRelyTotal);
            List<Map<String,Object>> rs = getCoutList(rely,total,noRely);
            List<Map<String, Object>> rs = getCoutList(rely, total, noRely);
            statisticsAllService.translateTeamLeaderName(rs);
            result.put("resultList",rs);
            result.put("resultList", rs);
        }
        return result;
    }
    /**
     *  统计当前级别下数据
     * 统计当前级别下数据
     *
     * @param level
     * @param area
     * @return
     */
    public JSONObject getConsultingTitle(int level,String area){
    public JSONObject getConsultingTitle(int level, String area) {
        JSONObject result = new JSONObject();
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        if(StringUtils.isBlank(timeKey)){
        if (StringUtils.isBlank(timeKey)) {
            return null;
        }
        //及时回复数
        String relyVal = redisTemplate.opsForValue().get("quota:23:"+level+":"+area+":"+timeKey);
        if(StringUtils.isBlank(relyVal)){
        String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(relyVal)) {
            return null;
        }
        JSONObject relyObject =new JSONObject(relyVal);
        JSONObject relyObject = new JSONObject(relyVal);
        JSONArray rely = new JSONArray();
        rely.put(relyObject);
        //咨询总数
        String relyTotal = redisTemplate.opsForValue().get("quota:25:"+level+":"+area+":"+timeKey);
        if(StringUtils.isBlank(relyTotal)){
        String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(relyTotal)) {
            return null;
        }
        JSONObject totalObject =new JSONObject(relyTotal);
        JSONObject totalObject = new JSONObject(relyTotal);
        JSONArray total = new JSONArray();
        total.put(totalObject);
        //未回复数
        String onRelyTotal = redisTemplate.opsForValue().get("quota:22:"+level+":"+area+":"+timeKey);
        if(StringUtils.isBlank(onRelyTotal)){
        String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(onRelyTotal)) {
            return null;
        }
        JSONObject onRelyObject =new JSONObject(onRelyTotal);
        JSONObject onRelyObject = new JSONObject(onRelyTotal);
        JSONArray onRely = new JSONArray();
        onRely.put(onRelyObject);
        result.put("result",getCoutList(rely,total,onRely));
        result.put("result", getCoutList(rely, total, onRely));
        return result;
    }
@ -1505,88 +1520,89 @@ public class StatisticsService extends BaseService {
    /**
     * 统计
     * 根据总数,未回复数,回复数统计,合并结果集及排序
     *
     * @param rely
     * @param total
     * @param onRely
     * @return
     */
    public List<Map<String,Object>> getCoutList(JSONArray rely,JSONArray total,JSONArray onRely){
    public List<Map<String, Object>> getCoutList(JSONArray rely, JSONArray total, JSONArray onRely) {
        Map<String,Object> relyMap = new HashMap<>();
        Map<String,Object> totalMap = new HashMap<>();
        Map<String,Object> onRelyMap = new HashMap<>();
        Map<String, Object> relyMap = new HashMap<>();
        Map<String, Object> totalMap = new HashMap<>();
        Map<String, Object> onRelyMap = new HashMap<>();
        //将List转换为Map,Key为要比较的CODE,降低循环层数
        //转换回复数
        Iterator iterator =  rely.iterator();
        while(iterator.hasNext()){
            JSONObject jsonObject = (JSONObject)iterator.next();
            relyMap.put(jsonObject.get("code").toString(),jsonObject);
        Iterator iterator = rely.iterator();
        while (iterator.hasNext()) {
            JSONObject jsonObject = (JSONObject) iterator.next();
            relyMap.put(jsonObject.get("code").toString(), jsonObject);
        }
        //转换总咨询数
        Iterator iterator2 =  total.iterator();
        while(iterator2.hasNext()){
            JSONObject jsonObject = (JSONObject)iterator2.next();
            totalMap.put(jsonObject.get("code").toString(),jsonObject);
        Iterator iterator2 = total.iterator();
        while (iterator2.hasNext()) {
            JSONObject jsonObject = (JSONObject) iterator2.next();
            totalMap.put(jsonObject.get("code").toString(), jsonObject);
        }
        //转换总咨询数
        Iterator iterator3 =  onRely.iterator();
        while(iterator3.hasNext()){
            JSONObject jsonObject = (JSONObject)iterator3.next();
            onRelyMap.put(jsonObject.get("code").toString(),jsonObject);
        }
        List<Map<String,Object>> resultMaps = new ArrayList<>();
        for(String key : totalMap.keySet()){
            Map<String,Object> rs = new HashMap<>();
            JSONObject relyRs = (JSONObject)relyMap.get(key);
            JSONObject totalRs = (JSONObject)totalMap.get(key);
            JSONObject onRelyRs = (JSONObject)onRelyMap.get(key);
        Iterator iterator3 = onRely.iterator();
        while (iterator3.hasNext()) {
            JSONObject jsonObject = (JSONObject) iterator3.next();
            onRelyMap.put(jsonObject.get("code").toString(), jsonObject);
        }
        List<Map<String, Object>> resultMaps = new ArrayList<>();
        for (String key : totalMap.keySet()) {
            Map<String, Object> rs = new HashMap<>();
            JSONObject relyRs = (JSONObject) relyMap.get(key);
            JSONObject totalRs = (JSONObject) totalMap.get(key);
            JSONObject onRelyRs = (JSONObject) onRelyMap.get(key);
            //合并结果集
            Long totalNm = totalRs.getLong("num");
            Long relyNm = relyRs.getLong("num");
            Long noRelyNm = onRelyRs.getLong("num");
            rs.put("name",relyRs.get("name"));
            rs.put("noRelyCount",noRelyNm);
            rs.put("relyCount",relyNm);
            rs.put("total",totalNm);
            rs.put("code",key);
            if(totalNm !=null&&totalNm!=0){
                if(relyNm!=null&&relyNm!=0){
                    double rr = (double)relyNm/totalNm*100;
                    DecimalFormat df  = new DecimalFormat("0.00");
                    rs.put("relyRate",df.format(rr)+"%");
                    rs.put("relyDoubleRate",rr);
                }else{
                    rs.put("relyRate","0.00%");
                    rs.put("relyDoubleRate",0.0);
                }
                if(noRelyNm!=null&&noRelyNm!=0){
                    double rr = (double)noRelyNm/totalNm*100;
                    DecimalFormat df  = new DecimalFormat("0.00");
                    rs.put("noRelyRate",df.format(rr)+"%");
                    rs.put("noRelyDoubleRate",rr);
                }else{
                    rs.put("noRelyRate","0.00%");
                    rs.put("noRelyDoubleRate",0.0);
                }
            }else{
                rs.put("relyRate","0.00%");
                rs.put("relyDoubleRate",0.0);
                rs.put("noRelyRate","0.00%");
                rs.put("noRelyDoubleRate",0.0);
            rs.put("name", relyRs.get("name"));
            rs.put("noRelyCount", noRelyNm);
            rs.put("relyCount", relyNm);
            rs.put("total", totalNm);
            rs.put("code", key);
            if (totalNm != null && totalNm != 0) {
                if (relyNm != null && relyNm != 0) {
                    double rr = (double) relyNm / totalNm * 100;
                    DecimalFormat df = new DecimalFormat("0.00");
                    rs.put("relyRate", df.format(rr) + "%");
                    rs.put("relyDoubleRate", rr);
                } else {
                    rs.put("relyRate", "0.00%");
                    rs.put("relyDoubleRate", 0.0);
                }
                if (noRelyNm != null && noRelyNm != 0) {
                    double rr = (double) noRelyNm / totalNm * 100;
                    DecimalFormat df = new DecimalFormat("0.00");
                    rs.put("noRelyRate", df.format(rr) + "%");
                    rs.put("noRelyDoubleRate", rr);
                } else {
                    rs.put("noRelyRate", "0.00%");
                    rs.put("noRelyDoubleRate", 0.0);
                }
            } else {
                rs.put("relyRate", "0.00%");
                rs.put("relyDoubleRate", 0.0);
                rs.put("noRelyRate", "0.00%");
                rs.put("noRelyDoubleRate", 0.0);
            }
            resultMaps.add(rs);
        }
        //根据为回复数排序
        Collections.sort(resultMaps, new Comparator<Map<String,Object>>(){
        Collections.sort(resultMaps, new Comparator<Map<String, Object>>() {
            public int compare(Map<String,Object> o1,Map<String,Object> o2){
                return  (double)o1.get("noRelyDoubleRate")<(double)o2.get("noRelyDoubleRate")?1:( (double)o1.get("noRelyDoubleRate")==(double)o2.get("noRelyDoubleRate")?0:-1);
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                return (double) o1.get("noRelyDoubleRate") < (double) o2.get("noRelyDoubleRate") ? 1 : ((double) o1.get("noRelyDoubleRate") == (double) o2.get("noRelyDoubleRate") ? 0 : -1);
            }
        });
@ -1595,49 +1611,50 @@ public class StatisticsService extends BaseService {
    /**
     * 获取及时回复的时间分布
     *
     * @param level
     * @param area
     * @return
     */
    public JSONObject getCoutListByTime(String level,String area){
    public JSONObject getCoutListByTime(String level, String area) {
        JSONObject result = new JSONObject();
        if(StringUtils.isNotBlank(level)&&StringUtils.isNotBlank(area)){
        if (StringUtils.isNotBlank(level) && StringUtils.isNotBlank(area)) {
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            String relyVal = redisTemplate.opsForValue().get("quota:24:"+level+":"+area+":"+timeKey);
            String relyVal = redisTemplate.opsForValue().get("quota:24:" + level + ":" + area + ":" + timeKey);
            JSONArray array = new JSONArray(relyVal);
            result.put("resultList",array);
            result.put("resultList", array);
        }
        return result;
    }
    public JSONObject getAVGSocre(String level,String area){
    public JSONObject getAVGSocre(String level, String area) {
        String sql = "SELECT ROUND(AVG(s.score),1) avgCount FROM wlyy_evaluate_score s ,wlyy_doctor d WHERE s.doctor = d.code ";
        //市级
        if("4".equals(level)){
            sql +=" AND d.city = ? ";
        //区级
        }else if("3".equals(level)){
            sql +=" AND d.town = ? ";
        //机构
        }else if("2".equals(level)){
            sql +=" AND d.hospital = ? ";
        if ("4".equals(level)) {
            sql += " AND d.city = ? ";
            //区级
        } else if ("3".equals(level)) {
            sql += " AND d.town = ? ";
            //机构
        } else if ("2".equals(level)) {
            sql += " AND d.hospital = ? ";
        }
        Map<String,Object> rs = jdbcTemplate.queryForMap(sql,new Object[]{area});
        Map<String, Object> rs = jdbcTemplate.queryForMap(sql, new Object[]{area});
        JSONObject json = new JSONObject();
        json.put("rs",rs);
        json.put("rs", rs);
        return json;
    }
    public JSONArray getAVGSocreByMonth(String level ,String area,String statDate,String endDate)throws  Exception{
    public JSONArray getAVGSocreByMonth(String level, String area, String statDate, String endDate) throws Exception {
        List<String> times =  getMonthBetween(statDate,endDate);
        if(times==null||times.size()==0){
        List<String> times = getMonthBetween(statDate, endDate);
        if (times == null || times.size() == 0) {
            throw new Exception("时间区间错误");
        }
@ -1647,38 +1664,38 @@ public class StatisticsService extends BaseService {
                "  LEFT JOIN wlyy_evaluate_score s ON s.doctor = t.doctor" +
                " WHERE t.czrq >=? AND t.czrq <=?";
        //市级
        if("4".equals(level)){
            sql +=" AND d.city = ? ";
        if ("4".equals(level)) {
            sql += " AND d.city = ? ";
            //区级
        }else if("3".equals(level)){
            sql +=" AND d.town = ? ";
        } else if ("3".equals(level)) {
            sql += " AND d.town = ? ";
            //机构
        }else if("2".equals(level)){
            sql +=" AND d.hospital = ? ";
        } else if ("2".equals(level)) {
            sql += " AND d.hospital = ? ";
        }
        sql +=" GROUP BY mt order by mt DESC ";
        sql += " GROUP BY mt order by mt DESC ";
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql,new Object[]{statDate,endDate,area});
        Map<String,Object> map = new HashMap<>();
        if(rs!=null&&rs.size()>0){
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql, new Object[]{statDate, endDate, area});
        Map<String, Object> map = new HashMap<>();
        if (rs != null && rs.size() > 0) {
            //降低循环层级
            for(Map<String,Object> m : rs){
                map.put((String)m.get("mt"),m);
            for (Map<String, Object> m : rs) {
                map.put((String) m.get("mt"), m);
            }
        }
        JSONArray jsRs = new JSONArray();
        for(String time : times){
            JSONObject json   = new JSONObject();
            json.put("month",time);
            json.put("socre",map.get(time)==null?0:((Map<String,Object>)map.get(time)).get("avgCount"));
        for (String time : times) {
            JSONObject json = new JSONObject();
            json.put("month", time);
            json.put("socre", map.get(time) == null ? 0 : ((Map<String, Object>) map.get(time)).get("avgCount"));
            jsRs.put(json);
        }
        return jsRs;
    }
    private  List<String> getMonthBetween(String minDate, String maxDate) throws Exception {
    private List<String> getMonthBetween(String minDate, String maxDate) throws Exception {
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月
@ -1700,26 +1717,26 @@ public class StatisticsService extends BaseService {
        return result;
    }
    public String getAvgAllInfo(int level ,String area,String lowLevel){
    public String getAvgAllInfo(int level, String area, String lowLevel) {
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        String rs = "";
        //市级
        if(level==4){
            if(StringUtils.isBlank(lowLevel)){
                rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":3:"+timeKey);
            }else{
                rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":2:"+timeKey);
            }
        } else if(level ==3){
            rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":2:"+timeKey);
        }else if(level ==2){
            String rstemp = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":1:"+timeKey);
        if (level == 4) {
            if (StringUtils.isBlank(lowLevel)) {
                rs = redisTemplate.opsForValue().get("quota:28:" + level + ":" + area + ":3:" + timeKey);
            } else {
                rs = redisTemplate.opsForValue().get("quota:28:" + level + ":" + area + ":2:" + timeKey);
            }
        } else if (level == 3) {
            rs = redisTemplate.opsForValue().get("quota:28:" + level + ":" + area + ":2:" + timeKey);
        } else if (level == 2) {
            String rstemp = redisTemplate.opsForValue().get("quota:28:" + level + ":" + area + ":1:" + timeKey);
            JSONObject jsonObject = new JSONObject(rstemp);
            JSONArray json = jsonObject.getJSONArray("data");
            statisticsAllService.translateTeamLeaderName(json);
            JSONObject rsjs = new JSONObject();
            rsjs.put("data",json);
            rsjs.put("data", json);
            rs = rsjs.toString();
        }
        return rs;
@ -1727,61 +1744,62 @@ public class StatisticsService extends BaseService {
    /**
     * 统计当前团队,签约人数,服务次数,平均满意度
     *
     * @return
     */
    public JSONArray getStatTitleInfo(String doctor,String startDate,String endDate)throws Exception{
    public JSONArray getStatTitleInfo(String doctor, String startDate, String endDate) throws Exception {
        JSONArray rs = new JSONArray();
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //1.统计签约数据
        //查找团队签约
        String sign_sql = "SELECT COUNT(1) signCount FROM wlyy_sign_family t WHERE t.admin_team_code ="+id+" AND t.czrq >='"+startDate+"' AND t.czrq<='"+endDate+"' AND t.status =1 AND t.expenses_status ='1'";
        String sign_sql = "SELECT COUNT(1) signCount FROM wlyy_sign_family t WHERE t.admin_team_code =" + id + " AND t.czrq >='" + startDate + "' AND t.czrq<='" + endDate + "' AND t.status =1 AND t.expenses_status ='1'";
        //查找续签表未转移的记录
        String renew_sql = "SELECT COUNT(1) renewCount FROM wlyy_sign_family_renew t WHERE t.admin_team_code ="+id+" AND t.czrq >='"+startDate+"' AND t.czrq<='"+endDate+"' AND t.status =1 AND t.expenses_status ='1' AND t.is_valid =0";
        String renew_sql = "SELECT COUNT(1) renewCount FROM wlyy_sign_family_renew t WHERE t.admin_team_code =" + id + " AND t.czrq >='" + startDate + "' AND t.czrq<='" + endDate + "' AND t.status =1 AND t.expenses_status ='1' AND t.is_valid =0";
        //3.平均满意度
        String avg_sql="SELECT ROUND(AVG(s.score),1) avgScore FROM wlyy_consult c LEFT JOIN wlyy_evaluate_score s ON c.`code` = s.consult WHERE c.czrq>='"+startDate+"' AND c.czrq<='"+endDate+"' AND s.doctor in(select m.doctor_code from wlyy_admin_team_member m where m.team_id="+id+")";
        String avg_sql = "SELECT ROUND(AVG(s.score),1) avgScore FROM wlyy_consult c LEFT JOIN wlyy_evaluate_score s ON c.`code` = s.consult WHERE c.czrq>='" + startDate + "' AND c.czrq<='" + endDate + "' AND s.doctor in(select m.doctor_code from wlyy_admin_team_member m where m.team_id=" + id + ")";
        //计算签约表记录
        Map<String,Object> signCount = jdbcTemplate.queryForMap(sign_sql);
        Map<String, Object> signCount = jdbcTemplate.queryForMap(sign_sql);
        //计算续签表记录
        Map<String,Object> renewCount = jdbcTemplate.queryForMap(renew_sql);
        Map<String, Object> renewCount = jdbcTemplate.queryForMap(renew_sql);
        //计算签约总数
        Long sc = (Long)signCount.get("signCount");
        Long rc = (Long)renewCount.get("renewCount");
        Long sc = (Long) signCount.get("signCount");
        Long rc = (Long) renewCount.get("renewCount");
        JSONObject signTotal =new JSONObject();
        signTotal.put("signTotal",sc+rc);
        JSONObject signTotal = new JSONObject();
        signTotal.put("signTotal", sc + rc);
        rs.put(signTotal);
        //获取咨詢數
        Map<String,Object> consultCout= getConsultByteam(id ,startDate ,endDate);
        Map<String, Object> consultCout = getConsultByteam(id, startDate, endDate);
        rs.put(consultCout);
        //获取待预约
        Map<String,Object> reservationCout = getReservationByteam(id ,startDate ,endDate);
        Map<String, Object> reservationCout = getReservationByteam(id, startDate, endDate);
        rs.put(reservationCout);
        //获取健康教育
        Map<String,Object> articleCout= getEduArticleByTeam(id,startDate,endDate);
        Map<String, Object> articleCout = getEduArticleByTeam(id, startDate, endDate);
        rs.put(articleCout);
        //获取健康指导
        Map<String,Object> guidanceCout= getGuidanceByTeam(id,startDate,endDate);
        Map<String, Object> guidanceCout = getGuidanceByTeam(id, startDate, endDate);
        rs.put(guidanceCout);
        //随访数目
        Map<String,Object> followupCout= getArticleByTeam(id,startDate,endDate);
        Map<String, Object> followupCout = getArticleByTeam(id, startDate, endDate);
        rs.put(followupCout);
        //平均满意度
        Map<String,Object> avgCout= jdbcTemplate.queryForMap(avg_sql);
        if(avgCout.get("avgScore")==null){
            avgCout.put("avgScore",0);
        Map<String, Object> avgCout = jdbcTemplate.queryForMap(avg_sql);
        if (avgCout.get("avgScore") == null) {
            avgCout.put("avgScore", 0);
        }
        rs.put(avgCout);
@ -1791,94 +1809,96 @@ public class StatisticsService extends BaseService {
    /**
     * 查询签约
     * @param type 0 按周,1 按月
     *
     * @param type      0 按周,1 按月
     * @param startDate
     * @param endDate
     * @return
     */
    public JSONArray getSignCountLineByType(String doctor,String type,String startDate,String endDate){
    public JSONArray getSignCountLineByType(String doctor, String type, String startDate, String endDate) {
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        String sql;
        //按周
        if("0".equals(type)){
           sql = "SELECT left(f.apply_date,10) as applyDate,count(1) as signCount " +
                   " FROM wlyy_sign_family f " +
                   " where f.apply_date >='"+startDate+" 00:00:00' " +
                   " AND f.apply_date<='"+endDate+" 00:00:00' " +
                   " AND f.status >0 " +
                   " AND f.expenses_status='1' " +
                   " AND f.admin_team_code="+id+
                   " GROUP BY left(f.apply_date,10)";
        //按月
        }else{
            sql ="SELECT (DATE_FORMAT(f.apply_date,'%v')-DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"','%v')+1) as weekOfMonth,count(1) as signCount " +
        if ("0".equals(type)) {
            sql = "SELECT left(f.apply_date,10) as applyDate,count(1) as signCount " +
                    " FROM wlyy_sign_family f " +
                    " where f.apply_date >='"+startDate+" 00:00:00' " +
                    " AND f.apply_date<='"+endDate+" 00:00:00' " +
                    " where f.apply_date >='" + startDate + " 00:00:00' " +
                    " AND f.apply_date<='" + endDate + " 00:00:00' " +
                    " AND f.status >0 " +
                    " AND f.expenses_status='1' " +
                    " AND f.admin_team_code="+id+
                    " AND f.admin_team_code=" + id +
                    " GROUP BY left(f.apply_date,10)";
            //按月
        } else {
            sql = "SELECT (DATE_FORMAT(f.apply_date,'%v')-DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "','%v')+1) as weekOfMonth,count(1) as signCount " +
                    " FROM wlyy_sign_family f " +
                    " where f.apply_date >='" + startDate + " 00:00:00' " +
                    " AND f.apply_date<='" + endDate + " 00:00:00' " +
                    " AND f.status >0 " +
                    " AND f.expenses_status='1' " +
                    " AND f.admin_team_code=" + id +
                    " GROUP BY DATE_FORMAT(f.apply_date,'%m %v')";
        }
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
        JSONArray rsJs = new JSONArray(rs);
        return rsJs;
    }
    /**
     * 查询续签约
     * @param type 0 按周,1 按月
     *
     * @param type      0 按周,1 按月
     * @param startDate
     * @param endDate
     * @return
     */
    public JSONArray getRenewCountLineByType(String doctor,String type,String startDate,String endDate){
    public JSONArray getRenewCountLineByType(String doctor, String type, String startDate, String endDate) {
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        String sql;
        //按周
        if("0".equals(type)){
        if ("0".equals(type)) {
            sql = "SELECT left(f.apply_date,10) as applyDate,count(1) as signCount " +
                    " FROM wlyy_sign_family_renew f " +
                    " where f.apply_date >='"+startDate+" 00:00:00' " +
                    " AND f.apply_date<='"+endDate+" 23:59:59' " +
                    " where f.apply_date >='" + startDate + " 00:00:00' " +
                    " AND f.apply_date<='" + endDate + " 23:59:59' " +
                    " AND f.status >0 " +
                    " AND f.expenses_status='1' " +
                    " AND f.admin_team_code="+id+
                    " AND f.admin_team_code=" + id +
                    " GROUP BY left(f.apply_date,10)";
            //按月
        }else{
            sql ="SELECT (DATE_FORMAT(f.apply_date,'%v')-DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"','%v')+1) as weekOfMonth,count(1) as signCount " +
        } else {
            sql = "SELECT (DATE_FORMAT(f.apply_date,'%v')-DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "','%v')+1) as weekOfMonth,count(1) as signCount " +
                    " FROM wlyy_sign_family_renew f " +
                    " where f.apply_date >='"+startDate+" 00:00:00' " +
                    " AND f.apply_date<='"+endDate+" 23:59:59' " +
                    " where f.apply_date >='" + startDate + " 00:00:00' " +
                    " AND f.apply_date<='" + endDate + " 23:59:59' " +
                    " AND f.status >0 " +
                    " AND f.expenses_status='1' " +
                    " AND f.admin_team_code="+id+
                    " AND f.admin_team_code=" + id +
                    " GROUP BY DATE_FORMAT(f.apply_date,'%m %v')";
        }
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
        JSONArray rsJs = new JSONArray(rs);
        return rsJs;
    }
    public JSONObject getReyStatbyTeam(String doctor,String startDate,String endDate,String isNow){
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
    public JSONObject getReyStatbyTeam(String doctor, String startDate, String endDate, String isNow) {
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
@ -1886,81 +1906,81 @@ public class StatisticsService extends BaseService {
        String noRelysql = "SELECT q.result FROM wlyy_quota_result q " +
                " WHERE q.quato_code ='22' " +
                " AND q.level1_type ='1' " +
                " AND q.quota_date ='"+startDate+"'" +
                " AND q.qkdoctor_code ='"+id+"';";
                " AND q.quota_date ='" + startDate + "'" +
                " AND q.qkdoctor_code ='" + id + "';";
        //查找起始时间咨询总数
        String totalsql = "SELECT q.result FROM wlyy_quota_result q " +
                " WHERE q.quato_code ='25' " +
                " AND q.level1_type ='1' " +
                " AND q.quota_date ='"+startDate+"' " +
                " AND q.qkdoctor_code ='"+id+"'";
                " AND q.quota_date ='" + startDate + "' " +
                " AND q.qkdoctor_code ='" + id + "'";
        List<Map<String,Object>> noRelyList = jdbcTemplate.queryForList(noRelysql);
        Long noRelystartCount =0L;
        List<Map<String, Object>> noRelyList = jdbcTemplate.queryForList(noRelysql);
        Long noRelystartCount = 0L;
        Long totalstartCount = 0L;
        if(noRelyList!=null&&noRelyList.size()>0){
            Map<String,Object> noRelyMap =noRelyList.get(0);
            noRelystartCount = Long.parseLong((String)noRelyMap.get("result"));
        if (noRelyList != null && noRelyList.size() > 0) {
            Map<String, Object> noRelyMap = noRelyList.get(0);
            noRelystartCount = Long.parseLong((String) noRelyMap.get("result"));
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalsql);
        if(totalList!=null&&totalList.size()>0){
            Map<String,Object> totalMap =totalList.get(0);
            totalstartCount = Long.parseLong((String)totalMap.get("result"));
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalsql);
        if (totalList != null && totalList.size() > 0) {
            Map<String, Object> totalMap = totalList.get(0);
            totalstartCount = Long.parseLong((String) totalMap.get("result"));
        }
        Long noRelyEndCount =0L;
        Long totalEndCount =0L;
        if("1".equals(isNow)){
        Long noRelyEndCount = 0L;
        Long totalEndCount = 0L;
        if ("1".equals(isNow)) {
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            //当前时间获取未回复咨询总数
            String noReyVal = redisTemplate.opsForValue().get("quota:22:1:"+id+":"+timeKey);
            if(StringUtils.isBlank(noReyVal)){
            String noReyVal = redisTemplate.opsForValue().get("quota:22:1:" + id + ":" + timeKey);
            if (StringUtils.isBlank(noReyVal)) {
                throw new RuntimeException("未找到截止日期数据");
            }
            JSONObject nr = new JSONObject(noReyVal);
            noRelyEndCount = nr.getLong("num");
            //获取当前时间咨询总数
            String totalVal = redisTemplate.opsForValue().get("quota:25:1:"+id+":"+timeKey);
            if(StringUtils.isBlank(totalVal)){
            String totalVal = redisTemplate.opsForValue().get("quota:25:1:" + id + ":" + timeKey);
            if (StringUtils.isBlank(totalVal)) {
                throw new RuntimeException("未找到截止日期数据");
            }
            JSONObject tr = new JSONObject(totalVal);
            totalEndCount = tr.getLong("num");
        }else{
        } else {
            //查找结束时间未回复总数
            String noRelyEndsql = "SELECT q.result FROM wlyy_quota_result q " +
                    " WHERE q.quato_code ='22' " +
                    " AND q.level1_type ='1' " +
                    " AND q.quota_date ='"+endDate+"'" +
                    " AND q.qkdoctor_code ='"+id+"';";
                    " AND q.quota_date ='" + endDate + "'" +
                    " AND q.qkdoctor_code ='" + id + "';";
            //查找结束时间咨询总数
            String totalEndsql = "SELECT q.result FROM wlyy_quota_result q " +
                    " WHERE q.quato_code ='25' " +
                    " AND q.level1_type ='1' " +
                    " AND q.quota_date ='"+startDate+"' " +
                    " AND q.qkdoctor_code ='"+id+"'";
            List<Map<String,Object>> noRelyEndList = jdbcTemplate.queryForList(noRelyEndsql);
            if(noRelyEndList!=null&&noRelyEndList.size()>0){
                Map<String,Object> noRelyEndMap = noRelyEndList.get(0);
                noRelyEndCount = Long.parseLong((String)noRelyEndMap.get("result"));
                    " AND q.quota_date ='" + startDate + "' " +
                    " AND q.qkdoctor_code ='" + id + "'";
            List<Map<String, Object>> noRelyEndList = jdbcTemplate.queryForList(noRelyEndsql);
            if (noRelyEndList != null && noRelyEndList.size() > 0) {
                Map<String, Object> noRelyEndMap = noRelyEndList.get(0);
                noRelyEndCount = Long.parseLong((String) noRelyEndMap.get("result"));
            }
            List<Map<String,Object>> totalEndList = jdbcTemplate.queryForList(totalEndsql);
            if(totalEndList!=null&&totalEndList.size()>0){
                Map<String,Object> totalEndMap = totalEndList.get(0);
                totalEndCount = Long.parseLong((String)totalEndMap.get("result"));
            List<Map<String, Object>> totalEndList = jdbcTemplate.queryForList(totalEndsql);
            if (totalEndList != null && totalEndList.size() > 0) {
                Map<String, Object> totalEndMap = totalEndList.get(0);
                totalEndCount = Long.parseLong((String) totalEndMap.get("result"));
            }
        }
        JSONObject rs = new JSONObject();
        rs.put("onReyCount",noRelyEndCount-noRelystartCount);
        rs.put("totalCount",totalEndCount-totalstartCount);
        rs.put("onReyCount", noRelyEndCount - noRelystartCount);
        rs.put("totalCount", totalEndCount - totalstartCount);
        return rs;
    }
    public JSONArray getServiceRankingList(String doctor ,String startDate,String endDate){
    public JSONArray getServiceRankingList(String doctor, String startDate, String endDate) {
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
@ -1974,48 +1994,48 @@ public class StatisticsService extends BaseService {
                "   FROM (" +
                "       SELECT COUNT(1) AS count,w.admin_team_code " +
                "       FROM wlyy_consult_team  w " +
                "       WHERE w.czrq>='"+startDate+" 00:00:00' AND w.czrq <='"+endDate+" 23:59:59' AND w.admin_team_code IN( " +
                "       WHERE w.czrq>='" + startDate + " 00:00:00' AND w.czrq <='" + endDate + " 23:59:59' AND w.admin_team_code IN( " +
                "       SELECT " +
                "       m.id FROM wlyy_admin_team m " +
                "       WHERE m.org_code ='"+orgcode+"'" +
                "       WHERE m.org_code ='" + orgcode + "'" +
                "       ) " +
                "   GROUP BY w.admin_team_code " +
                "   ORDER BY count DESC " +
                "   )t," +
                "   (SELECT(@rowNum := 0)) b " +
                " ) s " +
                " WHERE s.admin_team_code ="+id;
        List<Map<String,Object>> crc = jdbcTemplate.queryForList(crc_sql);
        if(crc!=null&&crc.size()>0){
                " WHERE s.admin_team_code =" + id;
        List<Map<String, Object>> crc = jdbcTemplate.queryForList(crc_sql);
        if (crc != null && crc.size() > 0) {
            rs.put(crc.get(0));
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("consultRK",0);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("consultRK", 0);
            rs.put(map);
        }
        //随访量排行
        String frc_sql ="SELECT s.rowno AS followupRK FROM " +
        String frc_sql = "SELECT s.rowno AS followupRK FROM " +
                "( " +
                " select (@rowNum :=@rowNum + 1) AS rowno,t.count,t.admin_team_code  " +
                " from ( " +
                " SELECT COUNT(1) AS count,w.admin_team_code " +
                " FROM wlyy_followup  w " +
                " WHERE w.org_code = '"+orgcode+"'  " +
                " WHERE w.org_code = '" + orgcode + "'  " +
                " AND w.admin_team_code IS NOT NULL " +
                " AND w.create_time >='"+startDate+" 00:00:00' AND w.create_time <='"+endDate+" 23:59:59'"+
                " AND w.create_time >='" + startDate + " 00:00:00' AND w.create_time <='" + endDate + " 23:59:59'" +
                " GROUP BY w.admin_team_code  " +
                " ORDER BY count DESC " +
                " ) t, " +
                " (SELECT(@rowNum := 0)) b " +
                ") s  " +
                "WHERE s.admin_team_code ="+id;
        List<Map<String,Object>> frc = jdbcTemplate.queryForList(frc_sql);
        if(frc!=null&&frc.size()>0){
                "WHERE s.admin_team_code =" + id;
        List<Map<String, Object>> frc = jdbcTemplate.queryForList(frc_sql);
        if (frc != null && frc.size() > 0) {
            rs.put(frc.get(0));
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("followupRK",0);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("followupRK", 0);
            rs.put(map);
        }
        //待预约量排行
@ -2025,73 +2045,73 @@ public class StatisticsService extends BaseService {
                "   FROM ( " +
                "   SELECT COUNT(1) AS reservationCount,w.admin_team_code " +
                "   FROM wlyy_patient_reservation  w " +
                "   WHERE w.czrq>='"+startDate+" 00:00:00' AND w.czrq <='"+endDate+" 23:59:59' AND " +
                "   w.org_code ='"+orgcode+"'" +
                "   WHERE w.czrq>='" + startDate + " 00:00:00' AND w.czrq <='" + endDate + " 23:59:59' AND " +
                "   w.org_code ='" + orgcode + "'" +
                "   AND w.doctor is not null " +
                "   AND w.admin_team_code IS NOT NULL " +
                "   GROUP BY w.admin_team_code " +
                "   ORDER BY reservationCount DESC " +
                "   ) t,(SELECT(@rowNum := 0)) b " +
                ") s  " +
                "WHERE s.admin_team_code ="+id;
        List<Map<String,Object>> resrc = jdbcTemplate.queryForList(resrc_sql);
        if(resrc!=null&&resrc.size()>0){
                "WHERE s.admin_team_code =" + id;
        List<Map<String, Object>> resrc = jdbcTemplate.queryForList(resrc_sql);
        if (resrc != null && resrc.size() > 0) {
            rs.put(resrc.get(0));
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("reservationRK",0);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("reservationRK", 0);
            rs.put(map);
        }
        //健康指导排行
        String grc_sql ="SELECT s.rowno AS guidanceRK FROM " +
        String grc_sql = "SELECT s.rowno AS guidanceRK FROM " +
                "( " +
                " SELECT (@rowNum :=@rowNum + 1) AS rowno,t.count,t.admin_team_code " +
                " FROM (" +
                " SELECT COUNT(1) AS count,w.admin_team_code " +
                " FROM wlyy_patient_health_guidance w " +
                " WHERE w.czrq>='"+startDate+" 00:00:00' AND w.czrq <='"+endDate+" 23:59:59' " +
                " WHERE w.czrq>='" + startDate + " 00:00:00' AND w.czrq <='" + endDate + " 23:59:59' " +
                " AND  w.admin_team_code IN( " +
                " SELECT m.id FROM wlyy_admin_team m" +
                "   WHERE m.org_code ='"+orgcode+"'" +
                "   WHERE m.org_code ='" + orgcode + "'" +
                "   ) " +
                " GROUP BY w.admin_team_code " +
                " ORDER BY count DESC " +
                "   ) t," +
                "(SELECT(@rowNum := 0)) b " +
                " ) s " +
                "WHERE s.admin_team_code ="+id;
        List<Map<String,Object>> grc = jdbcTemplate.queryForList(grc_sql);
        if(grc!=null&&grc.size()>0){
                "WHERE s.admin_team_code =" + id;
        List<Map<String, Object>> grc = jdbcTemplate.queryForList(grc_sql);
        if (grc != null && grc.size() > 0) {
            rs.put(grc.get(0));
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("guidanceRK",0);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("guidanceRK", 0);
            rs.put(map);
        }
        //健康教育排行
        String edurc_sql ="SELECT s.rowno AS articleRK FROM " +
        String edurc_sql = "SELECT s.rowno AS articleRK FROM " +
                "( " +
                " SELECT (@rowNum :=@rowNum + 1) AS rowno,t.count,t.admin_team_code " +
                " FROM ( " +
                " SELECT COUNT(1) AS count,w.admin_team_code " +
                " FROM wlyy_health_edu_article_patient w " +
                " WHERE w.czrq>='"+startDate+" 00:00:00' AND w.czrq <='"+endDate+" 23:59:59' AND " +
                " WHERE w.czrq>='" + startDate + " 00:00:00' AND w.czrq <='" + endDate + " 23:59:59' AND " +
                " w.admin_team_code IN(" +
                " SELECT m.id FROM wlyy_admin_team m " +
                " WHERE m.org_code ='"+orgcode+"'" +
                " WHERE m.org_code ='" + orgcode + "'" +
                "   ) " +
                "   GROUP BY w.admin_team_code " +
                "   ORDER BY count DESC " +
                ") t," +
                "(SELECT(@rowNum := 0)) b" +
                ") s " +
                "WHERE s.admin_team_code ="+id;
        List<Map<String,Object>> edurc = jdbcTemplate.queryForList(edurc_sql);
        if(edurc!=null&&edurc.size()>0){
                "WHERE s.admin_team_code =" + id;
        List<Map<String, Object>> edurc = jdbcTemplate.queryForList(edurc_sql);
        if (edurc != null && edurc.size() > 0) {
            rs.put(edurc.get(0));
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("articleRK",0);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("articleRK", 0);
            rs.put(map);
        }
        return rs;
@ -2099,123 +2119,125 @@ public class StatisticsService extends BaseService {
    /**
     * 获取咨询数
     *
     * @param id
     * @param startDate
     * @param endDate
     * @return
     */
    public Map<String,Object> getConsultByteam(Long id ,String startDate ,String endDate){
    public Map<String, Object> getConsultByteam(Long id, String startDate, String endDate) {
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        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) AS consultCount FROM wlyy_consult_team t WHERE t.admin_team_code = " + id + " AND t.czrq <='" + endDate + "' AND t.czrq >='" + startDate + "'";
        //获取咨詢數
        Map<String,Object> consultCout= jdbcTemplate.queryForMap(consult_sql);
        if(consultCout.get("consultCount")==null){
            consultCout.put("consultCount",0);
        Map<String, Object> consultCout = jdbcTemplate.queryForMap(consult_sql);
        if (consultCout.get("consultCount") == null) {
            consultCout.put("consultCount", 0);
        }
        return consultCout;
    }
    public Map<String,Object> getReservationByteam(Long id ,String startDate ,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public Map<String, Object> getReservationByteam(Long id, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //获取待预约
        String reservation_sql = "SELECT COUNT(1) AS reservationCount FROM wlyy_patient_reservation  w WHERE w.admin_team_code ="+id+" AND w.czrq <='"+endDate+"' AND w.czrq >='"+startDate+"'";
        String reservation_sql = "SELECT COUNT(1) AS reservationCount FROM wlyy_patient_reservation  w WHERE w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "'";
        //获取待预约
        Map<String,Object> reservationCout= jdbcTemplate.queryForMap(reservation_sql);
        if(reservationCout.get("reservationCount")==null){
            reservationCout.put("reservationCount",0);
        Map<String, Object> reservationCout = jdbcTemplate.queryForMap(reservation_sql);
        if (reservationCout.get("reservationCount") == null) {
            reservationCout.put("reservationCount", 0);
        }
        return reservationCout;
    }
    public Map<String,Object> getEduArticleByTeam(Long id ,String startDate ,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public Map<String, Object> getEduArticleByTeam(Long id, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //获取健康教育
        String article_sql = "SELECT COUNT(1) AS articleCount FROM wlyy_health_edu_article_patient w WHERE  w.admin_team_code ="+id+" AND w.czrq <='"+endDate+"' AND w.czrq >='"+startDate+"'";
        String article_sql = "SELECT COUNT(1) AS articleCount FROM wlyy_health_edu_article_patient w WHERE  w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "'";
        //获取健康教育
        Map<String,Object> articleCout= jdbcTemplate.queryForMap(article_sql);
        if(articleCout.get("articleCount")==null){
            articleCout.put("articleCount",0);
        Map<String, Object> articleCout = jdbcTemplate.queryForMap(article_sql);
        if (articleCout.get("articleCount") == null) {
            articleCout.put("articleCount", 0);
        }
        return articleCout;
    }
    public Map<String,Object> getGuidanceByTeam(Long id ,String startDate ,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public Map<String, Object> getGuidanceByTeam(Long id, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //获取健康指导
        String guidance_sql = "SELECT COUNT(1) AS guidanceCount  FROM wlyy_patient_health_guidance w WHERE w.admin_team_code ="+id+" AND w.czrq <='"+endDate+"' AND w.czrq >='"+startDate+"'";
        String guidance_sql = "SELECT COUNT(1) AS guidanceCount  FROM wlyy_patient_health_guidance w WHERE w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "'";
        //获取健康指导
        Map<String,Object> guidanceCout= jdbcTemplate.queryForMap(guidance_sql);
        if(guidanceCout.get("guidanceCount")==null){
            guidanceCout.put("guidanceCount",0);
        Map<String, Object> guidanceCout = jdbcTemplate.queryForMap(guidance_sql);
        if (guidanceCout.get("guidanceCount") == null) {
            guidanceCout.put("guidanceCount", 0);
        }
        return guidanceCout;
    }
    public Map<String,Object> getArticleByTeam(Long id ,String startDate ,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public Map<String, Object> getArticleByTeam(Long id, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //随访数目
        String followup_sql ="SELECT COUNT(1) AS followupCount from wlyy_followup w WHERE w.admin_team_code="+id+" AND  w.create_time >='"+startDate+"' AND w.create_time<='"+endDate+"' AND w.followup_class IS NOT NULL ";
        String followup_sql = "SELECT COUNT(1) AS followupCount from wlyy_followup w WHERE w.admin_team_code=" + id + " AND  w.create_time >='" + startDate + "' AND w.create_time<='" + endDate + "' AND w.followup_class IS NOT NULL ";
        //随访数目
        Map<String,Object> followupCout= jdbcTemplate.queryForMap(followup_sql);
        if(followupCout.get("followupCount")==null){
            followupCout.put("followupCount",0);
        Map<String, Object> followupCout = jdbcTemplate.queryForMap(followup_sql);
        if (followupCout.get("followupCount") == null) {
            followupCout.put("followupCount", 0);
        }
        return followupCout;
    }
    /***
     * 获取平均折线图
     *
     * @param doctor
     * @param startDate
     * @param endDate
     * @param type 0 周,1月
     * @param type      0 周,1月
     * @return
     */
    public JSONArray getAvgLine(String doctor,String startDate,String endDate,String type){
    public JSONArray getAvgLine(String doctor, String startDate, String endDate, String type) {
        AdminTeam admin =  adminTeamDao.findByLeaderCode(doctor);
        if(admin==null){
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String sql ;
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String sql;
        //周计算
        if("0".equals(type)){
        if ("0".equals(type)) {
            sql = "SELECT DATE_FORMAT(t.czrq,'%Y-%m-%d') AS dateNo,ifnull(ROUND(AVG(s.score),1),0)  as avgCount " +
                    "    FROM  wlyy_consult_team t" +
                    "    LEFT JOIN wlyy_doctor d ON d.code = t.doctor " +
                    "    LEFT JOIN wlyy_evaluate_score s ON s.doctor = t.doctor  " +
                    " WHERE t.czrq <='"+endDate+"' AND t.czrq >='"+startDate+"'" +
                    " AND t.admin_team_code =" +id+
                    " WHERE t.czrq <='" + endDate + "' AND t.czrq >='" + startDate + "'" +
                    " AND t.admin_team_code =" + id +
                    " GROUP BY dateNo ";
        }else{
            sql = "SELECT (DATE_FORMAT(t.czrq,'%v')-DATE_FORMAT('"+startDate+"','%v')+1) AS weekNo,ifnull(ROUND(AVG(s.score),1),0)  as avgCount " +
        } else {
            sql = "SELECT (DATE_FORMAT(t.czrq,'%v')-DATE_FORMAT('" + startDate + "','%v')+1) AS weekNo,ifnull(ROUND(AVG(s.score),1),0)  as avgCount " +
                    "    FROM  wlyy_consult_team t " +
                    "    LEFT JOIN wlyy_doctor d ON d.code = t.doctor " +
                    "    LEFT JOIN wlyy_evaluate_score s ON s.doctor = t.doctor " +
                    " WHERE t.czrq <='"+endDate+"' AND t.czrq >='"+startDate+"'" +
                    " AND t.admin_team_code =" +id+
                    " WHERE t.czrq <='" + endDate + "' AND t.czrq >='" + startDate + "'" +
                    " AND t.admin_team_code =" + id +
                    " GROUP BY weekNo";
        }
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
        JSONArray js = new JSONArray(rs);
        return js;
    }
    public JSONObject checkDoctorIsTeamleader(String doctor){
    public JSONObject checkDoctorIsTeamleader(String doctor) {
        AdminTeam team = adminTeamDao.findByLeaderCode(doctor);
        if(team!=null){
        if (team != null) {
            return new JSONObject(team);
        }
        return null;
@ -2223,36 +2245,37 @@ public class StatisticsService extends BaseService {
    /**
     * 获取团队月或周咨询未回复和总数折线图
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param type 0周,1月
     * @param type      0周,1月
     * @return
     */
    public JSONObject getTeamConsultCount(String teamCode,String startDate,String endDate,String type){
    public JSONObject getTeamConsultCount(String teamCode, String startDate, String endDate, String type) {
        String imDataBaseName = SystemConf.getInstance().getImDataBaseName();
        String sql ;
        String totalSql ;
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        if("0".equals(type)){
        String sql;
        String totalSql;
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(a.czrq,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+
                    " 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, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
@ -2260,57 +2283,57 @@ public class StatisticsService extends BaseService {
                    " AND s.type = 1 " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '"+endDate+"'" +
                    " AND t.create_time >= '"+startDate+"'" +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
            totalSql ="SELECT " +
            totalSql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS total " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '"+endDate+"'" +
                    " AND a.czrq >= '"+startDate+"'" +
                    " AND a.admin_team_code ="+teamCode+
                    " 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, " +
                    " " + 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 t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
        }else{
        } else {
            //按月统计
            sql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1" +
                    " 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+
                    " 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, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
@ -2318,83 +2341,84 @@ public class StatisticsService extends BaseService {
                    " AND s.type = 1 " +
                    " AND t. STATUS <> 10 " +
                    " AND t.`reply` = 0 " +
                    " AND t.create_time <= '"+endDate+"'" +
                    " AND t.create_time >= '"+startDate+"'" +
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            totalSql ="SELECT " +
            totalSql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1" +
                    " 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+
                    " 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, " +
                    " " + 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 t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
        }
        List<Map<String,Object>> noReyList = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> noReyList = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        JSONObject result = new JSONObject();
        result.put("noReyList",noReyList);
        result.put("totalList",totalList);
        result.put("noReyList", noReyList);
        result.put("totalList", totalList);
        return result;
    }
    /**
     *  计算团队医生月或周咨询未回复和总数折线图
     * 计算团队医生月或周咨询未回复和总数折线图
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param type
     * @param doctor 医生code
     * @param doctor    医生code
     * @return
     */
    public JSONObject getTeamDoctorConsultCount(String teamCode,String startDate,String endDate,String type,String doctor){
    public JSONObject getTeamDoctorConsultCount(String teamCode, String startDate, String endDate, String type, String doctor) {
        String imDataBaseName = SystemConf.getInstance().getImDataBaseName();
        String sql ;
        String totalSql ;
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        if("0".equals(type)){
        String sql;
        String totalSql;
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(a.czrq,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+
                    " 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, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
@ -2402,59 +2426,59 @@ public class StatisticsService extends BaseService {
                    " 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+"'"+
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
            totalSql ="SELECT " +
            totalSql = "SELECT " +
                    " left(a.czrq,10) AS dateNo,count(1) AS total " +
                    " FROM " +
                    " wlyy_consult_team a " +
                    " WHERE" +
                    " a.czrq <= '"+endDate+"'" +
                    " AND a.czrq >= '"+startDate+"'" +
                    " AND a.admin_team_code ="+teamCode+
                    " 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, " +
                    " " + 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+"'"+
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY left(a.czrq,10)";
        }else{
        } else {
            //按月统计
            sql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1" +
                    " 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+
                    " 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, " +
                    " " + imDataBaseName + ".sessions s " +
                    " WHERE " +
                    " p.participant_id = d.id " +
                    " AND t.session_id = p.session_id " +
@ -2462,64 +2486,65 @@ public class StatisticsService extends BaseService {
                    " 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+"'"+
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
            totalSql ="SELECT " +
            totalSql = "SELECT " +
                    " ( " +
                    " DATE_FORMAT(a.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1" +
                    " 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+
                    " 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, " +
                    " " + 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+"'"+
                    " AND t.create_time <= '" + endDate + "'" +
                    " AND t.create_time >= '" + startDate + "'" +
                    " AND d.id = '" + doctor + "'" +
                    " )" +
                    " GROUP BY " +
                    " DATE_FORMAT(a.czrq, '%m %v')";
        }
        List<Map<String,Object>> noReyList = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> noReyList = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        JSONObject result = new JSONObject();
        result.put("noReyList",noReyList);
        result.put("totalList",totalList);
        result.put("noReyList", noReyList);
        result.put("totalList", totalList);
        return result;
    }
    /**
     * 获取团队咨询情况列表
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param sort 0降序 1升续
     * @param sort      0降序 1升续
     * @return
     */
    public JSONArray getMemberConsultList(String teamCode,String startDate,String endDate,String sort,String sortType){
    public JSONArray getMemberConsultList(String teamCode, String startDate, String endDate, String sort, String sortType) {
        String imDataBaseName = SystemConf.getInstance().getImDataBaseName();
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        // 未回复咨询总量
        String onReySQL = "SELECT " +
                " t.doctor_code AS doctorCode, " +
@ -2538,10 +2563,10 @@ public class StatisticsService extends BaseService {
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " "+imDataBaseName+".topics t, " +
                " "+imDataBaseName+".participants p, " +
                " "+imDataBaseName+".doctors d, " +
                " "+imDataBaseName+".sessions s " +
                " " + 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 " +
@ -2549,12 +2574,12 @@ public class StatisticsService extends BaseService {
                " AND s.type = 1 " +
                " AND t. STATUS <> 10 " +
                " AND t.`reply` = 0 " +
                " AND t.create_time <= '"+endDate+"' " +
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND t.create_time >= '" + startDate + "' " +
                " ) c" +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code = " +teamCode+
                " AND a.admin_team_code = " + teamCode +
                " GROUP BY " +
                " c.doctorCode " +
                " ) r ON r.doctorCode = t.doctor_code, " +
@ -2562,15 +2587,15 @@ public class StatisticsService extends BaseService {
                " WHERE " +
                " t.doctor_code = d.`code` " +
                " AND t.available = 1 " +
                " AND t.team_id = "+teamCode ;
        if("0".equals(sort)){
            onReySQL = onReySQL+ " ORDER BY noRely DESC";
        }else{
            onReySQL = onReySQL+ " ORDER BY noRely ASC";
                " AND t.team_id = " + teamCode;
        if ("0".equals(sort)) {
            onReySQL = onReySQL + " ORDER BY noRely DESC";
        } else {
            onReySQL = onReySQL + " ORDER BY noRely ASC";
        }
        //总咨询量
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " t.doctor_code AS doctorCode, " +
                " d.`name`, " +
                " IFNULL(r.total,0) AS total " +
@ -2587,21 +2612,21 @@ public class StatisticsService extends BaseService {
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " "+imDataBaseName+".topics t, " +
                " "+imDataBaseName+".participants p, " +
                " "+imDataBaseName+".doctors d, " +
                " "+imDataBaseName+".sessions s " +
                " " + 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 t.create_time <= '" + endDate + "' " +
                " AND t.create_time >= '" + startDate + "' " +
                " ) c " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code = " +teamCode+
                " AND a.admin_team_code = " + teamCode +
                " GROUP BY " +
                " c.doctorCode " +
                ") r ON r.doctorCode = t.doctor_code, " +
@ -2609,15 +2634,15 @@ public class StatisticsService extends BaseService {
                "WHERE " +
                " t.doctor_code = d.`code` " +
                "AND t.available = 1 " +
                "AND t.team_id =  "+teamCode ;
        if("0".equals(sort)){
            totalSql = totalSql+ " ORDER BY total DESC";
        }else{
            totalSql = totalSql+ " ORDER BY total ASC";
                "AND t.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            totalSql = totalSql + " ORDER BY total DESC";
        } else {
            totalSql = totalSql + " ORDER BY total ASC";
        }
        //结束咨询
        String endConsultSql ="SELECT " +
        String endConsultSql = "SELECT " +
                " t.doctor_code doctorCode, " +
                " d.`name`, " +
                " IFNULL(r.endRey,0) AS endRey " +
@ -2634,22 +2659,22 @@ public class StatisticsService extends BaseService {
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " "+imDataBaseName+".topics t, " +
                " "+imDataBaseName+".participants p, " +
                " "+imDataBaseName+".doctors d, " +
                " "+imDataBaseName+".sessions s " +
                " " + 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+"' " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND t.create_time >= '" + startDate + "' " +
                " ) c " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code =" +teamCode+
                " AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                " c.doctorCode " +
                ") r ON r.doctorCode = t.doctor_code, " +
@ -2657,101 +2682,101 @@ public class StatisticsService extends BaseService {
                " WHERE " +
                " t.doctor_code = d.`code` " +
                " AND t.available = 1 " +
                " AND t.team_id = "+teamCode;
        if("0".equals(sort)){
            endConsultSql = endConsultSql+ " ORDER BY endRey DESC";
        }else{
            endConsultSql = endConsultSql+ " ORDER BY endRey ASC";
                " AND t.team_id = " + teamCode;
        if ("0".equals(sort)) {
            endConsultSql = endConsultSql + " ORDER BY endRey DESC";
        } else {
            endConsultSql = endConsultSql + " ORDER BY endRey ASC";
        }
        List<Map<String,Object>> onReyList = jdbcTemplate.queryForList(onReySQL);
        Map<String,Object> onReyMap = new HashMap<>();
        List<Map<String, Object>> onReyList = jdbcTemplate.queryForList(onReySQL);
        Map<String, Object> onReyMap = new HashMap<>();
        //将List转换为Map降低循环层级
        if(onReyList!=null&&onReyList.size()>0){
            for(Map<String,Object> list :onReyList){
                String code = (String)list.get("doctorCode");
                onReyMap.put(code,list);
        if (onReyList != null && onReyList.size() > 0) {
            for (Map<String, Object> list : onReyList) {
                String code = (String) list.get("doctorCode");
                onReyMap.put(code, list);
            }
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        Map<String,Object> totalMap = new HashMap<>();
        Map<String, Object> totalMap = new HashMap<>();
        //将List转换为Map降低循环层级
        if(totalList!=null&&totalList.size()>0){
            for(Map<String,Object> list :totalList){
                String code = (String)list.get("doctorCode");
                totalMap.put(code,list);
        if (totalList != null && totalList.size() > 0) {
            for (Map<String, Object> list : totalList) {
                String code = (String) list.get("doctorCode");
                totalMap.put(code, list);
            }
        }
        List<Map<String,Object>> endConsultList = jdbcTemplate.queryForList(endConsultSql);
        List<Map<String, Object>> endConsultList = jdbcTemplate.queryForList(endConsultSql);
        //将List转换为Map降低循环层级
        Map<String,Object> endConsultMap = new HashMap<>();
        Map<String, Object> endConsultMap = new HashMap<>();
        //将List转换为Map降低循环层级
        if(endConsultList!=null&&endConsultList.size()>0){
            for(Map<String,Object> list :endConsultList){
                String code = (String)list.get("doctorCode");
                endConsultMap.put(code,list);
        if (endConsultList != null && endConsultList.size() > 0) {
            for (Map<String, Object> list : endConsultList) {
                String code = (String) list.get("doctorCode");
                endConsultMap.put(code, list);
            }
        }
        if("0".equals(sortType)){
        if ("0".equals(sortType)) {
            //未回复数
            //合并结果集
            if(onReyList!=null&&onReyList.size()>0){
                for(Map<String,Object> map :onReyList){
                    String code = (String)map.get("doctorCode");
            if (onReyList != null && onReyList.size() > 0) {
                for (Map<String, Object> map : onReyList) {
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> t = ( Map<String,Object>)totalMap.get(code);
                    Long totalCout = (Long)t.get("total");
                    map.put("total",totalCout);
                    Map<String, Object> t = (Map<String, Object>) totalMap.get(code);
                    Long totalCout = (Long) t.get("total");
                    map.put("total", totalCout);
                    Map<String,Object> e =( Map<String,Object>)endConsultMap.get(code);
                    Long endCout = (Long)e.get("endRey");
                    map.put("endRey",endCout);
                    Map<String, Object> e = (Map<String, Object>) endConsultMap.get(code);
                    Long endCout = (Long) e.get("endRey");
                    map.put("endRey", endCout);
                }
            }
            return new JSONArray(onReyList);
        }else if("1".equals(sortType)){
        } else if ("1".equals(sortType)) {
            //总数
            //合并结果集
            if(totalList!=null&&totalList.size()>0){
                for(Map<String,Object> map :totalList){
                    String code = (String)map.get("doctorCode");
            if (totalList != null && totalList.size() > 0) {
                for (Map<String, Object> map : totalList) {
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> t = ( Map<String,Object>)onReyMap.get(code);
                    Long noRely = (Long)t.get("noRely");
                    map.put("noRely",noRely);
                    Map<String, Object> t = (Map<String, Object>) onReyMap.get(code);
                    Long noRely = (Long) t.get("noRely");
                    map.put("noRely", noRely);
                    Map<String,Object> e =( Map<String,Object>)endConsultMap.get(code);
                    Long endCout = (Long)e.get("endRey");
                    map.put("endRey",endCout);
                    Map<String, Object> e = (Map<String, Object>) endConsultMap.get(code);
                    Long endCout = (Long) e.get("endRey");
                    map.put("endRey", endCout);
                }
            }
            return new JSONArray(totalList);
        }else{
        } else {
            //结束咨询数
            //合并结果集
            if(endConsultList!=null&&endConsultList.size()>0){
                for(Map<String,Object> map :endConsultList){
                    String code = (String)map.get("doctorCode");
            if (endConsultList != null && endConsultList.size() > 0) {
                for (Map<String, Object> map : endConsultList) {
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> t = ( Map<String,Object>)totalMap.get(code);
                    Long totalCout = (Long)t.get("total");
                    map.put("total",totalCout);
                    Map<String, Object> t = (Map<String, Object>) totalMap.get(code);
                    Long totalCout = (Long) t.get("total");
                    map.put("total", totalCout);
                    Map<String,Object> r = ( Map<String,Object>)onReyMap.get(code);
                    Long noRely = (Long)r.get("noRely");
                    map.put("noRely",noRely);
                    Map<String, Object> r = (Map<String, Object>) onReyMap.get(code);
                    Long noRely = (Long) r.get("noRely");
                    map.put("noRely", noRely);
                }
            }
            return new JSONArray(endConsultList);
        }
    }
    public JSONObject getDoctorConsultTitle(String doctor,String teamCode,String startDate,String endDate){
    public JSONObject getDoctorConsultTitle(String doctor, String teamCode, String startDate, String endDate) {
        String imDataBaseName = SystemConf.getInstance().getImDataBaseName();
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        //获取咨询总数
        String couTotalSQL = "SELECT " +
                " c.doctorCode, " +
@ -2763,25 +2788,25 @@ public class StatisticsService extends BaseService {
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " "+imDataBaseName+".topics t, " +
                " "+imDataBaseName+".participants p, " +
                " "+imDataBaseName+".doctors d, " +
                " "+imDataBaseName+".sessions s " +
                " " + 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+"' " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND d.id='" + doctor + "' " +
                " ) c " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code = " +teamCode +
                " AND a.admin_team_code = " + teamCode +
                " GROUP BY " +
                " c.doctorCode ";
        //及时回复数
        String reyTotalSql ="SELECT " +
        String reyTotalSql = "SELECT " +
                " c.doctorCode, " +
                " count(1) AS total " +
                " FROM " +
@ -2791,10 +2816,10 @@ public class StatisticsService extends BaseService {
                " t.id consultId, " +
                " d.id doctorCode " +
                " FROM " +
                " "+imDataBaseName+".topics t, " +
                " "+imDataBaseName+".participants p, " +
                " "+imDataBaseName+".doctors d, " +
                " "+imDataBaseName+".sessions s " +
                " " + 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 " +
@ -2802,16 +2827,16 @@ public class StatisticsService extends BaseService {
                " AND s.business_type=2  " +
                " AND t.`reply`=1  " +
                " 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+"' " +
                " AND t.create_time <= '" + endDate + "' " +
                " AND d.id='" + doctor + "' " +
                " ) c " +
                " WHERE " +
                " c.consultId = a.consult " +
                " AND a.admin_team_code =" +teamCode+
                " AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                " c.doctorCode";
        //本周或月增量
        String addTotalSql ="SELECT " +
        String addTotalSql = "SELECT " +
                "  c.doctorCode, " +
                "  count(1) AS total " +
                " FROM " +
@ -2821,26 +2846,26 @@ public class StatisticsService extends BaseService {
                " t.id consultId," +
                " d.id doctorCode " +
                " FROM " +
                "    "+imDataBaseName+".topics t, " +
                "    "+imDataBaseName+".participants p, " +
                "    "+imDataBaseName+".doctors d, " +
                "    "+imDataBaseName+".sessions s " +
                "    " + 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+"' " +
                "   AND t.create_time <= '" + endDate + "' " +
                "   AND t.create_time >= '" + startDate + "' " +
                "   AND d.id='" + doctor + "' " +
                "  ) c " +
                " WHERE " +
                "  c.consultId = a.consult " +
                " AND a.admin_team_code =" +teamCode+
                " AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                "  c.doctorCode";
        //当前未回复咨询数
        String noRelySql ="SELECT " +
        String noRelySql = "SELECT " +
                "  c.doctorCode, " +
                "  count(1) AS total " +
                " FROM " +
@ -2850,10 +2875,10 @@ public class StatisticsService extends BaseService {
                "    t.id consultId, " +
                "    d.id doctorCode " +
                "   FROM " +
                "    "+imDataBaseName+".topics t, " +
                "    "+imDataBaseName+".participants p, " +
                "    "+imDataBaseName+".doctors d, " +
                "    "+imDataBaseName+".sessions s " +
                "    " + 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 " +
@ -2861,198 +2886,198 @@ public class StatisticsService extends BaseService {
                "   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+"' " +
                "   AND t.create_time <= '" + endDate + "' " +
                "   AND t.create_time >= '" + startDate + "' " +
                "   AND d.id='" + doctor + "' " +
                "  ) c " +
                " WHERE " +
                "  c.consultId = a.consult " +
                "  AND a.admin_team_code =" +teamCode+
                "  AND a.admin_team_code =" + teamCode +
                " GROUP BY " +
                "  c.doctorCode";
        JSONObject rs = new JSONObject();
        Long total =0L;
        Long relyOnTime =0L;
        Long total = 0L;
        Long relyOnTime = 0L;
        Long addNumber = 0L;
        Long noRelyNumber =0L;
        List<Map<String,Object>> couTotal = jdbcTemplate.queryForList(couTotalSQL);
        if(couTotal!=null&&couTotal.size()>0){
            Map<String,Object> couTotalMap = couTotal.get(0);
            total = (Long) couTotalMap.get("total")==null?0L:(Long) couTotalMap.get("total");
        }
        rs.put("total",total);
        List<Map<String,Object>> reyTotal = jdbcTemplate.queryForList(reyTotalSql);
        if(reyTotal!=null&&reyTotal.size()>0){
            Map<String,Object> reyTotalMap = reyTotal.get(0);
            relyOnTime = (Long) reyTotalMap.get("total")==null?0L:(Long) reyTotalMap.get("total");
        }
        if(total!=0L&&relyOnTime!=0L){
            double rr = (double)relyOnTime/total*100;
            double nrr = (double)relyOnTime/total*100;
            DecimalFormat df  = new DecimalFormat("###.00");
            rs.put("relyOnTimeRate",df.format(nrr)+"%");
        }else{
            rs.put("relyOnTimeRate","0.00%");
        Long noRelyNumber = 0L;
        List<Map<String, Object>> couTotal = jdbcTemplate.queryForList(couTotalSQL);
        if (couTotal != null && couTotal.size() > 0) {
            Map<String, Object> couTotalMap = couTotal.get(0);
            total = (Long) couTotalMap.get("total") == null ? 0L : (Long) couTotalMap.get("total");
        }
        rs.put("total", total);
        List<Map<String, Object>> reyTotal = jdbcTemplate.queryForList(reyTotalSql);
        if (reyTotal != null && reyTotal.size() > 0) {
            Map<String, Object> reyTotalMap = reyTotal.get(0);
            relyOnTime = (Long) reyTotalMap.get("total") == null ? 0L : (Long) reyTotalMap.get("total");
        }
        if (total != 0L && relyOnTime != 0L) {
            double rr = (double) relyOnTime / total * 100;
            double nrr = (double) relyOnTime / total * 100;
            DecimalFormat df = new DecimalFormat("###.00");
            rs.put("relyOnTimeRate", df.format(nrr) + "%");
        } else {
            rs.put("relyOnTimeRate", "0.00%");
        }
        List<Map<String,Object>> addTotal = jdbcTemplate.queryForList(addTotalSql);
        if(addTotal!=null&&addTotal.size()>0){
            Map<String,Object> addTotalMap = addTotal.get(0);
            addNumber = (Long) addTotalMap.get("total")==null?0L:(Long) addTotalMap.get("total");
        List<Map<String, Object>> addTotal = jdbcTemplate.queryForList(addTotalSql);
        if (addTotal != null && addTotal.size() > 0) {
            Map<String, Object> addTotalMap = addTotal.get(0);
            addNumber = (Long) addTotalMap.get("total") == null ? 0L : (Long) addTotalMap.get("total");
        }
        //本周或月增量
        rs.put("addNumber",addNumber);
        rs.put("addNumber", addNumber);
        List<Map<String,Object>> noRelyTotal = jdbcTemplate.queryForList(noRelySql);
        if(noRelyTotal!=null&&noRelyTotal.size()>0){
            Map<String,Object> noRelyTotalMap = noRelyTotal.get(0);
            noRelyNumber = (Long) noRelyTotalMap.get("total")==null?0L:(Long) noRelyTotalMap.get("total");
        List<Map<String, Object>> noRelyTotal = jdbcTemplate.queryForList(noRelySql);
        if (noRelyTotal != null && noRelyTotal.size() > 0) {
            Map<String, Object> noRelyTotalMap = noRelyTotal.get(0);
            noRelyNumber = (Long) noRelyTotalMap.get("total") == null ? 0L : (Long) noRelyTotalMap.get("total");
        }
        rs.put("noRelyNumber",noRelyNumber);
        rs.put("noRelyNumber", noRelyNumber);
        return rs;
    }
    public JSONObject getTeamDoctorFollowupLine(String teamCode,String startDate,String endDate,String type,String doctor){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSQL ;
        String planSQL ;
        if("0".equals(type)){
    public JSONObject getTeamDoctorFollowupLine(String teamCode, String startDate, String endDate, String type, String doctor) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSQL;
        String planSQL;
        if ("0".equals(type)) {
            //按周
            totalSQL ="SELECT " +
            totalSQL = "SELECT " +
                    " left(w.create_time,10) AS dateNo,COUNT(1) AS followupCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor_code ='"+doctor+"'"+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor_code ='" + doctor + "'" +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY dateNo";
            planSQL ="SELECT " +
            planSQL = "SELECT " +
                    " left(w.create_time,10) AS dateNo,COUNT(1) AS planCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor_code ='"+doctor+"'"+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " AND w.status ='2'"+
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor_code ='" + doctor + "'" +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.status ='2'" +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY dateNo";
        }else{
        } else {
            //按月
            totalSQL ="SELECT " +
            totalSQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS followupCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor_code ='"+doctor+"'"+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor_code ='" + doctor + "'" +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY weekOfMonth";
            planSQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS planCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor_code ='"+doctor+"'"+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " AND w.status ='2'"+
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor_code ='" + doctor + "'" +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.status ='2'" +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        List<Map<String,Object>> planList = jdbcTemplate.queryForList(planSQL);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        List<Map<String, Object>> planList = jdbcTemplate.queryForList(planSQL);
        JSONObject rs = new JSONObject();
        rs.put("totalLine",totalList);
        rs.put("planLine",planList);
        rs.put("totalLine", totalList);
        rs.put("planLine", planList);
        return rs;
    }
    public JSONObject getTeamFollowupLine(String teamCode,String startDate,String endDate,String type){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSQL ;
        String planSQL ;
        if("0".equals(type)){
    public JSONObject getTeamFollowupLine(String teamCode, String startDate, String endDate, String type) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSQL;
        String planSQL;
        if ("0".equals(type)) {
            //按周
            totalSQL ="SELECT " +
            totalSQL = "SELECT " +
                    " left(w.create_time,10) AS dateNo,COUNT(1) AS followupCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.create_time >= '"+startDate+"' " +
            " AND w.create_time <= '"+endDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY dateNo";
            planSQL ="SELECT " +
            planSQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS planCount " +
                    "FROM " +
                    " wlyy_followup w " +
                    "WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " AND w.status ='2'"+
                    " w.admin_team_code =" + teamCode +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.status ='2'" +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY weekOfMonth";
        }else{
        } else {
            //按月
            totalSQL ="SELECT " +
            totalSQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS followupCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY weekOfMonth";
            planSQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.create_time, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS followupCount " +
                    " FROM " +
                    " wlyy_followup w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.create_time >= '"+startDate+"' " +
                    " AND w.create_time <= '"+endDate+"' " +
                    " AND w.status ='2'"+
                    " w.admin_team_code =" + teamCode +
                    " AND w.create_time >= '" + startDate + "' " +
                    " AND w.create_time <= '" + endDate + "' " +
                    " AND w.status ='2'" +
                    " AND w.followup_class IS NOT NULL " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        List<Map<String,Object>> planList = jdbcTemplate.queryForList(planSQL);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        List<Map<String, Object>> planList = jdbcTemplate.queryForList(planSQL);
        JSONObject rs = new JSONObject();
        rs.put("totalLine",totalList);
        rs.put("planLine",planList);
        rs.put("totalLine", totalList);
        rs.put("planLine", planList);
        return rs;
    }
    public JSONArray getDoctorTeamFolList(String startDate,String endDate,String teamCode,String sort,String sortType){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public JSONArray getDoctorTeamFolList(String startDate, String endDate, String teamCode, String sort, String sortType) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSQL = "SELECT " +
                " IFNULL(c.followupCount,0) AS followupCount, " +
                " d.`code` AS doctorCode, " +
@ -3067,8 +3092,8 @@ public class StatisticsService extends BaseService {
                " FROM " +
                "  wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode+
                " AND w.create_time <= '"+endDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.followup_class IS NOT NULL " +
                " GROUP BY " +
                "  w.doctor_code " +
@ -3077,11 +3102,11 @@ public class StatisticsService extends BaseService {
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =" +teamCode ;
        if("0".equals(sort)){
            totalSQL =totalSQL+" ORDER BY followupCount DESC";
        }else{
            totalSQL =totalSQL+" ORDER BY followupCount ASC";
                " AND m.team_id =" + teamCode;
        if ("0".equals(sort)) {
            totalSQL = totalSQL + " ORDER BY followupCount DESC";
        } else {
            totalSQL = totalSQL + " ORDER BY followupCount ASC";
        }
        String addSQL = "SELECT " +
@ -3098,9 +3123,9 @@ public class StatisticsService extends BaseService {
                " FROM " +
                "  wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode+
                " AND w.create_time >= '"+startDate+"' " +
                " AND w.create_time <= '"+endDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.create_time >= '" + startDate + "' " +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.followup_class IS NOT NULL " +
                " GROUP BY " +
                "  w.doctor_code " +
@ -3109,11 +3134,11 @@ public class StatisticsService extends BaseService {
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =" +teamCode ;
        if("0".equals(sort)){
            addSQL =addSQL+" ORDER BY addCount DESC";
        }else{
            addSQL =addSQL+" ORDER BY addCount ASC";
                " AND m.team_id =" + teamCode;
        if ("0".equals(sort)) {
            addSQL = addSQL + " ORDER BY addCount DESC";
        } else {
            addSQL = addSQL + " ORDER BY addCount ASC";
        }
        String planSQL = "SELECT " +
@ -3130,10 +3155,10 @@ public class StatisticsService extends BaseService {
                " FROM " +
                "  wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode+
                " AND w.create_time >= '"+startDate+"' " +
                " AND w.create_time <= '"+endDate+"' " +
                " AND w.status ='2'"+
                " w.admin_team_code =" + teamCode +
                " AND w.create_time >= '" + startDate + "' " +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.status ='2'" +
                " AND w.followup_class IS NOT NULL " +
                " GROUP BY " +
                "  w.doctor_code " +
@ -3142,117 +3167,117 @@ public class StatisticsService extends BaseService {
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =" +teamCode ;
        if("0".equals(sort)){
            planSQL =planSQL+" ORDER BY planCount DESC";
        }else{
            planSQL =planSQL+" ORDER BY planCount ASC";
                " AND m.team_id =" + teamCode;
        if ("0".equals(sort)) {
            planSQL = planSQL + " ORDER BY planCount DESC";
        } else {
            planSQL = planSQL + " ORDER BY planCount ASC";
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        //降低循环层级
        Map<String,Object> totalMap = new HashMap<>();
        if(totalList!=null&&totalList.size()>0){
            for(Map<String,Object> map:totalList){
                String code = (String)map.get("doctorCode");
                totalMap.put(code,map);
        Map<String, Object> totalMap = new HashMap<>();
        if (totalList != null && totalList.size() > 0) {
            for (Map<String, Object> map : totalList) {
                String code = (String) map.get("doctorCode");
                totalMap.put(code, map);
            }
        }
        List<Map<String,Object>> addList= jdbcTemplate.queryForList(addSQL);
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSQL);
        //降低循环层级
        Map<String,Object> addMap = new HashMap<>();
        if(addList!=null&&addList.size()>0){
            for(Map<String,Object> map:addList){
                String code = (String)map.get("doctorCode");
                addMap.put(code,map);
        Map<String, Object> addMap = new HashMap<>();
        if (addList != null && addList.size() > 0) {
            for (Map<String, Object> map : addList) {
                String code = (String) map.get("doctorCode");
                addMap.put(code, map);
            }
        }
        List<Map<String,Object>> planList = jdbcTemplate.queryForList(planSQL);
        List<Map<String, Object>> planList = jdbcTemplate.queryForList(planSQL);
        //降低循环层级
        Map<String,Object> planMap = new HashMap<>();
        if(planList!=null&&planList.size()>0){
            for(Map<String,Object> map:planList){
                String code = (String)map.get("doctorCode");
                planMap.put(code,map);
        Map<String, Object> planMap = new HashMap<>();
        if (planList != null && planList.size() > 0) {
            for (Map<String, Object> map : planList) {
                String code = (String) map.get("doctorCode");
                planMap.put(code, map);
            }
        }
        if("0".equals(sortType)){
        if ("0".equals(sortType)) {
            //按总数排序
            if(totalList!=null&&totalList.size()>0){
            if (totalList != null && totalList.size() > 0) {
                //以总数为基准,合并结果集
                for(Map<String ,Object> map : totalList){
                for (Map<String, Object> map : totalList) {
                    String code = (String)map.get("doctorCode");
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> m =(Map<String,Object>)addMap.get(code);
                    if(m!=null){
                        Long addCount = (Long)m.get("addCount");
                        map.put("addCount",addCount==null?0L:addCount);
                    }else{
                        map.put("addCount",0L);
                    Map<String, Object> m = (Map<String, Object>) addMap.get(code);
                    if (m != null) {
                        Long addCount = (Long) m.get("addCount");
                        map.put("addCount", addCount == null ? 0L : addCount);
                    } else {
                        map.put("addCount", 0L);
                    }
                    Map<String,Object> m2 =(Map<String,Object>)planMap.get(code);
                    if(m2!=null){
                        Long planCount = (Long)m2.get("planCount");
                        map.put("planCount",planCount);
                    }else{
                        map.put("planCount",0L);
                    Map<String, Object> m2 = (Map<String, Object>) planMap.get(code);
                    if (m2 != null) {
                        Long planCount = (Long) m2.get("planCount");
                        map.put("planCount", planCount);
                    } else {
                        map.put("planCount", 0L);
                    }
                }
            }
            return new JSONArray(totalList);
        }else if("1".equals(sortType)){
        } else if ("1".equals(sortType)) {
            //按增量排序
            if(addList!=null&&addList.size()>0){
            if (addList != null && addList.size() > 0) {
                //以增量为基准,合并结果集
                for(Map<String ,Object> map : addList){
                for (Map<String, Object> map : addList) {
                    String code = (String)map.get("doctorCode");
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> m =(Map<String,Object>)planMap.get(code);
                    if(m!=null){
                        Long planCount = (Long)m.get("planCount");
                        map.put("planCount",planCount);
                    }else{
                        map.put("planCount",0L);
                    Map<String, Object> m = (Map<String, Object>) planMap.get(code);
                    if (m != null) {
                        Long planCount = (Long) m.get("planCount");
                        map.put("planCount", planCount);
                    } else {
                        map.put("planCount", 0L);
                    }
                    Map<String,Object> m2 =(Map<String,Object>)totalMap.get(code);
                    if(m2!=null){
                        Long followupCount = (Long)m2.get("followupCount");
                        map.put("followupCount",followupCount);
                    }else{
                        map.put("followupCount",0L);
                    Map<String, Object> m2 = (Map<String, Object>) totalMap.get(code);
                    if (m2 != null) {
                        Long followupCount = (Long) m2.get("followupCount");
                        map.put("followupCount", followupCount);
                    } else {
                        map.put("followupCount", 0L);
                    }
                }
            }
            return new JSONArray(addList);
        }else{
        } else {
            //按计划量排序
            if(planList!=null&&planList.size()>0){
            if (planList != null && planList.size() > 0) {
                //以增量为基准,合并结果集
                for(Map<String ,Object> map : planList){
                    String code = (String)map.get("doctorCode");
                for (Map<String, Object> map : planList) {
                    String code = (String) map.get("doctorCode");
                    Map<String,Object> m =(Map<String,Object>)totalMap.get(code);
                    if(m!=null){
                        Long followupCount = (Long)m.get("followupCount");
                        map.put("followupCount",followupCount);
                    }else{
                        map.put("followupCount",0L);
                    Map<String, Object> m = (Map<String, Object>) totalMap.get(code);
                    if (m != null) {
                        Long followupCount = (Long) m.get("followupCount");
                        map.put("followupCount", followupCount);
                    } else {
                        map.put("followupCount", 0L);
                    }
                    Map<String,Object> m2 =(Map<String,Object>)addMap.get(code);
                    if(m2!=null){
                        Long addCount = (Long)m2.get("addCount");
                        map.put("addCount",addCount==null?0L:addCount);
                    }else{
                        map.put("addCount",0L);
                    Map<String, Object> m2 = (Map<String, Object>) addMap.get(code);
                    if (m2 != null) {
                        Long addCount = (Long) m2.get("addCount");
                        map.put("addCount", addCount == null ? 0L : addCount);
                    } else {
                        map.put("addCount", 0L);
                    }
                }
            }
@ -3260,136 +3285,136 @@ public class StatisticsService extends BaseService {
        }
    }
    public JSONObject getTeamDoctorFolTitle(String teamCode,String doctor,String startDate,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public JSONObject getTeamDoctorFolTitle(String teamCode, String doctor, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql = "SELECT " +
                " COUNT(1) AS followupCount " +
                " FROM " +
                " wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode +
                " AND w.doctor_code ='"+doctor+"' " +
                " AND w.create_time <= '"+endDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.doctor_code ='" + doctor + "' " +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.followup_class IS NOT NULL";
        String addSql = "SELECT " +
                " COUNT(1) AS addCount " +
                " FROM " +
                " wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode +
                " AND w.doctor_code ='"+doctor+"' " +
                " AND w.create_time >= '"+startDate+"' " +
                " AND w.create_time <= '"+endDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.doctor_code ='" + doctor + "' " +
                " AND w.create_time >= '" + startDate + "' " +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.followup_class IS NOT NULL";
        String planSql = "SELECT " +
                " COUNT(1) AS planCount " +
                " FROM " +
                " wlyy_followup w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode +
                " AND w.doctor_code ='"+doctor+"' " +
                " AND w.create_time >= '"+startDate+"' " +
                " AND w.create_time <= '"+endDate+"' " +
                " AND w.status ='2'"+
                " w.admin_team_code =" + teamCode +
                " AND w.doctor_code ='" + doctor + "' " +
                " AND w.create_time >= '" + startDate + "' " +
                " AND w.create_time <= '" + endDate + "' " +
                " AND w.status ='2'" +
                " AND w.followup_class IS NOT NULL";
        JSONObject rs = new JSONObject();
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        if(totalList!=null&&totalList.size()>0){
            Map<String,Object> map = totalList.get(0);
            Long followupCount = (Long)map.get("followupCount");
            rs.put("followupCount",followupCount!=null?followupCount:0L);
        }
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSql);
        if(addList!=null&&addList.size()>0){
            Map<String,Object> map = addList.get(0);
            Long addCount = (Long)map.get("addCount");
            rs.put("addCount",addCount!=null?addCount:0L);
        }
        List<Map<String,Object>> planList = jdbcTemplate.queryForList(planSql);
        if(planList!=null&&planList.size()>0){
            Map<String,Object> map = planList.get(0);
            Long planCount = (Long)map.get("planCount");
            rs.put("planCount",planCount!=null?planCount:0L);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        if (totalList != null && totalList.size() > 0) {
            Map<String, Object> map = totalList.get(0);
            Long followupCount = (Long) map.get("followupCount");
            rs.put("followupCount", followupCount != null ? followupCount : 0L);
        }
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSql);
        if (addList != null && addList.size() > 0) {
            Map<String, Object> map = addList.get(0);
            Long addCount = (Long) map.get("addCount");
            rs.put("addCount", addCount != null ? addCount : 0L);
        }
        List<Map<String, Object>> planList = jdbcTemplate.queryForList(planSql);
        if (planList != null && planList.size() > 0) {
            Map<String, Object> map = planList.get(0);
            Long planCount = (Long) map.get("planCount");
            rs.put("planCount", planCount != null ? planCount : 0L);
        }
        return rs;
    }
    public JSONArray getTeamResLine(String teamCode,String startDate,String endDate,String type){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSql ;
        if("0".equals(type)){
    public JSONArray getTeamResLine(String teamCode, String startDate, String endDate, String type) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql;
        if ("0".equals(type)) {
            //查周
            totalSql = "SELECT " +
                    " left(w.czrq,10) AS dateNo,COUNT(1) AS reservationCount " +
                    " FROM " +
                    " wlyy_patient_reservation w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode +
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY dateNo";
        }else{
        } else {
            //查月
            //查周
            totalSql = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS reservationCount " +
                    " FROM " +
                    " wlyy_patient_reservation w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode +
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(totalSql);
        return new JSONArray(list);
    }
    public JSONArray getTeamDoctorResLine(String teamCode,String startDate,String endDate,String type,String doctor){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSql ;
        if("0".equals(type)){
    public JSONArray getTeamDoctorResLine(String teamCode, String startDate, String endDate, String type, String doctor) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql;
        if ("0".equals(type)) {
            //查周
            totalSql = "SELECT " +
                    " left(w.czrq,10) AS dateNo,COUNT(1) AS reservationCount " +
                    " FROM " +
                    " wlyy_patient_reservation w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode +
                    " AND w.doctor_code = '"+doctor+"'"+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.doctor_code = '" + doctor + "'" +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY dateNo";
        }else{
        } else {
            //查月
            totalSql = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+DateUtil.getFristDayOfMonth()+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + DateUtil.getFristDayOfMonth() + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS reservationCount " +
                    " FROM " +
                    " wlyy_patient_reservation w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode +
                    " AND w.doctor_code = '"+doctor+"'"+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.doctor_code = '" + doctor + "'" +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(totalSql);
        return new JSONArray(list);
    }
    public JSONArray getTeamDoctorResList(String teamCode,String startDate,String endDate,String sort,String sortType){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public JSONArray getTeamDoctorResList(String teamCode, String startDate, String endDate, String sort, String sortType) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql = "SELECT " +
                " IFNULL(c.reservationCount,0) AS reservationCount, " +
                " d.`code` AS doctorCode, " +
@ -3404,19 +3429,19 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_patient_reservation w " +
                " WHERE " +
                " w.admin_team_code = " +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " w.admin_team_code = " + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " GROUP BY doctorCode  " +
                " ) c ON c.doctorCode =m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode ;
        if("0".equals(sort)){
            totalSql = totalSql+  " ORDER BY reservationCount DESC";
        }else{
            totalSql = totalSql+  " ORDER BY reservationCount ASC";
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            totalSql = totalSql + " ORDER BY reservationCount DESC";
        } else {
            totalSql = totalSql + " ORDER BY reservationCount ASC";
        }
        String addSql = "SELECT " +
                " IFNULL(c.reservationCount,0) AS addCount, " +
@ -3432,42 +3457,42 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_patient_reservation w " +
                " WHERE " +
                " w.admin_team_code = " +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"' " +
                " w.admin_team_code = " + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "' " +
                " GROUP BY doctorCode  " +
                " ) c ON c.doctorCode =m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode ;
        if("0".equals(sort)){
            addSql = addSql+  " ORDER BY addCount DESC";
        }else{
            addSql = addSql+  " ORDER BY addCount ASC";
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            addSql = addSql + " ORDER BY addCount DESC";
        } else {
            addSql = addSql + " ORDER BY addCount ASC";
        }
        List<Map<String,Object>> totalList =jdbcTemplate.queryForList(totalSql);
        Map<String,Object> totalMap = new HashMap<>();
        if(totalList!=null&&totalList.size()>0){
            for(Map<String,Object> map :totalList){
                String code = (String)map.get("doctorCode");
                totalMap.put(code,map);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        Map<String, Object> totalMap = new HashMap<>();
        if (totalList != null && totalList.size() > 0) {
            for (Map<String, Object> map : totalList) {
                String code = (String) map.get("doctorCode");
                totalMap.put(code, map);
            }
        }
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String,Object> addMap = new HashMap<>();
        if(addList!=null&&addList.size()>0){
            for(Map<String,Object> map :addList){
                String code = (String)map.get("doctorCode");
                addMap.put(code,map);
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String, Object> addMap = new HashMap<>();
        if (addList != null && addList.size() > 0) {
            for (Map<String, Object> map : addList) {
                String code = (String) map.get("doctorCode");
                addMap.put(code, map);
            }
        }
        if("0".equals(sortType)){
        if ("0".equals(sortType)) {
            //按总数排序
            if(totalList!=null&&totalList.size()>0){
                for(Map<String,Object> map:totalList) {
            if (totalList != null && totalList.size() > 0) {
                for (Map<String, Object> map : totalList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) addMap.get(code);
                    if (m != null) {
@ -3479,10 +3504,10 @@ public class StatisticsService extends BaseService {
                }
            }
            return new JSONArray(totalList);
        }else{
        } else {
            //按增量排序
            if(addList!=null&&addList.size()>0){
                for(Map<String,Object> map:addList) {
            if (addList != null && addList.size() > 0) {
                for (Map<String, Object> map : addList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) totalMap.get(code);
                    if (m != null) {
@ -3497,125 +3522,125 @@ public class StatisticsService extends BaseService {
        }
    }
    public JSONObject getTeamDoctorResTitle(String teamCode,String doctor,String startDate,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSQL ="SELECT " +
    public JSONObject getTeamDoctorResTitle(String teamCode, String doctor, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSQL = "SELECT " +
                " COUNT(1) AS reservationCount " +
                " FROM " +
                " wlyy_patient_reservation w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.doctor_code ='"+doctor+"' " +
                " AND w.czrq <= '"+endDate+"' ";
                " w.admin_team_code =  " + teamCode +
                " AND w.doctor_code ='" + doctor + "' " +
                " AND w.czrq <= '" + endDate + "' ";
        String addSQL ="SELECT " +
        String addSQL = "SELECT " +
                " COUNT(1) AS addCount " +
                " FROM " +
                " wlyy_patient_reservation w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.doctor_code ='"+doctor+"' " +
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"'";
                " w.admin_team_code =  " + teamCode +
                " AND w.doctor_code ='" + doctor + "' " +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "'";
        JSONObject rs = new JSONObject();
        Long reservationCount =0L;
        Long reservationCount = 0L;
        Long addCount = 0L;
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        if(totalList!=null&&totalList.size()>0){
            Map<String,Object> map =totalList.get(0);
            reservationCount = (Long)map.get("reservationCount");
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        if (totalList != null && totalList.size() > 0) {
            Map<String, Object> map = totalList.get(0);
            reservationCount = (Long) map.get("reservationCount");
        }
        rs.put("reservationCount",reservationCount);
        rs.put("reservationCount", reservationCount);
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSQL);
        if(addList!=null&&addList.size()>0){
            Map<String,Object> map =addList.get(0);
            addCount = (Long)map.get("addCount");
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSQL);
        if (addList != null && addList.size() > 0) {
            Map<String, Object> map = addList.get(0);
            addCount = (Long) map.get("addCount");
        }
        rs.put("addCount",addCount);
        rs.put("addCount", addCount);
        return rs;
    }
    public JSONArray getTeamGuidLine(String teamCode,String startDate,String endDate,String type){
    public JSONArray getTeamGuidLine(String teamCode, String startDate, String endDate, String type) {
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String SQL ;
        if("0".equals(type)){
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String SQL;
        if ("0".equals(type)) {
            //按周统计
            SQL ="SELECT " +
            SQL = "SELECT " +
                    " left(w.create_time,10) AS dateNo, " +
                    " COUNT(1) AS guidanceCount " +
                    " FROM " +
                    " wlyy_patient_health_guidance w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode+
                    " AND w.czrq <= '"+startDate+"' " +
                    " AND w.czrq >= '"+endDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.czrq <= '" + startDate + "' " +
                    " AND w.czrq >= '" + endDate + "' " +
                    " GROUP BY dateNo";
        }else{
        } else {
            //按月统计
            SQL ="SELECT " +
            SQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + startDate + "', '%v') + 1 " +
                    " ) AS weekOfMonth, " +
                    " COUNT(1) AS guidanceCount " +
                    " FROM " +
                    " wlyy_patient_health_guidance w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(SQL);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(SQL);
        return new JSONArray(totalList);
    }
    public JSONArray getTeamDoctorGuidLine(String teamCode,String startDate,String endDate,String type,String doctor){
    public JSONArray getTeamDoctorGuidLine(String teamCode, String startDate, String endDate, String type, String doctor) {
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String SQL ;
        if("0".equals(type)){
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String SQL;
        if ("0".equals(type)) {
            //按周统计
            SQL ="SELECT " +
            SQL = "SELECT " +
                    " left(w.create_time,10) AS dateNo, " +
                    " COUNT(1) AS guidanceCount " +
                    " FROM " +
                    " wlyy_patient_health_guidance w " +
                    " WHERE " +
                    " w.admin_team_code = " +teamCode+
                    " AND w.doctor ='"+doctor+"'"+
                    " AND w.czrq <= '"+startDate+"' " +
                    " AND w.czrq >= '"+endDate+"' " +
                    " w.admin_team_code = " + teamCode +
                    " AND w.doctor ='" + doctor + "'" +
                    " AND w.czrq <= '" + startDate + "' " +
                    " AND w.czrq >= '" + endDate + "' " +
                    " GROUP BY dateNo";
        }else{
        } else {
            //按月统计
            SQL ="SELECT " +
            SQL = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + startDate + "', '%v') + 1 " +
                    " ) AS weekOfMonth, " +
                    " COUNT(1) AS guidanceCount " +
                    " FROM " +
                    " wlyy_patient_health_guidance w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor ='"+doctor+"'"+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor ='" + doctor + "'" +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(SQL);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(SQL);
        return new JSONArray(totalList);
    }
    public JSONArray getTeamGuidList(String teamCode,String startDate,String endDate,String sort,String sortType){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSql ="SELECT " +
    public JSONArray getTeamGuidList(String teamCode, String startDate, String endDate, String sort, String sortType) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql = "SELECT " +
                " IFNULL(c.guidanceCount,0) AS guidanceCount, " +
                " d.`code` AS doctorCode, " +
                " d.`name` AS name " +
@ -3628,23 +3653,23 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_patient_health_guidance w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"' " +
                " w.admin_team_code =  " + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "' " +
                " GROUP BY w.doctor " +
                " ) c ON c.doctor = m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode ;
        if("0".equals(sort)){
            totalSql = totalSql+   " ORDER BY guidanceCount DESC";
        }else{
            totalSql = totalSql+   " ORDER BY guidanceCount ASC";
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            totalSql = totalSql + " ORDER BY guidanceCount DESC";
        } else {
            totalSql = totalSql + " ORDER BY guidanceCount ASC";
        }
        String addSql ="SELECT " +
        String addSql = "SELECT " +
                " IFNULL(c.guidanceCount,0) AS addCount, " +
                " d.`code` AS doctorCode, " +
                " d.`name` AS name " +
@ -3657,42 +3682,42 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_patient_health_guidance w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"' " +
                " w.admin_team_code =  " + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "' " +
                " GROUP BY w.doctor " +
                " ) c ON c.doctor = m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode ;
        if("0".equals(sort)){
            addSql = addSql+   " ORDER BY addCount DESC";
        }else{
            addSql = addSql+   " ORDER BY addCount ASC";
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            addSql = addSql + " ORDER BY addCount DESC";
        } else {
            addSql = addSql + " ORDER BY addCount ASC";
        }
        List<Map<String,Object>> totalList =jdbcTemplate.queryForList(totalSql);
        Map<String,Object> totalMap = new HashMap<>();
        if(totalList!=null&&totalList.size()>0){
            for(Map<String,Object> map :totalList){
                String code = (String)map.get("doctorCode");
                totalMap.put(code,map);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        Map<String, Object> totalMap = new HashMap<>();
        if (totalList != null && totalList.size() > 0) {
            for (Map<String, Object> map : totalList) {
                String code = (String) map.get("doctorCode");
                totalMap.put(code, map);
            }
        }
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String,Object> addMap = new HashMap<>();
        if(addList!=null&&addList.size()>0){
            for(Map<String,Object> map :addList){
                String code = (String)map.get("doctorCode");
                addMap.put(code,map);
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String, Object> addMap = new HashMap<>();
        if (addList != null && addList.size() > 0) {
            for (Map<String, Object> map : addList) {
                String code = (String) map.get("doctorCode");
                addMap.put(code, map);
            }
        }
        if("0".equals(sortType)){
        if ("0".equals(sortType)) {
            //按总数排序
            if(totalList!=null&&totalList.size()>0){
                for(Map<String,Object> map:totalList) {
            if (totalList != null && totalList.size() > 0) {
                for (Map<String, Object> map : totalList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) addMap.get(code);
                    if (m != null) {
@ -3704,10 +3729,10 @@ public class StatisticsService extends BaseService {
                }
            }
            return new JSONArray(totalList);
        }else{
        } else {
            //按增量排序
            if(addList!=null&&addList.size()>0){
                for(Map<String,Object> map:addList) {
            if (addList != null && addList.size() > 0) {
                for (Map<String, Object> map : addList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) totalMap.get(code);
                    if (m != null) {
@ -3722,119 +3747,119 @@ public class StatisticsService extends BaseService {
        }
    }
    public JSONObject getTeamDoctorGuiTitle(String teamCode,String doctor,String startDate,String endDate){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSQL ="SELECT " +
    public JSONObject getTeamDoctorGuiTitle(String teamCode, String doctor, String startDate, String endDate) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSQL = "SELECT " +
                " COUNT(1) AS guidanceCount " +
                " FROM " +
                " wlyy_patient_health_guidance w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.doctor ='"+doctor+"'" +
                " AND w.czrq >= '"+endDate+"'";
                " w.admin_team_code =  " + teamCode +
                " AND w.doctor ='" + doctor + "'" +
                " AND w.czrq >= '" + endDate + "'";
        String addSQL ="SELECT " +
        String addSQL = "SELECT " +
                " COUNT(1) AS addCount " +
                " FROM " +
                " wlyy_patient_health_guidance w " +
                " WHERE " +
                " w.admin_team_code =  " +teamCode+
                " AND w.doctor ='"+doctor+"'" +
                " AND w.czrq <= '"+startDate+"' " +
                " AND w.czrq >= '"+endDate+"'";
                " w.admin_team_code =  " + teamCode +
                " AND w.doctor ='" + doctor + "'" +
                " AND w.czrq <= '" + startDate + "' " +
                " AND w.czrq >= '" + endDate + "'";
        JSONObject rs = new JSONObject();
        Long guidanceCount =0L;
        Long guidanceCount = 0L;
        Long addCount = 0L;
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        if(totalList!=null&&totalList.size()>0){
            Map<String,Object> map =totalList.get(0);
            guidanceCount = (Long)map.get("guidanceCount");
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSQL);
        if (totalList != null && totalList.size() > 0) {
            Map<String, Object> map = totalList.get(0);
            guidanceCount = (Long) map.get("guidanceCount");
        }
        rs.put("guidanceCount",guidanceCount);
        rs.put("guidanceCount", guidanceCount);
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSQL);
        if(addList!=null&&addList.size()>0){
            Map<String,Object> map =addList.get(0);
            addCount = (Long)map.get("addCount");
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSQL);
        if (addList != null && addList.size() > 0) {
            Map<String, Object> map = addList.get(0);
            addCount = (Long) map.get("addCount");
        }
        rs.put("addCount",addCount);
        rs.put("addCount", addCount);
        return rs;
    }
    public JSONArray getTeamEduLine(String teamCode,String startDate,String endDate,String type){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public JSONArray getTeamEduLine(String teamCode, String startDate, String endDate, String type) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String sql;
        if("0".equals(type)){
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(w.czrq,10) AS dateNo,COUNT(1) AS articleCount,count(DISTINCT w.batch_no) batchCount " +
                    " FROM " +
                    " wlyy_health_edu_article_patient w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY dateNo";
        }else{
            sql ="SELECT " +
        } else {
            sql = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + startDate + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS articleCount,count(DISTINCT w.batch_no) batchno " +
                    "FROM " +
                    " wlyy_health_edu_article_patient w " +
                    "WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    "GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return new JSONArray(list);
    }
    public JSONArray getTeamDoctorEduLine(String teamCode,String startDate,String endDate,String type,String doctor){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
    public JSONArray getTeamDoctorEduLine(String teamCode, String startDate, String endDate, String type, String doctor) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String sql;
        if("0".equals(type)){
        if ("0".equals(type)) {
            //按周统计
            sql = "SELECT " +
                    " left(w.czrq,10) AS dateNo,COUNT(1) AS articleCount,count(DISTINCT w.batch_no) batchCount " +
                    " FROM " +
                    " wlyy_health_edu_article_patient w " +
                    " WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor ='"+doctor+"'"+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor ='" + doctor + "'" +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    " GROUP BY dateNo";
        }else{
            sql ="SELECT " +
        } else {
            sql = "SELECT " +
                    " ( " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('"+startDate+"', '%v') + 1 " +
                    "  DATE_FORMAT(w.czrq, '%v') - DATE_FORMAT('" + startDate + "', '%v') + 1 " +
                    " ) AS weekOfMonth,COUNT(1) AS articleCount,count(DISTINCT w.batch_no) batchno " +
                    "FROM " +
                    " wlyy_health_edu_article_patient w " +
                    "WHERE " +
                    " w.admin_team_code =" +teamCode+
                    " AND w.doctor ='"+doctor+"'"+
                    " AND w.czrq <= '"+endDate+"' " +
                    " AND w.czrq >= '"+startDate+"' " +
                    " w.admin_team_code =" + teamCode +
                    " AND w.doctor ='" + doctor + "'" +
                    " AND w.czrq <= '" + endDate + "' " +
                    " AND w.czrq >= '" + startDate + "' " +
                    "GROUP BY weekOfMonth";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return new JSONArray(list);
    }
    public JSONArray getTeamEduList(String teamCode,String startDate,String endDate,String sort,String sortType){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSql ="SELECT " +
    public JSONArray getTeamEduList(String teamCode, String startDate, String endDate, String sort, String sortType) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql = "SELECT " +
                " IFNULL(c.articleCount,0) AS articleCount, " +
                " IFNULL(c.batchno,0) AS batchno, " +
                " d.`code` AS doctorCode, " +
@ -3849,32 +3874,32 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_health_edu_article_patient w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " GROUP BY doctorCode " +
                " ) c ON c.doctorCode =m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode;
        if("0".equals(sort)){
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            //降序
            if("0".equals(sortType)){
            if ("0".equals(sortType)) {
                //总人次
                totalSql = totalSql+ " ORDER BY articleCount DESC";
            }else if("2".equals(sortType)){
                totalSql = totalSql + " ORDER BY articleCount DESC";
            } else if ("2".equals(sortType)) {
                //总批次
                totalSql = totalSql+ " ORDER BY batchno DESC";
                totalSql = totalSql + " ORDER BY batchno DESC";
            }
        }else{
            if("0".equals(sortType)){
                totalSql = totalSql+ " ORDER BY articleCount ASC";
            }else if("2".equals(sortType)){
                totalSql = totalSql+ " ORDER BY batchno ASC";
        } else {
            if ("0".equals(sortType)) {
                totalSql = totalSql + " ORDER BY articleCount ASC";
            } else if ("2".equals(sortType)) {
                totalSql = totalSql + " ORDER BY batchno ASC";
            }
        }
        String addSql ="SELECT " +
        String addSql = "SELECT " +
                " IFNULL(c.articleCount,0) AS addCount, " +
                " IFNULL(c.batchno,0) AS addBatchno, " +
                " d.`code` AS doctorCode, " +
@ -3889,50 +3914,50 @@ public class StatisticsService extends BaseService {
                " FROM " +
                " wlyy_health_edu_article_patient w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode+
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"' " +
                " w.admin_team_code =" + teamCode +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "' " +
                " GROUP BY doctorCode " +
                " ) c ON c.doctorCode =m.doctor_code, " +
                " wlyy_doctor d " +
                " WHERE  " +
                "  d.`code` = m.doctor_code " +
                " AND m.available = 1 " +
                " AND m.team_id =  " +teamCode;
        if("0".equals(sort)){
            if("1".equals(sortType)){
                addSql = addSql+ " ORDER BY addCount DESC";
            }else if("3".equals(sortType)){
                addSql = addSql+ " ORDER BY addBatchno DESC";
                " AND m.team_id =  " + teamCode;
        if ("0".equals(sort)) {
            if ("1".equals(sortType)) {
                addSql = addSql + " ORDER BY addCount DESC";
            } else if ("3".equals(sortType)) {
                addSql = addSql + " ORDER BY addBatchno DESC";
            }
        }else{
            if("1".equals(sortType)){
                addSql = addSql+ " ORDER BY addCount ASC";
            }else if("3".equals(sortType)){
                addSql = addSql+ " ORDER BY addBatchno ASC";
        } else {
            if ("1".equals(sortType)) {
                addSql = addSql + " ORDER BY addCount ASC";
            } else if ("3".equals(sortType)) {
                addSql = addSql + " ORDER BY addBatchno ASC";
            }
        }
        List<Map<String,Object>> totalList =jdbcTemplate.queryForList(totalSql);
        Map<String,Object> totalMap = new HashMap<>();
        if(totalList!=null&&totalList.size()>0){
            for(Map<String,Object> map :totalList){
                String code = (String)map.get("doctorCode");
                totalMap.put(code,map);
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        Map<String, Object> totalMap = new HashMap<>();
        if (totalList != null && totalList.size() > 0) {
            for (Map<String, Object> map : totalList) {
                String code = (String) map.get("doctorCode");
                totalMap.put(code, map);
            }
        }
        List<Map<String,Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String,Object> addMap = new HashMap<>();
        if(addList!=null&&addList.size()>0){
            for(Map<String,Object> map :addList){
                String code = (String)map.get("doctorCode");
                addMap.put(code,map);
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSql);
        Map<String, Object> addMap = new HashMap<>();
        if (addList != null && addList.size() > 0) {
            for (Map<String, Object> map : addList) {
                String code = (String) map.get("doctorCode");
                addMap.put(code, map);
            }
        }
        if("0".equals(sortType)||"2".equals(sortType)){
        if ("0".equals(sortType) || "2".equals(sortType)) {
            //按总数排序
            if(totalList!=null&&totalList.size()>0){
                for(Map<String,Object> map:totalList) {
            if (totalList != null && totalList.size() > 0) {
                for (Map<String, Object> map : totalList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) addMap.get(code);
                    if (m != null) {
@ -3947,10 +3972,10 @@ public class StatisticsService extends BaseService {
                }
            }
            return new JSONArray(totalList);
        }else{
        } else {
            //按增量排序
            if(addList!=null&&addList.size()>0){
                for(Map<String,Object> map:addList) {
            if (addList != null && addList.size() > 0) {
                for (Map<String, Object> map : addList) {
                    String code = (String) map.get("doctorCode");
                    Map<String, Object> m = (Map<String, Object>) totalMap.get(code);
                    if (m != null) {
@ -3968,43 +3993,480 @@ public class StatisticsService extends BaseService {
        }
    }
    public JSONObject getTeamDoctorEduTitle(String teamCode,String startDate,String endDate,String doctor){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String totalSql ="SELECT " +
    public JSONObject getTeamDoctorEduTitle(String teamCode, String startDate, String endDate, String doctor) {
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        String totalSql = "SELECT " +
                " COUNT(1) AS articleCount, " +
                " COUNT(DISTINCT w.batch_no) batchno " +
                " FROM " +
                " wlyy_health_edu_article_patient w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode +
                " AND w.doctor ='"+doctor+"'" +
                " AND w.czrq <= '"+endDate+"' ";
        String addSql ="SELECT " +
                " w.admin_team_code =" + teamCode +
                " AND w.doctor ='" + doctor + "'" +
                " AND w.czrq <= '" + endDate + "' ";
        String addSql = "SELECT " +
                " COUNT(1) AS addCount, " +
                " COUNT(DISTINCT w.batch_no) addBatchno " +
                " FROM " +
                " wlyy_health_edu_article_patient w " +
                " WHERE " +
                " w.admin_team_code =" +teamCode +
                " AND w.doctor ='"+doctor+"'" +
                " AND w.czrq <= '"+endDate+"' " +
                " AND w.czrq >= '"+startDate+"'";
        List<Map<String,Object>> totalList = jdbcTemplate.queryForList(totalSql);
        List<Map<String,Object>> addList =jdbcTemplate.queryForList(addSql);
                " w.admin_team_code =" + teamCode +
                " AND w.doctor ='" + doctor + "'" +
                " AND w.czrq <= '" + endDate + "' " +
                " AND w.czrq >= '" + startDate + "'";
        List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
        List<Map<String, Object>> addList = jdbcTemplate.queryForList(addSql);
        JSONObject rs = new JSONObject();
        rs.put("totalList",totalList);
        rs.put("addList",addList);
        rs.put("totalList", totalList);
        rs.put("addList", addList);
        return rs;
    }
    public JSONObject getDoctorInfo(String code){
       Doctor doctor =  doctorDao.findByCode(code);
    public JSONObject getDoctorInfo(String code) {
        Doctor doctor = doctorDao.findByCode(code);
        JSONObject rs = new JSONObject();
        rs.put("doctorName",doctor.getName());
        rs.put("doctor",doctor.getCode());
        rs.put("photo",doctor.getPhoto());
        rs.put("doctorName", doctor.getName());
        rs.put("doctor", doctor.getCode());
        rs.put("photo", doctor.getPhoto());
        return rs;
    }
    /**
     * 获取单个数据
     *
     * @param date
     * @param level
     * @param index
     * @param area
     * @return
     */
    public WlyyQuotaResult findOneQuotaResult(String date, int level, String index, String area) {
        String sql = " select * from wlyy_quota_result w where w.quota_date ='" + date + "' and w.quato_code='" + index + "' and w.level1_type= " + level;
        if (level == 4) {
            // 市级别
            sql += " and city='" + area + "' ";
        } else if (level == 3) {
            // 区、城镇级别
            sql += " and town='" + area + "' ";
        } else if (level == 2) {
            // 机构级别
            sql = " and org_code='" + area + "' ";
        } else if (level == 1) {
            // 机构级别
            sql = " and qkdoctor_code ='" + area + "'";
        }
        List<WlyyQuotaResult> results = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyyQuotaResult.class));
        if (results.size() > 0) {
            return results.get(0);
        }
        return null;
    }
    public JSONObject getRenewPercentAndChangePercent(String level, String code, String year) {
        JSONObject jo = new JSONObject();
        //获取时间戳
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        //从redis中获取最新的续签数据  续签指标是29
        int renewNum = getLevel1NumForRedis("29", level, code, timeKey);
        ;
        //根据年度获取去年的签约数 签约指标是1
        String date = year + "-06-30";
        String index = "1";
        WlyyQuotaResult wlyyQuotaResult = findOneQuotaResult(date, Integer.valueOf(level), index, code);
        int signNum = Integer.valueOf(wlyyQuotaResult.getResult());
        //从redis中获取最新的转签数据  指标是37
        int switchNum = getLevel1NumForRedis("37", level, code, timeKey);
        jo.put("yesterYearSign", signNum);//去年的签约量
        jo.put("thisYearRenew", renewNum);//今年的续签量
        jo.put("thisYearSwithch", switchNum);//今年的转签量
        jo.put("renewRange", getRange(renewNum, signNum, 2));//续签率  50.00%
        jo.put("renewRange", getRange(switchNum, renewNum, 2));//转签率
        return jo;
    }
    public JSONObject getRenewAnalysis(String level, String code, String year) {
        JSONObject jo = new JSONObject();
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        //获取转签人数
        int switchNum = getLevel1NumForRedis("37", level, code, timeKey);
        ;
        //获取转签分布
        JSONArray switchJO = getLevel2JsonObjectForRedis("30", level, code, timeKey);
        //获取转签原因分析
        //从redis中获取最新的续签数据  续签指标是29
        int renewNum = getLevel1NumForRedis("29", level, code, timeKey);
        int changeTeam = getLevel1NumForRedis("31", level, code, timeKey);//夸团队的数目
        int changeHospital = getLevel1NumForRedis("32", level, code, timeKey);//夸社区的数目
        int changeTown = getLevel1NumForRedis("33", level, code, timeKey);//夸区的数目
        jo.put("thisYearSwithch", switchNum);//今年的转签量
        jo.put("switchHealth", switchJO);//今年的服务分布
        jo.put("switchTeam", getRange(changeTeam, renewNum, 2));//今年的转签量
        jo.put("switchHospital", getRange(changeHospital, renewNum, 2));//今年的转签量
        jo.put("switchTown", getRange(changeTown, renewNum, 2));//今年的转签量
        return jo;
    }
    //-==============================================通用方法=============================================
    /**
     * 通用的方法 获取一级维度的数据
     *
     * @param index
     * @param level
     * @param code
     * @param timeKey
     * @return
     */
    private int getLevel1NumForRedis(String index, String level, String code, String timeKey) {
        String key37 = "quota:" + index + ":" + level + ":" + code + ":" + timeKey;
        JSONObject switchJo = new JSONObject(redisTemplate.opsForValue().get(key37));
        return switchJo.getInt("num");
    }
    /**
     * 通用的方法 获取二级维度的数据列表
     *
     * @param index
     * @param level
     * @param code
     * @param timeKey
     * @return
     */
    private JSONArray getLevel2JsonObjectForRedis(String index, String level, String code, String timeKey) {
        String key37 = "quota:" + index + ":" + level + ":" + code + ":" + timeKey;
        JSONArray switchJo = new JSONArray(redisTemplate.opsForValue().get(key37));
        return switchJo;
    }
    /**
     * 获取2个数的百分比
     *
     * @param first
     * @param second
     * @param i
     * @return
     */
    public String getRange(int first, int second, int i) {
        float size = (float) (first * 100) / second;
        DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
        String filesize = df.format(size);
        return filesize + "%";
    }
    public JSONObject getConsultingTitleAll(Integer level, String area, String year) {
        JSONObject result = new JSONObject();
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        if (StringUtils.isBlank(timeKey)) {
            return null;
        }
        //获取今年的及时回复数
        String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(relyVal)) {
            return null;
        }
        JSONObject relyObject = new JSONObject(relyVal);
        //查找去年6月30号的及时回复数,然后累加
        relyObject.put("num", relyObject.getInt("num") + getSizeByIndexLevelArea(year, "23", level, area));
        JSONArray rely = new JSONArray();
        rely.put(relyObject);
        //咨询总数
        String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(relyTotal)) {
            return null;
        }
        JSONObject totalObject = new JSONObject(relyTotal);
        //查找去年6月30号的咨询总数,然后累加
        totalObject.put("num", totalObject.getInt("num") + getSizeByIndexLevelArea(year, "25", level, area));
        JSONArray total = new JSONArray();
        total.put(totalObject);
        //未回复数
        String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":" + timeKey);
        if (StringUtils.isBlank(onRelyTotal)) {
            return null;
        }
        JSONObject onRelyObject = new JSONObject(onRelyTotal);
        //查找去年6月30号的未回复数,然后累加
        onRelyObject.put("num", onRelyObject.getInt("num") + getSizeByIndexLevelArea(year, "22", level, area));
        JSONArray onRely = new JSONArray();
        onRely.put(onRelyObject);
        result.put("result", getCoutList(rely, total, onRely));
        return result;
    }
    public JSONObject getConsultingTitleWithYear(Integer level, String area, String year) {
        JSONObject result = new JSONObject();
        JSONObject relyObject = new JSONObject();
        //查找去年6月30号的及时回复数
        WlyyQuotaResult wlyyQuotaResult = findOneQuotaResult((Integer.valueOf(year) + 1) + "-06-30", level, "23", area);
        if (wlyyQuotaResult != null) {
            relyObject.put("name", getNameByLevel(wlyyQuotaResult, level));
            relyObject.put("code", getCodeByLevel(wlyyQuotaResult, level));
            relyObject.put("num", Integer.valueOf(wlyyQuotaResult.getResult()));
        }
        JSONArray rely = new JSONArray();
        rely.put(relyObject);
        JSONObject totalObject = new JSONObject();
        //查找去年6月30号的咨询总数
        wlyyQuotaResult = findOneQuotaResult("2017-06-30", level, "25", area);
        if (wlyyQuotaResult != null) {
            totalObject.put("name", getNameByLevel(wlyyQuotaResult, level));
            totalObject.put("code", getCodeByLevel(wlyyQuotaResult, level));
            totalObject.put("num", Integer.valueOf(wlyyQuotaResult.getResult()));
        }
        JSONArray total = new JSONArray();
        total.put(totalObject);
        //未回复数
        JSONObject onRelyObject = new JSONObject();
        //查找去年6月30号的未回复数,然后累加
        wlyyQuotaResult = findOneQuotaResult("2017-06-30", level, "22", area);
        //查找去年6月30号的咨询总数
        wlyyQuotaResult = findOneQuotaResult("2017-06-30", level, "25", area);
        if (wlyyQuotaResult != null) {
            onRelyObject.put("name", getNameByLevel(wlyyQuotaResult, level));
            onRelyObject.put("code", getCodeByLevel(wlyyQuotaResult, level));
            onRelyObject.put("num", Integer.valueOf(wlyyQuotaResult.getResult()));
        }
        JSONArray onRely = new JSONArray();
        onRely.put(onRelyObject);
        result.put("result", getCoutList(rely, total, onRely));
        return result;
    }
    public JSONObject getCoutListByTimeAll(String level, String area) {
        JSONObject result = new JSONObject();
        if (StringUtils.isNotBlank(level) && StringUtils.isNotBlank(area)) {
            String relyVal = findLevel1IndexInRedis("24", level, area);
            JSONArray array = new JSONArray(relyVal);
            result.put("resultList", array);
        }
        return result;
    }
    public JSONObject getCoutListByTimeYear(String level, String area, String year) {
        JSONObject result = new JSONObject();
        WlyyQuotaResult wlyyQuotaResult = findOneQuotaResult((Integer.valueOf(year) + 1) + "-06-30", Integer.valueOf(level), "24", area);
        if (wlyyQuotaResult != null) {
            result.put("name", getNameByLevel(wlyyQuotaResult, Integer.valueOf(level)));
            result.put("code", getCodeByLevel(wlyyQuotaResult, Integer.valueOf(level)));
            result.put("num", Integer.valueOf(wlyyQuotaResult.getResult()));
        }
        return result;
    }
    public JSONObject getConsultingStatisticsListAll(Integer level, String area, String lowlevel, String year) throws Exception {
        JSONObject result = new JSONObject();
        //级别为市级,统计区级统计区和机构
        if (level == 4) {
            if (StringUtils.isBlank(lowlevel)) {
                String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
                if (StringUtils.isBlank(timeKey)) {
                    return null;
                }
                //及时回复数
                String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(relyVal)) {
                    return null;
                }
                JSONArray rely = new JSONArray(relyVal);
                //咨询总数
                String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(relyTotal)) {
                    return null;
                }
                JSONArray total = new JSONArray(relyTotal);
                //未回复数
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":3:" + timeKey);
                if (StringUtils.isBlank(onRelyTotal)) {
                    return null;
                }
                JSONArray onRely = new JSONArray(onRelyTotal);
                result.put("resultList", getCoutList(rely, total, onRely));
            } else {
                String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
                if (StringUtils.isBlank(timeKey)) {
                    return null;
                }
                //及时回复数
                String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(relyVal)) {
                    return null;
                }
                JSONArray rely = new JSONArray(relyVal);
                //咨询总数
                String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(relyTotal)) {
                    return null;
                }
                JSONArray total = new JSONArray(relyTotal);
                //未回复数
                String onRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":2:" + timeKey);
                if (StringUtils.isBlank(onRelyTotal)) {
                    return null;
                }
                JSONArray onRely = new JSONArray(onRelyTotal);
                result.put("resultList", getCoutList(rely, total, onRely));
            }
        } else if (level == 3) {//区级底下的机构
            //quota:23:4:350200:2:1492939333191
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            if (StringUtils.isBlank(timeKey)) {
                return null;
            }
            //及时回复数
            String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(relyVal)) {
                return null;
            }
            JSONArray rely = new JSONArray(relyVal);
            //咨询总数
            String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(relyTotal)) {
                return null;
            }
            JSONArray total = new JSONArray(relyTotal);
            //未回复数
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":2:" + timeKey);
            if (StringUtils.isBlank(noRelyTotal)) {
                return null;
            }
            JSONArray noRely = new JSONArray(noRelyTotal);
            result.put("resultList", getCoutList(rely, total, noRely));
        } else if (level == 2) {//机构级别统计,统计所有团队
            //quota:23:4:350200:2:1492939333191
            String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
            if (StringUtils.isBlank(timeKey)) {
                return null;
            }
            //及时回复数
            String relyVal = redisTemplate.opsForValue().get("quota:23:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(relyVal)) {
                return null;
            }
            JSONArray rely = new JSONArray(relyVal);
            //咨询总数
            String relyTotal = redisTemplate.opsForValue().get("quota:25:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(relyTotal)) {
                return null;
            }
            JSONArray total = new JSONArray(relyTotal);
            //未回复数
            String noRelyTotal = redisTemplate.opsForValue().get("quota:22:" + level + ":" + area + ":1:" + timeKey);
            if (StringUtils.isBlank(noRelyTotal)) {
                return null;
            }
            JSONArray noRely = new JSONArray(noRelyTotal);
            List<Map<String, Object>> rs = getCoutList(rely, total, noRely);
            statisticsAllService.translateTeamLeaderName(rs);
            result.put("resultList", rs);
        }
        return result;
    }
    public JSONObject getConsultingStatisticsListYear(Integer level, String area, String lowlevel, String year) {
        return null;
    }
    //-----------------------------------通用方法-------------------------------
    /**
     * 得到某个指标的之前全部的数目
     *
     * @param year
     * @param index
     * @param level
     * @param area
     * @return
     */
    private Integer getSizeByIndexLevelArea(String year, String index, Integer level, String area) {
        //查找去年6月30号的及时回复数,然后累加
        WlyyQuotaResult wlyyQuotaResult = findOneQuotaResult("2017-06-30", level, index, area);
        if (wlyyQuotaResult != null) {
            return Integer.valueOf(wlyyQuotaResult.getResult());
        }
        return null;
    }
    private String findLevel1IndexInRedis(String index, String level, String area) {
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        String relyVal = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + timeKey);
        return relyVal;
    }
    private String getNameByLevel(WlyyQuotaResult wlyyQuotaResult, Integer level) {
        switch (level) {
            case 1: {
                return wlyyQuotaResult.getQkdoctorName();
            }
            case 2: {
                return wlyyQuotaResult.getOrgName();
            }
            case 3: {
                return wlyyQuotaResult.getTownName();
            }
            case 4: {
                return wlyyQuotaResult.getCityName();
            }
        }
        return null;
    }
    private String getCodeByLevel(WlyyQuotaResult wlyyQuotaResult, Integer level) {
        switch (level) {
            case 1: {
                return wlyyQuotaResult.getQkdoctorCode();
            }
            case 2: {
                return wlyyQuotaResult.getOrgCode();
            }
            case 3: {
                return wlyyQuotaResult.getTown();
            }
            case 4: {
                return wlyyQuotaResult.getCity();
            }
        }
        return null;
    }
}

+ 69 - 27
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.statistic;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
import com.yihu.wlyy.job.Constant;
import com.yihu.wlyy.service.app.statistics.StatisticsAllService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.util.ValueComparator;
@ -50,6 +51,7 @@ public class StatisticsController extends BaseController {
    /**
     * 指标按间隔统计  增量
     * 按年度统计是根据前端传的 startDate
     *
     * @param startDate 起始日期
     * @param endDate   结束时间
@ -101,7 +103,8 @@ public class StatisticsController extends BaseController {
                                    @RequestParam(required = true) String endDate,
                                    @RequestParam(required = true) String area,
                                    @RequestParam(required = true) int level,
                                    @RequestParam(required = true) String index) {
                                    @RequestParam(required = true) String index,
                                    @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
@ -120,6 +123,7 @@ public class StatisticsController extends BaseController {
    /**
     * 指标截止日期累积量  增量的累加接口
     *
     * @param startDate   开始时间
     * @param endDate     结束时间
     * @param area        父code
     * @param level       等级  1 团队,2 机构,3 区,4 市
@ -129,17 +133,19 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/total")
    @ResponseBody
    public String getIndexTotal(@RequestParam(required = true) String endDate,
                                @RequestParam(required = true) String area,
                                @RequestParam(required = true) int level,
                                @RequestParam(required = true) String index,
                                @RequestParam(required = false) String level2_type) {
    public String getIndexTotal(
            @RequestParam(required = true) String startDate,
            @RequestParam(required = true) String endDate,
            @RequestParam(required = true) String area,
            @RequestParam(required = true) int level,
            @RequestParam(required = true) String index,
            @RequestParam(required = false) String level2_type) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx, level2_type));
                result.put("index_" + idx, statisticsService.getTotalAmount(startDate, endDate, area, level, idx, level2_type));
            }
            return write(200, "查询成功", "data", result);
@ -167,7 +173,8 @@ public class StatisticsController extends BaseController {
                                            @RequestParam(required = true) int level,
                                            @RequestParam(required = true) String index,
                                            @RequestParam(required = true) int sort,
                                            @RequestParam(required = false) String lowLevel) {
                                            @RequestParam(required = false) String lowLevel,
                                            @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
@ -319,7 +326,8 @@ public class StatisticsController extends BaseController {
                                            @RequestParam(required = true) String endDate,
                                            @RequestParam(required = true) String area,
                                            @RequestParam(required = true) int level,
                                            @RequestParam(required = true) String index) {
                                            @RequestParam(required = true) String index,
                                            @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
@ -389,7 +397,8 @@ public class StatisticsController extends BaseController {
    public String getSixFiveStatistics(@RequestParam(required = false) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String area,
                                       int level) {
                                       int level,
                                       @RequestParam(required = false) String year) {
        try {
            JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
@ -430,7 +439,7 @@ public class StatisticsController extends BaseController {
            if (index != null) {
                for (String idx : indexes) {
                    JSONObject json = statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode);
                    //如果year不为空  那么因为是到达量 所以要扣除上一年的数据
                    //如果year不为空  那么因为是到达量 所以要累加上一年的数据
                    if (!org.springframework.util.StringUtils.isEmpty(year) && !"2016".equals(year)) {
                        //得到上一个年份的的最后一天的统计数据
                        String date = year + "-06-30";//固定是 6月三十号 为一个年份的最后一天,如果是2017年份 那么就是2017-7-1 到 2018-6-30
@ -440,8 +449,8 @@ public class StatisticsController extends BaseController {
                            for (int i = 0; i < ja.length(); i++) {
                                Integer value = Integer.valueOf(ja.getJSONObject(i).getString("amount"));
                                super.infoMessage("原来的总数:" + value);
                                ja.getJSONObject(i).put("amount", value - Integer.valueOf(wlyyQuotaResult.getResult()));
                                super.infoMessage("需要扣除的总数:" + wlyyQuotaResult.getResult());
                                ja.getJSONObject(i).put("amount", value + Integer.valueOf(wlyyQuotaResult.getResult()));
                                super.infoMessage("需要想加的总数:" + wlyyQuotaResult.getResult());
                            }
                        }
                    }
@ -475,7 +484,8 @@ public class StatisticsController extends BaseController {
                                            @RequestParam(required = true) String index,
                                            @RequestParam(required = true) int sort,
                                            @RequestParam(required = false) String lowLevel,
                                            @RequestParam(required = false) String lowCode) {
                                            @RequestParam(required = false) String lowCode,
                                            @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
@ -593,14 +603,14 @@ public class StatisticsController extends BaseController {
            for (String idx : indexes) {
                Long total = statisticsAllService.getIndexTotal(endDate, area, level, idx);
                super.infoMessage("原来的总数:" + total);
                //如果year不为空  那么因为是到达量 所以要扣除上一年的数据
                //如果year不为空  那么因为是到达量 所以要加上一年的数据
                if (!org.springframework.util.StringUtils.isEmpty(year) && !"2016".equals(year)) {
                    //得到上一个年份的的最后一天的统计数据
                    String date = year + "-06-30";//固定是 6月三十号 为一个年份的最后一天,如果是2017年份 那么就是2017-7-1 到 2018-6-30
                    WlyyQuotaResult wlyyQuotaResult = statisticsService.findOneQuotaResult(date, level, idx, area);
                    if (wlyyQuotaResult != null) {
                        super.infoMessage("需要扣除的数目:" + wlyyQuotaResult.getResult());
                        total = total - Long.valueOf(wlyyQuotaResult.getResult());
                        super.infoMessage("需要添加的数目:" + wlyyQuotaResult.getResult());
                        total = total + Long.valueOf(wlyyQuotaResult.getResult());
                    }
                }
                result.put("index_" + idx, total);
@ -648,9 +658,17 @@ public class StatisticsController extends BaseController {
    @ResponseBody
    public String getConsultingStatisticsList(@RequestParam(required = true) Integer level,
                                              @RequestParam(required = true) String area,
                                              @RequestParam(required = false) String lowlevel) {
                                              @RequestParam(required = false) String lowlevel,
                                              @RequestParam(required = false) String year) {
        try {
            JSONObject data = statisticsService.getConsultingStatisticsList(level, area, lowlevel);
            JSONObject data = null;
            if (Constant.getStartYear().equals(year)) {
                data = statisticsService.getConsultingStatisticsList(level, area, lowlevel);
            } else if (org.springframework.util.StringUtils.isEmpty(year)) {
                data = statisticsService.getConsultingStatisticsListAll(level, area, lowlevel,year);
            } else {
                data = statisticsService.getConsultingStatisticsListYear(level, area, lowlevel,year);
            }
            if (data != null) {
                return write(200, "查询成功", "data", data);
            } else {
@ -674,9 +692,21 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/Consulting_Title")
    @ResponseBody
    public String getConsultingTitle(@RequestParam(required = true) Integer level,
                                     @RequestParam(required = true) String area) {
                                     @RequestParam(required = true) String area,
                                     @RequestParam(required = false) String year) {
        try {
            JSONObject data = statisticsService.getConsultingTitle(level, area);
            JSONObject data = null;
            if (Constant.getStartYear().equals(year)) {
                //查今年的查找redis即可
                data = statisticsService.getConsultingTitle(level, area);
            } else if (org.springframework.util.StringUtils.isEmpty(year)) {
                //为空默认查询全部
                //查找redis的然后再添加去年年度的
                data = statisticsService.getConsultingTitleAll(level, area,year);
            } else {
                //去数据库查找年份
                data = statisticsService.getConsultingTitleWithYear(level, area, year);
            }
            if (data != null) {
                return write(200, "查询成功", "data", data);
            } else {
@ -696,9 +726,18 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getCoutListByTime")
    @ResponseBody
    public String getCoutListByTime(@RequestParam(required = true) String level, @RequestParam(required = true) String area) {
    public String getCoutListByTime(
            @RequestParam(required = true) String level,
            @RequestParam(required = true) String area,
            @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsService.getCoutListByTime(level, area));
            if (Constant.getStartYear().equals(year)) {
                return write(200, "查询成功", "data", statisticsService.getCoutListByTime(level, area));
            } else if (org.springframework.util.StringUtils.isEmpty(year)) {
                return write(200, "查询成功", "data", statisticsService.getCoutListByTimeAll(level, area));
            } else {
                return write(200, "查询成功", "data", statisticsService.getCoutListByTimeYear(level, area, year));
            }
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
@ -1361,9 +1400,10 @@ public class StatisticsController extends BaseController {
    /**
     * 获取转签率和续签率
     * 前端:续签进展页面中用到
     *
     * @param level 等级  4 市  3区  2社区 1团队
     * @param code  市 默认是厦门市 350200  区 就是区的code  社区就是社区的code 团队就是团队的code
     * @param year 年份 非比传
     * @param year  年份 非比传
     * @return
     */
    @RequestMapping(value = "/getRenewPercentAndChangePercent", method = RequestMethod.GET)
@ -1374,7 +1414,7 @@ public class StatisticsController extends BaseController {
            @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsService.getRenewPercentAndChangePercent(level, code,year));
            return write(200, "查询成功", "data", statisticsService.getRenewPercentAndChangePercent(level, code, year));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1384,9 +1424,10 @@ public class StatisticsController extends BaseController {
    /**
     * 获取转签人数,转签原因分析,转签分布
     * 前端:签约数据分析
     *
     * @param level 等级  4 市  3区  2社区 1团队
     * @param code  市 默认是厦门市 350200  区 就是区的code  社区就是社区的code 团队就是团队的code
     * @param year 年份 非比传
     * @param year  年份 非比传
     * @return
     */
    @RequestMapping(value = "/getRenewAnalysis", method = RequestMethod.GET)
@ -1396,10 +1437,11 @@ public class StatisticsController extends BaseController {
            @RequestParam(required = true) String code,
            @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsService.getRenewAnalysis(level, code,year));
            return write(200, "查询成功", "data", statisticsService.getRenewAnalysis(level, code, year));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
}