| @@ -0,0 +1,19 @@ | |||
| package com.xueyi.nlt.api.nlt.domain.vo; | |||
| import lombok.Data; | |||
| import java.io.Serial; | |||
| @Data | |||
| public class HotspotVo { | |||
| @Serial | |||
| private static final long serialVersionUID = 1L; | |||
| protected String title; | |||
| protected String content; | |||
| protected String label; | |||
| protected Long timestamp; | |||
| } | |||
| @@ -1,19 +1,20 @@ | |||
| package com.xueyi.nlt.api.nlt.feign; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.core.constant.basic.SecurityConstants; | |||
| import com.xueyi.common.core.constant.basic.ServiceConstants; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.common.core.web.result.R; | |||
| import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | |||
| import com.xueyi.nlt.api.nlt.feign.factory.RemoteIntentFallbackFactory; | |||
| import org.springframework.cloud.openfeign.FeignClient; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestHeader; | |||
| import org.springframework.web.bind.annotation.ResponseBody; | |||
| import java.util.List; | |||
| @FeignClient(contextId = "remoteIntentService", value = ServiceConstants.NLT_SERVICE, fallbackFactory = RemoteIntentFallbackFactory.class) | |||
| public interface RemoteIntentService { | |||
| @@ -29,4 +30,10 @@ public interface RemoteIntentService { | |||
| @PostMapping("/intent/inner/generateContextTask") | |||
| public AjaxResult generateContextTask(); | |||
| @PostMapping("/intent/inner/syncHotspot") | |||
| public AjaxResult syncHotspot(); | |||
| @PostMapping("/intent/inner/collectHotspot") | |||
| public AjaxResult collectHotspot(@RequestBody List<HotspotVo> hotspotVo); | |||
| } | |||
| @@ -0,0 +1,19 @@ | |||
| package com.xueyi.job.task; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| @Component("dmGenerativeKnowledgeTask") | |||
| public class DmSyncHotspotsTask { | |||
| private static final Logger log = LoggerFactory.getLogger(DmSyncHotspotsTask.class); | |||
| @Autowired | |||
| private RemoteIntentService remoteIntentService; | |||
| public void syncHotspot() { | |||
| log.info("定时任务调度测试:向数字人下发实时热点"); | |||
| remoteIntentService.syncHotspot(); | |||
| } | |||
| } | |||
| @@ -24,13 +24,8 @@ import com.xueyi.common.security.annotation.RequiresPermissions; | |||
| import com.xueyi.common.security.utils.SecurityUtils; | |||
| 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; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.DmRecognitionVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.KnowledgeVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.TaskKnowledgeVo; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmKnowledgeResponse; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | |||
| import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; | |||
| @@ -46,11 +41,9 @@ import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | |||
| import com.xueyi.nlt.nlt.domain.dto.DmSensitiveWordDto; | |||
| import com.xueyi.nlt.nlt.domain.po.DmRegularPo; | |||
| import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | |||
| import com.xueyi.nlt.nlt.domain.vo.DmKnowledgeLibAskVo; | |||
| import com.xueyi.nlt.nlt.domain.vo.IntentTemplateVo; | |||
| import com.xueyi.nlt.nlt.domain.vo.MarkRecordVo; | |||
| import com.xueyi.nlt.nlt.domain.vo.NLPLogVo; | |||
| import com.xueyi.nlt.nlt.domain.vo.*; | |||
| import com.xueyi.nlt.nlt.mapper.DmRegularMapper; | |||
| import com.xueyi.nlt.nlt.service.IDmHotspotService; | |||
| import com.xueyi.nlt.nlt.service.IDmIntentService; | |||
| import com.xueyi.nlt.nlt.service.ISensitiveService; | |||
| import com.xueyi.nlt.nlt.service.ISysLlmService; | |||
| @@ -183,6 +176,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| @Autowired | |||
| private ISysLlmService sysLlmService; | |||
| @Autowired | |||
| private IDmHotspotService dmHotspotService; | |||
| @Autowired | |||
| MqttTemplate mqttTemplate; | |||
| @@ -1173,6 +1169,35 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||
| return success(); | |||
| } | |||
| @PostMapping("/inner/syncHotspot") | |||
| @ResponseBody | |||
| public AjaxResult syncHotspot(){ | |||
| return dmHotspotService.syncHotspot(); | |||
| } | |||
| @PostMapping("/inner/collectHotspot") | |||
| @ResponseBody | |||
| public AjaxResult collectHotspot(@RequestBody List<HotspotVo> hotspotVo){ | |||
| return dmHotspotService.collectHotspot(hotspotVo); | |||
| } | |||
| @PostMapping("/api/updateHotspot") | |||
| @ResponseBody | |||
| public AjaxResult updateHotspot(@RequestBody JSONObject hotspotData){ | |||
| if(hotspotData == null||hotspotData.isEmpty()||!hotspotData.containsKey("data")){ | |||
| return AjaxResult.error("上传热点新闻失败"); | |||
| } | |||
| log.info(hotspotData.getString("data")); | |||
| List<HotspotVo> hotspotVoList = hotspotData.getList("data",HotspotVo.class); | |||
| return dmHotspotService.collectHotspot(hotspotVoList); | |||
| } | |||
| @PostMapping("/api/testForHotspot") | |||
| public AjaxResult testForHotspot(){ | |||
| return dmHotspotService.syncHotspot(); | |||
| } | |||
| interface Auth { | |||
| /** 系统 - 意图管理 | |||
| 管理 - 列表 */ | |||
| @@ -0,0 +1,13 @@ | |||
| package com.xueyi.nlt.nlt.service; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||
| import java.util.List; | |||
| public interface IDmHotspotService { | |||
| public AjaxResult syncHotspot(); | |||
| public AjaxResult collectHotspot(List<HotspotVo> hotspotVo); | |||
| } | |||
| @@ -0,0 +1,61 @@ | |||
| package com.xueyi.nlt.nlt.service.impl; | |||
| import com.alibaba.fastjson2.JSONArray; | |||
| import com.alibaba.fastjson2.JSONObject; | |||
| import com.xueyi.common.core.web.result.AjaxResult; | |||
| import com.xueyi.common.mqtt.connection.MqttTemplate; | |||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||
| import com.xueyi.nlt.nlt.service.IDmHotspotService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.context.annotation.Primary; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Service; | |||
| import java.time.LocalDateTime; | |||
| import java.time.format.DateTimeFormatter; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Service | |||
| @Primary | |||
| public class DmHotspotServiceImpl implements IDmHotspotService { | |||
| private static final Logger log = LoggerFactory.getLogger(DmHotspotServiceImpl.class); | |||
| @Autowired | |||
| RedisTemplate<Object,Object> redisTemplate; | |||
| @Autowired | |||
| MqttTemplate mqttTemplate; | |||
| @Value("${spring.profiles.active}") | |||
| private String activeProfile; | |||
| @Override | |||
| public AjaxResult syncHotspot() { | |||
| LocalDateTime dateTime = LocalDateTime.now(); | |||
| String date = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | |||
| String result = (String) redisTemplate.opsForHash().get("group:task:hotspot", date); | |||
| log.info(result); | |||
| JSONArray resultArray = JSONArray.parseArray(result); | |||
| resultArray.stream().forEach(item -> JSONObject.from(item).remove("content")); | |||
| Map<Object, Object> devices = redisTemplate.opsForHash().entries("group:dgman:device:"); | |||
| for(Object devId:devices.keySet()){ | |||
| mqttTemplate.sendToMqtt("/" + activeProfile + "/" + "digital_man" + "/" + devId.toString() + "/" + "notify" + "/" + "generate-hotspot", true, AjaxResult.success(resultArray).toJson().toJSONString()); | |||
| } | |||
| return AjaxResult.success(); | |||
| } | |||
| @Override | |||
| public AjaxResult collectHotspot(List<HotspotVo> hotspotVoList) { | |||
| LocalDateTime dateTime = LocalDateTime.now(); | |||
| String date = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | |||
| Long timestamp = System.currentTimeMillis(); | |||
| hotspotVoList.stream().forEach(hotspotVo -> hotspotVo.setTimestamp(timestamp)); | |||
| redisTemplate.opsForHash().put("group:task:hotspot", date, JSONArray.from(hotspotVoList).toJSONString()); | |||
| return AjaxResult.success(); | |||
| } | |||
| } | |||