|  | @ -3,7 +3,9 @@ package com.yihu.jw.care.service.consult;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONArray;
 |  | import com.alibaba.fastjson.JSONArray;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONObject;
 |  | import com.alibaba.fastjson.JSONObject;
 | 
												
													
														
															|  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.im.ConsultDo;
 |  | import com.yihu.jw.entity.base.im.ConsultDo;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 |  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.im.ConsultTeamDoctorDo;
 |  | import com.yihu.jw.entity.base.im.ConsultTeamDoctorDo;
 | 
												
											
												
													
														
															|  | @ -18,6 +20,7 @@ import com.yihu.jw.im.service.ImService;
 | 
												
													
														
															|  | import com.yihu.jw.im.util.ImUtil;
 |  | import com.yihu.jw.im.util.ImUtil;
 | 
												
													
														
															|  | import com.yihu.jw.patient.dao.BasePatientDao;
 |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
												
													
														
															|  | import com.yihu.jw.sms.dao.HospitalSysDictDao;
 |  | import com.yihu.jw.sms.dao.HospitalSysDictDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
												
													
														
															|  | import com.yihu.jw.util.date.DateUtil;
 |  | import com.yihu.jw.util.date.DateUtil;
 | 
												
													
														
															|  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
											
												
													
														
															|  | @ -63,6 +66,8 @@ public class ConsultService {
 | 
												
													
														
															|  |     private SystemMessageDao systemMessageDao;
 |  |     private SystemMessageDao systemMessageDao;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private HibenateUtils hibenateUtils;
 |  |     private HibenateUtils hibenateUtils;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private BaseDoctorHospitalDao doctorHospitalDao;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 居民结束咨询
 |  |      * 居民结束咨询
 | 
												
											
												
													
														
															|  | @ -177,6 +182,97 @@ public class ConsultService {
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 查询医生所有的咨询记录
 | 
												
													
														
															|  | 
 |  |      * @param doctor 医生标识
 | 
												
													
														
															|  | 
 |  |      * @param id 会话ID(等同IM表topicId)
 | 
												
													
														
															|  | 
 |  |      * @param type 咨询会话类型 : 0 全部
 | 
												
													
														
															|  | 
 |  |      * @param status 咨询状态:0全部,1候诊中,2就诊中,3结束
 | 
												
													
														
															|  | 
 |  |      * @param pagesize 分页大小
 | 
												
													
														
															|  | 
 |  |      * @param title 标题关键字
 | 
												
													
														
															|  | 
 |  |      * @param start_time 开始时间
 | 
												
													
														
															|  | 
 |  |      * @param end_time 结束时间
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public List<Map<String,Object>>  findConsultRecordByDoctor(String doctor, String id,
 | 
												
													
														
															|  | 
 |  |                                                                String type, Integer status,
 | 
												
													
														
															|  | 
 |  |                                                                int page,int pagesize,
 | 
												
													
														
															|  | 
 |  |                                                                String title,String start_time,String end_time) {
 | 
												
													
														
															|  | 
 |  |         String sql = "SELECT " +
 | 
												
													
														
															|  | 
 |  |                     "a.id AS \"id\"," +
 | 
												
													
														
															|  | 
 |  |                     "a.type AS \"type\"," +
 | 
												
													
														
															|  | 
 |  |                     "a.title AS \"title\"," +
 | 
												
													
														
															|  | 
 |  |                     "a.symptoms AS \"symptoms\","+
 | 
												
													
														
															|  | 
 |  |                     "date_format(a.czrq,'%Y-%m-%d %H:%i:%S' )  AS \"czrq\","+
 | 
												
													
														
															|  | 
 |  |                 	"b.status AS \"status\"," +
 | 
												
													
														
															|  | 
 |  |                     "b.evaluate AS \"evaluate\"," +
 | 
												
													
														
															|  | 
 |  |                     "d.name AS \"patientName\"," +
 | 
												
													
														
															|  | 
 |  |                     "d.id as \"patientId\"," +
 | 
												
													
														
															|  | 
 |  |                     "d.idcard as \"patientIdcard\"," +
 | 
												
													
														
															|  | 
 |  |                     "d.sex as \"patientSex\"," +
 | 
												
													
														
															|  | 
 |  |                     "d.photo AS \"patientPhoto\", " +
 | 
												
													
														
															|  | 
 |  |                     "b.doctor as \"doctor\" ,"+
 | 
												
													
														
															|  | 
 |  |                     "a.source as \"source\"  "+
 | 
												
													
														
															|  | 
 |  |                     "FROM wlyy_consult a," +
 | 
												
													
														
															|  | 
 |  |                     "wlyy_consult_team b," +
 | 
												
													
														
															|  | 
 |  |                     "base_patient d " +
 | 
												
													
														
															|  | 
 |  |                     "WHERE a.id=b.consult " +
 | 
												
													
														
															|  | 
 |  |                     "AND b.patient=d.id ";
 | 
												
													
														
															|  | 
 |  |             if (org.apache.commons.lang.StringUtils.isNotBlank(doctor)) {
 | 
												
													
														
															|  | 
 |  |                 sql += " AND b.doctor='" + doctor + "' ";
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             if (!StringUtils.isEmpty(title)) {
 | 
												
													
														
															|  | 
 |  |                 title = "%" + title + "%";
 | 
												
													
														
															|  | 
 |  |                 sql += " and a.symptoms like '" + title + "'";
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             if (!StringUtils.isEmpty(start_time)) {
 | 
												
													
														
															|  | 
 |  |                 sql += " and a.czrq >= '" + start_time + "'";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             if (!StringUtils.isEmpty(end_time)) {
 | 
												
													
														
															|  | 
 |  |                 sql += " and a.czrq <= '" + end_time + "'";
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             //咨询状态
 | 
												
													
														
															|  | 
 |  |             if (status != null) {
 | 
												
													
														
															|  | 
 |  |                 sql += " and b.status = "+status;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             //咨询类型
 | 
												
													
														
															|  | 
 |  |             if (!StringUtils.isEmpty(type)) {
 | 
												
													
														
															|  | 
 |  |                 sql += " AND a.type in (" + type + ")";
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             if (!StringUtils.isEmpty(id)) {
 | 
												
													
														
															|  | 
 |  |                 sql += " and a.id = '" + id + "'";
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             sql += " ORDER BY a.czrq desc ";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> mapList = hibenateUtils.createSQLQuery(sql,page,pagesize);
 | 
												
													
														
															|  | 
 |  |         for (Map<String,Object> map:mapList){
 | 
												
													
														
															|  | 
 |  |             if (map.get("patientIdcard")!=null){
 | 
												
													
														
															|  | 
 |  |                 String idcard = map.get("patientIdcard").toString();
 | 
												
													
														
															|  | 
 |  |                 Integer age = IdCardUtil.getAgeForIdcard(idcard);
 | 
												
													
														
															|  | 
 |  |                 map.put("patientAge",age);
 | 
												
													
														
															|  | 
 |  |             }else {
 | 
												
													
														
															|  | 
 |  |                 map.put("patientAge",null);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             if (map.get("doctor")!=null){
 | 
												
													
														
															|  | 
 |  |                 String doctorId = map.get("doctor").toString();
 | 
												
													
														
															|  | 
 |  |                 BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctorId);
 | 
												
													
														
															|  | 
 |  |                 List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
 | 
												
													
														
															|  | 
 |  |                 if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
 | 
												
													
														
															|  | 
 |  |                     map.put("deptName",doctorHospitalDOS.get(0).getDeptName());
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 if (baseDoctorDO!=null){
 | 
												
													
														
															|  | 
 |  |                     map.put("doctorName",baseDoctorDO.getName());
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return mapList;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 保存系统消息&发送IM外层刷新事件的消息
 |  |      * 保存系统消息&发送IM外层刷新事件的消息
 | 
												
													
														
															|  |      * @param systemMessageDO
 |  |      * @param systemMessageDO
 |