-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hubin6 <[email protected]>
- Loading branch information
hubin6
committed
Nov 7, 2017
1 parent
78e5588
commit b81ff90
Showing
39 changed files
with
829 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/BaseModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ChartModel> charts; | ||
private List<ValueModel> values; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<ChartModel> getCharts() { | ||
return charts; | ||
} | ||
|
||
public List<ValueModel> getValues() { | ||
return values; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ChartModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/CommonRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, List<Object>> arrayResult = new HashMap<>(); | ||
private Map<String, Object> singleResult = new HashMap<>(); | ||
|
||
public void addItem(String key, Object value) { | ||
if (arrayResult.get(key) == null) { | ||
List<Object> i = new ArrayList<>(); | ||
i.add(value); | ||
arrayResult.put(key, i); | ||
} else { | ||
List<Object> i = arrayResult.get(key); | ||
i.add(value); | ||
} | ||
} | ||
|
||
public void putItem(String key, Object value) { | ||
singleResult.put(key, value); | ||
} | ||
|
||
public Map<String, List<Object>> getArrayResult() { | ||
return arrayResult; | ||
} | ||
|
||
public Map<String, Object> getSingleResult() { | ||
return singleResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/ValueModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/domain/Warehouse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
70 changes: 70 additions & 0 deletions
70
...rd-domain-service/src/main/java/com/jd/logistics/cloud/data/service/ChartServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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<String, String> 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<String, List<Object>> 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<String, String> sqlList = getChartSql(funcName); | ||
Map res = new HashMap<>(); | ||
for (Map.Entry<String, String> 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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
dashboard-domain-service/src/main/java/com/jd/logistics/cloud/data/service/Constant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.