Ver código fonte

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

# Conflicts:
#	patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
#	patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java
lyr 8 anos atrás
pai
commit
6a0ed5b462

+ 6 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java

@ -44,9 +44,9 @@ public class ConsultTeam extends IdEntity {
	private Long guidance;   //关联指导
	private String doctorName;//醫生名字
	//起始消息id
	private Integer startMsgId;
	private String startMsgId;
	//结束消息id
	private Integer endMsgId;
	private String endMsgId;
	// 结束人
	private String endOperator;
	// 结束人类型
@ -256,19 +256,19 @@ public class ConsultTeam extends IdEntity {
	}
	public Integer getStartMsgId() {
	public String getStartMsgId() {
		return startMsgId;
	}
	public void setStartMsgId(Integer startMsgId) {
	public void setStartMsgId(String startMsgId) {
		this.startMsgId = startMsgId;
	}
	public Integer getEndMsgId() {
	public String getEndMsgId() {
		return endMsgId;
	}
	public void setEndMsgId(Integer endMsgId) {
	public void setEndMsgId(String endMsgId) {
		this.endMsgId = endMsgId;
	}

+ 64 - 68
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -15,81 +15,77 @@ import java.util.Date;
/**
 * 医生权限校验
 *
 * @author George
 *
 */
public class DoctorInterceptor extends BaseInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
        try {
            response.setCharacterEncoding("UTF-8");
            JSONObject json = getAgent(request);
            if (json == null) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            String tokenStr = json.has("token") ? json.getString("token") : "";
            String uid = json.has("uid") ? json.getString("uid") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            //如果是观察者直接返回true
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
                return true;
            }
            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		boolean flag = true;
		try {
			response.setCharacterEncoding("UTF-8");
			JSONObject json = getAgent(request);
			if (json == null) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
			String tokenStr = json.has("token") ? json.getString("token") : "";
			String uid = json.has("uid") ? json.getString("uid") : "";
			String imei = json.has("imei") ? json.getString("imei") : "";
			if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
            Token token = SystemData.doctorTokens.get(uid);
            if (token == null) {
                token = tokenDao.findByPatient(uid, 2);
                if (token != null) {
                    // 加入缓存
                    SystemData.doctorTokens.put(uid, token);
                }
            }
            if (token == null || token.getPlatform() != 2) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                flag = false;
            } else {
                if (token.getTimeout().getTime() < new Date().getTime()) {
                    // 登录超时
                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
                    flag = false;
                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
                    // 别处登录
                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
                    flag = false;
                } else {
                    // 一天只更新一次
                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        SystemData.doctorTokens.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
			Token token = SystemData.doctorTokens.get(uid);
			if (token == null) {
				token = tokenDao.findByPatient(uid, 2);
				if (token != null) {
					// 加入缓存
					SystemData.doctorTokens.put(uid, token);
				}
			}
			if (token == null || token.getPlatform() != 2) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				flag = false;
			} else {
				if (token.getTimeout().getTime() < new Date().getTime()) {
					// 登录超时
					response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
					flag = false;
				} else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
					// 别处登录
					response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
					flag = false;
				} else {
					// 一天只更新一次
					if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
						// 今天未更新,则更新缓存
						token.setCzrq(new Date());
						// 更新内存
						SystemData.doctorTokens.put(uid, token);
						// 更新数据库
						tokenDao.save(token);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }
	}
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    }
	}
}

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/PatientInterceptor.java

@ -24,6 +24,9 @@ public class PatientInterceptor extends BaseInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		boolean flag = true;
		if(flag){
			return true;
		}
		try {
			if(request.getRequestURI().contains("/patient/hosptail/getHositalByTownCode")){
				return true;

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

@ -38,15 +38,20 @@ import org.apache.poi.hssf.util.HSSFColor;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
@ -316,41 +321,6 @@ public class ConsultTeamService extends ConsultService {
        }
    }
    /**
     * 查询居民咨询记录
     *
     * @param patient
     * @param teamCode
     * @param page
     * @param pageSize
     * @return
     */
    public JSONArray findByPatientAndTeam(String patient, Long teamCode, int page, int pageSize) {
        PageRequest pageRequest = new PageRequest(page, pageSize);
        Patient p = patientDao.findByCode(patient);
        Page<Object> result = consultDao.findByPatientAndTeam(patient, teamCode, pageRequest);
        JSONArray array = new JSONArray();
        for (Object obj : result) {
            JSONObject consult = new JSONObject();
            Object[] objArr = (Object[]) obj;
            consult.put("id", objArr[0]);
            consult.put("code", objArr[2]);
            consult.put("type", objArr[1]);
            consult.put("title", objArr[3]);
            consult.put("symptoms", objArr[4]);
            consult.put("czrq", objArr[5]);
            consult.put("status", objArr[6]);
            consult.put("adminTeamCode", objArr[7]);
            consult.put("patient", patient);
            consult.put("patientName", p.getName());
            consult.put("patientPhoto", p.getPhoto());
            array.put(consult);
        }
        return array;
    }
    /**
     * 根据状态获取三师家庭咨询
     *
@ -589,18 +559,18 @@ public class ConsultTeamService extends ConsultService {
     * @return
     */
    public void reply(List<ConsultTeamLog> logs, String patient) throws Exception {
        ConsultTeam consultTeam = consultTeamDao.findByConsult(logs.get(0).getConsult());
        WlyyTalkGroup wlyyTalkGroup = talkGroupService.findConsultTalkGroupByType(logs.get(0).getConsult(), 2);
        for (ConsultTeamLog log : logs) {
            reply(log, patient, null, log.getType());
            //判断当前咨询是否创建讨论租
            if (wlyyTalkGroup != null) {
                sendGroupIM(patient, wlyyTalkGroup.getCode(), log.getChatType() + "", log.getContent());
            } else {
                //推送给IM
                sendIM(patient, consultTeam.getDoctor(), log.getChatType() + "", log.getContent());
            }
        }
        //ConsultTeam consultTeam = consultTeamDao.findByConsult(logs.get(0).getConsult());
        //WlyyTalkGroup wlyyTalkGroup = talkGroupService.findConsultTalkGroupByType(logs.get(0).getConsult(), 2);
        //for (ConsultTeamLog log : logs) {
        //    reply(log, patient, null, log.getType());
        //    //判断当前咨询是否创建讨论租
        //    if (wlyyTalkGroup != null) {
        //        sendGroupIM(patient, wlyyTalkGroup.getCode(), log.getChatType() + "", log.getContent());
        //    } else {
        //        //推送给IM
        //        sendIM(patient, consultTeam.getDoctor(), log.getChatType() + "", log.getContent());
        //    }
        //}
    }
    /**
@ -658,6 +628,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) {
            // 查询三师签约信息
@ -669,15 +640,21 @@ public class ConsultTeamService extends ConsultService {
            ct.setTeam(sc.getTeamCode());
            // 设置健康管理师,三师咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient);
             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());
                if(doctorTeamMember!=null){
                    users.put(doctorTeamMember.getMemberCode(),1);
                }
            }else{
                users.put(doctorTeamMemberHealthy.getMemberCode(),0);
                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
            }
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
            ct.setAdminTeamId(sc.getAdminTeamId());
        } else if (ct.getType() == 2) {
            // 咨询家庭医生
@ -690,14 +667,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());
                if(doctorTeamMember!=null){
                    users.put(doctorTeamMember.getMemberCode(),1);
                }
            }else{
                users.put(doctorTeamMemberHealthy.getMemberCode(),0);
                ct.setDoctor(doctorTeamMemberHealthy.getMemberCode());
            }
            ct.setTeam(sf.getTeamCode());
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
            ct.setAdminTeamId(sf.getAdminTeamId());
        }
        // 设置患者信息
@ -733,23 +715,21 @@ 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去创建议题,取得成员消息
        DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
        JSONObject messages = new JSONObject();
        messages.put("description",consult.getSymptoms());
        messages.put("title",consult.getTitle());
        messages.put("img",consult.getImages());
        messages.put("senderId",patient);
        messages.put("senderName",tempPatient.getName());
        users.put(patient,0);
        JSONObject obj  = createTopics(patient,consult.getCode(),"咨询问题:"+consult.getSymptoms(),users,messages);
        if(obj==null){
            throw new RuntimeException("IM消息结束异常!");
        }
        ct.setStartMsgId(obj.get("id").toString());
        consultTeamDao.save(ct);
        consultDao.save(consult);
        consultTeamDoctorDao.save(cd);
@ -760,21 +740,85 @@ public class ConsultTeamService extends ConsultService {
     * 发送消息给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");
    private String sendIM(String from,String fromName, String sessionId, String contentType, String content) {
        String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/"+sessionId+"/messages";
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("sender_name", fromName);
        params.put("content_type", contentType);
        params.put("content", content);
        params.put("sessionId", sessionId);;
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 创建议题
     *
     * @param topicId  议题ID
     * @param topicName  议题名称
     * @param participants 成员
     */
    private JSONObject createTopics(String sessionId, String topicId,String topicName, JSONObject participants,JSONObject messages) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+sessionId+"/topics";
        JSONObject params = new JSONObject();
        params.put("topicId", topicId);
        params.put("topicName", topicName);
        params.put("participants", participants.toString());
        params.put("messages", messages.toString());
        params.put("sessionId", sessionId);;
        String ret = HttpClientUtil.postBody(imAddr,params);
        JSONObject obj  = null;
        try{
            obj = new JSONObject(ret);
        }catch (Exception e){
            return null;
        }
        return obj;
    }
    /**
     * 结束议题
     *
     * @param topicId  议题ID
     * @param endUser  结束人
     * @param endUserName 结束人名字
     * @param sessionId 会话ID
     */
    private JSONObject endTopics(String sessionId,String endUser, String endUserName,String topicId) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+sessionId+"/topics/"+topicId+"/ended";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("end_user", endUser);
        params.put("end_user_name",endUserName);
        params.put("topic_id", topicId);
        String ret = HttpClientUtil.postBody(imAddr,params);
        JSONObject obj  = null;
        try{
            obj = new JSONObject(ret);
        }catch (Exception e){
            return null;
        }
        return obj;
    }
    /**
     * 议题邀请人员
     * @param user 结束人名字
     * @param sessionId 会话ID
     */
    private void updateTopicUser(String sessionId,String user) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/"+sessionId+"/participants/"+user;
        JSONObject params = new JSONObject();
        params.put("user", user+":"+0);
        HttpClientUtil.putBody(imAddr,params);
    }
    /**
     * 发送消息给IM
     *
@ -932,38 +976,24 @@ public class ConsultTeamService extends ConsultService {
    public int finish(String consult, String endOperator, int endType) throws Exception {
        ConsultTeam consultTeam = consultTeamDao.findByConsult(consult);
        String name = "";
        String returnJson = "";
        String endName = "";
        String endId = "";
        //推送给IM文字消息
        if (endType == 1) {
            Patient p = patientDao.findByCode(endOperator);
            name = p.getName();
            returnJson = sendIM(consultTeam.getPatient(), consultTeam.getDoctor(), "7", name + "结束了本次咨询");
            endName = p.getName();
            endId = p.getCode();
        } else {
            Doctor d = doctorDao.findByCode(endOperator);
            name = d.getName();
            returnJson = sendIM(consultTeam.getDoctor(), consultTeam.getPatient(), "7", name + "结束了本次咨询");
        }
        if (StringUtils.isEmpty(returnJson)) {
            throw new Exception("send consult finished IM message failed");
        } else {
            JSONObject jo = new JSONObject(returnJson);            //设置消息ID
            consultTeam.setEndMsgId(jo.getInt("startId"));
            consultTeam.setEndOperator(endOperator);
            consultTeam.setEndType(endType);
            endId = d.getCode();
            endName = d.getName();
        }
        JSONObject group = talkGroupService.findConsultTalkGroup(consultTeam.getConsult());
        if (group != null) {
            String json = sendGroupIM(endOperator, group.getString("code"), "7", name + "结束了本次咨询");
            if (StringUtils.isEmpty(json)) {
                throw new Exception("send consult finished IM message failed");
            }
        JSONObject obj = endTopics(consultTeam.getPatient(),endId,endName,consultTeam.getConsult());
        if(obj==null){
            throw new RuntimeException("IM消息结束异常!");
        }
        consultTeam.setType(endType);
        consultTeam.setEndMsgId(obj.get("id").toString());
        return consultTeamDao.updateStatusByConsult(consult);
    }
@ -1165,6 +1195,7 @@ public class ConsultTeamService extends ConsultService {
    public void addFamousTeamConsult(ConsultTeam ct, String uid, String type) throws Exception {
        // 设置患者信息
        ct.setPatient(uid);
        JSONObject messages = new JSONObject();
        if ("1".equals(type)) {
            // 查询患者信息
            Patient tempPatient = patientDao.findByCode(uid);
@ -1176,6 +1207,11 @@ public class ConsultTeamService extends ConsultService {
            ct.setSex(tempPatient.getSex());
            // 设置患者头像
            ct.setPhoto(tempPatient.getPhoto());
            messages.put("senderId",tempPatient.getCode());
            messages.put("senderName",tempPatient.getName());
        } else if ("2".equals(type)) {
            Doctor doctorTemp = doctorDao.findByCode(uid);
            // 设置医生姓名
@ -1208,20 +1244,19 @@ public class ConsultTeamService extends ConsultService {
        // 添加医生咨询日志
        String content = addLogs(ct);
        //推送给IM文字消息
        String returnJson = sendIM(ct.getPatient(), ct.getDoctor(), "6", content);
        ;
        JSONObject jo = new JSONObject(returnJson);
        //设置消息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);
                }
            }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(ct.getPatient(),0);
        jsonObject.put(ct.getDoctor(),0);
        messages.put("description",consult.getSymptoms());
        messages.put("title",consult.getTitle());
        messages.put("img",consult.getImages());
        JSONObject obj = createTopics(String.valueOf(jsonObject.hashCode()),consult.getCode(),consult.getSymptoms(),jsonObject,messages);
        if(obj==null){
            throw new RuntimeException("im消息创建异常!");
        }
        //设置消息ID
        ct.setStartMsgId(obj.get("id").toString());
        consultTeamDao.save(ct);  // 保存医生咨询信息
        consultTeamDoctorDao.save(cd);
        consultDao.save(consult);
@ -1284,7 +1319,6 @@ public class ConsultTeamService extends ConsultService {
    public List<ConsultTeamLog> getConsultLog(String consultCode) {
        return consultTeamLogDao.getConsultLogByConsultLog(consultCode);
    }
    /**
     * @param ct
     * @param uid
@ -1323,36 +1357,31 @@ public class ConsultTeamService extends ConsultService {
        // 添加医生咨询日志
        String content = addLogs(ct);
        //推送给IM文字消息
        String returnJson = null;
        JSONObject jo;
        if (StringUtils.isNotEmpty(oldConsultCode)) {
            ConsultTeam oldConsult = consultTeamDao.findByConsult(oldConsultCode);
            if (oldConsult != null) {
                returnJson = sendIM(ct.getPatient(), ct.getDoctor(), "6", "居民问题:" + oldConsult.getSymptoms());
                //推送给IM图片
                if (StringUtils.isNotEmpty(oldConsult.getImages())) {
                    String[] images = oldConsult.getImages().split(",");
                    for (String image : images) {
                        if (StringUtils.isNoneEmpty(image)) {
                            sendIM(ct.getPatient(), ct.getDoctor(), "2", image);
                        }
                    }
                }
            }
        }
        if (StringUtils.isEmpty(returnJson))
            returnJson = sendIM(ct.getPatient(), ct.getDoctor(), "6", content);
        else
            sendIM(ct.getPatient(), ct.getDoctor(), "6", content);
        jo = new JSONObject(returnJson);
        JSONObject messages = new JSONObject();
        messages.put("description",content);
        messages.put("title",consult.getTitle());
        messages.put("img",consult.getImages());
        messages.put("senderId",doctorTemp.getCode());
        messages.put("senderName",doctorTemp.getName());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(ct.getPatient(),0);
        jsonObject.put(ct.getDoctor(),0);
        //设置消息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);
        JSONObject obj = createTopics(String.valueOf(jsonObject.hashCode()),consult.getCode(),"咨询求助:"+doctorTemp.getName(),jsonObject,messages);
        if(obj==null){
            throw new RuntimeException("im消息创建异常!");
        }
        ct.setStartMsgId(obj.get("id").toString());
        //转发咨询问题
        if(StringUtils.isNotBlank(oldConsultCode)){
            Consult oldConsult = consultDao.findByCode(oldConsultCode);
            if(oldConsult!=null){
                sendIM(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"6",content);
                if(StringUtils.isNotBlank(oldConsult.getImages())){
                    String imgs[] = oldConsult.getImages().split(",");
                    for(String url :imgs)
                       sendIM(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"2",url);
                }
            }
        }
@ -1362,38 +1391,12 @@ public class ConsultTeamService extends ConsultService {
    }
    /**
     * @param ct
     * @param uid
     * @throws Exception
     */
    public void sendForHelpMsg(ConsultTeam ct, String uid, String oldConsultCode) throws Exception {
        ct.setPatient(uid);
    public void sendForHelpMsg(String oldConsultCode,String userId) throws Exception {
        Consult consult = consultDao.findByCode(oldConsultCode);
        //推送给IM文字消息
        if (StringUtils.isNotEmpty(oldConsultCode)) {
            ConsultTeam oldConsult = consultTeamDao.findByConsult(oldConsultCode);
            if (oldConsult != null) {
                sendIM(ct.getPatient(), ct.getDoctor(), "6", "居民问题:" + oldConsult.getSymptoms());
                //推送给IM图片
                if (StringUtils.isNotEmpty(oldConsult.getImages())) {
                    String[] images = oldConsult.getImages().split(",");
                    for (String image : images) {
                        if (StringUtils.isNoneEmpty(image)) {
                            sendIM(ct.getPatient(), ct.getDoctor(), "2", image);
                        }
                    }
                }
            }
        }
        sendIM(ct.getPatient(), ct.getDoctor(), "6", "咨询问题:" + ct.getSymptoms());
        //推送给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);
                }
            }
        }
        updateTopicUser(consult.getPatient(),userId);
    }
    /**
@ -1406,30 +1409,30 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 判断两医生是否在同一团队内
     *
     * @param docCode1
     * @param docCode2
     * @return
     */
    public boolean isCommonTeam(String docCode1, String docCode2) {
    public boolean isCommonTeam(String docCode1, String docCode2){
        String sqlQuSum =
                "SELECT c.team_id FROM " +
                        "(SELECT a.* FROM wlyy_admin_team_member a where a.doctor_code='" + docCode1 + "' ) c " +
                        "LEFT JOIN " +
                        "(SELECT b.* FROM wlyy_admin_team_member b where b.doctor_code='" + docCode2 + "' ) d " +
                        "on c.team_id=d.team_id " +
                        "WHERE d.team_id IS NOT NULL";
                    "(SELECT a.* FROM wlyy_admin_team_member a where a.doctor_code='"+ docCode1 +"' ) c " +
                    "LEFT JOIN " +
                    "(SELECT b.* FROM wlyy_admin_team_member b where b.doctor_code='"+ docCode2 +"' ) d " +
                    "on c.team_id=d.team_id " +
                    "WHERE d.team_id IS NOT NULL";
        List ls = jdbcTemplate.queryForList(sqlQuSum);
        return ls != null && ls.size() > 0;
        return ls!=null && ls.size()>0;
    }
    /**
     * 通过team获取医生code
     *
     * @param consult 关联的上一个咨询
     * @return
     */
    public List findByTeam(String consult) {
    public List findByTeam(String consult){
        return consultTeamDao.findByTeamAndType(consult, 10);
    }
}

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

@ -332,7 +332,10 @@ public class MessageService extends BaseService {
                map.put("value2", String.valueOf(item.getValue2()));
                map.put("czrq", DateUtil.dateToStrLong(item.getCzrq()));
                re.add(map);
                item.setRead(0);//把消息设置为已读
            }
            messageDao.save(list);
        }
        return re;
    }

+ 26 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java

@ -15,6 +15,10 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
public class HttpClientUtil {
@ -99,4 +103,26 @@ public class HttpClientUtil {
		return null;
	}
	public static String postBody(String url,JSONObject params){
		RestTemplate restTemplate = new RestTemplate();
		HttpHeaders headers = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
		headers.setContentType(type);
		headers.add("Accept", MediaType.APPLICATION_JSON.toString());
		org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
		String ret = restTemplate.postForObject(url, formEntity, String.class);
		return ret;
	}
	public static void putBody(String url,JSONObject params){
		RestTemplate restTemplate = new RestTemplate();
		HttpHeaders headers = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
		headers.setContentType(type);
		headers.add("Accept", MediaType.APPLICATION_JSON.toString());
		org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
		restTemplate.put(url, formEntity, String.class);
	}
}

+ 15 - 17
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -68,7 +68,6 @@ public class DoctorConsultController extends WeixinBaseController {
    private ConsultService consultService;
    @Autowired
    private TalkGroupService talkGroupService;
    /**
     * 三师咨询列表查询
     *
@ -531,7 +530,7 @@ public class DoctorConsultController extends WeixinBaseController {
                        json.put("first", p.getName() + ",您好!\n您的健康咨询有新的回复");
                        json.put("toUser", p.getCode());
                        String symp = ct.getSymptoms();
                        json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...") : content);
                        json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...")  : content);
                        String replycontent = content.length() > 50 ? content.substring(0, 50) + "..." : content;
                        if (type == 2) {
                            replycontent = "[图片]";
@ -844,10 +843,10 @@ public class DoctorConsultController extends WeixinBaseController {
            consult.setVoice(voice);
            consult.setDoctor(doctorCode);//设置专科医生
            // 保存到数据库
            if (consultTeamService.isCommonTeam(doctorCode, getUID()))
                consultTeamService.sendForHelpMsg(consult, getUID(), oldConsultCode);
            if(consultTeamService.isCommonTeam( doctorCode, getUID() ))
                consultTeamService.sendForHelpMsg(oldConsultCode,doctorCode);
            else
                consultTeamService.addForHelpTeamConsult(consult, getUID(), oldConsultCode);
                consultTeamService.addForHelpTeamConsult( consult, getUID(), oldConsultCode );
            // 推送消息给医生
            /*PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.D_CT_04.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.您有新的名医咨询.name(), consult.getConsult());
@ -868,23 +867,23 @@ public class DoctorConsultController extends WeixinBaseController {
    @ResponseBody
    public String hasUnfinished(String doctorCode) {
        try {
            String curDoc = getUID();
            String curDoc =  getUID();
            JSONObject json = new JSONObject();
            if (consultTeamService.isCommonTeam(doctorCode, curDoc)) {
            if(consultTeamService.isCommonTeam(doctorCode, curDoc)){
                json.put("isCommonTeam", 1);
                return write(200, "查询成功", "data", json);
            }
            List<ConsultTeam> ls = consultTeamService.hasUnfinished(doctorCode, curDoc);
            if (ls != null && ls.size() > 0) {
                ConsultTeam ct = ls.get(0);
            List<ConsultTeam>  ls = consultTeamService.hasUnfinished(doctorCode, curDoc);
            if(ls!=null && ls.size() > 0){
                ConsultTeam ct =  ls.get(0);
                json.put("consult", ct.getConsult());
                //是否是医生求助医生
                if (ct.getType() == 10) {
                if(ct.getType()==10){
                    List<WlyyTalkGroup> wlyyTalkGroups = talkGroupService.findAllConsultTalkGroup(ct.getTeam());
                    if (wlyyTalkGroups != null && wlyyTalkGroups.size() > 0) {
                        for (WlyyTalkGroup g : wlyyTalkGroups) {
                            if (g.getType() == 1) {
                    if(wlyyTalkGroups!=null && wlyyTalkGroups.size()>0){
                        for (WlyyTalkGroup g : wlyyTalkGroups){
                            if(g.getType()==1){
                                json.put("zxGroupCode", g.getCode());
                                json.put("from", ct.getPatient());
                                break;
@ -903,7 +902,6 @@ public class DoctorConsultController extends WeixinBaseController {
    /**
     * 该咨询求助过的医生列表
     *
     * @param consult 关联的上一个咨询
     * @return
     */
@ -913,8 +911,8 @@ public class DoctorConsultController extends WeixinBaseController {
        try {
            List<String> ls = consultTeamService.findByTeam(consult);
            JSONObject json = new JSONObject();
            if (ls != null) {
                for (String o : ls) {
            if(ls!=null){
                for(String o : ls){
                    json.put(o, 1);
                }
            }

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -566,7 +566,7 @@ public class ConsultController extends WeixinBaseController {
     */
    @RequestMapping(value = "finish")
    @ResponseBody
    public String finish(String code) {
    public String finish(@RequestParam(required = true) String code) {
        try {
            int row = consultTeamService.finish(code, getUID(), 1);
            if (row > 0) {

+ 1 - 1
patient-co-wlyy/src/main/resources/system.properties

@ -50,7 +50,7 @@ chat_server=http://weixin.xmtyw.cn/res/chat/
sign_check_upload=http://172.19.103.87:8011/wlyy_service
# IM配置
im_list_get=http://172.19.103.29:3000/
im_list_get=http://192.168.131.109:3008/
im_group_server=http://172.19.103.29:3000/api/v1/chats/gm
msg_push_server=http://172.19.103.29:3000/api/v1/chats/sm