|
|
@@ -14,19 +14,11 @@ import com.github.therapi.runtimejavadoc.repack.com.eclipsesource.json.JsonObjec
|
|
|
import com.inspur.device.domain.vo.DifyDatasetsFileRspData;
|
|
|
import com.inspur.device.domain.vo.SmsbDeviceGroupRelVo;
|
|
|
import com.inspur.device.mapper.SmsbDeviceGroupRelMapper;
|
|
|
-import com.inspur.digital.domain.SmsbAppointmentInfo;
|
|
|
-import com.inspur.digital.domain.SmsbDeviceChatScCase;
|
|
|
-import com.inspur.digital.domain.SmsbDeviceChatScProduct;
|
|
|
-import com.inspur.digital.domain.SmsbDeviceChatScReport;
|
|
|
-import com.inspur.digital.domain.SmsbDeviceScScanCode;
|
|
|
+import com.inspur.digital.domain.*;
|
|
|
import com.inspur.digital.domain.bo.SmsbAppointmentInfoBo;
|
|
|
import com.inspur.digital.domain.bo.SmsbStartInfoBo;
|
|
|
import com.inspur.digital.domain.vo.*;
|
|
|
-import com.inspur.digital.mapper.SmsbAppointmentInfoMapper;
|
|
|
-import com.inspur.digital.mapper.SmsbDeviceChatScProductMapper;
|
|
|
-import com.inspur.digital.mapper.SmsbDeviceChatScCaseMapper;
|
|
|
-import com.inspur.digital.mapper.SmsbDeviceChatScReportMapper;
|
|
|
-import com.inspur.digital.mapper.SmsbDeviceScScanCodeMapper;
|
|
|
+import com.inspur.digital.mapper.*;
|
|
|
import com.inspur.digital.service.ISmsbAppointmentInfoService;
|
|
|
import com.inspur.digital.util.DifyStreamUtil;
|
|
|
import com.inspur.digital.util.EncryptUtil;
|
|
|
@@ -69,6 +61,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private final SmsbDeviceChatScProductMapper smsbDeviceChatScProductMapper;
|
|
|
private final SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper;
|
|
|
private final SmsbDeviceScScanCodeMapper smsbDeviceScScanCodeMapper;
|
|
|
+ private final SmsbDeviceChatScSceneMapper smsbDeviceChatScSceneMapper;
|
|
|
@Autowired
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@Value("${sc.api.url}")
|
|
|
@@ -91,6 +84,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private String difyScDatasetCaseId;
|
|
|
@Value("${dify.sc_dataset.product}")
|
|
|
private String difyScDatasetProductId;
|
|
|
+ @Value("${dify.sc_dataset.scene}")
|
|
|
+ private String difyScDatasetSceneId;
|
|
|
@Value("${server.tempDir}")
|
|
|
private String tempDir;
|
|
|
@Value("${dify.datasets.apiKey}")
|
|
|
@@ -575,6 +570,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
List<String> caseContentList = new ArrayList<>();
|
|
|
// 针对套餐推荐的内容集合
|
|
|
List<String> productContentList = new ArrayList<>();
|
|
|
+ // 针对场景推荐的内容集合
|
|
|
+ List<String> sceneContentList = new ArrayList<>();
|
|
|
|
|
|
for (SmsbDeviceGroupRelVo deviceGroupRel : deviceGroupRelList) {
|
|
|
SmsbScDeviceStartInfoVo deviceStartInfo = new SmsbScDeviceStartInfoVo();
|
|
|
@@ -606,7 +603,17 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
caseContentList = createCaseContentList(caseVoList);
|
|
|
}
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_3)) {
|
|
|
-
|
|
|
+ SmsbDeviceChatScSceneVo scSceneVo = smsbDeviceChatScSceneMapper.selectVoOne(new LambdaQueryWrapper<SmsbDeviceChatScScene>()
|
|
|
+ .eq(SmsbDeviceChatScScene::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScScene::getType, 1)
|
|
|
+ .orderByDesc(SmsbDeviceChatScScene::getAppointmentId).last("limit 1"));
|
|
|
+ deviceStartInfo.setHelloWorld(scSceneVo.getDescription());
|
|
|
+ List<SmsbDeviceChatScSceneVo> sceneVoList = smsbDeviceChatScSceneMapper.selectVoList(new LambdaQueryWrapper<SmsbDeviceChatScScene>()
|
|
|
+ .eq(SmsbDeviceChatScScene::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScScene::getType, 2));
|
|
|
+ if (CollectionUtils.isNotEmpty(sceneVoList)) {
|
|
|
+ sceneContentList = createSceneContentList(sceneVoList);
|
|
|
+ }
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_4)) {
|
|
|
SmsbDeviceChatScProductVo productVo = smsbDeviceChatScProductMapper.selectVoOne(new LambdaQueryWrapper<SmsbDeviceChatScProduct>()
|
|
|
.eq(SmsbDeviceChatScProduct::getAppointmentId, appointmentInfo.getId())
|
|
|
@@ -623,13 +630,14 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
deviceStartInfoList.add(deviceStartInfo);
|
|
|
}
|
|
|
result.setDeviceStartInfoList(deviceStartInfoList);
|
|
|
- // TODO 异步现场启动 更新知识库
|
|
|
// 线程1 更新评估报告知识库
|
|
|
syncDatasetsReport(reportContentList, difyScDatasetReportId);
|
|
|
// 线程2 更新有样学样的知识库
|
|
|
syncDatasetsCase(caseContentList, difyScDatasetCaseId);
|
|
|
// 线程3 更新套餐推荐的知识库
|
|
|
syncDatasetsProduct(productContentList, difyScDatasetProductId);
|
|
|
+ // 线程4 更新场景推荐的知识库
|
|
|
+ syncDatasetsScene(sceneContentList, difyScDatasetSceneId);
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
|
|
|
@@ -656,6 +664,21 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
return contentList;
|
|
|
}
|
|
|
|
|
|
+ private List<String> createSceneContentList(List<SmsbDeviceChatScSceneVo> sceneVoList) {
|
|
|
+ List<String> contentList = new ArrayList<>();
|
|
|
+ for (SmsbDeviceChatScSceneVo scSceneVo : sceneVoList) {
|
|
|
+ StringBuilder allContentStr = new StringBuilder();
|
|
|
+ allContentStr.append("场景名称:").append(scSceneVo.getInteractionName()).append("\n");
|
|
|
+ allContentStr.append("服务商名称:").append(scSceneVo.getSupplierName()).append("\n");
|
|
|
+ allContentStr.append("应用价值:").append(scSceneVo.getApplicationValue()).append("\n");
|
|
|
+ allContentStr.append("场景介绍:").append(scSceneVo.getDescription()).append("\n");
|
|
|
+ allContentStr.append("价格及部署方式:").append(scSceneVo.getPriceText()).append("\n");
|
|
|
+ allContentStr.append("适用领域:").append(scSceneVo.getDomainsName()).append("\n");
|
|
|
+ contentList.add(allContentStr.toString());
|
|
|
+ }
|
|
|
+ return contentList;
|
|
|
+ }
|
|
|
+
|
|
|
private List<String> createProductContentList(List<SmsbDeviceChatScProductVo> productVoList) {
|
|
|
List<String> contentList = new ArrayList<>();
|
|
|
for (SmsbDeviceChatScProductVo productVo : productVoList) {
|
|
|
@@ -733,6 +756,28 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
threadPoolTaskExecutor.submit(transTask);
|
|
|
}
|
|
|
|
|
|
+ private void syncDatasetsScene(List<String> sceneContentList, String difyScDatasetSceneId) {
|
|
|
+ Runnable transTask = () -> {
|
|
|
+ try {
|
|
|
+ log.info("syncDatasetsScene thread begin contentList.size(): " + sceneContentList.size() + ",datasetsId : " + difyScDatasetSceneId);
|
|
|
+ // 组装条目
|
|
|
+ StringBuilder allContentStr = new StringBuilder();
|
|
|
+ for (String content : sceneContentList) {
|
|
|
+ allContentStr.append("###").append("\n");
|
|
|
+ allContentStr.append(content).append("\n");
|
|
|
+ }
|
|
|
+ String filePath = createTempFile(allContentStr.toString(), "scene_");
|
|
|
+ log.info("syncDatasetsScene thread createTempFile success tempFilePath = " + filePath);
|
|
|
+ boolean uploadResult = uploadDatasetsToDify(difyScDatasetSceneId,filePath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ log.info("syncDatasetsScene thread end !");
|
|
|
+ };
|
|
|
+ // 提交Runnable任务到线程池
|
|
|
+ threadPoolTaskExecutor.submit(transTask);
|
|
|
+ }
|
|
|
+
|
|
|
private boolean uploadDatasetsToDify(String datasetsId, String filePath) {
|
|
|
// 1、 根据知识库ID 获取文件列表
|
|
|
List<DifyDatasetsFileRspData> datasetsFiles = getDatasetsFiles(datasetsId);
|