|
|
|
@@ -36,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; |
|
|
|
@@ -151,6 +153,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
RemoteEnterpriseService remoteEnterpriseService; |
|
|
|
@Autowired |
|
|
|
private ElasticsearchClient esClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DmRegularMapper regularMapper; |
|
|
|
/** |
|
|
|
* 意图请求 |
|
|
|
列表 |
|
|
|
@@ -219,7 +224,6 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//走知识库 |
|
|
|
R<DmIntentResponse> intentResponseR = remoteIntentService.conversationInner(intent, manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER); |
|
|
|
|
|
|
|
return AjaxResult.success(intentResponseR.getData()); |
|
|
|
@@ -550,9 +554,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("没有数据"); |
|
|
|
} |
|
|
|
@@ -562,11 +573,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(); |
|
|
|
} |
|
|
|
@@ -688,38 +700,58 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
//查询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")); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
|