| 
					
				 | 
			
			
				@ -28,9 +28,7 @@ import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.SignFamilyDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.talk.TalkGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.SystemConf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.NameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.message.BasicNameValuePair; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -53,7 +51,8 @@ import org.springside.modules.persistence.SearchFilter.Operator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springside.modules.utils.Clock; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.task.PushMsgTask; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.MessageType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.print.Doc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 網絡諮詢类. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -88,6 +87,8 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientHealthGuidanceService guidanceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private TalkGroupService talkGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private com.yihu.wlyy.service.common.account.DoctorService doctorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询患者是否还有未结束的三师咨询 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -658,6 +659,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public int addTeamConsult(ConsultTeam ct, String patient) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject users = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 咨询三师 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (ct.getType() == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 查询三师签约信息 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -671,13 +673,20 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //查找病人所在的团队 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //得到团队的健康管理师 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (doctorTeamMember == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMemberHealthy = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (doctorTeamMemberHealthy == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ct.setDoctor(doctorTeamMember.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                users.put(doctorTeamMember.getMemberCode(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                users.put(doctorTeamMemberHealthy.getMemberCode(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(doctorTeamMember!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    users.put(doctorTeamMember.getMemberCode(),1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置家庭医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDoctor(doctorTeamMember.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setAdminTeamId(sc.getAdminTeamId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if (ct.getType() == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 咨询家庭医生 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -690,14 +699,19 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //查找病人所在的团队 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //得到团队的健康管理师 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (doctorTeamMember == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMemberHealthy = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (doctorTeamMemberHealthy == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ct.setDoctor(doctorTeamMember.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                users.put(doctorTeamMemberHealthy.getMemberCode(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                users.put(doctorTeamMemberHealthy.getMemberCode(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(doctorTeamMember!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    users.put(doctorTeamMember.getMemberCode(),1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setTeam(sf.getTeamCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置家庭医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDoctor(doctorTeamMember.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setAdminTeamId(sf.getAdminTeamId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置患者信息 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -733,23 +747,14 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setTo(ct.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content = addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String returnJson = sendIM(ct.getPatient(), ct.getDoctor(), "6", content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jo = new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (jo.has("startId")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setStartMsgId(jo.getInt("startId")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //推送给IM图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNotEmpty(ct.getImages())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String[] images = ct.getImages().split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (String image : images) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (StringUtils.isNoneEmpty(image)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sendIM(ct.getPatient(), ct.getDoctor(), "2", image); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM去创建议题,取得成员消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject messages  = ImUtill.getCreateTopicMessage(patient,tempPatient.getName(),consult.getTitle(),consult.getSymptoms(),consult.getImages()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        users.put(patient,0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject obj  = ImUtill.createTopics(patient+"_consult_"+ct.getType(),consult.getCode(),"咨询问题:"+consult.getSymptoms(),users,messages,"1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException("IM消息结束异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDao.save(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -949,7 +954,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("send consult finished IM message failed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject jo = new JSONObject(returnJson);            //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeam.setEndMsgId(jo.getInt("startId")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeam.setEndMsgId(jo.getInt("startId")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeam.setEndOperator(endOperator); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeam.setEndType(endType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1212,7 +1217,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jo = new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(jo.getInt("startId")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(jo.getInt("startId")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotEmpty(ct.getImages())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] images = ct.getImages().split(","); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1345,7 +1350,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sendIM(ct.getPatient(), ct.getDoctor(), "6", content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jo = new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(jo.getInt("startId")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(jo.getInt("startId")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotEmpty(ct.getImages())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] images = ct.getImages().split(","); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1429,4 +1434,227 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List findByTeam(String consult){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return consultTeamDao.findByTeamAndType(consult, 10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 全科医生求助专科医生(同团队) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param uid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param oldConsultCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void addSeekHelpTeam(ConsultTeam ct, String uid,String oldConsultCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPatient(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject participants = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        participants.put(ct.getPatient(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        participants.put(ct.getDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Doctor doctor = doctorService.findDoctorByCode(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject sessionJson =  ImUtill.createSession(participants,"2",doctor.getName()+"发起求助!",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(sessionJson.getInt("status")==-1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw  new RuntimeException(sessionJson.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject session = sessionJson.getJSONObject("data"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotEmpty(oldConsultCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ConsultTeam oldConsult =  consultTeamDao.findByConsult(oldConsultCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(oldConsult!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"),"1","居民问题:" +oldConsult.getSymptoms()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //推送给IM图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNotEmpty(oldConsult.getImages())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String[] images = oldConsult.getImages().split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (String image : images) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (StringUtils.isNoneEmpty(image)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2",image); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"),"1","咨询问题:"+ ct.getSymptoms()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotEmpty(ct.getImages())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] images = ct.getImages().split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String image : images) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNoneEmpty(image)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"), "2",image); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 全科医生求助专科医生(不同团队) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param uid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param oldConsultCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void addSeekHelpOtherTeam(ConsultTeam ct, String uid,String oldConsultCode) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPatient(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Doctor doctorTemp = doctorDao.findByCode(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置医生姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setName(doctorTemp.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置医生生日 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setBirthday(doctorTemp.getBirthday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //新增性别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setSex(doctorTemp.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置医生头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPhoto(doctorTemp.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置操作日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 患者未读数量为0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPatientRead(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ConsultTeamDoctor cd = new ConsultTeamDoctor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setTo(ct.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content = addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject messages  = ImUtill.getCreateTopicMessage(doctorTemp.getCode(),doctorTemp.getName(),consult.getTitle(),content,consult.getImages()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put(ct.getPatient(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put(ct.getDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject obj = ImUtill.createTopics(null,consult.getCode(),doctorTemp.getName(),jsonObject,messages,"2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj==null||obj.getInt("status")==-1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException("im消息创建异常!"+obj==null?"":obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //转发咨询问题 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(oldConsultCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Consult oldConsult = consultDao.findByCode(oldConsultCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(oldConsult!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"6",content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(StringUtils.isNotBlank(oldConsult.getImages())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String imgs[] = oldConsult.getImages().split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for(String url :imgs) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"2",url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDao.save(ct);  // 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public int finishConsult(String consult, String endOperator, int endType){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ConsultTeam consultTeam = consultTeamDao.findByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String endName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String endId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (endType == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Patient p = patientDao.findByCode(endOperator); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            endName = p.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            endId = p.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Doctor d = doctorDao.findByCode(endOperator); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            endId = d.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            endName = d.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject obj = ImUtill.endTopics(consultTeam.getPatient(),endId,endName,consultTeam.getConsult()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException("IM消息结束异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj.getInt("status")==-1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeam.setType(endType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeam.setEndMsgId(obj.getString("id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return consultTeamDao.updateStatusByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 新增名医咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param uid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type 1患者 2医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void famousConsult(ConsultTeam ct, String uid, String type) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPatient(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String senderId=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String senderName=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("1".equals(type)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 查询患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Patient tempPatient = patientDao.findByCode(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setName(tempPatient.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者生日 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setBirthday(tempPatient.getBirthday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //新增性别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setSex(tempPatient.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setPhoto(tempPatient.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            senderId = tempPatient.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            senderName = tempPatient.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("2".equals(type)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Doctor doctorTemp = doctorDao.findByCode(uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置医生姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setName(doctorTemp.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置医生生日 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setBirthday(doctorTemp.getBirthday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //新增性别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setSex(doctorTemp.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置医生头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setPhoto(doctorTemp.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            senderId = doctorTemp.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            senderName = doctorTemp.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置操作日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 患者未读数量为0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setPatientRead(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ConsultTeamDoctor cd = new ConsultTeamDoctor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setTo(ct.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content = addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put(ct.getPatient(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put(ct.getDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject messages = ImUtill.getCreateTopicMessage(senderId,senderName,senderName+"发起咨询",content,ct.getImages()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject obj = ImUtill.createTopics(null,consult.getCode(),consult.getSymptoms(),jsonObject,messages,"2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException("im消息创建异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(obj.getInt("status")==-1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ct.setStartMsgId(obj.getString("start_msg_id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDao.save(ct);  // 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |