suqinyi 1 год назад
Родитель
Сommit
9f54579984

+ 944 - 927
business/im-service/src/main/java/com/yihu/jw/im/util/ImUtil.java

@ -17,954 +17,971 @@ import java.util.List;
/**
 * IM工具类
 *
 * @author huangwenjie
 */
@Component
public class ImUtil {
	@Autowired
	private HttpClientUtil HttpClientUtil;
	@Value("${im.im_list_get}")
	private String im_host;
	public enum ContentType {
		plainText("信息", "1"),
		image("图片信息", "2"),
		audio("创建处方", "3"),
		article("文章信息", "4"),
		goTo("跳转信息,求组其他医生或者邀请其他医生发送的推送消息", "5"),
		topicBegin("议题开始", "6"),
		topicEnd("议题结束", "7"),
		personalCard("个人名片", "18"),
		messageForward("消息转发", "19"),
		topicInto("进入议题", "14"),
		video("视频", "12"),
		system("系统消息", "13"),
		prescriptionCheck("续方审核消息消息", "15"),
		prescriptionBloodStatus("续方咨询血糖血压咨询消息", "16"),
		prescriptionFollowupContent("续方咨询随访问卷消息", "17"),
		Rehabilitation("康复计划发送","20"),
		Reservation("转诊预约发送","21"),
		Know("已知悉","22"),
		KnowCommonQuestion("知识库-常见问题","3001"),
		KnowCommonCustomer("知识库-客服欢迎","3008"),
		KnowCommonQuestions("知识库-常见问题集","3002"),
		KnowCommonDict("知识库-字典","3003"),
		KnowDeptDoctor("知识库-科室医生","3004"),
		KnowSymptomsDisease("知识库-疾病症状","3005"),
		KnowSymptomsDiseaseQ("知识库-疾病症状问题","3006"),
		KnowSymptomsDiseaseA("知识库-疾病症状回答","3007");
		private String name;
		private String value;
		ContentType(String name, String value) {
			this.name = name;
			this.value = value;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	public String sendMDTSocketMessageToDoctor(String targetUserId, String message) {
		String imAddr = im_host + "api/v2/message/doctorSystemMessage";
		JSONObject params = new JSONObject();
		params.put("targetUserId", targetUserId);
		params.put("message", message);
		String response = HttpClientUtil.postBody(imAddr,params);
		return response;
	}
	public String sendPcManageMessageToPc(String clientType, String message) {
		String imAddr = im_host + "api/v2/message/cloudCarePcManageMessage";
		JSONObject params = new JSONObject();
		params.put("clientType", clientType);
		params.put("message", message);
		String response = HttpClientUtil.postBody(imAddr,params);
		return response;
	}
	public String sendPatientSystemMessage(String targetUserId, String message) {
		String imAddr = im_host + "api/v2/message/patientSystemMessage";
		JSONObject params = new JSONObject();
		params.put("targetUserId", targetUserId);
		params.put("message", message);
		String response = HttpClientUtil.postBody(imAddr,params);
		return response;
	}
	/**
	 * 发送消息
	 * @param senderId 发送者的code
	 * @param receiverId 接受者code
	 * @param contentType 消息类型 1二维码内容
	 * @param content 消息内容
	 * @return
	 */
	public String sendMessage(String senderId,String receiverId,String contentType,String content){
		String imAddr = im_host + "api/v2/message/send";
		JSONObject params = new JSONObject();
		params.put("sender_id", senderId);
		params.put("sender_name", receiverId);
		params.put("content_type", contentType);
		params.put("content", content);
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	/**
	 * 获取医生统计数据
	 * status reply 为空值是是该医生总咨询量
	 *
	 * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param adminTeamCode
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getConsultData(String user, Integer adminTeamCode, Integer status, Integer reply) {
		String imAddr = im_host + "api/v2/sessions/topics/count/reply";
		imAddr = imAddr + "?user=" + user;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (adminTeamCode != null) {
			imAddr += ("&adminTeamCode=" + adminTeamCode);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	public void updateTopics(String topicId, String jsonValue) {
		String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
		JSONObject params = new JSONObject();
		params.put("topic_id", topicId);
		params.put("data", jsonValue);
		HttpClientUtil.putBody(imAddr, params);
	}
	/**
	 * 当前医生下当前团队列表接口
	 * 获取团队内医生的健康咨询状况
	 * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 *
	 * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param adminTeamCode 行政团队code
	 * @param page
	 * @param pagesize
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getTeamConsultByStatus(String user, Integer adminTeamCode, Integer status, Integer reply, int page, int pagesize) {
		String imAddr = im_host + "api/v2/sessions/healthTeamTopics";
		imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
		if (adminTeamCode != null) {
			imAddr += ("&adminTeamCode=" + adminTeamCode);
		}
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	/**
	 * 列表接口
	 * 获取团队内医生的健康咨询状况
	 * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 *
	 * @param user     团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param page
	 * @param pagesize
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
		String imAddr = im_host + "api/v2/sessions/healthTopics";
		imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	/**
	 * 咨询列表
	 * @param user
	 * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 * @param reply
	 * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public String getConsultByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime,int page,int pagesize){
		String imAddr = im_host + "api/v2/sessions/topicListByType";
		imAddr = imAddr + "?user="+user + "&page=" + page + "&pagesize=" + pagesize;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		if (type != null) {
			imAddr += ("&type=" + type);
		}
		if (patientName != null) {
			imAddr += ("&patientName=" + patientName);
		}
		if (startTime != null) {
			imAddr += ("&startTime=" + startTime);
		}
		if (endTime != null) {
			imAddr += ("&endTime=" + endTime);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	/**
	 * 咨询列表总数
	 * @param user
	 * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 * @param reply
	 * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
	 * @return
	 */
	public String getConsultCountByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime){
		String imAddr = im_host + "api/v2/sessions/topicListCountByType";
		imAddr = imAddr + "?user="+user;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		if (type != null) {
			imAddr += ("&type=" + type);
		}
		if (patientName != null) {
			imAddr += ("&patientName=" + patientName);
		}
		if (startTime != null) {
			imAddr += ("&startTime=" + startTime);
		}
		if (endTime != null) {
			imAddr += ("&endTime=" + endTime);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType,String extend) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages";
		System.out.println("im地址"+imAddr);
		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("session_id", sessionId);
		params.put("business_type", businessType);
		params.put("extend",extend);
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public static  String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType) {
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Value("${im.im_list_get}")
    private String im_host;
    public enum ContentType {
        plainText("信息", "1"),
        image("图片信息", "2"),
        audio("创建处方", "3"),
        article("文章信息", "4"),
        goTo("跳转信息,求组其他医生或者邀请其他医生发送的推送消息", "5"),
        topicBegin("议题开始", "6"),
        topicEnd("议题结束", "7"),
        personalCard("个人名片", "18"),
        messageForward("消息转发", "19"),
        topicInto("进入议题", "14"),
        video("视频", "12"),
        system("系统消息", "13"),
        prescriptionCheck("续方审核消息消息", "15"),
        prescriptionBloodStatus("续方咨询血糖血压咨询消息", "16"),
        prescriptionFollowupContent("续方咨询随访问卷消息", "17"),
        Rehabilitation("康复计划发送", "20"),
        Reservation("转诊预约发送", "21"),
        Know("已知悉", "22"),
        KnowCommonQuestion("知识库-常见问题", "3001"),
        KnowCommonCustomer("知识库-客服欢迎", "3008"),
        KnowCommonQuestions("知识库-常见问题集", "3002"),
        KnowCommonDict("知识库-字典", "3003"),
        KnowDeptDoctor("知识库-科室医生", "3004"),
        KnowSymptomsDisease("知识库-疾病症状", "3005"),
        KnowSymptomsDiseaseQ("知识库-疾病症状问题", "3006"),
        KnowSymptomsDiseaseA("知识库-疾病症状回答", "3007");
        private String name;
        private String value;
        ContentType(String name, String value) {
            this.name = name;
            this.value = value;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        }
    }
    public String sendMDTSocketMessageToDoctor(String targetUserId, String message) {
        String imAddr = im_host + "api/v2/message/doctorSystemMessage";
        JSONObject params = new JSONObject();
        params.put("targetUserId", targetUserId);
        params.put("message", message);
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    public String sendPcManageMessageToPc(String clientType, String message) {
        String imAddr = im_host + "api/v2/message/cloudCarePcManageMessage";
        JSONObject params = new JSONObject();
        params.put("clientType", clientType);
        params.put("message", message);
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    public String sendPatientSystemMessage(String targetUserId, String message) {
        String imAddr = im_host + "api/v2/message/patientSystemMessage";
        JSONObject params = new JSONObject();
        params.put("targetUserId", targetUserId);
        params.put("message", message);
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 发送消息
     *
     * @param senderId    发送者的code
     * @param receiverId  接受者code
     * @param contentType 消息类型 1二维码内容
     * @param content     消息内容
     * @return
     */
    public String sendMessage(String senderId, String receiverId, String contentType, String content) {
        String imAddr = im_host + "api/v2/message/send";
        JSONObject params = new JSONObject();
        params.put("sender_id", senderId);
        params.put("sender_name", receiverId);
        params.put("content_type", contentType);
        params.put("content", content);
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 获取医生统计数据
     * status reply 为空值是是该医生总咨询量
     *
     * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
     * @param adminTeamCode
     * @param status
     * @param reply
     * @return
     */
    public String getConsultData(String user, Integer adminTeamCode, Integer status, Integer reply) {
        String imAddr = im_host + "api/v2/sessions/topics/count/reply";
        imAddr = imAddr + "?user=" + user;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (adminTeamCode != null) {
            imAddr += ("&adminTeamCode=" + adminTeamCode);
        }
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
    public void updateTopics(String topicId, String jsonValue) {
        String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
        JSONObject params = new JSONObject();
        params.put("topic_id", topicId);
        params.put("data", jsonValue);
        HttpClientUtil.putBody(imAddr, params);
    }
    /**
     * 当前医生下当前团队列表接口
     * 获取团队内医生的健康咨询状况
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     *
     * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
     * @param adminTeamCode 行政团队code
     * @param page
     * @param pagesize
     * @param status
     * @param reply
     * @return
     */
    public String getTeamConsultByStatus(String user, Integer adminTeamCode, Integer status, Integer reply, int page, int pagesize) {
        String imAddr = im_host + "api/v2/sessions/healthTeamTopics";
        imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
        if (adminTeamCode != null) {
            imAddr += ("&adminTeamCode=" + adminTeamCode);
        }
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
    /**
     * 列表接口
     * 获取团队内医生的健康咨询状况
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     *
     * @param user     团队就把团队的医生合并起来用,隔开(医生编码)
     * @param page
     * @param pagesize
     * @param status
     * @param reply
     * @return
     */
    public String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
        String imAddr = im_host + "api/v2/sessions/healthTopics";
        imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
    /**
     * 咨询列表
     *
     * @param user
     * @param status   status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     * @param reply
     * @param type     1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
     * @param page
     * @param pagesize
     * @return
     */
    public String getConsultByStatusAndType(String user, Integer status, Integer reply, Integer type, String patientName, String startTime, String endTime, int page, int pagesize) {
        String imAddr = im_host + "api/v2/sessions/topicListByType";
        imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        if (type != null) {
            imAddr += ("&type=" + type);
        }
        if (patientName != null) {
            imAddr += ("&patientName=" + patientName);
        }
        if (startTime != null) {
            imAddr += ("&startTime=" + startTime);
        }
        if (endTime != null) {
            imAddr += ("&endTime=" + endTime);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
    /**
     * 咨询列表总数
     *
     * @param user
     * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     * @param reply
     * @param type   1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
     * @return
     */
    public String getConsultCountByStatusAndType(String user, Integer status, Integer reply, Integer type, String patientName, String startTime, String endTime) {
        String imAddr = im_host + "api/v2/sessions/topicListCountByType";
        imAddr = imAddr + "?user=" + user;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        if (type != null) {
            imAddr += ("&type=" + type);
        }
        if (patientName != null) {
            imAddr += ("&patientName=" + patientName);
        }
        if (startTime != null) {
            imAddr += ("&startTime=" + startTime);
        }
        if (endTime != null) {
            imAddr += ("&endTime=" + endTime);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType, String extend) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages";
        System.out.println("im地址" + imAddr);
        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("session_id", sessionId);
        params.put("business_type", businessType);
        params.put("extend", extend);
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public static String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType) {
//		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages";//原本的
		String host = ImService.im_host ;
		String imAddr = host + "api/v2/sessions/" + sessionId + "/messages";
		System.out.println("im地址"+imAddr);
		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("session_id", sessionId);
		params.put("business_type", businessType);
		params.put("extend",null);
        String host = ImService.im_host;
        String imAddr = host + "api/v2/sessions/" + sessionId + "/messages";
        System.out.println("im地址" + imAddr);
        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("session_id", sessionId);
        params.put("business_type", businessType);
        params.put("extend", null);
//		String response = HttpClientUtil.postBody(imAddr, params);
		String response = com.yihu.jw.util.http.HttpClientUtil.postBodyStatic(imAddr, params);
		return response;
	}
	/**
	 * 更新会话状态
	 *
	 * @param sessionId 会话ID
	 * @param status    状态
	 */
	public String updateSessionStatus(String sessionId, String status) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
		JSONObject params = new JSONObject();
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	/**
	 * 更新会话状态
	 *
	 * @param sessionId 会话ID
	 * @param status    状态
	 */
	public String updateTopicEvaluate(String sessionId, String status) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
		JSONObject params = new JSONObject();
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent) {
		String url = im_host + "api/v2/sessions/topic/" + topicId + "/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("topic_id", topicId);
		params.put("agent", agent);
		String response = HttpClientUtil.postBody(url, params);
		return response;
	}
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent,String patient_name,int patient_sex,int patient_age) {
		String url = im_host + "api/v2/sessions/topic/" + topicId + "/messages";
		JSONObject params = new JSONObject();
		params.put("sender_id", from);
		params.put("sender_name", fromName);
		params.put("patient_name", patient_name);
		params.put("patient_sex", patient_sex);
		params.put("patient_age", patient_age);
		params.put("content_type", contentType);
		params.put("content", content);
		params.put("topic_id", topicId);
		params.put("agent", agent);
		String response = HttpClientUtil.postBody(url, params);
		return response;
	}
	/**
	 * 发送进入im消息
	 * IM: ParticipantUpdate:'/:session_id/participant/update'
	 *
	 * @param from
	 * @param sessionId
	 * @param topicId
	 * @return
	 */
	public String sendIntoTopicIM(String from, String sessionId, String topicId, String content, String intoUser, String intoUserName) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/into";
		JSONObject params = new JSONObject();
		params.put("sender_id", from);
		params.put("topic_id", topicId);
		params.put("into_user", intoUser);
		params.put("into_user_name", intoUserName);
		params.put("content", content);
		String response = HttpClientUtil.postBody(url, params);
		return response;
	}
	/**
	 * 更新会话成员(新增或删除)
	 * @param sessionId 会话id
	 * @param user 新增的成员id
	 * @param oldUserId  删除的成员id
	 */
	public String updateParticipant(String sessionId, String user,String oldUserId) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId );
		params.put("user_id", user );
		if(!StringUtils.isEmpty(oldUserId)){
			params.put("old_user_id", oldUserId);
		}
		return HttpClientUtil.postBody(imAddr, params);
	}
	/**
	 * 更新会话成员(新增或删除) 活跃成员
	 * @param sessionId 会话id
	 * @param user 新增的成员id
	 * @param oldUserId  删除的成员id
	 */
	public String updateParticipantNew(String sessionId, String user,String oldUserId) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/updateNew";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId );
		params.put("user_id", user );
		if(!StringUtils.isEmpty(oldUserId)){
			params.put("old_user_id", oldUserId);
		}
		return HttpClientUtil.postBody(imAddr, params);
	}
	/**
	 * 更新消息内容
	 * @param sessionId 会话id
	 * @param sessionType 会话类型
	 * @param msgId  消息id
	 * @param content  消息内容
	 */
	public String updateMessage(String sessionId, String sessionType,String msgId,String content) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages/"+ msgId +"/update";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId );
		params.put("session_type", sessionType );
		params.put("message_id", msgId );
		params.put("content", content );
		return HttpClientUtil.postBody(imAddr, params);
	}
	/**
	 * 结束议题
	 *
	 * @param topicId     议题ID
	 * @param endUser     结束人
	 * @param endUserName 结束人名字
	 * @param sessionId   会话ID
	 */
	public JSONObject endTopics(String sessionId, String endUser, String endUserName, String topicId) {
		String imAddr = im_host + "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 = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	/**
	 * 议题邀请人员
	 *
	 * @param user      结束人名字
	 * @param sessionId 会话ID
	 */
	public void updateTopicUser(String sessionId, String user) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participants/" + user;
		JSONObject params = new JSONObject();
		params.put("user", user + ":" + 0);
		HttpClientUtil.putBody(imAddr, params);
	}
	/**
	 * 创建议题
	 *
	 * @param topicId      议题ID
	 * @param topicName    议题名称
	 * @param participants 成员
	 */
	public JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
		String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
		JSONObject params = new JSONObject();
		params.put("topic_id", topicId);
		params.put("topic_name", topicName);
		params.put("participants", participants.toString());
		params.put("messages", messages.toString());
		params.put("session_id", sessionId);
		params.put("session_type", sessionType);
		String ret = HttpClientUtil.postBody(imAddr, params);
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	/**
	 * 判断会话是否存在
	 */
	public Boolean sessionIsExist(String sessionId) {
		Boolean re = false;
		String url = im_host + "api/v2/sessions/isExist?session_id="+sessionId;
		JSONObject params = new JSONObject();
		String ret = HttpClientUtil.get(url, "UTF-8");
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
			if(obj.getInteger("status") ==200&&sessionId.equals(obj.getString("sessionId"))){
				String sessionStatus = obj.getString("sessionId");
				if (StringUtils.isNoneBlank(sessionStatus)){
					String sessionStatusUrl = im_host + "api/v2/sessions/"+sessionId+"/status?status=0&sessionId="+sessionId;
					JSONObject object = new JSONObject();
					String rs = HttpClientUtil.postBody(sessionStatusUrl, object);
				}
				re = true;
			}
		} catch (Exception e) {
			return null;
		}
		return re;
	}
	public Integer sessionStatus(String sessionId) {
		String url = im_host + "api/v2/sessions/isExist?session_id="+sessionId;
		String ret = HttpClientUtil.get(url, "UTF-8");
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
			if(obj.getInteger("status") ==200&&sessionId.equals(obj.getString("sessionId"))){
				String session_id = obj.getString("sessionId");
				Integer sessionStatus = obj.getInteger("sessionStatus");
				return sessionStatus;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return null;
	}
	/**
	 * 创建会话(system)
	 */
	public static JSONObject createSession(JSONObject participants, String sessionType, String sessionName, String sessionId) {
        String response = com.yihu.jw.util.http.HttpClientUtil.postBodyStatic(imAddr, params);
        return response;
    }
    /**
     * 更新会话状态
     *
     * @param sessionId 会话ID
     * @param status    状态
     */
    public String updateSessionStatus(String sessionId, String status) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
        JSONObject params = new JSONObject();
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 更新会话状态
     *
     * @param sessionId 会话ID
     * @param status    状态
     */
    public String updateTopicEvaluate(String sessionId, String status) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
        JSONObject params = new JSONObject();
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent) {
        String url = im_host + "api/v2/sessions/topic/" + topicId + "/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("topic_id", topicId);
        params.put("agent", agent);
        String response = HttpClientUtil.postBody(url, params);
        return response;
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent, String patient_name, int patient_sex, int patient_age) {
        String url = im_host + "api/v2/sessions/topic/" + topicId + "/messages";
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("sender_name", fromName);
        params.put("patient_name", patient_name);
        params.put("patient_sex", patient_sex);
        params.put("patient_age", patient_age);
        params.put("content_type", contentType);
        params.put("content", content);
        params.put("topic_id", topicId);
        params.put("agent", agent);
        String response = HttpClientUtil.postBody(url, params);
        return response;
    }
    /**
     * 发送进入im消息
     * IM: ParticipantUpdate:'/:session_id/participant/update'
     *
     * @param from
     * @param sessionId
     * @param topicId
     * @return
     */
    public String sendIntoTopicIM(String from, String sessionId, String topicId, String content, String intoUser, String intoUserName) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/into";
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("topic_id", topicId);
        params.put("into_user", intoUser);
        params.put("into_user_name", intoUserName);
        params.put("content", content);
        String response = HttpClientUtil.postBody(url, params);
        return response;
    }
    /**
     * 更新会话成员(新增或删除)
     *
     * @param sessionId 会话id
     * @param user      新增的成员id
     * @param oldUserId 删除的成员id
     */
    public String updateParticipant(String sessionId, String user, String oldUserId) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("user_id", user);
        if (!StringUtils.isEmpty(oldUserId)) {
            params.put("old_user_id", oldUserId);
        }
        return HttpClientUtil.postBody(imAddr, params);
    }
    /**
     * 更新会话成员(新增或删除) 活跃成员
     *
     * @param sessionId 会话id
     * @param user      新增的成员id
     * @param oldUserId 删除的成员id
     */
    public String updateParticipantNew(String sessionId, String user, String oldUserId) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/updateNew";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("user_id", user);
        if (!StringUtils.isEmpty(oldUserId)) {
            params.put("old_user_id", oldUserId);
        }
        return HttpClientUtil.postBody(imAddr, params);
    }
    /**
     * 更新消息内容
     *
     * @param sessionId   会话id
     * @param sessionType 会话类型
     * @param msgId       消息id
     * @param content     消息内容
     */
    public String updateMessage(String sessionId, String sessionType, String msgId, String content) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages/" + msgId + "/update";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
        params.put("session_type", sessionType);
        params.put("message_id", msgId);
        params.put("content", content);
        return HttpClientUtil.postBody(imAddr, params);
    }
    /**
     * 结束议题
     *
     * @param topicId     议题ID
     * @param endUser     结束人
     * @param endUserName 结束人名字
     * @param sessionId   会话ID
     */
    public JSONObject endTopics(String sessionId, String endUser, String endUserName, String topicId) {
        String imAddr = im_host + "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 = JSON.parseObject(ret);
        } catch (Exception e) {
            return null;
        }
        return obj;
    }
    /**
     * 议题邀请人员
     *
     * @param user      结束人名字
     * @param sessionId 会话ID
     */
    public void updateTopicUser(String sessionId, String user) {
        String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participants/" + user;
        JSONObject params = new JSONObject();
        params.put("user", user + ":" + 0);
        HttpClientUtil.putBody(imAddr, params);
    }
    /**
     * 创建议题
     *
     * @param topicId      议题ID
     * @param topicName    议题名称
     * @param participants 成员
     */
    public JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
        JSONObject obj = new JSONObject();
        try {
            String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
            JSONObject params = new JSONObject();
            params.put("topic_id", topicId);
            params.put("topic_name", topicName);
            params.put("participants", participants.toString());
            params.put("messages", messages.toString());
            params.put("session_id", sessionId);
            params.put("session_type", sessionType);
            String ret = HttpClientUtil.postBody(imAddr, params);
            obj = JSON.parseObject(ret);
            return obj;
        } catch (Exception e) {
            System.out.println("创建议题失败:topicId=>" + topicId);
            return null;
        }
    }
    /**
     * 判断会话是否存在
     */
    public Boolean sessionIsExist(String sessionId) {
        Boolean re = false;
        String url = im_host + "api/v2/sessions/isExist?session_id=" + sessionId;
        JSONObject params = new JSONObject();
        String ret = HttpClientUtil.get(url, "UTF-8");
        JSONObject obj = null;
        try {
            obj = JSON.parseObject(ret);
            if (obj.getInteger("status") == 200 && sessionId.equals(obj.getString("sessionId"))) {
                String sessionStatus = obj.getString("sessionId");
                if (StringUtils.isNoneBlank(sessionStatus)) {
                    String sessionStatusUrl = im_host + "api/v2/sessions/" + sessionId + "/status?status=0&sessionId=" + sessionId;
                    JSONObject object = new JSONObject();
                    String rs = HttpClientUtil.postBody(sessionStatusUrl, object);
                }
                re = true;
            }
        } catch (Exception e) {
            return null;
        }
        return re;
    }
    public Integer sessionStatus(String sessionId) {
        String url = im_host + "api/v2/sessions/isExist?session_id=" + sessionId;
        String ret = HttpClientUtil.get(url, "UTF-8");
        JSONObject obj = null;
        try {
            obj = JSON.parseObject(ret);
            if (obj.getInteger("status") == 200 && sessionId.equals(obj.getString("sessionId"))) {
                String session_id = obj.getString("sessionId");
                Integer sessionStatus = obj.getInteger("sessionStatus");
                return sessionStatus;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return null;
    }
    /**
     * 创建会话(system)
     */
    public static JSONObject createSession(JSONObject participants, String sessionType, String sessionName, String sessionId) {
//		String imAddr = im_host + "api/v2/sessions";
		String imAddr = ImService.im_host + "/sessions";
		JSONObject params = new JSONObject();
		params.put("participants", participants.toString());
		params.put("session_name", sessionName);
		params.put("session_type", sessionType);
		params.put("session_id", sessionId);
        String imAddr = ImService.im_host + "/sessions";
        JSONObject params = new JSONObject();
        params.put("participants", participants.toString());
        params.put("session_name", sessionName);
        params.put("session_type", sessionType);
        params.put("session_id", sessionId);
//		String ret = HttpClientUtil.postBody(imAddr, params);
		String ret = com.yihu.jw.util.http.HttpClientUtil.postBodyStatic(imAddr, params);
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	/**
	 * 获取会话实例的消息对象
	 *
	 * @param senderId
	 * @param senderName
	 * @param title
	 * @param description
	 * @param images
	 * @param agent
	 * @return
	 */
	public JSONObject getCreateTopicMessage(String senderId, String senderName, String title, String description, String images, String agent) {
		JSONObject messages = new JSONObject();
		messages.put("description", description);
		messages.put("title", title);
		messages.put("img", images);
		messages.put("sender_id", senderId);
		messages.put("sender_name", senderName);
		messages.put("agent", agent);
		return messages;
	}
	public JSONObject getTopicMessage(String topicId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
		String url = im_host
				+ "api/v2/sessions/topic/" + topicId + "/messages?topic_id=" + topicId + "&end=" + startMsgId
				+ "&start=" + (endMsgId == null ? "" : endMsgId) + "&page=" + page + "&pagesize=" + pagesize + "&user=" + uid;
		try {
			String ret = HttpClientUtil.get(url, "UTF-8");
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException(obj.getString("message"));
			} else {
				return obj.getJSONObject("data");
			}
		} catch (Exception e) {
			return null;
		}
	}
	public JSONArray getSessionMessage(String sessionId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/messages?session_id=" + sessionId + "&user=" + uid + "&start_message_id=" + startMsgId + "&end_message_id=" + endMsgId + "&page=" + page + "&pagesize=" + pagesize;
		try {
			String ret = HttpClientUtil.get(url, "UTF-8");
			JSONArray obj = JSON.parseArray(ret);
			return obj;
		} catch (Exception e) {
			return null;
		}
	}
	/**
	 * 删除对应的成员信息在MUC模式中
	 *
	 * @param userId
	 * @param oldUserId
	 * @param sessionId
	 * @return
	 */
	public JSONObject deleteMucUser(String userId, String oldUserId, String sessionId) throws Exception {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
		try {
			JSONObject params = new JSONObject();
			params.put("user_id", userId);
			params.put("old_user_id", oldUserId);
			params.put("session_id", sessionId);
			String ret = HttpClientUtil.postBody(url, params);
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException("人员更换失败!");
			} else {
				return obj;
			}
		} catch (Exception e) {
			throw new RuntimeException("人员更换失败!");
		}
	}
	/**
	 * 删除会话人员
	 * @param sessionId
	 * @param participants
	 * @return
	 */
	public JSONObject deleteParticipants(String sessionId,String participants){
		String url  = im_host+"api/v2/sessions/"+sessionId+"/participants/"+participants;
		String rs = com.yihu.jw.util.http.HttpClientUtil.doDelete(url,null,null);
		JSONObject obj = JSONObject.parseObject(rs);
		if (obj.getInteger("status")==-1){
			throw new RuntimeException("删除会话人员失败!");
		}else {
			return obj;
		}
	}
	/**
	 * 获取议题
	 *
	 * @param topicId
	 * @return
	 */
	public JSONObject getTopic(String topicId) throws Exception {
		String url = im_host + "api/v2/sessions/topics/" + topicId + "?topic_id=" + topicId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException("获取议题失败!");
			} else {
				return obj;
			}
		} catch (Exception e) {
			throw new RuntimeException("获取议题失败!");
		}
	}
	/**
	 * 获取会话成员
	 *
	 * @param sessionId
	 * @return
	 * @throws Exception
	 */
	public JSONArray getParticipants(String sessionId) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			return JSON.parseArray(ret);
		} catch (Exception e) {
			throw new RuntimeException("获取会话成员!sessionId =" + sessionId);
		}
	}
	/**
	 * 获取会话成员
	 *
	 * @param sessionId
	 * @return
	 * @throws Exception
	 */
	public JSONArray getSessions(String sessionId) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			return JSON.parseArray(ret);
		} catch (Exception e) {
			throw new RuntimeException("获取议题失败!");
		}
	}
	public JSONObject cleanMessageToRedis(String sessionId){
		String url = im_host + "api/v2/message/dataMessage?sessionId="+sessionId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	public JSONObject cleanMessageLastFetchTime(String sessionId,String userId){
		String url = im_host + "api/v2/message/cleanMessageLastFetchTimeToRedis?sessionId="+sessionId+"&userId="+userId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	/**
	 * 根据session和userid获取单个会话
	 * @param sessionId
	 * @param userId
	 * @return
	 */
	public JSONObject getSingleSessionInfo(String sessionId,String userId){
		String url = im_host + "api/v2/sessions/" + sessionId + "/session?user_id=" + userId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param to
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendIM(String from, String to, String contentType, String content) {
		String imAddr = im_host + "api/v1/chats/pm";
		List<NameValuePair> params = new ArrayList<>();
		params.add(new BasicNameValuePair("from", from));
		params.add(new BasicNameValuePair("to", to));
		params.add(new BasicNameValuePair("contentType", contentType));
		params.add(new BasicNameValuePair("content", content));
		String response = HttpClientUtil.post(imAddr, params, "UTF-8");
		return response;
	}
	public static final String SESSION_TYPE_MUC = "1";
	public static final String SESSION_TYPE_P2P = "2";
	public static final String SESSION_TYPE_GROUP = "3";
	public static final String SESSION_TYPE_SYSTEM = "0";
	public static final String SESSION_TYPE_PRESCRIPTION = "8";//续方
	public static final String SESSION_TYPE_KANGFU = "18";//续方
	public static final String SESSION_TYPE_EXAMINATION = "9";//在线复诊-图文
	public static final String SESSION_TYPE_ONDOOR_NURSING = "11";//上门护理
	public static final String SESSION_TYPE_COLLABORATION_HOSPITAL = "12";///互联网医院协同门诊
	public static final String SESSION_TYPE_GUIDANCE_HOSPITAL = "14";//互联网医院居民导诊聊天
	public static final String SESSION_TYPE_GENERAL_EXPERT = "15";//全科医生发起求助专科医生的专家咨询
	public static final String SESSION_TYPE_EXAMINATION_VIDEO = "16";//在线复诊-视频
	public static final String SESSION_TYPE_MUC_VIDEO = "17";//专家-视频
	public static final String SESSION_TYPE_GUIDANCE_ASSISTANT = "18";//导诊助手
	public static final String SESSION_STATUS_PROCEEDINGS = "0";
	public static final String SESSION_STATUS_END = "1";
	public static final String SESSION_TYPE_EMERGENCY_ASSISTANCE = "20";//紧急救助
	public static final String SESSION_TYPE_DOOR_COACH = "21";//上门辅导(上门预约)
	public static final String SESSION_TYPE_SECURITY_WARN = "22";//安防咨询
	public static final String SESSION_TYPE_ONLINE = "23";//新生儿在线咨询
	public static final String SESSION_TYPE_ONLINEAged = "24";//老人在线咨询
	public static final String SESSION_TYPE_HealthConsult = "25";//老人在线咨询
	public static final String CONTENT_TYPE_TEXT = "1";
	/**
	 *按会话类型获取会话总数
	 * @param userid
	 * @param type
	 * @param status
	 * @return
	 */
	public Integer sessionCountByType(String userid,Integer type,Integer status){
		String url = im_host + "api/v2/sessions/sessionCountByType?user_id="+userid+"&type="+type+"&status="+status;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
		if(obj.getInteger("status") ==200){
			return obj.getInteger("count");
		}else{
			return 0;
		}
	}
	public Integer SessionsUnreadMessageCountByUserId(String userid){
		String url = im_host + "api/v2/sessions/unread_message_count?user_id="+userid;
        String ret = com.yihu.jw.util.http.HttpClientUtil.postBodyStatic(imAddr, params);
        JSONObject obj = null;
        try {
            obj = JSON.parseObject(ret);
        } catch (Exception e) {
            return null;
        }
        return obj;
    }
    /**
     * 获取会话实例的消息对象
     *
     * @param senderId
     * @param senderName
     * @param title
     * @param description
     * @param images
     * @param agent
     * @return
     */
    public JSONObject getCreateTopicMessage(String senderId, String senderName, String title, String description, String images, String agent) {
        JSONObject messages = new JSONObject();
        messages.put("description", description);
        messages.put("title", title);
        messages.put("img", images);
        messages.put("sender_id", senderId);
        messages.put("sender_name", senderName);
        messages.put("agent", agent);
        return messages;
    }
    public JSONObject getTopicMessage(String topicId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
        String url = im_host
                + "api/v2/sessions/topic/" + topicId + "/messages?topic_id=" + topicId + "&end=" + startMsgId
                + "&start=" + (endMsgId == null ? "" : endMsgId) + "&page=" + page + "&pagesize=" + pagesize + "&user=" + uid;
        try {
            String ret = HttpClientUtil.get(url, "UTF-8");
            JSONObject obj = JSON.parseObject(ret);
            if (obj.getInteger("status") == -1) {
                throw new RuntimeException(obj.getString("message"));
            } else {
                return obj.getJSONObject("data");
            }
        } catch (Exception e) {
            return null;
        }
    }
    public JSONArray getSessionMessage(String sessionId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/messages?session_id=" + sessionId + "&user=" + uid + "&start_message_id=" + startMsgId + "&end_message_id=" + endMsgId + "&page=" + page + "&pagesize=" + pagesize;
        try {
            String ret = HttpClientUtil.get(url, "UTF-8");
            JSONArray obj = JSON.parseArray(ret);
            return obj;
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 删除对应的成员信息在MUC模式中
     *
     * @param userId
     * @param oldUserId
     * @param sessionId
     * @return
     */
    public JSONObject deleteMucUser(String userId, String oldUserId, String sessionId) throws Exception {
        String url = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
        try {
            JSONObject params = new JSONObject();
            params.put("user_id", userId);
            params.put("old_user_id", oldUserId);
            params.put("session_id", sessionId);
            String ret = HttpClientUtil.postBody(url, params);
            JSONObject obj = JSON.parseObject(ret);
            if (obj.getInteger("status") == -1) {
                throw new RuntimeException("人员更换失败!");
            } else {
                return obj;
            }
        } catch (Exception e) {
            throw new RuntimeException("人员更换失败!");
        }
    }
    /**
     * 删除会话人员
     *
     * @param sessionId
     * @param participants
     * @return
     */
    public JSONObject deleteParticipants(String sessionId, String participants) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/participants/" + participants;
        String rs = com.yihu.jw.util.http.HttpClientUtil.doDelete(url, null, null);
        JSONObject obj = JSONObject.parseObject(rs);
        if (obj.getInteger("status") == -1) {
            throw new RuntimeException("删除会话人员失败!");
        } else {
            return obj;
        }
    }
    /**
     * 获取议题
     *
     * @param topicId
     * @return
     */
    public JSONObject getTopic(String topicId) throws Exception {
        String url = im_host + "api/v2/sessions/topics/" + topicId + "?topic_id=" + topicId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            JSONObject obj = JSON.parseObject(ret);
            if (obj.getInteger("status") == -1) {
                throw new RuntimeException("获取议题失败!");
            } else {
                return obj;
            }
        } catch (Exception e) {
            throw new RuntimeException("获取议题失败!");
        }
    }
    /**
     * 获取会话成员
     *
     * @param sessionId
     * @return
     * @throws Exception
     */
    public JSONArray getParticipants(String sessionId) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSON.parseArray(ret);
        } catch (Exception e) {
            throw new RuntimeException("获取会话成员!sessionId =" + sessionId);
        }
    }
    /**
     * 获取会话成员
     *
     * @param sessionId
     * @return
     * @throws Exception
     */
    public JSONArray getSessions(String sessionId) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSON.parseArray(ret);
        } catch (Exception e) {
            throw new RuntimeException("获取议题失败!");
        }
    }
    public JSONObject cleanMessageToRedis(String sessionId) {
        String url = im_host + "api/v2/message/dataMessage?sessionId=" + sessionId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSON.parseObject(ret);
        } catch (Exception e) {
            throw new RuntimeException("操作失败!");
        }
    }
    public JSONObject cleanMessageLastFetchTime(String sessionId, String userId) {
        String url = im_host + "api/v2/message/cleanMessageLastFetchTimeToRedis?sessionId=" + sessionId + "&userId=" + userId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSON.parseObject(ret);
        } catch (Exception e) {
            throw new RuntimeException("操作失败!");
        }
    }
    /**
     * 根据session和userid获取单个会话
     *
     * @param sessionId
     * @param userId
     * @return
     */
    public JSONObject getSingleSessionInfo(String sessionId, String userId) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/session?user_id=" + userId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSON.parseObject(ret);
        } catch (Exception e) {
            throw new RuntimeException("操作失败!");
        }
    }
    /**
     * 发送消息给IM
     *
     * @param from        来自
     * @param to
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public String sendIM(String from, String to, String contentType, String content) {
        String imAddr = im_host + "api/v1/chats/pm";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("from", from));
        params.add(new BasicNameValuePair("to", to));
        params.add(new BasicNameValuePair("contentType", contentType));
        params.add(new BasicNameValuePair("content", content));
        String response = HttpClientUtil.post(imAddr, params, "UTF-8");
        return response;
    }
    public static final String SESSION_TYPE_MUC = "1";
    public static final String SESSION_TYPE_P2P = "2";
    public static final String SESSION_TYPE_GROUP = "3";
    public static final String SESSION_TYPE_SYSTEM = "0";
    public static final String SESSION_TYPE_PRESCRIPTION = "8";//续方
    public static final String SESSION_TYPE_KANGFU = "18";//续方
    public static final String SESSION_TYPE_EXAMINATION = "9";//在线复诊-图文
    public static final String SESSION_TYPE_ONDOOR_NURSING = "11";//上门护理
    public static final String SESSION_TYPE_COLLABORATION_HOSPITAL = "12";///互联网医院协同门诊
    public static final String SESSION_TYPE_GUIDANCE_HOSPITAL = "14";//互联网医院居民导诊聊天
    public static final String SESSION_TYPE_GENERAL_EXPERT = "15";//全科医生发起求助专科医生的专家咨询
    public static final String SESSION_TYPE_EXAMINATION_VIDEO = "16";//在线复诊-视频
    public static final String SESSION_TYPE_MUC_VIDEO = "17";//专家-视频
    public static final String SESSION_TYPE_GUIDANCE_ASSISTANT = "18";//导诊助手
    public static final String SESSION_STATUS_PROCEEDINGS = "0";
    public static final String SESSION_STATUS_END = "1";
    public static final String SESSION_TYPE_EMERGENCY_ASSISTANCE = "20";//紧急救助
    public static final String SESSION_TYPE_DOOR_COACH = "21";//上门辅导(上门预约)
    public static final String SESSION_TYPE_SECURITY_WARN = "22";//安防咨询
    public static final String SESSION_TYPE_ONLINE = "23";//新生儿在线咨询
    public static final String SESSION_TYPE_ONLINEAged = "24";//老人在线咨询
    public static final String SESSION_TYPE_HealthConsult = "25";//老人在线咨询
    public static final String CONTENT_TYPE_TEXT = "1";
    /**
     * 按会话类型获取会话总数
     *
     * @param userid
     * @param type
     * @param status
     * @return
     */
    public Integer sessionCountByType(String userid, Integer type, Integer status) {
        String url = im_host + "api/v2/sessions/sessionCountByType?user_id=" + userid + "&type=" + type + "&status=" + status;
        String ret = HttpClientUtil.get(url, "utf-8");
        JSONObject obj = JSON.parseObject(ret);
        if (obj.getInteger("status") == 200) {
            return obj.getInteger("count");
        } else {
            return 0;
        }
    }
    public Integer SessionsUnreadMessageCountByUserId(String userid) {
        String url = im_host + "api/v2/sessions/unread_message_count?user_id=" + userid;
//		String url = "http://ehr.yihu.com/api/v2/sessions/unread_message_count?user_id="+userid;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
        String ret = HttpClientUtil.get(url, "utf-8");
        JSONObject obj = JSON.parseObject(ret);
//		if(obj.getInteger("count") ==200){
		return obj.getInteger("count");
        return obj.getInteger("count");
//		}else{
//			return 0;
//		}
	}
	/**
	 *获取所有会话未读消息数。
	 * @param userid
	 * @param type
	 * @return
	 */
	public Integer SessionsUnreadMessageCount(String userid,String type){
		String url = im_host + "api/v2/sessions/unread_message_count?user_id="+userid+"&type="+type;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
    }
    /**
     * 获取所有会话未读消息数。
     *
     * @param userid
     * @param type
     * @return
     */
    public Integer SessionsUnreadMessageCount(String userid, String type) {
        String url = im_host + "api/v2/sessions/unread_message_count?user_id=" + userid + "&type=" + type;
        String ret = HttpClientUtil.get(url, "utf-8");
        JSONObject obj = JSON.parseObject(ret);
//		if(obj.getInteger("count") ==200){
		return obj.getInteger("count");
        return obj.getInteger("count");
//		}else{
//			return 0;
//		}
	}
	/**
	 *获取某个会话某个对象的未读消息数。
	 * @param
	 * @return
	 */
	public Integer UserSessionsUnreadMessageCount(String session,String userid){
		String url = im_host + "api/v2/sessions/"+session+"/unread_message_count?user_id="+userid;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
    }
    /**
     * 获取某个会话某个对象的未读消息数。
     *
     * @param
     * @return
     */
    public Integer UserSessionsUnreadMessageCount(String session, String userid) {
        String url = im_host + "api/v2/sessions/" + session + "/unread_message_count?user_id=" + userid;
        String ret = HttpClientUtil.get(url, "utf-8");
        JSONObject obj = JSON.parseObject(ret);
//		if(obj.getInteger("count") ==200){
		return obj.getInteger("count");
        return obj.getInteger("count");
//		}else{
//			return 0;
//		}
	}
	/**
	 * 获取会话未读消息数量
	 * @param sessionId
	 * @param userId
	 * @return
	 */
	public JSONObject getSessionUnreadMessageCount(String sessionId, String userId) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/unread_message_count?user_id=" + userId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			return  JSONObject.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("获取会话成员!sessionId =" + sessionId);
		}
	}
	/**
	 * 获取在线人数
	 * helper 社工,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
	 */
	public String getOnlineCountByType(String type) {
		String url = im_host + "api/v2/sessions/getOnlineCountByType?type="+type;
		String ret = HttpClientUtil.get(url, "UTF-8");
		return ret;
	}
	/**
	 * 获取在线人数列表
	 * helper 社工,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
	 */
	public String getOnlineListByType(String type) {
		String url = im_host + "api/v2/sessions/getOnlineListByType?type="+type;
		String ret = HttpClientUtil.get(url, "UTF-8");
		return ret;
	}
	/**
	 * 获取在线状态
	 * helper 社工,teacher 教师,child 幼儿,older 老人
	 * 返回 {"status":200,"data":1} data>0 说明在线 data =0 不在线
	 */
	public String findByUserIdAndType(String userId,String type) {
		String url = im_host + "api/v2/sessions/findByUserIdAndType?userId="+userId+"&type="+type;
		String ret = HttpClientUtil.get(url, "UTF-8");
		return ret;
	}
	/**
	 *按会话类型、会话状态获取会话列表
	 * @param user_id
	 * @param page
	 * @param size
	 * @param type
	 * @param status 不传为获取所有状态
	 * @param name
	 * @param search_type 仅当type为2时有效 1与医生p2p会话 2与患者p2p
	 * @return
	 */
	public String getSessionListByType(String user_id, String page, String size, String type, String status, String name,String search_type){
		String url = im_host + "api/v2/sessions/sessionListByType?user_id="+user_id+"&page="+page+"&size="+size+"&type="+type+"&status="+(status==null?"":status)+"&name="+(name==null?"":name)+"&search_type="+(search_type==null?"":search_type);
		String ret = HttpClientUtil.get(url, "utf-8");
		return ret;
	}
    }
    /**
     * 获取会话未读消息数量
     *
     * @param sessionId
     * @param userId
     * @return
     */
    public JSONObject getSessionUnreadMessageCount(String sessionId, String userId) {
        String url = im_host + "api/v2/sessions/" + sessionId + "/unread_message_count?user_id=" + userId;
        try {
            String ret = HttpClientUtil.get(url, "utf-8");
            return JSONObject.parseObject(ret);
        } catch (Exception e) {
            throw new RuntimeException("获取会话成员!sessionId =" + sessionId);
        }
    }
    /**
     * 获取在线人数
     * helper 社工,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
     */
    public String getOnlineCountByType(String type) {
        String url = im_host + "api/v2/sessions/getOnlineCountByType?type=" + type;
        String ret = HttpClientUtil.get(url, "UTF-8");
        return ret;
    }
    /**
     * 获取在线人数列表
     * helper 社工,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
     */
    public String getOnlineListByType(String type) {
        String url = im_host + "api/v2/sessions/getOnlineListByType?type=" + type;
        String ret = HttpClientUtil.get(url, "UTF-8");
        return ret;
    }
    /**
     * 获取在线状态
     * helper 社工,teacher 教师,child 幼儿,older 老人
     * 返回 {"status":200,"data":1} data>0 说明在线 data =0 不在线
     */
    public String findByUserIdAndType(String userId, String type) {
        String url = im_host + "api/v2/sessions/findByUserIdAndType?userId=" + userId + "&type=" + type;
        String ret = HttpClientUtil.get(url, "UTF-8");
        return ret;
    }
    /**
     * 按会话类型、会话状态获取会话列表
     *
     * @param user_id
     * @param page
     * @param size
     * @param type
     * @param status      不传为获取所有状态
     * @param name
     * @param search_type 仅当type为2时有效 1与医生p2p会话 2与患者p2p
     * @return
     */
    public String getSessionListByType(String user_id, String page, String size, String type, String status, String name, String search_type) {
        String url = im_host + "api/v2/sessions/sessionListByType?user_id=" + user_id + "&page=" + page + "&size=" + size + "&type=" + type + "&status=" + (status == null ? "" : status) + "&name=" + (name == null ? "" : name) + "&search_type=" + (search_type == null ? "" : search_type);
        String ret = HttpClientUtil.get(url, "utf-8");
        return ret;
    }
}

+ 12 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/qvo/ParamQvo.java

@ -22,12 +22,23 @@ public class ParamQvo {
    private String dictItemId;//字典服务项id
    private String configureIf;//是否是配置
    private String pageIf;//是否分页
    private int page = 1;//是否分页
    private int pageSize = 20;//数量
    private String loginUserCode;//登录人的code
    public String getLoginUserCode() {
        return loginUserCode;
    }
    public void setLoginUserCode(String loginUserCode) {
        this.loginUserCode = loginUserCode;
    }
    public String getDictItemId() {
        return dictItemId;
    }

+ 7 - 11
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultService.java

@ -20,10 +20,10 @@ import java.util.UUID;
public class ConsultService {
	@Autowired
	public ConsultOrderDao consultDao;
    @Autowired
    public ConsultOrderDao consultDao;
//    @Autowired
    //    @Autowired
//    public BasePatientDao patientDao;
    @Autowired
    public BaseDoctorDao doctorDao;
@ -32,7 +32,7 @@ public class ConsultService {
    @Autowired
    private ImUtil imUtill;
//    @Value("${hlwyy.url}")
    //    @Value("${hlwyy.url}")
//    private String hlwyyUrl;
//    @Value("${im.data_base_name}")
////    private String ImDbName;
@ -67,10 +67,11 @@ public class ConsultService {
     * @param type    咨询类型:1三师咨询,2视频咨询,3图文咨询,4公共咨询,5病友圈,9在线复诊,11上门服务
     * @return
     */
    public ConsultDo addConsult(String patient, String title, String symptoms, String images, int type) {
    public ConsultDo addConsult(
            String patient, String title, String symptoms, String images, int type
    ) throws Exception {
        ConsultDo consult = new ConsultDo();
        consult.setCode(UUID.randomUUID().toString().replaceAll("-", ""));//UUID
        consult.setCzrq(new Date());
        consult.setDel("1");
        consult.setPatient(patient);
@ -78,11 +79,6 @@ public class ConsultService {
        consult.setSymptoms(symptoms);
        consult.setImages(images);
        consult.setType(type);
        //这边是没有签约
//		SignFamily signFamily = signFamilyDao.findByPatient(patient);
//		if(signFamily!=null){
//			consult.setSignCode(signFamily.getCode());
//		}
        return consultDao.save(consult);
    }

+ 25 - 47
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultTeamService.java

@ -68,12 +68,12 @@ public class ConsultTeamService extends ConsultService {
    private ConsultTeamLogDao consultTeamLogDao;
    @Autowired
    private ConsultTeamDoctorDao consultTeamDoctorDao;
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
   
    @Autowired
    private MessageDao messageDao;
    @Autowired
@ -81,7 +81,7 @@ public class ConsultTeamService extends ConsultService {
    @Autowired
    private BasePatientDao patientDao;
    
    @Autowired
    private PrescriptionLogService prescriptionLogService;
    @Autowired
@ -89,17 +89,16 @@ public class ConsultTeamService extends ConsultService {
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    
    
    @Autowired
    private WeiXinAccessTokenUtils accessTokenUtils;
    
    @Autowired
    private BasePatientService patientService;
   
    @Autowired
    private MessageService messageService;
  
    @Autowired
    private PrescriptionExpressageDao expressageDao;
    @Autowired
@ -108,13 +107,13 @@ public class ConsultTeamService extends ConsultService {
    private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
    @Autowired
    private WlyyDoorServiceOrderService wlyyDoorServiceOrderService;
    
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    
    Map<Integer, String> relations = new HashMap<>();
    @Value("${im.im_list_get}")
    private String im_list_get;
@ -122,10 +121,10 @@ public class ConsultTeamService extends ConsultService {
    private String imdb;
    @Autowired
    private PushMsgTask pushMsgTask;
    
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    
    @Autowired
    private ImUtil imUtill;
@ -180,7 +179,6 @@ public class ConsultTeamService extends ConsultService {
//    private ZyDictService zyDictService;
    /**
     * 添加上门服务咨询
     */
@ -194,27 +192,15 @@ public class ConsultTeamService extends ConsultService {
        String doctorName = doorServiceOrderDO.getDispatcherName();
        int orderStatus = doorServiceOrderDO.getStatus();
//        // 判断居民是否已经签约
//        SignFamily signFamily = signFamilyDao.findByPatient(patient);
//        if (signFamily == null) {
//            result.put(ResponseContant.resultFlag, ResponseContant.fail);
//            String failMsg = "当前居民未签约,无法进行上门服务咨询!";
//            result.put(ResponseContant.resultMsg, failMsg);
//            return result;
//        }
        // 添加咨询记录
        //添加咨询记录
        BasePatientDO patientDO = patientService.findPatientById(patient);
        if (null == patientDO) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前咨询的居民不存在!";
            result.put(ResponseContant.resultMsg, failMsg);
            return result;
            throw new Exception("当前居民不存在");
        }
        //咨询记录
        String title = patientDO.getName() + "-发起了服务咨询";
        ConsultDo consult = super.addConsult(patient, title, doorServiceOrderDO.getServeDesc(), patientDO.getPhone(), 11);
        ConsultDo consult = addConsult(patient, title, doorServiceOrderDO.getServeDesc(), patientDO.getPhone(), 11);
        //咨询详细信息
        ConsultTeamDo consultTeam = new ConsultTeamDo();
@ -243,22 +229,21 @@ public class ConsultTeamService extends ConsultService {
        participants.put(patient, 0);
//        String content = patientDO.getName() + "-上门服务咨询";
//        String content = signFamily.getHospitalName() + "为您服务";
        String content = doorServiceOrderDO.getDoctorName() + "为您服务";
        JSONObject messages = imUtill.getCreateTopicMessage(patient, patientDO.getName(), consult.getTitle(), content, consult.getImages(), "");
        //这边应该是要抛出异常比较合适
        JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getCode(), content, participants, messages, ImUtil.SESSION_TYPE_ONDOOR_NURSING);
        JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getCode(), content, participants, messages, imUtill.SESSION_TYPE_ONDOOR_NURSING);
        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
            result.put(ResponseContant.resultFlag, ResponseContant.success);
            result.put(ResponseContant.resultMsg, failMsg);
            return result;
//        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
//            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
//            result.put(ResponseContant.resultFlag, ResponseContant.success);
//            result.put(ResponseContant.resultMsg, failMsg);
//            return result;
//        }
        if (imResponseJson != null && imResponseJson.get("start_msg_id") != null) {
            consultTeam.setStartMsgId(imResponseJson.get("start_msg_id").toString());
        }
        consultTeam.setStartMsgId(imResponseJson.get("start_msg_id").toString());
        consultTeamDao.save(consultTeam);
        consultDao.save(consult);
@ -267,7 +252,6 @@ public class ConsultTeamService extends ConsultService {
        return result;
    }
    
//    @PostConstruct
//    public void init() {
@ -547,7 +531,7 @@ public class ConsultTeamService extends ConsultService {
     * 医生主动发送im消息
     */
    public void doctorSendImMsg(String patient, String doctor, String doctorName, String sessionId, String content, String contentType) {
        BasePatientDO  p = patientDao.findById(patient).orElse(null);
        BasePatientDO p = patientDao.findById(patient).orElse(null);
        if (StringUtils.isNotBlank(p.getOpenid())) {
            WechatTemplateConfig temp = templateConfigDao.findByScene("template_consult_notice", "yszdxx");
            org.json.JSONObject json = new org.json.JSONObject();
@ -1857,7 +1841,6 @@ public class ConsultTeamService extends ConsultService {
//
//        return prescription;
//    }
    public String getZyCommonDictName(String code) {
        try {
            String sql = "SELECT t.name FROM zy_common_dict t WHERE t.code=? AND t.dict_name='IV_RECIPE_FREQUENCY_DICT'";
@ -2194,7 +2177,6 @@ public class ConsultTeamService extends ConsultService {
//    public int cancel(String consult) {
//        return consultTeamDao.cancel(consult);
//    }
    public ConsultTeamDo findByCode(String code) {
        return consultTeamDao.findByConsult(code);
    }
@ -2306,7 +2288,6 @@ public class ConsultTeamService extends ConsultService {
//
//        return consultDao.findByPatient(patientCode, doctorCode);
//    }
    public List<Map<String, Object>> getConsultSign(String[] consults) {
        String params = "";
        List<String> paramList = new ArrayList<>();
@ -2402,7 +2383,6 @@ public class ConsultTeamService extends ConsultService {
//        sf.append(sf1);
//        return sf.toString();
//    }
    public void save(ConsultTeamDo consult) {
        consultTeamDao.save(consult);
    }
@ -3346,8 +3326,6 @@ public class ConsultTeamService extends ConsultService {
//    }
    /**
     * 根据关联业务code查询咨询记录 wlyyDoorServiceOrderService.queryOneDetail(consult.getRelationCode());
     */

+ 87 - 66
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/DoorOrderController.java

@ -1,3 +1,6 @@
package com.yihu.jw.hospital.module.door.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.door.WlyyDoorConclusionDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
@ -7,6 +10,7 @@ import com.yihu.jw.hospital.module.door.service.DoorOrderService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorPrescriptionService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
@ -28,6 +32,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@ -40,7 +45,7 @@ import java.util.Map;
 */
@RestController
@RequestMapping(value = "/doctor/serviceOrder", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-思明区上门服务")
@Api(value = "医生端-上门服务")
public class DoorOrderController extends EnvelopRestEndpoint {
    @Autowired
@ -71,6 +76,87 @@ public class DoorOrderController extends EnvelopRestEndpoint {
//    private HospitalService hospitalService;
    /**
     * 获取登录医生的信息
     */
    @GetMapping(value = "getDoctorInfo")
    @ApiOperation(value = "获取登录医生的信息")
    public Envelop getDoctorInfo(
            @ApiParam(name = "jsonStr", value = "jsonStr", required = true) @RequestParam String jsonStr
    ) {
        try {
            jsonStr = URLDecoder.decode(jsonStr, "UTF-8");
            ParamQvo qvo = JSON.parseObject(jsonStr, ParamQvo.class);
            System.out.println("参数:" + JSON.toJSONString(qvo));
            JSONObject result = wlyyDoorServiceOrderService.getDoctorInfo(qvo);
            return success("查询成功!", result);
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = "queryDoctorList")
    @ApiOperation(value = "服务人员列表(医生列表)")
    public Envelop queryDoctorList(
            @ApiParam(name = "town", value = "调度员所在的机构code") @RequestParam(value = "town", required = true) String town,
            @ApiParam(name = "doctorName", value = "医生姓名") @RequestParam(value = "doctorName", required = false) String doctorName,
            @ApiParam(name = "status", value = "医生接单状态,状态为全部时不传") @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "patient", value = "居民code") @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        try {
            JSONObject result = wlyyDoorServiceOrderService.queryDoctorList(patient, town, doctorName, status, page, size);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
            }
            int count = result.getIntValue(ResponseContant.count);
            JSONObject object = new JSONObject();
            object.put("total", count);
            if (count > 0) {
                object.put("detailModelList", result.get(ResponseContant.resultMsg));
            } else {
                List list = new ArrayList();
                object.put("detailModelList", list);
            }
            object.put("currPage", page);
            object.put("pageSize", size);
            return success("查询成功", object);
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = "queryBriefList")
    @ApiOperation(value = "调度员查询工单列表")
    public Envelop queryBriefList(
            @ApiParam(name = "dispatcher", value = "调度员code") @RequestParam(value = "dispatcher", required = true) String dispatcher,
            @ApiParam(name = "hospital", value = "调度员所在机构code") @RequestParam(value = "hospital", required = true) String hospital,
            @ApiParam(name = "orderNumber", value = "工单号") @RequestParam(value = "orderNumber", required = false) String orderNumber,
            @ApiParam(name = "patientName", value = "工单服务对象姓名") @RequestParam(value = "patientName", required = false) String patientName,
            @ApiParam(name = "phone", value = "发起工单的居民的联系方式") @RequestParam(value = "phone", required = false) String phone,
            @ApiParam(name = "status", value = "工单状态") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(name = "patientType", value = "居民类型") @RequestParam(value = "patientType", required = false) String patientType,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        try {
            JSONObject result = wlyyDoorServiceOrderService.queryBriefList(dispatcher, hospital, orderNumber, patientName, phone, status, patientType, page, size);
            int count = result.getIntValue(ResponseContant.count);
            JSONObject object = new JSONObject();
            object.put("total", count);
            object.put("detailModelList", result.get(ResponseContant.resultMsg));
            object.put("currPage", page);
            object.put("pageSize", size);
            return success("查询成功", object);
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @PostMapping(value = "proxyCreate")
    @ApiOperation(value = "创建上门服务咨询--医生代预约")
    public Envelop create(
@ -143,7 +229,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
            @ApiParam(value = "工单状态", name = "status", required = false) @RequestParam(value = "status", required = false) Integer[] status,
            //1.6.8.6版本,创建时间修改为服务时间
            @ApiParam(value = "创建时间开始,格式(yyyy-MM-dd mm:dd:ss)", name = "createTimeStart", required = false) @RequestParam(value = "createTimeStart", required = false) String createTimeStart,
            //1.6.8.6版本,创建时间修改为服务时间
            @ApiParam(value = "创建时间结束,格式(yyyy-MM-dd mm:dd:ss)", name = "createTimeEnd", required = false) @RequestParam(value = "createTimeEnd", required = false) String createTimeEnd,
            @ApiParam(value = "服务医生的名称", name = "serverDoctorName", required = false)
            @RequestParam(value = "serverDoctorName", required = false) String serverDoctorName, @ApiParam(value = "医生的code", name = "doctorCode", required = false)
@ -580,7 +665,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
    @PostMapping("updateDoctorInfo")
    @ApiOperation(value = "修改保存服务医生")
    public Envelop updateDoctorInfo(
            @ApiParam(value = "jsonData", name = "jsonData")
            @RequestParam(value = "jsonData", required = false) String jsonData) {
@ -714,69 +798,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
//        }
//    }
    @GetMapping(value = "queryBriefList")
    @ApiOperation(value = "调度员查询工单列表")
    public Envelop queryBriefList(
            @ApiParam(name = "dispatcher", value = "调度员code") @RequestParam(value = "dispatcher", required = true) String dispatcher,
            @ApiParam(name = "hospital", value = "调度员所在机构code") @RequestParam(value = "hospital", required = true) String hospital,
            @ApiParam(name = "orderNumber", value = "工单号") @RequestParam(value = "orderNumber", required = false) String orderNumber,
            @ApiParam(name = "patientName", value = "工单服务对象姓名") @RequestParam(value = "patientName", required = false) String patientName,
            @ApiParam(name = "phone", value = "发起工单的居民的联系方式") @RequestParam(value = "phone", required = false) String phone,
            @ApiParam(name = "status", value = "工单状态") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(name = "patientType", value = "居民类型") @RequestParam(value = "patientType", required = false) String patientType,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        try {
            JSONObject result = wlyyDoorServiceOrderService.queryBriefList(dispatcher, hospital, orderNumber, patientName, phone, status, patientType, page, size);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
            }
            int count = result.getIntValue(ResponseContant.count);
            JSONObject object = new JSONObject();
            object.put("total", count);
            object.put("detailModelList", result.get(ResponseContant.resultMsg));
            object.put("currPage", page);
            object.put("pageSize", size);
            return success("查询成功", object);
        } catch (RuntimeException se) {
            return failed(se.getMessage());
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = "queryDoctorList")
    @ApiOperation(value = "服务人员列表(医生列表)")
    public Envelop queryDoctorList(
            @ApiParam(name = "town", value = "调度员所在的机构code") @RequestParam(value = "town", required = true) String town,
            @ApiParam(name = "doctorName", value = "医生姓名") @RequestParam(value = "doctorName", required = false) String doctorName,
            @ApiParam(name = "status", value = "医生接单状态,状态为全部时不传") @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "patient", value = "居民code") @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        try {
            JSONObject result = wlyyDoorServiceOrderService.queryDoctorList(patient, town, doctorName, status, page, size);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
            }
            int count = result.getIntValue(ResponseContant.count);
            JSONObject object = new JSONObject();
            object.put("total", count);
            if (count > 0) {
                object.put("detailModelList", result.get(ResponseContant.resultMsg));
            } else {
                List list = new ArrayList();
                object.put("detailModelList", list);
            }
            object.put("currPage", page);
            object.put("pageSize", size);
            return success("查询成功", object);
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = "queryDoctorListNotStopped")
    @ApiOperation(value = "服务人员列表(可接单状态的医生列表)")

+ 10 - 9
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/WlyyDoorServiceOrderController.java

@ -15,6 +15,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.net.URLDecoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@ -56,17 +57,14 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
    @PostMapping(value = "create")
    @ApiOperation(value = "创建上门服务咨询")
    public Envelop create(@ApiParam(name = "jsonData", value = "Json数据", required = true) @RequestParam String jsonData) {
        JSONObject result = new JSONObject();
        try {
            result = wlyyDoorServiceOrderService.create(jsonData);
            jsonData = URLDecoder.decode(jsonData, "UTF-8");
            JSONObject result = wlyyDoorServiceOrderService.create(jsonData);
            return success(result.get(ResponseContant.resultMsg));
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
        if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
            return failed(result.getString(ResponseContant.resultMsg));
        }
        return success(result.get(ResponseContant.resultMsg));
    }
@ -270,9 +268,12 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
            @ApiParam(name = "doctorName", value = "医生姓名") @RequestParam(value = "doctorName") String doctorName,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1") @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15") @RequestParam(value = "size") int size) {
        JSONObject result = wlyyDoorServiceOrderService.queryDoctorList(getUID(), hospital, doctorName, null, page, size);
        if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
            return PageEnvelop.getError(result.getString(ResponseContant.resultMsg), -1);
        JSONObject result = null;
        try {
            result = wlyyDoorServiceOrderService.queryDoctorList(getUID(), hospital, doctorName, null, page, size);
        } catch (Exception e) {
            e.printStackTrace();
            return PageEnvelop.getError(e.getMessage());
        }
        int count = result.getIntValue(ResponseContant.count);
        return success((List) result.get(ResponseContant.resultMsg), count, page, size);

+ 121 - 212
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java

@ -24,6 +24,7 @@ import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
@ -67,12 +68,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    private Logger logger = LoggerFactory.getLogger(WlyyDoorServiceOrderService.class);
    @Value("${server.server_url}")
    private String wxServerUrl;
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
//    @Value("${server.server_url}")
//    private String wxServerUrl;
//    @Value("${doctorAssistant.api}")
//    private String doctorAssistant;
//    @Value("${doctorAssistant.target_url}")
//    private String targetUrl;
    @Autowired
@ -355,7 +356,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean orderWithPackageItemFeeAdd(JSONObject result, JSONObject jsonObjectParam, WlyyDoorServiceOrderDO order) {
    public boolean orderWithPackageItemFeeAdd(
            JSONObject result, JSONObject jsonObjectParam, WlyyDoorServiceOrderDO order
    ) throws Exception {
        List<WlyyDoorFeeDetailDO> feeDetailDOList = new ArrayList<>();
        List<WlyyDoorOrderItemDO> orderItemDOList = new ArrayList<>();
        BigDecimal totalFee = order.getTotalFee();
@ -366,34 +369,16 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        JSONArray packageItemArray = jsonObjectParam.getJSONArray("packageItemArr");
        if (!CollectionUtils.isEmpty(packageItemArray)) {
            for (Object one : packageItemArray) {
                WlyyDoorFeeDetailDO feeDetailDO = null;
                JSONObject oneJson = (JSONObject) one;
                try {
                    feeDetailDO = EntityUtils.jsonToEntity(one.toString(), WlyyDoorFeeDetailDO.class);
                    WlyyDoorOrderItemDO orderItemDO = new WlyyDoorOrderItemDO();
                    orderItemDO.setDoctor(order.getDoctor());
                    orderItemDO.setCode(feeDetailDO.getCode());
                    orderItemDO.setCreateTime(new Date());
                    orderItemDO.setPatient(orderItemDO.getPatient());
                    orderItemDOList.add(orderItemDO);
                } catch (Exception e) {
                    result.put(ResponseContant.resultFlag, ResponseContant.fail);
                    String failMsg = "工单与服务费用关联关系时," + e.getMessage();
                    result.put(ResponseContant.resultMsg, failMsg);
                    logger.error(failMsg);
                    return true;
                }
                try {
                    //工单主表中记录总费用
                    totalFee = totalFee.add(feeDetailDO.getFee().multiply(BigDecimal.valueOf(feeDetailDO.getNumber())));
                } catch (Exception e) {
                    result.put(ResponseContant.resultFlag, ResponseContant.fail);
                    String failMsg = "工单主表中记录总费用时," + e.getMessage();
                    result.put(ResponseContant.resultMsg, failMsg);
                    logger.error(failMsg);
                    return true;
                }
                WlyyDoorFeeDetailDO feeDetailDO = EntityUtils.jsonToEntity(one.toString(), WlyyDoorFeeDetailDO.class);
                WlyyDoorOrderItemDO orderItemDO = new WlyyDoorOrderItemDO();
                //工单主表中记录总费用
                totalFee = totalFee.add(feeDetailDO.getFee().multiply(BigDecimal.valueOf(feeDetailDO.getNumber())));
                //赋值
                orderItemDO.setDoctor(order.getDoctor());
                orderItemDO.setCode(feeDetailDO.getCode());
                orderItemDO.setCreateTime(new Date());
                orderItemDO.setPatient(orderItemDO.getPatient());
                orderItemDOList.add(orderItemDO);
                // 服务项可能一开始由居民预约,后期由医生新增或医生删除
                Integer status = jsonObjectParam.getInteger("status");
                if (null == status || status == 1) {
@ -401,7 +386,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                } else {
                    feeDetailDO.setStatus(status);
                }
//                feeDetailDO.setNumber(1);
                feeDetailDO.setOrderId(order.getId());
                if (StringUtils.isBlank(feeDetailDO.getId())) {
                    feeDetailDO.setCreateTime(new Date());
@ -410,24 +394,14 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                }
                feeDetailDOList.add(feeDetailDO);
            }
//            order.setTotalFee(totalFee);
//            this.save(order);
            try {
                wlyyDoorFeeDetailDao.saveAll(feeDetailDOList);
                doorOrderItemDao.saveAll(orderItemDOList);
//                wlyyDoorFeeDetailService.batchInsert(feeDetailDOList);
            } catch (Exception e) {
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                String failMsg = "保存服务费用到数据库异常:," + e.getMessage();
                result.put(ResponseContant.resultMsg, failMsg);
                logger.error(failMsg);
                return true;
            }
        }/*else{
            // 未添加服务项时,费用默认为0
            order.setTotalFee(new BigDecimal(0));
            this.save(order);
        }*/
            wlyyDoorFeeDetailDao.saveAll(feeDetailDOList);
            doorOrderItemDao.saveAll(orderItemDOList);
//          //更新总费用-这边没用到
//           order.setTotalFee(totalFee);
//           wlyyDoorServiceOrderDao.save(order);
            return true;
        }
        return false;
    }
@ -678,30 +652,16 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @param jsonData
     * @return
     */
    public JSONObject create(String jsonData) {
    @Transactional
    public JSONObject create(String jsonData) throws Exception {
        logger.info("创建上门服务jsonData参数:" + jsonData);
        JSONObject result = new JSONObject();
        JSONObject jsonObjectParam;
        try {
            jsonObjectParam = JSONObject.parseObject(jsonData);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        WlyyDoorServiceOrderDO orderDO = null;
        try {
            orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "上门服务工单服务基本信息:" + e.getMessage();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        JSONObject jsonObjectParam = JSONObject.parseObject(jsonData);
        WlyyDoorServiceOrderDO orderDO = EntityUtils.jsonToEntity(
                jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
        orderDO.setNumber(getRandomIntStr());
        orderDO.setCreateTime(new Date());
        orderDO.setCreateUser(orderDO.getProxyPatient());
@ -709,19 +669,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        orderDO.setOrderInfo("0");
        if (StringUtils.isEmpty(orderDO.getPatient())) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
            throw new Exception("当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient());
        }
        if (StringUtils.isEmpty(orderDO.getProxyPatient())) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
            throw new Exception(failMsg);
        }
        //已取消的订单也可以申请
@ -734,10 +687,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        if (bool) {
            String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
            throw new Exception(failMsg);
        }
        orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
@ -749,22 +699,13 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            orderDO.setType(2);
        }
        orderDO.setServiceStatus("1");
        this.save(orderDO);
        wlyyDoorServiceOrderDao.save(orderDO);
        //创建咨询
        JSONObject successOrNot = null;
        try {
            successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
        } catch (Exception e) {
            String failMsg = "创建咨询时异常: " + e.getMessage();
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        if (Integer.parseInt(successOrNot.get(ResponseContant.resultFlag).toString()) == ResponseContant.fail) {
            return JSONObject.parseObject(successOrNot.toString());
        }
        JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
//        if (Integer.parseInt(successOrNot.get(ResponseContant.resultFlag).toString()) == ResponseContant.fail) {
//            return JSONObject.parseObject(successOrNot.toString());
//        }
        ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
        //新增工单与服务项费用关联关系
@ -1913,7 +1854,10 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     *
     * @return
     */
    public JSONObject queryBriefList(String dispatcher, String hospital, String orderNumber, String patientName, String phone, Integer status, String patientType, int page, int size) {
    public JSONObject queryBriefList(
            String dispatcher, String hospital, String orderNumber,
            String patientName, String phone, Integer status, String patientType, int page, int size
    ) throws Exception {
        JSONObject result = new JSONObject();
        orderNumber = null == orderNumber ? "" : orderNumber;
@ -1953,7 +1897,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "   t1.`type` as patientType " +
                " FROM " +
                " ( wlyy_door_service_order o " +
                "LEFT JOIN wlyy_patient p ON o.patient = p.`code` ) LEFT JOIN wlyy_consult c on o.id = c.relation_code" +
                " LEFT JOIN base_patient p ON o.patient = p.`id` ) " +
                " LEFT JOIN wlyy_consult c on o.id = c.relation_code " +
                " left JOIN ( " +
                "         select a.patient, group_concat(v.type) as type " +
                "         from wlyy_door_service_voucher v " +
@ -1981,7 +1926,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "   count(o.id)  " +
                " FROM  " +
                "   wlyy_door_service_order o  " +
                " LEFT JOIN wlyy_patient p ON o.patient = p.`code` " +
                " LEFT JOIN base_patient p ON o.patient = p.`id` " +
                " left JOIN  ( " +
                "         select a.patient, group_concat(v.type) as type " +
                "         from wlyy_door_service_voucher v " +
@ -2044,11 +1989,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                                }
                            }
                    );
                    /*// 筛选居民类型 半失能/失能老人 肺结核患者 计生特殊家庭 残疾人 重性精神病 其他 等
                    if(patientSet.contains(oneMap.get("patient"))){
                        filteredResult.add(oneMap);
                    }*/
                });
        result.put(ResponseContant.resultFlag, ResponseContant.success);
@ -2065,7 +2005,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     *
     * @return
     */
    public JSONObject queryDoctorList(String patient, String hospital, String doctorName, String status, int page, int size) {
    public JSONObject queryDoctorList(
            String patient, String hospital, String doctorName, String status, int page, int size
    ) throws Exception {
        JSONObject result = new JSONObject();
        doctorName = null == doctorName ? "" : doctorName;
@ -2075,9 +2017,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        int start = 0 == page ? page++ : (page - 1) * size;
        int end = 0 == size ? 15 : size;
        //
        String sql = "SELECT " +
                "  d.code as doctor, " +
                "  d.id as doctor, " +
                "  d.photo as photo, " +
                "  d.name as name," +
                "  case d.sex  " +
@ -2085,20 +2026,26 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "  when 1 then '男' " +
                "  when 2 then '女' " +
                "  end as sex, " +
                "  d.`job_name` AS jobName, " +
                "  d.mobile as phone, " +
                "  d.`job_title_name` AS jobName, " +
                "  d.mobile as phone," +
                "  CONCAT(d.doctor_lat ,',',d.doctor_lon) 'position', " +
                "  IFNULL(ds.`status`,5) as status," +
                "  1 as sortFlag ,count(o.id) as count" +
                " FROM " +
                " wlyy_doctor d " +
                " LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor LEFT JOIN wlyy_door_service_order o on o.doctor = d.code and o.`status` in (2,3,4) " +
                " WHERE d.status = 1" +
                " AND d.level <> 11" +
                " AND d.hospital = '{hospital}' " +
                " base_doctor d " +
                " LEFT JOIN wlyy_door_doctor_status ds ON d.`id` = ds.doctor " +
                " LEFT JOIN wlyy_door_service_order o on o.doctor = d.id  " +
                " LEFT JOIN base_doctor_hospital a ON d.id=a.doctor_code " +
                " WHERE 1=1 " +
                " and o.`status` in (2,3,4) " +
                " and d.enabled = 1 " +
//                " AND d.level <> 11" +
                " AND a.org_code = '{hospital}' " +
                " AND d.`name` like '%{doctorName}%' " +
                " AND (ds.`status` in ({status}) or '-100' = '{status}')" +
                " AND d.del=1  " +
                " GROUP BY d.`code` ORDER BY ds.create_time DESC " +
                " GROUP BY d.`id` " +
                " ORDER BY ds.create_time DESC " +
                " LIMIT {start},{end}";
        String finalSql = sql.replace("{hospital}", hospital)
@ -2110,50 +2057,24 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        String countSql = "SELECT  " +
                "   count(d.id)  " +
                " FROM  " +
                "   wlyy_doctor d  " +
                " LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor " +
                " WHERE d.status = 1" +
                " AND d.level <> 4" +
                " AND d.hospital = '{hospital}' " +
                "   base_doctor d  " +
                " LEFT JOIN wlyy_door_doctor_status ds ON d.`id` = ds.doctor " +
                " LEFT JOIN base_doctor_hospital a ON d.id=a.doctor_code " +
                " WHERE d.enabled = 1" +
//                " AND d.level <> 4" +
                " AND a.org_code = '{hospital}' " +
                " AND d.`name` like '%{doctorName}%' " +
                " AND d.del=1 and d.status=1 " +
                " AND d.del=1 and d.enabled=1 " +
                " AND (ds.`status` in ({status}) or '-100' = '{status}')";
        String finalCountSql = countSql.replace("{hospital}", hospital)
                .replace("{doctorName}", doctorName)
                .replace("{status}", String.valueOf(status));
        List<Map<String, Object>> sqlResultlist = new ArrayList<>();
        try {
            sqlResultlist = jdbcTemplate.queryForList(finalSql);
            if (sqlResultlist != null && sqlResultlist.size() != 0) {
                for (Map<String, Object> map : sqlResultlist) {
                    BaseDoctorDO doctor = doctorDao.findById(map.get("doctor").toString()).orElse(null);
                    //先注释需要在加字段20231011
//                    Hospital hospital1 = hospitalDao.findByCode(doctor.getHospital());
//                    if (doctor.getPosition() == null || doctor.getPosition() == "") {
//                        map.put("position", hospital1.getPosition());
//                    } else {
//                        map.put("position", doctor.getPosition());
//                    }
                }
            }
            logger.info("服务医生人员sql:" + finalSql);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, "从数据库查询 服务医生人员 列表信息失败:" + e.getMessage());
            return result;
        }
        List<Map<String, Object>> sqlResultlist = jdbcTemplate.queryForList(finalSql);
        logger.info("服务医生人员sql:" + finalSql);
        Integer count = jdbcTemplate.queryForObject(finalCountSql, Integer.class);
        Integer count = 0;
        try {
            count = jdbcTemplate.queryForObject(finalCountSql, Integer.class);
        } catch (Exception e) {
            e.printStackTrace();
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, "从数据库统计  服务医生人员 数量失败:" + e.getMessage());
            return result;
        }
        //添加未完成服务工单列表
        for (Map<String, Object> map : sqlResultlist) {
            String doctor = map.get("doctor") + "";
@ -2167,60 +2088,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                map.put("notFinishList", notFinishList);
            }
        }
        // 居民端第一页置顶家庭医生 -- 先注释掉-20231011
//        if (!StringUtils.isEmpty(patient) && page == 1) {
//            SignFamily signFamily = signFamilyDao.findByPatient(patient);
//            if (null != signFamily) {
//                String signDoctor = signFamily.getDoctor();
//                String signDoctorName = signFamily.getDoctorName();
//                //判断当前居民是否有家庭医生
//                boolean doctorExist = wlyyDoorDoctorStatusDao.existsByDoctorAndStatusIn(signDoctor, new Integer[]{1, 2, 3, 4});
//                if (doctorExist) {
//                    boolean bool = false;
//                    Map<String, Object> signDoctorMap = new HashMap<>();
//                    for (Map<String, Object> oneDoctorMap : sqlResultlist) {
//                        bool = oneDoctorMap.containsValue(signDoctor);
//                        if (bool) {
//                            oneDoctorMap.put("sortFlag", 0L);
//                            oneDoctorMap.put("isSignDoctor", true);
//                            break;
//                        }
//                    }
//                    if (!bool) {
//                        //查出家签医生置顶
//                        String signDocSql = "SELECT " +
//                                " d. CODE AS doctor, " +
//                                " d.photo AS photo, " +
//                                " d. NAME AS name, " +
//                                " CASE d.sex " +
//                                "WHEN 0 THEN " +
//                                " '无' " +
//                                "WHEN 1 THEN " +
//                                " '男' " +
//                                "WHEN 2 THEN " +
//                                " '女' " +
//                                "END AS sex, " +
//                                " d.`job_name` AS jobName, " +
//                                " d.mobile AS phone, " +
//                                " IFNULL(ds.`status`, 5) AS STATUS, " +
//                                " 0 AS sortFlag, " +
//                                " count(o.id) AS count " +
//                                "FROM " +
//                                " wlyy_doctor d " +
//                                "LEFT JOIN wlyy_door_doctor_status ds ON d.`code` = ds.doctor " +
//                                "LEFT JOIN wlyy_door_service_order o ON o.doctor = d. CODE " +
//                                "AND o.`status` IN (2, 3, 4) " +
//                                "WHERE " +
//                                " d. STATUS = 1 AND d.hospital = '" + hospital + "'" +
//                                " and d.name like '%" + doctorName + "%'" +
//                                "AND d.`code` = '" + signDoctor + "'";
//                        sqlResultlist.addAll(jdbcTemplate.queryForList(signDocSql));
////                        count += 1;
//                    }
//                    sqlResultlist.sort(comparing((doctor) -> Integer.parseInt(doctor.get("sortFlag").toString())));
//                }
//            }
//        }
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, sqlResultlist);
@ -2997,4 +2864,46 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        result.put(ResponseContant.resultMsg, wlyyDoorServiceOrder);
        return result;
    }
    public JSONObject getDoctorInfo(ParamQvo qvo) {
        JSONObject result = new JSONObject();
        String sql = "SELECT\n" +
                "	a.*,\n" +
                "	b.dept_name 'deptName',\n" +
                "	b.org_code 'orgCode',\n" +
                "	b.org_name 'orgName',\n" +
                "	c.mapping_code 'jobNumber',\n" +
                "	h.dept_type_code 'deptTypeCode' \n" +
                "FROM\n" +
                "	base_doctor a\n" +
                "	LEFT JOIN base_doctor_hospital b ON a.id = b.doctor_code\n" +
                "	LEFT JOIN base_doctor_mapping c ON a.id = c.doctor\n" +
                "	LEFT JOIN dict_hospital_dept h ON b.dept_code = h.CODE \n" +
                "WHERE\n" +
                "	1 = 1 \n" +
                "	AND a.id='" + qvo.getLoginUserCode() + "' " +
                "	AND b.org_code = '922b9636-5aff-11e6-8344-fa163e8aee56'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (!list.isEmpty()) {
            Map<String, Object> map = list.get(0);
            //查询角色
            String roleSql = "SELECT " +
                    " t.CODE AS \"roleCode\", " +
                    " t.NAME AS \"roleName\"" +
                    " FROM " +
                    " base_doctor_role r " +
                    " JOIN base_doctor_role_dict t ON t.code = r.role_code " +
                    " WHERE " +
                    " r.doctor_code = '" + qvo.getLoginUserCode() + "'";
            List<Map<String, Object>> roleList = jdbcTemplate.queryForList(roleSql);
            if (roleList != null && roleList.size() > 0) {
                map.put("roles", list);
            } else {
                map.put("roles", null);
            }
            result.put("data", map);
        }
        return result;
    }
}