Merge remote-tracking branch 'origin/develop' into develop

master
luoyang 6 years ago
commit c722acd720

@ -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);
}
}

Loading…
Cancel
Save