提交 86a9e623 编写于 作者: O o2sword

修复设计搜索,减少线程创建

上级 fd74eeca
......@@ -170,42 +170,28 @@ class ActionSearch extends BaseAction {
}catch (Exception e){
logger.error(e);
}
Executor executor = Executors.newFixedThreadPool(batchList.size());
List<CompletableFuture<List<Wo>>> cfList = new ArrayList<>();
List<Wo> resWos = new ArrayList<>();
for (List<String> partProcessIds : batchList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<Process> processList = emc.list(Process.class, partProcessIds);
for (Process process : processList) {
try {
Wo wo = doProcessSearch(business, process, wi);
if (wo!=null){
resWos.add(wo);
}
} catch (Exception e) {
logger.error(e);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<Process> processList = emc.list(Process.class, partProcessIds);
for (Process process : processList) {
try {
Wo wo = doProcessSearch(business, process, wi);
if (wo!=null){
resWos.add(wo);
}
} catch (Exception e) {
logger.error(e);
}
processList.clear();
processList = null;
}catch (Exception e){
logger.error(e);
}
return resWos;
}, executor);
cfList.add(cf);
}
List<Wo> woList = new ArrayList<>();
for (CompletableFuture<List<Wo>> cf : cfList){
try {
woList.addAll(cf.get(30, TimeUnit.SECONDS));
} catch (Exception e){
processList.clear();
processList = null;
}catch (Exception e){
logger.error(e);
}
}
return woList;
return resWos;
}
......
......@@ -34,7 +34,7 @@ class ActionSearch extends BaseAction {
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
logger.info("{}搜索设计:{}的关键字:{}", effectivePerson.getDistinguishedName(), wi.getModuleList(), wi.getKeyword());
logger.debug("{}搜索设计:{}的关键字:{}", effectivePerson.getDistinguishedName(), wi.getModuleList(), wi.getKeyword());
if (ListTools.isNotEmpty(wi.getModuleList())) {
result.setData(search(wi, effectivePerson));
}else{
......@@ -92,67 +92,38 @@ class ActionSearch extends BaseAction {
moduleMap.put(ModuleType.service.toString(), list);
}
}
Executor executor = Executors.newFixedThreadPool(5);
CompletableFuture<List<WrapDesigner>> processPlatformCf = searchAsync(wi, moduleMap, ModuleType.processPlatform.toString(), x_processplatform_assemble_designer.class, executor);
CompletableFuture<List<WrapDesigner>> portalCf = searchAsync(wi, moduleMap, ModuleType.portal.toString(), x_portal_assemble_designer.class, executor);
CompletableFuture<List<WrapDesigner>> cmsCf = searchAsync(wi, moduleMap, ModuleType.cms.toString(), x_cms_assemble_control.class, executor);
CompletableFuture<List<WrapDesigner>> queryCf = searchAsync(wi, moduleMap, ModuleType.query.toString(), x_query_assemble_designer.class, executor);
CompletableFuture<List<WrapDesigner>> serviceCf = searchAsync(wi, moduleMap, ModuleType.service.toString(), x_program_center.class, executor);
Wo wo = new Wo();
try {
wo.setProcessPlatformList(processPlatformCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索流程平台设计异常:{}",e.getMessage());
}
try {
wo.setPortalList(portalCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索门户平台设计异常:{}",e.getMessage());
}
try {
wo.setCmsList(cmsCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索内容管理平台设计异常:{}",e.getMessage());
}
try {
wo.setQueryList(queryCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索数据中心平台设计异常:{}",e.getMessage());
}
try {
wo.setServiceList(serviceCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索服务管理平台设计异常:{}",e.getMessage());
}
wo.setProcessPlatformList(searchApp(wi, moduleMap, ModuleType.processPlatform.toString(), x_processplatform_assemble_designer.class));
wo.setPortalList(searchApp(wi, moduleMap, ModuleType.portal.toString(), x_portal_assemble_designer.class));
wo.setCmsList(searchApp(wi, moduleMap, ModuleType.cms.toString(), x_cms_assemble_control.class));
wo.setQueryList(searchApp(wi, moduleMap, ModuleType.query.toString(), x_query_assemble_designer.class));
wo.setServiceList(searchApp(wi, moduleMap, ModuleType.service.toString(), x_program_center.class));
return wo;
}
private CompletableFuture<List<WrapDesigner>> searchAsync(final Wi wi, final Map<String, List<WiDesigner.ModuleApp>> moduleMap, final String moduleType, final Class<?> applicationClass, Executor executor){
CompletableFuture<List<WrapDesigner>> cf = CompletableFuture.supplyAsync(() -> {
List<WrapDesigner> swList = null;
if(moduleMap.containsKey(moduleType)) {
private List<WrapDesigner> searchApp(final Wi wi, final Map<String, List<WiDesigner.ModuleApp>> moduleMap, final String moduleType, final Class<?> applicationClass){
List<WrapDesigner> swList = null;
if(moduleMap.containsKey(moduleType)) {
try {
WiDesigner wiDesigner = new WiDesigner();
BeanUtils.copyProperties(wiDesigner, wi);
wiDesigner.setModuleAppList(moduleMap.get(moduleType));
List<WrapDesigner> designerList = ThisApplication.context().applications().postQuery(applicationClass,
Applications.joinQueryUri("designer", "search"), wiDesigner).getDataAsList(WrapDesigner.class);
logger.debug("设计搜索关联{}的匹配设计个数:{}", moduleType, designerList.size());
getSearchRes(wi, designerList);
swList = designerList;
} catch (Exception e) {
logger.error(e);
}
if (swList!=null && swList.size() > 2) {
try {
WiDesigner wiDesigner = new WiDesigner();
BeanUtils.copyProperties(wiDesigner, wi);
wiDesigner.setModuleAppList(moduleMap.get(moduleType));
List<WrapDesigner> designerList = ThisApplication.context().applications().postQuery(applicationClass,
Applications.joinQueryUri("designer", "search"), wiDesigner).getDataAsList(WrapDesigner.class);
logger.info("设计搜索关联{}的匹配设计个数:{}", moduleType, designerList.size());
getSearchRes(wi, designerList);
swList = designerList;
SortTools.desc(swList, "designerType","appId");
} catch (Exception e) {
logger.error(e);
}
if (swList!=null && swList.size() > 2) {
try {
SortTools.desc(swList, "designerType","appId");
} catch (Exception e) {
}
}
}
return swList;
}, executor);
return cf;
}
return swList;
}
private void getSearchRes(final Wi wi, List<WrapDesigner> designerList){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册