forked from fanruan/finekit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.0 KiB
75 lines
3.0 KiB
package com.fanruan.api.report.analy; |
|
|
|
import com.fanruan.api.report.analy.data.TreeNode; |
|
import com.fr.cache.list.IntList; |
|
import com.fr.form.ui.Widget; |
|
import com.fr.report.cell.ResultCellElement; |
|
import com.fr.report.cell.WidgetAttrElem; |
|
import com.fr.report.web.button.form.TreeNodeToggleButton; |
|
import com.fr.report.worksheet.AnalysisRWorkSheet; |
|
|
|
import java.util.HashMap; |
|
import java.util.Iterator; |
|
import java.util.Map; |
|
|
|
/** |
|
* 数据分析相关的业务类,此类是为了接盘AnalyKit中的庞杂的私有方法,增强AnalyKit的可读性 |
|
*/ |
|
public class AnalyKitHelper { |
|
|
|
public static Map<Integer, TreeNode> generateNodeTree(AnalysisRWorkSheet resultWS) { |
|
int rowSize = resultWS.getRowCount(); |
|
Map<Integer, TreeNode> nodeMap = new HashMap<Integer, TreeNode>(); |
|
|
|
for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {//遍历行 |
|
ResultCellElement treeNodeCell = findToggleCell(resultWS, rowIndex); |
|
if (treeNodeCell != null) { |
|
Widget widget = ((WidgetAttrElem) treeNodeCell).getWidget(); |
|
IntList sonList = ((TreeNodeToggleButton) widget).getRelativeIndexList(); |
|
if (sonList != null && sonList.size() > 1) { |
|
if (sonList.get(0) == -1) { |
|
//折叠行 |
|
if (nodeMap.containsKey(treeNodeCell.getRow())) { |
|
continue; |
|
} |
|
buildNodeMap(resultWS, treeNodeCell, nodeMap, -1); |
|
} else { |
|
//折叠列 暂不处理 |
|
} |
|
} |
|
} |
|
} |
|
return nodeMap; |
|
} |
|
|
|
private static ResultCellElement findToggleCell(AnalysisRWorkSheet reportCase, int rowIndex) { |
|
Iterator cellIterator = reportCase.getRow(rowIndex); |
|
while (cellIterator.hasNext()) { |
|
ResultCellElement tmpCell = (ResultCellElement) cellIterator.next(); |
|
if (tmpCell instanceof WidgetAttrElem) { |
|
if (((WidgetAttrElem) tmpCell).getWidget() instanceof TreeNodeToggleButton) { |
|
return tmpCell; |
|
} |
|
} |
|
} |
|
return null; |
|
} |
|
|
|
private static void buildNodeMap(AnalysisRWorkSheet reportCase, ResultCellElement cellElment, Map<Integer, TreeNode> nodeMap, int parent) { |
|
if (cellElment == null) { |
|
return; |
|
} |
|
TreeNodeToggleButton toggleButton = (TreeNodeToggleButton) ((WidgetAttrElem) cellElment).getWidget(); |
|
int self = cellElment.getRow(); |
|
IntList sonList = toggleButton.getRelativeIndexList(); |
|
if (sonList != null && sonList.size() > 1) { |
|
if (sonList.get(0) == -1) {//折叠行 |
|
nodeMap.put(self, new TreeNode(self, parent, sonList)); |
|
int size = sonList.size(); |
|
for (int i = 0; i < size; i++) { |
|
buildNodeMap(reportCase, findToggleCell(reportCase, sonList.get(i)), nodeMap, self); |
|
} |
|
} |
|
} |
|
} |
|
} |