From b81ff9053178416fa0bc26677e2acbbab73ee84d Mon Sep 17 00:00:00 2001 From: hubin6 Date: Wed, 1 Nov 2017 19:14:00 +0800 Subject: [PATCH] new API Signed-off-by: hubin6 --- dashboard-domain-service/pom.xml | 5 ++ .../cloud/data/domain/BaseModel.java | 31 +++++++ .../cloud/data/domain/ChartModel.java | 25 ++++++ .../cloud/data/domain/CommonRes.java | 41 ++++++++++ .../data/domain/{Dim.java => DateCycle.java} | 4 +- .../cloud/data/domain/ValueModel.java | 25 ++++++ .../cloud/data/domain/Warehouse.java | 17 ++++ .../cloud/data/repository/DimRepository.java | 16 ++-- .../cloud/data/repository/FuncRepository.java | 12 +-- .../cloud/data/service/ChartService.java | 14 ++++ .../cloud/data/service/ChartServiceImpl.java | 70 ++++++++++++++++ .../cloud/data/service/Constant.java | 14 ++++ .../cloud/data/service/DimService.java | 9 +-- .../cloud/data/service/DimServiceImpl.java | 9 +-- .../cloud/data/service/GenStatService.java | 4 +- .../cloud/data/service/ModelService.java | 12 +++ .../cloud/data/service/ModelServiceImpl.java | 35 ++++++++ .../cloud/data/service/StringUtils.java | 36 +++++++++ .../cloud/data/service/ValueService.java | 12 +++ .../cloud/data/service/ValueServiceImpl.java | 62 ++++++++++++++ .../src/main/resources/schema.sql | 80 ++++++++++++++----- .../cloud/data/web/api/ChartApi.java | 25 ++++++ .../data/web/api/ChartRestController.java | 29 +++++++ .../logistics/cloud/data/web/api/DimApi.java | 13 +-- .../cloud/data/web/api/DimRestController.java | 8 +- .../data/web/api/FetchRestController.java | 46 +++++++++++ .../cloud/data/web/api/ModelApi.java | 21 +++++ .../data/web/api/ModelRestController.java | 24 ++++++ .../cloud/data/web/api/ValueApi.java | 20 +++++ .../data/web/api/ValueRestController.java | 24 ++++++ .../src/main/resources/metrics/sample1/a.sql | 1 + .../src/main/resources/metrics/sample1/b.sql | 1 + .../src/main/resources/metrics/sample1/c.sql | 1 + .../main/resources/metrics/sample1/chart.html | 33 ++++++++ .../resources/metrics/sample1/chart1.option | 56 +++++++++++++ .../src/main/resources/metrics/sample1/d.sql | 9 +++ .../src/main/resources/metrics/sample1/e.sql | 4 + .../main/resources/metrics/sample1/model.json | 23 ++++++ .../resources/metrics/sample1/number.html | 21 +++++ 39 files changed, 829 insertions(+), 63 deletions(-) create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/BaseModel.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ChartModel.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/CommonRes.java rename dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/{Dim.java => DateCycle.java} (76%) create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ValueModel.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Warehouse.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartService.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartServiceImpl.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/Constant.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelService.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelServiceImpl.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/StringUtils.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueService.java create mode 100644 dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueServiceImpl.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartApi.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartRestController.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FetchRestController.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelApi.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelRestController.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueApi.java create mode 100644 dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueRestController.java create mode 100644 dashboard-web/src/main/resources/metrics/sample1/a.sql create mode 100644 dashboard-web/src/main/resources/metrics/sample1/b.sql create mode 100644 dashboard-web/src/main/resources/metrics/sample1/c.sql create mode 100644 dashboard-web/src/main/resources/metrics/sample1/chart.html create mode 100644 dashboard-web/src/main/resources/metrics/sample1/chart1.option create mode 100644 dashboard-web/src/main/resources/metrics/sample1/d.sql create mode 100644 dashboard-web/src/main/resources/metrics/sample1/e.sql create mode 100644 dashboard-web/src/main/resources/metrics/sample1/model.json create mode 100644 dashboard-web/src/main/resources/metrics/sample1/number.html diff --git a/dashboard-domain-service/pom.xml b/dashboard-domain-service/pom.xml index bfbdb6a..57f941b 100644 --- a/dashboard-domain-service/pom.xml +++ b/dashboard-domain-service/pom.xml @@ -112,6 +112,11 @@ 1.0-SNAPSHOT + + com.alibaba + fastjson + 1.2.7 + diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/BaseModel.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/BaseModel.java new file mode 100644 index 0000000..d35001d --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/BaseModel.java @@ -0,0 +1,31 @@ +package com.jd.logistics.cloud.data.domain; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/6 10:39 + */ +@Data +public class BaseModel implements Serializable { + private static final long serialVersionUID = 7593767886021869685L; + private String name; + private List charts; + private List values; + + public String getName() { + return name; + } + + public List getCharts() { + return charts; + } + + public List getValues() { + return values; + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ChartModel.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ChartModel.java new file mode 100644 index 0000000..8e5286e --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ChartModel.java @@ -0,0 +1,25 @@ +package com.jd.logistics.cloud.data.domain; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/6 10:40 + */ +@Data +public class ChartModel implements Serializable { + private static final long serialVersionUID = -1320829926542972100L; + private String name; + private String sql; + + public String getName() { + return name; + } + + public String getSql() { + return sql; + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/CommonRes.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/CommonRes.java new file mode 100644 index 0000000..0314dfc --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/CommonRes.java @@ -0,0 +1,41 @@ +package com.jd.logistics.cloud.data.domain; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/2 11:21 + */ +public class CommonRes implements Serializable { + private static final long serialVersionUID = 2211076189595925918L; + private Map> arrayResult = new HashMap<>(); + private Map singleResult = new HashMap<>(); + + public void addItem(String key, Object value) { + if (arrayResult.get(key) == null) { + List i = new ArrayList<>(); + i.add(value); + arrayResult.put(key, i); + } else { + List i = arrayResult.get(key); + i.add(value); + } + } + + public void putItem(String key, Object value) { + singleResult.put(key, value); + } + + public Map> getArrayResult() { + return arrayResult; + } + + public Map getSingleResult() { + return singleResult; + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/DateCycle.java similarity index 76% rename from dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java rename to dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/DateCycle.java index 1c78bc4..e8c1679 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Dim.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/DateCycle.java @@ -10,8 +10,8 @@ * @Date 2017/10/31 14:38 */ @Data -public class Dim implements Serializable{ +public class DateCycle implements Serializable { private static final long serialVersionUID = 8657041672009519925L; private long id; - private String name; + private String dateCycle; } diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ValueModel.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ValueModel.java new file mode 100644 index 0000000..ea98ec2 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ValueModel.java @@ -0,0 +1,25 @@ +package com.jd.logistics.cloud.data.domain; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/6 10:40 + */ +@Data +public class ValueModel implements Serializable { + private static final long serialVersionUID = 5265311276161051035L; + private String name; + private String sql; + + public String getName() { + return name; + } + + public String getSql() { + return sql; + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Warehouse.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Warehouse.java new file mode 100644 index 0000000..e2d2da9 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Warehouse.java @@ -0,0 +1,17 @@ +package com.jd.logistics.cloud.data.domain; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author hubin + * @Description: + * @Date 2017/10/31 14:38 + */ +@Data +public class Warehouse implements Serializable { + private static final long serialVersionUID = 8657041672009519925L; + private long id; + private String warehouseName; +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/DimRepository.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/DimRepository.java index 379299b..41342a3 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/DimRepository.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/DimRepository.java @@ -1,13 +1,9 @@ package com.jd.logistics.cloud.data.repository; -import com.jd.logistics.cloud.data.domain.Dim; -import com.jd.logistics.cloud.data.domain.DimQuery; -import com.jd.logistics.cloud.data.domain.Function; -import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.domain.DateCycle; +import com.jd.logistics.cloud.data.domain.Warehouse; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.Update; import java.util.List; @@ -18,10 +14,10 @@ */ @Mapper public interface DimRepository { - @Select("SELECT * FROM T_WAREHOUSE") - List getWarehouses(); + @Select("SELECT id, warehouse_name as warehouseName FROM T_WAREHOUSE") + List getWarehouses(); - @Select("SELECT * FROM T_DATECYCLE") - List getDateCycles(); + @Select("SELECT id, date_cycle as dateCycle FROM T_DATE_CYCLE") + List getDateCycles(); } diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/FuncRepository.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/FuncRepository.java index 25a435f..5c1bcef 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/FuncRepository.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/repository/FuncRepository.java @@ -1,8 +1,10 @@ package com.jd.logistics.cloud.data.repository; import com.jd.logistics.cloud.data.domain.Function; -import com.jd.logistics.cloud.data.domain.User; -import org.apache.ibatis.annotations.*; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; @@ -14,12 +16,12 @@ @Mapper public interface FuncRepository { - @Select("SELECT id, name as funcName, type as funcType, seq FROM T_FUNCTION where type=#{type}order by seq") + @Select("SELECT id, func_name as funcName, func_type_id as funcType, seq FROM T_FUNCTION where func_type_id=#{type} order by seq") List getByType(@Param("type") int type); - @Select("SELECT id, name as funcName, type as funcType, seq FROM T_FUNCTION order by seq") + @Select("SELECT id, func_name as funcName, func_type_id as funcType, seq FROM T_FUNCTION order by seq") List getAll(); - @Update("UPDATE T_FUNCTION SET type=#{func.funcType}, seq=#{func.seq} WHERE name=#{func.funcName}") + @Update("UPDATE T_FUNCTION SET func_type_id=#{func.funcType}, seq=#{func.seq} WHERE func_name=#{func.funcName}") void update(@Param("func") Function func); } diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartService.java new file mode 100644 index 0000000..c6e420b --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartService.java @@ -0,0 +1,14 @@ +package com.jd.logistics.cloud.data.service; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:22 + */ +public interface ChartService { + Map getFuncChart(String funcName); + + String getFuncChartOption(String funcName, String chartId); +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartServiceImpl.java new file mode 100644 index 0000000..ecd2161 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartServiceImpl.java @@ -0,0 +1,70 @@ +package com.jd.logistics.cloud.data.service; + +import com.alibaba.fastjson.JSON; +import com.jd.logistics.cloud.data.domain.BaseModel; +import com.jd.logistics.cloud.data.domain.ChartModel; +import com.jd.logistics.cloud.data.domain.CommonRes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:26 + */ +@Service +public class ChartServiceImpl implements ChartService { + @Autowired + JdbcTemplate jdbcTemplate; + + private Map getChartSql(String funcName) { + String json = StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + Constant.TEMPLATE_MODEL_FILE); + BaseModel bm = JSON.parseObject(json, BaseModel.class); + System.out.println(bm.getName()); + Map sqlList = new HashMap<>(); + for (ChartModel model : bm.getCharts()) { + sqlList.put(model.getName(), StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + model.getSql())); + } + return sqlList; + } + + private Map> RowSet2ArrayRes(SqlRowSet rowSet) { + SqlRowSetMetaData metaData = rowSet.getMetaData(); + String[] colNames = metaData.getColumnNames(); + CommonRes cr = new CommonRes(); + while (rowSet.next()) { + for (String col : colNames) { + String c = col.toLowerCase(); + cr.addItem(c, rowSet.getObject(col)); + } + } + return cr.getArrayResult(); + } + + @Override + public Map getFuncChart(String funcName) { + Map sqlList = getChartSql(funcName); + Map res = new HashMap<>(); + for (Map.Entry e : sqlList.entrySet()) { + String sql = e.getValue(); + SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); + res.put(e.getKey(), RowSet2ArrayRes(rowSet)); + } + return res; + } + + @Override + public String getFuncChartOption(String funcName, String chartId) { + return StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + chartId + Constant.CHART_OPTION_SUFFIX); + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/Constant.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/Constant.java new file mode 100644 index 0000000..9a29730 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/Constant.java @@ -0,0 +1,14 @@ +package com.jd.logistics.cloud.data.service; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:32 + */ +public class Constant { + public static final String TEMPLATE_PARENT_FOLDER = "metrics"; + public static final String CHART_OPTION_SUFFIX = ".chart.json"; + 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"; +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java index f72e876..47e7136 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimService.java @@ -1,8 +1,7 @@ package com.jd.logistics.cloud.data.service; -import com.jd.logistics.cloud.data.domain.Dim; -import com.jd.logistics.cloud.data.domain.DimQuery; -import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.domain.DateCycle; +import com.jd.logistics.cloud.data.domain.Warehouse; import java.util.List; @@ -12,8 +11,8 @@ * @Date 2017/10/31 14:39 */ public interface DimService { - List getWarehouses(); + List getWarehouses(); - List getDateCycles(); + List getDateCycles(); } diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java index 5a3764a..1b1f936 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/DimServiceImpl.java @@ -1,8 +1,7 @@ package com.jd.logistics.cloud.data.service; -import com.jd.logistics.cloud.data.domain.Dim; -import com.jd.logistics.cloud.data.domain.DimQuery; -import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.domain.DateCycle; +import com.jd.logistics.cloud.data.domain.Warehouse; import com.jd.logistics.cloud.data.repository.DimRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -19,12 +18,12 @@ public class DimServiceImpl implements DimService { @Autowired DimRepository dimRepository; @Override - public List getWarehouses() { + public List getWarehouses() { return dimRepository.getWarehouses(); } @Override - public List getDateCycles() { + public List getDateCycles() { return dimRepository.getDateCycles(); } diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/GenStatService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/GenStatService.java index 1ccb564..7227819 100644 --- a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/GenStatService.java +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/GenStatService.java @@ -17,7 +17,7 @@ public class GenStatService { public static List statList = new ArrayList<>(); public static List functionList = new ArrayList<>(); static { - gen(rec_num); + // gen(rec_num); } private static void gen(int num){ Calendar date = Calendar.getInstance(); @@ -62,7 +62,7 @@ private static void gen(int num){ funcValue = 20000 + r.nextInt(3000) - 1500; for(String index: item.getValue()) { double indexValue; - if(idx<=1) indexValue = funcValue * 0.95; + if(idx<=1) indexValue = funcValue * (r.nextDouble()+0.45); else indexValue = (double)((int)((r.nextDouble()-0.25)*1000))/100; System.out.println(function+','+warehouse+','+item.getKey()+','+tmp_date+','+funcValue+','+index+','+indexValue); idx++; diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelService.java new file mode 100644 index 0000000..c487c7c --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelService.java @@ -0,0 +1,12 @@ +package com.jd.logistics.cloud.data.service; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:35 + */ +public interface ModelService { + Map getFuncModel(String funcName); +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelServiceImpl.java new file mode 100644 index 0000000..cbf0620 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ModelServiceImpl.java @@ -0,0 +1,35 @@ +package com.jd.logistics.cloud.data.service; + +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:35 + */ +@Service +public class ModelServiceImpl implements ModelService { + private String getFuncChartFormat(String funcName) { + return StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + Constant.CHART_TEMPLATE_SUFFIX); + } + + private String getFuncValueFormat(String funcName) { + return StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + Constant.VALUE_TEMPLATE_SUFFIX); + } + + @Override + public Map getFuncModel(String funcName) { + String chartTemplate = getFuncChartFormat(funcName); + String numberTemplate = getFuncValueFormat(funcName); + Map res = new HashMap<>(); + res.put("name", funcName); + res.put("chartTemplate", chartTemplate); + res.put("numberTemplate", numberTemplate); + return res; + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/StringUtils.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/StringUtils.java new file mode 100644 index 0000000..5ac858b --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/StringUtils.java @@ -0,0 +1,36 @@ +package com.jd.logistics.cloud.data.service; + +import com.google.common.io.Resources; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:28 + */ +public class StringUtils { + public static String InputStream2String(InputStream in) { + StringBuffer out = new StringBuffer(); + byte[] b = new byte[4096]; + try { + for (int n; (n = in.read(b)) != -1; ) { + out.append(new String(b, 0, n)); + } + } catch (IOException e) { + e.printStackTrace(); + } + return out.toString(); + } + + public static String getStringFromResourcePath(String filePath) { + InputStream in = null; + try { + in = Resources.getResource(filePath).openStream(); + } catch (IOException e) { + e.printStackTrace(); + } + return StringUtils.InputStream2String(in); + } +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueService.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueService.java new file mode 100644 index 0000000..efffc97 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueService.java @@ -0,0 +1,12 @@ +package com.jd.logistics.cloud.data.service; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:22 + */ +public interface ValueService { + Map getFuncValues(String funcName); +} diff --git a/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueServiceImpl.java b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueServiceImpl.java new file mode 100644 index 0000000..4f8a980 --- /dev/null +++ b/dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ValueServiceImpl.java @@ -0,0 +1,62 @@ +package com.jd.logistics.cloud.data.service; + +import com.alibaba.fastjson.JSON; +import com.jd.logistics.cloud.data.domain.BaseModel; +import com.jd.logistics.cloud.data.domain.CommonRes; +import com.jd.logistics.cloud.data.domain.ValueModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:22 + */ +@Service +public class ValueServiceImpl implements ValueService { + @Autowired + JdbcTemplate jdbcTemplate; + + private Map getValueSql(String funcName) { + String json = StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + Constant.TEMPLATE_MODEL_FILE); + BaseModel bm = JSON.parseObject(json, BaseModel.class); + System.out.println(bm.getName()); + Map sqlList = new HashMap<>(); + for (ValueModel model : bm.getValues()) { + sqlList.put(model.getName(), StringUtils.getStringFromResourcePath(Constant.TEMPLATE_PARENT_FOLDER + "/" + + funcName + "/" + model.getSql())); + } + return sqlList; + } + + private Map RowSet2SingleRes(SqlRowSet rowSet) { + SqlRowSetMetaData metaData = rowSet.getMetaData(); + String[] colNames = metaData.getColumnNames(); + CommonRes cr = new CommonRes(); + rowSet.next(); + for (String col : colNames) { + String c = col.toLowerCase(); + cr.putItem(c, rowSet.getObject(col)); + } + return cr.getSingleResult(); + } + + @Override + public Map getFuncValues(String funcName) { + Map sqlList = getValueSql(funcName); + Map res = new HashMap<>(); + for (Map.Entry e : sqlList.entrySet()) { + String sql = e.getValue(); + SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); + res.put(e.getKey(), RowSet2SingleRes(rowSet)); + } + return res; + } +} diff --git a/dashboard-domain-service/src/main/resources/schema.sql b/dashboard-domain-service/src/main/resources/schema.sql index c180339..0c1a20d 100644 --- a/dashboard-domain-service/src/main/resources/schema.sql +++ b/dashboard-domain-service/src/main/resources/schema.sql @@ -10,39 +10,77 @@ CREATE TABLE IF NOT EXISTS T_USER( -- --CREATE TABLE IF NOT EXISTS T_WAREHOUSE( -- ID INT NOT NULL AUTO_INCREMENT, --- NAME VARCHAR(100) NOT NULL, +-- WAREHOUSE_NAME VARCHAR(100) NOT NULL, +-- PRIMARY KEY ( ID ) +--); +--INSERT INTO T_WAREHOUSE(WAREHOUSE_NAME) VALUES('全部仓库'); +--INSERT INTO T_WAREHOUSE(WAREHOUSE_NAME) VALUES('上海1仓'); +--INSERT INTO T_WAREHOUSE(WAREHOUSE_NAME) VALUES('上海2仓'); +--INSERT INTO T_WAREHOUSE(WAREHOUSE_NAME) VALUES('上海3仓'); +-- +--CREATE TABLE IF NOT EXISTS T_DATE_CYCLE( +-- ID INT NOT NULL AUTO_INCREMENT, +-- DATE_CYCLE VARCHAR(100) NOT NULL, -- PRIMARY KEY ( ID ) --); ---INSERT INTO T_WAREHOUSE(NAME) VALUES('全部仓库'); ---INSERT INTO T_WAREHOUSE(NAME) VALUES('上海1仓'); ---INSERT INTO T_WAREHOUSE(NAME) VALUES('上海2仓'); ---INSERT INTO T_WAREHOUSE(NAME) VALUES('上海3仓'); +--INSERT INTO T_DATE_CYCLE(DATE_CYCLE) VALUES('日维度'); +--INSERT INTO T_DATE_CYCLE(DATE_CYCLE) VALUES('周维度'); +--INSERT INTO T_DATE_CYCLE(DATE_CYCLE) VALUES('月维度'); -- ---CREATE TABLE IF NOT EXISTS T_DATECYCLE( +--CREATE TABLE IF NOT EXISTS T_FUNC_TYPE( -- ID INT NOT NULL AUTO_INCREMENT, --- NAME VARCHAR(100) NOT NULL, +-- FUNC_TYPE VARCHAR(100) NOT NULL, -- PRIMARY KEY ( ID ) --); ---INSERT INTO T_DATECYCLE(NAME) VALUES('日维度'); ---INSERT INTO T_DATECYCLE(NAME) VALUES('周维度'); ---INSERT INTO T_DATECYCLE(NAME) VALUES('月维度'); +--INSERT INTO T_FUNC_TYPE(FUNC_TYPE) VALUES('数据框'); +--INSERT INTO T_FUNC_TYPE(FUNC_TYPE) VALUES('数据趋势图'); +--INSERT INTO T_FUNC_TYPE(FUNC_TYPE) VALUES('未添加'); -- --CREATE TABLE IF NOT EXISTS T_FUNCTION( -- ID INT NOT NULL AUTO_INCREMENT, --- NAME VARCHAR(100) NOT NULL, --- TYPE int NOT NULL, +-- FUNC_NAME VARCHAR(100) NOT NULL, +-- FUNC_TYPE_ID INT NOT NULL, -- SEQ int NOT NULL, -- PRIMARY KEY ( ID ) --); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('接收订单量', 0, 0); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('Sku准确率', 0, 1); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('调拨入库单数', 0, 2); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('发出订单量', 0, 3); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('在库Sku', 1, 0); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('人效-DO', 1, 1); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('成本效率', 2, 0); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('测试1', 2, 1); ---INSERT INTO T_FUNCTION (NAME, TYPE, SEQ) VALUES ('测试', 2, 2); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('接收订单量', 1, 0); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('Sku准确率', 1, 1); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('调拨入库单数', 1, 2); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('在库Sku', 2, 0); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('人效-DO', 2, 1); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('成本效率', 3, 0); +--INSERT INTO T_FUNCTION (FUNC_NAME, FUNC_TYPE_ID, SEQ) VALUES ('发出订单量', 3, 1); +-- +--CREATE TABLE IF NOT EXISTS T_FUNC_DESC( +-- ID INT NOT NULL AUTO_INCREMENT, +-- FUNC_ID INT NOT NULL, +-- DATE_CYCLE_ID INT NOT NULL, +-- DESC VARCHAR(2000) NULL, +-- SQL blob NOT NULL, +-- CHART blob NOT NULL, +-- PRIMARY KEY ( ID ) +--); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (1, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (1, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (1, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (2, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (2, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (2, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (3, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (3, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (3, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (4, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (4, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (4, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (5, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (5, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (5, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (6, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (6, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (6, 3); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (7, 1); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (7, 2); +--INSERT INTO T_FUNC_DESC (FUNC_ID, DATE_CYCLE_ID) VALUES (7, 3); -- --CREATE TABLE IF NOT EXISTS T_RESULT( -- ID INT NOT NULL AUTO_INCREMENT, diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartApi.java new file mode 100644 index 0000000..a2cbd0c --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartApi.java @@ -0,0 +1,25 @@ +package com.jd.logistics.cloud.data.web.api; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:18 + */ +@RequestMapping(value = "/api") +public interface ChartApi { + @RequestMapping(value = "/chart/{funcName}", + produces = {"application/json"}, + method = RequestMethod.GET) + Map getFuncChart(@PathVariable("funcName") String funcName); + + @RequestMapping(value = "/chartOption/{funcName}/{chartName}", + produces = {"application/json"}, + method = RequestMethod.GET) + String getFuncChartOption(@PathVariable("funcName") String funcName, @PathVariable("chartName") String chartName); +} \ No newline at end of file diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartRestController.java new file mode 100644 index 0000000..3072b5c --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ChartRestController.java @@ -0,0 +1,29 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.service.ChartService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:25 + */ +@RestController +public class ChartRestController implements ChartApi { + @Autowired + ChartService chartService; + + @Override + public Map getFuncChart(@PathVariable("funcName") String funcName) { + return chartService.getFuncChart(funcName); + } + + @Override + public String getFuncChartOption(@PathVariable("funcName") String funcName, @PathVariable("chartName") String chartName) { + return chartService.getFuncChartOption(funcName, chartName); + } +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java index 98e41eb..cb578f8 100644 --- a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimApi.java @@ -1,15 +1,10 @@ package com.jd.logistics.cloud.data.web.api; -import com.jd.logistics.cloud.data.domain.Dim; -import com.jd.logistics.cloud.data.domain.Function; -import com.jd.logistics.cloud.data.domain.GenericRes; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; +import com.jd.logistics.cloud.data.domain.DateCycle; +import com.jd.logistics.cloud.data.domain.Warehouse; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import javax.validation.Valid; import java.util.List; /** @@ -23,11 +18,11 @@ public interface DimApi { @RequestMapping(value = "/warehouse", produces = {"application/json"}, method = RequestMethod.GET) - List getWarehouses(); + List getWarehouses(); @RequestMapping(value = "/datecycle", produces = {"application/json"}, method = RequestMethod.GET) - List getDateCycles(); + List getDateCycles(); } diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java index f8d1b62..30020f8 100644 --- a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/DimRestController.java @@ -1,7 +1,7 @@ package com.jd.logistics.cloud.data.web.api; -import com.jd.logistics.cloud.data.domain.Dim; -import com.jd.logistics.cloud.data.domain.GenericRes; +import com.jd.logistics.cloud.data.domain.DateCycle; +import com.jd.logistics.cloud.data.domain.Warehouse; import com.jd.logistics.cloud.data.service.DimService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -18,12 +18,12 @@ public class DimRestController implements DimApi{ @Autowired DimService dimService; @Override - public List getWarehouses() { + public List getWarehouses() { return dimService.getWarehouses(); } @Override - public List getDateCycles() { + public List getDateCycles() { return dimService.getDateCycles(); } } diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FetchRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FetchRestController.java new file mode 100644 index 0000000..758ba74 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/FetchRestController.java @@ -0,0 +1,46 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.domain.CommonRes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/2 10:38 + */ +@RestController +public class FetchRestController { + @Autowired + JdbcTemplate jdbcTemplate; + + @RequestMapping(value = "/api/charts/{chart}", produces = {"application/json"}, method = RequestMethod.GET) + public Map getChart(@PathVariable("chart") String chart) throws IOException { + String sql = "select stat_date, cast(max(func_value)as signed) as func_value " + + "from T_RESULT where func_name='接收订单量' and warehouse_name='全部仓库' and date_cycle='日维度' " + + "group by stat_date order by stat_date"; + SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); + SqlRowSetMetaData metaData = rowSet.getMetaData(); + String[] colNames = metaData.getColumnNames(); + CommonRes cr = new CommonRes(); + while (rowSet.next()) { + for (String col : colNames) { + String c = col.toLowerCase(); + cr.addItem(c, rowSet.getObject(col)); + } + } + Map res = new HashMap<>(); + res.put(chart, cr); + return res; + } +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelApi.java new file mode 100644 index 0000000..e0d116e --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelApi.java @@ -0,0 +1,21 @@ +package com.jd.logistics.cloud.data.web.api; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:18 + */ +@RequestMapping(value = "/api/model") +public interface ModelApi { + @RequestMapping(value = "/{funcName}", + produces = {"application/json"}, + method = RequestMethod.GET) + Map getFuncModel(@PathVariable("funcName") String funcName); + +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelRestController.java new file mode 100644 index 0000000..8ffe4d2 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ModelRestController.java @@ -0,0 +1,24 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.service.ModelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:27 + */ +@RestController +public class ModelRestController implements ModelApi { + @Autowired + ModelService modelService; + + @Override + public Map getFuncModel(@PathVariable("funcName") String funcName) { + return modelService.getFuncModel(funcName); + } +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueApi.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueApi.java new file mode 100644 index 0000000..6457194 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueApi.java @@ -0,0 +1,20 @@ +package com.jd.logistics.cloud.data.web.api; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:19 + */ +@RequestMapping(value = "/api/value") +public interface ValueApi { + @RequestMapping(value = "/{funcName}", + produces = {"application/json"}, + method = RequestMethod.GET) + Map getFuncValues(@PathVariable("funcName") String funcName); +} diff --git a/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueRestController.java b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueRestController.java new file mode 100644 index 0000000..7be66c8 --- /dev/null +++ b/dashboard-web/src/main/java/com/jd/logistics/cloud/data/web/api/ValueRestController.java @@ -0,0 +1,24 @@ +package com.jd.logistics.cloud.data.web.api; + +import com.jd.logistics.cloud.data.service.ValueService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * @Author hubin + * @Description: + * @Date 2017/11/7 9:21 + */ +@RestController +public class ValueRestController implements ValueApi { + @Autowired + ValueService valueService; + + @Override + public Map getFuncValues(@PathVariable("funcName") String funcName) { + return valueService.getFuncValues(funcName); + } +} diff --git a/dashboard-web/src/main/resources/metrics/sample1/a.sql b/dashboard-web/src/main/resources/metrics/sample1/a.sql new file mode 100644 index 0000000..7b7040b --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/a.sql @@ -0,0 +1 @@ +SELECT '14,300' as v1, 8.8 as v2, -4.3 as v3 \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/b.sql b/dashboard-web/src/main/resources/metrics/sample1/b.sql new file mode 100644 index 0000000..f6c5134 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/b.sql @@ -0,0 +1 @@ +SELECT '124,300' as v1, 4.8 as v2, -1.3 as v3 \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/c.sql b/dashboard-web/src/main/resources/metrics/sample1/c.sql new file mode 100644 index 0000000..c1db1d7 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/c.sql @@ -0,0 +1 @@ +SELECT '624,300' as v1, 2.8 as v2, 1.3 as v3 \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/chart.html b/dashboard-web/src/main/resources/metrics/sample1/chart.html new file mode 100644 index 0000000..6d7c9c7 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/chart.html @@ -0,0 +1,33 @@ + + + + {{data.labels.val1}} + + {{data.labels.val2}}
{{data.values.val2}}%
+ trending_up + trending_flat + trending_down +
+ + 2017/07/07 + more_horiz + {{data.values.val1}} + + {{data.labels.val3}}
{{data.values.val3}}%
+ trending_up + trending_flat + trending_down +
+ + 2017/07/14 + +
+
+ + + +
+
+
+
+
\ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/chart1.option b/dashboard-web/src/main/resources/metrics/sample1/chart1.option new file mode 100644 index 0000000..fb7b3ff --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/chart1.option @@ -0,0 +1,56 @@ +{ + tooltip: { + trigger: 'axis', + axisPointer: { + animation: false + }, + formatter:function(params) { + return '' + params[0].name + ' : ' + params[0].value + '
' + + '' + addDate(params[0].name, -7) + ' : ' + params[1].value + '' + } + }, + xAxis: { + type: 'category', + splitLine: { + show: false + }, + axisLine: { + lineStyle: { + color: '#6E88AC' + } + }, + data: res.r_date.slice(-7) + }, + yAxis: { + type: 'value', + boundaryGap: [0, '100%'], + splitLine: { + show: false + }, + axisLine: { + lineStyle: { + color: '#6E88AC' + } + } + }, + series: [{ + type: 'line', + itemStyle: { + normal: { + color: '#00D7FB', + width: 1 + } + }, + data: res.metrics_3.slice(-7) + }, + { + type: 'line', + itemStyle: { + normal: { + color: '#6E88AC', + width: 1 + } + }, + data: res.metrics_3.slice(0,7) + }] +} \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/d.sql b/dashboard-web/src/main/resources/metrics/sample1/d.sql new file mode 100644 index 0000000..43e1677 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/d.sql @@ -0,0 +1,9 @@ +SELECT strftime('%Y/%m/%d',fact.date) AS r_date, + sum(metrics2) AS metrics_2, + sum(metrics3) AS metrics_3 +FROM fact +inner JOIN a ON a.id=fact.dim1 +where strftime('%Y/%m/%d',fact.date) between '2017/07/01' and '2017/07/14' +GROUP BY + strftime('%Y/%m/%d',fact.date) +ORDER BY r_date \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/e.sql b/dashboard-web/src/main/resources/metrics/sample1/e.sql new file mode 100644 index 0000000..b3b10b4 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/e.sql @@ -0,0 +1,4 @@ +select stat_date, cast(max(func_value)as signed) as func_value +from T_RESULT +where func_name='接收订单量' and warehouse_name='全部仓库' and date_cycle='日维度' +group by stat_date order by stat_date \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/model.json b/dashboard-web/src/main/resources/metrics/sample1/model.json new file mode 100644 index 0000000..d76fd63 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/model.json @@ -0,0 +1,23 @@ +{ + "charts": [ + { + "name": "chart1", + "sql": "e.sql" + } + ], + "name": "sample1", + "values": [ + { + "name": "day", + "sql": "a.sql" + }, + { + "name": "week", + "sql": "b.sql" + }, + { + "name": "month", + "sql": "c.sql" + } + ] +} \ No newline at end of file diff --git a/dashboard-web/src/main/resources/metrics/sample1/number.html b/dashboard-web/src/main/resources/metrics/sample1/number.html new file mode 100644 index 0000000..a008153 --- /dev/null +++ b/dashboard-web/src/main/resources/metrics/sample1/number.html @@ -0,0 +1,21 @@ + + + + {{data.labels.val1}} + + {{data.labels.val2}}
{{data.values.val2}}%
+ trending_up + trending_flat + trending_down +
+ {{data.values.val1}} + + {{data.labels.val3}}
{{data.values.val3}}%
+ trending_up + trending_flat + trending_down +
+ +
+
+
\ No newline at end of file