Reviewed-on: http://39.105.23.186:3000/develop/digimeta-MultiSaas/pulls/38tags/B.1.2.1.0_20230822_base
| @@ -0,0 +1,29 @@ | |||
| package com.xueyi.nlt.api.nlt.domain.vo; | |||
| import lombok.Data; | |||
| import lombok.NoArgsConstructor; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @Data | |||
| @NoArgsConstructor | |||
| public class DmLandingLlmVo { | |||
| private String category; | |||
| private List<DmLlm> message = new ArrayList<>(); | |||
| @Data | |||
| @NoArgsConstructor | |||
| class DmLlm { | |||
| private String role; | |||
| private String content; | |||
| } | |||
| // 定义创建DmLlm的对象方法,并添加到message中 | |||
| public void addDmLlm(String role, String content) { | |||
| DmLlm dmLlm = new DmLlm(); | |||
| dmLlm.setRole(role); | |||
| dmLlm.setContent(content); | |||
| message.add(dmLlm); | |||
| } | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| package com.xueyi.nlt.api.nlt.feign; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.DmLandingLlmVo; | |||
| import com.xueyi.nlt.api.nlt.feign.factory.RemoteLandingLlmFallbackFactory; | |||
| import com.xueyi.nlt.api.nlt.feign.factory.RemoteQAFallbackFactory; | |||
| import org.springframework.cloud.openfeign.FeignClient; | |||
| import org.springframework.web.bind.annotation.*; | |||
| /** | |||
| * 问答服务 | |||
| * @Param man_id 机器人id | |||
| * @Param question 问题 | |||
| * @Param tenant_id 租户id | |||
| * @author yrx | |||
| */ | |||
| @FeignClient(url = "${notification.landing-llm.url}",name = "landing-llm", fallbackFactory = RemoteLandingLlmFallbackFactory.class) | |||
| public interface RemoteLandingLlmService { | |||
| @PostMapping("/search/questionAnswer") | |||
| @ResponseBody | |||
| JSONObject query(@RequestBody DmLandingLlmVo vo); | |||
| @PostMapping("/search/questionAnswer") | |||
| @ResponseBody | |||
| JSONObject query(@RequestBody JSONObject jsonObject); | |||
| } | |||
| @@ -0,0 +1,27 @@ | |||
| package com.xueyi.nlt.api.nlt.feign; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.nlt.api.nlt.feign.factory.RemoteQAFallbackFactory; | |||
| import com.xueyi.system.api.sms.domain.vo.SmsReqEntity; | |||
| import com.xueyi.system.api.sms.feign.factory.RemoteSmsFallbackFactory; | |||
| import org.springframework.cloud.openfeign.FeignClient; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestParam; | |||
| /** | |||
| * 问答服务 | |||
| * @Param man_id 机器人id | |||
| * @Param question 问题 | |||
| * @Param tenant_id 租户id | |||
| * @author yrx | |||
| */ | |||
| @FeignClient(url = "${notification.qa.url}",name = "qa", fallbackFactory = RemoteQAFallbackFactory.class) | |||
| public interface RemoteQAService { | |||
| @GetMapping("/knowledge") | |||
| AjaxResult query(@RequestParam(value = "man_code") String manCode, @RequestParam(value = "question") String question, @RequestParam(value = "tenant_id") Long tenantId); | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| package com.xueyi.nlt.api.nlt.feign.factory; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.DmLandingLlmVo; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteQAService; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.cloud.openfeign.FallbackFactory; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * 会议室服务 降级处理 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Slf4j | |||
| @Component | |||
| public class RemoteLandingLlmFallbackFactory implements FallbackFactory<RemoteLandingLlmService> { | |||
| @Override | |||
| public RemoteLandingLlmService create(Throwable throwable) { | |||
| log.error("短信服务调用失败:{}", throwable.getMessage()); | |||
| return new RemoteLandingLlmService() { | |||
| @Override | |||
| public JSONObject query(DmLandingLlmVo vo) { | |||
| JSONObject jsonObject = new JSONObject(); | |||
| jsonObject.put("status","fail"); | |||
| jsonObject.put("data",""); | |||
| return jsonObject; | |||
| } | |||
| @Override | |||
| public JSONObject query(JSONObject jsonObject) { | |||
| JSONObject jResult = new JSONObject(); | |||
| jResult.put("status","fail2"); | |||
| jResult.put("data",""); | |||
| return jResult; | |||
| } | |||
| }; | |||
| } | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| package com.xueyi.nlt.api.nlt.feign.factory; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteQAService; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.cloud.openfeign.FallbackFactory; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * 会议室服务 降级处理 | |||
| * | |||
| * @author xueyi | |||
| */ | |||
| @Slf4j | |||
| @Component | |||
| public class RemoteQAFallbackFactory implements FallbackFactory<RemoteQAService> { | |||
| @Override | |||
| public RemoteQAService create(Throwable throwable) { | |||
| log.error("短信服务调用失败:{}", throwable.getMessage()); | |||
| return new RemoteQAService() { | |||
| @Override | |||
| public AjaxResult query(String manCode, String question, Long tenantId) { | |||
| return AjaxResult.error("查询失败"); | |||
| } | |||
| }; | |||
| } | |||
| } | |||
| @@ -16,8 +16,11 @@ 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.DmLandingLlmVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.DmRecognitionVo; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteQAService; | |||
| import com.xueyi.nlt.netty.client.WebSocketClient; | |||
| import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | |||
| import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | |||
| @@ -28,6 +31,7 @@ import com.xueyi.nlt.nlt.service.IDmIntentService; | |||
| import com.xueyi.nlt.nlt.template.GenerativeKnowledgeTemplate; | |||
| import com.xueyi.nlt.nlt.template.MeetingOrderTemplate; | |||
| import com.xueyi.system.api.digitalmans.domain.dto.DmManDeviceDto; | |||
| import com.xueyi.system.api.digitalmans.feign.RemoteDigitalmanService; | |||
| import com.xueyi.system.api.digitalmans.feign.RemoteManDeviceService; | |||
| import com.xueyi.system.api.digitalmans.feign.RemoteQuestionanswersService; | |||
| import com.xueyi.system.api.model.Source; | |||
| @@ -93,6 +97,15 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| @Autowired | |||
| RemoteEnterpriseService enterpriseService; | |||
| @Autowired | |||
| RemoteLandingLlmService remoteLandingLlmService; | |||
| @Autowired | |||
| RemoteQAService remoteQAService; | |||
| @Autowired | |||
| RemoteDigitalmanService remoteDigitalmanService; | |||
| /** | |||
| * 意图请求 | |||
| 列表 | |||
| @@ -125,6 +138,8 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| public AjaxResult sayHelloApi(@RequestBody DmRecognitionVo recognition) { | |||
| log.info(recognition.toString()); | |||
| redisTemplate.opsForValue().increment("dashboard:recognition", 1); | |||
| redisTemplate.opsForValue().increment("dashboard:conversation-times", 1); | |||
| JSONObject joResult = new JSONObject(); | |||
| joResult.put("msg",""); | |||
| joResult.put("target",0); | |||
| @@ -144,21 +159,92 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| joResult.put("msg",jo.get("content")); | |||
| joResult.put("target",1); | |||
| redisTemplate.opsForHash().delete("group:nlp" + ":" + recognition.getPersonId(), "meeting"); | |||
| break; | |||
| redisTemplate.opsForValue().increment("dashboard:conversation-duration", jo.get("content").toString().length() / 4); | |||
| return AjaxResult.success(joResult); | |||
| } else if (Double.valueOf(String.valueOf(jo.get("timestamp"))) - System.currentTimeMillis() < 0) { | |||
| redisTemplate.opsForHash().delete("group:nlp" + ":" + recognition.getPersonId(), "meeting"); | |||
| } | |||
| } else { | |||
| joResult.put("msg",value); | |||
| redisTemplate.opsForValue().increment("dashboard:conversation-duration", value.toString().length() / 4); | |||
| joResult.put("target",1); | |||
| redisTemplate.opsForHash().delete("group:nlp" + ":" + recognition.getPersonId(),key); | |||
| break; | |||
| return AjaxResult.success(joResult); | |||
| } | |||
| } | |||
| } | |||
| redisTemplate.opsForValue().increment("dashboard:conversation-duration", 3); | |||
| return AjaxResult.success(joResult); | |||
| } | |||
| /** | |||
| * 知识库问答请求 | |||
| */ | |||
| @PostMapping("/api/searchQA") | |||
| @ResponseBody | |||
| public AjaxResult searchQA(@RequestBody DmIntentVo intent) { | |||
| log.info("交互对象:{}",intent.toString()); | |||
| redisTemplate.opsForValue().increment("dashboard:recognition", 1); | |||
| JSONObject joResult = new JSONObject(); | |||
| joResult.put("msg",""); | |||
| joResult.put("target",0); | |||
| DmLandingLlmVo vo = new DmLandingLlmVo(); | |||
| vo.setCategory("bj_unicom"); | |||
| vo.addDmLlm("user", intent.getContent()); | |||
| JSONObject testJ = new JSONObject(); | |||
| testJ.put("category","bj_unicom"); | |||
| JSONArray ja1 = new JSONArray(); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("role","user"); | |||
| jo.put("content",intent.getContent()); | |||
| ja1.add(jo); | |||
| testJ.put("messages",ja1); | |||
| R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); | |||
| Source source = SourceUtil.getSourceCache(manDeviceDtoR.getData().getStrategyId()); | |||
| return remoteQAService.query(manDeviceDtoR.getData().getManCode(),intent.getContent(),manDeviceDtoR.getData().getTenantId()); | |||
| // JSONArray ja = JSONArray.parseArray(resultJson.get("data").toString()); | |||
| // | |||
| // if (ja.size() > 0) { | |||
| // joResult.put("msg",ja.getJSONObject(0).get("text")); | |||
| // joResult.put("target",1); | |||
| // } | |||
| // return AjaxResult.success(joResult); | |||
| } | |||
| /** | |||
| * 联动北方大模型请求 | |||
| */ | |||
| @PostMapping("/api/searchQuestionAnswer") | |||
| @ResponseBody | |||
| public AjaxResult searchQuestionAnswer(@RequestBody DmIntentVo intent) { | |||
| log.info("交互对象:{}",intent.toString()); | |||
| redisTemplate.opsForValue().increment("dashboard:recognition", 1); | |||
| JSONObject joResult = new JSONObject(); | |||
| joResult.put("msg",""); | |||
| joResult.put("target",0); | |||
| DmLandingLlmVo vo = new DmLandingLlmVo(); | |||
| vo.setCategory("bj_unicom"); | |||
| vo.addDmLlm("user", intent.getContent()); | |||
| JSONObject testJ = new JSONObject(); | |||
| testJ.put("category","bj_unicom"); | |||
| JSONArray ja1 = new JSONArray(); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("role","user"); | |||
| jo.put("content",intent.getContent()); | |||
| ja1.add(jo); | |||
| testJ.put("messages",ja1); | |||
| JSONObject resultJson = remoteLandingLlmService.query(testJ); | |||
| JSONArray ja = resultJson.getJSONArray("data"); | |||
| if (ja.size() > 0) { | |||
| joResult.put("msg",ja.getJSONObject(0).get("text")); | |||
| joResult.put("target",1); | |||
| } | |||
| return AjaxResult.success(joResult); | |||
| } | |||
| /** | |||
| * 意图请求列表 | |||
| */ | |||
| @@ -166,6 +252,11 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| @ResponseBody | |||
| public R<JSONObject> conversationInner(@RequestBody DmIntentVo intent) { | |||
| JSONObject joResult = null; | |||
| if (StringUtils.isEmpty(intent.getSkillCode())) { | |||
| // 调用知识库问答 | |||
| AjaxResult qaAjax = searchQA(intent); | |||
| return R.ok(JSONObject.from(qaAjax.get("data"))); | |||
| } | |||
| SkillType.BOOK_MEETING_ROOM.getCode(); | |||
| // 判断skill code的值 | |||
| if (SkillType.BOOK_MEETING_ROOM.getCode().equals(intent.getSkillCode())) { | |||
| @@ -1,14 +1,21 @@ | |||
| package com.xueyi.system.digitalmans.manager.impl; | |||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
| import com.xueyi.system.digitalmans.domain.po.DmQAndAPo; | |||
| import com.xueyi.system.digitalmans.domain.po.DmQuestionsPo; | |||
| import com.xueyi.system.digitalmans.domain.dto.DmQuestionsDto; | |||
| import com.xueyi.system.digitalmans.domain.query.DmQuestionsQuery; | |||
| import com.xueyi.system.digitalmans.domain.model.DmQuestionsConverter; | |||
| import com.xueyi.system.digitalmans.mapper.DmQAndAMapper; | |||
| import com.xueyi.system.digitalmans.mapper.DmQuestionsMapper; | |||
| import com.xueyi.common.web.entity.manager.impl.BaseManagerImpl; | |||
| import com.xueyi.system.digitalmans.manager.IDmQuestionsManager; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| import java.io.Serializable; | |||
| import java.util.Collection; | |||
| /** | |||
| * 企业知识库问题管理 数据封装层处理 | |||
| * | |||
| @@ -16,4 +23,24 @@ import org.springframework.stereotype.Component; | |||
| */ | |||
| @Component | |||
| public class DmQuestionsManager extends BaseManagerImpl<DmQuestionsQuery, DmQuestionsDto, DmQuestionsPo, DmQuestionsMapper, DmQuestionsConverter> implements IDmQuestionsManager { | |||
| @Autowired | |||
| DmQAndAMapper dmQAndAMapper; | |||
| @Override | |||
| public int deleteByIds(Collection<? extends Serializable> idList) { | |||
| // 根据知识库id删除对应问题集 | |||
| idList.forEach(item->{ | |||
| dmQAndAMapper.delete(Wrappers.<DmQAndAPo>query().lambda().eq(DmQAndAPo::getKnowledgeId,item)); | |||
| }); | |||
| return super.deleteByIds(idList); | |||
| } | |||
| @Override | |||
| public int updateStatus(DmQuestionsDto dto) { | |||
| // 根据知识库id更新对应问题集状态 | |||
| // dmQAndAMapper.selectList(Wrappers.<DmQAndAPo>query().lambda().eq(DmQAndAPo::getKnowledgeId,dto.getId())).forEach(item->{ | |||
| // item.setStatus(dto.getStatus()); | |||
| // dmQAndAMapper.update(item); | |||
| // }; | |||
| return super.updateStatus(dto); | |||
| } | |||
| } | |||