From 2436757e1dc581df5f854d29a92f5928ea2ef51c Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 19 Sep 2018 11:40:08 +0800 Subject: [PATCH] update --- .../cms/core/Impl/AppStyleServiceImpl.java | 74 +++---------------- 1 file changed, 9 insertions(+), 65 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/support/cms/core/Impl/AppStyleServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/support/cms/core/Impl/AppStyleServiceImpl.java index dee97a580..804daffe8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/support/cms/core/Impl/AppStyleServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/support/cms/core/Impl/AppStyleServiceImpl.java @@ -1,18 +1,14 @@ package au.com.royalpay.payment.manage.support.cms.core.Impl; import au.com.royalpay.payment.manage.support.cms.core.AppStyleService; -import au.com.royalpay.payment.tools.exceptions.ServerErrorException; -import cn.yixblog.platform.http.HttpRequestGenerator; -import cn.yixblog.platform.http.HttpRequestResult; +import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport; + import com.alibaba.fastjson.JSONObject; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestMethod; - -import java.io.IOException; -import java.net.URISyntaxException; @Service public class AppStyleServiceImpl implements AppStyleService { @@ -21,81 +17,29 @@ public class AppStyleServiceImpl implements AppStyleService { private String cmsHost; private Logger logger = LoggerFactory.getLogger(getClass()); + private RoyalPayCMSSupport royalPayCMSSupport; @Override public JSONObject listAppStyleGroup(int page, int limit) { - String url = concatUrl("/app/style_group"); - HttpRequestGenerator gen = new HttpRequestGenerator(url, RequestMethod.GET).addQueryString("page", page + "").addQueryString("limit", limit + ""); - try { - HttpRequestResult res = gen.execute(); - if (res.isSuccess()) { - return res.getResponseContentJSONObj(); - } - } catch (URISyntaxException | IOException e) { - logger.error(e.getMessage(), e); - } - throw new ServerErrorException("Failed to request CMS"); + return royalPayCMSSupport.listAppStyleGroup(page,limit); } @Override public JSONObject getAppStyleByStyleId(String style_id) { - String url = concatUrl("/app/style_group/" + style_id); - HttpRequestGenerator gen = new HttpRequestGenerator(url, RequestMethod.GET); - try { - HttpRequestResult res = gen.execute(); - if (res.isSuccess()) { - return res.getResponseContentJSONObj(); - } - } catch (URISyntaxException | IOException e) { - logger.error(e.getMessage(), e); - } - throw new ServerErrorException("Failed to request CMS"); + return royalPayCMSSupport.getAppStyleByStyleId(style_id); } @Override public void switchGroupByStyleId(String style_id) { - String url = concatUrl("/app/style_group/" + style_id); - try { - HttpRequestResult res = new HttpRequestGenerator(url, RequestMethod.PUT).execute(); - if (res.isSuccess()) { - return; - } - } catch (URISyntaxException e) { - logger.error(e.getMessage(), e); - } - throw new ServerErrorException("Failed to request CMS"); + royalPayCMSSupport.switchGroupByStyleId(style_id); } @Override public void addAppStyle(String style_id, JSONObject appStyleGroup) { - String url = concatUrl("/app/style_group"); - try { - HttpRequestResult gen = new HttpRequestGenerator(url, RequestMethod.POST).addQueryString("style_id", style_id).setJSONEntity(appStyleGroup).execute(); - if (gen.isSuccess()) { - return; - } - } catch (URISyntaxException e) { - logger.error(e.getMessage(), e); - } - throw new ServerErrorException("Failed to request CMS"); + royalPayCMSSupport.addAppStyle(style_id,appStyleGroup); } @Override public void updateAppStyleByStyleId(String style_id, String originStyleId, JSONObject appStyleGroup) { - String url = concatUrl("/app/style_group/" + style_id + "/style"); - try { - HttpRequestResult gen = new HttpRequestGenerator(url, RequestMethod.PUT).addQueryString("originStyleId", originStyleId).setJSONEntity(appStyleGroup).execute(); - if (gen.isSuccess()) { - return; - } - } catch (URISyntaxException e) { - logger.error(e.getMessage(), e); - } - throw new ServerErrorException("Failed to request CMS"); - } - - private String concatUrl(String uri) { - String host = cmsHost.endsWith("/") ? cmsHost.substring(0, cmsHost.length() - 1) : cmsHost; - uri = uri.startsWith("/") ? uri.substring(1) : uri; - return host + "/" + uri; + royalPayCMSSupport.updateAppStyleByStyleId(style_id,originStyleId,appStyleGroup); } }