同步知识库的优化

This commit is contained in:
wangliwen 2022-08-25 17:55:27 +08:00
parent 30b5ee12f0
commit 70c706ba73
1 changed files with 54 additions and 53 deletions

View File

@ -1224,64 +1224,65 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
if (list.isEmpty() || list.size() < pageSize) { if (list.isEmpty() || list.size() < pageSize) {
end.set(false); end.set(false);
} }
customThreadPool.submit(() -> { customThreadPool.submit(() -> list.parallelStream().filter(resource -> {
list.parallelStream().filter(resource -> { Map<String, Object> map = (Map<String, Object>) resource;
Map<String, Object> map = (Map<String, Object>) resource; return !knowledgeUUID.contains(map.get("uuid").toString());
return !knowledgeUUID.contains(map.get("uuid").toString()); }).forEach(resource -> {
}).forEach(resource -> { Map<String, Object> map = (Map<String, Object>) resource;
Map<String, Object> map = (Map<String, Object>) resource; ResourceDTO dto = new ResourceDTO();
ResourceDTO dto = new ResourceDTO(); dto.setName(map.get("title").toString());
dto.setName(map.get("title").toString()); dto.setType("知识库");
dto.setType("知识库"); dto.setVisits(0L);
dto.setVisits(0L); //所属部门暂时设为青岛市政府办公厅
//所属部门暂时设为青岛市政府办公厅 dto.setDeptId(1517116100113850370L);
dto.setDeptId(1517116100113850370L); dto.setNote1(map.get("uuid").toString());
dto.setNote1(map.get("uuid").toString()); dto.setDelFlag(0);
dto.setDelFlag(0); ArrayList<AttrEntity> infoList = new ArrayList<>();
ArrayList<AttrEntity> infoList = new ArrayList<>(); map.forEach((key, value) -> {
map.forEach((key, value) -> { switch (key) {
switch (key) { case "title":
case "title": dto.setName(value.toString());
dto.setName(value.toString()); break;
break; case "url":
case "url": dto.setLink(value.toString());
dto.setLink(value.toString()); break;
break; case "createtime":
case "createtime": Date createDate = new Date(Long.parseLong(value.toString()));
Date createDate = new Date(Long.parseLong(value.toString())); dto.setCreateDate(createDate);
dto.setCreateDate(createDate); break;
break; default:
default: AttrEntity attrEntity = new AttrEntity();
AttrEntity attrEntity = new AttrEntity(); attrEntity.setDelFlag(0);
attrEntity.setDelFlag(0); attrEntity.setAttrType(key);
attrEntity.setAttrType(key); attrEntity.setAttrValue(value.toString());
attrEntity.setAttrValue(value.toString()); infoList.add(attrEntity);
infoList.add(attrEntity); break;
break;
}
});
AttrEntity attrEntity = new AttrEntity();
attrEntity.setDelFlag(0);
attrEntity.setAttrType("文件类型");
if ("f49561afc7204f008c4bb3cd821eb6ba".equals(index)) {
attrEntity.setAttrValue("政府公报");
} else {
attrEntity.setAttrValue("政策解读");
} }
infoList.add(attrEntity);
dto.setInfoList(infoList);
this.insertWithAttrs(dto);
logger.info("插入:{}", dto.getName());
}); });
}).join(); AttrEntity attrEntity = new AttrEntity();
attrEntity.setDelFlag(0);
attrEntity.setAttrType("文件类型");
if ("f49561afc7204f008c4bb3cd821eb6ba".equals(index)) {
attrEntity.setAttrValue("政府公报");
} else {
attrEntity.setAttrValue("政策解读");
}
infoList.add(attrEntity);
dto.setInfoList(infoList);
this.insertWithAttrs(dto);
logger.info("插入:{}", dto.getName());
})).join();
customThreadPool.shutdown(); customThreadPool.shutdown();
}, executor)); }, executor));
try {
Thread.sleep(100L); // 防止任务运行过快无法跳出循环 if (maxPage.get() == 100) {
} catch (InterruptedException e) { try {
logger.info("知识库同步异常", e); Thread.sleep(new Random().nextInt(100)); // 防止任务运行过快无法跳出循环
// throw new RuntimeException(e); } catch (InterruptedException e) {
logger.info("知识库同步异常", e);
}
} }
} while (end.get() || pageIndex.get() < maxPage.get()); } while (end.get() || pageIndex.get() < maxPage.get());
return task; return task;
}).collect(Collectors.toList()); }).collect(Collectors.toList());