From 57663673908f0d557fc16153263f7d89f8b16d63 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 10 Sep 2024 16:54:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=B7=A5=E4=BD=9C=E5=8F=B0):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=8E=E6=A8=A1=E7=89=88=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=A8=A1=E7=89=88=E6=96=B9=E5=BC=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=A8=A1=E7=89=88=E5=B8=82=E5=9C=BA=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=95=B0=E9=87=8F=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=B8=82=E5=9C=BA=E4=B8=AD=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=A8=A1=E6=9D=BF=E4=BD=BF=E7=94=A8=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E2=80=9C=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=E2=80=9D=20#12039?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/manage/TemplateCenterManage.java | 54 +++++++++++++------ .../server/DataVisualizationServer.java | 2 +- .../response/MarketLatestRelease.java | 8 +++ .../response/MarketTemplateV2ItemResult.java | 3 ++ .../vo/MarketApplicationMetaDataVO.java | 9 ++++ .../api/template/vo/MarketApplicationVO.java | 3 ++ .../template/vo/MarketLatestReleaseVO.java | 14 +++++ .../api/template/vo/MarketReleaseAssetVO.java | 9 ++++ .../template/vo/MarketReleaseMetaDataVO.java | 8 +++ .../api/template/vo/MarketReleaseVO.java | 9 ++++ 10 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketLatestRelease.java create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationMetaDataVO.java create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketLatestReleaseVO.java create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseAssetVO.java create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseMetaDataVO.java create mode 100644 sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseVO.java diff --git a/core/core-backend/src/main/java/io/dataease/template/manage/TemplateCenterManage.java b/core/core-backend/src/main/java/io/dataease/template/manage/TemplateCenterManage.java index 4d9bebc9b7..c8bf7328fc 100644 --- a/core/core-backend/src/main/java/io/dataease/template/manage/TemplateCenterManage.java +++ b/core/core-backend/src/main/java/io/dataease/template/manage/TemplateCenterManage.java @@ -5,7 +5,9 @@ import io.dataease.api.template.dto.TemplateManageFileDTO; import io.dataease.api.template.dto.TemplateMarketDTO; import io.dataease.api.template.dto.TemplateMarketPreviewInfoDTO; import io.dataease.api.template.response.*; +import io.dataease.api.template.vo.MarketApplicationMetaDataVO; import io.dataease.api.template.vo.MarketApplicationSpecVO; +import io.dataease.api.template.vo.MarketLatestReleaseVO; import io.dataease.api.template.vo.MarketMetaDataVO; import io.dataease.constant.CommonConstants; import io.dataease.exception.DEException; @@ -36,6 +38,7 @@ import java.util.stream.Collectors; public class TemplateCenterManage { private final static String POSTS_API_V2 = "/apis/api.store.halo.run/v1alpha1/applications?keyword=&priceMode=&sort=latestReleaseTimestamp%2Cdesc&type=THEME&deVersion=V2&templateType=&label=&page=1&size=2000"; private final static String TEMPLATE_META_DATA_URL = "/upload/meta_data.json"; + private final static String TEMPLATE_BASE_INFO_URL = "/apis/api.store.halo.run/v1alpha1/applications/"; @Resource private SysParameterManage sysParameterManage; @@ -54,8 +57,8 @@ public class TemplateCenterManage { */ public TemplateManageFileDTO getTemplateFromMarket(String templateUrl) { if (StringUtils.isNotEmpty(templateUrl)) { - String templateName = templateUrl.substring(templateUrl.lastIndexOf("/")+1,templateUrl.length()); - templateUrl = templateUrl.replace(templateName,URLEncoder.encode(templateName, StandardCharsets.UTF_8).replace("+", "%20")); + String templateName = templateUrl.substring(templateUrl.lastIndexOf("/") + 1, templateUrl.length()); + templateUrl = templateUrl.replace(templateName, URLEncoder.encode(templateName, StandardCharsets.UTF_8).replace("+", "%20")); String sufUrl = sysParameterManage.groupVal("template.").get("template.url"); String templateInfo = HttpClientUtil.get(sufUrl + templateUrl, null); return JsonUtil.parseObject(templateInfo, TemplateManageFileDTO.class); @@ -64,6 +67,25 @@ public class TemplateCenterManage { } } + /** + * @param templateUrl template url + * @Description Get template file from template market + */ + public TemplateManageFileDTO getTemplateFromMarketV2(String templateName) { + if (StringUtils.isNotEmpty(templateName)) { + String sufUrl = sysParameterManage.groupVal("template.").get("template.url"); + String templateBaseInfo = HttpClientUtil.get(sufUrl + TEMPLATE_BASE_INFO_URL + templateName, null); + MarketTemplateV2ItemResult baseItemInfo = JsonUtil.parseObject(templateBaseInfo, MarketTemplateV2ItemResult.class); + String templateUrl = sufUrl + "/store/apps/" + templateName + + "/releases/download/" + baseItemInfo.getLatestRelease().getRelease().getMetadata().getName() + + "/assets/" + baseItemInfo.getLatestRelease().getAssets().getFirst().getMetadata().getName(); + String templateInfo = HttpClientUtil.get(templateUrl, null); + return JsonUtil.parseObject(templateInfo, TemplateManageFileDTO.class); + } else { + return null; + } + } + /** * @param url content api url * @Description Get info from template market content api @@ -117,8 +139,8 @@ public class TemplateCenterManage { manageResult.stream().forEach(templateManageDTO -> { templateManageDTO.setCategoryName(categoryMap.get(templateManageDTO.getPid())); List categories = templateManageDTO.getCategories(); - if(!CollectionUtils.isEmpty(categories)){ - List categoryNames = categories.stream().map(categoryId ->categoryMap.get(categoryId)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(categories)) { + List categoryNames = categories.stream().map(categoryId -> categoryMap.get(categoryId)).collect(Collectors.toList()); templateManageDTO.setCategoryNames(categoryNames); result.add(new TemplateMarketDTO(templateManageDTO)); } @@ -172,7 +194,7 @@ public class TemplateCenterManage { } } - private MarketBaseResponse baseResponseV2TransRecommend(MarketTemplateV2BaseResponse v2BaseResponse,List templateManages, String url) { + private MarketBaseResponse baseResponseV2TransRecommend(MarketTemplateV2BaseResponse v2BaseResponse, List templateManages, String url) { Map useTime = coreOptRecentManage.findTemplateRecentUseTime(); List categoryVO = getCategoriesV2().stream().filter(node -> !"全部".equalsIgnoreCase(node.getLabel())).collect(Collectors.toList()); Map categoriesMap = categoryVO.stream() @@ -181,8 +203,9 @@ public class TemplateCenterManage { if (v2BaseResponse != null) { v2BaseResponse.getItems().stream().forEach(marketTemplateV2ItemResult -> { MarketApplicationSpecVO spec = marketTemplateV2ItemResult.getApplication().getSpec(); + MarketApplicationMetaDataVO metadata = marketTemplateV2ItemResult.getApplication().getMetadata(); if ("Y".equalsIgnoreCase(spec.getSuggest())) { - contents.add(new TemplateMarketDTO(spec.getReadmeName(), spec.getDisplayName(), spec.getScreenshots().get(0).getUrl(), spec.getLinks().get(0).getUrl(), categoriesMap.get(spec.getLabel()), spec.getTemplateType(), useTime.get(spec.getReadmeName()), "Y")); + contents.add(new TemplateMarketDTO(metadata.getName(), spec.getDisplayName(), spec.getScreenshots().get(0).getUrl(), spec.getLinks().get(0).getUrl(), categoriesMap.get(spec.getLabel()), spec.getTemplateType(), useTime.get(spec.getReadmeName()), "Y")); } }); } @@ -192,16 +215,16 @@ public class TemplateCenterManage { Long countDashboard = contents.stream().filter(item -> "SCREEN".equals(item.getTemplateType())).count(); List templateDataV = templateManages.stream().filter(item -> "PANEL".equals(item.getTemplateType())).collect(Collectors.toList()); List templateDashboard = templateManages.stream().filter(item -> "SCREEN".equals(item.getTemplateType())).collect(Collectors.toList()); - if(countDataV<10){ - Long addItemCount = 10 -countDataV; - Long addIndex = templateDataV.size() { MarketApplicationSpecVO spec = marketTemplateV2ItemResult.getApplication().getSpec(); - contents.add(new TemplateMarketDTO(spec.getReadmeName(), spec.getDisplayName(), spec.getScreenshots().get(0).getUrl(), spec.getLinks().get(0).getUrl(), categoriesMap.get(spec.getLabel()), spec.getTemplateType(), useTime.get(spec.getReadmeName()), spec.getSuggest())); + MarketApplicationMetaDataVO metadata = marketTemplateV2ItemResult.getApplication().getMetadata(); + contents.add(new TemplateMarketDTO(metadata.getName(), spec.getDisplayName(), spec.getScreenshots().get(0).getUrl(), spec.getLinks().get(0).getUrl(), categoriesMap.get(spec.getLabel()), spec.getTemplateType(), useTime.get(spec.getReadmeName()), spec.getSuggest())); if (categoriesMap.get(spec.getLabel()) != null) { activeCategoriesName.add(categoriesMap.get(spec.getLabel())); } diff --git a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java index 7fbda9ee6b..0f9b83d565 100644 --- a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java +++ b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java @@ -571,7 +571,7 @@ public class DataVisualizationServer implements DataVisualizationApi { name = request.getName(); dvType = request.getType(); } else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_MARKET_TEMPLATE.equals(newFrom)) { - TemplateManageFileDTO templateFileInfo = templateCenterManage.getTemplateFromMarket(request.getTemplateUrl()); + TemplateManageFileDTO templateFileInfo = templateCenterManage.getTemplateFromMarketV2(request.getResourceName()); if (templateFileInfo == null) { DEException.throwException("Can't find the template's info from market,please check"); } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketLatestRelease.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketLatestRelease.java new file mode 100644 index 0000000000..06cf155e42 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketLatestRelease.java @@ -0,0 +1,8 @@ +package io.dataease.api.template.response; + +import lombok.Data; + +@Data +public class MarketLatestRelease { + +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketTemplateV2ItemResult.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketTemplateV2ItemResult.java index ca07c4889e..a169da7f6d 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketTemplateV2ItemResult.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/response/MarketTemplateV2ItemResult.java @@ -1,6 +1,7 @@ package io.dataease.api.template.response; import io.dataease.api.template.vo.MarketApplicationVO; +import io.dataease.api.template.vo.MarketLatestReleaseVO; import lombok.Data; /** @@ -12,4 +13,6 @@ public class MarketTemplateV2ItemResult { private MarketApplicationVO application; + private MarketLatestReleaseVO latestRelease; + } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationMetaDataVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationMetaDataVO.java new file mode 100644 index 0000000000..fb97f2b820 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationMetaDataVO.java @@ -0,0 +1,9 @@ +package io.dataease.api.template.vo; + +import lombok.Data; + +@Data +public class MarketApplicationMetaDataVO { + + private String name; +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationVO.java index 22ac987851..fbeddc1b2e 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationVO.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketApplicationVO.java @@ -9,5 +9,8 @@ import lombok.Data; */ @Data public class MarketApplicationVO { + private MarketApplicationSpecVO spec; + + private MarketApplicationMetaDataVO metadata; } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketLatestReleaseVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketLatestReleaseVO.java new file mode 100644 index 0000000000..8c3fe5ed99 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketLatestReleaseVO.java @@ -0,0 +1,14 @@ +package io.dataease.api.template.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class MarketLatestReleaseVO { + + private MarketReleaseVO release; + + private List assets; + +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseAssetVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseAssetVO.java new file mode 100644 index 0000000000..678f0c22f0 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseAssetVO.java @@ -0,0 +1,9 @@ +package io.dataease.api.template.vo; + +import lombok.Data; + +@Data +public class MarketReleaseAssetVO { + + private MarketReleaseMetaDataVO metadata; +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseMetaDataVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseMetaDataVO.java new file mode 100644 index 0000000000..07f49774a4 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseMetaDataVO.java @@ -0,0 +1,8 @@ +package io.dataease.api.template.vo; + +import lombok.Data; + +@Data +public class MarketReleaseMetaDataVO { + private String name; +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseVO.java new file mode 100644 index 0000000000..dde660f0ba --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/template/vo/MarketReleaseVO.java @@ -0,0 +1,9 @@ +package io.dataease.api.template.vo; + +import lombok.Data; + +@Data +public class MarketReleaseVO { + + private MarketReleaseMetaDataVO metadata; +}