|
|
|
@@ -1,5 +1,4 @@ |
|
|
|
package com.xueyi.nlt.nlt.controller; |
|
|
|
|
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient; |
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery; |
|
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse; |
|
|
|
@@ -23,6 +22,8 @@ import com.xueyi.common.security.annotation.Logical; |
|
|
|
import com.xueyi.common.security.annotation.RequiresPermissions; |
|
|
|
import com.xueyi.common.web.entity.controller.BaseController; |
|
|
|
import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.*; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.CoversationSessionVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.DmLandingLlmVo; |
|
|
|
@@ -35,9 +36,11 @@ import com.xueyi.nlt.api.nlt.feign.RemoteQAService; |
|
|
|
import com.xueyi.nlt.netty.client.WebSocketClient; |
|
|
|
import com.xueyi.nlt.nlt.context.TerminalSecurityContextHolder; |
|
|
|
import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; |
|
|
|
import com.xueyi.nlt.nlt.domain.po.DmRegularPo; |
|
|
|
import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.IntentTemplateVo; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.MarkRecordVo; |
|
|
|
import com.xueyi.nlt.nlt.mapper.DmRegularMapper; |
|
|
|
import com.xueyi.nlt.nlt.service.IDmIntentService; |
|
|
|
import com.xueyi.nlt.nlt.template.FreeChatTemplate; |
|
|
|
import com.xueyi.nlt.nlt.template.GenerativeKnowledgeTemplate; |
|
|
|
@@ -72,6 +75,11 @@ import java.io.IOException; |
|
|
|
import java.io.Serializable; |
|
|
|
import java.text.DateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.time.Instant; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
@@ -145,6 +153,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
RemoteEnterpriseService remoteEnterpriseService; |
|
|
|
@Autowired |
|
|
|
private ElasticsearchClient esClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DmRegularMapper regularMapper; |
|
|
|
/** |
|
|
|
* 意图请求 |
|
|
|
列表 |
|
|
|
@@ -152,8 +163,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
@PostMapping("/api/conversation") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult conversationApi(@RequestBody DmIntentVo intent) { |
|
|
|
log.info("对话详情:{}", intent.toString()); |
|
|
|
TerminalSecurityContextHolder.setOperatorId(String.valueOf(intent.getOperator())); |
|
|
|
log.info("对话详情:{}", intent.toString()); |
|
|
|
log.info("交互对象:{}", intent.toString()); |
|
|
|
redisTemplate.opsForValue().increment("dashboard:server", 1); |
|
|
|
// 获取今天日期,并格式化成yyyy-MM-dd |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
@@ -161,25 +173,25 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
redisTemplate.opsForValue().increment(("dashboard:server-chart:" + today), 1); |
|
|
|
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); |
|
|
|
Source source = SourceUtil.getSourceCache(manDeviceDtoR.getData().getStrategyId()); |
|
|
|
R<JSONObject> jsonObjectR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
R<DmIntentResponse> jsonObjectR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
IntentTemplateVo voResult = new IntentTemplateVo(); |
|
|
|
voResult.setMsg(""); |
|
|
|
if (jsonObjectR.getData() != null) { |
|
|
|
if (jsonObjectR.getData().containsKey("result") && StringUtils.isEmpty(jsonObjectR.getData().getString("result")) ) { |
|
|
|
voResult.setTarget(0); |
|
|
|
} else { |
|
|
|
voResult.setTarget(1); |
|
|
|
} |
|
|
|
} else { |
|
|
|
voResult.setTarget(0); |
|
|
|
} |
|
|
|
if (intent.getMode() != null && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { |
|
|
|
voResult.setMsg(jsonObjectR.getData().get("msg").toString()); |
|
|
|
} |
|
|
|
else { |
|
|
|
voResult.setFormat(jsonObjectR.getData()); |
|
|
|
} |
|
|
|
return AjaxResult.success(voResult); |
|
|
|
// if (jsonObjectR.getData() != null) { |
|
|
|
// if (jsonObjectR.getData().containsKey("result") && StringUtils.isEmpty(jsonObjectR.getData().getString("result")) ) { |
|
|
|
// voResult.setTarget(0); |
|
|
|
// } else { |
|
|
|
// voResult.setTarget(1); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// voResult.setTarget(0); |
|
|
|
// } |
|
|
|
// if (intent.getMode() != null && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { |
|
|
|
// voResult.setMsg(jsonObjectR.getData().get("msg").toString()); |
|
|
|
// } |
|
|
|
// else { |
|
|
|
// voResult.setFormat(jsonObjectR.getData()); |
|
|
|
// } |
|
|
|
return AjaxResult.success(jsonObjectR.getData()); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/api/skill-intent") |
|
|
|
@@ -188,72 +200,33 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
log.info("交互对象:{}", intent.toString()); |
|
|
|
redisTemplate.opsForValue().increment("dashboard:server", 1); |
|
|
|
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); |
|
|
|
if (!manDeviceDtoR.isOk() || manDeviceDtoR.getData() == null) { |
|
|
|
return AjaxResult.error("设备不存在或服务没有启动,请确认。"); |
|
|
|
} |
|
|
|
Source source = SourceUtil.getSourceCache(manDeviceDtoR.getData().getStrategyId()); |
|
|
|
IntentTemplateVo voResult = new IntentTemplateVo(); |
|
|
|
//查询es,将满足条件的数据调用后续处理,不满足条件的返回原始数据 |
|
|
|
SearchResponse<JSONObject> dateResponse = null; |
|
|
|
List<Hit<JSONObject>> question_list = null; |
|
|
|
try { |
|
|
|
MatchQuery byName = MatchQuery.of(m->m.field("name").query(intent.getContent())); |
|
|
|
dateResponse = esClient.search(builder -> builder |
|
|
|
.index("regular_expression").query(q->q.match(byName)), |
|
|
|
JSONObject.class); |
|
|
|
question_list = dateResponse.hits().hits(); |
|
|
|
log.info("esClient search result: {}", dateResponse); |
|
|
|
}catch (IOException ie) { |
|
|
|
log.error("esClient search error", ie); |
|
|
|
return null; |
|
|
|
Long enterpriseId = manDeviceDtoR.getData().getTId(); |
|
|
|
// 如果当前模式为闲聊模式,清除缓存 |
|
|
|
if (!intent.getMode().equals(MessageConstants.MODE_WORK)) { |
|
|
|
redisTemplate2.delete("group:device" + ":" + intent.getDevId() + ":" +"session"); |
|
|
|
} |
|
|
|
for (Hit<JSONObject> jsonObjectHit : question_list) { |
|
|
|
JSONObject jo = jsonObjectHit.source(); |
|
|
|
Pattern pat = Pattern.compile(jo.get("name").toString()); |
|
|
|
Matcher m = pat.matcher(intent.getContent()); |
|
|
|
if (m.find()) { |
|
|
|
// R<JSONObject> jsonObjectR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
|
|
|
|
voResult.setMsg(jo.get("answer").toString()); |
|
|
|
// 如果包含Json数据并且json的skillCode字段不等于空 |
|
|
|
if (jo.containsKey("json") && StringUtils.isNotEmpty(jo.getString("json"))) { |
|
|
|
String skillCode = jo.getJSONObject("json").getString("skillCode"); |
|
|
|
intent.setSkillCode(skillCode); |
|
|
|
R<List<DmSkillDto>> skilllistInner = remoteskillService.skilllistInner(intent.getDevId(),"1",manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
if(skilllistInner.isOk()){ |
|
|
|
List<DmSkillDto> skilllist=skilllistInner.getData(); |
|
|
|
for (DmSkillDto dmSkillDto : skilllist) { |
|
|
|
if (dmSkillDto.getSkillCode().equals(skillCode)) { |
|
|
|
if(dmSkillDto.getStatus().equals("0")){ |
|
|
|
return AjaxResult.error(10001,"操作无权限"); |
|
|
|
} |
|
|
|
voResult.setMotion(dmSkillDto.getMotionName()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
voResult.setJsonFormat(jo.getJSONObject("json")); |
|
|
|
voResult.setType("1"); |
|
|
|
} |
|
|
|
|
|
|
|
// return AjaxResult.success(voResult); |
|
|
|
DmIntentResponse response = new DmIntentResponse(); |
|
|
|
// 判断会议室缓存 |
|
|
|
// 获取设备号对应缓存 |
|
|
|
CoversationSessionVo sessionObject = (CoversationSessionVo) redisTemplate2.opsForValue().get("group:device" + ":" + intent.getDevId() + ":" +"session"); //category |
|
|
|
if (sessionObject != null) { |
|
|
|
switch (sessionObject.getCategory()) { |
|
|
|
case "meeting": |
|
|
|
response.setMsg(""); |
|
|
|
response.setSkillCode("1"); |
|
|
|
response.setH5(meetingOrderTemplate.handle(intent.getDevId(),intent.getContent(), enterpriseId)); |
|
|
|
response.setAction("Meeting"); |
|
|
|
return AjaxResult.success(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//走知识库 |
|
|
|
R<JSONObject> jsonObjectR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
if (jsonObjectR.getData() != null) { |
|
|
|
if (jsonObjectR.getData().containsKey("result") && StringUtils.isEmpty(jsonObjectR.getData().getString("result")) ) { |
|
|
|
voResult.setTarget(0); |
|
|
|
} else { |
|
|
|
voResult.setTarget(1); |
|
|
|
} |
|
|
|
} else { |
|
|
|
voResult.setTarget(0); |
|
|
|
} |
|
|
|
if (intent.getMode() != null && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { |
|
|
|
voResult.setMsg(jsonObjectR.getData().get("msg").toString()); |
|
|
|
} |
|
|
|
else { |
|
|
|
voResult.setFormat(jsonObjectR.getData()); |
|
|
|
} |
|
|
|
return AjaxResult.success(voResult); |
|
|
|
R<DmIntentResponse> intentResponseR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
|
|
|
|
return AjaxResult.success(intentResponseR.getData()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -320,8 +293,8 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); |
|
|
|
Source source = SourceUtil.getSourceCache(manDeviceDtoR.getData().getStrategyId()); |
|
|
|
KnowledgeVo knowledgeVo = new KnowledgeVo(); |
|
|
|
knowledgeVo.setMan_code(manDeviceDtoR.getData().getManCode()); |
|
|
|
knowledgeVo.setTenant_id(manDeviceDtoR.getData().getTId()); |
|
|
|
knowledgeVo.setManCode(manDeviceDtoR.getData().getManCode()); |
|
|
|
knowledgeVo.setTenantId(manDeviceDtoR.getData().getTId()); |
|
|
|
knowledgeVo.setQuestion(intent.getContent()); |
|
|
|
// return remoteQAService.query(manDeviceDtoR.getData().getManCode(),intent.getContent(),manDeviceDtoR.getData().getTId()); |
|
|
|
return remoteQAService.query(knowledgeVo); |
|
|
|
@@ -379,69 +352,110 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
*/ |
|
|
|
@PostMapping("/inner/conversation") |
|
|
|
@ResponseBody |
|
|
|
public R<JSONObject> conversationInner(@RequestBody DmIntentVo intent) { |
|
|
|
JSONObject joResult = null; |
|
|
|
if (intent.getMode() !=null && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { |
|
|
|
// 闲聊 |
|
|
|
joResult = freeChatTemplate.handle(intent.getDevId(),intent.getContent()); |
|
|
|
return R.ok(joResult); |
|
|
|
} |
|
|
|
public R<DmIntentResponse> conversationInner(@RequestBody DmIntentVo intent) { |
|
|
|
DmIntentResponse response = new DmIntentResponse(); |
|
|
|
|
|
|
|
|
|
|
|
String enterpriseId = (String)SecurityContextHolder.getLocalMap().get("enterprise_id"); |
|
|
|
String enterpriseName = ""; |
|
|
|
R<SysEnterpriseDto> enterpriseDtoR = remoteEnterpriseService.getInfo(Long.valueOf(enterpriseId)); |
|
|
|
Source source = SourceUtil.getSourceCache(enterpriseDtoR.getData().getStrategyId()); |
|
|
|
if (enterpriseDtoR.isOk()) { |
|
|
|
enterpriseName = enterpriseDtoR.getData().getName(); |
|
|
|
} |
|
|
|
// 获取设备号对应缓存 |
|
|
|
CoversationSessionVo sessionObject = (CoversationSessionVo) redisTemplate2.opsForValue().get("group:device" + ":" + intent.getDevId() + ":" +"session"); //category |
|
|
|
if (sessionObject != null) { |
|
|
|
switch (sessionObject.getCategory()) { |
|
|
|
case "meeting": |
|
|
|
joResult = meetingOrderTemplate.handle(intent.getDevId(),intent.getContent(), Long.parseLong(SecurityContextHolder.getLocalMap().get("enterprise_id").toString())); |
|
|
|
return R.ok(joResult); |
|
|
|
|
|
|
|
//先调用意图 |
|
|
|
//根据技能调用知识库或大模型 |
|
|
|
|
|
|
|
response = doMatchRegular(intent); |
|
|
|
if (intent.getMode() != null && |
|
|
|
!intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { |
|
|
|
if (response == null || StringUtils.isEmpty(response.getSkillCode())) { |
|
|
|
// 做场景1、2处理 |
|
|
|
if (!StringUtils.isEmpty(response.getMsg())) { |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
else { |
|
|
|
// 调用知识库 |
|
|
|
// 调用知识库问答 |
|
|
|
response.setSkillCode("30"); |
|
|
|
AjaxResult qaAjax = searchQA(intent); |
|
|
|
JSONObject qajson = qaAjax.toJson(); |
|
|
|
String content = ""; |
|
|
|
log.info("知识库问答返回结果:{}",qaAjax.toString()); |
|
|
|
if (qajson.containsKey("data") && qajson.getJSONObject("data").containsKey("result") && qajson.getJSONObject("data").size() > 0) { |
|
|
|
content = qajson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("knowledge_lib"); |
|
|
|
pushIntoDashboardRedis(enterpriseName,content,"knowledge"); |
|
|
|
response.setH5(JSONObject.from(qaAjax.get("data"))); |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
if (qajson.containsKey("data") && qajson.getJSONObject("data").getString("target").equals("0")) { |
|
|
|
// 知识库没有答案,返回空 |
|
|
|
response.clear(); |
|
|
|
response.setMsg(""); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(intent.getSkillCode())) { |
|
|
|
// 调用知识库问答 |
|
|
|
AjaxResult qaAjax = searchQA(intent); |
|
|
|
JSONObject qajson = qaAjax.toJson(); |
|
|
|
String content = ""; |
|
|
|
log.info("知识库问答返回结果:{}",qaAjax.toString()); |
|
|
|
if (qajson.containsKey("data") && qajson.getJSONObject("data").containsKey("result") && qajson.getJSONObject("data").size() > 0) { |
|
|
|
|
|
|
|
content = qajson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("knowledge_lib"); |
|
|
|
else { |
|
|
|
// 判断skill code的值 |
|
|
|
if (SkillType.BOOK_MEETING_ROOM.getCode().equals(intent.getSkillCode()) ) { |
|
|
|
if (!redisTemplate2.hasKey("group:device" + ":" + intent.getDevId() + ":" +"session")) { |
|
|
|
// 获取名称为"meeting-order"的BaseTemplate的实例 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:meeting", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName, "会议室预定", "skill"); |
|
|
|
} |
|
|
|
} else if (SkillType.CREATE_VISITOR_INFO.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 访客预定 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:create_visitor_info", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"访客邀约","skill"); |
|
|
|
} else if (SkillType.REGISTER_VISITOR.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 访客登记 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:register_visitor", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"陌生人登记","skill"); |
|
|
|
} else if (SkillType.BROADCAST_DISPLAY.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 播报展示 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:broadcast_display", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"播报展示","skill"); |
|
|
|
} else if (SkillType.OPEN_DOOR.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 开门记录 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:open_door", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"开门","skill"); |
|
|
|
} |
|
|
|
// 判断是否有权限 |
|
|
|
R<List<DmSkillDto>> skilllistInner = remoteskillService.skilllistInner(intent.getDevId(),"1",Long.parseLong(enterpriseId), source.getMaster(), SecurityConstants.INNER); |
|
|
|
if(skilllistInner.isOk()){ |
|
|
|
List<DmSkillDto> skilllist=skilllistInner.getData(); |
|
|
|
for (DmSkillDto dmSkillDto : skilllist) { |
|
|
|
if (dmSkillDto.getSkillCode().equals(response.getSkillCode())) { |
|
|
|
if(dmSkillDto.getStatus().equals("0")){ |
|
|
|
response.clear(); |
|
|
|
response.setMsg("操作无权限"); |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
// 为技能设置motion |
|
|
|
response.setMotion(dmSkillDto.getMotionName()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
switch (response.getSkillCode()) { |
|
|
|
case "1": |
|
|
|
// 做会议室处理 |
|
|
|
response.setH5(meetingOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.parseLong(SecurityContextHolder.getLocalMap().get("enterprise_id").toString()))); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
pushIntoDashboardRedis(enterpriseName,content,"knowledge"); |
|
|
|
return R.ok(JSONObject.from(qaAjax.get("data"))); |
|
|
|
} |
|
|
|
SkillType.BOOK_MEETING_ROOM.getCode(); |
|
|
|
// 判断skill code的值 |
|
|
|
if (SkillType.BOOK_MEETING_ROOM.getCode().equals(intent.getSkillCode()) ) { |
|
|
|
if (!redisTemplate2.hasKey("group:device" + ":" + intent.getDevId() + ":" +"session")) { |
|
|
|
// 获取名称为"meeting-order"的BaseTemplate的实例 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:meeting", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName, "会议室预定", "skill"); |
|
|
|
} |
|
|
|
joResult = meetingOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.parseLong(SecurityContextHolder.getLocalMap().get("enterprise_id").toString())); |
|
|
|
} else if (SkillType.CREATE_VISITOR_INFO.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 访客预定 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:create_visitor_info", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"访客邀约","skill"); |
|
|
|
} else if (SkillType.REGISTER_VISITOR.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 访客登记 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:register_visitor", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"陌生人登记","skill"); |
|
|
|
} else if (SkillType.BROADCAST_DISPLAY.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 播报展示 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:broadcast_display", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"播报展示","skill"); |
|
|
|
} else if (SkillType.OPEN_DOOR.getCode().equals(intent.getSkillCode())) { |
|
|
|
// 开门记录 |
|
|
|
redisTemplate.opsForValue().increment("dashboard:open_door", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName,"开门","skill"); |
|
|
|
else { |
|
|
|
// 闲聊 |
|
|
|
JSONObject joResult = freeChatTemplate.handle(intent.getDevId(),intent.getContent()); |
|
|
|
response.setH5(joResult); |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
return R.ok(joResult); |
|
|
|
|
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -495,10 +509,10 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
// 从列表中获取知识库任务 |
|
|
|
TaskKnowledgeVo vo = (TaskKnowledgeVo) redisTemplate2.opsForList().leftPop("group:task"); |
|
|
|
|
|
|
|
log.info("从缓存中获取对象:{}",vo.toString()); |
|
|
|
if (vo == null) { |
|
|
|
return R.ok(null,"没有任务"); |
|
|
|
} |
|
|
|
log.info("从缓存中获取对象:{}",vo.toString()); |
|
|
|
|
|
|
|
if (vo.getSplit() != SYS_DICT_DATA_SPLITED) { |
|
|
|
// 请开始你的表演 |
|
|
|
@@ -545,9 +559,16 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
列表 |
|
|
|
*/ |
|
|
|
@GetMapping("/getRecordList") |
|
|
|
public AjaxResult getRecordList(MarkRecordVo recordVo) { |
|
|
|
public AjaxResult getRecordList() { |
|
|
|
// 获取缓存nlt:record:origin前十的列表 |
|
|
|
Map<Object,Object> records = redisTemplate2.opsForHash().randomEntries("nlt:record:origin", 10); |
|
|
|
int size = redisTemplate2.opsForHash().size("nlt:record:origin").intValue(); |
|
|
|
Map<Object,Object> records = null; |
|
|
|
if (size < 10) { |
|
|
|
records = redisTemplate2.opsForHash().entries("nlt:record:origin"); |
|
|
|
} else { |
|
|
|
records = redisTemplate2.opsForHash().randomEntries("nlt:record:origin", 10); |
|
|
|
} |
|
|
|
|
|
|
|
if (records == null || records.isEmpty()) { |
|
|
|
return AjaxResult.success("没有数据"); |
|
|
|
} |
|
|
|
@@ -557,11 +578,12 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/commitRecord") |
|
|
|
public AjaxResult commitRecordList(MarkRecordVo recordVo) { |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult commitRecordList(@RequestBody MarkRecordVo recordVo) { |
|
|
|
// 获取缓存nlt:record:origin前十的列表 |
|
|
|
if (redisTemplate2.opsForHash().hasKey("nlt:record:origin",recordVo.getId())) { |
|
|
|
if (redisTemplate2.opsForHash().hasKey("nlt:record:origin",String.valueOf(recordVo.getId()))) { |
|
|
|
redisTemplate.opsForList().rightPush("nlt:record:marked", JSONObject.toJSONString(recordVo)); |
|
|
|
redisTemplate.opsForHash().delete("nlt:record:origin",recordVo.getId()); |
|
|
|
redisTemplate.opsForHash().delete("nlt:record:origin",String.valueOf(recordVo.getId())); |
|
|
|
} |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
@@ -682,6 +704,62 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isMatchRegular(String str,String regular) { |
|
|
|
Pattern pattern = Pattern.compile(regular); |
|
|
|
Matcher matcher = pattern.matcher(str); |
|
|
|
return matcher.find(); |
|
|
|
} |
|
|
|
|
|
|
|
private DmIntentResponse doMatchRegular(DmIntentVo intent) { |
|
|
|
DmIntentResponse response = new DmIntentResponse(); |
|
|
|
|
|
|
|
List <DmRegularPo> regularPos = regularMapper.selectList(null); |
|
|
|
|
|
|
|
|
|
|
|
for (DmRegularPo regularPo : regularPos) { |
|
|
|
if (isMatchRegular(intent.getContent(), regularPo.getExpression())) { |
|
|
|
response.setMsg(regularPo.getText()); |
|
|
|
response.setSkillCode(regularPo.getSkillCode()); |
|
|
|
response.setAction(regularPo.getAction()); |
|
|
|
response.setH5(regularPo.getJson()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//查询es,将满足条件的数据调用后续处理,不满足条件的返回原始数据 |
|
|
|
// SearchResponse<JSONObject> dateResponse = null; |
|
|
|
// List<Hit<JSONObject>> question_list = null; |
|
|
|
// try { |
|
|
|
// MatchQuery byName = MatchQuery.of(m->m.field("name").query(intent.getContent())); |
|
|
|
// dateResponse = esClient.search(builder -> builder |
|
|
|
// .index("regular_expression").query(q->q.match(byName)), |
|
|
|
// JSONObject.class); |
|
|
|
// question_list = dateResponse.hits().hits(); |
|
|
|
// log.info("esClient search result: {}", dateResponse); |
|
|
|
// }catch (IOException ie) { |
|
|
|
// log.error("esClient search error", ie); |
|
|
|
// return null; |
|
|
|
// } |
|
|
|
// for (Hit<JSONObject> jsonObjectHit : question_list) { |
|
|
|
// JSONObject jo = jsonObjectHit.source(); |
|
|
|
// Pattern pat = Pattern.compile(jo.get("name").toString()); |
|
|
|
// Matcher m = pat.matcher(intent.getContent()); |
|
|
|
// if (m.find()) { |
|
|
|
// |
|
|
|
// response.setMsg((jo.getString("answer"))); |
|
|
|
// // 如果包含Json数据并且json的skillCode字段不等于空 |
|
|
|
// if (jo.containsKey("json") && StringUtils.isNotEmpty(jo.getString("json"))) { |
|
|
|
// response.setSkillCode(jo.getString("skillCode")); |
|
|
|
// response.setH5(jo.getJSONObject("json")); |
|
|
|
// response.setAction(jo.getString("action")); |
|
|
|
// } |
|
|
|
// break; |
|
|
|
// } |
|
|
|
// } |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
interface Auth { |
|
|
|
/** 系统 - 意图管理 |
|
|
|
管理 - 列表 */ |
|
|
|
|