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 11, 2017
1 parent 5ec528f commit 8b0ad63
Show file tree
Hide file tree
Showing 47 changed files with 507 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ChartServiceImpl implements ChartService {
JdbcTemplate jdbcTemplate;

@Override
public Map getFuncChart(String funcId) {
public Map getFuncCharts(String funcId) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcId, ShowType.CHART);
Map res = new HashMap<>();
for (Map.Entry<String, String> e : sqlList.entrySet()) {
Expand All @@ -35,8 +35,16 @@ public Map getFuncChart(String funcId) {
}

@Override
public String getFuncChartOption(String funcId, String chartId) {
public Map getFuncChartByDateCycle(String funcId, String dateCycle) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcId, ShowType.CHART);
String sql = sqlList.get(dateCycle);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
return Helper.RowSet2ArrayRes(rowSet);
}

@Override
public String getFuncChartOptionByDateCycle(String funcId, String dateCycle) {
return Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + chartId + Constants.CHART_OPTION_SUFFIX);
funcId + "/" + dateCycle + Constants.CHART_OPTION_SUFFIX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public Map getFuncValues(String funcId) {
}
return res;
}

@Override
public Map getFuncValuesByDateCycle(String funcId, String dateCycle) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcId, ShowType.VALUE);
String sql = sqlList.get(dateCycle);
Map res = new HashMap<>();
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
res.put("value", Helper.RowSet2SingleRes(rowSet));
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
* @Date 2017/11/7 9:22
*/
public interface ChartService {
Map getFuncChart(String funcId);
Map getFuncCharts(String funcId);

String getFuncChartOption(String funcId, String chartId);
Map getFuncChartByDateCycle(String funcId, String dateCycle);

String getFuncChartOptionByDateCycle(String funcId, String dateCycle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
*/
public interface ValueService {
Map getFuncValues(String funcId);

Map getFuncValuesByDateCycle (String fucId, String dateCycle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ public interface ChartApi {
@RequestMapping(value = "/chart/{funcId}",
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncChart(@PathVariable("funcId") String funcId);
Map getFuncCharts(@PathVariable("funcId") String funcId);

@RequestMapping(value = "/chartOption/{funcId}/{chartId}",
@RequestMapping(value = "/chart/{funcId}/{dateCycle}",
produces = {"application/json"},
method = RequestMethod.GET)
String getFuncChartOption(@PathVariable("funcId") String funcId, @PathVariable("chartId") String chartId);
Map getFuncChartByDateCycle(@PathVariable("funcId") String funcId, @PathVariable("dateCycle") String dateCycle);

@RequestMapping(value = "/chartOption/{funcId}/{dateCycle}",
produces = {"application/json"},
method = RequestMethod.GET)
String getFuncChartOptionByDateCycle(@PathVariable("funcId") String funcId, @PathVariable("dateCycle") String dateCycle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public interface ValueApi {
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncValues(@PathVariable("funcId") String funcId);

@RequestMapping(value = "/{funcId}/{dateCycle}",
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncValuesByDateCycle(@PathVariable("funcId") String funcId, @PathVariable("dateCycle") String dateCycle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ public class ChartRestController implements ChartApi {
ChartService chartService;

@Override
public Map getFuncChart(@PathVariable("funcId") String funcId) {
return chartService.getFuncChart(funcId);
public Map getFuncCharts(@PathVariable("funcId") String funcId) {
return chartService.getFuncCharts(funcId);
}

@Override
public String getFuncChartOption(@PathVariable("funcId") String funcId, @PathVariable("chartId") String chartId) {
return chartService.getFuncChartOption(funcId, chartId);
public Map getFuncChartByDateCycle(@PathVariable("funcId")String funcId, @PathVariable("dateCycle")String dateCycle) {
return chartService.getFuncChartByDateCycle(funcId, dateCycle);
}

@Override
public String getFuncChartOptionByDateCycle(@PathVariable("funcId") String funcId, @PathVariable("dateCycle") String dateCycle) {
return chartService.getFuncChartOptionByDateCycle(funcId, dateCycle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class ValueRestController implements ValueApi {
public Map getFuncValues(@PathVariable("funcId") String funcId) {
return valueService.getFuncValues(funcId);
}

@Override
public Map getFuncValuesByDateCycle(@PathVariable("funcId")String funcId, @PathVariable("dateCycle")String dateCycle) {
return valueService.getFuncValuesByDateCycle(funcId, dateCycle);
}
}
1 change: 0 additions & 1 deletion dashboard-web/src/main/resources/metrics/sample1/a.sql

This file was deleted.

62 changes: 42 additions & 20 deletions dashboard-web/src/main/resources/metrics/sample1/chart.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
<v-flex xs12 chart-header v-if="data.day">
<v-flex xs12 chart-header v-if="data.value">
<v-card>
<v-layout row wrap>
<v-flex xs4 chart-func-name-tag>{{data.day.f1}}</v-flex>
<v-flex xs3 chart-idx-name>
<span>{{data.day.f2}}<br><span class="box-idx-value"><b>{{data.day.v2}}%</b></span>
<div v-if="data.day.v2 > 0" class="trending-up"></div>
<div v-else-if="data.day.v2 == 0" class="trending-flat"></div>
<div v-else-if="data.day.v2 < 0" class="trending-down"></div></span>
<v-flex xs4 chart-func-name-tag @click="goDetails('sample1')">{{data.value.f1}}</v-flex>
<v-flex xs2>
<v-layout row wrap>
<v-flex xs12 chart-idx-name>{{data.value.f2}}</v-flex>
<v-flex xs9 chart-idx-value><b>{{data.value.v2}}%</b></v-flex>
<v-flex xs3 text-xs-left>
<div v-if="data.value.v2 > 0" class="trending-up"></div>
<div v-else-if="data.value.v2 == 0" class="trending-flat"></div>
<div v-else-if="data.value.v2 < 0" class="trending-down"></div>
</v-flex>
</v-layout>
</v-flex>
<v-flex xs4 offset-xs1 style="padding-top: 20px">
<v-layout row wrap>
<v-flex xs2 grey-bar></v-flex>
<v-flex xs4 chart-idx-name>{{sysDateBefore}}</v-flex>
</v-layout>
</v-flex>
<v-flex xs1 grey-bar></v-flex>
<v-flex xs3 chart-idx-name>2017/07/07</v-flex>
<v-flex xs1>
<v-btn icon v-on:click="goDetails('sample1')">
<v-btn icon @click="goDetails('sample1')">
<i class="material-icons md-24 grey100">more_horiz</i>
</v-btn>
</v-flex>
<v-flex xs4 chart-func-value-tag><b>{{data.day.v1}}</b></v-flex>
<v-flex xs3 chart-idx-name>
<span>{{data.day.f3}}<br><span class="box-idx-value"><b>{{data.day.v3}}%</b></span>
<div v-if="data.day.v3 > 0" class="trending-up"></div>
<div v-else-if="data.day.v3 == 0" class="trending-flat"></div>
<div v-else-if="data.day.v3 < 0" class="trending-down"></div></span>
<v-flex xs4>
<v-layout row wrap>
<v-flex xs12 chart-func-value-tag @click="goDetails('sample1')"><b>{{data.value.v1}}</b></v-flex>
<v-flex xs9 under-bar></v-flex>
</v-layout>
</v-flex>
<v-flex xs2>
<v-layout row wrap>
<v-flex xs12 chart-idx-name>{{data.value.f3}}</v-flex>
<v-flex xs9 chart-idx-value><b>{{data.value.v3}}%</b></v-flex>
<v-flex xs3 text-xs-left>
<div v-if="data.value.v3 > 0" class="trending-up"></div>
<div v-else-if="data.value.v3 == 0" class="trending-flat"></div>
<div v-else-if="data.value.v3 < 0" class="trending-down"></div>
</v-flex>
</v-layout>
</v-flex>
<v-flex xs4 offset-xs1 style="padding-top: 10px">
<v-layout row wrap>
<v-flex xs2 cyan-bar></v-flex>
<v-flex xs4 chart-idx-name>{{sysDate}}</v-flex>
</v-layout>
</v-flex>
<v-flex xs1 cyan-bar></v-flex>
<v-flex xs4 chart-idx-name>2017/07/14</v-flex>
<v-flex xs3 under-bar></div></v-flex>
</v-layout>
</v-card>
<v-layout row wrap>
<v-flex xs12 chart-detail>
<v-card>
<div id="sample1-day" style="width:100%;height:240px"></div>
<div id="sample1-day" style="width:100%;height:180px"></div>
</v-card>
</v-flex>
</v-layout>
Expand Down
7 changes: 7 additions & 0 deletions dashboard-web/src/main/resources/metrics/sample1/chart.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select stat_date, cast(max(func_value)as signed) as func_value
from T_RESULT
where func_name='在库SKU'
and warehouse_name='#{{warehouse}}'
and date_cycle='#{{dateCycle}}'
and stat_date between DATE_FORMAT(DATE_SUB('#{{sysDate}}',INTERVAL 13 DAY),'%Y/%m/%d') and DATE_FORMAT('#{{sysDate}}','%Y/%m/%d')
group by stat_date order by stat_date
5 changes: 5 additions & 0 deletions dashboard-web/src/main/resources/metrics/sample1/day.option
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
'<span style="font-size:12px; color: #6E88AC">' + addDate(params[0].name, -7) + ' : ' + params[1].value + '</span>'
}
},
grid: {
top: 20,
left: '15%',
bottom: 20
},
xAxis: {
type: 'category',
splitLine: {
Expand Down
34 changes: 12 additions & 22 deletions dashboard-web/src/main/resources/metrics/sample1/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,15 @@
"charts": [
{
"name": "day",
"sql": "e.sql",
"params": [
{
"name": "dateCycle",
"value": ""
}
]
"sql": "e.sql"
},
{
"name": "week",
"sql": "e.sql",
"params": [
{
"name": "dateCycle",
"value": ""
}
]
"sql": "e.sql"
},
{
"name": "month",
"sql": "e.sql",
"params": [
{
"name": "dateCycle",
"value": ""
}
]
"sql": "e.sql"
}
],
"id": "sample1",
Expand All @@ -50,7 +32,15 @@
"values": [
{
"name": "day",
"sql": "a.sql"
"sql": "number-day.sql"
},
{
"name": "week",
"sql": "number-week.sql"
},
{
"name": "month",
"sql": "number-month.sql"
}
]
}
11 changes: 7 additions & 4 deletions dashboard-web/src/main/resources/metrics/sample1/month.option
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
},
formatter:function(params) {
return '<span style="font-size:12px; color: #00D7FB">' + params[0].name + ' : ' + params[0].value + '</span><br>' +
'<span style="font-size:12px; color: #6E88AC">' + addDate(params[0].name, -7) + ' : ' + params[1].value + '</span>'
'<span style="font-size:12px; color: #6E88AC">' + addDate(params[0].name, -12) + ' : ' + params[1].value + '</span>'
}
},
grid: {
left: '15%',
},
xAxis: {
type: 'category',
splitLine: {
Expand All @@ -19,7 +22,7 @@
color: '#6E88AC'
}
},
data: res.stat_date.slice(-7)
data: res.stat_date.slice(-12)
},
yAxis: {
type: 'value',
Expand All @@ -41,7 +44,7 @@
width: 1
}
},
data: res.func_value.slice(-7)
data: res.func_value.slice(-12)
},
{
type: 'bar',
Expand All @@ -51,6 +54,6 @@
width: 1
}
},
data: res.func_value.slice(0,7)
data: res.func_value.slice(0,12)
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT '在库SKU数'as f1, '14,300' as v1,
'日环比'as f2, 8.8 as v2,
'周同比'as f3, -4.3 as v3,
'昨日全天'as f4, '13,222' as v4,
'上周同日'as f5, '15,775' as v5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT '在库SKU数'as f1, '424,367' as v1,
'月环比'as f2, 2.8 as v2,
'年同比'as f3, 4.3 as v3,
'整月数据'as f4, '413,733' as v4,
'去年同月'as f5, '417,662' as v5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT '在库SKU数'as f1, '104,123' as v1,
'周环比'as f2, 4.8 as v2,
'年同比'as f3, -2.3 as v3,
'整周数据'as f4, '103,468' as v4,
'去年同周'as f5, '105,637' as v5
44 changes: 29 additions & 15 deletions dashboard-web/src/main/resources/metrics/sample1/number.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<v-flex xs6 v-if="data.day">
<v-flex xs6 v-if="data.value">
<v-card>
<v-layout row wrap>
<v-flex xs8 box-func-name-tag>{{data.day.f1}}</v-flex>
<v-flex xs4 box-idx-name>
<span>{{data.day.f2}}<br><span class="box-idx-value"><b>{{data.day.v2}}%</b></span>
<div v-if="data.day.v2 > 0" class="trending-up"></div>
<div v-else-if="data.day.v2 == 0" class="trending-flat"></div>
<div v-else-if="data.day.v2 < 0" class="trending-down"></div></span>
<v-layout row wrap @click="goDetails('sample1')">
<v-flex xs8 box-func-name-tag>{{data.value.f1}}</v-flex>
<v-flex xs4>
<v-layout row wrap>
<v-flex xs12 box-idx-name>{{data.value.f2}}</v-flex>
<v-flex xs9 box-idx-value>{{data.value.v2}}%</v-flex>
<v-flex xs3 text-xs-left>
<div v-if="data.value.v2 > 0" class="trending-up"></div>
<div v-else-if="data.value.v2 == 0" class="trending-flat"></div>
<div v-else-if="data.value.v2 < 0" class="trending-down"></div>
</v-flex>
</v-layout>
</v-flex>
<v-flex xs8 box-func-value-tag><b>{{data.day.v1}}</b></v-flex>
<v-flex xs4 box-idx-name>
<span>{{data.day.f3}}<br><span class="box-idx-value"><b>{{data.day.v3}}%</b></span>
<div v-if="data.day.v3 > 0" class="trending-up"></div>
<div v-else-if="data.day.v3 == 0" class="trending-flat"></div>
<div v-else-if="data.day.v3 < 0" class="trending-down"></div></span>
<v-flex xs8>
<v-layout row wrap>
<v-flex xs12 box-func-value-tag><b>{{data.value.v1}}</b></v-flex>
<v-flex xs9 under-bar></v-flex>
</v-layout>
</v-flex>
<v-flex xs4>
<v-layout row wrap>
<v-flex xs12 box-idx-name>{{data.value.f3}}</v-flex>
<v-flex xs9 box-idx-value>{{data.value.v3}}%</v-flex>
<v-flex xs3 text-xs-left>
<div v-if="data.value.v3 > 0" class="trending-up"></div>
<div v-else-if="data.value.v3 == 0" class="trending-flat"></div>
<div v-else-if="data.value.v3 < 0" class="trending-down"></div>
</v-flex>
</v-layout>
</v-flex>
<v-flex xs6 under-bar></v-flex>
</v-layout>
</v-card>
</v-flex>
Loading

0 comments on commit 8b0ad63

Please sign in to comment.