|
|
@@ -26,6 +26,7 @@ import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
@@ -171,17 +172,17 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
@Override
|
|
|
public void initZhiPuInfo() {
|
|
|
//获取应用列表
|
|
|
- //List<BmApplication> appList = getApplicationList();
|
|
|
+ List<BmApplication> appList = getValidAppList();
|
|
|
//获取知识库列表
|
|
|
- List<BmKnowledge> knowledgeList = getKnowledgeList();
|
|
|
+ List<BmKnowledge> knowledgeList = getValidKnowledgeList();
|
|
|
//获取知识列表
|
|
|
if(!knowledgeList.isEmpty()) {
|
|
|
for(BmKnowledge bmKnowledge : knowledgeList) {
|
|
|
- List<BmDocument> documentList = getDocumentList(bmKnowledge.getKnowledgeId());
|
|
|
+ List<BmDocument> documentList = getValidDocumentList(bmKnowledge.getKnowledgeId());
|
|
|
if(!documentList.isEmpty()) {
|
|
|
for (BmDocument bmDocument : documentList) {
|
|
|
//获取知识图片列表
|
|
|
- List<BmMediaReplacement> imageList = getDocumentImageList(bmDocument.getDocumentId());
|
|
|
+ List<BmMediaReplacement> imageList = getValidImageList(bmDocument.getDocumentId());
|
|
|
if(!imageList.isEmpty()) {
|
|
|
for(BmMediaReplacement image : imageList) {
|
|
|
redisCache.setCacheObject(image.getOriginText(),image.getMediaUrl());
|
|
|
@@ -193,6 +194,141 @@ public class BigModelServiceImpl implements IBigModelService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private List<BmApplication> getValidAppList() {
|
|
|
+ //接口获取数据
|
|
|
+ List<BmApplication> appList = getApplicationList();
|
|
|
+ if(!appList.isEmpty()) {
|
|
|
+ //更新数据库
|
|
|
+ updateAppList(appList);
|
|
|
+ } else {
|
|
|
+ //数据库获取数据
|
|
|
+ appList = bmApplicationMapper.selectApplicationList(null);
|
|
|
+ }
|
|
|
+ return appList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BmKnowledge> getValidKnowledgeList() {
|
|
|
+ //接口获取数据
|
|
|
+ List<BmKnowledge> knowledgeList = getKnowledgeList();
|
|
|
+ if(!knowledgeList.isEmpty()) {
|
|
|
+ //更新数据库
|
|
|
+ updateKnowledgeList(knowledgeList);
|
|
|
+ } else {
|
|
|
+ //数据库获取数据
|
|
|
+ knowledgeList = bmKnowledgeMapper.selectKnowledgeList(null);
|
|
|
+ }
|
|
|
+ return knowledgeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BmDocument> getValidDocumentList(String knowledgeId) {
|
|
|
+ //接口获取数据
|
|
|
+ List<BmDocument> documentList = getDocumentList(knowledgeId);
|
|
|
+ if(!documentList.isEmpty()) {
|
|
|
+ //更新数据库
|
|
|
+ updateDocumentList(documentList,knowledgeId);
|
|
|
+ } else {
|
|
|
+ //数据库获取数据
|
|
|
+ BmDocument conditon = BmDocument.builder().knowledgeId(knowledgeId).build();
|
|
|
+ documentList = bmDocumentMapper.selectDocumentList(conditon);
|
|
|
+ }
|
|
|
+ return documentList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BmMediaReplacement> getValidImageList(String documentId) {
|
|
|
+ //接口获取数据
|
|
|
+ List<BmMediaReplacement> imageList = getDocumentImageList(documentId);
|
|
|
+ if(!imageList.isEmpty()) {
|
|
|
+ //更新数据库
|
|
|
+ updateImageList(imageList,documentId);
|
|
|
+ } else {
|
|
|
+ //数据库获取数据
|
|
|
+ BmMediaReplacement conditon = BmMediaReplacement.builder().documentId(documentId).build();
|
|
|
+ imageList = bmMediaReplacementMapper.selectMediaList(conditon);
|
|
|
+ }
|
|
|
+ return imageList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void updateAppList(List<BmApplication> appList) {
|
|
|
+ List<BmApplication> dbList = bmApplicationMapper.selectApplicationList(null);
|
|
|
+ for(BmApplication app : appList) {
|
|
|
+ Optional<BmApplication> optObj = dbList.stream().filter(a -> a.getAppId().equals(app.getAppId())).findFirst();
|
|
|
+ if (!optObj.isPresent()) {
|
|
|
+ bmApplicationMapper.insertApplication(app);
|
|
|
+ } else if(!optObj.get().getName().equals(app.getName())) {
|
|
|
+ BmApplication updateObj = optObj.get();
|
|
|
+ updateObj.setName(app.getName());
|
|
|
+ updateObj.setDesc(app.getDesc());
|
|
|
+ updateObj.setPrompt(app.getPrompt());
|
|
|
+ updateObj.setKnowledgeIds(app.getKnowledgeIds());
|
|
|
+
|
|
|
+ bmApplicationMapper.updateApplication(updateObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateKnowledgeList(List<BmKnowledge> knowledgeList) {
|
|
|
+ List<BmKnowledge> dbList = bmKnowledgeMapper.selectKnowledgeList(null);
|
|
|
+ for(BmKnowledge knowledge : knowledgeList) {
|
|
|
+ Optional<BmKnowledge> optObj = dbList.stream().filter(a -> a.getKnowledgeId().equals(knowledge.getKnowledgeId())).findFirst();
|
|
|
+ if (!optObj.isPresent()) {
|
|
|
+ bmKnowledgeMapper.insertKnowledge(knowledge);
|
|
|
+ } else if(!optObj.get().getName().equals(knowledge.getName())) {
|
|
|
+ BmKnowledge updateObj = optObj.get();
|
|
|
+ updateObj.setName(knowledge.getName());
|
|
|
+ updateObj.setDescription(knowledge.getDescription());
|
|
|
+ updateObj.setWordNum(knowledge.getWordNum());
|
|
|
+ updateObj.setDocumentSize(knowledge.getDocumentSize());
|
|
|
+ updateObj.setLength(knowledge.getLength());
|
|
|
+
|
|
|
+ bmKnowledgeMapper.updateKnowledge(updateObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateDocumentList(List<BmDocument> documentList, String knowledgeId) {
|
|
|
+ BmDocument conditon = BmDocument.builder().knowledgeId(knowledgeId).build();
|
|
|
+ List<BmDocument> dbList = bmDocumentMapper.selectDocumentList(conditon);
|
|
|
+ for(BmDocument document : documentList) {
|
|
|
+ Optional<BmDocument> optObj = dbList.stream().filter(a -> a.getDocumentId().equals(document.getDocumentId())).findFirst();
|
|
|
+ if (!optObj.isPresent()) {
|
|
|
+ document.setKnowledgeId(knowledgeId);
|
|
|
+ bmDocumentMapper.insertDocument(document);
|
|
|
+ } else if(!optObj.get().getName().equals(document.getName())) {
|
|
|
+ BmDocument updateObj = optObj.get();
|
|
|
+ updateObj.setName(document.getName());
|
|
|
+ updateObj.setCustomSeparator(document.getCustomSeparator());
|
|
|
+ updateObj.setWordNum(document.getWordNum());
|
|
|
+ updateObj.setKnowledgeType(document.getKnowledgeType());
|
|
|
+ updateObj.setLength(document.getLength());
|
|
|
+ updateObj.setParseImage(document.getParseImage());
|
|
|
+
|
|
|
+ bmDocumentMapper.updateDocument(updateObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateImageList(List<BmMediaReplacement> imageList,String documentId) {
|
|
|
+ BmMediaReplacement condition = BmMediaReplacement.builder().documentId(documentId).build();
|
|
|
+ List<BmMediaReplacement> dbList = bmMediaReplacementMapper.selectMediaList(condition);
|
|
|
+ for(BmMediaReplacement image : imageList) {
|
|
|
+ Optional<BmMediaReplacement> optObj = dbList.stream().filter(a -> a.getOriginText().equals(image.getOriginText())).findFirst();
|
|
|
+ if (!optObj.isPresent()) {
|
|
|
+ image.setDocumentId(documentId);
|
|
|
+ bmMediaReplacementMapper.insertMedia(image);
|
|
|
+ } else if(!optObj.get().getOriginText().equals(image.getOriginText())
|
|
|
+ || !optObj.get().getMediaUrl().equals(image.getMediaUrl())) {
|
|
|
+ BmMediaReplacement updateObj = optObj.get();
|
|
|
+ updateObj.setDocumentId(image.getDocumentId());
|
|
|
+ updateObj.setOriginText(image.getOriginText());
|
|
|
+ updateObj.setMediaUrl(image.getMediaUrl());
|
|
|
+
|
|
|
+ bmMediaReplacementMapper.updateMedia(updateObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<BmMediaReplacement> getDocumentImageList(String documentId) {
|
|
|
String url = bigModelConfig.getBaseurl() + bigModelConfig.getImage().replace("{id}",documentId);
|