Commit 92ecc440 authored by gaozhaochen's avatar gaozhaochen

update: 统计接口新增预约时间维度,机器人推荐科室小东门单独处理

parent 307551ac
package cn.sh.stc.sict.theme.hpgp.controller.mobile;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.sh.stc.sict.cloud.common.core.util.R;
......@@ -11,6 +14,7 @@ import cn.sh.stc.sict.cloud.upms.dto.CurrentUser;
import cn.sh.stc.sict.theme.hpgp.vo.IntelligentAnswerVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.api.client.util.Lists;
import com.google.common.collect.Sets;
import io.swagger.annotations.Api;
......@@ -22,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
......@@ -46,94 +51,108 @@ public class HpGpIntelligentQAController {
* 打浦桥科室
*/
private final static Set<String> DPQ_DEPARTMENT = Sets.newHashSet("皮肤性病科", "中医科", "儿保科", "全科医疗科");
// @SysLog
// @ApiOperation("智能问答")
// @PostMapping
// public R<?> qa(String question) {
// CurrentUser current = SecurityUtils.getCurrentUser();
// String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString();
//
// String xml = "<xml>\n" +
// " <ToUserName><![CDATA[huangpurobot]]></ToUserName>\n" +
// " <FromUserName><![CDATA[" + from + "]]></FromUserName>\n" +
// " <CreateTime>" + DateUtil.now() + "</CreateTime>\n" +
// " <MsgType><![CDATA[text]]></MsgType>\n" +
// " <Content><![CDATA[" + question + "]]></Content>\n" +
// " <MsgId>" + IdWorker.getId() + "</MsgId>\n" +
// "</xml>";
// // 162 为黄浦高血压专病导医机器人
// // 51 黄浦高血压全科导诊机器人
// String body = HttpRequest.post(" http://www.365jqr.com/jqrsvr.ashx?Command=talk_51")
// .body(xml)
// .execute()
// .body();
// log.error("孙总接口请求 xml = {}", xml);
// log.error("孙总接口返回 body = {}", body);
// IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
// Map<String, Object> result = XmlUtil.xmlToMap(body);
// if (result.containsKey(CONTENT)) {
// answerVO.setAnswer(MapUtil.getStr(result, CONTENT));
// if (StrUtil.isNotBlank(current.getHospitalCode())
// && "42502942300".equals(current.getHospitalCode())) {
// if (StrUtil.isNotBlank(answerVO.getDeptName())
// && !DPQ_DEPARTMENT.contains(answerVO.getDeptName())) {
// String oldDeptName = answerVO.getDeptName();
// answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科医疗科"));
// answerVO.setDeptName("全科医疗科");
// }
// }
// }
// return new R<>(answerVO);
// }
private final static Set<String> XDM_DEPARTMENT = Sets.newHashSet("全科", "全科名医", "中医", "针伤科","齿科");
@SysLog
@ApiOperation("智能问答")
@PostMapping
public R qaV2(String question) {
public R<?> qa(String question) {
CurrentUser current = SecurityUtils.getCurrentUser();
List<List<String>> qaHistory = current.getQaHistory();
String from = current.getId().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("username", from);
if (CollUtil.isEmpty(qaHistory)) {
qaHistory = Lists.newArrayListWithCapacity(1);
}
if (qaHistory.size() > qaHistoryLimit) {
qaHistory = qaHistory.subList(0, qaHistoryLimit - 1);
}
List<String> currentQa = Lists.newArrayList();
currentQa.add(question);
currentQa.add(null);
qaHistory.add(currentQa);
jsonObject.put("history", qaHistory);
String req = JSON.toJSONString(jsonObject);
String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString();
String xml = "<xml>\n" +
" <ToUserName><![CDATA[huangpurobot]]></ToUserName>\n" +
" <FromUserName><![CDATA[" + from + "]]></FromUserName>\n" +
" <CreateTime>" + DateUtil.now() + "</CreateTime>\n" +
" <MsgType><![CDATA[text]]></MsgType>\n" +
" <Content><![CDATA[" + question + "]]></Content>\n" +
" <MsgId>" + IdWorker.getId() + "</MsgId>\n" +
"</xml>";
// 162 为黄浦高血压专病导医机器人
// 51 黄浦高血压全科导诊机器人
HttpResponse response = HttpRequest.post(qaUrl)
.body(req, "application/json")
.execute();
String body = response.body();
log.error("接口请求 req = {}", req);
log.error("接口返回 body = {}", body);
if (response.getStatus() != 200 || StrUtil.isBlank(body)) {
return new R();
String body = HttpRequest.post("http://30.30.5.74:9988/qa/jqrsvr.ashx?Command=talk_51")
.body(xml)
.execute()
.body();
log.error("孙总接口请求 xml = {}", xml);
log.error("孙总接口返回 body = {}", body);
IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
Map<String, Object> result = XmlUtil.xmlToMap(body);
if (result.containsKey(CONTENT)) {
answerVO.setAnswer(MapUtil.getStr(result, CONTENT));
// 打浦桥单独处理
if (StrUtil.isNotBlank(current.getHospitalCode())
&& "42502942300".equals(current.getHospitalCode())) {
if (StrUtil.isNotBlank(answerVO.getDeptName())
&& !DPQ_DEPARTMENT.contains(answerVO.getDeptName())) {
String oldDeptName = answerVO.getDeptName();
answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科医疗科"));
answerVO.setDeptName("全科医疗科");
}
}
body = body.replaceAll(QA_RESULT_FLAG, "");
body = body.replaceAll("<[.[^>]]*>", "");
currentQa.set(1, body);
current.setQaHistory(qaHistory);
SecurityUtils.updateCurrent(current);
// 小东门单独处理
if (StrUtil.isNotBlank(current.getHospitalCode())
&& "42507025800".equals(current.getHospitalCode())) {
if (StrUtil.isNotBlank(answerVO.getDeptName())
&& !XDM_DEPARTMENT.contains(answerVO.getDeptName())) {
String oldDeptName = answerVO.getDeptName();
answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科"));
answerVO.setDeptName("全科");
}
}
IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
answerVO.setAnswer(body);
return new R(answerVO);
}
return new R<>(answerVO);
}
// @SysLog
// @ApiOperation("智能问答")
// @PostMapping
// public R qaV2(String question) {
// CurrentUser current = SecurityUtils.getCurrentUser();
// List<List<String>> qaHistory = current.getQaHistory();
// String from = current.getId().toString();
//
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("username", from);
// if (CollUtil.isEmpty(qaHistory)) {
// qaHistory = Lists.newArrayListWithCapacity(1);
// }
//
// if (qaHistory.size() > qaHistoryLimit) {
// qaHistory = qaHistory.subList(0, qaHistoryLimit - 1);
// }
//
// List<String> currentQa = Lists.newArrayList();
// currentQa.add(question);
// currentQa.add(null);
// qaHistory.add(currentQa);
//
// jsonObject.put("history", qaHistory);
// String req = JSON.toJSONString(jsonObject);
//
// // 162 为黄浦高血压专病导医机器人
// // 51 黄浦高血压全科导诊机器人
// HttpResponse response = HttpRequest.post(qaUrl)
// .body(req, "application/json")
// .execute();
// String body = response.body();
// log.error("接口请求 req = {}", req);
// log.error("接口返回 body = {}", body);
// if (response.getStatus() != 200 || StrUtil.isBlank(body)) {
// return new R();
// }
//
// body = body.replaceAll(QA_RESULT_FLAG, "");
// body = body.replaceAll("<[.[^>]]*>", "");
// currentQa.set(1, body);
// current.setQaHistory(qaHistory);
// SecurityUtils.updateCurrent(current);
//
// IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
// answerVO.setAnswer(body);
// return new R(answerVO);
// }
}
......@@ -72,14 +72,19 @@
</select>
<select id="countAll4Third" resultType="java.util.LinkedHashMap">
SELECT * FROM
(
-- 统计各家医院预约人数
SELECT
IFNULL(c.appointment_count,0) AS '导诊数',
h.hos_org_code AS '医疗机构代码',
h.hos_name AS '医疗机构名称',
t.inter_des AS '对接状态'
t.inter_des AS '对接状态',
DATE_FORMAT(c.create_time,'%Y-%m-%d') AS '导诊时间'
FROM (
SELECT count(1) AS appointment_count, hos_org_code
SELECT count(1) AS appointment_count,
hos_org_code,
create_time
FROM `hp_appointment`
<where>
<if test="startTime != null and startTime != '' ">
......@@ -89,7 +94,7 @@
AND create_time &lt;= #{endTime}
</if>
</where>
GROUP BY hos_org_code
GROUP BY hos_org_code,DATE_FORMAT(create_time,'%Y-%m-%d')
) c
RIGHT JOIN hp_hos_info h ON c.hos_org_code = h.hos_org_code
RIGHT JOIN hp_third_interface_status t ON h.hos_org_code = t.hos_org_code
......@@ -99,7 +104,8 @@
COUNT(1) AS '导诊数' ,
1 AS '医疗机构代码' ,
'卫管中心' AS '医疗机构名称',
'已对接' AS '对接状态'
'已对接' AS '对接状态',
DATE_FORMAT(create_time,'%Y-%m-%d') AS '导诊时间'
FROM `sys_log`
WHERE title = '预约' AND create_by like '%wx24c55f38b535cd96%'
<if test="startTime != null and startTime != '' ">
......@@ -108,6 +114,10 @@
<if test="endTime != null and endTime != '' ">
AND create_time &lt;= #{endTime}
</if>
GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d')
) t
WHERE 导诊时间 IS not null
order by `医疗机构代码`,`导诊时间`
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment