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.
80 lines
3.7 KiB
80 lines
3.7 KiB
3 years ago
|
package com.fr.plugin.mail.fold;
|
||
|
|
||
|
import com.fr.main.workbook.ResultWorkBook;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
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 com.fr.schedule.base.bean.output.OutputEmail;
|
||
|
import com.fr.schedule.base.constant.ScheduleConstants;
|
||
|
import com.fr.schedule.extension.report.job.output.formula.EmailFormula;
|
||
|
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
|
||
|
import com.fr.schedule.feature.util.ScheduleUtils;
|
||
|
import com.fr.stable.unit.UNIT;
|
||
|
import com.fr.web.core.ReportSessionIDInfor;
|
||
|
|
||
|
import java.util.*;
|
||
|
|
||
|
/**
|
||
|
* @Author fr.open
|
||
|
* @Date 2021/5/8
|
||
|
* @Description
|
||
|
**/
|
||
|
@FunctionRecorder
|
||
|
public class MailFoldFormula extends EmailFormula {
|
||
|
@Override
|
||
|
public void dealWithFormulaParam(OutputEmail outputEmail, ResultWorkBook resultWorkBook, List<Map<String, Object>> list) throws Exception {
|
||
|
ResultWorkBook fold = getFold(resultWorkBook, list.get(0));
|
||
|
String contentText = ScheduleParameterUtils.dealWithParameter(outputEmail.getBodyContent(), list.get(0), fold);
|
||
|
super.dealWithFormulaParam(outputEmail, fold, list);
|
||
|
ReportSessionIDInfor sessionIdInfo = (new ReportSessionIDInfor(Collections.emptyMap())).buildResultWorkBook(fold);
|
||
|
boolean showTPL = outputEmail.isPreviewAttach();// 是否勾选正文
|
||
|
boolean addLink = outputEmail.isAddLink();// 是否勾选链接
|
||
|
String bodyContent = contentText;
|
||
|
bodyContent = showTPL ? bodyContent + "<br />" + TagUtils.exportTemplateAsHtml(null, sessionIdInfo) : bodyContent;
|
||
|
bodyContent = addLink ? bodyContent + "<br /> <a href=" + outputEmail.getResultURL() + ScheduleUtils.getScheduleResultURL((Map) list.get(1)) + ">" + ScheduleConstants.SCHEDULE_LINK + "</a>" : bodyContent;
|
||
|
outputEmail.setBodyContent(bodyContent);
|
||
|
outputEmail.setBodyContentWithoutTPL(bodyContent);
|
||
|
}
|
||
|
|
||
|
private ResultWorkBook getFold(ResultWorkBook book, Map<String, Object> param) {
|
||
|
if (param.containsKey("expand") && "false".equals(param.get("expand").toString())) {
|
||
|
return book;
|
||
|
}
|
||
|
for (int i = 0; i < book.getReportCount(); i++) {
|
||
|
if (book.getReport(i) instanceof AnalysisRWorkSheet) {
|
||
|
AnalysisRWorkSheet sheet = (AnalysisRWorkSheet) book.getReport(i);
|
||
|
Map<Integer, TreeNode> map = ExportUtil.generateNodeTree(sheet, new ArrayList());
|
||
|
for (int j = 0; j < sheet.getRowCount(); j++) {
|
||
|
if (findToggleCell(sheet, j)) {
|
||
|
if (map.get(j) == null || map.get(j).getParent() != -1) {
|
||
|
sheet.setRowHeight(j, UNIT.ZERO);
|
||
|
if (map.get(j) != null && map.get(j).getSons() != null) {
|
||
|
for (int k = 1; k < map.get(j).getSons().size(); k++) {
|
||
|
sheet.setRowHeight(map.get(j).getSons().get(k), UNIT.ZERO);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return book;
|
||
|
}
|
||
|
|
||
|
private boolean 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 true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|