use of org.sagacity.sqltoy.config.model.UnpivotModel in project sagacity-sqltoy by chenrenfei.
the class ResultUtils method calculate.
/**
* @todo 非存储过程模式调用结果计算处理器
* @param sqlToyConfig
* @param dataSetResult
* @param pivotCategorySet
* @param debug
* @throws Exception
*/
public static void calculate(SqlToyConfig sqlToyConfig, DataSetResult dataSetResult, List pivotCategorySet, boolean debug) throws Exception {
if (sqlToyConfig.getResultProcessor() != null) {
List items = dataSetResult.getRows();
List resultProcessors = sqlToyConfig.getResultProcessor();
Object processor;
HashMap<String, Integer> labelIndexMap = new HashMap<String, Integer>();
String realLabelName;
String[] fields = dataSetResult.getLabelNames();
for (int i = 0, n = fields.length; i < n; i++) {
realLabelName = fields[i].toLowerCase();
if (realLabelName.indexOf(":") != -1)
realLabelName = realLabelName.substring(0, realLabelName.indexOf(":")).trim();
labelIndexMap.put(realLabelName, i);
}
for (int i = 0; i < resultProcessors.size(); i++) {
processor = resultProcessors.get(i);
// 数据旋转
if (processor instanceof PivotModel) {
items = pivotResult((PivotModel) processor, labelIndexMap, items, pivotCategorySet, debug);
} else if (processor instanceof UnpivotModel) {
items = unPivotResult((UnpivotModel) processor, dataSetResult, labelIndexMap, items);
} else {
// 数据汇总合计
groupSummary((SummaryModel) processor, labelIndexMap, items);
}
}
dataSetResult.setRows(items);
}
}
use of org.sagacity.sqltoy.config.model.UnpivotModel in project sagacity-sqltoy by chenrenfei.
the class ResultUtils method calculate.
/**
* @todo 对查询结果进行计算处理:字段脱敏、格式化、数据旋转、同步环比、分组汇总等
* @param desensitizeProvider
* @param sqlToyConfig
* @param dataSetResult
* @param pivotCategorySet
* @param extend
* @return
*/
public static boolean calculate(DesensitizeProvider desensitizeProvider, SqlToyConfig sqlToyConfig, DataSetResult dataSetResult, List pivotCategorySet, QueryExecutorExtend extend) {
List items = dataSetResult.getRows();
// 数据为空直接跳出处理
if (items == null || items.isEmpty()) {
return false;
}
boolean changedCols = false;
List<SecureMask> secureMasks = sqlToyConfig.getSecureMasks();
List<FormatModel> formatModels = sqlToyConfig.getFormatModels();
List resultProcessors = new ArrayList();
if (!sqlToyConfig.getResultProcessor().isEmpty()) {
resultProcessors.addAll(sqlToyConfig.getResultProcessor());
}
if (extend != null && !extend.calculators.isEmpty()) {
resultProcessors.addAll(extend.calculators);
}
// 整理列名称跟index的对照map
LabelIndexModel labelIndexMap = null;
if (!secureMasks.isEmpty() || !formatModels.isEmpty() || (extend != null && (!extend.secureMask.isEmpty() || !extend.colsFormat.isEmpty())) || !resultProcessors.isEmpty()) {
labelIndexMap = wrapLabelIndexMap(dataSetResult.getLabelNames());
}
// 字段脱敏
if (!secureMasks.isEmpty()) {
secureMask(desensitizeProvider, items, secureMasks.iterator(), labelIndexMap);
}
// 自动格式化
if (!formatModels.isEmpty()) {
formatColumn(items, formatModels.iterator(), labelIndexMap);
}
// 扩展脱敏和格式化处理
if (extend != null) {
if (!extend.secureMask.isEmpty()) {
secureMask(desensitizeProvider, items, extend.secureMask.values().iterator(), labelIndexMap);
}
if (!extend.colsFormat.isEmpty()) {
formatColumn(items, extend.colsFormat.values().iterator(), labelIndexMap);
}
}
// 计算
if (!resultProcessors.isEmpty()) {
Object processor;
for (int i = 0; i < resultProcessors.size(); i++) {
processor = resultProcessors.get(i);
// 数据旋转(行转列)
if (processor instanceof PivotModel) {
items = pivotResult((PivotModel) processor, labelIndexMap, items, pivotCategorySet);
changedCols = true;
} else // 列转行
if (processor instanceof UnpivotModel) {
items = UnpivotList.process((UnpivotModel) processor, dataSetResult, labelIndexMap, items);
} else if (processor instanceof SummaryModel) {
// 数据汇总合计
GroupSummary.process((SummaryModel) processor, labelIndexMap, items);
} else if (processor instanceof ColsChainRelativeModel) {
// 列数据环比
ColsChainRelative.process((ColsChainRelativeModel) processor, labelIndexMap, items);
changedCols = true;
} else if (processor instanceof RowsChainRelativeModel) {
// 行数据环比
RowsChainRelative.process((RowsChainRelativeModel) processor, labelIndexMap, items);
} else if (processor instanceof ReverseModel) {
// 数据反序
ReverseList.process((ReverseModel) processor, labelIndexMap, items);
}
}
dataSetResult.setRows(items);
}
return changedCols;
}
Aggregations