chenweida hace 8 años
padre
commit
dc8e60f136
Se han modificado 23 ficheros con 1990 adiciones y 1629 borrados
  1. 3 4
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/SignFamily.java
  2. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java
  3. 90 41
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java
  4. 51 6
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  5. 36 12
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java
  6. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java
  7. 93 41
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  8. 43 26
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java
  9. 85 5
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java
  10. 1186 1334
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  11. 33 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java
  12. 39 27
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  13. 11 11
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  14. 33 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java
  15. 36 20
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultPublicController.java
  16. 38 20
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java
  17. 17 6
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/DoctorPatientGroupController.java
  18. 7 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  19. 7 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorSignController.java
  20. 43 23
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  21. 28 8
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java
  22. 78 22
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java
  23. 31 5
      patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinOpenIdUtils.java

+ 3 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/SignFamily.java

@ -1,13 +1,12 @@
package com.yihu.wlyy.entity.patient;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import java.util.Date;
/**
 * 家庭签约

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -40,7 +40,7 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Query(" from Message a where a.read = 1 and over ='1' and a.sender = ?1 and a.receiver=?2 and a.signStatus='1'")
    Message findByPatient(String patient,String doctor);
    @Query("select a from Message a where a.receiver = ?1 and a.sender=?2 and a.tzType=?3 order by a.czrq desc")
    @Query("select a from Message a where a.receiver = ?1 and a.sender=?2 and a.tzType=?3 order by a.createTime desc")
    List<Message> getHealthIndexMessageByPatient(String doctor,String patient,String type,Pageable pageRequest);
    @Modifying

+ 90 - 41
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -1,18 +1,16 @@
package com.yihu.wlyy.service.app.account;
import java.util.*;
import com.yihu.wlyy.entity.address.City;
import com.yihu.wlyy.entity.address.Province;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.entity.consult.Consult;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.doctor.OperatorLog;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroup;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
import com.yihu.wlyy.entity.doctor.OperatorLog;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.WlyyPatientSick;
@ -22,20 +20,17 @@ import com.yihu.wlyy.repository.address.TownDao;
import com.yihu.wlyy.repository.consult.ConsultDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.doctor.DoctorTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.repository.doctor.OperatorLogDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientSickDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.talk.TalkGroupService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.EncodesUtil;
import com.yihu.wlyy.util.ImUtill;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
@ -47,7 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
@ -57,8 +51,7 @@ import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.EncodesUtil;
import java.util.*;
/**
 * 医生基本信息类.
@ -864,6 +857,7 @@ public class DoctorInfoService extends BaseService {
            }
        } else {
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", newD.getCode());
            data.put("doctorName", newD.getName());
            data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位责任医生,医生信息如下:");
@ -880,19 +874,35 @@ public class DoctorInfoService extends BaseService {
        //判断是否判定openId,有没有发则查找家人发送
        if (StringUtils.isNotBlank(p.getOpenid())) {
            PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        } else {
            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
            Patient member = (Patient) json.get("member");
            if (StringUtils.isNotBlank(member.getOpenid())) {
                String first = (String) data.get("first");
                data.remove("first");
                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
        }
//        else {
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                String first = (String) data.get("first");
//                data.remove("first");
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
//                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//
//            }
//        }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
        if(jsonArray!=null&&jsonArray.length()>0){
            String first = (String) data.get("first");
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser",member.getCode());
                    json.remove("first");
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), json);
                }
            }
        }
    }
    @Transactional
@ -981,6 +991,7 @@ public class DoctorInfoService extends BaseService {
        Patient p = patientDao.findByCode(patient);
        JSONObject data = new JSONObject();
        data.put("toUser", patient);
        data.put("represented",patient);//被代理人
        data.put("doctor", newD.getCode());
        data.put("doctorName", newD.getName());
        data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位责任医生,医生信息如下:");
@ -995,15 +1006,34 @@ public class DoctorInfoService extends BaseService {
        if (StringUtils.isNotBlank(p.getOpenid())) {
            PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        } else {
            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
            Patient member = (Patient) json.get("member");
            if (StringUtils.isNotBlank(member.getOpenid())) {
                String first = (String) data.get("first");
                data.remove("first");
                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
        }
//        else {
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                String first = (String) data.get("first");
//                data.remove("first");
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
//                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//            }
//        }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
        if(jsonArray!=null&&jsonArray.length()>0){
            String first = (String) data.get("first");
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser",member.getCode());
                    json.remove("first");
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), json);
                }
            }
        }
        return 1;
@ -1184,6 +1214,7 @@ public class DoctorInfoService extends BaseService {
        Patient p = patientDao.findByCode(patient);
        JSONObject data = new JSONObject();
        data.put("toUser", patient);
        data.put("represented",patient);//被代理人
        data.put("doctor", newD.getCode());
        data.put("doctorName", newD.getName());
        data.put("keyword3", "家庭医生");
@ -1199,16 +1230,34 @@ public class DoctorInfoService extends BaseService {
            data.put("first", p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
                    "医生无法继续为您服务,具体变动如下:");
            PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        } else {
            //如果自己没有绑定,则发给家人
            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
            Patient member = (Patient) json.get("member");
            if (StringUtils.isNotBlank(member.getOpenid())) {
                data.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), member.getName()) + p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
                        "医生无法继续为您服务,具体变动如下:");
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
            }
        }
//        else {
//            //如果自己没有绑定,则发给家人
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), member.getName()) + p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
//                        "医生无法继续为您服务,具体变动如下:");
//                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//            }
//        }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
        if(jsonArray!=null&&jsonArray.length()>0){
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser",member.getCode());
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), member.getName()) + p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
                            "医生无法继续为您服务,具体变动如下:");
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), json);
                }
            }
        }
    }
}

+ 51 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -31,6 +31,7 @@ import com.yihu.wlyy.service.app.talk.TalkGroupService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
@ -91,7 +92,8 @@ public class ConsultTeamService extends ConsultService {
    private PatientFamilyMemberDao familyMemberDao;
    @Autowired
    private HealthEduArticleService healthEduArticleService;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private TalkGroupService talkGroupService;
    @Autowired
@ -1782,7 +1784,7 @@ public class ConsultTeamService extends ConsultService {
        consultDao.save(consult);
    }
    public int finishConsult(String consult, String endOperator, int endType) {
    public int finishConsult(String consult, String endOperator, int endType) throws Exception{
        ConsultTeam consultTeam = consultTeamDao.findByConsult(consult);
        Consult cons = consultDao.findByCode(consult);
@ -1803,10 +1805,31 @@ public class ConsultTeamService extends ConsultService {
            json.put("keyword1", "满意度评价");
            json.put("keyword2", sdf.format(new Date()));
            json.put("toUser", p.getCode());
            json.put("represented",p.getCode());//被代理人
            json.put("remark", "");
            json.put("consult", consult);
            json.put("first", endName + ",您好!您有1条咨询已结束,请及时对咨询医生进行满意度评价。");
            PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
            String first = endName + ",您好!您有1条咨询已结束,请及时对咨询医生进行满意度评价。";
            json.put("first", first);
            if(StringUtils.isNotBlank(p.getOpenid())){
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                        PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), data);
                    }
                }
            }
        } else {
            if (endOperator.equals("admin")) {
                endId = "system";
@ -1825,10 +1848,32 @@ public class ConsultTeamService extends ConsultService {
                json.put("keyword1", "满意度评价");
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", p.getCode());
                json.put("represented",p.getCode());//被代理人
                json.put("remark", "");
                json.put("consult", consult);
                json.put("first", name + ",您好!您有1条咨询已结束,请及时对咨询医生进行满意度评价。");
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
                String first = name + ",您好!您有1条咨询已结束,请及时对咨询医生进行满意度评价。";
                json.put("first", first);
                if(StringUtils.isNotBlank(p.getOpenid())){
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                if(jsonArray!=null&&jsonArray.length()>0){
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                            PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 17, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
            }
        }
        JSONObject obj = ImUtill.endTopics(consultTeam.getPatient(), endId, endName, consultTeam.getConsult());

+ 36 - 12
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java

@ -12,6 +12,7 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -49,6 +50,8 @@ public class PatientHealthGuidanceService extends BaseService {
	WeiXinOpenIdUtils weiXinOpenIdUtils;
	@Autowired
	private PatientService patientService;
	@Autowired
	private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
	public JSONObject findById(Long id){
		PatientHealthGuidance guidance = patientHealthGuidanceDao.findOne(id);
@ -127,26 +130,47 @@ public class PatientHealthGuidanceService extends BaseService {
			json.put("first", "健康指导提醒");
			//name = patient.getName();
			openId = patient.getOpenid();
		}else{
			JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
			Patient member = (Patient)j.get("member");
			openId = member.getOpenid();
			//name = member.getName();
			if (StringUtils.isNotEmpty(openId)) {
				json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()) + "健康指导提醒");
			}
		}
		if (guidance != null && StringUtils.isNotEmpty(openId)) {
//		else{
//			JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
//			Patient member = (Patient)j.get("member");
//			openId = member.getOpenid();
//			//name = member.getName();
//			if (StringUtils.isNotEmpty(openId)) {
//				json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()) + "健康指导提醒");
//			}
//		}
		if (guidance != null ) {
			json.put("toUser", patient.getCode());
			json.put("represented",patient.getCode());//被代理人
			json.put("id", guidance.getId());
			json.put("date", DateUtil.getStringDate());
			json.put("orgName", doctor.getHospitalName());
			json.put("doctorName", doctor.getName());
			json.put("content", "您好!医生给您发来了一份新的健康指导。");
			json.put("remark", "请点击查看");
			// 推送消息到微信端
			PushMsgTask.getInstance().putWxMsg(accessToken, 4, openId, patient.getName(), json);
			if(StringUtils.isNotEmpty(openId)){
				// 推送消息到微信端
				PushMsgTask.getInstance().putWxMsg(accessToken, 4, openId, patient.getName(), json);
			}
			//发送代理人
			JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode());
			if(jsonArray!=null&&jsonArray.length()>0){
				for (int i = 0;i<jsonArray.length();i++){
					JSONObject j  = jsonArray.getJSONObject(i);
					Patient member = (Patient) j.get("member");
					if(StringUtils.isNotBlank(member.getOpenid())){
						JSONObject data = json;
						data.remove("toUser");
						data.put("toUser",member.getCode());
						String first = (String) json.get("first");
						data.remove("first");
						data.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), member.getName()) + "健康指导提醒");
						PushMsgTask.getInstance().putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 4, member.getOpenid(), member.getName(), data);
					}
				}
			}
		}
		return guidance;
	}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -384,7 +384,7 @@ public class MessageService extends BaseService {
                map.put("read", String.valueOf(item.getRead()));
                map.put("sex", String.valueOf(item.getSex()));
                map.put("czrq", DateUtil.dateToStrLong(item.getCzrq()));
                map.put("czrq", DateUtil.dateToStrLong(item.getCreateTime()));
                DevicePatientHealthIndex data =devicePatientHealthIndexDao.findOne(Long.valueOf(item.getTzCode()));
                if(data!=null)

+ 93 - 41
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -1,7 +1,6 @@
package com.yihu.wlyy.service.app.sign;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.OperatorLog;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.profile.DoctorService;
@ -32,11 +31,9 @@ import com.yihu.wlyy.task.SignUploadTask;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.CachedIntrospectionResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -1412,6 +1409,7 @@ public class FamilyContractService extends BaseService {
            JSONObject json = new JSONObject();
            json.put("first", "解约申请通知");
            json.put("toUser", sf.getPatient());
            json.put("represented",sf.getPatient());//被代理人
            json.put("date", DateUtil.getStringDateShort());
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
@ -1421,19 +1419,36 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
            }
//            else {
//                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
//                Patient member = (Patient) j.get("member");
//                if (StringUtils.isNotBlank(member.getOpenid())) {
//                    String first = (String) json.get("first");
//                    json.remove("first");
//                    Patient p = patientDao.findByCode(patient);
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
//                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient());
            if(jsonArray!=null&&jsonArray.length()>0){
                Patient p = patientDao.findByCode(patient);
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                        PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), data);
                    }
                }
            }
        } else {
            // 更新状态为正常
            signFamilyDao.refuseSurrender(patient);
@ -1441,6 +1456,7 @@ public class FamilyContractService extends BaseService {
            JSONObject json = new JSONObject();
            json.put("first", "解约申请通知");
            json.put("toUser", sf.getPatient());
            json.put("represented",sf.getPatient());//被代理人
            json.put("date", DateUtil.getStringDateShort());
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
@ -1450,19 +1466,37 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
            }
//            else {
//                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
//                Patient member = (Patient) j.get("member");
//                if (StringUtils.isNotBlank(member.getOpenid())) {
//                    String first = (String) json.get("first");
//                    json.remove("first");
//                    Patient p = patientDao.findByCode(patient);
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
//                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient());
            if(jsonArray!=null&&jsonArray.length()>0){
                Patient p = patientDao.findByCode(patient);
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                        PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), data);
                    }
                }
            }
        }
        return 1;
    }
@ -1871,7 +1905,7 @@ public class FamilyContractService extends BaseService {
     * @param healthDoctor 健康管理师code
     * @return
     */
    public JSONObject updateSignInfo(String patient, String healthDoctor, String doctor, String expensesType, String loginUser) {
    public JSONObject updateSignInfo(String patient, String healthDoctor, String doctor, String expensesType, String loginUser) throws Exception{
        JSONObject result = new JSONObject();
        Patient p = patientDao.findByCode(patient);
@ -2038,6 +2072,7 @@ public class FamilyContractService extends BaseService {
            JSONObject data = new JSONObject();
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", docQk.getCode());
            data.put("doctorName", docQk.getName());
            data.put("first", p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
@ -2070,24 +2105,41 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotBlank(p.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), msg);
            } else {
                //如果自己没有绑定,则发给家人
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) msg.get("first");
                    msg.remove("first");
                    try {
                        msg.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    } catch (Exception e) {
                        e.printStackTrace();
            }
//            else {
//                //如果自己没有绑定,则发给家人
//                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                Patient member = (Patient) j.get("member");
//                if (StringUtils.isNotBlank(member.getOpenid())) {
//                    String first = (String) msg.get("first");
//                    msg.remove("first");
//
//                    try {
//                        msg.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), msg);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        JSONObject data = msg;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        String first = (String) data.get("first");
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                        PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
                    }
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), msg);
                }
            }
        }
        OperatorLog operatorLog = new OperatorLog();
        operatorLog.setCreateTime(new Date());
@ -3482,7 +3534,7 @@ public class FamilyContractService extends BaseService {
                        if(labelCode.indexOf("-")==-1){
                            if(labelCode.equals(serverType)){
                                Map<String,String> code = new HashMap<>();
                                code.put("code",serverType);
                                code.put("code",(String)p.get("patient"));
                                codes.add(code);
                                iterator.remove();
                            }
@ -3490,7 +3542,7 @@ public class FamilyContractService extends BaseService {
                            String[] key = labelCode.split("-");
                            if(key[0].equals(serverType)){
                                Map<String,String> code = new HashMap<>();
                                code.put("code",serverType);
                                code.put("code",(String)p.get("patient"));
                                codes.add(code);
                                iterator.remove();
                            }

+ 43 - 26
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java

@ -14,19 +14,17 @@ import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.task.RemindExpensesTask;
import com.yihu.wlyy.task.RemindFocusWechatTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
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.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -213,34 +211,53 @@ public class PatientRemindService extends BaseService {
            }
//            if (StringUtils.isNotEmpty(p.getOpenid())) {
                // 微信提醒
                JSONObject json = new JSONObject();
                json.put("first", "缴费提醒");
                json.put("toUser", p.getCode());
                json.put("name", p.getName());
                json.put("doctor", doc.getCode());
                json.put("doctorName", "提醒医生:  "+doc.getName());
                json.put("date", DateUtil.dateToStrShort(new Date()));
                json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
                json.put("remark", "");
                //判断是否判定openId,有没有发则查找家人发送
                if(StringUtils.isNotBlank(p.getOpenid())){
                    isOpenIdExist = true;
                    // 添加到发送队列
                    PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
                }else{
                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
            // 微信提醒
            JSONObject json = new JSONObject();
            json.put("first", "缴费提醒");
            json.put("toUser", p.getCode());
            json.put("represented",p.getCode());//被代理人
            json.put("name", p.getName());
            json.put("doctor", doc.getCode());
            json.put("doctorName", "提醒医生:  "+doc.getName());
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
            json.put("remark", "");
            //判断是否判定openId,有没有发则查找家人发送
            if(StringUtils.isNotBlank(p.getOpenid())){
                isOpenIdExist = true;
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
            }
//                else{
//                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                    Patient member = (Patient) j.get("member");
//                    if(StringUtils.isNotBlank(member.getOpenid())){
//                        isOpenIdExist = true;
//                        String first = (String) json.get("doctorName");
//                        json.remove("doctorName");
//                        json.put("doctorName",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+"\n"+first);
//                        PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), member.getName(), json);
//                    }
//                }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
            if(jsonArray!=null&&jsonArray.length()>0){
                String first = (String) json.get("doctorName");
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        isOpenIdExist = true;
                        String first = (String) json.get("doctorName");
                        json.remove("doctorName");
                        json.put("doctorName",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+"\n"+first);
                        PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), member.getName(), json);
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        data.remove("doctorName");
                        data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) +"\n"+first);
                        PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), member.getName(), data);
                    }
                }
            }
                wFlag = true;
//            }

+ 85 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -1,7 +1,5 @@
package com.yihu.wlyy.service.app.sign;
import java.util.*;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
@ -16,6 +14,8 @@ import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.SignFamilyRenewDao;
import com.yihu.wlyy.repository.patient.SignFamilyRenewLogDao;
import com.yihu.wlyy.repository.patient.SignWebDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.SMSService;
@ -24,10 +24,10 @@ import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -37,8 +37,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.yihu.wlyy.repository.patient.SignWebDao;
import com.yihu.wlyy.service.BaseService;
import java.util.*;
/**
 * 网络签约业务处理类
@ -81,6 +80,8 @@ public class SignWebService extends BaseService {
    private DoctorTeamDao doctorTeamDao;
    @Autowired
    private DoctorTeamMemberDao doctorTeamMemberDao;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    /**
     * 根据医生代码及签约状态编码 获取该医生签约患者的信息列表
@ -981,6 +982,85 @@ public class SignWebService extends BaseService {
    }
    /**
     * 批量提醒用户
     *
     * @param access_token
     * @param doctor
     * @return
     * @throws Exception
     */
    public int sendRenewOverToPatients(String access_token, String doctor) throws Exception {
        String sql = "SELECT " +
                " p. NAME, " +
                " p.openid, " +
                " t.doctor_name doctorName, " +
                " p. CODE, " +
                " p.mobile " +
                " FROM " +
                " wlyy_sign_family t, " +
                " wlyy_patient p " +
                " WHERE " +
                " t.patient = p. CODE " +
                " AND t.doctor = '"+doctor+"' " +
                " AND t.status =-4 " +
                " AND t.expenses_status = '1' " +
                " AND t.sign_year = '"+(DateUtil.getSignYear()-1)+"' " +
                " AND NOT EXISTS ( " +
                " SELECT " +
                "  1 " +
                " FROM " +
                "  wlyy_sign_family a " +
                " WHERE " +
                "  a.patient = t.patient " +
                " AND a.status>0  " +
                " AND a.sign_year = '"+DateUtil.getSignYear()+"' " +
                ")";
        List<Map<String, Object>> signFamilies = jdbcTemplate.queryForList(sql, new Object[]{doctor});
        if (signFamilies != null && signFamilies.size() > 0) {
            for (Map<String, Object> signFamily : signFamilies) {
                String openid = (String) signFamily.get("openid");
                String name = (String) signFamily.get("name");
                String doctorName = (String) signFamily.get("doctorName");
                JSONObject json = new JSONObject();
                json.put("keyword1", "续签家庭医生");
                json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                json.put("remark", "提醒医生 :" + doctorName + "\n"
                        + "我们将继续为您提供优质的健康服务。");
                if (StringUtils.isNotBlank(openid)) {
                    json.put("first", name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                    PushMsgTask.getInstance().putWxMsg(access_token, 16, openid, name, json);
                } else {
                    //如果自己没有绑定,则发给家人
                    String code = (String) signFamily.get("code");
                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(code);
                    Patient member = (Patient) j.get("member");
                    Patient p = patientService.findByCode(code);
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), member.getName()) + "\n" +
                                name + ",您好!\n" +
                                "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                        PushMsgTask.getInstance().putWxMsg(access_token, 16, member.getOpenid(), member.getName(), json);
                    } else {
                        //发送短信
                        String mobile = (String) signFamily.get("mobile");
                        if (StringUtils.isNotBlank(mobile)) {
                            SMSService.sendMsg(mobile, name + "您好!您的家庭医生将于6月30日到期,为了继续给您提供健康服务,请关注“厦门i健康”公众号,回复“续签”,进行家庭医生线上续签。");
                        }
                    }
                }
            }
            return 1;
        }
        return 0;
    }
    /**
     * 同意或拒绝签约签约
     *

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

@ -5,14 +5,12 @@ 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;
@ -22,7 +20,6 @@ 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;
@ -55,8 +52,6 @@ public class StatisticsService extends BaseService {
    private StringRedisTemplate redisTemplate;
    @Autowired
    private StatisticsAllService statisticsAllService;
    @Autowired
    private WlyyQuotaResultDao wyyQuotaResultDao;
    /**
@ -69,7 +64,7 @@ public class StatisticsService extends BaseService {
        try {
            date = redisTemplate.opsForValue().get("quota:date");
        } catch (Exception e) {
        }catch (Exception e){
            e.printStackTrace();
        }
@ -104,13 +99,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;
        // 查询语句
@ -136,8 +131,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});
@ -147,7 +142,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 = "";
            }
@ -209,7 +204,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 = "";
            }
@ -236,7 +231,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, String year) throws Exception {
    public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel,String level2_type) throws Exception {
        String areaField = "";
        String lowLevelField = "";
        String lowLevelName = "";
@ -288,17 +283,13 @@ 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 + "'";
        }
        //如果year有值 就按照年度来查询 即2017年 就是大于2017-06-30
        if (!org.springframework.util.StringUtils.isEmpty(year)) {
            sql += " and quota_date > '" + year + "-06-30' ";
        if(org.apache.commons.lang3.StringUtils.isNoneEmpty(level2_type)){
            sql+=" and level2_type = '"+level2_type+"'";
        }
        sql += " group by " + lowLevelField;//+ "," + lowLevelName;更具名称group by会有问题
        sql+=   " group by " + lowLevelField ;//+ "," + lowLevelName;更具名称group by会有问题
        if (sort == 1) {
            sql += " order by amount desc";
@ -385,7 +376,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 = "";
                    }
@ -401,26 +392,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);
            }
@ -509,8 +500,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";
@ -595,7 +586,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 = "";
                    }
@ -640,13 +631,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();
@ -662,7 +653,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 = "";
@ -724,7 +715,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 = "";
                }
@ -752,11 +743,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);
@ -802,7 +793,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 = "";
@ -898,7 +889,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 = "";
                }
@ -929,11 +920,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);
@ -1011,7 +1002,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 = "";
@ -1104,7 +1095,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 = "";
                }
@ -1136,10 +1127,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);
@ -1203,56 +1194,55 @@ 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," +
@ -1263,27 +1253,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 ");
        }
@ -1292,226 +1282,222 @@ 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;
    }
@ -1519,89 +1505,88 @@ 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);
            }
        });
@ -1610,50 +1595,49 @@ 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("时间区间错误");
        }
@ -1663,38 +1647,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");//格式化为年月
@ -1716,26 +1700,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;
@ -1743,62 +1727,61 @@ 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);
@ -1808,96 +1791,94 @@ 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();
@ -1905,81 +1886,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();
@ -1993,48 +1974,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);
        }
        //待预约量排行
@ -2044,73 +2025,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;
@ -2118,125 +2099,123 @@ 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;
@ -2244,37 +2223,36 @@ 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 " +
@ -2282,57 +2260,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 " +
@ -2340,84 +2318,83 @@ 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 " +
@ -2425,59 +2402,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 " +
@ -2485,65 +2462,64 @@ 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, " +
@ -2562,10 +2538,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 " +
@ -2573,12 +2549,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, " +
@ -2586,15 +2562,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 " +
@ -2611,21 +2587,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, " +
@ -2633,15 +2609,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 " +
@ -2658,22 +2634,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, " +
@ -2681,101 +2657,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, " +
@ -2787,25 +2763,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 " +
@ -2815,10 +2791,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 " +
@ -2826,16 +2802,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 " +
@ -2845,26 +2821,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 " +
@ -2874,10 +2850,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 " +
@ -2885,198 +2861,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, " +
@ -3091,8 +3067,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 " +
@ -3101,11 +3077,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 " +
@ -3122,9 +3098,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 " +
@ -3133,11 +3109,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 " +
@ -3154,10 +3130,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 " +
@ -3166,117 +3142,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);
                    }
                }
            }
@ -3284,136 +3260,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, " +
@ -3428,19 +3404,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, " +
@ -3456,42 +3432,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) {
@ -3503,10 +3479,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) {
@ -3521,125 +3497,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 " +
@ -3652,23 +3628,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 " +
@ -3681,42 +3657,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) {
@ -3728,10 +3704,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) {
@ -3746,119 +3722,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, " +
@ -3873,32 +3849,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, " +
@ -3913,50 +3889,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) {
@ -3971,10 +3947,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) {
@ -3992,167 +3968,43 @@ 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 + "%";
    }
}

+ 33 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -698,7 +698,14 @@ public class PatientService extends TokenService {
            teamCodeSql=" and f.admin_team_code="+teamCode+" ";
        }
        // 获取总分组数量
        String totalGSql = "SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name AS serverTypeName FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"') AND f.`status`>0 AND f.server_type IS NOT NULL "+teamCodeSql+" GROUP BY f.server_type ORDER BY f.server_type ASC";
        String totalGSql ="SELECT d.`code` AS serverType,d.`name` AS serverTypeName,ifNULL(c.Amount,0) AS Amount FROM " +
                " wlyy_sign_dict d LEFT JOIN" +
                " ("+
                " SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name AS serverTypeName FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"') AND f.`status`>0 AND f.server_type IS NOT NULL "+teamCodeSql+" GROUP BY f.server_type ORDER BY f.server_type ASC"+
                " ) c ON d.code = c.serverType " +
                " WHERE d.`year`='"+DateUtil.getSignYear()+"' AND d.`code` NOT LIKE '%-%' ";
//        String totalGSql = "SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name AS serverTypeName FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"') AND f.`status`>0 AND f.server_type IS NOT NULL "+teamCodeSql+" GROUP BY f.server_type ORDER BY f.server_type ASC";
        List<Map<String,Object>> totalG = jdbcTemplate.queryForList(totalGSql);
        //获取关注量分组数量
@ -706,7 +713,31 @@ public class PatientService extends TokenService {
        List<Map<String,Object>> fousG = jdbcTemplate.queryForList(fousGSql);
        //获取二级节点分组总数
        String sesTotalSql ="SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name As serverTypeName ,f.special_population AS specialPopulation,f.special_population_name AS specialPopulationName  FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"')  "+teamCodeSql+" AND f.`status`>0  AND f.special_population Is NOT NULL AND f.server_type IS NOT NULL GROUP BY f.special_population ORDER BY f.special_population ASC ";
        String sesTotalSql ="SELECT " +
                " LEFT ( " +
                "  d.`code`, " +
                "  INSTR(d.`code`, '-') - 1 " +
                " ) AS serverType, " +
                " substring( " +
                "  d.`code`, " +
                "  INSTR(d.`code`, '-') + 1 " +
                " ) AS specialPopulation, " +
                " d.`name` AS specialPopulationName, " +
                " ifnull(c.Amount, 0) AS Amount " +
                " FROM " +
                " wlyy_sign_dict d " +
                " LEFT JOIN ( "+
                " SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name As serverTypeName ,f.special_population AS specialPopulation,f.special_population_name AS specialPopulationName ," +
                " CONCAT(" +
                " f.server_type," +
                " '-'," +
                " f.special_population" +
                " ) AS dcode FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"')  "+teamCodeSql+" AND f.`status`>0  AND f.special_population Is NOT NULL AND f.server_type IS NOT NULL GROUP BY f.special_population ORDER BY f.special_population ASC )" +
                " c ON c.dcode = d.code " +
                " WHERE\n" +
                " d.`year` = '"+DateUtil.getSignYear()+"'" +
                " AND d.`code` LIKE '%-%'";
        //String sesTotalSql ="SELECT count(1) AS Amount,f.server_type AS serverType,f.server_type_name As serverTypeName ,f.special_population AS specialPopulation,f.special_population_name AS specialPopulationName  FROM wlyy_sign_family f WHERE (f.doctor ='"+doctor+"' OR f.doctor_health ='"+doctor+"')  "+teamCodeSql+" AND f.`status`>0  AND f.special_population Is NOT NULL AND f.server_type IS NOT NULL GROUP BY f.special_population ORDER BY f.special_population ASC ";
        List<Map<String,Object>> sesTotal = jdbcTemplate.queryForList(sesTotalSql);
        //获取二级节点分组数量

+ 39 - 27
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -1,27 +1,17 @@
package com.yihu.wlyy.service.survey;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplate;
import com.yihu.wlyy.entity.wechat.WechatTemplateData;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.doctor.survey.ManagerQuestionnaireController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;
import org.bouncycastle.jce.provider.symmetric.HC128;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
@ -29,7 +19,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -86,7 +75,8 @@ public class ManagerQuestionnaireService extends BaseService {
    private DoctorDao doctorDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
@ -261,28 +251,50 @@ public class ManagerQuestionnaireService extends BaseService {
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("represented", c);
                        json.put("survey_id", surveyCode);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                        json.put("first", first);
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            if (StringUtils.isNotBlank(member.getOpenid())) {
                                String first = (String) json.get("first");
                                json.remove("first");
                                try {
                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                } catch (Exception e) {
                                    e.printStackTrace();
                        }
//                        else {
//                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
//                            Patient member = (Patient) j.get("member");
//                            if (StringUtils.isNotBlank(member.getOpenid())) {
//                                String first = (String) json.get("first");
//                                json.remove("first");
//                                try {
//                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
//                                } catch (Exception e) {
//                                    e.printStackTrace();
//                                }
//                                logger.error("没有opIn  json =======>" + json);
////                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
//                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if(StringUtils.isNotBlank(member.getOpenid())){
                                    json.remove("toUser");
                                    json.put("toUser",member.getCode());
                                    json.remove("first");
                                    try {
                                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    PushMsgTask.getInstance().sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), member.getName(), json);
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }

+ 11 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -250,9 +250,9 @@ public class PushMsgTask {
            String temp_id = "";
            if (type == 3) {
                if (json.has("isPublic") && json.getInt("isPublic") == 1) {
                    temp.setUrl(url + "jbsq/html/public-consult-detail.html?openid=" + openid + "&code=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                    temp.setUrl(url + "jbsq/html/public-consult-detail.html?openid=" + openid + "&code=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                } else {
                    temp.setUrl(url + "yszx/html/consulting-doctor.html?openid=" + openid + "&consult=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                    temp.setUrl(url + "yszx/html/consulting-doctor.html?openid=" + openid + "&consult=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                }
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_consult_notice");
                temp.setTemplate_id(temp_id);
@ -307,7 +307,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("content"));
                m.put("keyword4", keyword4);
            } else if (type == 4) {
                temp.setUrl(url + "yszd/html/guidance-detail.html?openid=" + openid + "&toUser=" + json.getString("toUser") + "&id=" + String.valueOf(json.get("id")) + "&toName=" + name);
                temp.setUrl(url + "yszd/html/guidance-detail.html?openid=" + openid + "&toUser=" + json.getString("toUser") + "&id=" + String.valueOf(json.get("id")) + "&toName=" + name+"&represented="+json.getString("represented"));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_health_notice");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -331,7 +331,7 @@ public class PushMsgTask {
                keyword5.setValue(json.getString("content"));
                m.put("keyword5", keyword5);
            } else if (type == 5) {
                temp.setUrl(url + "ssgg/html/doctor-homepage-new.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "ssgg/html/doctor-homepage-new.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_termination");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -351,7 +351,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("date"));
                m.put("keyword4", keyword4);
            } else if (type == 6) {
                temp.setUrl(url + "wdyy/html/detail-appointment.html?openid=" + openid + "&orgCode=" + json.get("orgCode") + "&id=" + json.getString("id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "wdyy/html/detail-appointment.html?openid=" + openid + "&orgCode=" + json.get("orgCode") + "&id=" + json.getString("id") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_appoint_success");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -371,7 +371,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("date"));
                m.put("planstarttime", keyword4);
            } else if (type == 7) {
                temp.setUrl(url + "wdyy/html/my-appointment.html?openid=" + openid + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "wdyy/html/my-appointment.html?openid=" + openid + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_appoint_failed");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -411,7 +411,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("content"));
                m.put("remark", keyword4);
            } else if (type == 9) {
                temp.setUrl(url + "jkjy/html/article.html?openid=" + openid + "&dataId=" + json.getString("article") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "jkjy/html/article.html?openid=" + openid + "&dataId=" + json.getString("article") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_healthy_article");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -435,7 +435,7 @@ public class PushMsgTask {
                keyword5.setValue(json.getString("remark"));
                m.put("remark", keyword5);
            } else if (type == 10) {
                temp.setUrl(url + "qygl/html/signing-doctors.html?openid=" + openid + "&state=" + openid + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "qygl/html/signing-doctors.html?openid=" + openid + "&state=" + openid + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_change"));
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -453,7 +453,7 @@ public class PushMsgTask {
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            } else if (type == 11) {
                String xinurl = url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name;
                String xinurl = url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented");
//                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(xinurl);
//                temp.setTemplate_id("fgYiMntj1amEkE8_GLUPmAIyssUAroJrNSHqvydt-PQ");
@ -539,7 +539,7 @@ public class PushMsgTask {
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
            } else if (type == 16) {
                temp.setUrl(url + "xuqian/html/information.html?openid=" + openid+"&changeDoctor="+1);
                temp.setUrl(url + "xuqian/html/information.html?openid=" + openid+"&changeDoctor="+1 + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
@ -550,7 +550,7 @@ public class PushMsgTask {
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
            } else if (type == 17) {
                temp.setUrl(url + "yszx/html/doctor-consultation.html?openid=" + openid + "&consult=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "yszx/html/doctor-consultation.html?openid=" + openid + "&consult=" + json.getString("consult") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&represented="+json.getString("represented"));
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");

+ 33 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java

@ -7,14 +7,13 @@ import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.print.Doc;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -32,6 +31,8 @@ public class RemindExpensesTask implements Runnable {
    @Autowired
    WeiXinAccessTokenUtils tokenUtils;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    ConsultService consultService;
    public RemindExpensesTask(List<Patient> patients, Doctor doctor, Hospital hospital) {
@ -53,20 +54,39 @@ public class RemindExpensesTask implements Runnable {
                    }
                    sb.append(p.getMobile());
                }
                // 微信提醒
                JSONObject json = new JSONObject();
                json.put("first", "缴费提醒");
                json.put("toUser", p.getCode());
                json.put("represented",p.getCode());//被代理人
                json.put("name", p.getName());
                json.put("doctor", doctor.getCode());
                json.put("doctorName", doctor.getName());
                json.put("date", DateUtil.dateToStrShort(new Date()));
                json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                json.put("remark", "");
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    // 微信提醒
                    JSONObject json = new JSONObject();
                    json.put("first", "缴费提醒");
                    json.put("toUser", p.getCode());
                    json.put("name", p.getName());
                    json.put("doctor", doctor.getCode());
                    json.put("doctorName", doctor.getName());
                    json.put("date", DateUtil.dateToStrShort(new Date()));
                    json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                    json.put("remark", "");
                    // 添加到发送队列
                    PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                if(jsonArray!=null&&jsonArray.length()>0){
                    String first = (String) json.get("doctorName");
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            data.remove("doctorName");
                            data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) +"\n"+first);
                            PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), member.getName(), data);
                        }
                    }
                }
                //发送IM
                consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                        "尽早为您提供家庭医生服务,请尽快到" + doctor.getName() + "(地址:" + hospital.getAddress() + ")缴费", "1", p.getName());

+ 36 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultPublicController.java

@ -1,11 +1,16 @@
package com.yihu.wlyy.web.doctor.consult;
import java.util.Date;
import com.yihu.wlyy.entity.consult.ConsultPublic;
import com.yihu.wlyy.entity.consult.ConsultPublicReply;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.service.app.account.DoctorInfoService;
import com.yihu.wlyy.service.app.consult.ConsultPublicService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
@ -17,18 +22,10 @@ import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yihu.wlyy.entity.consult.ConsultPublic;
import com.yihu.wlyy.entity.consult.ConsultPublicReply;
import com.yihu.wlyy.service.app.consult.ConsultPublicService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MessageType;
import com.yihu.wlyy.web.BaseController;
import java.util.Date;
/**
 * 医生端:公共咨询控制类
@ -234,8 +231,10 @@ public class DoctorConsultPublicController extends BaseController {
				Patient p = patientService.findByCode(cp.getPatient());
				JSONObject json = new JSONObject();
				json.put("isPublic", 1);
				json.put("first", p.getName() + ",您好!\n您的公共咨询有新的回复");
				String first = p.getName() + ",您好!\n您的公共咨询有新的回复";
				json.put("first", first);
				json.put("toUser", p.getCode());
				json.put("represented",p.getCode());//被代理人
				String symp = cp.getContent();
//				json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...")  : content);
				json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...")  : symp);
@ -249,14 +248,31 @@ public class DoctorConsultPublicController extends BaseController {
				if(StringUtils.isNotBlank(p.getOpenid())){
					// 添加到发送队列
					PushMsgTask.getInstance().putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, p.getOpenid(), p.getName(), json);
				}else{
					JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
					Patient member = (Patient) j.get("member");
					if(StringUtils.isNotBlank(member.getOpenid())){
						String first = (String) json.get("first");
						json.remove("first");
						json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
						PushMsgTask.getInstance().putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), member.getName(), json);
				}
//				else{
//					JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//					Patient member = (Patient) j.get("member");
//					if(StringUtils.isNotBlank(member.getOpenid())){
//						String first = (String) json.get("first");
//						json.remove("first");
//						json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//						PushMsgTask.getInstance().putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), member.getName(), json);
//					}
//				}
				//发送代理人
				JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
				if(jsonArray!=null&&jsonArray.length()>0){
					for (int i = 0;i<jsonArray.length();i++){
						JSONObject j  = jsonArray.getJSONObject(i);
						Patient member = (Patient) j.get("member");
						if(StringUtils.isNotBlank(member.getOpenid())){
							JSONObject data = json;
							data.remove("toUser");
							data.put("toUser",member.getCode());
							data.remove("first");
							data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
							PushMsgTask.getInstance().putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), member.getName(), data);
						}
					}
				}

+ 38 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -1,7 +1,6 @@
package com.yihu.wlyy.web.doctor.health;
import java.util.*;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.education.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
@ -10,18 +9,19 @@ import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.health.*;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ImUtill;
import com.yihu.wlyy.util.MessageType;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.doctor.message.DoctorMessageController;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.htmlparser.Parser;
import org.htmlparser.beans.StringBean;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.TextExtractingVisitor;
import org.json.JSONArray;
@ -35,12 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MessageType;
import com.yihu.wlyy.web.BaseController;
import java.util.*;
/**
 * 医生端:健康教育控制类
@ -429,6 +425,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
                        json.put("article", temp.getCode() + "");
                        json.put("title", temp.getTitle());
                        json.put("doctorName", doctor.getName());
                        json.put("represented",p);//被代理人
                        json.put("date", DateUtil.dateToStrLong(DateUtil.getNowDate()));
                        json.put("remark", endMsg);
                        Map<String, Object> content = new HashMap<>();
@ -456,18 +453,39 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
                                map.get("openid") == null ? "" : map.get("openid").toString(),
                                map.get("name") == null ? "" : map.get("name").toString(),
                                (JSONObject) map.get("json"));
                    }else{
                        JSONObject j = weiXinOpenIdUtils.getFamilyOpenId((String)map.get("code"));
                    }
//                    else{
//                        JSONObject j = weiXinOpenIdUtils.getFamilyOpenId((String)map.get("code"));
//                        Patient p = patientService.findByCode((String)map.get("code"));
//                        Patient member = (Patient)j.get("member");
//                        JSONObject data = (JSONObject) map.get("json");
//                        String first = (String)data.get("first");
//                        data.remove("first");
//                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.isNull("relation")?1:j.getInt("relation"),p.getName()));
//                        if(StringUtils.isNotBlank(member.getOpenid())){
//                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 9, member.getOpenid(), member.getName(), data);
//                        }
//                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId((String)map.get("code"));
                    if(jsonArray!=null&&jsonArray.length()>0){
                        Patient p = patientService.findByCode((String)map.get("code"));
                        Patient member = (Patient)j.get("member");
                        JSONObject data = (JSONObject) map.get("json");
                        String first = (String)data.get("first");
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.isNull("relation")?1:j.getInt("relation"),p.getName()));
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 9, member.getOpenid(), member.getName(), data);
                        for (int i=0;i<jsonArray.length();i++){
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient)j.get("member");
                            JSONObject data = (JSONObject) map.get("json");
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            String first = (String)data.get("first");
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.isNull("relation")?1:j.getInt("relation"),member.getName()));
                            if(StringUtils.isNotBlank(member.getOpenid())){
                                PushMsgTask.getInstance().putWxMsg(getAccessToken(), 9, member.getOpenid(), member.getName(), data);
                            }
                        }
                    }
                }
                for (HealthEduArticlePatient heap : list) {
                    BusinessLogs.info(BusinessLogs.BusinessType.article, getUID(), heap.getPatient(), new JSONObject(heap));

+ 17 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/DoctorPatientGroupController.java

@ -3,8 +3,10 @@ package com.yihu.wlyy.web.doctor.patient;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroup;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorTeamDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.account.DoctorInfoService;
import com.yihu.wlyy.service.app.account.DoctorPatientGroupService;
@ -53,6 +55,8 @@ public class DoctorPatientGroupController extends BaseController {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private DoctorTeamDao doctorTeamDao;
    private final int DOCTOR_PATIENT_OBJECT_LENGTH = 13;
@ -1144,14 +1148,21 @@ public class DoctorPatientGroupController extends BaseController {
            JSONArray array = new JSONArray();
            List<Doctor> doctors = new ArrayList<>();
            SignFamily signFamily = signFamilyDao.findByFamilyDoctorAndPatient(getUID(), patient);
            if (signFamily != null) {
            //签约团队
            DoctorTeam dt = doctorTeamDao.findByPatientCode(patient);
            if(dt!=null){
                // 查询家庭医生团队
                doctors = drHealthTeamService.findTeamDoctors(signFamily.getTeamCode());
            }else{
                //健管查询
                doctors = drHealthTeamService.findTeamDoctorsByPatient(patient);
                doctors = drHealthTeamService.findTeamDoctors(dt.getCode());
            }
//            SignFamily signFamily = signFamilyDao.findByFamilyDoctorAndPatient(getUID(), patient);
//            if (signFamily != null) {
//                // 查询家庭医生团队
//                doctors = drHealthTeamService.findTeamDoctors(signFamily.getTeamCode());
//            }else{
//                //健管查询
//                doctors = drHealthTeamService.findTeamDoctorsByPatient(patient);
//            }
            if (doctors != null && doctors.size() > 0) {
                for (Doctor doctor : doctors) {
                    if (doctor == null) {

+ 7 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -223,6 +223,13 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    @ResponseBody
    public String getPatientLables(String labelType, String level, String oldDoctorCode, Long teamCode) {
        try {
            //修改年度服务类型1.3.4需求
            if("1".equals(labelType)){
                JSONObject  rs =  familyContractService.getServerPatientList(teamCode);
                return write(200, "查询成功!", "data", rs);
            }
            int count = 0;
            List listNum = new ArrayList();
            JSONObject list = familyContractService.getPatientByLable(oldDoctorCode, labelType, level, teamCode);

+ 7 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorSignController.java

@ -424,7 +424,13 @@ public class DoctorSignController extends WeixinBaseController {
    @ApiOperation(value = "提醒用户签约接口")
    public String sendRenewToPatients(){
        try{
            int rs = signWebService.sendRenewToPatients(getAccessToken(),getUID());
            int rs ;
            if(DateUtil.getNowMonth()>=7){
                rs = signWebService.sendRenewOverToPatients(getAccessToken(),getUID());
            }else{
                rs = signWebService.sendRenewToPatients(getAccessToken(),getUID());
            }
            //int rs = signWebService.sendRenewToPatients(getAccessToken(),"zbqD201703150222");
            if(rs == 0){
                return write(200, "您当前签约用户无需提醒!", "data", rs);

+ 43 - 23
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java

@ -1,18 +1,12 @@
package com.yihu.wlyy.web.doctor.survey;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplates;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplate;
import com.yihu.wlyy.entity.wechat.WechatTemplateData;
import com.yihu.wlyy.repository.doctor.SurveyUserDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.survey.ManagerQuestionnaireService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -23,7 +17,6 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -31,7 +24,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 管理端问卷调查 manager路径需要验证
@ -50,6 +46,8 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    private SurveyUserDao surveyUserDao;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
@ -470,28 +468,50 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("represented", c);
                        json.put("survey_id", code);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                        json.put("first", first);
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            if (StringUtils.isNotBlank(member.getOpenid())) {
                                String first = (String) json.get("first");
                                json.remove("first");
                                try {
                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                } catch (Exception e) {
                                    e.printStackTrace();
                        }
//                        else {
//                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
//                            Patient member = (Patient) j.get("member");
//                            if (StringUtils.isNotBlank(member.getOpenid())) {
//                                String first = (String) json.get("first");
//                                json.remove("first");
//                                try {
//                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
//                                } catch (Exception e) {
//                                    e.printStackTrace();
//                                }
//                                logger.error("没有opIn  json =======>" + json);
////                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
//                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if(StringUtils.isNotBlank(member.getOpenid())){
                                    json.remove("toUser");
                                    json.put("toUser",member.getCode());
                                    json.remove("first");
                                    try {
                                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    PushMsgTask.getInstance().sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), member.getName(), json);
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }

+ 28 - 8
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java

@ -13,6 +13,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -70,6 +71,7 @@ public class PatientBookingController extends WeixinBaseController{
                    JSONObject json = new JSONObject();
                    json.put("first", "");
                    json.put("toUser", p.getCode());
                    json.put("represented",p.getCode());//被代理人
                    json.put("name", obj.getName());
                    json.put("date", obj.getStartTime());
                    json.put("doctorName", obj.getDoctorName());
@ -80,14 +82,32 @@ public class PatientBookingController extends WeixinBaseController{
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
                    }else{
                        JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                        Patient member = (Patient) j.get("member");
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            String first = (String) json.get("first");
                            json.remove("first");
                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
                    }
//                    else{
//                        JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                        Patient member = (Patient) j.get("member");
//                        if(StringUtils.isNotBlank(member.getOpenid())){
//                            String first = (String) json.get("first");
//                            json.remove("first");
//                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
//                        }
//                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                    if(jsonArray!=null&&jsonArray.length()>0){
                        String first = (String) json.get("first");
                        for (int i = 0;i<jsonArray.length();i++){
                            JSONObject j  = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            if(StringUtils.isNotBlank(member.getOpenid())){
                                JSONObject data = json;
                                data.remove("toUser");
                                data.put("toUser",member.getCode());
                                data.remove("first");
                                data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                                PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), data);
                            }
                        }
                    }
                }

+ 78 - 22
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/BookingController.java

@ -300,6 +300,7 @@ public class BookingController extends WeixinBaseController {
                JSONObject json = new JSONObject();
                json.put("first", "");
                json.put("toUser", p.getCode());
                json.put("represented",p.getCode());//被代理人
                json.put("id", obj.getCode());
                json.put("date", obj.getStartTime());
                json.put("orgCode", obj.getOrgCode());
@ -312,19 +313,36 @@ public class BookingController extends WeixinBaseController {
                if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
                    }else{
                        JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                }
//                else{
//                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                    Patient member = (Patient) j.get("member");
//                    if(StringUtils.isNotBlank(member.getOpenid())){
//                        String first = (String) json.get("first");
//                        json.remove("first");
//                        json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
//                    }
//                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                if(jsonArray!=null&&jsonArray.length()>0){
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            String first = (String) json.get("first");
                            json.remove("first");
                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), data);
                        }
                    }
                }
                //发送短信小时
                // 调用总部发送信息的接口
                //String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
@ -378,6 +396,7 @@ public class BookingController extends WeixinBaseController {
                    JSONObject json = new JSONObject();
                    json.put("first", "");
                    json.put("toUser", p.getCode());
                    json.put("represented",p.getCode());//被代理人
                    json.put("name", obj.getName());
                    json.put("date", obj.getStartTime());
                    json.put("doctorName", obj.getDoctorName());
@ -388,14 +407,32 @@ public class BookingController extends WeixinBaseController {
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
                    }else{
                        JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                        Patient member = (Patient) j.get("member");
                        if(StringUtils.isNotBlank(member.getOpenid())){
                            String first = (String) json.get("first");
                            json.remove("first");
                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
                    }
//                    else{
//                        JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                        Patient member = (Patient) j.get("member");
//                        if(StringUtils.isNotBlank(member.getOpenid())){
//                            String first = (String) json.get("first");
//                            json.remove("first");
//                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
//                        }
//                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                    if(jsonArray!=null&&jsonArray.length()>0){
                        for (int i = 0;i<jsonArray.length();i++){
                            JSONObject j  = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            if(StringUtils.isNotBlank(member.getOpenid())){
                                JSONObject data = json;
                                data.remove("toUser");
                                data.put("toUser",member.getCode());
                                String first = (String) json.get("first");
                                data.remove("first");
                                data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                                PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), data);
                            }
                        }
                    }
                }
@ -503,6 +540,7 @@ public class BookingController extends WeixinBaseController {
                        JSONObject json = new JSONObject();
                        json.put("first", "");
                        json.put("toUser", patient);
                        json.put("represented",patient);//被代理人
                        json.put("id", orderCode);
                        json.put("date", obj.getStartTime());
                        json.put("orgName", obj.getOrgName());
@ -515,14 +553,32 @@ public class BookingController extends WeixinBaseController {
                        if(StringUtils.isNotBlank(p.getOpenid())){
                            // 添加到发送队列
                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), patientName, json);
                        }else{
                            JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                            Patient member = (Patient) j.get("member");
                            if(StringUtils.isNotBlank(member.getOpenid())){
                                String first = (String) json.get("first");
                                json.remove("first");
                                json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                                PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
                        }
//                        else{
//                            JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                            Patient member = (Patient) j.get("member");
//                            if(StringUtils.isNotBlank(member.getOpenid())){
//                                String first = (String) json.get("first");
//                                json.remove("first");
//                                json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                                PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if(StringUtils.isNotBlank(member.getOpenid())){
                                    JSONObject data = json;
                                    data.remove("toUser");
                                    data.put("toUser",member.getCode());
                                    String first = (String) json.get("first");
                                    data.remove("first");
                                    data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                                    PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), data);
                                }
                            }
                        }

+ 31 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinOpenIdUtils.java

@ -1,16 +1,14 @@
package com.yihu.wlyy.wechat.util;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.util.IdCardUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
@ -102,8 +100,36 @@ public class WeiXinOpenIdUtils {
        return result;
    }
    /**
     * 查找代理人的openId
     * @param code
     * @return
     */
    public JSONArray getAgentOpenId(String code) {
        JSONArray result = new JSONArray();
        StringBuffer sql = new StringBuffer("SELECT * FROM wlyy_patient_family_member t WHERE t.patient = '" + code + "' and t.is_authorize =1 ");
        List<Map<String, Object>> members = jdbcTemplate.queryForList(sql.toString());
        if (members != null && members.size() > 0) {
            for (Map<String, Object> member : members) {
                String memberCode = (String) member.get("family_member");
                if (StringUtils.isNotBlank(memberCode)) {
                    Patient p = patientDao.findByCode(memberCode);
                    if (StringUtils.isNotBlank(p.getOpenid())) {
                        JSONObject json = new JSONObject();
                        json.put("member", p);
                        json.put("relation", (int) member.get("family_relation"));
                        result.put(json);
                    }
                }
            }
        }
        return result;
    }
    public String getTitleMes(Patient p, int ralation, String dealerName) throws Exception {
        return "因您的" + relations.get(familyRelationTrans(p, ralation)) + p.getName() + "未绑定微信,故请将该消息传达给" + dealerName + ":";
        return "因您是" + relations.get(familyRelationTrans(p, ralation)) + p.getName() + "的代理人,故请将该消息传达给" + dealerName + ":";
    }
    /**