|  | @ -0,0 +1,1035 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.im.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamDoctorDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamLogDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultTeamDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultTeamDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultTeamLogDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.im.util.ImUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.util.ImageCompress;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.im.ConsultVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.FileUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.service.WxAccessTokenService;
 | 
	
		
			
				|  |  | import org.apache.http.NameValuePair;
 | 
	
		
			
				|  |  | import org.apache.http.message.BasicNameValuePair;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Page;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.PageRequest;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Sort;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | import java.io.File;
 | 
	
		
			
				|  |  | import java.io.FileOutputStream;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.io.InputStream;
 | 
	
		
			
				|  |  | import java.net.HttpURLConnection;
 | 
	
		
			
				|  |  | import java.net.URL;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * IM接口业务类
 | 
	
		
			
				|  |  |  * @author huangwenjie
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class ImService {
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public ConsultDao consultDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public ConsultTeamDao consultTeamDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public ConsultTeamDoctorDao consultTeamDoctorDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public ConsultTeamLogDao consultTeamLogDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public BasePatientDao basePatientDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public ImUtil imUtil;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	public FileUtil fileUtil;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	protected HttpServletRequest request;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	public WxAccessTokenService wxAccessTokenService;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${im.data_base_name}")
 | 
	
		
			
				|  |  | 	private String data_base_name;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${FileTempPath.upload_temp_path}")
 | 
	
		
			
				|  |  | 	private String upload_temp_path;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${FileTempPath.image_path}")
 | 
	
		
			
				|  |  | 	private String image_path;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${FileTempPath.voice_path}")
 | 
	
		
			
				|  |  | 	private String voice_path;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${FileTempPath.chat_file_path}")
 | 
	
		
			
				|  |  | 	private String chat_file_path;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Value("${fastDFS.fastdfs_file_url}")
 | 
	
		
			
				|  |  | 	private String fastdfs_file_url;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	private BaseDoctorDao baseDoctorDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	@Autowired
 | 
	
		
			
				|  |  | 	private OutpatientDao outpatientDao;
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 查询患者所有的咨询记录
 | 
	
		
			
				|  |  | 	 * @param patient 患者标识
 | 
	
		
			
				|  |  | 	 * @param id 会话ID(等同IM表topicId)
 | 
	
		
			
				|  |  | 	 * @param type 咨询会话类型
 | 
	
		
			
				|  |  | 	 * @param pagesize 分页大小
 | 
	
		
			
				|  |  | 	 * @param title 标题关键字
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public List<ConsultVO>  findConsultRecordByPatient(String patient, String id,Integer type, int pagesize, String title) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 		if (pagesize <= 0) {
 | 
	
		
			
				|  |  | 			pagesize = 10;
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String  sql = "SELECT " +
 | 
	
		
			
				|  |  | 				"a.id AS id," +
 | 
	
		
			
				|  |  | 				"a.type AS type," +
 | 
	
		
			
				|  |  | 				"a.title AS title," +
 | 
	
		
			
				|  |  | 				"a.symptoms AS symptoms," +
 | 
	
		
			
				|  |  | 				"a.czrq AS czrq," +
 | 
	
		
			
				|  |  | 				"b.status AS status," +
 | 
	
		
			
				|  |  | 				"b.evaluate AS evaluate," +
 | 
	
		
			
				|  |  | 				"d.name AS doctorName," +
 | 
	
		
			
				|  |  | 				"d.photo AS doctorphoto," +
 | 
	
		
			
				|  |  | 				"d.job_title_name AS jobTitleName " +
 | 
	
		
			
				|  |  | 				"FROM wlyy_consult a," +
 | 
	
		
			
				|  |  | 				"wlyy_consult_team b," +
 | 
	
		
			
				|  |  | 				"base_doctor d " +
 | 
	
		
			
				|  |  | 				"WHERE a.id=b.consult " +
 | 
	
		
			
				|  |  | 				"AND b.doctor=d.id AND a.patient='"+patient+"' AND a.type="+type;
 | 
	
		
			
				|  |  | 		List<ConsultVO> result = new ArrayList<>();
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		if(!StringUtils.isEmpty(title)){
 | 
	
		
			
				|  |  | 			title="%"+title+"%";
 | 
	
		
			
				|  |  | 			sql +=" and a.title like '"+title+"'";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		if (!StringUtils.isEmpty(id)) {
 | 
	
		
			
				|  |  | 			sql += " and a.id = '" + id + "'";
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		sql += " ORDER BY a.id desc limit 0,"+pagesize+"";
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		result = jdbcTemplate.query(sql, new BeanPropertyRowMapper(ConsultVO.class));
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		return result;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 查询居民与某个医生未结束的咨询
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param patient 居民
 | 
	
		
			
				|  |  | 	 * @param doctor  医生
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public String  getUnfinishedConsult(String patient, String doctor) {
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String totalSql = "SELECT a.consult as consultCode " +
 | 
	
		
			
				|  |  | 				"FROM wlyy_consult_team a,wlyy_consult_team_doctor b " +
 | 
	
		
			
				|  |  | 				"WHERE a.consult=b.consult " +
 | 
	
		
			
				|  |  | 				"AND a.patient= '" +patient+"' "+
 | 
	
		
			
				|  |  | 				"AND b.to_doctor='" +doctor+"' "+
 | 
	
		
			
				|  |  | 				"AND a.del='1' " +
 | 
	
		
			
				|  |  | 				"AND a.type<> 8 " +
 | 
	
		
			
				|  |  | 				"AND a.`status`=0";
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String consultCode = "";
 | 
	
		
			
				|  |  | 		if (rstotal != null && rstotal.size() > 0) {
 | 
	
		
			
				|  |  | 			consultCode = rstotal.get(0).get("consultCode").toString();
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return consultCode;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取会话成员
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param sessionId
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 * @throws Exception
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONArray getSessions(String sessionId) {
 | 
	
		
			
				|  |  | 		JSONArray participants = imUtil.getSessions(sessionId);
 | 
	
		
			
				|  |  | 		return participants;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 根据会话ID获取消息记录
 | 
	
		
			
				|  |  | 	 * @param sessionId 会话ID
 | 
	
		
			
				|  |  | 	 * @param startMsgId 开始的消息记录ID
 | 
	
		
			
				|  |  | 	 * @param endMsgId  结束的消息记录ID
 | 
	
		
			
				|  |  | 	 * @param page  第几页
 | 
	
		
			
				|  |  | 	 * @param pagesize  分页数量
 | 
	
		
			
				|  |  | 	 * @param uid 居民CODE
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONArray getSessionMessage(String sessionId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
 | 
	
		
			
				|  |  | 		JSONArray messageArray = imUtil.getSessionMessage(sessionId, startMsgId, endMsgId, page, pagesize, uid);
 | 
	
		
			
				|  |  | 		return messageArray;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 根据咨询CODE进入会话
 | 
	
		
			
				|  |  | 	 * @param consult 咨询CODE
 | 
	
		
			
				|  |  | 	 * @param currentUid 当前居民ID
 | 
	
		
			
				|  |  | 	 * @param uid 代理人ID(目前版本废弃)
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public int intoTopic(String consult, String currentUid, String uid) {
 | 
	
		
			
				|  |  | 		ConsultTeamDo ct = consultTeamDao.findByConsult(consult);
 | 
	
		
			
				|  |  | 		if (ct.getStatus() != 0) {
 | 
	
		
			
				|  |  | 			return -1;
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String content = "进入了咨询";
 | 
	
		
			
				|  |  | 		BasePatientDO p = basePatientDao.findById(currentUid);
 | 
	
		
			
				|  |  | 		String intoUserName = p.getName();
 | 
	
		
			
				|  |  | //		if (currentUid.equals(uid)) {
 | 
	
		
			
				|  |  | //			content = intoUserName + content;
 | 
	
		
			
				|  |  | //		} else {
 | 
	
		
			
				|  |  | 			BasePatientDO member = basePatientDao.findById(currentUid);
 | 
	
		
			
				|  |  | 			content = intoUserName + content;
 | 
	
		
			
				|  |  | 			//目前没有家人关系,所以家人名称的名字获取暂时注释
 | 
	
		
			
				|  |  | //			content = member.getName() + "(" + relations.get(familyMember.getFamilyRelation()) + ")" + content;
 | 
	
		
			
				|  |  | //		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		imUtil.sendIntoTopicIM(ct.getPatient(), ct.getPatient(), ct.getConsult(), content, currentUid, intoUserName);
 | 
	
		
			
				|  |  | 		return 0;
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 居民咨询发消息(追问接口)
 | 
	
		
			
				|  |  | 	 * @param consult 咨询标识-咨询CODE
 | 
	
		
			
				|  |  | 	 * @param content 消息内容
 | 
	
		
			
				|  |  | 	 * @param type 消息类型
 | 
	
		
			
				|  |  | 	 * @param times 次数
 | 
	
		
			
				|  |  | 	 * @param patientcode 发送的居民CODE
 | 
	
		
			
				|  |  | 	 * @param wechat_appid 微信公众号appid
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public List<String> append(String consult, String content, Integer type, Integer times,String patientcode,String wechat_appid) throws Exception {
 | 
	
		
			
				|  |  | 		List<ConsultTeamLogDo> logs = new ArrayList<ConsultTeamLogDo>();
 | 
	
		
			
				|  |  | 		ConsultTeamDo consultModel = consultTeamDao.findByConsult(consult);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		if (consultModel == null) {
 | 
	
		
			
				|  |  | 			throw new Exception("咨询记录不存在!");
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		if (consultModel.getEndMsgId() != null) {
 | 
	
		
			
				|  |  | 			throw new Exception("咨询已结束!");
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String[] arr = null;
 | 
	
		
			
				|  |  | 		if (type == 3) {
 | 
	
		
			
				|  |  | //			String path = fetchWxVoices(wechat_appid);
 | 
	
		
			
				|  |  | //			JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  | //			// 将临时语音拷贝到正式存储路径下
 | 
	
		
			
				|  |  | //			if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
 | 
	
		
			
				|  |  | //				content = fileUtil.copyTempVoice(path,fastdfs_file_url);
 | 
	
		
			
				|  |  | //				obj.put("path", path);
 | 
	
		
			
				|  |  | //				obj.put("times", times);
 | 
	
		
			
				|  |  | //				content = obj.toString();
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | 			ConsultTeamLogDo log = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 			log.setConsult(consult);
 | 
	
		
			
				|  |  | 			log.setContent(content);
 | 
	
		
			
				|  |  | 			log.setDel("1");
 | 
	
		
			
				|  |  | 			log.setChatType(type);
 | 
	
		
			
				|  |  | 			log.setType(type);
 | 
	
		
			
				|  |  | 			logs.add(log);
 | 
	
		
			
				|  |  | 		} else if (type == 2) {
 | 
	
		
			
				|  |  | //			// 图片消息
 | 
	
		
			
				|  |  | //			content = fetchWxImages(wechat_appid);
 | 
	
		
			
				|  |  | //			// 将临时图片拷贝到正式存储路径下
 | 
	
		
			
				|  |  | //			if (org.apache.commons.lang3.StringUtils.isNotEmpty(content)) {
 | 
	
		
			
				|  |  | //				content = fileUtil.copyTempImage(content,upload_temp_path);
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | //			if (org.apache.commons.lang3.StringUtils.isEmpty(content)) {
 | 
	
		
			
				|  |  | //				throw new Exception("图片上传失败!");
 | 
	
		
			
				|  |  | ////				return error(-1, "图片上传失败!");
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | 			String[] images = content.split(",");
 | 
	
		
			
				|  |  | 			for (String image : images) {
 | 
	
		
			
				|  |  | 				ConsultTeamLogDo log = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 				log.setConsult(consult);
 | 
	
		
			
				|  |  | 				log.setContent(image);
 | 
	
		
			
				|  |  | 				log.setDel("1");
 | 
	
		
			
				|  |  | 				log.setChatType(type);
 | 
	
		
			
				|  |  | 				log.setType(type);
 | 
	
		
			
				|  |  | 				logs.add(log);
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		} else {
 | 
	
		
			
				|  |  | 			ConsultTeamLogDo log = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 			log.setConsult(consult);
 | 
	
		
			
				|  |  | 			log.setContent(content);
 | 
	
		
			
				|  |  | 			log.setDel("1");
 | 
	
		
			
				|  |  | 			log.setChatType(type);
 | 
	
		
			
				|  |  | 			log.setType(type);
 | 
	
		
			
				|  |  | 			logs.add(log);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			arr = new String[]{content};
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | //            Patient patient = patientDao.findByCode(getUID());
 | 
	
		
			
				|  |  | 		BasePatientDO patient = basePatientDao.findById(patientcode);
 | 
	
		
			
				|  |  | 		int i = 0;
 | 
	
		
			
				|  |  | 		List<String> failed = new ArrayList<>();
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		for (ConsultTeamLogDo log : logs) {
 | 
	
		
			
				|  |  | //                String response = ImUtill.sendTopicIM(getUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent());
 | 
	
		
			
				|  |  | 			String response = imUtil.sendTopicIM(patientcode, patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),null);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			if (org.apache.commons.lang3.StringUtils.isNotEmpty(response)) {
 | 
	
		
			
				|  |  | 				JSONObject resObj = JSON.parseObject(response);
 | 
	
		
			
				|  |  | 				if (resObj.getInteger("status")  == -1) {
 | 
	
		
			
				|  |  | 					throw new Exception("追问失败!" + resObj.getString("message"));
 | 
	
		
			
				|  |  | //					return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!" + resObj.getString("message"));
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 				failed.add(String.valueOf(resObj.get("data")));
 | 
	
		
			
				|  |  | //				try {
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //					String sql = "";
 | 
	
		
			
				|  |  | //					if (consultModel.getType() == 2){
 | 
	
		
			
				|  |  | //						//家庭咨询
 | 
	
		
			
				|  |  | //						sql = "SELECT t.participant_id FROM " + data_base_name +
 | 
	
		
			
				|  |  | //								".participants t where t.session_id = '" +
 | 
	
		
			
				|  |  | //								patient.getId() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
 | 
	
		
			
				|  |  | //								"' and t.participant_role = 0";
 | 
	
		
			
				|  |  | //					}else if (consultModel.getType() == 8 || consultModel.getType() == 9 || consultModel.getType() == 11){
 | 
	
		
			
				|  |  | //						//8-续方咨询 9-在线复诊咨询 11-上门预约服务
 | 
	
		
			
				|  |  | //						sql = "SELECT t.participant_id FROM " + data_base_name +
 | 
	
		
			
				|  |  | //								".participants t where t.session_id = '" +
 | 
	
		
			
				|  |  | //								patient.getId() + "_" + consultModel.getConsult() + "_" + consultModel.getType() +
 | 
	
		
			
				|  |  | //								"' and t.participant_role = 0";
 | 
	
		
			
				|  |  | //					}
 | 
	
		
			
				|  |  | 					
 | 
	
		
			
				|  |  | //					if(org.apache.commons.lang3.StringUtils.isEmpty(sql)){
 | 
	
		
			
				|  |  | //						throw new Exception("追问失败!不存在该类型!【type】:" + type);
 | 
	
		
			
				|  |  | //						return write(-1, "追问失败!", "data", "不存在该类型!【type】:" + type);
 | 
	
		
			
				|  |  | //					}
 | 
	
		
			
				|  |  | //					List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //					for (Map<String, Object> participant : participants) {
 | 
	
		
			
				|  |  | //                          //有居民、健管、全科
 | 
	
		
			
				|  |  | //						String doctorCode = participant.get("participant_id").toString();
 | 
	
		
			
				|  |  | //						if (doctorCode.equals(patient.getCode())) {
 | 
	
		
			
				|  |  | //							continue;
 | 
	
		
			
				|  |  | //						}
 | 
	
		
			
				|  |  | 						//健管
 | 
	
		
			
				|  |  | //						Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
 | 
	
		
			
				|  |  | 						//全科
 | 
	
		
			
				|  |  | //                            Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
 | 
	
		
			
				|  |  | //						if (flag) {
 | 
	
		
			
				|  |  | //							//            新增发送医生助手模板消息 v1.4.0 by wujunjie
 | 
	
		
			
				|  |  | //							Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  | //							String doctorOpenID = doctor.getOpenid();
 | 
	
		
			
				|  |  | //							if (org.apache.commons.lang3.StringUtils.isNotEmpty(doctorOpenID)) {
 | 
	
		
			
				|  |  | //								String title = "";
 | 
	
		
			
				|  |  | //								Consult consultSingle = consultDao.findByCode(log.getConsult());
 | 
	
		
			
				|  |  | //								if (consultSingle != null) {
 | 
	
		
			
				|  |  | //									Integer singleType = consultSingle.getType();
 | 
	
		
			
				|  |  | //									if (singleType != null && singleType == 8) {
 | 
	
		
			
				|  |  | //										title = consultSingle.getTitle();
 | 
	
		
			
				|  |  | //									} else if (singleType != null && singleType != 8) {
 | 
	
		
			
				|  |  | //										title = consultSingle.getSymptoms();
 | 
	
		
			
				|  |  | //									}
 | 
	
		
			
				|  |  | //									String repContent = parseContentType(type + "", content);
 | 
	
		
			
				|  |  | //									String first = "居民" + patient.getName() + "的咨询有新的回复。";
 | 
	
		
			
				|  |  | //									String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
 | 
	
		
			
				|  |  | //									List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("type", "8"));
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("openId", doctorOpenID));
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("url", targetUrl));
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("first", first));
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
 | 
	
		
			
				|  |  | //									String keywords = title + "," + repContent + "," + doctor.getName();
 | 
	
		
			
				|  |  | //									params.add(new BasicNameValuePair("keywords", keywords));
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //									httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  | //									System.out.println("发送对象:"+doctorCode);
 | 
	
		
			
				|  |  | //									System.out.println("发送对象名字:"+doctor.getName());
 | 
	
		
			
				|  |  | //								}
 | 
	
		
			
				|  |  | //							}
 | 
	
		
			
				|  |  | //						}
 | 
	
		
			
				|  |  | //					}
 | 
	
		
			
				|  |  | //				} catch (Exception e) {
 | 
	
		
			
				|  |  | //					e.printStackTrace();
 | 
	
		
			
				|  |  | //				}
 | 
	
		
			
				|  |  | 				
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return failed;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取微信服务器语音
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public String fetchWxVoices(String wecha_appid) {
 | 
	
		
			
				|  |  | 		String voiceIds = "";
 | 
	
		
			
				|  |  | 		try {
 | 
	
		
			
				|  |  | 			String voices = request.getParameter("voices");
 | 
	
		
			
				|  |  | 			if (org.apache.commons.lang3.StringUtils.isEmpty(voices)) {
 | 
	
		
			
				|  |  | 				return voices;
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			String[] mediaIds = voices.split(",");
 | 
	
		
			
				|  |  | 			for (String mediaId : mediaIds) {
 | 
	
		
			
				|  |  | 				if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
 | 
	
		
			
				|  |  | 					continue;
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 				String temp = saveVoiceToDisk(mediaId,wecha_appid);
 | 
	
		
			
				|  |  | 				if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
 | 
	
		
			
				|  |  | 					if (voiceIds.length() == 0) {
 | 
	
		
			
				|  |  | 						voiceIds = temp;
 | 
	
		
			
				|  |  | 					} else {
 | 
	
		
			
				|  |  | 						voiceIds += "," + temp;
 | 
	
		
			
				|  |  | 					}
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		} catch (Exception e) {
 | 
	
		
			
				|  |  | 			e.printStackTrace();
 | 
	
		
			
				|  |  | //			error(e);
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return voiceIds;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取下载语音信息(jpg)
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param mediaId 文件的id
 | 
	
		
			
				|  |  | 	 * @throws Exception
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public String saveVoiceToDisk(String mediaId,String wechat_appid) throws Exception {
 | 
	
		
			
				|  |  | 		// 文件保存的临时路径
 | 
	
		
			
				|  |  | 		String tempPath = upload_temp_path + File.separator;
 | 
	
		
			
				|  |  | 		// 拼接年月日路径
 | 
	
		
			
				|  |  | 		String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
 | 
	
		
			
				|  |  | 		// 重命名文件
 | 
	
		
			
				|  |  | 		String fileBase =  DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000);
 | 
	
		
			
				|  |  | 		String newFileName = fileBase+ ".amr";
 | 
	
		
			
				|  |  | 		String mp3FileName  = fileBase + ".mp3";
 | 
	
		
			
				|  |  | 		// 保存路径
 | 
	
		
			
				|  |  | 		File uploadFile = new File(tempPath + datePath + newFileName);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		InputStream inputStream = null;
 | 
	
		
			
				|  |  | 		FileOutputStream fileOutputStream = null;
 | 
	
		
			
				|  |  | 		try {
 | 
	
		
			
				|  |  | 			if (!uploadFile.getParentFile().exists()) {
 | 
	
		
			
				|  |  | 				uploadFile.getParentFile().mkdirs();
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			inputStream = getInputStream(mediaId,wechat_appid);
 | 
	
		
			
				|  |  | 			byte[] data = new byte[1024];
 | 
	
		
			
				|  |  | 			int len = 0;
 | 
	
		
			
				|  |  | 			fileOutputStream = new FileOutputStream(uploadFile);
 | 
	
		
			
				|  |  | 			while ((len = inputStream.read(data)) != -1) {
 | 
	
		
			
				|  |  | 				fileOutputStream.write(data, 0, len);
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			String amrFilePath = tempPath+datePath+newFileName;
 | 
	
		
			
				|  |  | 			String Mp3FilePath = tempPath+datePath+mp3FileName;
 | 
	
		
			
				|  |  | 			fileUtil.changeToMp3(amrFilePath,Mp3FilePath);
 | 
	
		
			
				|  |  | 			// 返回保存路径
 | 
	
		
			
				|  |  | 			return Mp3FilePath;
 | 
	
		
			
				|  |  | 		} catch (IOException e) {
 | 
	
		
			
				|  |  | 			e.printStackTrace();
 | 
	
		
			
				|  |  | 		} finally {
 | 
	
		
			
				|  |  | 			if (inputStream != null) {
 | 
	
		
			
				|  |  | 				try {
 | 
	
		
			
				|  |  | 					inputStream.close();
 | 
	
		
			
				|  |  | 				} catch (IOException e) {
 | 
	
		
			
				|  |  | 					e.printStackTrace();
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			if (fileOutputStream != null) {
 | 
	
		
			
				|  |  | 				try {
 | 
	
		
			
				|  |  | 					fileOutputStream.close();
 | 
	
		
			
				|  |  | 				} catch (IOException e) {
 | 
	
		
			
				|  |  | 					e.printStackTrace();
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return null;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public InputStream getInputStream(String mediaId,String wechat_appid) {
 | 
	
		
			
				|  |  | 		String accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
 | 
	
		
			
				|  |  | 		InputStream is = null;
 | 
	
		
			
				|  |  | 		String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
 | 
	
		
			
				|  |  | 		try {
 | 
	
		
			
				|  |  | 			URL urlGet = new URL(url);
 | 
	
		
			
				|  |  | 			HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
 | 
	
		
			
				|  |  | 			http.setRequestMethod("GET"); // 必须是get方式请求
 | 
	
		
			
				|  |  | 			http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 | 
	
		
			
				|  |  | 			http.setDoOutput(true);
 | 
	
		
			
				|  |  | 			http.setDoInput(true);
 | 
	
		
			
				|  |  | 			System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
 | 
	
		
			
				|  |  | 			System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
 | 
	
		
			
				|  |  | 			http.connect();
 | 
	
		
			
				|  |  | 			// 获取文件转化为byte流
 | 
	
		
			
				|  |  | 			is = http.getInputStream();
 | 
	
		
			
				|  |  | 		} catch (Exception e) {
 | 
	
		
			
				|  |  | 			e.printStackTrace();
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return is;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取微信服务器图片
 | 
	
		
			
				|  |  | 	 * @param wechat_appid 微信公众号appid
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public String fetchWxImages(String wechat_appid) {
 | 
	
		
			
				|  |  | 		String photos = "";
 | 
	
		
			
				|  |  | 		try {
 | 
	
		
			
				|  |  | 			String images = request.getParameter("mediaIds");
 | 
	
		
			
				|  |  | 			if (org.apache.commons.lang3.StringUtils.isEmpty(images)) {
 | 
	
		
			
				|  |  | 				return photos;
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			String[] mediaIds = images.split(",");
 | 
	
		
			
				|  |  | 			for (String mediaId : mediaIds) {
 | 
	
		
			
				|  |  | 				if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
 | 
	
		
			
				|  |  | 					continue;
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 				String temp = saveImageToDisk(mediaId,wechat_appid);
 | 
	
		
			
				|  |  | 				if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
 | 
	
		
			
				|  |  | 					if (photos.length() == 0) {
 | 
	
		
			
				|  |  | 						photos = temp;
 | 
	
		
			
				|  |  | 					} else {
 | 
	
		
			
				|  |  | 						photos += "," + temp;
 | 
	
		
			
				|  |  | 					}
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		} catch (Exception e) {
 | 
	
		
			
				|  |  | 			e.printStackTrace();
 | 
	
		
			
				|  |  | //			error(e);
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return photos;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取下载图片信息(jpg)
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param mediaId 文件的id
 | 
	
		
			
				|  |  | 	 * @param wechat_appid 微信appid
 | 
	
		
			
				|  |  | 	 * @throws Exception
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public String saveImageToDisk(String mediaId,String wechat_appid) throws Exception {
 | 
	
		
			
				|  |  | 		// 文件保存的临时路径
 | 
	
		
			
				|  |  | 		String tempPath = upload_temp_path + File.separator;
 | 
	
		
			
				|  |  | 		// 拼接年月日路径
 | 
	
		
			
				|  |  | 		String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
 | 
	
		
			
				|  |  | 		// 重命名文件
 | 
	
		
			
				|  |  | 		String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
 | 
	
		
			
				|  |  | 		// 保存路径
 | 
	
		
			
				|  |  | 		File uploadFile = new File(tempPath + datePath + newFileName);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		InputStream inputStream = null;
 | 
	
		
			
				|  |  | 		FileOutputStream fileOutputStream = null;
 | 
	
		
			
				|  |  | 		try {
 | 
	
		
			
				|  |  | 			if (!uploadFile.getParentFile().exists()) {
 | 
	
		
			
				|  |  | 				uploadFile.getParentFile().mkdirs();
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			inputStream = getInputStream(mediaId,wechat_appid);
 | 
	
		
			
				|  |  | 			byte[] data = new byte[1024];
 | 
	
		
			
				|  |  | 			int len = 0;
 | 
	
		
			
				|  |  | 			fileOutputStream = new FileOutputStream(uploadFile);
 | 
	
		
			
				|  |  | 			while ((len = inputStream.read(data)) != -1) {
 | 
	
		
			
				|  |  | 				fileOutputStream.write(data, 0, len);
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			// 生成缩略图
 | 
	
		
			
				|  |  | 			ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
 | 
	
		
			
				|  |  | 			// 返回保存路径
 | 
	
		
			
				|  |  | 			return datePath + newFileName;
 | 
	
		
			
				|  |  | 		} catch (IOException e) {
 | 
	
		
			
				|  |  | 			e.printStackTrace();
 | 
	
		
			
				|  |  | 		} finally {
 | 
	
		
			
				|  |  | 			if (inputStream != null) {
 | 
	
		
			
				|  |  | 				try {
 | 
	
		
			
				|  |  | 					inputStream.close();
 | 
	
		
			
				|  |  | 				} catch (IOException e) {
 | 
	
		
			
				|  |  | 					e.printStackTrace();
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			if (fileOutputStream != null) {
 | 
	
		
			
				|  |  | 				try {
 | 
	
		
			
				|  |  | 					fileOutputStream.close();
 | 
	
		
			
				|  |  | 				} catch (IOException e) {
 | 
	
		
			
				|  |  | 					e.printStackTrace();
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		return null;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 患者端
 | 
	
		
			
				|  |  | 	 * 发起专家咨询
 | 
	
		
			
				|  |  | 	 * @param ct      专家咨询对象
 | 
	
		
			
				|  |  | 	 * @param patient 患者标识
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 * @throws Exception
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONObject addTeamConsult(ConsultTeamDo ct, String patient, String doctor) throws Exception {
 | 
	
		
			
				|  |  | 		JSONObject re = new JSONObject();
 | 
	
		
			
				|  |  | 		if (!StringUtils.isEmpty(getUnfinishedConsult(patient, doctor))) {//判断是否有未结束的咨询移到同步方法中
 | 
	
		
			
				|  |  | //			re.put("status", -3);
 | 
	
		
			
				|  |  | //			return re;
 | 
	
		
			
				|  |  | 			throw new RuntimeException("居民还有未结束的专家咨询!");
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		JSONObject users = new JSONObject();
 | 
	
		
			
				|  |  | 		users.put(doctor,0);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		// 设置患者信息
 | 
	
		
			
				|  |  | 		ct.setPatient(patient);
 | 
	
		
			
				|  |  | 		// 查询患者信息
 | 
	
		
			
				|  |  | 		BasePatientDO tempPatient = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  | 		// 设置患者姓名
 | 
	
		
			
				|  |  | 		ct.setName(tempPatient.getName());
 | 
	
		
			
				|  |  | 		// 设置患者生日
 | 
	
		
			
				|  |  | 		ct.setBirthday(tempPatient.getBirthday());
 | 
	
		
			
				|  |  | 		//新增性别
 | 
	
		
			
				|  |  | 		ct.setSex(tempPatient.getSex());
 | 
	
		
			
				|  |  | 		// 设置患者头像
 | 
	
		
			
				|  |  | 		ct.setPhoto(tempPatient.getPhoto());
 | 
	
		
			
				|  |  | 		// 设置操作日期
 | 
	
		
			
				|  |  | 		ct.setCzrq(new Date());
 | 
	
		
			
				|  |  | 		ct.setDel("1");
 | 
	
		
			
				|  |  | 		ct.setStatus(0);
 | 
	
		
			
				|  |  | 		ct.setEvaluate(0);
 | 
	
		
			
				|  |  | 		// 医生未读数量为1
 | 
	
		
			
				|  |  | 		ct.setDoctorRead(1);
 | 
	
		
			
				|  |  | 		// 添加咨询记录
 | 
	
		
			
				|  |  | 		ConsultDo consult = addConsult(ct.getPatient(), "专家咨询", ct.getSymptoms(), ct.getImages(), ct.getType());
 | 
	
		
			
				|  |  | //		// 设置关联指导
 | 
	
		
			
				|  |  | //		consult.setGuidance(ct.getGuidance());
 | 
	
		
			
				|  |  | 		// 设置咨询标识
 | 
	
		
			
				|  |  | 		ct.setConsult(consult.getId());
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		//推送给IM去创建议题,取得成员消息
 | 
	
		
			
				|  |  | 		JSONObject messages = imUtil.getCreateTopicMessage(patient, tempPatient.getName(), consult.getTitle(), consult.getSymptoms(), consult.getImages(), doctor);
 | 
	
		
			
				|  |  | 		users.put(patient, 0);//+ " "+(tempPatient.getSex()==1?"(男 ":"(女 ") + IdCardUtil.getAgeForIdcard(tempPatient.getIdcard())+")"
 | 
	
		
			
				|  |  | 		JSONObject obj = imUtil.createTopics(patient + "_" + doctor + "_" + ct.getType(), consult.getId(), tempPatient.getName(), users, messages, imUtil.SESSION_TYPE_MUC);
 | 
	
		
			
				|  |  | 		if (obj == null) {
 | 
	
		
			
				|  |  | 			throw new RuntimeException("IM消息发送异常!");
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		if (obj.getInteger("status") == -1) {//im议题创建失败
 | 
	
		
			
				|  |  | 			throw new RuntimeException(obj.getString("message"));
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		ct.setStartMsgId(obj.get("start_msg_id").toString());
 | 
	
		
			
				|  |  | 		consultTeamDao.save(ct);
 | 
	
		
			
				|  |  | 		consultDao.save(consult);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		JSONArray doctors = new JSONArray();
 | 
	
		
			
				|  |  | 		for (String key : users.keySet()) {
 | 
	
		
			
				|  |  | 			if (patient.equals(key)) {
 | 
	
		
			
				|  |  | 				continue;
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			doctors.add(key);
 | 
	
		
			
				|  |  | 			//记录咨询的医生详情误删
 | 
	
		
			
				|  |  | 			ConsultTeamDoctorDo cd = new ConsultTeamDoctorDo();
 | 
	
		
			
				|  |  | 			cd.setConsult(consult.getId());
 | 
	
		
			
				|  |  | 			cd.setDel("1");
 | 
	
		
			
				|  |  | 			cd.setCzrq(new Date());
 | 
	
		
			
				|  |  | 			cd.setTo(key);
 | 
	
		
			
				|  |  | 			consultTeamDoctorDao.save(cd);
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		// 保存医生咨询信息
 | 
	
		
			
				|  |  | 		// 添加咨询转发记录
 | 
	
		
			
				|  |  | 		// 添加医生咨询日志
 | 
	
		
			
				|  |  | 		String content = addLogs(ct);
 | 
	
		
			
				|  |  | 		re.put("doctor", doctor);
 | 
	
		
			
				|  |  | 		re.put("status", 1);
 | 
	
		
			
				|  |  | 		return re;
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 添加一条咨询记录
 | 
	
		
			
				|  |  | 	 * @param patient 患者信息
 | 
	
		
			
				|  |  | 	 * @param title 咨询标题
 | 
	
		
			
				|  |  | 	 * @param type 咨询类型:9在线复诊,13专家咨询
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public ConsultDo addConsult(String patient, String title, String symptoms, String images, int type) {
 | 
	
		
			
				|  |  | 		ConsultDo consult = new ConsultDo();
 | 
	
		
			
				|  |  | 		consult.setId(UUID.randomUUID().toString().replaceAll("-", ""));
 | 
	
		
			
				|  |  | 		consult.setCzrq(new Date());
 | 
	
		
			
				|  |  | 		consult.setDel("1");
 | 
	
		
			
				|  |  | 		consult.setPatient(patient);
 | 
	
		
			
				|  |  | 		consult.setTitle(title);
 | 
	
		
			
				|  |  | 		consult.setSymptoms(symptoms);
 | 
	
		
			
				|  |  | 		consult.setImages(images);
 | 
	
		
			
				|  |  | 		consult.setType(type);
 | 
	
		
			
				|  |  | 		return consultDao.save(consult);
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 添加咨询日志
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param ct
 | 
	
		
			
				|  |  | 	 * @throws Exception
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	private String addLogs(ConsultTeamDo ct) throws Exception {
 | 
	
		
			
				|  |  | 		List<ConsultTeamLogDo> logs = new ArrayList<ConsultTeamLogDo>();
 | 
	
		
			
				|  |  | 		// 添加问题咨询日志
 | 
	
		
			
				|  |  | 		String content = "";
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		content += "咨询问题:" + (org.apache.commons.lang3.StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		// 生成提问日志,并推送相关消息
 | 
	
		
			
				|  |  | 		ConsultTeamLogDo infoLog = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 		infoLog.setConsult(ct.getConsult());
 | 
	
		
			
				|  |  | 		if (content.length() > 2500) {
 | 
	
		
			
				|  |  | 			content = content.substring(0, 2500);
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		infoLog.setContent(content);
 | 
	
		
			
				|  |  | 		infoLog.setDel("1");
 | 
	
		
			
				|  |  | 		infoLog.setType(0);
 | 
	
		
			
				|  |  | 		infoLog.setChatType(1);
 | 
	
		
			
				|  |  | 		infoLog.setCzrq(new Date());
 | 
	
		
			
				|  |  | 		logs.add(infoLog);
 | 
	
		
			
				|  |  | 		// 图片日志
 | 
	
		
			
				|  |  | 		if (org.apache.commons.lang3.StringUtils.isNotEmpty(ct.getImages())) {
 | 
	
		
			
				|  |  | 			String[] images = ct.getImages().split(",");
 | 
	
		
			
				|  |  | 			for (String image : images) {
 | 
	
		
			
				|  |  | 				if (org.apache.commons.lang3.StringUtils.isNoneEmpty(image)) {
 | 
	
		
			
				|  |  | 					ConsultTeamLogDo imgLog = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 					// 设置咨询标识
 | 
	
		
			
				|  |  | 					imgLog.setConsult(ct.getConsult());
 | 
	
		
			
				|  |  | 					// 设置图片URL
 | 
	
		
			
				|  |  | 					imgLog.setContent(image);
 | 
	
		
			
				|  |  | 					imgLog.setDel("1");
 | 
	
		
			
				|  |  | 					infoLog.setType(0);
 | 
	
		
			
				|  |  | 					imgLog.setCzrq(new Date());
 | 
	
		
			
				|  |  | 					// 图片类型
 | 
	
		
			
				|  |  | 					imgLog.setChatType(2);
 | 
	
		
			
				|  |  | 					// 添加到待保存队列
 | 
	
		
			
				|  |  | 					logs.add(imgLog);
 | 
	
		
			
				|  |  | 				}
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		// 语音日志
 | 
	
		
			
				|  |  | 		if (org.apache.commons.lang3.StringUtils.isNotEmpty(ct.getVoice())) {
 | 
	
		
			
				|  |  | 			ConsultTeamLogDo voiceLog = new ConsultTeamLogDo();
 | 
	
		
			
				|  |  | 			// 设置咨询标识
 | 
	
		
			
				|  |  | 			voiceLog.setConsult(ct.getConsult());
 | 
	
		
			
				|  |  | 			// 设置语音URL
 | 
	
		
			
				|  |  | 			voiceLog.setContent(ct.getVoice());
 | 
	
		
			
				|  |  | 			voiceLog.setDel("1");
 | 
	
		
			
				|  |  | 			infoLog.setType(0);
 | 
	
		
			
				|  |  | 			// 语音类型
 | 
	
		
			
				|  |  | 			voiceLog.setChatType(3);
 | 
	
		
			
				|  |  | 			voiceLog.setCzrq(new Date());
 | 
	
		
			
				|  |  | 			// 添加到待保存队列
 | 
	
		
			
				|  |  | 			logs.add(voiceLog);
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		if (!logs.isEmpty()) {
 | 
	
		
			
				|  |  | 			Iterable<ConsultTeamLogDo> iterable = consultTeamLogDao.save(logs);
 | 
	
		
			
				|  |  | 			if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
 | 
	
		
			
				|  |  | 				// 日志保存失败
 | 
	
		
			
				|  |  | 				throw new Exception("consult team log save failed!");
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		// 患者提问或追问,给医生发消息
 | 
	
		
			
				|  |  | 		// sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0);
 | 
	
		
			
				|  |  | 		return content;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 添加续方咨询
 | 
	
		
			
				|  |  | 	 *
 | 
	
		
			
				|  |  | 	 * @param outpatientCode
 | 
	
		
			
				|  |  | 	 * @param patient
 | 
	
		
			
				|  |  | 	 * @param agent
 | 
	
		
			
				|  |  | 	 * @param doctorCode
 | 
	
		
			
				|  |  | 	 * @param reason
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONObject addPrescriptionConsult(String outpatientCode, String patient,String doctorCode, ConsultTeamDo ct, String reason, Integer type) throws Exception {
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		synchronized (outpatientCode.intern()) {
 | 
	
		
			
				|  |  | 			/**
 | 
	
		
			
				|  |  | 			 * toto 判断是否存在未审核的复诊
 | 
	
		
			
				|  |  | 			 */
 | 
	
		
			
				|  |  | //			String check = prescriptionInfoService.presCheckState(jwCode);
 | 
	
		
			
				|  |  | //			if ("0".equals(check)) {//存在未审核的续方
 | 
	
		
			
				|  |  | //				return -1;
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
 | 
	
		
			
				|  |  | //			doctorCode = doctor.getCode();
 | 
	
		
			
				|  |  | 			// 查询患者信息
 | 
	
		
			
				|  |  | 			BasePatientDO p = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//1、获取his就诊记录详情(保存续方表、药品续方信息表、续方疾病类型表)
 | 
	
		
			
				|  |  | 			WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findOne(outpatientCode);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  | 			jsonObject.put("title", p.getName() + "申请复诊");
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			String content = jsonObject.toString();
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//4、创建咨询
 | 
	
		
			
				|  |  | 			JSONObject users = new JSONObject();//咨询参与者
 | 
	
		
			
				|  |  | 			users.put(patient, 0);
 | 
	
		
			
				|  |  | 			users.put(doctorCode, 0);
 | 
	
		
			
				|  |  | 			//关联业务code
 | 
	
		
			
				|  |  | 			ct.setRelationCode(outpatientCode);
 | 
	
		
			
				|  |  | 			//医生信息
 | 
	
		
			
				|  |  | 			ct.setDoctor(doctorCode);
 | 
	
		
			
				|  |  | 			ct.setDoctorName(doctor.getName());
 | 
	
		
			
				|  |  | 			// 设置患者信息
 | 
	
		
			
				|  |  | 			ct.setPatient(patient);
 | 
	
		
			
				|  |  | //			if (1 == type) {
 | 
	
		
			
				|  |  | //				ct.setSymptoms("高血压");
 | 
	
		
			
				|  |  | //			} else if (2 == type) {
 | 
	
		
			
				|  |  | //				ct.setSymptoms("糖尿病");
 | 
	
		
			
				|  |  | //			} else if (3 == type) {
 | 
	
		
			
				|  |  | //				ct.setSymptoms("高血压,糖尿病");
 | 
	
		
			
				|  |  | //			} else {
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			// 设置患者姓名
 | 
	
		
			
				|  |  | 			ct.setName(p.getName());
 | 
	
		
			
				|  |  | 			// 设置患者生日
 | 
	
		
			
				|  |  | 			ct.setBirthday(p.getBirthday());
 | 
	
		
			
				|  |  | 			//新增性别
 | 
	
		
			
				|  |  | 			ct.setSex(p.getSex());
 | 
	
		
			
				|  |  | 			// 设置患者头像
 | 
	
		
			
				|  |  | 			ct.setPhoto(p.getPhoto());
 | 
	
		
			
				|  |  | 			// 设置操作日期
 | 
	
		
			
				|  |  | 			ct.setCzrq(new Date());
 | 
	
		
			
				|  |  | 			ct.setDel("1");
 | 
	
		
			
				|  |  | 			ct.setStatus(0);
 | 
	
		
			
				|  |  | 			ct.setEvaluate(0);
 | 
	
		
			
				|  |  | 			// 医生未读数量为1
 | 
	
		
			
				|  |  | 			ct.setDoctorRead(1);
 | 
	
		
			
				|  |  | 			// 添加咨询记录
 | 
	
		
			
				|  |  | 			ConsultDo consult = addConsult(ct.getPatient(), "申请复诊", ct.getSymptoms(), ct.getImages(), ct.getType());
 | 
	
		
			
				|  |  | 			// 设置关联指导
 | 
	
		
			
				|  |  | 			consult.setGuidance(ct.getGuidance());
 | 
	
		
			
				|  |  | 			//关联业务code
 | 
	
		
			
				|  |  | 			consult.setRelationCode(outpatientCode);
 | 
	
		
			
				|  |  | 			// 设置咨询标识
 | 
	
		
			
				|  |  | 			ct.setConsult(consult.getId());
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//推送给IM去创建议题,取得成员消息
 | 
	
		
			
				|  |  | 			JSONObject messages = imUtil.getCreateTopicMessage(doctorCode, doctor.getName(), consult.getTitle(), content, consult.getImages(), patient);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+咨询类型(图文,视频,图文+视频)
 | 
	
		
			
				|  |  | 			String sessionId = patient + "_" + outpatientCode + "_" + ct.getType();
 | 
	
		
			
				|  |  | 			JSONObject obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION);
 | 
	
		
			
				|  |  | 			if (obj == null) {
 | 
	
		
			
				|  |  | 				throw new RuntimeException("IM消息发送异常!");
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			if (obj.getInteger("status") == -1) {//im议题创建失败
 | 
	
		
			
				|  |  | 				throw new RuntimeException(obj.getString("message"));
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			ct.setStartMsgId(obj.get("start_msg_id").toString());
 | 
	
		
			
				|  |  | 			consultTeamDao.save(ct);
 | 
	
		
			
				|  |  | 			consultDao.save(consult);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//设置咨询code
 | 
	
		
			
				|  |  | //			wlyyOutpatientDO.setConsult(consult.getCode());
 | 
	
		
			
				|  |  | //			prescriptionDao.save(prescription);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//6、记录咨询的医生详情
 | 
	
		
			
				|  |  | 			ConsultTeamDoctorDo cd = new ConsultTeamDoctorDo();
 | 
	
		
			
				|  |  | 			cd.setConsult(consult.getId());
 | 
	
		
			
				|  |  | 			cd.setDel("1");
 | 
	
		
			
				|  |  | 			cd.setCzrq(new Date());
 | 
	
		
			
				|  |  | 			cd.setTo(doctorCode);
 | 
	
		
			
				|  |  | 			consultTeamDoctorDao.save(cd);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//7、发送系统消息提示团队长有未审核的消息
 | 
	
		
			
				|  |  | //			addCheckMessage(prescription, sessionId, p);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			//8、 保存医生咨询信息
 | 
	
		
			
				|  |  | 			// 添加咨询转发记录
 | 
	
		
			
				|  |  | 			// 添加医生咨询日志
 | 
	
		
			
				|  |  | 			addLogs(ct);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			JSONObject result = imUtil.getSingleSessionInfo(sessionId,doctorCode);
 | 
	
		
			
				|  |  | 			
 | 
	
		
			
				|  |  | 			return result;
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 居民结束咨询
 | 
	
		
			
				|  |  | 	 * @param consult 咨询CODE
 | 
	
		
			
				|  |  | 	 * @param endOperator 操作人
 | 
	
		
			
				|  |  | 	 * @param endType 1居民 2医生
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public int finish(String consult, String endOperator, int endType) {
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		ConsultTeamDo consultTeam = consultTeamDao.findByConsult(consult);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		ConsultDo cons = consultDao.findOne(consult);
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		if (consultTeam.getStatus() == 1) {
 | 
	
		
			
				|  |  | 			return -1;
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String endName = "";
 | 
	
		
			
				|  |  | 		String endId = "";
 | 
	
		
			
				|  |  | 		JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  | 		//结束咨询才发送推送给IM文字消息
 | 
	
		
			
				|  |  | 		if (endType == 1) {
 | 
	
		
			
				|  |  | 			BasePatientDO p = basePatientDao.findById(endOperator);
 | 
	
		
			
				|  |  | 			endName = p.getName();
 | 
	
		
			
				|  |  | 			endId = p.getId();
 | 
	
		
			
				|  |  | 			obj = imUtil.endTopics(consultTeam.getPatient(), endId, endName, consultTeam.getConsult());
 | 
	
		
			
				|  |  | 		} else {
 | 
	
		
			
				|  |  | 			BaseDoctorDO d = baseDoctorDao.findById(endOperator);
 | 
	
		
			
				|  |  | 			if (endOperator.equals("admin")) {
 | 
	
		
			
				|  |  | 				endId = "system";
 | 
	
		
			
				|  |  | 				endName = "咨询超时未回复,系统自动";
 | 
	
		
			
				|  |  | 			} else {
 | 
	
		
			
				|  |  | 				endId = d.getId();
 | 
	
		
			
				|  |  | 				endName = d.getName();
 | 
	
		
			
				|  |  | 			}
 | 
	
		
			
				|  |  | 			obj = imUtil.endTopics(consultTeam.getDoctor(), endId, d.getName(), consultTeam.getConsult());
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		if (obj == null) {
 | 
	
		
			
				|  |  | 			throw new RuntimeException("IM消息结束异常!");
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 		if (obj.getInteger("status") == -1) {
 | 
	
		
			
				|  |  | 			throw new RuntimeException(String.valueOf(obj.get("message")));
 | 
	
		
			
				|  |  | 		}
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		String name = "";
 | 
	
		
			
				|  |  | 		String returnJson = "";
 | 
	
		
			
				|  |  | 		//推送给IM文字消息
 | 
	
		
			
				|  |  | //		if (endType == 1) {
 | 
	
		
			
				|  |  | //			BasePatientDO p = basePatientDao.findById(endOperator);
 | 
	
		
			
				|  |  | //			name = p.getName();
 | 
	
		
			
				|  |  | //			returnJson = imUtil.sendIM(consultTeam.getPatient(), consultTeam.getDoctor(), "7", name + "结束了本次咨询");
 | 
	
		
			
				|  |  | //		} else {
 | 
	
		
			
				|  |  | //			BaseDoctorDO d = baseDoctorDao.findById(endOperator);
 | 
	
		
			
				|  |  | //			name = d.getName();
 | 
	
		
			
				|  |  | //			returnJson = imUtil.sendIM(consultTeam.getDoctor(), consultTeam.getPatient(), "7", name + "结束了本次咨询");
 | 
	
		
			
				|  |  | //		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | //		if (org.apache.commons.lang3.StringUtils.isEmpty(returnJson)) {
 | 
	
		
			
				|  |  | //			throw new RuntimeException("send consult finished IM message failed!");
 | 
	
		
			
				|  |  | ////			throw new Exception("send consult finished IM message failed");
 | 
	
		
			
				|  |  | //		} else {
 | 
	
		
			
				|  |  | //			JSONObject jo = JSON.parseObject(returnJson);            //设置消息ID
 | 
	
		
			
				|  |  | //			consultTeam.setEndMsgId(jo.getInteger("startId") + "");
 | 
	
		
			
				|  |  | //			consultTeam.setEndOperator(endOperator);
 | 
	
		
			
				|  |  | //			consultTeam.setEndType(endType);
 | 
	
		
			
				|  |  | //		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | //		org.json.JSONObject group = talkGroupService.findConsultTalkGroup(consultTeam.getConsult());
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //		if (group != null) {
 | 
	
		
			
				|  |  | //			String json = sendGroupIM(endOperator, group.getString("code"), "7", name + "结束了本次咨询");
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //			if (org.apache.commons.lang3.StringUtils.isEmpty(json)) {
 | 
	
		
			
				|  |  | //				throw new Exception("send consult finished IM message failed");
 | 
	
		
			
				|  |  | //			}
 | 
	
		
			
				|  |  | //		}
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		consultTeam.setEndMsgId(obj.getString("id"));
 | 
	
		
			
				|  |  | 		cons.setEndTime(new Date());
 | 
	
		
			
				|  |  | 		consultTeam.setEndTime(new Date());
 | 
	
		
			
				|  |  | 		consultTeam.setStatus(1);
 | 
	
		
			
				|  |  | 		consultDao.save(cons);
 | 
	
		
			
				|  |  | 		consultTeamDao.save(consultTeam);
 | 
	
		
			
				|  |  | 		return 1;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 根据咨询CODE获取session_id
 | 
	
		
			
				|  |  | 	 * @param consult
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONObject getTopic(String consult) throws Exception {
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		return imUtil.getTopic(consult);
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	
 | 
	
		
			
				|  |  | 	/**
 | 
	
		
			
				|  |  | 	 * 获取咨询问题,图片,居民信息
 | 
	
		
			
				|  |  | 	 * @param consult
 | 
	
		
			
				|  |  | 	 * @param patientCode
 | 
	
		
			
				|  |  | 	 * @return
 | 
	
		
			
				|  |  | 	 */
 | 
	
		
			
				|  |  | 	public JSONObject getConsultInfoAndPatientInfo(String consult,String patientCode) {
 | 
	
		
			
				|  |  | 		BasePatientDO basePatientDO = basePatientDao.findById(patientCode);
 | 
	
		
			
				|  |  | 		ConsultDo consultDo = consultDao.findOne(consult);
 | 
	
		
			
				|  |  | 		JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  | 		
 | 
	
		
			
				|  |  | 		JSONObject patientinfoObj = new JSONObject();
 | 
	
		
			
				|  |  | 		patientinfoObj.put("name",basePatientDO.getName());
 | 
	
		
			
				|  |  | 		patientinfoObj.put("sex",basePatientDO.getSex());
 | 
	
		
			
				|  |  | 		patientinfoObj.put("mobile",basePatientDO.getMobile());
 | 
	
		
			
				|  |  | 		patientinfoObj.put("address",basePatientDO.getAddress());
 | 
	
		
			
				|  |  | 		Integer age = DateUtil.getAgeForIdcard(basePatientDO.getIdcard());
 | 
	
		
			
				|  |  | 		patientinfoObj.put("age",age);
 | 
	
		
			
				|  |  | 		result.put("patientInfo",patientinfoObj);
 | 
	
		
			
				|  |  | 		result.put("consultDo",consultDo);
 | 
	
		
			
				|  |  | 		return result;
 | 
	
		
			
				|  |  | 	}
 | 
	
		
			
				|  |  | }
 |