|
|
|
package com.fr.design.mainframe.share.util;
|
|
|
|
|
|
|
|
import com.fr.design.DesignerCloudURLManager;
|
|
|
|
import com.fr.design.i18n.Toolkit;
|
|
|
|
import com.fr.design.mainframe.share.Bean.FilterTypeInfo;
|
|
|
|
import com.fr.form.share.bean.OnlineShareWidget;
|
|
|
|
import com.fr.form.share.bean.SortParameter;
|
|
|
|
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo;
|
|
|
|
import com.fr.design.mainframe.share.Bean.WidgetFilterTypeInfo;
|
|
|
|
import com.fr.design.mainframe.share.config.ComponentReuseConfigManager;
|
|
|
|
import com.fr.general.ComparatorUtils;
|
|
|
|
import com.fr.general.http.HttpClient;
|
|
|
|
import com.fr.general.http.HttpToolbox;
|
|
|
|
import com.fr.json.JSONArray;
|
|
|
|
import com.fr.json.JSONObject;
|
|
|
|
import com.fr.log.FineLoggerFactory;
|
|
|
|
import com.fanruan.product.ProductConstants;
|
|
|
|
import com.fr.stable.StableUtils;
|
|
|
|
import com.fr.stable.StringUtils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by kerry on 2021/11/3
|
|
|
|
*/
|
|
|
|
public class OnlineShopUtils {
|
|
|
|
|
|
|
|
private static final String CHART = "chart";
|
|
|
|
private static final String REPORT = "report";
|
|
|
|
private static final String CID_PREFIX = "cid";
|
|
|
|
private static final String CHART_IDS = "123457";
|
|
|
|
|
|
|
|
private OnlineShopUtils() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getWebMiniShopPath() {
|
|
|
|
return ComponentReuseConfigManager.getInstance().getWebMiniShopUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getReuInfoPath() {
|
|
|
|
return ComponentReuseConfigManager.getInstance().getMiniShopUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getWidgetReusePath() {
|
|
|
|
return StableUtils.pathJoin(getReuInfoPath(), "all/detail/");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getPackageChildrenPath() {
|
|
|
|
return StableUtils.pathJoin(getReuInfoPath(), "children/");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getWidgetFilterPath() {
|
|
|
|
return StableUtils.pathJoin(getReuInfoPath(), "/all/filter/");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getGetCompositeSortParaPath() {
|
|
|
|
return StableUtils.pathJoin(getReuInfoPath(), "sort_parameter");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getLatestReusesPath() {
|
|
|
|
return StableUtils.pathJoin(getReuInfoPath(), "prompt/update/");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getTestConnectionUrl() {
|
|
|
|
return DesignerCloudURLManager.getInstance().acquireUrlByKind("ping");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<FilterTypeInfo> getShowFilterTypeInfos() {
|
|
|
|
List<FilterTypeInfo> filterTypeInfos = new ArrayList<>();
|
|
|
|
List<WidgetFilterTypeInfo> widgetFilterTypeInfos = getWidgetFilterTypeInfos();
|
|
|
|
FilterTypeInfo widgetTypeInfo =
|
|
|
|
new FilterTypeInfo(Toolkit.i18nText("Fine-Design_Share_Filter_Widget_Type"), ShareFilterConstants.WIDGET_TYPE_FILTER_KEY);
|
|
|
|
for (WidgetFilterTypeInfo info : widgetFilterTypeInfos) {
|
|
|
|
if (ComparatorUtils.equals(ShareFilterConstants.CHART_FILTER_KEY, info.getKey())
|
|
|
|
|| ComparatorUtils.equals(ShareFilterConstants.REPORT_FILTER_KEY, info.getKey())) {
|
|
|
|
widgetTypeInfo.addFilterType(info);
|
|
|
|
if (!filterTypeInfos.contains(widgetTypeInfo)) {
|
|
|
|
filterTypeInfos.add(widgetTypeInfo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FilterTypeInfo typeInfo = new FilterTypeInfo(info.getTitle(), info.getKey());
|
|
|
|
typeInfo.addFilterType(info);
|
|
|
|
filterTypeInfos.add(typeInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filterTypeInfos.sort(Comparator.comparingInt(o -> OnlineFilterType.parse(o.getKey()).ordinal()));
|
|
|
|
return filterTypeInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum OnlineFilterType {
|
|
|
|
SHOW_DEVICE(ShareFilterConstants.SHOW_TERMINAL_FILTER_KEY),
|
|
|
|
STYLE(ShareFilterConstants.STYLE_FILTER_KEY),
|
|
|
|
WIDGET_TYPE(ShareFilterConstants.WIDGET_TYPE_FILTER_KEY),
|
|
|
|
FEE(ShareFilterConstants.FEE_FILTER_KEY),
|
|
|
|
VERSION(ShareFilterConstants.VERSION_FILTER_KEY);
|
|
|
|
private String flag;
|
|
|
|
|
|
|
|
private OnlineFilterType(String flag) {
|
|
|
|
this.flag = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static OnlineFilterType parse(String flag) {
|
|
|
|
for (OnlineFilterType filterType : values()) {
|
|
|
|
if (ComparatorUtils.equals(filterType.flag, flag)) {
|
|
|
|
return filterType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SHOW_DEVICE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<FilterTypeInfo> getEmbPaneShowFilterTypeInfos() {
|
|
|
|
List<FilterTypeInfo> filterTypeInfos = new ArrayList<>();
|
|
|
|
List<WidgetFilterTypeInfo> widgetFilterTypeInfos = getWidgetFilterTypeInfos();
|
|
|
|
WidgetFilterTypeInfo widgetTypeFilterInfo = new WidgetFilterTypeInfo();
|
|
|
|
widgetTypeFilterInfo.setTitle(Toolkit.i18nText("Fine-Design_Share_Filter_Widget_Type"));
|
|
|
|
FilterTypeInfo widgetType = new FilterTypeInfo(widgetTypeFilterInfo.getTitle(), ShareFilterConstants.WIDGET_TYPE_FILTER_KEY);
|
|
|
|
widgetType.addFilterType(widgetTypeFilterInfo);
|
|
|
|
WidgetFilterInfo reportCard = new WidgetFilterInfo();
|
|
|
|
reportCard.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Indicator_Card"));
|
|
|
|
WidgetFilterInfo chartType = new WidgetFilterInfo();
|
|
|
|
chartType.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Chart"));
|
|
|
|
WidgetFilterInfo otherType = new WidgetFilterInfo();
|
|
|
|
otherType.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Other_Type"));
|
|
|
|
widgetTypeFilterInfo.addFilterItem(reportCard);
|
|
|
|
widgetTypeFilterInfo.addFilterItem(chartType);
|
|
|
|
widgetTypeFilterInfo.addFilterItem(otherType);
|
|
|
|
for (WidgetFilterTypeInfo info : widgetFilterTypeInfos) {
|
|
|
|
if (ComparatorUtils.equals(ShareFilterConstants.SHOW_TERMINAL_FILTER_KEY, info.getKey())) {
|
|
|
|
FilterTypeInfo showTerminalInfo = new FilterTypeInfo(info.getTitle(), info.getKey());
|
|
|
|
showTerminalInfo.addFilterType(info);
|
|
|
|
filterTypeInfos.add(showTerminalInfo);
|
|
|
|
|
|
|
|
} else if (ComparatorUtils.equals(ShareFilterConstants.STYLE_FILTER_KEY, info.getKey())) {
|
|
|
|
FilterTypeInfo styleTypeInfo = new FilterTypeInfo(info.getTitle(), info.getKey());
|
|
|
|
styleTypeInfo.addFilterType(info);
|
|
|
|
filterTypeInfos.add(styleTypeInfo);
|
|
|
|
} else if (ComparatorUtils.equals(ShareFilterConstants.REPORT_FILTER_KEY, info.getKey())) {
|
|
|
|
for (WidgetFilterInfo filterInfo : info.getFilterItems()) {
|
|
|
|
if (ComparatorUtils.equals(filterInfo.getId(), "1")) {
|
|
|
|
reportCard.addChildFilterInfo(filterInfo);
|
|
|
|
} else {
|
|
|
|
otherType.addChildFilterInfo(filterInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ComparatorUtils.equals(ShareFilterConstants.CHART_FILTER_KEY, info.getKey())) {
|
|
|
|
for (WidgetFilterInfo filterInfo : info.getFilterItems()) {
|
|
|
|
if (filterInfo.getId() != null && CHART_IDS.contains(filterInfo.getId())) {
|
|
|
|
chartType.addChildFilterInfo(filterInfo);
|
|
|
|
} else {
|
|
|
|
otherType.addChildFilterInfo(filterInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filterTypeInfos.add(widgetType);
|
|
|
|
return filterTypeInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, SortParameter> getCompositeSortPara() {
|
|
|
|
Map<String, SortParameter> para = new HashMap<>();
|
|
|
|
try {
|
|
|
|
JSONArray resultArr = getResultAttrFromUrl(getGetCompositeSortParaPath());
|
|
|
|
int size = resultArr.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject jo = resultArr.getJSONObject(i);
|
|
|
|
SortParameter sortParameter = SortParameter.parseFromJSONObject(jo);
|
|
|
|
para.put(sortParameter.getParameter(), sortParameter);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String assembleFilter(List<WidgetFilterInfo> filterInfos) {
|
|
|
|
List<WidgetFilterInfo> allFilterInfos = getAllFilterInfoList(filterInfos);
|
|
|
|
List<String> cidList = new ArrayList<>();
|
|
|
|
Map<String, String> queryParaMap = new HashMap<>();
|
|
|
|
for (WidgetFilterInfo filterInfo : allFilterInfos) {
|
|
|
|
if (ComparatorUtils.equals(CHART, filterInfo.getType())
|
|
|
|
|| ComparatorUtils.equals(REPORT, filterInfo.getType())) {
|
|
|
|
cidList.add(filterInfo.getType() + "-" + filterInfo.getId());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String queryValue = queryParaMap.get(filterInfo.getType());
|
|
|
|
if (StringUtils.isNotEmpty(queryValue)) {
|
|
|
|
queryValue += "," + filterInfo.getId();
|
|
|
|
} else {
|
|
|
|
queryValue = filterInfo.getId();
|
|
|
|
}
|
|
|
|
queryParaMap.put(filterInfo.getType(), queryValue);
|
|
|
|
}
|
|
|
|
StringBuffer sb;
|
|
|
|
List<String> queryCondition = new ArrayList<>();
|
|
|
|
if (!cidList.isEmpty()) {
|
|
|
|
sb = new StringBuffer();
|
|
|
|
sb.append(CID_PREFIX).append("=").append(StringUtils.join(",", cidList.toArray(new String[cidList.size()])));
|
|
|
|
queryCondition.add(sb.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, String>> iterator = queryParaMap.entrySet().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Map.Entry<String, String> entry = iterator.next();
|
|
|
|
sb = new StringBuffer();
|
|
|
|
sb.append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
|
queryCondition.add(sb.toString());
|
|
|
|
}
|
|
|
|
return StringUtils.join("&", queryCondition.toArray(new String[queryCondition.size()]));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<WidgetFilterInfo> getAllFilterInfoList(List<WidgetFilterInfo> filterInfos) {
|
|
|
|
List<WidgetFilterInfo> allFilterList = new ArrayList<>();
|
|
|
|
for (WidgetFilterInfo filterInfo : filterInfos) {
|
|
|
|
if (filterInfo.hasChildFilter()) {
|
|
|
|
allFilterList.addAll(filterInfo.getInnerFilterInfo());
|
|
|
|
} else {
|
|
|
|
allFilterList.add(filterInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allFilterList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean testConnection() {
|
|
|
|
HttpClient httpClient = new HttpClient(getTestConnectionUrl());
|
|
|
|
httpClient.asGet();
|
|
|
|
int responseCode = httpClient.getResponseCode();
|
|
|
|
return responseCode == HttpURLConnection.HTTP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<OnlineShareWidget>[] getAllSharableWidgetsFromShop() throws Exception {
|
|
|
|
List<OnlineShareWidget>[] sharableWidgetsArray = new List[]{new ArrayList<>(), new ArrayList<>()};
|
|
|
|
JSONArray resultArr = getResultAttrFromUrl(getWidgetReusePath());
|
|
|
|
int size = resultArr.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject jo = resultArr.getJSONObject(i);
|
|
|
|
OnlineShareWidget temp = OnlineShareWidget.parseFromJSONObject(jo);
|
|
|
|
if (temp.isWidgetPackage()) {
|
|
|
|
sharableWidgetsArray[1].add(temp);
|
|
|
|
} else {
|
|
|
|
sharableWidgetsArray[0].add(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sharableWidgetsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static OnlineShareWidget[] getPackageWidgets(OnlineShareWidget widgetPackage) {
|
|
|
|
return getPackageWidgets(widgetPackage, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static OnlineShareWidget[] getPackageWidgets(OnlineShareWidget widgetPackage, boolean requireCompatible) {
|
|
|
|
String targetDesignerVersion = requireCompatible ? ProductConstants.RELEASE_VERSION : "0";
|
|
|
|
String plistUrl = getPackageChildrenPath() + widgetPackage.getId() + "?designerVersion="+ targetDesignerVersion;
|
|
|
|
OnlineShareWidget[] widgets = getOnlineShareWidgets(plistUrl);
|
|
|
|
for (OnlineShareWidget widget : widgets) {
|
|
|
|
widget.setParentPackage(widgetPackage);
|
|
|
|
}
|
|
|
|
return widgets;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<WidgetFilterTypeInfo> getWidgetFilterTypeInfos() {
|
|
|
|
List<WidgetFilterTypeInfo> result = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
JSONArray resultArr = getResultAttrFromUrl(getWidgetFilterPath());
|
|
|
|
int size = resultArr.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject jo = resultArr.getJSONObject(i);
|
|
|
|
result.add(WidgetFilterTypeInfo.parseFromJSONObject(jo));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static OnlineShareWidget[] getOnlineShareWidgets(String url) {
|
|
|
|
if (StringUtils.isNotBlank(url)) {
|
|
|
|
try {
|
|
|
|
JSONArray resultArr = getResultAttrFromUrl(url);
|
|
|
|
int size = resultArr.size();
|
|
|
|
List<OnlineShareWidget> onlineShareWidgets = new ArrayList<>();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject jo = resultArr.getJSONObject(i);
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(jo);
|
|
|
|
if (!widget.isWidgetPackage()) {
|
|
|
|
onlineShareWidgets.add(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return onlineShareWidgets.toArray(new OnlineShareWidget[0]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new OnlineShareWidget[]{};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static OnlineShareWidget[] getFilterWidgets(String filterStr) {
|
|
|
|
|
|
|
|
String plistUrl = getWidgetReusePath() + "?" + filterStr;
|
|
|
|
return getOnlineShareWidgets(plistUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<OnlineShareWidget> getLatestReusesByDesignerVersion(Set<String> reuseIds, String designerVersion) {
|
|
|
|
List<OnlineShareWidget> result = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
JSONObject params = JSONObject.create();
|
|
|
|
StringBuilder reuseIdsStr = new StringBuilder();
|
|
|
|
for (String id: reuseIds) {
|
|
|
|
reuseIdsStr.append(id).append(",");
|
|
|
|
}
|
|
|
|
params.put("reuseIds", reuseIdsStr.toString());
|
|
|
|
params.put("designerVersion", designerVersion);
|
|
|
|
JSONArray resultArr = postResultAttrFormUrl(getLatestReusesPath(), params);
|
|
|
|
int size = resultArr.size();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject jo = resultArr.getJSONObject(i);
|
|
|
|
result.add(OnlineShareWidget.parseFromJSONObject(jo));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static JSONArray getResultAttrFromUrl(String url) {
|
|
|
|
HttpClient httpClient = new HttpClient(url);
|
|
|
|
httpClient.asGet();
|
|
|
|
String responseText = httpClient.getResponseText();
|
|
|
|
JSONObject resultJSONObject = new JSONObject(responseText);
|
|
|
|
return resultJSONObject.getJSONArray("result");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static JSONArray postResultAttrFormUrl(String url, JSONObject params) {
|
|
|
|
JSONArray result = JSONArray.create();
|
|
|
|
try {
|
|
|
|
String responseText = HttpToolbox.post(url, params.toMap());
|
|
|
|
if (StringUtils.isNotEmpty(responseText)) {
|
|
|
|
JSONObject resultJSONObject = new JSONObject(responseText);
|
|
|
|
result = resultJSONObject.getJSONArray("result");
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|