|
|
@@ -72,6 +72,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private final SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper;
|
|
|
private final SmsbDeviceScScanCodeMapper smsbDeviceScScanCodeMapper;
|
|
|
private final SmsbDifyDatasetsQuestionMapper smsbDifyDatasetsQuestionMapper;
|
|
|
+ private final SmsbDatasetsIdentifierRelMapper smsbDatasetsIdentifierRelMapper;
|
|
|
@Autowired
|
|
|
private SmsbDeviceMapper smsbDeviceMapper;
|
|
|
@Autowired
|
|
|
@@ -659,14 +660,20 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
List<String> qaList = questionVoList.stream()
|
|
|
.map(questionVo -> questionVo.getQuestion() + ":" + questionVo.getAnswer())
|
|
|
.toList();
|
|
|
- // 线程1 更新诊断报告的知识库
|
|
|
- syncDatasetsReport(qaList, difyScDatasetReportId);
|
|
|
- // 线程2 更新有样学样的知识库
|
|
|
- syncDatasetsCase(qaList, difyScDatasetCaseId);
|
|
|
- // 线程3 更新套餐推荐的知识库
|
|
|
- syncDatasetsProduct(qaList, difyScDatasetProductId);
|
|
|
- // 线程4 更新场景推荐的知识库
|
|
|
- syncDatasetsScene(qaList, difyScDatasetSceneId);
|
|
|
+
|
|
|
+ // 根据identifier查询设备组中其他设备,拿到其他设备的identifierList
|
|
|
+ List<SmsbDeviceGroupRelVo> groupRelList = smsbDeviceGroupRelMapper.queryGroupRelVoListByIdentifier(smsbStartInfoBo.getIdentifier());
|
|
|
+ // 循环遍历查到的List,根据identifier查询知识库关联表,拿到数据库id更新知识库
|
|
|
+ if (groupRelList == null || groupRelList.isEmpty()) {
|
|
|
+ return R.fail("未找到设备的设备组");
|
|
|
+ }
|
|
|
+
|
|
|
+ groupRelList.forEach(groupRel -> {
|
|
|
+ String difyId = smsbDatasetsIdentifierRelMapper.queryDifyIdByIdentifier(groupRel.getDeviceIdentifier());
|
|
|
+ // 创建线程,将设备组中设备关联的知识库更新
|
|
|
+ syncDatasets(qaList, difyId);
|
|
|
+ });
|
|
|
+
|
|
|
// 3、同步成功 设置key的value为common
|
|
|
RedisUtils.setCacheObject(REDIS_SYNC_DATASETS_FLAG_KEY, REDIS_SYNC_DATASETS_FLAG_VALUE_COMMON);
|
|
|
}
|
|
|
@@ -691,14 +698,16 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
List<SmsbScDeviceStartInfoVo> deviceStartInfoList = new ArrayList<>();
|
|
|
- // 针对评估所有内容集合
|
|
|
- List<String> reportContentList = new ArrayList<>();
|
|
|
- // 针对有样学样的内容集合
|
|
|
- List<String> caseContentList = new ArrayList<>();
|
|
|
- // 针对套餐推荐的内容集合
|
|
|
- List<String> productContentList = new ArrayList<>();
|
|
|
- // 针对场景推荐的内容集合
|
|
|
- List<String> sceneContentList = new ArrayList<>();
|
|
|
+ var ref = new Object() {
|
|
|
+ // 针对评估所有内容集合
|
|
|
+ List<String> reportContentList = new ArrayList<>();
|
|
|
+ // 针对有样学样的内容集合
|
|
|
+ List<String> caseContentList = new ArrayList<>();
|
|
|
+ // 针对套餐推荐的内容集合
|
|
|
+ List<String> productContentList = new ArrayList<>();
|
|
|
+ // 针对场景推荐的内容集合
|
|
|
+ List<String> sceneContentList = new ArrayList<>();
|
|
|
+ };
|
|
|
|
|
|
for (SmsbDeviceGroupRelVo deviceGroupRel : deviceGroupRelList) {
|
|
|
SmsbScDeviceStartInfoVo deviceStartInfo = new SmsbScDeviceStartInfoVo();
|
|
|
@@ -719,7 +728,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
.eq(SmsbDeviceChatScReport::getAppointmentId, appointmentInfo.getId())
|
|
|
.eq(SmsbDeviceChatScReport::getType, 2));
|
|
|
if (CollectionUtils.isNotEmpty(reportVoList)) {
|
|
|
- reportContentList = reportVoList.stream().map(SmsbDeviceChatScReportVo::getContent).collect(Collectors.toList());
|
|
|
+ ref.reportContentList = reportVoList.stream().map(SmsbDeviceChatScReportVo::getContent).collect(Collectors.toList());
|
|
|
}
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_2)) {
|
|
|
List<SmsbScDeviceStartProductVO> productVOList = new ArrayList<>();
|
|
|
@@ -748,7 +757,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
}else {
|
|
|
deviceStartInfo.setProductVOList(productVOList);
|
|
|
}
|
|
|
- caseContentList = createCaseContentList(caseVoList);
|
|
|
+ ref.caseContentList = createCaseContentList(caseVoList);
|
|
|
}
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_3)) {
|
|
|
List<SmsbScDeviceStartProductVO> productVOList = new ArrayList<>();
|
|
|
@@ -780,7 +789,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
}else {
|
|
|
deviceStartInfo.setProductVOList(productVOList);
|
|
|
}
|
|
|
- sceneContentList = createSceneContentList(sceneVoList);
|
|
|
+ ref.sceneContentList = createSceneContentList(sceneVoList);
|
|
|
}
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_4)) {
|
|
|
SmsbDeviceChatScProductVo productVo = smsbDeviceChatScProductMapper.selectVoOne(new LambdaQueryWrapper<SmsbDeviceChatScProduct>()
|
|
|
@@ -796,21 +805,46 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
.eq(SmsbDeviceChatScProduct::getAppointmentId, appointmentInfo.getId())
|
|
|
.eq(SmsbDeviceChatScProduct::getType, 2));
|
|
|
if (CollectionUtils.isNotEmpty(productVoList)) {
|
|
|
- productContentList = createProductContentList(productVoList);
|
|
|
+ ref.productContentList = createProductContentList(productVoList);
|
|
|
}
|
|
|
}
|
|
|
deviceStartInfoList.add(deviceStartInfo);
|
|
|
}
|
|
|
result.setDeviceStartInfoList(deviceStartInfoList);
|
|
|
- // 线程1 更新评估报告知识库
|
|
|
- syncDatasetsReport(reportContentList, difyScDatasetReportId);
|
|
|
- // 线程2 更新有样学样的知识库
|
|
|
- syncDatasetsCase(caseContentList, difyScDatasetCaseId);
|
|
|
- // 线程3 更新套餐推荐的知识库
|
|
|
- syncDatasetsProduct(productContentList, difyScDatasetProductId);
|
|
|
- // 线程4 更新场景推荐的知识库
|
|
|
- syncDatasetsScene(sceneContentList, difyScDatasetSceneId);
|
|
|
- // TODO redis缓存同步标识为企业扫识
|
|
|
+
|
|
|
+ // 根据identifier查询设备组中其他设备,拿到其他设备的identifierList
|
|
|
+ List<SmsbDeviceGroupRelVo> groupRelList = smsbDeviceGroupRelMapper.queryGroupRelVoListByIdentifier(smsbStartInfoBo.getIdentifier());
|
|
|
+ // 循环遍历查到的List,根据identifier查询知识库关联表,拿到数据库id更新知识库
|
|
|
+ if (groupRelList == null || groupRelList.isEmpty()) {
|
|
|
+ return R.fail("未找到设备的设备组");
|
|
|
+ }
|
|
|
+
|
|
|
+ groupRelList.forEach(groupRel -> {
|
|
|
+ String difyId = smsbDatasetsIdentifierRelMapper.queryDifyIdByIdentifier(groupRel.getDeviceIdentifier());
|
|
|
+ Long sort = groupRel.getSceneSort();
|
|
|
+ switch (sort.toString()) {
|
|
|
+ case "1":
|
|
|
+ // 线程1 更新诊断报告的知识库
|
|
|
+ syncDatasets(ref.reportContentList, difyId);
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ // 线程2 更新有样学样的知识库
|
|
|
+ syncDatasets(ref.caseContentList, difyId);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ // 线程3 更新套餐推荐的知识库
|
|
|
+ syncDatasets(ref.productContentList, difyId);
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ // 线程4 更新场景推荐的知识库
|
|
|
+ syncDatasets(ref.sceneContentList, difyId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // redis缓存同步标识为企业扫识
|
|
|
RedisUtils.setCacheObject(REDIS_SYNC_DATASETS_FLAG_KEY, REDIS_SYNC_DATASETS_FLAG_VALUE_ENTERPRISE);
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
@@ -865,89 +899,23 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
return contentList;
|
|
|
}
|
|
|
|
|
|
- private synchronized void syncDatasetsReport(List<String> contentList, String datasetsId) {
|
|
|
- Runnable transTask = () -> {
|
|
|
- try {
|
|
|
- log.info("syncDatasetsReport thread begin contentList.size(): " + contentList.size() + ",datasetsId : " + datasetsId);
|
|
|
- // 组装条目
|
|
|
- StringBuilder allContentStr = new StringBuilder();
|
|
|
- for (String content : contentList) {
|
|
|
- allContentStr.append("###").append("\n");
|
|
|
- allContentStr.append(content).append("\n");
|
|
|
- }
|
|
|
- String filePath = createTempFile(allContentStr.toString(), "report_");
|
|
|
- log.info("syncDatasetsReport thread createTempFile success tempFilePath = " + filePath);
|
|
|
- boolean uploadResult = uploadDatasetsToDify(datasetsId,filePath);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- log.info("syncDatasetsReport thread end !");
|
|
|
- };
|
|
|
- // 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
- }
|
|
|
-
|
|
|
- private synchronized void syncDatasetsCase(List<String> contentList, String datasetsId) {
|
|
|
- Runnable transTask = () -> {
|
|
|
- try {
|
|
|
- log.info("syncDatasetsCase thread begin contentList.size(): " + contentList.size() + ",datasetsId : " + datasetsId);
|
|
|
- // 组装条目
|
|
|
- StringBuilder allContentStr = new StringBuilder();
|
|
|
- for (String content : contentList) {
|
|
|
- allContentStr.append("###").append("\n");
|
|
|
- allContentStr.append(content).append("\n");
|
|
|
- }
|
|
|
- String filePath = createTempFile(allContentStr.toString(), "case_");
|
|
|
- log.info("syncDatasetsCase thread createTempFile success tempFilePath = " + filePath);
|
|
|
- boolean uploadResult = uploadDatasetsToDify(datasetsId,filePath);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- log.info("syncDatasetsCase thread end !");
|
|
|
- };
|
|
|
- // 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
- }
|
|
|
-
|
|
|
- private synchronized void syncDatasetsProduct(List<String> contentList, String datasetsId) {
|
|
|
+ private synchronized void syncDatasets(List<String> contentList, String datasetsId) {
|
|
|
Runnable transTask = () -> {
|
|
|
try {
|
|
|
- log.info("syncDatasetsProduct thread begin contentList.size(): " + contentList.size() + ",datasetsId : " + datasetsId);
|
|
|
+ log.info("syncDatasets thread begin contentList.size(): " + contentList.size() + ",datasetsId : " + datasetsId);
|
|
|
// 组装条目
|
|
|
StringBuilder allContentStr = new StringBuilder();
|
|
|
for (String content : contentList) {
|
|
|
allContentStr.append("###").append("\n");
|
|
|
allContentStr.append(content).append("\n");
|
|
|
}
|
|
|
- String filePath = createTempFile(allContentStr.toString(), "product_");
|
|
|
- log.info("syncDatasetsProduct thread createTempFile success tempFilePath = " + filePath);
|
|
|
+ String filePath = createTempFile(allContentStr.toString(), datasetsId);
|
|
|
+ log.info("syncDatasets thread createTempFile success tempFilePath = " + filePath);
|
|
|
boolean uploadResult = uploadDatasetsToDify(datasetsId,filePath);
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- log.info("syncDatasetsProduct thread end !");
|
|
|
- };
|
|
|
- // 提交Runnable任务到线程池
|
|
|
- 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 !");
|
|
|
+ log.info("syncDatasets thread end !");
|
|
|
};
|
|
|
// 提交Runnable任务到线程池
|
|
|
threadPoolTaskExecutor.submit(transTask);
|