| 
					
				 | 
			
			
				@ -1,6 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/******************************************************************************* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Copyright (c) 2005, 2014 springside.github.io 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * <p> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Licensed under the Apache License, Version 2.0 (the "License"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 *******************************************************************************/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.wlyy.service.app.consult; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -24,8 +24,12 @@ import com.yihu.wlyy.repository.doctor.DoctorTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.util.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.SystemConf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.NameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.message.BasicNameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.domain.Page; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -89,7 +93,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 查询三师签约信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(sc == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (sc == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("不存在三师签约"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置健康管理师,三师咨询默认给健康管理师处理 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -104,7 +108,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if (type == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 咨询家庭医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            SignFamily sf = signFamilyDao.findByjiatingPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(sf == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (sf == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("不存在家庭签约"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置健康管理师,家庭医生咨询默认给健康管理师处理 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -117,7 +121,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                member = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(member == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (member == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("找不到签约服务团队医生"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int count = consultTeamDao.countByPatient(patient, member.getMemberCode()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -536,6 +540,8 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void reply(List<ConsultTeamLog> logs, String patient) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (ConsultTeamLog log : logs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            reply(log, patient, null, log.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //推送给IM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sendIM(patient, log.getDoctor(), log.getChatType()+"", log.getContent()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -585,6 +591,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 患者端 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 添加三师咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ct      三师咨询对象 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -669,20 +676,52 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setTo(ct.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content = addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String returnJson= sendIM(ct.getPatient(), ct.getDoctor(), "1", content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jo=new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consult.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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 发送消息给IM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param from 来自 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param to 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param contentType 1文字 2图片消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param content 内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String sendIM(String from, String to, String contentType, String content) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String imAddr = SystemConf.getInstance().getImListGet() + "api/v1/chats/pm"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("from", from)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("to", to)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("contentType", contentType)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("content", content)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String response = HttpClientUtil.post(imAddr, params, "UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return response; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 添加三师咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private void addLogs(ConsultTeam ct) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String addLogs(ConsultTeam ct) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加问题咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content = ""; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -751,6 +790,7 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 患者提问或追问,给医生发消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -810,6 +850,14 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public int finish(String consult) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Consult consultObj=consultDao.findByCode(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ConsultTeam consultTeam=consultTeamDao.findByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String returnJson=  sendIM(consultTeam.getPatient(), consultTeam.getDoctor(), "1", "本次咨询结束");; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jo=new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultObj.setEndMsgId(jo.getInt("startId")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return consultTeamDao.updateStatusByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1052,9 +1100,25 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cd.setTo(ct.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String content=addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //推送给IM文字消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String returnJson=  sendIM(ct.getPatient(), ct.getDoctor(), "1", content);; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jo=new JSONObject(returnJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置消息ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consult.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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 |