From ffe1b86a28158830fe53341c68dd5a077e35e59e Mon Sep 17 00:00:00 2001 From: Koi-tsk <337023856@qq.com> Date: Fri, 26 Aug 2022 14:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=9E=8D=E5=90=88=E6=9C=8D=E5=8A=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fuse/controller/FuseController.java | 7 -- .../modules/fuse/service/TbFuseService.java | 2 - .../fuse/service/impl/TbFuseServiceImpl.java | 75 ++++++++++--------- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/fuse/controller/FuseController.java b/renren-admin/src/main/java/io/renren/modules/fuse/controller/FuseController.java index d05ee9ca..3da55e70 100644 --- a/renren-admin/src/main/java/io/renren/modules/fuse/controller/FuseController.java +++ b/renren-admin/src/main/java/io/renren/modules/fuse/controller/FuseController.java @@ -62,13 +62,6 @@ public class FuseController { return new Result().ok(tbFuseService.getFuseById(id)); } - @GetMapping("getDataResource") - @ApiOperation("获取资源数据") - @LogOperation("获取资源数据") - public Result> getDataResource() { - return new Result().ok(tbFuseService.getDataResource()); - } - @PostMapping @ApiOperation("保存") @LogOperation("保存") diff --git a/renren-admin/src/main/java/io/renren/modules/fuse/service/TbFuseService.java b/renren-admin/src/main/java/io/renren/modules/fuse/service/TbFuseService.java index b296b7ef..f50ea326 100644 --- a/renren-admin/src/main/java/io/renren/modules/fuse/service/TbFuseService.java +++ b/renren-admin/src/main/java/io/renren/modules/fuse/service/TbFuseService.java @@ -16,8 +16,6 @@ public interface TbFuseService extends CrudService { TbFuseDTO getFuseById(Long id); - List getDataResource(); - Integer addFuse(TbFuseDTO dto); Integer updateFuse(TbFuseDTO dto); diff --git a/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java index 39d39908..407db5dd 100644 --- a/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java @@ -33,7 +33,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.swing.text.html.Option; import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -46,6 +50,10 @@ public class TbFuseServiceImpl extends CrudServiceImpl getDataResource() { - int pageNum=0; - int pageSize=getDataResourceCount(); - List result = new ArrayList<>(); - Optional factory = DataResourceFactory.build(); - if (factory.isPresent()) { - GetDataResourceListDto dto = new GetDataResourceListDto().setPageNum(pageNum).setPageSize(pageSize); - Map dataMap = (Map) factory.get().getDataResource(dto); - if (dataMap != null) { - List> list = (List>) dataMap.get("data"); - list.forEach(map -> result.add(new HashMap() {{ - if (map.containsKey("zyname")) { - put("id", map.get("guid")); - put("name", map.get("zyname")); - } else { - put("id", map.get("serviceId")); - put("name", map.get("serviceName")); + private Map> getDataResource() { + Map result=new ConcurrentHashMap(); + final int pageSize = CPU_NUM * 10; + AtomicInteger pageIndex = new AtomicInteger(1); + AtomicBoolean end = new AtomicBoolean(true); + List completableFutures=new CopyOnWriteArrayList<>(); + while(end.get()){ + completableFutures.add(CompletableFuture.supplyAsync(()->{ + Optional factory = DataResourceFactory.build(); + if (factory.isPresent()) { + GetDataResourceListDto dto=new GetDataResourceListDto().setPageNum(pageIndex.get()).setPageSize(pageSize); + Map dataResource = (Map) factory.get().getDataResource(dto); + if(!dataResource.isEmpty()){ + List> list = (List>) dataResource.get("data"); + pageIndex.getAndIncrement(); + return new HashMap(){{put( list.stream().map(map->{ + if (map.containsKey("zyname")) { + return map.get("guid"); + } else { + return map.get("serviceId"); + } + }), list);}}; } - }})); - } + } + return null; + }).thenAcceptAsync(map->{ + if(map != null){ + result.putAll(map); + } + })); } return result; } - private int getDataResourceCount() { - int count=30; - Optional factory = DataResourceFactory.build(); - if (factory.isPresent()) { - GetDataResourceListDto dto = new GetDataResourceListDto().setPageNum(0).setPageSize(30); - Map dataMap = (Map) factory.get().getDataResource(dto); - if (dataMap != null) { - count=Integer.parseInt(dataMap.get("rows").toString()); - } - } - return count; - } - private List getFuseResourceByFuseId(Long fuseId) { - List dataResourceMap = new ArrayList<>(); + Map dataResourceMap = new HashMap(); List result = new ArrayList(); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("fuse_id", fuseId); List list = fuseResourceDao.selectList(wrapper); Map> resourceMap = list.stream().filter(index -> index.getType() != null).collect(Collectors.groupingBy(TbFuseResourceEntity::getType)); if (resourceMap.containsKey("数据资源")) { - dataResourceMap.addAll(getDataResource()); + dataResourceMap.putAll(getDataResource()); } resourceMap.forEach((type, value) -> { if ("组件服务".equals(type)) { @@ -215,7 +220,7 @@ public class TbFuseServiceImpl extends CrudServiceImpl { TbFuseResourceDTO dto = new TbFuseResourceDTO(); BeanUtils.copyProperties(attr, dto); - dto.setResource(dataResourceMap.stream().filter(it->it.get("id").equals(dto.getResourceId())).findFirst()); + dto.setResource(dataResourceMap.get(dto.getResourceId())); return dto; }).collect(Collectors.toList())); } else if ("基础设施".equals(type)) {