融合服务修改

This commit is contained in:
Koi-tsk 2022-08-26 14:47:55 +08:00
parent bc6dfd164d
commit ffe1b86a28
3 changed files with 40 additions and 44 deletions

View File

@ -62,13 +62,6 @@ public class FuseController {
return new Result<TbFuseDTO>().ok(tbFuseService.getFuseById(id));
}
@GetMapping("getDataResource")
@ApiOperation("获取资源数据")
@LogOperation("获取资源数据")
public Result<List<Map>> getDataResource() {
return new Result().ok(tbFuseService.getDataResource());
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")

View File

@ -16,8 +16,6 @@ public interface TbFuseService extends CrudService<TbFuseEntity, TbFuseDTO> {
TbFuseDTO getFuseById(Long id);
List<Map> getDataResource();
Integer addFuse(TbFuseDTO dto);
Integer updateFuse(TbFuseDTO dto);

View File

@ -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<TbFuseDao, TbFuseEntity,
private static final Logger logger = LoggerFactory.getLogger(ResourceServiceImpl.class);
private static final Integer CPU_NUM = Runtime.getRuntime().availableProcessors();
private static final ExecutorService executor = Executors.newWorkStealingPool(CPU_NUM * 3);
@Autowired
private TbFuseDao fuseDao;
@Autowired
@ -154,52 +162,49 @@ public class TbFuseServiceImpl extends CrudServiceImpl<TbFuseDao, TbFuseEntity,
}).collect(Collectors.toList());
}
public List<Map> getDataResource() {
int pageNum=0;
int pageSize=getDataResourceCount();
List<Map> result = new ArrayList<>();
Optional<AbstractDataResourceService> factory = DataResourceFactory.build();
if (factory.isPresent()) {
GetDataResourceListDto dto = new GetDataResourceListDto().setPageNum(pageNum).setPageSize(pageSize);
Map<String, Object> dataMap = (Map<String, Object>) factory.get().getDataResource(dto);
if (dataMap != null) {
List<Map<String, Object>> list = (List<Map<String, Object>>) 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<String, List<Map>> getDataResource() {
Map result=new ConcurrentHashMap();
final int pageSize = CPU_NUM * 10;
AtomicInteger pageIndex = new AtomicInteger(1);
AtomicBoolean end = new AtomicBoolean(true);
List<CompletableFuture> completableFutures=new CopyOnWriteArrayList<>();
while(end.get()){
completableFutures.add(CompletableFuture.supplyAsync(()->{
Optional<AbstractDataResourceService> factory = DataResourceFactory.build();
if (factory.isPresent()) {
GetDataResourceListDto dto=new GetDataResourceListDto().setPageNum(pageIndex.get()).setPageSize(pageSize);
Map<String, Object> dataResource = (Map<String, Object>) factory.get().getDataResource(dto);
if(!dataResource.isEmpty()){
List<Map<String, Object>> list = (List<Map<String, Object>>) 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<AbstractDataResourceService> factory = DataResourceFactory.build();
if (factory.isPresent()) {
GetDataResourceListDto dto = new GetDataResourceListDto().setPageNum(0).setPageSize(30);
Map<String, Object> dataMap = (Map<String, Object>) factory.get().getDataResource(dto);
if (dataMap != null) {
count=Integer.parseInt(dataMap.get("rows").toString());
}
}
return count;
}
private List<TbFuseResourceDTO> getFuseResourceByFuseId(Long fuseId) {
List<Map> dataResourceMap = new ArrayList<>();
Map dataResourceMap = new HashMap();
List<TbFuseResourceDTO> result = new ArrayList();
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("fuse_id", fuseId);
List<TbFuseResourceEntity> list = fuseResourceDao.selectList(wrapper);
Map<String, List<TbFuseResourceEntity>> 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<TbFuseDao, TbFuseEntity,
result.addAll(value.stream().map(attr -> {
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)) {