refactor(工作台): 优化从模版市场获取模版方式支持模版市场记录下载数量,修复模板市场中的部分模板使用时报“解析错误” #12039

This commit is contained in:
wangjiahao 2024-09-10 16:54:00 +08:00
parent aef0629df0
commit 5766367390
10 changed files with 103 additions and 16 deletions

View File

@ -5,7 +5,9 @@ import io.dataease.api.template.dto.TemplateManageFileDTO;
import io.dataease.api.template.dto.TemplateMarketDTO; import io.dataease.api.template.dto.TemplateMarketDTO;
import io.dataease.api.template.dto.TemplateMarketPreviewInfoDTO; import io.dataease.api.template.dto.TemplateMarketPreviewInfoDTO;
import io.dataease.api.template.response.*; 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.MarketApplicationSpecVO;
import io.dataease.api.template.vo.MarketLatestReleaseVO;
import io.dataease.api.template.vo.MarketMetaDataVO; import io.dataease.api.template.vo.MarketMetaDataVO;
import io.dataease.constant.CommonConstants; import io.dataease.constant.CommonConstants;
import io.dataease.exception.DEException; import io.dataease.exception.DEException;
@ -36,6 +38,7 @@ import java.util.stream.Collectors;
public class TemplateCenterManage { 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 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_META_DATA_URL = "/upload/meta_data.json";
private final static String TEMPLATE_BASE_INFO_URL = "/apis/api.store.halo.run/v1alpha1/applications/";
@Resource @Resource
private SysParameterManage sysParameterManage; private SysParameterManage sysParameterManage;
@ -54,8 +57,8 @@ public class TemplateCenterManage {
*/ */
public TemplateManageFileDTO getTemplateFromMarket(String templateUrl) { public TemplateManageFileDTO getTemplateFromMarket(String templateUrl) {
if (StringUtils.isNotEmpty(templateUrl)) { if (StringUtils.isNotEmpty(templateUrl)) {
String templateName = templateUrl.substring(templateUrl.lastIndexOf("/")+1,templateUrl.length()); String templateName = templateUrl.substring(templateUrl.lastIndexOf("/") + 1, templateUrl.length());
templateUrl = templateUrl.replace(templateName,URLEncoder.encode(templateName, StandardCharsets.UTF_8).replace("+", "%20")); templateUrl = templateUrl.replace(templateName, URLEncoder.encode(templateName, StandardCharsets.UTF_8).replace("+", "%20"));
String sufUrl = sysParameterManage.groupVal("template.").get("template.url"); String sufUrl = sysParameterManage.groupVal("template.").get("template.url");
String templateInfo = HttpClientUtil.get(sufUrl + templateUrl, null); String templateInfo = HttpClientUtil.get(sufUrl + templateUrl, null);
return JsonUtil.parseObject(templateInfo, TemplateManageFileDTO.class); 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 * @param url content api url
* @Description Get info from template market content api * @Description Get info from template market content api
@ -117,8 +139,8 @@ public class TemplateCenterManage {
manageResult.stream().forEach(templateManageDTO -> { manageResult.stream().forEach(templateManageDTO -> {
templateManageDTO.setCategoryName(categoryMap.get(templateManageDTO.getPid())); templateManageDTO.setCategoryName(categoryMap.get(templateManageDTO.getPid()));
List<String> categories = templateManageDTO.getCategories(); List<String> categories = templateManageDTO.getCategories();
if(!CollectionUtils.isEmpty(categories)){ if (!CollectionUtils.isEmpty(categories)) {
List<String> categoryNames = categories.stream().map(categoryId ->categoryMap.get(categoryId)).collect(Collectors.toList()); List<String> categoryNames = categories.stream().map(categoryId -> categoryMap.get(categoryId)).collect(Collectors.toList());
templateManageDTO.setCategoryNames(categoryNames); templateManageDTO.setCategoryNames(categoryNames);
result.add(new TemplateMarketDTO(templateManageDTO)); result.add(new TemplateMarketDTO(templateManageDTO));
} }
@ -172,7 +194,7 @@ public class TemplateCenterManage {
} }
} }
private MarketBaseResponse baseResponseV2TransRecommend(MarketTemplateV2BaseResponse v2BaseResponse,List<TemplateMarketDTO> templateManages, String url) { private MarketBaseResponse baseResponseV2TransRecommend(MarketTemplateV2BaseResponse v2BaseResponse, List<TemplateMarketDTO> templateManages, String url) {
Map<String, Long> useTime = coreOptRecentManage.findTemplateRecentUseTime(); Map<String, Long> useTime = coreOptRecentManage.findTemplateRecentUseTime();
List<MarketMetaDataVO> categoryVO = getCategoriesV2().stream().filter(node -> !"全部".equalsIgnoreCase(node.getLabel())).collect(Collectors.toList()); List<MarketMetaDataVO> categoryVO = getCategoriesV2().stream().filter(node -> !"全部".equalsIgnoreCase(node.getLabel())).collect(Collectors.toList());
Map<String, String> categoriesMap = categoryVO.stream() Map<String, String> categoriesMap = categoryVO.stream()
@ -181,8 +203,9 @@ public class TemplateCenterManage {
if (v2BaseResponse != null) { if (v2BaseResponse != null) {
v2BaseResponse.getItems().stream().forEach(marketTemplateV2ItemResult -> { v2BaseResponse.getItems().stream().forEach(marketTemplateV2ItemResult -> {
MarketApplicationSpecVO spec = marketTemplateV2ItemResult.getApplication().getSpec(); MarketApplicationSpecVO spec = marketTemplateV2ItemResult.getApplication().getSpec();
MarketApplicationMetaDataVO metadata = marketTemplateV2ItemResult.getApplication().getMetadata();
if ("Y".equalsIgnoreCase(spec.getSuggest())) { 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(); Long countDashboard = contents.stream().filter(item -> "SCREEN".equals(item.getTemplateType())).count();
List<TemplateMarketDTO> templateDataV = templateManages.stream().filter(item -> "PANEL".equals(item.getTemplateType())).collect(Collectors.toList()); List<TemplateMarketDTO> templateDataV = templateManages.stream().filter(item -> "PANEL".equals(item.getTemplateType())).collect(Collectors.toList());
List<TemplateMarketDTO> templateDashboard = templateManages.stream().filter(item -> "SCREEN".equals(item.getTemplateType())).collect(Collectors.toList()); List<TemplateMarketDTO> templateDashboard = templateManages.stream().filter(item -> "SCREEN".equals(item.getTemplateType())).collect(Collectors.toList());
if(countDataV<10){ if (countDataV < 10) {
Long addItemCount = 10 -countDataV; Long addItemCount = 10 - countDataV;
Long addIndex = templateDataV.size()<addItemCount? templateDataV.size() :addItemCount; Long addIndex = templateDataV.size() < addItemCount ? templateDataV.size() : addItemCount;
contents.addAll(templateDataV.subList(0,addIndex.intValue())); contents.addAll(templateDataV.subList(0, addIndex.intValue()));
} }
if(countDashboard<10){ if (countDashboard < 10) {
Long addItemCount = 10 -countDashboard; Long addItemCount = 10 - countDashboard;
Long addIndex = templateDashboard.size()<addItemCount? templateDashboard.size() :addItemCount; Long addIndex = templateDashboard.size() < addItemCount ? templateDashboard.size() : addItemCount;
contents.addAll(templateDashboard.subList(0,addIndex.intValue())); contents.addAll(templateDashboard.subList(0, addIndex.intValue()));
} }
return new MarketBaseResponse(url, categoryVO, contents); return new MarketBaseResponse(url, categoryVO, contents);
@ -221,7 +244,8 @@ public class TemplateCenterManage {
if (v2BaseResponse != null) { if (v2BaseResponse != null) {
v2BaseResponse.getItems().stream().forEach(marketTemplateV2ItemResult -> { v2BaseResponse.getItems().stream().forEach(marketTemplateV2ItemResult -> {
MarketApplicationSpecVO spec = marketTemplateV2ItemResult.getApplication().getSpec(); 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) { if (categoriesMap.get(spec.getLabel()) != null) {
activeCategoriesName.add(categoriesMap.get(spec.getLabel())); activeCategoriesName.add(categoriesMap.get(spec.getLabel()));
} }

View File

@ -571,7 +571,7 @@ public class DataVisualizationServer implements DataVisualizationApi {
name = request.getName(); name = request.getName();
dvType = request.getType(); dvType = request.getType();
} else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_MARKET_TEMPLATE.equals(newFrom)) { } 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) { if (templateFileInfo == null) {
DEException.throwException("Can't find the template's info from market,please check"); DEException.throwException("Can't find the template's info from market,please check");
} }

View File

@ -0,0 +1,8 @@
package io.dataease.api.template.response;
import lombok.Data;
@Data
public class MarketLatestRelease {
}

View File

@ -1,6 +1,7 @@
package io.dataease.api.template.response; package io.dataease.api.template.response;
import io.dataease.api.template.vo.MarketApplicationVO; import io.dataease.api.template.vo.MarketApplicationVO;
import io.dataease.api.template.vo.MarketLatestReleaseVO;
import lombok.Data; import lombok.Data;
/** /**
@ -12,4 +13,6 @@ public class MarketTemplateV2ItemResult {
private MarketApplicationVO application; private MarketApplicationVO application;
private MarketLatestReleaseVO latestRelease;
} }

View File

@ -0,0 +1,9 @@
package io.dataease.api.template.vo;
import lombok.Data;
@Data
public class MarketApplicationMetaDataVO {
private String name;
}

View File

@ -9,5 +9,8 @@ import lombok.Data;
*/ */
@Data @Data
public class MarketApplicationVO { public class MarketApplicationVO {
private MarketApplicationSpecVO spec; private MarketApplicationSpecVO spec;
private MarketApplicationMetaDataVO metadata;
} }

View File

@ -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<MarketReleaseAssetVO> assets;
}

View File

@ -0,0 +1,9 @@
package io.dataease.api.template.vo;
import lombok.Data;
@Data
public class MarketReleaseAssetVO {
private MarketReleaseMetaDataVO metadata;
}

View File

@ -0,0 +1,8 @@
package io.dataease.api.template.vo;
import lombok.Data;
@Data
public class MarketReleaseMetaDataVO {
private String name;
}

View File

@ -0,0 +1,9 @@
package io.dataease.api.template.vo;
import lombok.Data;
@Data
public class MarketReleaseVO {
private MarketReleaseMetaDataVO metadata;
}