Commit 613c012b authored by 黎博's avatar 黎博

优化/getSingleTypeApp接口

parent 36ada25d
......@@ -269,24 +269,27 @@ public class K8sController {
*/
@GetMapping("/getSingleTypeApp")
public JsonResult getSingleTypeApp(@RequestParam String namespace, @RequestParam String type) {
Map<String, Object> repoMap = imageService.getSingleTypeApp(namespace);
Map<String, Object> resultMap = new HashMap<>();
List<RepoInfo> repoInfoList = (List<RepoInfo>) repoMap.get("RepoInfo");
List<RepoInfo> newRepoInfoList = new ArrayList<>();
QueryWrapper<DockerProject> queryWrapper = new QueryWrapper<>();
for (RepoInfo repoInfo: repoInfoList) {
queryWrapper
.eq("project_name", repoInfo.getRepoName().split("/")[1])
.eq("project_type", type)
.eq("is_active", 1);
if (dockerProjectService.getOne(queryWrapper) != null) {
newRepoInfoList.add(repoInfo);
List<RepoInfo> repoInfoList = imageService.getRepoInfoList(namespace);
if (repoInfoList.size() > 0) {
Map<String, Object> resultMap = new HashMap<>();
List<RepoInfo> newRepoInfoList = new ArrayList<>();
QueryWrapper<DockerProject> queryWrapper = new QueryWrapper<>();
for (RepoInfo repoInfo: repoInfoList) {
queryWrapper
.eq("project_name", repoInfo.getRepoName().split("/")[1])
.eq("project_type", type)
.eq("is_active", 1);
if (dockerProjectService.getOne(queryWrapper) != null) {
newRepoInfoList.add(repoInfo);
}
queryWrapper.clear();
}
queryWrapper.clear();
resultMap.put("RepoInfo", newRepoInfoList);
resultMap.put("TotalCount", newRepoInfoList.size());
return JsonResult.buildSuccessResult(resultMap);
} else {
return JsonResult.buildSuccessResult(null);
}
resultMap.put("RepoInfo", newRepoInfoList);
resultMap.put("TotalCount", repoMap.get("TotalCount"));
return JsonResult.buildSuccessResult(resultMap);
}
/**
......
......@@ -57,7 +57,7 @@ public class ImageService {
* @param namespace qa-base, qa-java, qa-ui 等等
* @return
*/
public Map<String, Object> getSingleTypeApp(String namespace) {
public List<RepoInfo> getRepoInfoList(String namespace) {
try {
DescribeRepositoryFilterPersonalRequest request = new DescribeRepositoryFilterPersonalRequest();
request.setNamespace(namespace);
......@@ -66,9 +66,7 @@ public class ImageService {
request.setLimit(100L);
request.setRepoName("");
DescribeRepositoryFilterPersonalResponse response = tcrClient.DescribeRepositoryFilterPersonal(request);
Map<String, Object> resultMap = new HashMap<>();
Long TotalCount = response.getData().getTotalCount();
resultMap.put("TotalCount", TotalCount);
List<RepoInfo> repoInfoList = new ArrayList<>(Arrays.asList(response.getData().getRepoInfo()));
int num = Math.toIntExact(TotalCount / 100);
if ((TotalCount % 100) > 0) {
......@@ -79,8 +77,7 @@ public class ImageService {
response = tcrClient.DescribeRepositoryFilterPersonal(request);
repoInfoList.addAll(Arrays.asList(response.getData().getRepoInfo()));
}
resultMap.put("RepoInfo", repoInfoList);
return resultMap;
return repoInfoList;
} catch (Exception e) {
e.printStackTrace();
return null;
......@@ -89,7 +86,7 @@ public class ImageService {
public static void main(String[] args) {
ImageService imageService = new ImageService();
System.out.println(JSON.toJSONString(imageService.getSingleTypeApp("qa-test")));
System.out.println(JSON.toJSONString(imageService.getRepoInfoList("qa-test")));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment