|
@ -599,7 +599,7 @@ public class ConsultController extends WeixinBaseController {
|
|
|
if (consultModel.getEndMsgId() != null) {
|
|
|
return error(-1, "咨询已结束");
|
|
|
}
|
|
|
|
|
|
Patient patient = patientDao.findByCode(getUID());
|
|
|
String[] arr = null;
|
|
|
|
|
|
if (type == 2) {
|
|
@ -651,37 +651,36 @@ public class ConsultController extends WeixinBaseController {
|
|
|
List<String> failed = new ArrayList<>();
|
|
|
|
|
|
for (ConsultTeamLog log : logs) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ (group != null ? "api/v1/chats/gm" : "api/v1/chats/pm");
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
if (group == null) {
|
|
|
params.add(new BasicNameValuePair("from", getUID()));
|
|
|
params.add(new BasicNameValuePair("to", consultModel.getDoctor()));
|
|
|
params.add(new BasicNameValuePair("content", log.getContent()));
|
|
|
params.add(new BasicNameValuePair("contentType", String.valueOf(log.getType())));
|
|
|
} else {
|
|
|
params.add(new BasicNameValuePair("from", getUID()));
|
|
|
params.add(new BasicNameValuePair("at", ""));
|
|
|
params.add(new BasicNameValuePair("group", group.getString("code")));
|
|
|
params.add(new BasicNameValuePair("groupType", "2"));
|
|
|
params.add(new BasicNameValuePair("content", log.getContent()));
|
|
|
params.add(new BasicNameValuePair("contentType", String.valueOf(log.getType())));
|
|
|
}
|
|
|
|
|
|
String response = HttpClientUtil.post(url, params, "UTF-8");
|
|
|
|
|
|
if (StringUtils.isEmpty(response)) {
|
|
|
failed.add(arr[i]);
|
|
|
String response = sendTopicIM(getUID(),patient.getName(),consult,String.valueOf(log.getType()),log.getContent());
|
|
|
if (StringUtils.isNotEmpty(response)) {
|
|
|
failed.add(response);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return write(200, "追问成功!", "data", failed);
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return invalidUserException(e, -1, "追问失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送消息给IM
|
|
|
*
|
|
|
* @param from 来自
|
|
|
* @param contentType 1文字 2图片消息
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
private String sendTopicIM(String from,String fromName, String topicId, String contentType, String content) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ ("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);;
|
|
|
String response = HttpClientUtil.postBody(url, params);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 网络咨询咨询日志查询
|
|
@ -695,145 +694,14 @@ public class ConsultController extends WeixinBaseController {
|
|
|
public String loglist(@RequestParam String consult, @RequestParam long id, @RequestParam int pagesize) {
|
|
|
try {
|
|
|
ConsultTeam consultModel = consultTeamService.findByCode(consult);
|
|
|
|
|
|
if (consultModel == null) {
|
|
|
return error(-1, "咨询记录不存在!");
|
|
|
}
|
|
|
|
|
|
Patient p = patientDao.findByCode(getUID());
|
|
|
Map<String, Doctor> map = new HashMap<>();
|
|
|
|
|
|
List<JSONObject> jsonArray = new ArrayList<>();
|
|
|
JSONObject group = talkGroupService.findConsultTalkGroup(consultModel.getConsult());
|
|
|
|
|
|
if (group != null) {
|
|
|
String urlG = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v1/chats/gm";
|
|
|
String reG = HttpUtil.sendGet(urlG, "user_id=" + getUID() + "&group_id=" + group.getString("code"));
|
|
|
JSONObject resultG = null;
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(reG)) {
|
|
|
resultG = new JSONObject(new String(reG.getBytes(), "utf-8"));
|
|
|
}
|
|
|
|
|
|
if (resultG != null && resultG.getInt("count") > 0) {
|
|
|
JSONArray list = resultG.getJSONArray("records");
|
|
|
|
|
|
for (int i = 0; i < list.length(); i++) {
|
|
|
JSONObject obj = list.getJSONObject(i);
|
|
|
|
|
|
if (obj.getInt("contentType") == 5 || obj.getInt("contentType") == 6) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", obj.getInt("id"));
|
|
|
if (!obj.getString("from").equals(getUID())) {
|
|
|
Doctor doc = null;
|
|
|
|
|
|
if (map.containsKey(obj.getString("from"))) {
|
|
|
doc = map.get(obj.getString("from"));
|
|
|
} else {
|
|
|
doc = doctorService.findDoctorByCode(obj.getString("from"));
|
|
|
}
|
|
|
|
|
|
// 设置回复医生姓名
|
|
|
json.put("doctorName", doc.getName());
|
|
|
json.put("photo", doc.getPhoto());
|
|
|
} else {
|
|
|
// 设置回复医生姓名
|
|
|
json.put("doctorName", p.getName());
|
|
|
json.put("photo", p.getPhoto());
|
|
|
}
|
|
|
|
|
|
|
|
|
// 设置回复内容
|
|
|
json.put("content", obj.getString("content"));
|
|
|
// 设置咨询或回复时间
|
|
|
json.put("time", DateUtil.dateToStr(new Date(obj.getLong("timestamp")), DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// 设置记录类型:1文字,2图片,3语音 4 文章
|
|
|
json.put("msgType", obj.getInt("contentType"));
|
|
|
// 设置类型:0患者问,1医生回复,2患者追问,3患者评价
|
|
|
if (!obj.getString("from").equals(getUID())) {
|
|
|
json.put("type", 1);
|
|
|
} else {
|
|
|
json.put("type", obj.getInt("contentType") == 6 ? 0 : 2);
|
|
|
}
|
|
|
jsonArray.add(json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
JSONObject result = null;
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v1/chats/pm";
|
|
|
String re = HttpUtil.sendGet(url, "closed_interval=true&user_id=" + getUID() + "&peer_id=" + consultModel.getDoctor()
|
|
|
+ "&message_end_id=" + consultModel.getStartMsgId() + (consultModel.getEndMsgId() != null ? ("&message_start_id=" + consultModel.getEndMsgId()) : ""));
|
|
|
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(re)) {
|
|
|
result = new JSONObject(new String(re.getBytes(), "utf-8"));
|
|
|
}
|
|
|
|
|
|
if (result != null && result.getInt("count") > 0) {
|
|
|
JSONArray list = result.getJSONArray("records");
|
|
|
|
|
|
for (int i = 0; i < list.length(); i++) {
|
|
|
JSONObject obj = list.getJSONObject(i);
|
|
|
|
|
|
if (obj.getInt("contentType") == 5) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", obj.getInt("id"));
|
|
|
if (!obj.getString("from").equals(getUID())) {
|
|
|
Doctor doc = null;
|
|
|
|
|
|
if (map.containsKey(obj.getString("from"))) {
|
|
|
doc = map.get(obj.getString("from"));
|
|
|
} else {
|
|
|
doc = doctorService.findDoctorByCode(obj.getString("from"));
|
|
|
}
|
|
|
|
|
|
// 设置回复医生姓名
|
|
|
json.put("doctorName", doc.getName());
|
|
|
json.put("photo", doc.getPhoto());
|
|
|
} else {
|
|
|
// 设置回复医生姓名
|
|
|
json.put("doctorName", p.getName());
|
|
|
json.put("photo", p.getPhoto());
|
|
|
}
|
|
|
|
|
|
// 设置回复内容
|
|
|
json.put("content", obj.getString("content"));
|
|
|
// 设置咨询或回复时间
|
|
|
json.put("time", DateUtil.dateToStr(new Date(obj.getLong("timestamp")), DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// 设置记录类型:1文字,2图片,3语音
|
|
|
json.put("msgType", obj.getInt("contentType"));
|
|
|
// 设置类型:0患者问,1医生回复,2患者追问,3患者评价
|
|
|
if (!obj.getString("from").equals(getUID())) {
|
|
|
json.put("type", 1);
|
|
|
} else {
|
|
|
json.put("type", obj.getInt("contentType") == 6 ? 0 : 2);
|
|
|
}
|
|
|
jsonArray.add(json);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
jsonArray.sort(new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
if (o1.getString("time").compareTo(o2.getString("time")) > 0) {
|
|
|
return -1;
|
|
|
} else if (o1.getString("time").compareTo(o2.getString("time")) < 0) {
|
|
|
return 1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ "api/v2/sessions/topic/"+consultModel.getConsult()+"/messages?topic_id="+consultModel.getConsult();
|
|
|
String re = HttpClientUtil.get(url, "UTF-8");
|
|
|
// 返回结果
|
|
|
return write(200, "查询成功", "list", new JSONArray(jsonArray));
|
|
|
return write(200, "查询成功", "list", new JSONArray(re));
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return invalidUserException(e, -1, "查询失败!");
|