|
|
@@ -14,14 +14,13 @@ 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.SmsbDeviceChatScReport;
|
|
|
import com.inspur.digital.domain.bo.SmsbAppointmentInfoBo;
|
|
|
import com.inspur.digital.domain.bo.SmsbStartInfoBo;
|
|
|
-import com.inspur.digital.domain.vo.SmsbAppointmentInfoVo;
|
|
|
-import com.inspur.digital.domain.vo.SmsbDeviceChatScReportVo;
|
|
|
-import com.inspur.digital.domain.vo.SmsbScDeviceStartInfoVo;
|
|
|
-import com.inspur.digital.domain.vo.SmsbScStartInfoVo;
|
|
|
+import com.inspur.digital.domain.vo.*;
|
|
|
import com.inspur.digital.mapper.SmsbAppointmentInfoMapper;
|
|
|
+import com.inspur.digital.mapper.SmsbDeviceChatScCaseMapper;
|
|
|
import com.inspur.digital.mapper.SmsbDeviceChatScReportMapper;
|
|
|
import com.inspur.digital.service.ISmsbAppointmentInfoService;
|
|
|
import com.inspur.digital.util.DifyStreamUtil;
|
|
|
@@ -65,6 +64,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private final SmsbAppointmentInfoMapper baseMapper;
|
|
|
private final SmsbDeviceGroupRelMapper smsbDeviceGroupRelMapper;
|
|
|
private final SmsbDeviceChatScReportMapper smsbDeviceChatScReportMapper;
|
|
|
+ private final SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper;
|
|
|
@Autowired
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@Value("${sc.api.url}")
|
|
|
@@ -83,6 +83,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private String difyScAgentApiKey;
|
|
|
@Value("${dify.sc_dataset.report}")
|
|
|
private String difyScDatasetReportId;
|
|
|
+ @Value("${dify.sc_dataset.case}")
|
|
|
+ private String difyScDatasetCaseId;
|
|
|
@Value("${server.tempDir}")
|
|
|
private String tempDir;
|
|
|
@Value("${dify.datasets.apiKey}")
|
|
|
@@ -158,6 +160,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
lqw.eq(bo.getPhone() != null, SmsbAppointmentInfo::getPhone, bo.getPhone());
|
|
|
lqw.eq(bo.getAppointmentTime() != null, SmsbAppointmentInfo::getAppointmentTime, bo.getAppointmentTime());
|
|
|
lqw.eq(bo.getPeopleNum() != null, SmsbAppointmentInfo::getPeopleNum, bo.getPeopleNum());
|
|
|
+ lqw.orderByDesc(SmsbAppointmentInfo::getId);
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
@@ -183,11 +186,73 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
// 4 启动线程,保存至数据库,生成总结
|
|
|
createReport(reportList, add, smsbDeviceChatScReportMapper);
|
|
|
}
|
|
|
-
|
|
|
+ // 5、看样学样:应用案例列表
|
|
|
+ List<SmsbDeviceChatScCase> caseList = getCaseList(reportMap,add);
|
|
|
+ if (!CollectionUtils.isEmpty(reportList)) {
|
|
|
+ // 6 启动线程,保存至数据库,生成总结
|
|
|
+ createCaseList(caseList, add, smsbDeviceChatScCaseMapper);
|
|
|
+ }
|
|
|
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ private void createCaseList(List<SmsbDeviceChatScCase> caseList, SmsbAppointmentInfo add, SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper) {
|
|
|
+ Runnable transTask = () -> {
|
|
|
+ log.info("createCaseList thread begin caseList.size(): " + caseList.size());
|
|
|
+ smsbDeviceChatScCaseMapper.insertBatch(caseList);
|
|
|
+ StringBuilder caseContentStr = new StringBuilder();
|
|
|
+ caseContentStr.append("帮我对一下内容进行汇总总结,返回100字的纯文本内容:").append("\n");
|
|
|
+ for (SmsbDeviceChatScCase caseItem : caseList) {
|
|
|
+ caseContentStr.append(caseItem.getName()).append(":").append(caseItem.getIntroduction()).append("\n");
|
|
|
+ }
|
|
|
+ // 调用公共Dify接口 进行内容总结 并保存
|
|
|
+ String reportSummary = DifyStreamUtil.callDifyStreamApi(difyBaseUrl + "/v1/chat-messages", difyScAgentApiKey, caseContentStr.toString());
|
|
|
+ SmsbDeviceChatScCase scCase = new SmsbDeviceChatScCase();
|
|
|
+ scCase.setType(1);
|
|
|
+ String content = "你好," + add.getEnterprise() + "企业,我是小数智能分析助手。您企业的诊断评估简单介绍为:" + reportSummary + "您可以继续向我提问。";
|
|
|
+ scCase.setIntroduction(content);
|
|
|
+ scCase.setName("欢迎词");
|
|
|
+ scCase.setAppointmentId(add.getId());
|
|
|
+ scCase.setEnterprise(add.getEnterprise());
|
|
|
+ scCase.setTenantId(add.getTenantId());
|
|
|
+ smsbDeviceChatScCaseMapper.insert(scCase);
|
|
|
+ log.info("createCaseList thread end !");
|
|
|
+ };
|
|
|
+ // 提交Runnable任务到线程池
|
|
|
+ threadPoolTaskExecutor.submit(transTask);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SmsbDeviceChatScCase> getCaseList(String reportMap,SmsbAppointmentInfo add) {
|
|
|
+ try {
|
|
|
+ JSONObject reportMapJson = JSONUtil.parseObj(reportMap);
|
|
|
+ if (!"true".equalsIgnoreCase(reportMapJson.getStr("result"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 读取报告具体内容
|
|
|
+ JSONObject reportContent = reportMapJson.getJSONObject("reportContent");
|
|
|
+ JSONObject recommend = reportContent.getJSONObject("recommend");
|
|
|
+ // 应用案例列表:
|
|
|
+ JSONArray caseList = recommend.getJSONArray("caseList");
|
|
|
+ List<SmsbDeviceChatScCase> addCaseList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < caseList.size(); i++) {
|
|
|
+ JSONObject caseItem = caseList.getJSONObject(i);
|
|
|
+ SmsbDeviceChatScCase addCase = new SmsbDeviceChatScCase();
|
|
|
+ addCase.setName(caseItem.getStr("name"));
|
|
|
+ addCase.setPhoto(caseItem.getStr("photo"));
|
|
|
+ addCase.setIntroduction(caseItem.getStr("introduction"));
|
|
|
+ addCase.setAppointmentId(add.getId());
|
|
|
+ addCase.setEnterprise(add.getEnterprise());
|
|
|
+ addCase.setTenantId(add.getTenantId());
|
|
|
+ addCase.setType(2);
|
|
|
+ addCaseList.add(addCase);
|
|
|
+ }
|
|
|
+ return addCaseList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取应用案例列表内容失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void createReport(List<String> reportContentList, SmsbAppointmentInfo add, SmsbDeviceChatScReportMapper smsbDeviceChatScReportMapper) {
|
|
|
Runnable transTask = () -> {
|
|
|
log.info("createReport thread begin reportContentList.size(): " + reportContentList.size());
|
|
|
@@ -220,7 +285,6 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
};
|
|
|
// 提交Runnable任务到线程池
|
|
|
threadPoolTaskExecutor.submit(transTask);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private List<String> getAssessmentReportV2(String reportMap) {
|
|
|
@@ -422,6 +486,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
List<SmsbScDeviceStartInfoVo> deviceStartInfoList = new ArrayList<>();
|
|
|
// 针对评估所有内容集合
|
|
|
List<String> reportContentList = new ArrayList<>();
|
|
|
+ // 针对有样学样的内容集合
|
|
|
+ List<String> caseContentList = new ArrayList<>();
|
|
|
for (SmsbDeviceGroupRelVo deviceGroupRel : deviceGroupRelList) {
|
|
|
SmsbScDeviceStartInfoVo deviceStartInfo = new SmsbScDeviceStartInfoVo();
|
|
|
deviceStartInfo.setIdentifier(deviceGroupRel.getDeviceIdentifier());
|
|
|
@@ -440,7 +506,17 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
reportContentList = reportVoList.stream().map(SmsbDeviceChatScReportVo::getContent).collect(Collectors.toList());
|
|
|
}
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_2)) {
|
|
|
-
|
|
|
+ SmsbDeviceChatScCaseVo caseVo = smsbDeviceChatScCaseMapper.selectVoOne(new LambdaQueryWrapper<SmsbDeviceChatScCase>()
|
|
|
+ .eq(SmsbDeviceChatScCase::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScCase::getType, 1)
|
|
|
+ .orderByDesc(SmsbDeviceChatScCase::getAppointmentId).last("limit 1"));
|
|
|
+ deviceStartInfo.setHelloWorld(caseVo.getIntroduction());
|
|
|
+ List<SmsbDeviceChatScCaseVo> caseVoList = smsbDeviceChatScCaseMapper.selectVoList(new LambdaQueryWrapper<SmsbDeviceChatScCase>()
|
|
|
+ .eq(SmsbDeviceChatScCase::getAppointmentId, appointmentInfo.getId())
|
|
|
+ .eq(SmsbDeviceChatScCase::getType, 2));
|
|
|
+ if (CollectionUtils.isNotEmpty(caseVoList)) {
|
|
|
+ caseContentList = createCaseContentList(caseVoList);
|
|
|
+ }
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_3)) {
|
|
|
|
|
|
} else if (deviceGroupRel.getSceneSort().equals(DEFAULT_SCENE_SORT_4)) {
|
|
|
@@ -452,11 +528,23 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
// TODO 异步现场启动 更新知识库
|
|
|
// 线程1 更新评估报告知识库
|
|
|
syncDatasets(reportContentList, difyScDatasetReportId);
|
|
|
-
|
|
|
+ // 线程2 更新有样学样的知识库
|
|
|
+ syncDatasets(caseContentList, difyScDatasetCaseId);
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
|
|
|
- private void syncDatasets(List<String> contentList, String datasetsId) {
|
|
|
+ private List<String> createCaseContentList(List<SmsbDeviceChatScCaseVo> caseVoList) {
|
|
|
+ List<String> contentList = new ArrayList<>();
|
|
|
+ for (SmsbDeviceChatScCaseVo caseVo : caseVoList) {
|
|
|
+ StringBuilder allContentStr = new StringBuilder();
|
|
|
+ allContentStr.append("案例名称:").append(caseVo.getName()).append("\n");
|
|
|
+ allContentStr.append("案例简介:").append(caseVo.getIntroduction()).append("\n");
|
|
|
+ contentList.add(allContentStr.toString());
|
|
|
+ }
|
|
|
+ return contentList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private synchronized void syncDatasets(List<String> contentList, String datasetsId) {
|
|
|
Runnable transTask = () -> {
|
|
|
try {
|
|
|
log.info("syncDatasets thread begin contentList.size(): " + contentList.size() + ",datasetsId : " + datasetsId);
|