| @@ -1,11 +1,10 @@ | |||||
| package com.xueyi.nlt.nlt.manager; | package com.xueyi.nlt.nlt.manager; | ||||
| import com.xueyi.common.web.entity.manager.IBaseManager; | import com.xueyi.common.web.entity.manager.IBaseManager; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | ||||
| import com.xueyi.nlt.nlt.domain.dto.DmRegularDto; | import com.xueyi.nlt.nlt.domain.dto.DmRegularDto; | ||||
| import com.xueyi.nlt.nlt.domain.query.DmRegularQuery; | import com.xueyi.nlt.nlt.domain.query.DmRegularQuery; | ||||
| public interface IDmRegularManager extends IBaseManager<DmRegularQuery, DmRegularDto> { | public interface IDmRegularManager extends IBaseManager<DmRegularQuery, DmRegularDto> { | ||||
| public DmIntentResponse doRegularMatch(DmIntentVo intent); | |||||
| public DmIntentResponse doRegularMatch(String content); | |||||
| } | } | ||||
| @@ -2,7 +2,6 @@ package com.xueyi.nlt.nlt.manager.impl; | |||||
| import com.xueyi.common.web.entity.manager.impl.BaseManagerImpl; | import com.xueyi.common.web.entity.manager.impl.BaseManagerImpl; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | ||||
| import com.xueyi.nlt.nlt.domain.model.DmRegularConverter; | import com.xueyi.nlt.nlt.domain.model.DmRegularConverter; | ||||
| import com.xueyi.nlt.nlt.domain.po.DmRegularPo; | import com.xueyi.nlt.nlt.domain.po.DmRegularPo; | ||||
| @@ -19,11 +18,11 @@ import java.util.regex.Pattern; | |||||
| @Component | @Component | ||||
| public class DmRegularManager extends BaseManagerImpl<DmRegularQuery, DmRegularDto, DmRegularPo, DmRegularMapper, DmRegularConverter> implements IDmRegularManager { | public class DmRegularManager extends BaseManagerImpl<DmRegularQuery, DmRegularDto, DmRegularPo, DmRegularMapper, DmRegularConverter> implements IDmRegularManager { | ||||
| @Override | @Override | ||||
| public DmIntentResponse doRegularMatch(DmIntentVo intent) { | |||||
| public DmIntentResponse doRegularMatch(String content) { | |||||
| DmIntentResponse response = new DmIntentResponse(); | DmIntentResponse response = new DmIntentResponse(); | ||||
| List<DmRegularPo> regularPos =baseMapper.selectList(null); | List<DmRegularPo> regularPos =baseMapper.selectList(null); | ||||
| for (DmRegularPo regularPo : regularPos) { | for (DmRegularPo regularPo : regularPos) { | ||||
| if (isMatchRegular(intent.getContent(), regularPo.getExpression())) { | |||||
| if (isMatchRegular(content, regularPo.getExpression())) { | |||||
| response.setMsg(regularPo.getText()); | response.setMsg(regularPo.getText()); | ||||
| response.setSkillCode(regularPo.getSkillCode()); | response.setSkillCode(regularPo.getSkillCode()); | ||||
| response.setAction(regularPo.getAction()); | response.setAction(regularPo.getAction()); | ||||
| @@ -1,8 +1,11 @@ | |||||
| package com.xueyi.nlt.nlt.service; | package com.xueyi.nlt.nlt.service; | ||||
| import com.xueyi.common.web.entity.service.IBaseService; | import com.xueyi.common.web.entity.service.IBaseService; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | |||||
| import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | ||||
| import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | ||||
| public interface IDmIntentService extends IBaseService<DmIntentQuery, DmIntentDto> { | public interface IDmIntentService extends IBaseService<DmIntentQuery, DmIntentDto> { | ||||
| DmIntentResponse conversation(DmIntentVo intent); | |||||
| } | } | ||||
| @@ -0,0 +1,10 @@ | |||||
| package com.xueyi.nlt.nlt.service; | |||||
| import com.xueyi.common.web.entity.service.IBaseService; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | |||||
| import com.xueyi.nlt.nlt.domain.dto.DmRegularDto; | |||||
| import com.xueyi.nlt.nlt.domain.query.DmRegularQuery; | |||||
| public interface IDmRegularService extends IBaseService<DmRegularQuery, DmRegularDto> { | |||||
| DmIntentResponse doRegularMatch(String content); | |||||
| } | |||||
| @@ -1,12 +1,242 @@ | |||||
| package com.xueyi.nlt.nlt.service.impl; | package com.xueyi.nlt.nlt.service.impl; | ||||
| import com.alibaba.fastjson2.JSONObject; | |||||
| import com.baomidou.mybatisplus.core.toolkit.StringUtils; | |||||
| import com.xueyi.common.cache.utils.SourceUtil; | |||||
| import com.xueyi.common.core.constant.basic.SecurityConstants; | |||||
| import com.xueyi.common.core.constant.digitalman.MessageConstants; | |||||
| import com.xueyi.common.core.constant.digitalman.SkillConstants; | |||||
| import com.xueyi.common.core.utils.core.IdUtil; | |||||
| import com.xueyi.common.core.web.result.R; | |||||
| import com.xueyi.common.web.entity.service.impl.BaseServiceImpl; | import com.xueyi.common.web.entity.service.impl.BaseServiceImpl; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.KnowledgeVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmKnowledgeResponse; | |||||
| import com.xueyi.nlt.api.nlt.feign.RemoteQAService; | |||||
| import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | ||||
| import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | ||||
| import com.xueyi.nlt.nlt.domain.vo.MarkRecordVo; | |||||
| import com.xueyi.nlt.nlt.manager.IDmIntentManager; | import com.xueyi.nlt.nlt.manager.IDmIntentManager; | ||||
| import com.xueyi.nlt.nlt.manager.impl.DmRegularManager; | |||||
| import com.xueyi.nlt.nlt.service.IDmIntentService; | import com.xueyi.nlt.nlt.service.IDmIntentService; | ||||
| import com.xueyi.nlt.nlt.template.DeliveryOrderTemplate; | |||||
| import com.xueyi.nlt.nlt.template.FlightMessageTemplate; | |||||
| import com.xueyi.nlt.nlt.template.FreeChatTemplate; | |||||
| import com.xueyi.nlt.nlt.template.MeetingOrderTemplate; | |||||
| import com.xueyi.system.api.digitalmans.domain.dto.DmManDeviceDto; | |||||
| import com.xueyi.system.api.digitalmans.domain.dto.DmSkillDto; | |||||
| import com.xueyi.system.api.digitalmans.feign.RemoteManDeviceService; | |||||
| import com.xueyi.system.api.digitalmans.feign.RemoteSkillService; | |||||
| import com.xueyi.system.api.model.Source; | |||||
| import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto; | |||||
| import com.xueyi.system.api.organize.feign.RemoteEnterpriseService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.time.LocalDateTime; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| @Service | @Service | ||||
| public class DmIntentServiceImpl extends BaseServiceImpl<DmIntentQuery, DmIntentDto, IDmIntentManager> implements IDmIntentService { | public class DmIntentServiceImpl extends BaseServiceImpl<DmIntentQuery, DmIntentDto, IDmIntentManager> implements IDmIntentService { | ||||
| private static final Logger log = LoggerFactory.getLogger(DmIntentServiceImpl.class); | |||||
| @Autowired | |||||
| RemoteEnterpriseService remoteEnterpriseService; | |||||
| @Autowired | |||||
| private DmRegularManager regularManager; | |||||
| @Autowired | |||||
| private RemoteManDeviceService manDeviceService; | |||||
| @Autowired | |||||
| private RemoteQAService remoteQAService; | |||||
| @Autowired | |||||
| private StringRedisTemplate redisTemplate; | |||||
| @Autowired | |||||
| private RedisTemplate<Object,Object> redisTemplate2; | |||||
| @Autowired | |||||
| private MeetingOrderTemplate meetingOrderTemplate; | |||||
| @Autowired | |||||
| private DeliveryOrderTemplate deliveryOrderTemplate; | |||||
| @Autowired | |||||
| private FreeChatTemplate freeChatTemplate; | |||||
| @Autowired | |||||
| private RemoteSkillService remoteskillService; | |||||
| @Autowired | |||||
| private FlightMessageTemplate flightMessageTemplate; | |||||
| @Override | |||||
| public DmIntentResponse conversation(DmIntentVo intent) { | |||||
| MarkRecordVo recordVo = new MarkRecordVo(); | |||||
| recordVo.setDevId(intent.getDevId()); | |||||
| recordVo.setId(IdUtil.getSnowflakeNextId()); | |||||
| recordVo.setCreateTime(LocalDateTime.now()); | |||||
| recordVo.setQuestion(intent.getContent()); | |||||
| recordVo.setHit(1); | |||||
| R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); | |||||
| String enterpriseId = manDeviceDtoR.getData().getTId().toString(); | |||||
| String enterpriseName = ""; | |||||
| R<SysEnterpriseDto> enterpriseDtoR = remoteEnterpriseService.getInfo(Long.valueOf(enterpriseId)); | |||||
| Source source = SourceUtil.getSourceCache(enterpriseDtoR.getData().getStrategyId()); | |||||
| if (enterpriseDtoR.isOk()) { | |||||
| enterpriseName = enterpriseDtoR.getData().getName(); | |||||
| } | |||||
| // 正则技能匹配 | |||||
| DmIntentResponse response = regularManager.doRegularMatch(intent.getContent()); | |||||
| if (response != null && StringUtils.isNotEmpty(response.getSkillCode())){ | |||||
| sendToDashboard(intent, enterpriseName); | |||||
| // 判断是否有权限 | |||||
| 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 response; | |||||
| } | |||||
| // 为技能设置motion | |||||
| response.setMotion(dmSkillDto.getMotionName()); | |||||
| } | |||||
| } | |||||
| } | |||||
| switch (response.getSkillCode()) { | |||||
| case "1": | |||||
| // 做会议室处理 | |||||
| response.setH5(meetingOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.valueOf(enterpriseId))); | |||||
| break; | |||||
| case "33": | |||||
| // 做快递预约处理 | |||||
| response.setH5(deliveryOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.valueOf(enterpriseId))); | |||||
| break; | |||||
| case "34": | |||||
| // 做查询航班信息处理 | |||||
| response.setH5(flightMessageTemplate.handle(intent.getDevId(), intent.getContent(), Long.valueOf(enterpriseId))); | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| else if(response != null && StringUtils.isNotEmpty(response.getMsg())){ | |||||
| // 记录log | |||||
| recordVo.setType(2); | |||||
| List answers = new ArrayList(); | |||||
| answers.add(response.getMsg()); | |||||
| recordVo.setAnswers(answers); | |||||
| return response; | |||||
| } | |||||
| else{ | |||||
| // 调用知识库问答 | |||||
| response.setSkillCode("30"); | |||||
| DmKnowledgeResponse qaAjax = null; | |||||
| KnowledgeVo knowledgeVo = new KnowledgeVo(); | |||||
| knowledgeVo.setManCode(manDeviceDtoR.getData().getManCode()); | |||||
| knowledgeVo.setTenantId(manDeviceDtoR.getData().getTId()); | |||||
| knowledgeVo.setQuestion(intent.getContent()); | |||||
| R<DmKnowledgeResponse> dmKnowledgeResponseR = remoteQAService.query(knowledgeVo); | |||||
| if (dmKnowledgeResponseR!= null && dmKnowledgeResponseR.getData() != null) { | |||||
| qaAjax = dmKnowledgeResponseR.getData(); | |||||
| } | |||||
| String content = ""; | |||||
| if (qaAjax != null) { | |||||
| log.info("知识库问答返回结果:{}",qaAjax.toString()); | |||||
| if (qaAjax.getTarget() == 1) { | |||||
| content = qaAjax.getResult().get(0).getKnowledgeLib(); | |||||
| pushIntoDashboardRedis(enterpriseName,content,"knowledge"); | |||||
| response.setH5(JSONObject.from(qaAjax)); | |||||
| // 记录log | |||||
| recordVo.setType(2); | |||||
| List answers = new ArrayList(); | |||||
| answers.add(response.getMsg()); | |||||
| recordVo.setAnswers(answers); // 航班查询 | |||||
| return response; | |||||
| } | |||||
| else { | |||||
| // 知识库没有答案,返回空 | |||||
| response.clear(); | |||||
| response.setMsg(""); | |||||
| } | |||||
| } | |||||
| } | |||||
| if(StringUtils.isEmpty(response.getSkillCode()) && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { | |||||
| JSONObject joResult = freeChatTemplate.handle(intent.getDevId(),intent.getContent()); | |||||
| response.setH5(joResult); | |||||
| } | |||||
| return response; | |||||
| } | |||||
| private int pushIntoDashboardRedis(String name,String content,String type) { | |||||
| try { | |||||
| JSONObject object = new JSONObject(); | |||||
| object.put("tenantName", name); | |||||
| object.put("content", content); | |||||
| if (type.equals("skill")) { | |||||
| redisTemplate2.opsForList().leftPush("dashboard:skill-consume", object.toJSONString()); | |||||
| } else if (type.equals("knowledge")) { | |||||
| redisTemplate2.opsForList().leftPush("dashboard:knowledge-consume", object.toJSONString()); | |||||
| } | |||||
| return 1; | |||||
| } catch (Exception e) { | |||||
| log.error("推送到仪表盘失败:{}",e.getMessage()); | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| private void sendToDashboard(DmIntentVo intent, String enterpriseName) { | |||||
| if (SkillConstants.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 (SkillConstants.SkillType.CREATE_VISITOR_INFO.getCode().equals(intent.getSkillCode())) { | |||||
| // 访客预定 | |||||
| redisTemplate.opsForValue().increment("dashboard:create_visitor_info", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"访客邀约","skill"); | |||||
| } else if (SkillConstants.SkillType.REGISTER_VISITOR.getCode().equals(intent.getSkillCode())) { | |||||
| // 访客登记 | |||||
| redisTemplate.opsForValue().increment("dashboard:register_visitor", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"陌生人登记","skill"); | |||||
| } else if (SkillConstants.SkillType.BROADCAST_DISPLAY.getCode().equals(intent.getSkillCode())) { | |||||
| // 播报展示 | |||||
| redisTemplate.opsForValue().increment("dashboard:broadcast_display", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"播报展示","skill"); | |||||
| } else if (SkillConstants.SkillType.OPEN_DOOR.getCode().equals(intent.getSkillCode())) { | |||||
| // 开门记录 | |||||
| redisTemplate.opsForValue().increment("dashboard:open_door", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"开门","skill"); | |||||
| }else if (SkillConstants.SkillType.DELIVERY.getCode().equals(intent.getSkillCode()) ) { | |||||
| if (!redisTemplate2.hasKey("group:device" + ":" + intent.getDevId() + ":" + "session")) { | |||||
| // 获取名称为"meeting-order"的BaseTemplate的实例 | |||||
| redisTemplate.opsForValue().increment("dashboard:delivery", 1); | |||||
| pushIntoDashboardRedis(enterpriseName, "寄快递", "skill"); | |||||
| } | |||||
| }else if (SkillConstants.SkillType.FLIGHT.getCode().equals(intent.getSkillCode()) ) { | |||||
| redisTemplate.opsForValue().increment("dashboard:flight", 1); | |||||
| pushIntoDashboardRedis(enterpriseName, "查询航班信息", "skill"); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -41,200 +41,8 @@ import java.util.List; | |||||
| @Service | @Service | ||||
| public class DmNltServiceImpl implements IDmNltService { | public class DmNltServiceImpl implements IDmNltService { | ||||
| private static final Logger log = LoggerFactory.getLogger(DmNltServiceImpl.class); | |||||
| @Autowired | |||||
| RemoteEnterpriseService remoteEnterpriseService; | |||||
| @Autowired | |||||
| private DmRegularManager regularManager; | |||||
| @Autowired | |||||
| private RemoteManDeviceService manDeviceService; | |||||
| @Autowired | |||||
| private RemoteQAService remoteQAService; | |||||
| @Autowired | |||||
| private StringRedisTemplate redisTemplate; | |||||
| @Autowired | |||||
| private RedisTemplate<Object,Object> redisTemplate2; | |||||
| @Autowired | |||||
| private MeetingOrderTemplate meetingOrderTemplate; | |||||
| @Autowired | |||||
| private DeliveryOrderTemplate deliveryOrderTemplate; | |||||
| @Autowired | |||||
| private FreeChatTemplate freeChatTemplate; | |||||
| @Autowired | |||||
| private RemoteSkillService remoteskillService; | |||||
| @Autowired | |||||
| private FlightMessageTemplate flightMessageTemplate; | |||||
| @Override | @Override | ||||
| public R<DmIntentResponse> conversation(DmIntentVo intent) { | public R<DmIntentResponse> conversation(DmIntentVo intent) { | ||||
| MarkRecordVo recordVo = new MarkRecordVo(); | |||||
| recordVo.setDevId(intent.getDevId()); | |||||
| recordVo.setId(IdUtil.getSnowflakeNextId()); | |||||
| recordVo.setCreateTime(LocalDateTime.now()); | |||||
| recordVo.setQuestion(intent.getContent()); | |||||
| recordVo.setHit(1); | |||||
| R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); | |||||
| String enterpriseId = manDeviceDtoR.getData().getTId().toString(); | |||||
| String enterpriseName = ""; | |||||
| R<SysEnterpriseDto> enterpriseDtoR = remoteEnterpriseService.getInfo(Long.valueOf(enterpriseId)); | |||||
| Source source = SourceUtil.getSourceCache(enterpriseDtoR.getData().getStrategyId()); | |||||
| if (enterpriseDtoR.isOk()) { | |||||
| enterpriseName = enterpriseDtoR.getData().getName(); | |||||
| } | |||||
| // 正则技能匹配 | |||||
| DmIntentResponse response = regularManager.doRegularMatch(intent); | |||||
| if (response != null && StringUtils.isNotEmpty(response.getSkillCode())){ | |||||
| sendToDashboard(intent, enterpriseName); | |||||
| // 判断是否有权限 | |||||
| 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.valueOf(enterpriseId))); | |||||
| break; | |||||
| case "33": | |||||
| // 做快递预约处理 | |||||
| response.setH5(deliveryOrderTemplate.handle(intent.getDevId(), intent.getContent(), Long.valueOf(enterpriseId))); | |||||
| break; | |||||
| case "34": | |||||
| // 做查询航班信息处理 | |||||
| response.setH5(flightMessageTemplate.handle(intent.getDevId(), intent.getContent(), Long.valueOf(enterpriseId))); | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| else if(response != null && StringUtils.isNotEmpty(response.getMsg())){ | |||||
| // 记录log | |||||
| recordVo.setType(2); | |||||
| List answers = new ArrayList(); | |||||
| answers.add(response.getMsg()); | |||||
| recordVo.setAnswers(answers); | |||||
| return R.ok(response); | |||||
| } | |||||
| else{ | |||||
| // 调用知识库问答 | |||||
| response.setSkillCode("30"); | |||||
| DmKnowledgeResponse qaAjax = null; | |||||
| KnowledgeVo knowledgeVo = new KnowledgeVo(); | |||||
| knowledgeVo.setManCode(manDeviceDtoR.getData().getManCode()); | |||||
| knowledgeVo.setTenantId(manDeviceDtoR.getData().getTId()); | |||||
| knowledgeVo.setQuestion(intent.getContent()); | |||||
| R<DmKnowledgeResponse> dmKnowledgeResponseR = remoteQAService.query(knowledgeVo); | |||||
| if (dmKnowledgeResponseR!= null && dmKnowledgeResponseR.getData() != null) { | |||||
| qaAjax = dmKnowledgeResponseR.getData(); | |||||
| } | |||||
| String content = ""; | |||||
| if (qaAjax != null) { | |||||
| log.info("知识库问答返回结果:{}",qaAjax.toString()); | |||||
| if (qaAjax.getTarget() == 1) { | |||||
| content = qaAjax.getResult().get(0).getKnowledgeLib(); | |||||
| pushIntoDashboardRedis(enterpriseName,content,"knowledge"); | |||||
| response.setH5(JSONObject.from(qaAjax)); | |||||
| // 记录log | |||||
| recordVo.setType(2); | |||||
| List answers = new ArrayList(); | |||||
| answers.add(response.getMsg()); | |||||
| recordVo.setAnswers(answers); // 航班查询 | |||||
| return R.ok(response); | |||||
| } | |||||
| else { | |||||
| // 知识库没有答案,返回空 | |||||
| response.clear(); | |||||
| response.setMsg(""); | |||||
| } | |||||
| } | |||||
| } | |||||
| if(StringUtils.isEmpty(response.getSkillCode()) && intent.getMode().equals(MessageConstants.MODE_FREE_CHAT)) { | |||||
| JSONObject joResult = freeChatTemplate.handle(intent.getDevId(),intent.getContent()); | |||||
| response.setH5(joResult); | |||||
| } | |||||
| return R.ok(response); | |||||
| } | |||||
| private int pushIntoDashboardRedis(String name,String content,String type) { | |||||
| try { | |||||
| JSONObject object = new JSONObject(); | |||||
| object.put("tenantName", name); | |||||
| object.put("content", content); | |||||
| if (type.equals("skill")) { | |||||
| redisTemplate2.opsForList().leftPush("dashboard:skill-consume", object.toJSONString()); | |||||
| } else if (type.equals("knowledge")) { | |||||
| redisTemplate2.opsForList().leftPush("dashboard:knowledge-consume", object.toJSONString()); | |||||
| } | |||||
| return 1; | |||||
| } catch (Exception e) { | |||||
| log.error("推送到仪表盘失败:{}",e.getMessage()); | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| private void sendToDashboard(DmIntentVo intent, String enterpriseName) { | |||||
| if (SkillConstants.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 (SkillConstants.SkillType.CREATE_VISITOR_INFO.getCode().equals(intent.getSkillCode())) { | |||||
| // 访客预定 | |||||
| redisTemplate.opsForValue().increment("dashboard:create_visitor_info", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"访客邀约","skill"); | |||||
| } else if (SkillConstants.SkillType.REGISTER_VISITOR.getCode().equals(intent.getSkillCode())) { | |||||
| // 访客登记 | |||||
| redisTemplate.opsForValue().increment("dashboard:register_visitor", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"陌生人登记","skill"); | |||||
| } else if (SkillConstants.SkillType.BROADCAST_DISPLAY.getCode().equals(intent.getSkillCode())) { | |||||
| // 播报展示 | |||||
| redisTemplate.opsForValue().increment("dashboard:broadcast_display", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"播报展示","skill"); | |||||
| } else if (SkillConstants.SkillType.OPEN_DOOR.getCode().equals(intent.getSkillCode())) { | |||||
| // 开门记录 | |||||
| redisTemplate.opsForValue().increment("dashboard:open_door", 1); | |||||
| pushIntoDashboardRedis(enterpriseName,"开门","skill"); | |||||
| }else if (SkillConstants.SkillType.DELIVERY.getCode().equals(intent.getSkillCode()) ) { | |||||
| if (!redisTemplate2.hasKey("group:device" + ":" + intent.getDevId() + ":" + "session")) { | |||||
| // 获取名称为"meeting-order"的BaseTemplate的实例 | |||||
| redisTemplate.opsForValue().increment("dashboard:delivery", 1); | |||||
| pushIntoDashboardRedis(enterpriseName, "寄快递", "skill"); | |||||
| } | |||||
| }else if (SkillConstants.SkillType.FLIGHT.getCode().equals(intent.getSkillCode()) ) { | |||||
| redisTemplate.opsForValue().increment("dashboard:flight", 1); | |||||
| pushIntoDashboardRedis(enterpriseName, "查询航班信息", "skill"); | |||||
| } | |||||
| return null; | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| package com.xueyi.nlt.nlt.service.impl; | |||||
| import com.xueyi.common.web.entity.service.impl.BaseServiceImpl; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | |||||
| import com.xueyi.nlt.nlt.domain.query.DmRegularQuery; | |||||
| import com.xueyi.nlt.nlt.domain.dto.DmRegularDto; | |||||
| import com.xueyi.nlt.nlt.manager.IDmRegularManager; | |||||
| import com.xueyi.nlt.nlt.service.IDmRegularService; | |||||
| public class DmRegularServiceImpl extends BaseServiceImpl<DmRegularQuery, DmRegularDto, IDmRegularManager> implements IDmRegularService { | |||||
| @Override | |||||
| public DmIntentResponse doRegularMatch(String content) { | |||||
| return baseManager.doRegularMatch(content); | |||||
| } | |||||
| } | |||||