From f009996a95f53b8e4c3a93acf4f6bca34a13359e Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 20 Dec 2022 16:08:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=A8=A1=E6=9D=BF=E5=B8=82=E5=9C=BA):?= =?UTF-8?q?=20=E6=A8=A1=E6=9D=BF=E5=B8=82=E5=9C=BA=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=BA=94=E7=94=A8=E7=B3=BB=E5=88=97=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateMarket/TemplateMarketService.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/templateMarket/TemplateMarketService.java b/backend/src/main/java/io/dataease/service/templateMarket/TemplateMarketService.java index 658c23aa91..978f11c73b 100644 --- a/backend/src/main/java/io/dataease/service/templateMarket/TemplateMarketService.java +++ b/backend/src/main/java/io/dataease/service/templateMarket/TemplateMarketService.java @@ -29,56 +29,56 @@ import java.util.stream.Collectors; @Service public class TemplateMarketService { - private final static String POSTS_API="/api/content/posts?page=0&size=2000"; - private final static String CATEGORIES_API="/api/content/categories"; + private final static String POSTS_API = "/api/content/posts?page=0&size=2000"; + private final static String CATEGORIES_API = "/api/content/categories"; @Resource private SystemParameterService systemParameterService; /** - * @Description Get template file from template market * @param templateUrl template url + * @Description Get template file from template market */ - public PanelTemplateFileDTO getTemplateFromMarket(String templateUrl){ - if(StringUtils.isNotEmpty(templateUrl)){ + public PanelTemplateFileDTO getTemplateFromMarket(String templateUrl) { + if (StringUtils.isNotEmpty(templateUrl)) { String sufUrl = systemParameterService.templateMarketInfo().getTemplateMarketUlr(); Gson gson = new Gson(); - String templateInfo = HttpClientUtil.get(sufUrl+templateUrl,null); + String templateInfo = HttpClientUtil.get(sufUrl + templateUrl, null); return gson.fromJson(templateInfo, PanelTemplateFileDTO.class); - }else{ + } else { return null; } } /** - * @Description Get info from template market content api * @param url content api url + * @Description Get info from template market content api */ - public String marketGet(String url,String accessKey){ + public String marketGet(String url, String accessKey) { HttpClientConfig config = new HttpClientConfig(); - config.addHeader("API-Authorization",accessKey); - return HttpClientUtil.get(url,config); + config.addHeader("API-Authorization", accessKey); + return HttpClientUtil.get(url, config); } - public MarketBaseResponse searchTemplate(TemplateMarketSearchRequest request){ - try{ + public MarketBaseResponse searchTemplate(TemplateMarketSearchRequest request) { + try { BasicInfo basicInfo = systemParameterService.templateMarketInfo(); - String result = marketGet(basicInfo.getTemplateMarketUlr()+POSTS_API,basicInfo.getTemplateAccessKey()); - List postsResult = JSONObject.parseObject(result).getJSONObject("data").getJSONArray("content").toJavaList(TemplateMarketDTO.class); - return new MarketBaseResponse(basicInfo.getTemplateMarketUlr(),postsResult); - }catch (Exception e){ + String result = marketGet(basicInfo.getTemplateMarketUlr() + POSTS_API, basicInfo.getTemplateAccessKey()); + List postsResult = JSONObject.parseObject(result).getJSONObject("data").getJSONArray("content").toJavaList(TemplateMarketDTO.class); + return new MarketBaseResponse(basicInfo.getTemplateMarketUlr(), postsResult); + } catch (Exception e) { DataEaseException.throwException(e); } return null; } - public List getCategories(){ + public List getCategories() { BasicInfo basicInfo = systemParameterService.templateMarketInfo(); - String resultStr = marketGet(basicInfo.getTemplateMarketUlr()+CATEGORIES_API,basicInfo.getTemplateAccessKey()); + String resultStr = marketGet(basicInfo.getTemplateMarketUlr() + CATEGORIES_API, basicInfo.getTemplateAccessKey()); List categories = JSONObject.parseObject(resultStr).getJSONArray("data").toJavaList(TemplateCategory.class); - if(CollectionUtils.isNotEmpty(categories)){ - return categories.stream().sorted(Comparator.comparing(TemplateCategory::getPriority)).map(TemplateCategory :: getName).collect(Collectors.toList()); - }else{ + if (CollectionUtils.isNotEmpty(categories)) { + return categories.stream().filter(item -> !"应用系列".equals(item.getName())).sorted(Comparator.comparing(TemplateCategory::getPriority)).map(TemplateCategory::getName).collect(Collectors.toList()); + } else { return null; }