Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
Signed-off-by: hubin6 <[email protected]>
  • Loading branch information
hubin6 committed Nov 13, 2017
1 parent bf980ea commit 041a2b9
Show file tree
Hide file tree
Showing 70 changed files with 446 additions and 1,310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @Date 2017/11/7 9:32
*/
public class Constants {
public static final String TEMPLATE_PARENT_FOLDER = "metrics";
public static final String CHART_OPTION_SUFFIX = ".option";
public static final String CHART_TEMPLATE_SUFFIX = "chart.html";
public static final String VALUE_TEMPLATE_SUFFIX = "number.html";
public static final String TEMPLATE_MODEL_FILE = "model.json";
public static final String CONFIG_PARENT_FOLDER = "metrics";
public static final String CHART_OPTION_SUFFIX = ".chartOption";
public static final String CHART_TEMPLATE_FILE = "chart.html";
public static final String VALUE_TEMPLATE_FILE = "number.html";
public static final String CONFIG_MODEL_FILE = "model.json";
public static final String TEMPLATE_PARENT_FOLDER = "templates";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jd.logistics.cloud.data.commons;

import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.domain.Stat;
import com.jd.logistics.cloud.data.domain.Metric;

import java.text.SimpleDateFormat;
import java.util.*;
Expand All @@ -14,8 +13,7 @@
public class GenStatService {
private final static int rec_num = 32;
private final static Random r = new Random(rec_num);
public static List<Stat> statList = new ArrayList<>();
public static List<Function> functionList = new ArrayList<>();
public static List<Metric> functionList = new ArrayList<>();

static {
// gen(rec_num);
Expand Down Expand Up @@ -77,20 +75,11 @@ private static void gen(int num) {

}

public static List<Stat> getStatList(int limit, int offset) {
List<Stat> tmpList = new ArrayList<>();
for (int i = offset; i < offset + limit; i++) {
if (i > count - 1) break;
tmpList.add(statList.get(i));
}
return tmpList;
}

public static List<Function> getFunctionList() {
public static List<Metric> getFunctionList() {
return functionList;
}

public static int count = statList.size();

public static void main(String[] args) {
GenStatService gs = new GenStatService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.io.Resources;
import com.jd.logistics.cloud.data.domain.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

Expand Down Expand Up @@ -41,37 +42,72 @@ public static String getStringFromResourcePath(String filePath) {
} catch (IOException e) {
e.printStackTrace();
}
return Helper.InputStream2String(in);
return InputStream2String(in);
}

public static Map<String, String> getDesc(String funcId) {
String json = Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + Constants.TEMPLATE_MODEL_FILE);
public static BaseModel getBaseModel(String metricId) {
String json = getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + Constants.CONFIG_MODEL_FILE);
BaseModel bm = JSON.parseObject(json, BaseModel.class);
Map<String, String> descList = new HashMap<>();
for (Description desc: bm.getDescriptions()) {
descList.put(desc.getName(), desc.getText());
return bm;
}

public static Map<String, String> getDesc(String metricId) {
BaseModel model = getBaseModel(metricId);
Map<String, String> defList = new HashMap<>();
for (Def def : model.getDef()) {
defList.put(def.getName(), def.getText());
}
return descList;
return defList;
}

public static Map<String, String> getFuncSqlByType(String funcId, ShowType type) {
String json = Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + Constants.TEMPLATE_MODEL_FILE);
BaseModel bm = JSON.parseObject(json, BaseModel.class);
Map<String, String> sqlList = new HashMap<>();
if (type == ShowType.CHART) {
for (ChartModel model : bm.getCharts()) {
sqlList.put(model.getName(), Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + model.getSql()));
}
} else if (type == ShowType.VALUE) {
for (ValueModel model : bm.getValues()) {
sqlList.put(model.getName(), Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + model.getSql()));
}
public static List<ChartModel> getChartModels(String metricId) {
BaseModel model = getBaseModel(metricId);
return model.getCharts();
}

@Nullable
public static ChartModel getChartModelByDateCycle(String metricId, String dateCycle) {
BaseModel model = getBaseModel(metricId);
for (ChartModel m : model.getCharts()) {
if (m.getName().equals(dateCycle))
return m;
}
return sqlList;
return null;
}

public static List<ValueModel> getValueModels(String metricId) {
BaseModel model = getBaseModel(metricId);
return model.getValues();
}

@Nullable
public static ValueModel getValueModelByDateCycle(String metricId, String dateCycle) {
BaseModel model = getBaseModel(metricId);
for (ValueModel m : model.getValues()) {
if (m.getName().equals(dateCycle))
return m;
}
return null;
}

@NotNull
public static String getMetricChartSql(String metricId, String dateCycle) {
ChartModel model = getChartModelByDateCycle(metricId, dateCycle);
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
}

@NotNull
public static String getMetricValueSql(String metricId, String dateCycle) {
ValueModel model = getValueModelByDateCycle(metricId, dateCycle);
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
}

public static String getMetricChartOption(String metricId, String dateCycle) {
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + dateCycle + Constants.CHART_OPTION_SUFFIX);
}

public static Map<String, List<Object>> RowSet2ArrayRes(SqlRowSet rowSet) {
Expand All @@ -87,7 +123,6 @@ public static Map<String, List<Object>> RowSet2ArrayRes(SqlRowSet rowSet) {
return cr.getArrayResult();
}


public static Map<String, Object> RowSet2SingleRes(SqlRowSet rowSet) {
SqlRowSetMetaData metaData = rowSet.getMetaData();
String[] colNames = metaData.getColumnNames();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;
import org.apache.ibatis.javassist.runtime.Desc;

import java.io.Serializable;
import java.util.List;
Expand All @@ -18,7 +17,7 @@ public class BaseModel implements Serializable {
private String name;
private List<ChartModel> charts;
private List<ValueModel> values;
private List<Description> descriptions;
private List<Def> def;

public String getId() {
return id;
Expand All @@ -36,7 +35,7 @@ public List<ValueModel> getValues() {
return values;
}

public List<Description> getDescriptions() {
return descriptions;
public List<Def> getDef() {
return def;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @Date 2017/11/10 10:10
*/
@Data
public class Description implements Serializable {
public class Def implements Serializable {
private static final long serialVersionUID = -8617270101773389965L;
private String name;
private String text;
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 041a2b9

Please sign in to comment.