Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hphy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向怀芳
hphy
Commits
a145aaef
Commit
a145aaef
authored
Aug 07, 2023
by
gaozhaochen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize: 机器人问答返回结果
parent
92ecc440
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
99 deletions
+103
-99
CurrentUser.java
.../main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java
+1
-1
HpGpIntelligentQAController.java
...e/hpgp/controller/mobile/HpGpIntelligentQAController.java
+102
-98
No files found.
smart-health-modules/cloud-upms/cloud-upms-api/src/main/java/cn/sh/stc/sict/cloud/upms/dto/CurrentUser.java
View file @
a145aaef
...
@@ -41,6 +41,6 @@ public class CurrentUser implements Serializable {
...
@@ -41,6 +41,6 @@ public class CurrentUser implements Serializable {
/**
/**
* 机器人问答
* 机器人问答
*/
*/
private
List
<
List
<
String
>>
qaHistory
;
private
String
qaHistory
;
}
}
smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hpgp/controller/mobile/HpGpIntelligentQAController.java
View file @
a145aaef
package
cn
.
sh
.
stc
.
sict
.
theme
.
hpgp
.
controller
.
mobile
;
package
cn
.
sh
.
stc
.
sict
.
theme
.
hpgp
.
controller
.
mobile
;
import
cn.hutool.core.collection.CollUtil
;
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.StrUtil
;
import
cn.hutool.core.util.XmlUtil
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpResponse
;
import
cn.sh.stc.sict.cloud.common.core.util.R
;
import
cn.sh.stc.sict.cloud.common.core.util.R
;
...
@@ -13,8 +10,8 @@ import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils;
...
@@ -13,8 +10,8 @@ import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils;
import
cn.sh.stc.sict.cloud.upms.dto.CurrentUser
;
import
cn.sh.stc.sict.cloud.upms.dto.CurrentUser
;
import
cn.sh.stc.sict.theme.hpgp.vo.IntelligentAnswerVO
;
import
cn.sh.stc.sict.theme.hpgp.vo.IntelligentAnswerVO
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
com.google.api.client.util.Lists
;
import
com.google.api.client.util.Lists
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
...
@@ -25,8 +22,8 @@ import org.springframework.web.bind.annotation.PostMapping;
...
@@ -25,8 +22,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
...
@@ -51,108 +48,115 @@ public class HpGpIntelligentQAController {
...
@@ -51,108 +48,115 @@ public class HpGpIntelligentQAController {
* 打浦桥科室
* 打浦桥科室
*/
*/
private
final
static
Set
<
String
>
DPQ_DEPARTMENT
=
Sets
.
newHashSet
(
"皮肤性病科"
,
"中医科"
,
"儿保科"
,
"全科医疗科"
);
private
final
static
Set
<
String
>
DPQ_DEPARTMENT
=
Sets
.
newHashSet
(
"皮肤性病科"
,
"中医科"
,
"儿保科"
,
"全科医疗科"
);
private
final
static
Set
<
String
>
XDM_DEPARTMENT
=
Sets
.
newHashSet
(
"全科"
,
"全科名医"
,
"中医"
,
"针伤科"
,
"齿科"
);
private
final
static
Set
<
String
>
XDM_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://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
(
"全科医疗科"
);
}
}
// 小东门单独处理
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
(
"全科"
);
}
}
}
return
new
R
<>(
answerVO
);
}
// @SysLog
// @SysLog
// @ApiOperation("智能问答")
// @ApiOperation("智能问答")
// @PostMapping
// @PostMapping
// public R
qaV2
(String question) {
// public R
<?> qa
(String question) {
// CurrentUser current = SecurityUtils.getCurrentUser();
// CurrentUser current = SecurityUtils.getCurrentUser();
// List<List<String>> qaHistory = current.getQaHistory();
// String from = StrUtil.isNotBlank(current.getOpenId()) ? current.getOpenId() : current.getId().toString();
// 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 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 为黄浦高血压专病导医机器人
// // 162 为黄浦高血压专病导医机器人
// // 51 黄浦高血压全科导诊机器人
// // 51 黄浦高血压全科导诊机器人
// HttpResponse response = HttpRequest.post(qaUrl)
// String body = HttpRequest.post("http://30.30.5.74:9988/qa/jqrsvr.ashx?Command=talk_51")
// .body(req, "application/json")
// .body(xml)
// .execute();
// .execute()
// String body = response.body();
// .body();
// log.error("接口请求 req = {}", req);
// log.error("孙总接口请求 xml = {}", xml);
// log.error("接口返回 body = {}", body);
// log.error("孙总接口返回 body = {}", body);
// if (response.getStatus() != 200 || StrUtil.isBlank(body)) {
// IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
// return new R();
// Map<String, Object> result = XmlUtil.xmlToMap(body);
// }
// if (result.containsKey(CONTENT)) {
// answerVO.setAnswer(MapUtil.getStr(result, CONTENT));
//
//
// body = body.replaceAll(QA_RESULT_FLAG, "");
// // 打浦桥单独处理
// body = body.replaceAll("<[.[^>]]*>", "");
// if (StrUtil.isNotBlank(current.getHospitalCode())
// currentQa.set(1, body);
// && "42502942300".equals(current.getHospitalCode())) {
// current.setQaHistory(qaHistory);
// if (StrUtil.isNotBlank(answerVO.getDeptName())
// SecurityUtils.updateCurrent(current);
// && !DPQ_DEPARTMENT.contains(answerVO.getDeptName())) {
// String oldDeptName = answerVO.getDeptName();
// answerVO.setAnswer(answerVO.getAnswer().replace(oldDeptName, "全科医疗科"));
// answerVO.setDeptName("全科医疗科");
// }
// }
//
//
// IntelligentAnswerVO answerVO = new IntelligentAnswerVO();
// // 小东门单独处理
// answerVO.setAnswer(body);
// if (StrUtil.isNotBlank(current.getHospitalCode())
// return new R(answerVO);
// && "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("全科");
// }
// }
//
// }
// return new R<>(answerVO);
// }
// }
@SysLog
@ApiOperation
(
"智能问答"
)
@PostMapping
public
R
qaV2
(
String
question
)
{
CurrentUser
current
=
SecurityUtils
.
getCurrentUser
();
List
<
String
>
qaHistory
=
JSON
.
parseArray
(
current
.
getQaHistory
(),
String
.
class
);
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
(
JSON
.
toJSONString
(
currentQa
));
List
<
List
<
String
>>
reqList
=
new
ArrayList
<>();
for
(
Object
item
:
qaHistory
)
{
if
(
item
instanceof
String
)
{
List
<
String
>
itemList
=
JSONArray
.
parseArray
((
String
)
item
,
String
.
class
);
reqList
.
add
(
itemList
);
}
}
jsonObject
.
put
(
"history"
,
reqList
);
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
.
substring
(
1
,
body
.
lastIndexOf
(
"\""
));
currentQa
.
set
(
1
,
body
);
current
.
setQaHistory
(
JSON
.
toJSONString
(
qaHistory
));
SecurityUtils
.
updateCurrent
(
current
);
IntelligentAnswerVO
answerVO
=
new
IntelligentAnswerVO
();
answerVO
.
setAnswer
(
body
);
return
new
R
(
answerVO
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment