|
|
@@ -14,8 +14,10 @@ import com.github.therapi.runtimejavadoc.repack.com.eclipsesource.json.JsonObjec
|
|
|
import com.inspur.device.domain.SmsbDifyDatasetsQuestion;
|
|
|
import com.inspur.device.domain.vo.DifyDatasetsFileRspData;
|
|
|
import com.inspur.device.domain.vo.SmsbDeviceGroupRelVo;
|
|
|
+import com.inspur.device.domain.vo.SmsbDeviceVo;
|
|
|
import com.inspur.device.domain.vo.SmsbDifyDatasetsQuestionVo;
|
|
|
import com.inspur.device.mapper.SmsbDeviceGroupRelMapper;
|
|
|
+import com.inspur.device.mapper.SmsbDeviceMapper;
|
|
|
import com.inspur.device.mapper.SmsbDifyDatasetsQuestionMapper;
|
|
|
import com.inspur.digital.domain.*;
|
|
|
import com.inspur.digital.domain.bo.SmsbAppointmentInfoBo;
|
|
|
@@ -26,6 +28,7 @@ import com.inspur.digital.service.ISmsbAppointmentInfoService;
|
|
|
import com.inspur.digital.util.DifyStreamUtil;
|
|
|
import com.inspur.digital.util.EncryptUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
@@ -34,6 +37,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
@@ -46,6 +50,7 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -68,6 +73,8 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
private final SmsbDeviceScScanCodeMapper smsbDeviceScScanCodeMapper;
|
|
|
private final SmsbDifyDatasetsQuestionMapper smsbDifyDatasetsQuestionMapper;
|
|
|
@Autowired
|
|
|
+ private SmsbDeviceMapper smsbDeviceMapper;
|
|
|
+ @Autowired
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@Value("${sc.api.url}")
|
|
|
private String scApiBaseUrl;
|
|
|
@@ -184,55 +191,74 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@Override
|
|
|
- public Boolean insertByBoV2(SmsbAppointmentInfoBo bo) {
|
|
|
- SmsbAppointmentInfo add = MapstructUtils.convert(bo, SmsbAppointmentInfo.class);
|
|
|
- add.setTenantId(bo.getTenantId());
|
|
|
+ public SmsbAppointmentInfo insertByBoV2(SmsbStartInfoBo bo) {
|
|
|
+ List<CompletableFuture<Void>> futures = new ArrayList<>();
|
|
|
+
|
|
|
+ SmsbAppointmentInfo add = new SmsbAppointmentInfo();
|
|
|
+ BeanUtils.copyProperties(bo, add);
|
|
|
+ SmsbDeviceVo smsbDeviceVo = smsbDeviceMapper.getDeviceVoByIdentifier(bo.getIdentifier());
|
|
|
+ String tenantId = smsbDeviceVo.getTenantId();
|
|
|
+ add.setTenantId(tenantId);
|
|
|
add.setIsArrived(0);
|
|
|
validEntityBeforeSave(add);
|
|
|
- // 1、 保存预约信息
|
|
|
- boolean flag = baseMapper.insert(add) > 0;
|
|
|
- // 2、 调用第三方接口 获取数据
|
|
|
+ // 查询当前企业是否已经存数据,如果存在 直接返回
|
|
|
+ SmsbAppointmentInfo exist = baseMapper.selectOne(new LambdaQueryWrapper<SmsbAppointmentInfo>()
|
|
|
+ .eq(SmsbAppointmentInfo::getEnterprise, add.getEnterprise()).eq(SmsbAppointmentInfo::getPhone, add.getPhone())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (exist != null) {
|
|
|
+ return exist;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1、 调用第三方接口 获取数据
|
|
|
String reportMap = "";
|
|
|
String interactionListStr = "";
|
|
|
try {
|
|
|
String data = requestApiGetReportMap(add);
|
|
|
reportMap = JSONUtil.parseObj(data).getStr("reportMap");
|
|
|
+ // 说明当前企业没有报告反返回
|
|
|
+ JSONObject reportMapJson = JSONUtil.parseObj(reportMap);
|
|
|
+ if (!"true".equalsIgnoreCase(reportMapJson.getStr("result"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
interactionListStr = JSONUtil.parseObj(data).getStr("interactionList");
|
|
|
} catch (Exception e) {
|
|
|
log.error("请求第三方接口失败", e);
|
|
|
- return false;
|
|
|
+ return null;
|
|
|
}
|
|
|
+ // 1、 保存预约信息
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
// 3、 读取评估报告内容
|
|
|
List<String> reportList = getAssessmentReportV2(reportMap);
|
|
|
if (!CollectionUtils.isEmpty(reportList)) {
|
|
|
// 4 启动线程,保存至数据库,生成总结
|
|
|
- createReport(reportList, add, smsbDeviceChatScReportMapper);
|
|
|
+ // createReport(reportList, add, smsbDeviceChatScReportMapper);
|
|
|
+ futures.add(CompletableFuture.runAsync(() -> createReport(reportList, add, smsbDeviceChatScReportMapper), threadPoolTaskExecutor));
|
|
|
}
|
|
|
-
|
|
|
// 解析报告内容拿到场景体验
|
|
|
List<SmsbDeviceChatScScene> interactionList = parseInteractionList(interactionListStr, add);
|
|
|
- System.out.println("interactionList" + interactionList);
|
|
|
if (interactionList != null && !interactionList.isEmpty()) {
|
|
|
// 套餐推荐:服务产品列表
|
|
|
- createInteractionList(interactionList, add, smsbDeviceChatScSceneMapper);
|
|
|
+ // createInteractionList(interactionList, add, smsbDeviceChatScSceneMapper);
|
|
|
+ futures.add(CompletableFuture.runAsync(() -> createInteractionList(interactionList, add, smsbDeviceChatScSceneMapper), threadPoolTaskExecutor));
|
|
|
}
|
|
|
-
|
|
|
// 解析报告内容拿到套餐推荐
|
|
|
List<Map<String, String>> productList = parseProductList(reportMap);
|
|
|
-// System.out.println("productList" + productList);
|
|
|
if (productList != null && !productList.isEmpty()) {
|
|
|
// 套餐推荐:服务产品列表
|
|
|
- createProduct(productList, add, smsbDeviceChatScProductMapper);
|
|
|
+ // createProduct(productList, add, smsbDeviceChatScProductMapper);
|
|
|
+ futures.add(CompletableFuture.runAsync(() -> createProduct(productList, add, smsbDeviceChatScProductMapper), threadPoolTaskExecutor));
|
|
|
}
|
|
|
// 5、看样学样:应用案例列表
|
|
|
- List<SmsbDeviceChatScCase> caseList = getCaseList(reportMap,add);
|
|
|
+ List<SmsbDeviceChatScCase> caseList = getCaseList(reportMap, add);
|
|
|
if (!CollectionUtils.isEmpty(reportList)) {
|
|
|
- // 6 启动线程,保存至数据库,生成总结
|
|
|
- createCaseList(caseList, add, smsbDeviceChatScCaseMapper);
|
|
|
+ futures.add(CompletableFuture.runAsync(() -> createCaseList(caseList, add, smsbDeviceChatScCaseMapper), threadPoolTaskExecutor));
|
|
|
}
|
|
|
+ // 等待所有任务完成
|
|
|
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
|
|
|
|
- return flag;
|
|
|
+ return add;
|
|
|
}
|
|
|
|
|
|
private List<SmsbDeviceChatScScene> parseInteractionList(String interactionListStr, SmsbAppointmentInfo add) {
|
|
|
@@ -270,7 +296,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
}
|
|
|
|
|
|
private void createInteractionList(List<SmsbDeviceChatScScene> sceneList, SmsbAppointmentInfo add, SmsbDeviceChatScSceneMapper smsbDeviceChatScInteractionMapper) {
|
|
|
- Runnable transTask = () -> {
|
|
|
+ // Runnable transTask = () -> {
|
|
|
log.info("createInteractionList thread begin sceneList.size(): " + sceneList.size());
|
|
|
smsbDeviceChatScInteractionMapper.insertBatch(sceneList);
|
|
|
StringBuilder InteractionContentStr = new StringBuilder();
|
|
|
@@ -296,13 +322,13 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
scInteraction.setTenantId(add.getTenantId());
|
|
|
smsbDeviceChatScInteractionMapper.insert(scInteraction);
|
|
|
log.info("createInteractionList thread end !");
|
|
|
- };
|
|
|
+ // };
|
|
|
// 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
+ // threadPoolTaskExecutor.submit(transTask);
|
|
|
}
|
|
|
|
|
|
private void createCaseList(List<SmsbDeviceChatScCase> caseList, SmsbAppointmentInfo add, SmsbDeviceChatScCaseMapper smsbDeviceChatScCaseMapper) {
|
|
|
- Runnable transTask = () -> {
|
|
|
+ // Runnable transTask = () -> {
|
|
|
log.info("createCaseList thread begin caseList.size(): " + caseList.size());
|
|
|
smsbDeviceChatScCaseMapper.insertBatch(caseList);
|
|
|
StringBuilder caseContentStr = new StringBuilder();
|
|
|
@@ -322,9 +348,9 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
scCase.setTenantId(add.getTenantId());
|
|
|
smsbDeviceChatScCaseMapper.insert(scCase);
|
|
|
log.info("createCaseList thread end !");
|
|
|
- };
|
|
|
+ // };
|
|
|
// 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
+ // threadPoolTaskExecutor.submit(transTask);
|
|
|
}
|
|
|
|
|
|
private List<SmsbDeviceChatScCase> getCaseList(String reportMap,SmsbAppointmentInfo add) {
|
|
|
@@ -384,7 +410,7 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
}
|
|
|
|
|
|
private void createProduct(List<Map<String, String>> reportContentList, SmsbAppointmentInfo add, SmsbDeviceChatScProductMapper smsbDeviceChatScProductMapper) {
|
|
|
- Runnable transTask = () -> {
|
|
|
+ // Runnable transTask = () -> {
|
|
|
log.info("createReport thread begin reportContentList.size(): " + reportContentList.size());
|
|
|
// 数据库保存条目
|
|
|
List<SmsbDeviceChatScProduct> scReportList = new ArrayList<>();
|
|
|
@@ -415,13 +441,13 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
scReport.setTenantId(add.getTenantId());
|
|
|
smsbDeviceChatScProductMapper.insert(scReport);
|
|
|
log.info("createReport thread end !");
|
|
|
- };
|
|
|
+ // };
|
|
|
// 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
+ // threadPoolTaskExecutor.submit(transTask);
|
|
|
}
|
|
|
|
|
|
private void createReport(List<String> reportContentList, SmsbAppointmentInfo add, SmsbDeviceChatScReportMapper smsbDeviceChatScReportMapper) {
|
|
|
- Runnable transTask = () -> {
|
|
|
+ // Runnable transTask = () -> {
|
|
|
log.info("createReport thread begin reportContentList.size(): " + reportContentList.size());
|
|
|
// 数据库保存条目
|
|
|
List<SmsbDeviceChatScReport> scReportList = new ArrayList<>();
|
|
|
@@ -449,9 +475,9 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
scReport.setTenantId(add.getTenantId());
|
|
|
smsbDeviceChatScReportMapper.insert(scReport);
|
|
|
log.info("createReport thread end !");
|
|
|
- };
|
|
|
+ // };
|
|
|
// 提交Runnable任务到线程池
|
|
|
- threadPoolTaskExecutor.submit(transTask);
|
|
|
+ // threadPoolTaskExecutor.submit(transTask);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -574,13 +600,14 @@ public class SmsbAppointmentInfoServiceImpl implements ISmsbAppointmentInfoServi
|
|
|
public R<SmsbScStartInfoVo> getSmsbScStartInfoVo(SmsbStartInfoBo smsbStartInfoBo) {
|
|
|
SmsbScStartInfoVo result = new SmsbScStartInfoVo();
|
|
|
// 根据前端传递的企业名称和手机号查询预约信息
|
|
|
- String enterprise = smsbStartInfoBo.getEnterprise();
|
|
|
+ /*String enterprise = smsbStartInfoBo.getEnterprise();
|
|
|
String phone = smsbStartInfoBo.getPhone();
|
|
|
SmsbAppointmentInfo appointmentInfo = baseMapper.selectOne(new LambdaQueryWrapper<SmsbAppointmentInfo>()
|
|
|
.eq(SmsbAppointmentInfo::getEnterprise, enterprise)
|
|
|
- .eq(SmsbAppointmentInfo::getPhone, phone).orderByDesc(SmsbAppointmentInfo::getId).last("limit 1"));
|
|
|
+ .eq(SmsbAppointmentInfo::getPhone, phone).orderByDesc(SmsbAppointmentInfo::getId).last("limit 1"));*/
|
|
|
+ SmsbAppointmentInfo appointmentInfo = this.insertByBoV2(smsbStartInfoBo);
|
|
|
// 未查询到预约信息 返回
|
|
|
- if (appointmentInfo == null) {
|
|
|
+ if (null == appointmentInfo) {
|
|
|
result.setBaseHelloWorld("你好,我是小数智能分析助手,有什么可以帮你?");
|
|
|
// TODO 同步公共知识库
|
|
|
// 1、根据redis key 获取redis value
|