|
|
@@ -16,12 +16,14 @@ 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.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;
|
|
|
@@ -64,6 +66,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private final SmsbAppointmentInfoMapper baseMapper;
|
|
|
private final SmsbDeviceGroupRelMapper smsbDeviceGroupRelMapper;
|
|
|
private final SmsbDeviceChatScReportMapper smsbDeviceChatScReportMapper;
|
|
|
+ private final SmsbDeviceChatScProductMapper smsbDeviceChatScProductMapper;
|
|
|
private final SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper;
|
|
|
private final SmsbDeviceScScanCodeMapper smsbDeviceScScanCodeMapper;
|
|
|
@Autowired
|
|
|
@@ -86,6 +89,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private String difyScDatasetReportId;
|
|
|
@Value("${dify.sc_dataset.case}")
|
|
|
private String difyScDatasetCaseId;
|
|
|
+ @Value("${dify.sc_dataset.product}")
|
|
|
+ private String difyScDatasetProductId;
|
|
|
@Value("${server.tempDir}")
|
|
|
private String tempDir;
|
|
|
@Value("${dify.datasets.apiKey}")
|
|
|
@@ -187,6 +192,14 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
// 4 启动线程,保存至数据库,生成总结
|
|
|
createReport(reportList, add, smsbDeviceChatScReportMapper);
|
|
|
}
|
|
|
+
|
|
|
+ // 解析报告内容拿到套餐推荐
|
|
|
+ List<Map<String, String>> productList = parseProductList(reportMap);
|
|
|
+ System.out.println("productList" + productList);
|
|
|
+ if (productList != null && !productList.isEmpty()) {
|
|
|
+ // 套餐推荐:服务产品列表
|
|
|
+ createProduct(productList, add, smsbDeviceChatScProductMapper);
|
|
|
+ }
|
|
|
// 5、看样学样:应用案例列表
|
|
|
List<SmsbDeviceChatScCase> caseList = getCaseList(reportMap,add);
|
|
|
if (!CollectionUtils.isEmpty(reportList)) {
|
|
|
@@ -254,6 +267,68 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private List<Map<String, String>> parseProductList(String reportMapStr) {
|
|
|
+ JSONObject reportMap = JSONUtil.parseObj(reportMapStr);
|
|
|
+ if ("false".equalsIgnoreCase(reportMap.getStr("result"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 获取solutionList数组
|
|
|
+ JSONArray productList = reportMap.getJSONObject("reportContent")
|
|
|
+ .getJSONObject("recommend").getJSONArray("productList");
|
|
|
+ if (productList == null || productList.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 创建结果List
|
|
|
+ List<Map<String, String>> resultList = new ArrayList<>();
|
|
|
+ // 遍历每个解决方案对象
|
|
|
+ for (int i = 0; i < productList.size(); i++) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ JSONObject product = productList.getJSONObject(i);
|
|
|
+ // 提取并处理每个字段
|
|
|
+ map.put("name", product.getStr("name"));
|
|
|
+ map.put("photo", product.getStr("photo"));
|
|
|
+ resultList.add(map);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createProduct(List<Map<String, String>> reportContentList, SmsbAppointmentInfo add, SmsbDeviceChatScProductMapper smsbDeviceChatScProductMapper) {
|
|
|
+ Runnable transTask = () -> {
|
|
|
+ log.info("createReport thread begin reportContentList.size(): " + reportContentList.size());
|
|
|
+ // 数据库保存条目
|
|
|
+ List<SmsbDeviceChatScProduct> scReportList = new ArrayList<>();
|
|
|
+ StringBuilder reportContentStr = new StringBuilder();
|
|
|
+ reportContentStr.append("帮我对一下内容进行汇总总结,返回100字的纯文本内容:").append("\n");
|
|
|
+ for (Map<String, String> reportContent : reportContentList) {
|
|
|
+ reportContentStr.append("套餐名称:").append(reportContent.get("name")).append("\n")
|
|
|
+ .append("套餐图片:").append(reportContent.get("photo")).append("\n");
|
|
|
+ SmsbDeviceChatScProduct scProduct = new SmsbDeviceChatScProduct();
|
|
|
+ scProduct.setType(2L);
|
|
|
+ scProduct.setName(reportContent.get("name"));
|
|
|
+ scProduct.setPhoto(reportContent.get("photo"));
|
|
|
+ scProduct.setAppointmentId(add.getId());
|
|
|
+ scProduct.setEnterprise(add.getEnterprise());
|
|
|
+ scProduct.setTenantId(add.getTenantId());
|
|
|
+ scReportList.add(scProduct);
|
|
|
+ }
|
|
|
+ smsbDeviceChatScProductMapper.insertBatch(scReportList);
|
|
|
+ // 调用公共Dify接口 进行内容总结 并保存
|
|
|
+ String reportSummary = DifyStreamUtil.callDifyStreamApi(difyBaseUrl + "/v1/chat-messages", difyScAgentApiKey, reportContentStr.toString());
|
|
|
+ SmsbDeviceChatScProduct scReport = new SmsbDeviceChatScProduct();
|
|
|
+ scReport.setType(1L);
|
|
|
+ String content = "你好," + add.getEnterprise() + "企业,我是小数智能分析助手。您企业转型的套餐为:" + reportSummary + "您可以继续向我提问。";
|
|
|
+ scReport.setName("欢迎词");
|
|
|
+ scReport.setIntroduction(content);
|
|
|
+ scReport.setAppointmentId(add.getId());
|
|
|
+ scReport.setEnterprise(add.getEnterprise());
|
|
|
+ scReport.setTenantId(add.getTenantId());
|
|
|
+ smsbDeviceChatScProductMapper.insert(scReport);
|
|
|
+ log.info("createReport thread end !");
|
|
|
+ };
|
|
|
+ // 提交Runnable任务到线程池
|
|
|
+ threadPoolTaskExecutor.submit(transTask);
|
|
|
+ }
|
|
|
+
|
|
|
private void createReport(List<String> reportContentList, SmsbAppointmentInfo add, SmsbDeviceChatScReportMapper smsbDeviceChatScReportMapper) {
|
|
|
Runnable transTask = () -> {
|
|
|
log.info("createReport thread begin reportContentList.size(): " + reportContentList.size());
|
|
|
@@ -286,6 +361,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
};
|
|
|
// 提交Runnable任务到线程池
|
|
|
threadPoolTaskExecutor.submit(transTask);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private List<String> getAssessmentReportV2(String reportMap) {
|
|
|
@@ -497,6 +573,9 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
List<String> reportContentList = new ArrayList<>();
|
|
|
// 针对有样学样的内容集合
|
|
|
List<String> caseContentList = new ArrayList<>();
|
|
|
+ // 针对套餐推荐的内容集合
|
|
|
+ List<String> productContentList = new ArrayList<>();
|
|
|
+
|
|
|
for (SmsbDeviceGroupRelVo deviceGroupRel : deviceGroupRelList) {
|
|
|
SmsbScDeviceStartInfoVo deviceStartInfo = new SmsbScDeviceStartInfoVo();
|
|
|
deviceStartInfo.setIdentifier(deviceGroupRel.getDeviceIdentifier());
|
|
|
@@ -529,7 +608,17 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_3)) {
|
|
|
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_4)) {
|
|
|
-
|
|
|
+ SmsbDeviceChatScProductVo productVo = smsbDeviceChatScProductMapper.selectVoOne(new LambdaQueryWrapper<SmsbDeviceChatScProduct>()
|
|
|
+ .eq(SmsbDeviceChatScProduct::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScProduct::getType, 1)
|
|
|
+ .orderByDesc(SmsbDeviceChatScProduct::getAppointmentId).last("limit 1"));
|
|
|
+ deviceStartInfo.setHelloWorld(productVo.getIntroduction());
|
|
|
+ List<SmsbDeviceChatScProductVo> productVoList = smsbDeviceChatScProductMapper.selectVoList(new LambdaQueryWrapper<SmsbDeviceChatScProduct>()
|
|
|
+ .eq(SmsbDeviceChatScProduct::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScProduct::getType, 2));
|
|
|
+ if (CollectionUtils.isNotEmpty(productVoList)) {
|
|
|
+ productContentList = createProductContentList(productVoList);
|
|
|
+ }
|
|
|
}
|
|
|
deviceStartInfoList.add(deviceStartInfo);
|
|
|
}
|
|
|
@@ -539,6 +628,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
syncDatasetsReport(reportContentList, difyScDatasetReportId);
|
|
|
// 线程2 更新有样学样的知识库
|
|
|
syncDatasetsCase(caseContentList, difyScDatasetCaseId);
|
|
|
+ // 线程3 更新套餐推荐的知识库
|
|
|
+ syncDatasetsProduct(productContentList, difyScDatasetProductId);
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
|
|
|
@@ -565,6 +656,17 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
return contentList;
|
|
|
}
|
|
|
|
|
|
+ private List<String> createProductContentList(List<SmsbDeviceChatScProductVo> productVoList) {
|
|
|
+ List<String> contentList = new ArrayList<>();
|
|
|
+ for (SmsbDeviceChatScProductVo productVo : productVoList) {
|
|
|
+ StringBuilder allContentStr = new StringBuilder();
|
|
|
+ allContentStr.append("套餐名称:").append(productVo.getName()).append("\n");
|
|
|
+ allContentStr.append("套餐简介:").append(productVo.getIntroduction()).append("\n");
|
|
|
+ contentList.add(allContentStr.toString());
|
|
|
+ }
|
|
|
+ return contentList;
|
|
|
+ }
|
|
|
+
|
|
|
private synchronized void syncDatasetsReport(List<String> contentList, String datasetsId) {
|
|
|
Runnable transTask = () -> {
|
|
|
try {
|
|
|
@@ -609,6 +711,28 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
threadPoolTaskExecutor.submit(transTask);
|
|
|
}
|
|
|
|
|
|
+ private synchronized void syncDatasetsProduct(List<String> contentList, String datasetsId) {
|
|
|
+ Runnable transTask = () -> {
|
|
|
+ try {
|
|
|
+ log.info("syncDatasetsProduct 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);
|
|
|
+ boolean uploadResult = uploadDatasetsToDify(datasetsId,filePath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ log.info("syncDatasetsProduct thread end !");
|
|
|
+ };
|
|
|
+ // 提交Runnable任务到线程池
|
|
|
+ threadPoolTaskExecutor.submit(transTask);
|
|
|
+ }
|
|
|
+
|
|
|
private boolean uploadDatasetsToDify(String datasetsId, String filePath) {
|
|
|
// 1、 根据知识库ID 获取文件列表
|
|
|
List<DifyDatasetsFileRspData> datasetsFiles = getDatasetsFiles(datasetsId);
|