mirror of
https://github.com/dataease/dataease.git
synced 2025-02-25 20:42:55 +08:00
feat(视图): 快速计算支持占比
This commit is contained in:
parent
d4c8492313
commit
a08ccdeed2
@ -10,4 +10,5 @@ public class ChartConstants {
|
|||||||
public static final String YEAR_YOY = "year_yoy";
|
public static final String YEAR_YOY = "year_yoy";
|
||||||
public static final String DAY_MOM = "day_mom";
|
public static final String DAY_MOM = "day_mom";
|
||||||
public static final String MONTH_YOY = "month_yoy";
|
public static final String MONTH_YOY = "month_yoy";
|
||||||
|
public static final String[] M_Y = {YEAR_MOM, MONTH_MOM, YEAR_YOY, DAY_MOM, MONTH_YOY};
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,8 @@ public class ChartViewService {
|
|||||||
}
|
}
|
||||||
boolean hasParameters = false;
|
boolean hasParameters = false;
|
||||||
if (StringUtils.isNotEmpty(table.getSqlVariableDetails())) {
|
if (StringUtils.isNotEmpty(table.getSqlVariableDetails())) {
|
||||||
List<SqlVariableDetails> sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken<List<SqlVariableDetails>>() {}.getType());
|
List<SqlVariableDetails> sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken<List<SqlVariableDetails>>() {
|
||||||
|
}.getType());
|
||||||
for (String parameter : Optional.ofNullable(request.getParameters()).orElse(new ArrayList<>())) {
|
for (String parameter : Optional.ofNullable(request.getParameters()).orElse(new ArrayList<>())) {
|
||||||
if (sqlVariables.stream().map(SqlVariableDetails::getVariableName).collect(Collectors.toList()).contains(parameter)) {
|
if (sqlVariables.stream().map(SqlVariableDetails::getVariableName).collect(Collectors.toList()).contains(parameter)) {
|
||||||
hasParameters = true;
|
hasParameters = true;
|
||||||
@ -994,6 +995,14 @@ public class ChartViewService {
|
|||||||
if (StringUtils.isNotEmpty(compareCalc.getType())
|
if (StringUtils.isNotEmpty(compareCalc.getType())
|
||||||
&& !StringUtils.equalsIgnoreCase(compareCalc.getType(), "none")) {
|
&& !StringUtils.equalsIgnoreCase(compareCalc.getType(), "none")) {
|
||||||
String compareFieldId = compareCalc.getField();// 选中字段
|
String compareFieldId = compareCalc.getField();// 选中字段
|
||||||
|
// 计算指标对应的下标
|
||||||
|
int dataIndex = 0;// 数据字段下标
|
||||||
|
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||||
|
dataIndex = xAxis.size() + extStack.size() + i;
|
||||||
|
} else {
|
||||||
|
dataIndex = xAxis.size() + i;
|
||||||
|
}
|
||||||
|
if (Arrays.asList(ChartConstants.M_Y).contains(compareCalc.getType())) {
|
||||||
String resultData = compareCalc.getResultData();// 数据设置
|
String resultData = compareCalc.getResultData();// 数据设置
|
||||||
// 获取选中字段以及下标
|
// 获取选中字段以及下标
|
||||||
List<ChartViewFieldDTO> checkedField = new ArrayList<>(xAxis);
|
List<ChartViewFieldDTO> checkedField = new ArrayList<>(xAxis);
|
||||||
@ -1008,13 +1017,6 @@ public class ChartViewService {
|
|||||||
timeField = checkedField.get(j);
|
timeField = checkedField.get(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 计算指标对应的下标
|
|
||||||
int dataIndex = 0;// 数据字段下标
|
|
||||||
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
|
||||||
dataIndex = xAxis.size() + extStack.size() + i;
|
|
||||||
} else {
|
|
||||||
dataIndex = xAxis.size() + i;
|
|
||||||
}
|
|
||||||
// 无选中字段,或者选中字段已经不在维度list中,或者选中字段日期格式不符合对比类型的,直接将对应数据置为null
|
// 无选中字段,或者选中字段已经不在维度list中,或者选中字段日期格式不符合对比类型的,直接将对应数据置为null
|
||||||
if (ObjectUtils.isEmpty(timeField) || !checkCalcType(timeField.getDateStyle(), compareCalc.getType())) {
|
if (ObjectUtils.isEmpty(timeField) || !checkCalcType(timeField.getDateStyle(), compareCalc.getType())) {
|
||||||
// set null
|
// set null
|
||||||
@ -1060,6 +1062,29 @@ public class ChartViewService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (StringUtils.equalsIgnoreCase(compareCalc.getType(), "percent")) {
|
||||||
|
// 求和
|
||||||
|
BigDecimal sum = new BigDecimal(0);
|
||||||
|
for (int index = 0; index < data.size(); index++) {
|
||||||
|
String[] item = data.get(index);
|
||||||
|
String cValue = item[dataIndex];
|
||||||
|
if (StringUtils.isEmpty(cValue)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sum = sum.add(new BigDecimal(cValue));
|
||||||
|
}
|
||||||
|
// 计算占比
|
||||||
|
for (int index = 0; index < data.size(); index++) {
|
||||||
|
String[] item = data.get(index);
|
||||||
|
String cValue = item[dataIndex];
|
||||||
|
if (StringUtils.isEmpty(cValue)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
item[dataIndex] = new BigDecimal(cValue)
|
||||||
|
.divide(sum, 8, RoundingMode.HALF_UP)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1599,7 +1624,8 @@ public class ChartViewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table, Datasource ds) throws Exception {
|
private String handleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table, Datasource ds) throws Exception {
|
||||||
List<SqlVariableDetails> sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken<List<SqlVariableDetails>>() {}.getType());
|
List<SqlVariableDetails> sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken<List<SqlVariableDetails>>() {
|
||||||
|
}.getType());
|
||||||
if (requestList != null && CollectionUtils.isNotEmpty(requestList.getFilter())) {
|
if (requestList != null && CollectionUtils.isNotEmpty(requestList.getFilter())) {
|
||||||
for (ChartExtFilterRequest chartExtFilterRequest : requestList.getFilter()) {
|
for (ChartExtFilterRequest chartExtFilterRequest : requestList.getFilter()) {
|
||||||
if (CollectionUtils.isEmpty(chartExtFilterRequest.getValue())) {
|
if (CollectionUtils.isEmpty(chartExtFilterRequest.getValue())) {
|
||||||
|
@ -1429,7 +1429,8 @@ export default {
|
|||||||
reserve_one: '1',
|
reserve_one: '1',
|
||||||
reserve_two: '2',
|
reserve_two: '2',
|
||||||
proportion: 'Proportion',
|
proportion: 'Proportion',
|
||||||
label_content: 'Label Content'
|
label_content: 'Label Content',
|
||||||
|
percent: 'Percent'
|
||||||
},
|
},
|
||||||
dataset: {
|
dataset: {
|
||||||
parse_filed: 'Parse Field',
|
parse_filed: 'Parse Field',
|
||||||
|
@ -1429,7 +1429,8 @@ export default {
|
|||||||
reserve_one: '一位',
|
reserve_one: '一位',
|
||||||
reserve_two: '两位',
|
reserve_two: '两位',
|
||||||
proportion: '佔比',
|
proportion: '佔比',
|
||||||
label_content: '標籤展示'
|
label_content: '標籤展示',
|
||||||
|
percent: '占比'
|
||||||
},
|
},
|
||||||
dataset: {
|
dataset: {
|
||||||
parse_filed: '解析字段',
|
parse_filed: '解析字段',
|
||||||
|
@ -1428,7 +1428,8 @@ export default {
|
|||||||
reserve_one: '一位',
|
reserve_one: '一位',
|
||||||
reserve_two: '两位',
|
reserve_two: '两位',
|
||||||
proportion: '占比',
|
proportion: '占比',
|
||||||
label_content: '标签展示'
|
label_content: '标签展示',
|
||||||
|
percent: '占比'
|
||||||
},
|
},
|
||||||
dataset: {
|
dataset: {
|
||||||
parse_filed: '解析字段',
|
parse_filed: '解析字段',
|
||||||
|
@ -153,7 +153,7 @@
|
|||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
|
|
||||||
<!--同比/环比-->
|
<!--同比/环比等快速计算-->
|
||||||
<el-dropdown-item v-show="!item.chartId && chart.type !== 'table-info'">
|
<el-dropdown-item v-show="!item.chartId && chart.type !== 'table-info'">
|
||||||
<el-dropdown
|
<el-dropdown
|
||||||
placement="right-start"
|
placement="right-start"
|
||||||
@ -175,6 +175,7 @@
|
|||||||
:disabled="disableEditCompare"
|
:disabled="disableEditCompare"
|
||||||
:command="beforeQuickCalc('setting')"
|
:command="beforeQuickCalc('setting')"
|
||||||
>{{ $t('chart.yoy_label') }}...</el-dropdown-item>
|
>{{ $t('chart.yoy_label') }}...</el-dropdown-item>
|
||||||
|
<el-dropdown-item :command="beforeQuickCalc('percent')">{{ $t('chart.percent') }}</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -383,6 +384,10 @@ export default {
|
|||||||
case 'setting':
|
case 'setting':
|
||||||
this.editCompare()
|
this.editCompare()
|
||||||
break
|
break
|
||||||
|
case 'percent':
|
||||||
|
this.item.compareCalc.type = 'percent'
|
||||||
|
this.$emit('onQuotaItemChange', this.item)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@
|
|||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
|
|
||||||
<!--同比/环比-->
|
<!--同比/环比等快速计算-->
|
||||||
<el-dropdown-item v-show="!item.chartId && chart.type !== 'table-info'">
|
<el-dropdown-item v-show="!item.chartId && chart.type !== 'table-info'">
|
||||||
<el-dropdown
|
<el-dropdown
|
||||||
placement="right-start"
|
placement="right-start"
|
||||||
@ -175,6 +175,7 @@
|
|||||||
:disabled="disableEditCompare"
|
:disabled="disableEditCompare"
|
||||||
:command="beforeQuickCalc('setting')"
|
:command="beforeQuickCalc('setting')"
|
||||||
>{{ $t('chart.yoy_label') }}...</el-dropdown-item>
|
>{{ $t('chart.yoy_label') }}...</el-dropdown-item>
|
||||||
|
<el-dropdown-item :command="beforeQuickCalc('percent')">{{ $t('chart.percent') }}</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -380,6 +381,10 @@ export default {
|
|||||||
case 'setting':
|
case 'setting':
|
||||||
this.editCompare()
|
this.editCompare()
|
||||||
break
|
break
|
||||||
|
case 'percent':
|
||||||
|
this.item.compareCalc.type = 'percent'
|
||||||
|
this.$emit('onQuotaItemChange', this.item)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user