Przeglądaj źródła

统计新增6个指标

chenweida 8 lat temu
rodzic
commit
b3a4901108

+ 21 - 21
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/dataFilter/RenewSignDataFilter.java

@ -162,46 +162,46 @@ public class RenewSignDataFilter {
            //判断社区有没有值
            Hospital hospital = hospitalsMap.get(orgCodeTemp);
            if (hospital == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_hospital_noExist));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_hospital_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
            String town = hospital.getTown();
            if (StringUtils.isEmpty(town)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_town_null));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_town_null));
                isAll = false;
                errorCount++;
                continue;
            }
            Town townObj = townsMap.get(town);
            if (townObj == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_town_noExist));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_town_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
            Long adminId = signFamily.getAdminTeamId();
            if (adminId == null || adminId <= 0) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_adminTeam_null));
                isAll = false;
                errorCount++;
                continue;
            }
            AdminTeam adminTeam = adminTeamMap.get(adminId + "");
            if (adminTeam == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
            String idCard = signFamily.getIdcard();
            if (idCard == null || ((idCard.length() != 18 && idCard.length() != 15))) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_idcard_error));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_adminTeam_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
//            String idCard = signFamily.getIdcard();
//            if (idCard == null || ((idCard.length() != 18 && idCard.length() != 15))) {
//                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_idcard_error));
//                isAll = false;
//                errorCount++;
//                continue;
//            }
            //设置二级维度的Key
            String returnLevel2Key = getLevel2Key(level2Key, signFamily);
            String returnLevel3Key = getLevel3Key(level3Key, signFamily);
@ -348,13 +348,13 @@ public class RenewSignDataFilter {
            SignFamilyRenew signFamily = signFamilies.get(i);
            String orgCode = signFamily.getHospital();
            if (StringUtils.isEmpty(orgCode)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_hospital_null));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_hospital_null));
                isAll = false;
                errorCount++;
                continue;
            }
            if (orgCode.length() != 10) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_hospital_isTest));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_hospital_isTest));
                isAll = false;
                errorCount++;
                continue;
@ -370,28 +370,28 @@ public class RenewSignDataFilter {
            //判断社区有没有值
            Hospital hospital = hospitalsMap.get(orgCodeTemp);
            if (hospital == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_hospital_noExist));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_hospital_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
            String town = hospital.getTown();
            if (StringUtils.isEmpty(town)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_town_null));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_town_null));
                isAll = false;
                errorCount++;
                continue;
            }
            Town townObj = townsMap.get(town);
            if (townObj == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_town_noExist));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_town_noExist));
                isAll = false;
                errorCount++;
                continue;
            }
            String idCard = signFamily.getIdcard();
            if (idCard == null || ((idCard.length() != 18 && idCard.length() != 15))) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_idcard_error));
                errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_idcard_error));
                isAll = false;
                errorCount++;
                continue;
@ -406,7 +406,7 @@ public class RenewSignDataFilter {
                    String sqlD = "select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='" + signFamily.getDoctor() + "'";
                    adminTeamList = jdbcTemplate.queryForList(sqlD, Long.class);
                    if (adminTeamList == null && adminTeamList.size() == 0) {
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_adminTeam_null));
                        isAll = false;
                        errorCount++;
                        continue;
@ -416,13 +416,13 @@ public class RenewSignDataFilter {
                    String sqlD = "select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='" + signFamily.getDoctorHealth() + "'  ";
                    adminTeamList = jdbcTemplate.queryForList(sqlD, Long.class);
                    if (adminTeamList == null && adminTeamList.size() == 0) {
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_adminTeam_null));
                        isAll = false;
                        errorCount++;
                        continue;
                    }
                } else {
                    errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                    errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.renew_adminTeam_null));
                    isAll = false;
                    errorCount++;
                    continue;

+ 12 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/model/ErrorModel.java

@ -43,6 +43,18 @@ public class ErrorModel {
    public static String sign_idcard_error_age="签约表中(wlyy_sign_family)中的身份证解析年龄失败";
    public static String sign_idcard_error_sex="签约表中(wlyy_sign_family)中的身份证解析性别失败";
    public static String renew_hospital_null="续签表中(wlyy_sign_family_renew)中的hospital数据为空";
    public static String renew_hospital_noExist="续签表中(wlyy_sign_family_renew)中的hospital数据不存在";
    public static String renew_hospital_isTest="续签表中(wlyy_sign_family_renew)中的hospital数据是测试数据";
    public static String renew_adminTeam_null="续签表中(wlyy_sign_family_renew)中的团队数据为空";
    public static String renew_adminTeam_noExist="续签表中(wlyy_sign_family_renew)中的团队数据不存在";
    public static String renew_town_null="机构表的中的town为空";
    public static String renew_town_noExist="机构表的中的town不存在";
    public static String renew_idcard_error="续签表中(wlyy_sign_family_renew)中的身份证错误";
    public static String renew_idcard_error_age="续签表中(wlyy_sign_family_renew)中的身份证解析年龄失败";
    public static String renew_idcard_error_sex="续签表中(wlyy_sign_family_renew)中的身份证解析性别失败";
    public static String consult_adminTeam_null="咨询的团队(wlyy_consult_team)中的admin_team_code数据为空";
    public static String consult_adminTeam_noExist="咨询的团队(wlyy_consult_team)中的admin_team_code数据不存在";
    public static String consult_hospital_null="咨询的团队(wlyy_consult_team)中的admin_team_code在团队表中的orgCode为空";

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

@ -184,6 +184,7 @@ public class CurrentDayAllQuotaJob implements Job {
        computequota_34(); //续签签入
        computequota_35(); //统计续签签出
        computequota_36(sql, signFamilies, null); //签约服务类型
        computequota_37(); //统计转签
        quartzJobLog.setJobContent(allContent.toString());
@ -207,6 +208,26 @@ public class CurrentDayAllQuotaJob implements Job {
        redisTemplate.opsForValue().set("quota:timeKey", RedisStorage.timeKey);
    }
    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+"'";
            //抽取數據
            List<SignFamily> signFamilies = SpringUtil.getBean(DBExtract.class).extract(SignFamily.class, sql);
            //清洗數據
            FilterModel etlModels = SpringUtil.getBean(SignDataFilter.class).filter(signFamilies, sql, "now");
            //统计数据
            List<Map<String, List<ETLModel>>> returnDatas = SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //保存数据
            SpringUtil.getBean(RedisStorage.class).saveByLevel1(returnDatas, null, quotaId);
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        } catch (Exception e) {
            e.printStackTrace();
            allContent.append("统计失败:" + e.getMessage());
        }
        allContent.append("-----------37----------");
    }
    private void computequota_36(String sql, List<SignFamily> signFamilies, Object o) {
        String quotaId = "36";
        //找出今天的签约信息

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

@ -0,0 +1,105 @@
package com.yihu.wlyy.statistics.job.business;
import com.yihu.wlyy.statistics.dao.QuartzJobLogDao;
import com.yihu.wlyy.statistics.etl.dataFilter.RenewSignDataFilter;
import com.yihu.wlyy.statistics.etl.extract.DBExtract;
import com.yihu.wlyy.statistics.etl.model.ETLModel;
import com.yihu.wlyy.statistics.etl.model.FilterModel;
import com.yihu.wlyy.statistics.etl.role.Level1Role;
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
import com.yihu.wlyy.statistics.model.signfamily.SignFamilyRenew;
import com.yihu.wlyy.statistics.util.JsonUtil;
import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
import com.yihu.wlyy.statistics.vo.WlyyQuotaVO;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 转签的指标执行类
 */
@Component
@Scope("prototype")
@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
public class SwitchSignJob implements Job {
    private WlyyQuotaVO wlyyQuota;//指标对象
    private WlyyJobConfigVO wlyyJobConfig;//配置对象
    @Autowired
    private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private Level1Role levelRole;
    @Autowired
    private DBStorage dbStorage;
    @Autowired
    private DBExtract dbExtract;
    @Autowired
    private RenewSignDataFilter signDataFilter;
    String yesterday;
    String daybefore;
    @Override
    public void execute(JobExecutionContext context)
            throws JobExecutionException {
        try{
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            //初始化参数
            JobDataMap map = context.getJobDetail().getJobDataMap();
            wlyyQuota = (WlyyQuotaVO) map.get("quota");
            wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
            daybefore= StringUtils.isEmpty(map.get("daybefore"))?SignJob.getDayString(-2):map.get("daybefore").toString();
            yesterday= StringUtils.isEmpty(map.get("yesterday"))?SignJob.getDayString(-1):map.get("yesterday").toString();
            //计算指标
            computequota();
        }catch (Exception e){
            //如果出錯立即重新執行
            JobExecutionException e2 =new JobExecutionException(e);
            e2.setRefireImmediately(true);
        }
    }
    /**
     * 计算指标
     */
    @Transactional
    private void computequota() {
        try{
            jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+37+"'");
            //新建任务日志对象
            QuartzJobLog quartzJobLog = new QuartzJobLog();
            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.old_admin_team_id!=fr.admin_team_id and fr.apply_date<'"+yesterday+Constant.quota_date_last+"'";
            //抽取數據
            List<SignFamilyRenew> signFamilies= dbExtract.extract(SignFamilyRenew.class,sql);
            //清洗數據
            FilterModel etlModels= signDataFilter.filter(signFamilies,null,null,sql,yesterday);
            //统计数据
            List<Map<String, List<ETLModel>>>  returnDatas= levelRole.elt(etlModels.getEtlModelList());
            //保存数据
            dbStorage.saveByLevel1(returnDatas,yesterday,wlyyQuota);
            //保存日志
            quartzJobLog.setJobEndTime(new Date());
            quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));
            quartzJobLog.setJobType(etlModels.getError()?"1":"0");
            quartzJobLogDao.save(quartzJobLog);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

+ 106 - 106
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -27,112 +27,112 @@ public class DoctorInterceptor extends BaseInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
        try {
            request.setCharacterEncoding("UTF-8");
            request.setAttribute("log-start", new Date().getTime());
            response.setCharacterEncoding("UTF-8");
            JSONObject json = getAgent(request);
            if (json == null) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            if (json.has("uid") && json.has("admin_token") && StringUtils.isNotEmpty(json.getString("admin_token"))) {
                String adminToken = SystemConf.getInstance().getSystemProperties().getProperty("admin_token");
                String adminUid = SystemConf.getInstance().getSystemProperties().getProperty("admin_uid");
                if (json.getString("uid").equals(adminUid) && json.getString("admin_token").equals(adminToken)) {
                    return true;
                }
            }
            String tokenStr = json.has("token") ? json.getString("token") : "";
            String uid = json.has("uid") ? json.getString("uid") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            //如果是观察者直接返回true
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
                Class cls = ((HandlerMethod) handler).getBeanType();
                RequestMapping clsRm = (RequestMapping) cls.getAnnotation(RequestMapping.class);
                Method method = ((HandlerMethod) handler).getMethod();
                RequestMapping mthRm = method.getAnnotation(RequestMapping.class);
                String url = "";
                String urlCls = "";
                String urlMth = "";
                if (clsRm.value() != null && clsRm.value().length > 0) {
                    urlCls = clsRm.value()[0];
                }
                if (mthRm.value() != null && mthRm.value().length > 0) {
                    urlMth = mthRm.value()[0];
                }
                if (StringUtils.isNotEmpty(urlCls)) {
                    url += urlCls.startsWith("/") ? urlCls : ("/" + urlCls);
                }
                if (StringUtils.isNotEmpty(urlMth)) {
                    url += urlMth.startsWith("/") ? urlMth : ("/" + urlMth);
                }
                url = url.replace("\\", "/").replace("//", "/");
                CudUrl cudUrl = cudUrlDao.findByUrl(url);
                if (url.equals("/doctor/consult/readed")) {
                    response.getOutputStream().write(write(200, "操作成功").getBytes());
                    return false;
                }
                if (cudUrl != null) {
                    if (StringUtils.isNotEmpty(cudUrl.getMethod()) &&
                            request.getMethod().toUpperCase().compareTo(cudUrl.getMethod()) != 0) {
                        return true;
                    } else {
                        response.getOutputStream().write(error(403, "该操作没有权限").getBytes());
                        return false;
                    }
                }
                return true;
            }
            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            Token token = SystemData.doctorTokens.get(uid);
            if (token == null) {
                token = tokenDao.findByPatient(uid, 2);
                if (token != null) {
                    // 加入缓存
                    SystemData.doctorTokens.put(uid, token);
                }
            }
            if (token == null || token.getPlatform() != 2) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                flag = false;
            } else {
                if (token.getTimeout().getTime() < new Date().getTime()) {
                    // 登录超时
                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
                    flag = false;
                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
                    // 别处登录
                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
                    flag = false;
                } else {
                    // 一天只更新一次
                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        SystemData.doctorTokens.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
//        try {
//            request.setCharacterEncoding("UTF-8");
//            request.setAttribute("log-start", new Date().getTime());
//            response.setCharacterEncoding("UTF-8");
//            JSONObject json = getAgent(request);
//
//            if (json == null) {
//                // 未登录
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                return false;
//            }
//
//            if (json.has("uid") && json.has("admin_token") && StringUtils.isNotEmpty(json.getString("admin_token"))) {
//                String adminToken = SystemConf.getInstance().getSystemProperties().getProperty("admin_token");
//                String adminUid = SystemConf.getInstance().getSystemProperties().getProperty("admin_uid");
//                if (json.getString("uid").equals(adminUid) && json.getString("admin_token").equals(adminToken)) {
//                    return true;
//                }
//            }
//
//            String tokenStr = json.has("token") ? json.getString("token") : "";
//            String uid = json.has("uid") ? json.getString("uid") : "";
//            String imei = json.has("imei") ? json.getString("imei") : "";
//            String observer = json.has("observer") ? json.getString("observer") : "";
//            //如果是观察者直接返回true
//            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
//                Class cls = ((HandlerMethod) handler).getBeanType();
//                RequestMapping clsRm = (RequestMapping) cls.getAnnotation(RequestMapping.class);
//                Method method = ((HandlerMethod) handler).getMethod();
//                RequestMapping mthRm = method.getAnnotation(RequestMapping.class);
//                String url = "";
//                String urlCls = "";
//                String urlMth = "";
//                if (clsRm.value() != null && clsRm.value().length > 0) {
//                    urlCls = clsRm.value()[0];
//                }
//                if (mthRm.value() != null && mthRm.value().length > 0) {
//                    urlMth = mthRm.value()[0];
//                }
//                if (StringUtils.isNotEmpty(urlCls)) {
//                    url += urlCls.startsWith("/") ? urlCls : ("/" + urlCls);
//                }
//                if (StringUtils.isNotEmpty(urlMth)) {
//                    url += urlMth.startsWith("/") ? urlMth : ("/" + urlMth);
//                }
//                url = url.replace("\\", "/").replace("//", "/");
//                CudUrl cudUrl = cudUrlDao.findByUrl(url);
//
//                if (url.equals("/doctor/consult/readed")) {
//                    response.getOutputStream().write(write(200, "操作成功").getBytes());
//                    return false;
//                }
//
//                if (cudUrl != null) {
//                    if (StringUtils.isNotEmpty(cudUrl.getMethod()) &&
//                            request.getMethod().toUpperCase().compareTo(cudUrl.getMethod()) != 0) {
//                        return true;
//                    } else {
//                        response.getOutputStream().write(error(403, "该操作没有权限").getBytes());
//                        return false;
//                    }
//                }
//
//                return true;
//            }
//            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                return false;
//            }
//
//            Token token = SystemData.doctorTokens.get(uid);
//            if (token == null) {
//                token = tokenDao.findByPatient(uid, 2);
//                if (token != null) {
//                    // 加入缓存
//                    SystemData.doctorTokens.put(uid, token);
//                }
//            }
//            if (token == null || token.getPlatform() != 2) {
//                // 未登录
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                flag = false;
//            } else {
//                if (token.getTimeout().getTime() < new Date().getTime()) {
//                    // 登录超时
//                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
//                    flag = false;
//                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
//                    // 别处登录
//                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
//                    flag = false;
//                } else {
//                    // 一天只更新一次
//                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
//                        // 今天未更新,则更新缓存
//                        token.setCzrq(new Date());
//                        // 更新内存
//                        SystemData.doctorTokens.put(uid, token);
//                        // 更新数据库
//                        tokenDao.save(token);
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return flag;
    }

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

@ -5,12 +5,14 @@ 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;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.statistics.PopulationBaseDao;
import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.DateUtil;
@ -20,6 +22,7 @@ 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;
@ -52,6 +55,8 @@ public class StatisticsService extends BaseService {
    private StringRedisTemplate redisTemplate;
    @Autowired
    private StatisticsAllService statisticsAllService;
    @Autowired
    private WlyyQuotaResultDao wyyQuotaResultDao;
    /**
@ -64,7 +69,7 @@ public class StatisticsService extends BaseService {
        try {
            date = redisTemplate.opsForValue().get("quota:date");
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -99,13 +104,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 endDate, String area, int level, String index, String level2_type) {
        int todayAmount = 0;
        // 查询语句
@ -131,8 +136,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 +147,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 +209,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 +236,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 +288,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 +385,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 +401,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 +509,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 +595,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 +640,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 +662,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 +724,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 +752,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 +802,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 +898,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 +929,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 +1011,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 +1104,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 +1136,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 +1203,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 +1263,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 +1292,226 @@ 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 +1519,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);
            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);
                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);
            } 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 +1610,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 +1663,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 +1716,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 +1743,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 +1808,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' " +
                    " 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 " +
                    " 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 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 +1905,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 +1993,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 +2044,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 +2118,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 +2244,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 +2282,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 +2340,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 +2425,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 +2485,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 +2562,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 +2573,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 +2586,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 +2611,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 +2633,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 +2658,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 +2681,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 +2787,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 +2815,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 +2826,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 +2845,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 +2874,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 +2885,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 +3091,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 +3101,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 +3122,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 +3133,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 +3154,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 +3166,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 +3284,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 +3428,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 +3456,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 +3503,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 +3521,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 +3652,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 +3681,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 +3728,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 +3746,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 +3873,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 +3913,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 +3971,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 +3992,167 @@ 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 + "%";
    }
}

+ 316 - 205
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -1,6 +1,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.service.app.statistics.StatisticsAllService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.util.ValueComparator;
@ -10,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
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.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -49,14 +49,14 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标按间隔统计
     * 指标按间隔统计  增量
     *
     * @param startDate 起始日期
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构
     * @param level     级别
     * @param index     指标
     * @param index     指标 3 4 5 27
     * @return
     */
    @RequestMapping(value = "/interval")
@ -86,7 +86,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标期间增长量
     * 指标期间 增长量
     *
     * @param startDate
     * @param endDate
@ -118,16 +118,16 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标截止日期累积量
     * 指标截止日期累积量  增量的累加接口
     *
     * @param endDate     结束时间
     * @param area        父code
     * @param level       等级  1 团队,2 机构,3 区,4 市
     * @param index       指标代码
     * @param index       指标代码 3 4 5 27
     * @param level2_type 指标代码 例如性别 1 男 2 女  不传就返回男和女的总和
     * @return
     */
        @RequestMapping("/total")
    @RequestMapping("/total")
    @ResponseBody
    public String getIndexTotal(@RequestParam(required = true) String endDate,
                                @RequestParam(required = true) String area,
@ -149,7 +149,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标期间增长量
     * 指标期间增长量    此接口前端没用
     *
     * @param startDate
     * @param endDate
@ -160,6 +160,7 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/lowlevel_increment")
    @ResponseBody
    @Deprecated
    public String getIndexLowLevelIncrement(@RequestParam(required = true) String startDate,
                                            @RequestParam(required = true) String endDate,
                                            @RequestParam(required = true) String area,
@ -183,8 +184,9 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标截止日期增量
     * 指标截止日期      增量
     * (如:待预约量)
     *
     * @param endDate     结束时间
     * @param area        父code
     * @param level       等级  1 团队,2 机构,3 区,4 市
@ -202,13 +204,14 @@ public class StatisticsController extends BaseController {
                                        @RequestParam(required = true) String index,
                                        @RequestParam(required = true) int sort,
                                        @RequestParam(required = false) String lowLevel,
                                        @RequestParam(required = false) String level2_type) {
                                        @RequestParam(required = false) String level2_type,
                                        @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel, level2_type));
                result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel, level2_type, year));
            }
            return write(200, "查询成功", "data", result);
@ -218,13 +221,13 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标截止日期累积量
     * 指标截止日期累积量  增量
     * 根据2个ID合并指标
     *
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @param index   3,22
     * @return
     */
    @RequestMapping("/lowlevel_total_mesh")
@ -234,14 +237,15 @@ public class StatisticsController extends BaseController {
                                            @RequestParam(required = true) int level,//等级
                                            @RequestParam(required = true) String index,//指标code
                                            @RequestParam(required = true) int sort,//1是倒叙 0是正序
                                            @RequestParam(required = false) String lowLevel) {
                                            @RequestParam(required = false) String lowLevel,
                                            @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            JSONArray returnJa = new JSONArray();
            List<JSONArray> jsonArrays = new ArrayList<>();
            JSONArray jsonArray1 = statisticsService.getLowLevelTotalDetail(endDate, area, level, indexes[0], sort, lowLevel, null);
            JSONArray jsonArray1 = statisticsService.getLowLevelTotalDetail(endDate, area, level, indexes[0], sort, lowLevel, null, year);
            jsonArrays.add(jsonArray1);
            JSONArray jsonArray2 = statisticsService.getLowLevelIncrementDetail(endDate, endDate, area, level, indexes[1], sort, lowLevel);
@ -259,22 +263,22 @@ public class StatisticsController extends BaseController {
                }
            } else {
                //如果是2个指标的时候,分别放入map中,以减少查询次数
                Map<String,JSONObject> in =new TreeMap<>();
                Map<String, JSONObject> in = new TreeMap<>();
                ValueComparator vc = new ValueComparator(in);
                Map<String,JSONObject> index2=new TreeMap<>();
                Map<String, JSONObject> index2 = new TreeMap<>();
                for (int i = 0; i < jsonArrays.get(0).length(); i++) {
                    JSONObject map1 = jsonArrays.get(0).getJSONObject(i);
                    in.put(map1.get("code").toString(),map1);
                    in.put(map1.get("code").toString(), map1);
                }
                Map<String,JSONObject> index1 =new TreeMap<>(vc);
                Map<String, JSONObject> index1 = new TreeMap<>(vc);
                index1.putAll(in);
                for (int i = 0; i < jsonArrays.get(1).length(); i++) {
                    JSONObject map1 = jsonArrays.get(1).getJSONObject(i);
                    index2.put(map1.get("code").toString(),map1);
                    index2.put(map1.get("code").toString(), map1);
                }
                for(Map.Entry<String , JSONObject> one:index1.entrySet()){
                for (Map.Entry<String, JSONObject> one : index1.entrySet()) {
                    JSONObject map1 = one.getValue();
                    JSONObject map2 = index2.get(one.getKey());
                    String amount = map1.get("amount").toString() + "," + map2.get("amount").toString();
@ -283,7 +287,7 @@ public class StatisticsController extends BaseController {
                }
            }
            if(level==2){
            if (level == 2) {
                statisticsAllService.translateTeamLeaderNameByCode(returnJa);
            }
            result.put("index_" + indexes[0], returnJa);
@ -300,7 +304,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标期间增长量
     * 指标期间      增长量
     *
     * @param startDate
     * @param endDate
@ -345,7 +349,9 @@ public class StatisticsController extends BaseController {
    public String getAreaSignInfo(@RequestParam(required = true) String endDate,
                                  @RequestParam(required = true) String area,
                                  @RequestParam(required = true) int level,
                                  @RequestParam(required = false) String lowCode) {
                                  @RequestParam(required = false) String lowCode,
                                  @RequestParam(required = false) String year
    ) {
        try {
            JSONObject result = new JSONObject();
@ -370,7 +376,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 获取三级指标增量
     * 获取三级指标增量  到达量
     *
     * @param startDate
     * @param endDate
@ -382,7 +388,8 @@ public class StatisticsController extends BaseController {
    @ResponseBody
    public String getSixFiveStatistics(@RequestParam(required = false) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String area, int level) {
                                       @RequestParam(required = true) String area,
                                       int level) {
        try {
            JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
@ -394,14 +401,16 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标按间隔统计
     * 指标按间隔统计  到达量
     *
     * @param startDate 起始日期
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构
     * @param level     级别
     * @param index     指标
     * @param index     指标 除了增量的指标都会调用
     * @param lowCode   子维度
     * @param year      查询年份
     * @return
     */
    @RequestMapping(value = "/interval_total")
@ -412,17 +421,35 @@ public class StatisticsController extends BaseController {
                                     @RequestParam(required = true) String area,
                                     @RequestParam(required = true) int level,
                                     @RequestParam(required = true) String index,
                                     @RequestParam(required = false) String lowCode) {
                                     @RequestParam(required = false) String lowCode,
                                     @RequestParam(required = false) String year) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            if (index != null) {
                for (String idx : indexes) {
                    result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode));
                    JSONObject json = statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode);
                    //如果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) {
                            JSONArray ja = json.getJSONArray("data");
                            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());
                            }
                        }
                    }
                    result.put("index_" + idx, json);
                }
            }
            return write(200, "查询成功!", "data", result);
        } catch (Exception e) {
            return error(-1, "查询失败!");
@ -430,13 +457,14 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标截止日期累积量
     * 指标截止日期累积量 到达量
     *
     * @param date
     * @param area
     * @param level level1_type等级 1:团队 2社区机构 3区级 4市级
     * @param index quotoCode 18/19两率
     * @param sort  1降序排列-1升序排列
     * @param level   level1_type等级 1:团队 2社区机构 3区级 4市级
     * @param index   quotoCode 18/19两率  28  13 17
     * @param sort    0:升序 1:降序
     * @param lowCode
     * @return
     */
    @RequestMapping("/lowlevel_all")
@ -447,20 +475,18 @@ 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 startDate) {
                                            @RequestParam(required = false) String lowCode) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            if (StringUtils.isNotEmpty(lowCode)) {
//                指定level下特定查询级别
                if(index.equals("17")){
                if (index.equals("17")) {
                    result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotalTeamLeader(date, area, level, index, sort, lowLevel, lowCode));
                }else{
                } else {
                    result.put("index_" + index, statisticsAllService.getLevelTwoLowLevelTotal(date, area, level, index, sort, lowLevel, lowCode));
                }
            } else {
//                未指定level下特定查询级别
                for (String idx : indexes) {
@ -468,11 +494,11 @@ public class StatisticsController extends BaseController {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
                    } else if (idx.equals("1") || index.equals("21")) {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal2(date, area, level, idx, sort, lowLevel));
                    } else if (idx.equals("28")){
                        result.put("index_" + idx, statisticsService.getAvgAllInfo(level,area,lowLevel));
                    } else if(idx.equals("13")){
                    } else if (idx.equals("28")) {
                        result.put("index_" + idx, statisticsService.getAvgAllInfo(level, area, lowLevel));
                    } else if (idx.equals("13")) {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotalTeamLeader(date, area, level, idx, sort, lowLevel));
                    }else{
                    } else {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
                    }
                }
@ -514,7 +540,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 二级指标到达量
     * 二级指标 到达量  废弃接口 前端没有调用
     *
     * @param date
     * @param area
@ -524,6 +550,7 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping(value = "/leveltwo_all")
    @ResponseBody
    @Deprecated
    public String getIndexLevelTwoTotal(@RequestParam(required = true) String date,
                                        @RequestParam(required = true) String area,
                                        @RequestParam(required = true) int level,
@ -544,7 +571,7 @@ public class StatisticsController extends BaseController {
    }
    /**
     * 指标截止日期到达量
     * 指标截止日期  到达量
     *
     * @param endDate
     * @param area
@ -557,13 +584,26 @@ public class StatisticsController extends BaseController {
    public String getIndexAll(@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();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
                Long total = statisticsAllService.getIndexTotal(endDate, area, level, idx);
                super.infoMessage("原来的总数:" + total);
                //如果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());
                    }
                }
                result.put("index_" + idx, total);
            }
            return write(200, "查询成功", "data", result);
@ -683,6 +723,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取得分平均数
     *
     * @param level
     * @param area
     * @return
@ -691,7 +732,7 @@ public class StatisticsController extends BaseController {
    @ResponseBody
    public String getAVGSocre(@RequestParam(required = true) String level, @RequestParam(required = true) String area) {
        try {
            return write(200, "查询成功", "data", statisticsService.getAVGSocre(level,area));
            return write(200, "查询成功", "data", statisticsService.getAVGSocre(level, area));
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
@ -700,16 +741,17 @@ public class StatisticsController extends BaseController {
    /**
     * 获取得分平均数按月份
     *
     * @return
     */
    @RequestMapping("/getAVGSocreByMonth")
    @ResponseBody
    public String getAVGSocreByMonth(@RequestParam(required = true)String level ,
                                     @RequestParam(required = true)String area,
                                     @RequestParam(required = true)String statDate,
                                     @RequestParam(required = true)String endDate){
    public String getAVGSocreByMonth(@RequestParam(required = true) String level,
                                     @RequestParam(required = true) String area,
                                     @RequestParam(required = true) String statDate,
                                     @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getAVGSocreByMonth(level,area,statDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getAVGSocreByMonth(level, area, statDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -718,15 +760,16 @@ public class StatisticsController extends BaseController {
    /**
     * 统计当前团队,签约人数,服务次数,平均满意度
     *
     * @return
     */
    @RequestMapping("/getStatTitleInfo")
    @ResponseBody
    public String getStatTitleInfo(@RequestParam(required = true)String startDate,
                                   @RequestParam(required = true)String endDate){
    public String getStatTitleInfo(@RequestParam(required = true) String startDate,
                                   @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getStatTitleInfo(getUID(),startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getStatTitleInfo(getUID(), startDate, endDate));
            //return write(200, "查询成功", "data", statisticsService.getStatTitleInfo("xh1D201703150222",startDate,endDate));
        } catch (Exception e) {
@ -737,25 +780,26 @@ public class StatisticsController extends BaseController {
    /**
     * 获取签约折线图
     *
     * @param startDate
     * @param endDate
     * @param signType 0 签约,1 续签
     * @param type 0 按周,1 按月
     * @param signType  0 签约,1 续签
     * @param type      0 按周,1 按月
     * @return
     */
    @RequestMapping("/getSignCountLineByType")
    @ResponseBody
    public String getSignCountLineByType(@RequestParam(required = true)String startDate,
                                         @RequestParam(required = true)String endDate,
                                         @RequestParam(required = true)String signType,
                                         @RequestParam(required = true)String type){
    public String getSignCountLineByType(@RequestParam(required = true) String startDate,
                                         @RequestParam(required = true) String endDate,
                                         @RequestParam(required = true) String signType,
                                         @RequestParam(required = true) String type) {
        try {
            //判断是签约还是续签
            if("0".equals(signType)){
                return write(200, "查询成功", "data", statisticsService.getSignCountLineByType(getUID(),type,startDate,endDate));
            if ("0".equals(signType)) {
                return write(200, "查询成功", "data", statisticsService.getSignCountLineByType(getUID(), type, startDate, endDate));
                //return write(200, "查询成功", "data", statisticsService.getSignCountLineByType("xh1D201703150222",type,startDate,endDate));
            }else{
                return write(200, "查询成功", "data", statisticsService.getRenewCountLineByType(getUID(),type,startDate,endDate));
            } else {
                return write(200, "查询成功", "data", statisticsService.getRenewCountLineByType(getUID(), type, startDate, endDate));
                //return write(200, "查询成功", "data", statisticsService.getRenewCountLineByType("xh1D201703150222",type,startDate,endDate));
            }
        } catch (Exception e) {
@ -766,18 +810,19 @@ public class StatisticsController extends BaseController {
    /**
     * 获取咨询数和未回复数
     *
     * @param startDate
     * @param endDate
     * @param isNow 1 为当前;2为非当前
     * @param isNow     1 为当前;2为非当前
     * @return
     */
    @RequestMapping("/getReyStatbyTeam")
    @ResponseBody
    public String  getReyStatbyTeam(@RequestParam(required = true)String startDate,
                                    @RequestParam(required = true)String endDate,
                                    @RequestParam(required = true)String isNow){
    public String getReyStatbyTeam(@RequestParam(required = true) String startDate,
                                   @RequestParam(required = true) String endDate,
                                   @RequestParam(required = true) String isNow) {
        try {
            return write(200, "查询成功", "data", statisticsService.getReyStatbyTeam(getUID(),startDate,endDate,isNow));
            return write(200, "查询成功", "data", statisticsService.getReyStatbyTeam(getUID(), startDate, endDate, isNow));
            //return write(200, "查询成功", "data", statisticsService.getReyStatbyTeam("xh1D201703150222",startDate,endDate,isNow));
        } catch (Exception e) {
            error(e);
@ -787,16 +832,17 @@ public class StatisticsController extends BaseController {
    /**
     * 获取机构内服务排行
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("/getServiceRankingList")
    @ResponseBody
    public String getServiceRankingList(@RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate){
    public String getServiceRankingList(@RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getServiceRankingList(getUID(),startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getServiceRankingList(getUID(), startDate, endDate));
            //return write(200, "查询成功", "data", statisticsService.getServiceRankingList("xh1D201703150222",startDate,endDate));
        } catch (Exception e) {
            error(e);
@ -805,20 +851,21 @@ public class StatisticsController extends BaseController {
    }
    /**
     *  获取平均值统计折线图
     * 获取平均值统计折线图
     *
     * @param startDate
     * @param endDate
     * @param type 0周,1月
     * @param type      0周,1月
     * @return
     */
    @RequestMapping("/getAvgLine")
    @ResponseBody
    public String getAvgLine(@RequestParam(required = true)String startDate,
                             @RequestParam(required = true)String endDate,
                             @RequestParam(required = true)String type){
    public String getAvgLine(@RequestParam(required = true) String startDate,
                             @RequestParam(required = true) String endDate,
                             @RequestParam(required = true) String type) {
        try {
            return write(200, "查询成功", "data", statisticsService.getAvgLine(getUID(),startDate,endDate,type));
           // return write(200, "查询成功", "data", statisticsService.getAvgLine("xh1D201703150222",startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getAvgLine(getUID(), startDate, endDate, type));
            // return write(200, "查询成功", "data", statisticsService.getAvgLine("xh1D201703150222",startDate,endDate,type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -827,11 +874,12 @@ public class StatisticsController extends BaseController {
    /**
     * 判断团队是否是团队长
     *
     * @return
     */
    @RequestMapping("/checkDoctorIsTeamLeder")
    @ResponseBody
    public String checkDoctorIsTeamLeder(){
    public String checkDoctorIsTeamLeder() {
        try {
            return write(200, "查询成功", "data", statisticsService.checkDoctorIsTeamleader(getUID()));
        } catch (Exception e) {
@ -842,20 +890,21 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队月或周咨询未回复和总数折线图
     * @param teamCode 团队id
     *
     * @param teamCode  团队id
     * @param startDate
     * @param endDate
     * @param type 0周,1月
     * @param type      0周,1月
     * @return
     */
    @RequestMapping("/getTeamConsultCount")
    @ResponseBody
    public String getTeamConsultCount(@RequestParam(required = true)String teamCode,
                                      @RequestParam(required = true)String startDate,
                                      @RequestParam(required = true)String endDate,
                                      @RequestParam(required = true)String type){
    public String getTeamConsultCount(@RequestParam(required = true) String teamCode,
                                      @RequestParam(required = true) String startDate,
                                      @RequestParam(required = true) String endDate,
                                      @RequestParam(required = true) String type) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamConsultCount(teamCode,startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getTeamConsultCount(teamCode, startDate, endDate, type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -863,23 +912,24 @@ public class StatisticsController extends BaseController {
    }
    /**
     *  计算团队医生月或周咨询未回复和总数折线图
     * 计算团队医生月或周咨询未回复和总数折线图
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param type 0周,1月
     * @param type      0周,1月
     * @param doctor
     * @return
     */
    @RequestMapping("/getTeamDoctorConsultCount")
    @ResponseBody
    public String getTeamDoctorConsultCount(@RequestParam(required = true)String teamCode,
                                             @RequestParam(required = true)String startDate,
                                             @RequestParam(required = true)String endDate,
                                             @RequestParam(required = true)String type,
                                             @RequestParam(required = true)String doctor){
    public String getTeamDoctorConsultCount(@RequestParam(required = true) String teamCode,
                                            @RequestParam(required = true) String startDate,
                                            @RequestParam(required = true) String endDate,
                                            @RequestParam(required = true) String type,
                                            @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorConsultCount(teamCode,startDate,endDate,type,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorConsultCount(teamCode, startDate, endDate, type, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -888,21 +938,22 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队内这成员,未回复数,总数,结束咨询数
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param sort 0降序,1升序
     * @param sort      0降序,1升序
     * @return
     */
    @RequestMapping("/getMemberConsultList")
    @ResponseBody
    public String getMemberConsultList(@RequestParam(required = true)String teamCode,
                                       @RequestParam(required = true)String startDate,
                                       @RequestParam(required = true)String endDate,
                                       @RequestParam(required = true)String sort,
                                       @RequestParam(required = true)String sortType){
    public String getMemberConsultList(@RequestParam(required = true) String teamCode,
                                       @RequestParam(required = true) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String sort,
                                       @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getMemberConsultList(teamCode,startDate,endDate,sort,sortType));
            return write(200, "查询成功", "data", statisticsService.getMemberConsultList(teamCode, startDate, endDate, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -911,6 +962,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取Doctor咨询结果
     *
     * @param doctor
     * @param teamCode
     * @param startDate
@ -919,12 +971,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getDoctorConsultTitle")
    @ResponseBody
    public String getDoctorConsultTitle(@RequestParam(required = true)String doctor,
                                        @RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate){
    public String getDoctorConsultTitle(@RequestParam(required = true) String doctor,
                                        @RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getDoctorConsultTitle(doctor,teamCode,startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getDoctorConsultTitle(doctor, teamCode, startDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -933,6 +985,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队随访量折线统计图
     *
     * @param type
     * @param teamCode
     * @param startDate
@ -941,12 +994,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamFollowupLine")
    @ResponseBody
    public String getTeamFollowupLine(@RequestParam(required = true)String type,
                                      @RequestParam(required = true)String teamCode,
                                      @RequestParam(required = true)String startDate,
                                      @RequestParam(required = true)String endDate){
    public String getTeamFollowupLine(@RequestParam(required = true) String type,
                                      @RequestParam(required = true) String teamCode,
                                      @RequestParam(required = true) String startDate,
                                      @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamFollowupLine(teamCode,startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getTeamFollowupLine(teamCode, startDate, endDate, type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -955,13 +1008,13 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getTeamDoctorFollowupLine")
    @ResponseBody
    public String getTeamDoctorFollowupLine(@RequestParam(required = true)String type,
                                            @RequestParam(required = true)String teamCode,
                                            @RequestParam(required = true)String startDate,
                                            @RequestParam(required = true)String endDate,
                                            @RequestParam(required = true)String doctor){
    public String getTeamDoctorFollowupLine(@RequestParam(required = true) String type,
                                            @RequestParam(required = true) String teamCode,
                                            @RequestParam(required = true) String startDate,
                                            @RequestParam(required = true) String endDate,
                                            @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorFollowupLine(teamCode,startDate,endDate,type,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorFollowupLine(teamCode, startDate, endDate, type, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -970,22 +1023,23 @@ public class StatisticsController extends BaseController {
    /**
     * 根据团队获取团队底下用户列表
     * @param sort 0为降序,1为升序
     *
     * @param sort      0为降序,1为升序
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param sortType 0为总数排序,1为增量排序,2为计划中排序
     * @param sortType  0为总数排序,1为增量排序,2为计划中排序
     * @return
     */
    @RequestMapping("/getDoctorTeamFolList")
    @ResponseBody
    public String getDoctorTeamFolList(@RequestParam(required = true)String sort,
                                       @RequestParam(required = true)String teamCode,
                                       @RequestParam(required = true)String startDate,
                                       @RequestParam(required = true)String endDate,
                                       @RequestParam(required = true)String sortType){
    public String getDoctorTeamFolList(@RequestParam(required = true) String sort,
                                       @RequestParam(required = true) String teamCode,
                                       @RequestParam(required = true) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getDoctorTeamFolList(startDate,endDate,teamCode,sort,sortType));
            return write(200, "查询成功", "data", statisticsService.getDoctorTeamFolList(startDate, endDate, teamCode, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -994,6 +1048,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取医生随访头信息
     *
     * @param teamCode
     * @param doctor
     * @param startDate
@ -1002,12 +1057,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorFolTitle")
    @ResponseBody
    public String getTeamDoctorFolTitle(@RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String doctor,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate){
    public String getTeamDoctorFolTitle(@RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String doctor,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorFolTitle(teamCode,doctor,startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorFolTitle(teamCode, doctor, startDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1016,6 +1071,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取待预约量团队统计则线图
     *
     * @param teamCode
     * @param type
     * @param startDate
@ -1024,12 +1080,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamResLine")
    @ResponseBody
    public String getTeamResLine(@RequestParam(required = true)String teamCode,
                                 @RequestParam(required = true)String type,
                                 @RequestParam(required = true)String startDate,
                                 @RequestParam(required = true)String endDate){
    public String getTeamResLine(@RequestParam(required = true) String teamCode,
                                 @RequestParam(required = true) String type,
                                 @RequestParam(required = true) String startDate,
                                 @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamResLine(teamCode,startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getTeamResLine(teamCode, startDate, endDate, type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1038,6 +1094,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队医生预约量团队统计则线图
     *
     * @param teamCode
     * @param type
     * @param startDate
@ -1047,13 +1104,13 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorResLine")
    @ResponseBody
    public String getTeamDoctorResLine(@RequestParam(required = true)String teamCode,
                                       @RequestParam(required = true)String type,
                                       @RequestParam(required = true)String startDate,
                                       @RequestParam(required = true)String endDate,
                                       @RequestParam(required = true)String doctor){
    public String getTeamDoctorResLine(@RequestParam(required = true) String teamCode,
                                       @RequestParam(required = true) String type,
                                       @RequestParam(required = true) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResLine(teamCode,startDate,endDate,type,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResLine(teamCode, startDate, endDate, type, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1062,22 +1119,23 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队待预约量医生列表信息
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param sort 0为降序,1为升序
     * @param sortType 0为按总数,1为按增数
     * @param sort      0为降序,1为升序
     * @param sortType  0为按总数,1为按增数
     * @return
     */
    @RequestMapping("/getTeamDoctorResList")
    @ResponseBody
    public String getTeamDoctorResList(@RequestParam(required = true)String teamCode,
                                       @RequestParam(required = true)String startDate,
                                       @RequestParam(required = true)String endDate,
                                       @RequestParam(required = true)String sort,
                                       @RequestParam(required = true)String sortType){
    public String getTeamDoctorResList(@RequestParam(required = true) String teamCode,
                                       @RequestParam(required = true) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String sort,
                                       @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResList(teamCode,startDate,endDate,sort,sortType));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResList(teamCode, startDate, endDate, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1086,6 +1144,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队医生待预信息
     *
     * @param teamCode
     * @param doctor
     * @param startDate
@ -1094,12 +1153,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorResTitle")
    @ResponseBody
    public String getTeamDoctorResTitle(@RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String doctor,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate){
    public String getTeamDoctorResTitle(@RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String doctor,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResTitle(teamCode,doctor,startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorResTitle(teamCode, doctor, startDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1108,20 +1167,21 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队健康指导折线图
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param type 0周,1月
     * @param type      0周,1月
     * @return
     */
    @RequestMapping("/getTeamGuidLine")
    @ResponseBody
    public String getTeamGuidLine(@RequestParam(required = true)String teamCode,
                                  @RequestParam(required = true)String startDate,
                                  @RequestParam(required = true)String endDate,
                                  @RequestParam(required = true)String type){
    public String getTeamGuidLine(@RequestParam(required = true) String teamCode,
                                  @RequestParam(required = true) String startDate,
                                  @RequestParam(required = true) String endDate,
                                  @RequestParam(required = true) String type) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamGuidLine(teamCode,startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getTeamGuidLine(teamCode, startDate, endDate, type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1129,7 +1189,8 @@ public class StatisticsController extends BaseController {
    }
    /**
     *  获取团队医生则线图
     * 获取团队医生则线图
     *
     * @param teamCode
     * @param startDate
     * @param endDate
@ -1139,13 +1200,13 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorGuidLine")
    @ResponseBody
    public String getTeamDoctorGuidLine(@RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate,
                                        @RequestParam(required = true)String type,
                                        @RequestParam(required = true)String doctor){
    public String getTeamDoctorGuidLine(@RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate,
                                        @RequestParam(required = true) String type,
                                        @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorGuidLine(teamCode,startDate,endDate,type,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorGuidLine(teamCode, startDate, endDate, type, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1154,6 +1215,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队指导总数List
     *
     * @param teamCode
     * @param startDate
     * @param endDate
@ -1163,13 +1225,13 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamGuidList")
    @ResponseBody
    public String getTeamGuidList(@RequestParam(required = true)String teamCode,
                                  @RequestParam(required = true)String startDate,
                                  @RequestParam(required = true)String endDate,
                                  @RequestParam(required = true)String sort,
                                  @RequestParam(required = true)String sortType){
    public String getTeamGuidList(@RequestParam(required = true) String teamCode,
                                  @RequestParam(required = true) String startDate,
                                  @RequestParam(required = true) String endDate,
                                  @RequestParam(required = true) String sort,
                                  @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamGuidList(teamCode,startDate,endDate,sort,sortType));
            return write(200, "查询成功", "data", statisticsService.getTeamGuidList(teamCode, startDate, endDate, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1178,6 +1240,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取医生健康指导头部信息
     *
     * @param teamCode
     * @param doctor
     * @param startDate
@ -1186,12 +1249,12 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorGuiTitle")
    @ResponseBody
    public String getTeamDoctorGuiTitle(@RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String doctor,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate){
    public String getTeamDoctorGuiTitle(@RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String doctor,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorGuiTitle(teamCode,doctor,startDate,endDate));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorGuiTitle(teamCode, doctor, startDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1200,20 +1263,21 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队健康教育折线统计
     *
     * @param teamCode
     * @param startDate
     * @param endDate
     * @param type 0按周 1按月
     * @param type      0按周 1按月
     * @return
     */
    @RequestMapping("/getTeamEduLine")
    @ResponseBody
    public String getTeamEduLine(@RequestParam(required = true)String teamCode,
                                 @RequestParam(required = true)String startDate,
                                 @RequestParam(required = true)String endDate,
                                 @RequestParam(required = true)String type){
    public String getTeamEduLine(@RequestParam(required = true) String teamCode,
                                 @RequestParam(required = true) String startDate,
                                 @RequestParam(required = true) String endDate,
                                 @RequestParam(required = true) String type) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamEduLine(teamCode,startDate,endDate,type));
            return write(200, "查询成功", "data", statisticsService.getTeamEduLine(teamCode, startDate, endDate, type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1222,6 +1286,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队健康
     *
     * @param teamCode
     * @param startDate
     * @param endDate
@ -1230,13 +1295,13 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamDoctorEduLine")
    @ResponseBody
    public String getTeamDoctorEduLine(@RequestParam(required = true)String teamCode,
                                 @RequestParam(required = true)String startDate,
                                 @RequestParam(required = true)String endDate,
                                 @RequestParam(required = true)String type,
                                 @RequestParam(required = true)String doctor){
    public String getTeamDoctorEduLine(@RequestParam(required = true) String teamCode,
                                       @RequestParam(required = true) String startDate,
                                       @RequestParam(required = true) String endDate,
                                       @RequestParam(required = true) String type,
                                       @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduLine(teamCode,startDate,endDate,type,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduLine(teamCode, startDate, endDate, type, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1245,6 +1310,7 @@ public class StatisticsController extends BaseController {
    /**
     * 获取团队成员健康教育列表
     *
     * @param teamCode
     * @param startDate
     * @param endDate
@ -1254,13 +1320,13 @@ public class StatisticsController extends BaseController {
     */
    @RequestMapping("/getTeamEduList")
    @ResponseBody
    public String getTeamEduList(@RequestParam(required = true)String teamCode,
                                 @RequestParam(required = true)String startDate,
                                 @RequestParam(required = true)String endDate,
                                 @RequestParam(required = true)String sort,
                                 @RequestParam(required = true)String sortType){
    public String getTeamEduList(@RequestParam(required = true) String teamCode,
                                 @RequestParam(required = true) String startDate,
                                 @RequestParam(required = true) String endDate,
                                 @RequestParam(required = true) String sort,
                                 @RequestParam(required = true) String sortType) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamEduList(teamCode,startDate,endDate,sort,sortType));
            return write(200, "查询成功", "data", statisticsService.getTeamEduList(teamCode, startDate, endDate, sort, sortType));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1269,12 +1335,12 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getTeamDoctorEduTitle")
    @ResponseBody
    public String getTeamDoctorEduTitle(@RequestParam(required = true)String teamCode,
                                        @RequestParam(required = true)String startDate,
                                        @RequestParam(required = true)String endDate,
                                        @RequestParam(required = true)String doctor){
    public String getTeamDoctorEduTitle(@RequestParam(required = true) String teamCode,
                                        @RequestParam(required = true) String startDate,
                                        @RequestParam(required = true) String endDate,
                                        @RequestParam(required = true) String doctor) {
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduTitle(teamCode,startDate,endDate,doctor));
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduTitle(teamCode, startDate, endDate, doctor));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -1283,7 +1349,7 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getDotorInfo")
    @ResponseBody
    public String getDotorInfo(String code){
    public String getDotorInfo(String code) {
        try {
            return write(200, "查询成功", "data", statisticsService.getDoctorInfo(code));
        } catch (Exception e) {
@ -1291,4 +1357,49 @@ public class StatisticsController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取转签率和续签率
     * 前端:续签进展页面中用到
     * @param level 等级  4 市  3区  2社区 1团队
     * @param code  市 默认是厦门市 350200  区 就是区的code  社区就是社区的code 团队就是团队的code
     * @param year 年份 非比传
     * @return
     */
    @RequestMapping(value = "/getRenewPercentAndChangePercent", method = RequestMethod.GET)
    @ResponseBody
    public String getRenewPercentAndChangePercent(
            @RequestParam(required = true) String level,
            @RequestParam(required = true) String code,
            @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsService.getRenewPercentAndChangePercent(level, code,year));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取转签人数,转签原因分析,转签分布
     * 前端:签约数据分析
     * @param level 等级  4 市  3区  2社区 1团队
     * @param code  市 默认是厦门市 350200  区 就是区的code  社区就是社区的code 团队就是团队的code
     * @param year 年份 非比传
     * @return
     */
    @RequestMapping(value = "/getRenewAnalysis", method = RequestMethod.GET)
    @ResponseBody
    public String getRenewAnalysis(
            @RequestParam(required = true) String level,
            @RequestParam(required = true) String code,
            @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsService.getRenewAnalysis(level, code,year));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
}