Skip to content

Commit

Permalink
增加对于兄弟节点并行展开的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 14, 2024
1 parent ff842f4 commit 9ca29e8
Show file tree
Hide file tree
Showing 43 changed files with 869 additions and 167 deletions.
10 changes: 10 additions & 0 deletions docs/dev-guide/report/xpt-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ SUM(A3:D5)

* xptRt.seq(seqName): 相当于是 seqName ++,即读取seqName对应的变量值,执行递增操作,然后返回递增之前的值。如果一开始变量不存在,则认为初始化为1

## 调试
在【XptWorkbookModel】配置中可以设置`dump=true`启用调试文件输出,在模板展开的过程中会把每一个中间结果输出到dumpDir目录下,dumpDir的缺省值为`./target`

![](xpt-report/report-dump.png)

调试文件的文件名格式为`{seq}-{cellPos}.html`
![](xpt-report/report-dump-file.png)

调试文件中的每个单元格中的内容为 `cellText <- cellLayerCoordinate`

## 常见问题解答:

### 1. 单元格的展开值`cell.expandValue`和单元格个的值`cell.value`之间有什么区别?
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/dev-guide/report/xpt-report/report-dump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void transformModule(IOrmModel ormModel, NopDynModule dynModule) {
List<OrmMappingTableMeta> mappingTables = new ArrayList<>();
ormModel.getEntityModels().forEach(entityModel -> {
// many-to-many的中间表不转换为实体表
if (entityModel.containsTag(OrmModelConstants.TAG_MANY_TO_MANY)) {
if (OrmMappingTableMeta.isMappingTable(entityModel)) {
mappingTables.add(new OrmMappingTableMeta(entityModel));
return;
}
Expand Down
13 changes: 13 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/ExcelConfigs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.nop.excel;

import io.nop.api.core.config.IConfigReference;
import io.nop.api.core.util.SourceLocation;

import static io.nop.api.core.config.AppConfig.varRef;

public interface ExcelConfigs {
SourceLocation s_loc = SourceLocation.fromClass(ExcelConfigs.class);

IConfigReference<Integer> CFG_EXCEL_MAX_SHEET_NAME_LENGTH =
varRef(s_loc, "nop.excel.max-sheet-name-length", Integer.class, 31);
}
2 changes: 1 addition & 1 deletion nop-excel/src/main/java/io/nop/excel/model/ExcelCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.nop.core.model.table.ICell;
import io.nop.excel.model._gen._ExcelCell;

public class ExcelCell extends _ExcelCell {
public class ExcelCell extends _ExcelCell implements IExcelCell {
private ExcelCell realCell;
private int rowOffset;
private int colOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
*/
package io.nop.excel.model;

import io.nop.core.model.table.IColumnConfig;
import io.nop.excel.model._gen._ExcelColumnConfig;

public class ExcelColumnConfig extends _ExcelColumnConfig implements IColumnConfig {
public class ExcelColumnConfig extends _ExcelColumnConfig implements IExcelCol {
public ExcelColumnConfig() {

}

@Override
public ExcelColumnConfig getColModel() {
return this;
}
}
2 changes: 1 addition & 1 deletion nop-excel/src/main/java/io/nop/excel/model/ExcelRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.util.ArrayList;

public class ExcelRow extends _ExcelRow {
public class ExcelRow extends _ExcelRow implements IExcelRow {
public ExcelRow() {
setCells(new ArrayList<>());
}
Expand Down
2 changes: 1 addition & 1 deletion nop-excel/src/main/java/io/nop/excel/model/ExcelTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.HashSet;
import java.util.Set;

public class ExcelTable extends _ExcelTable implements INeedInit {
public class ExcelTable extends _ExcelTable implements INeedInit, IExcelTable {
public ExcelTable() {
setRows(new ArrayList<>());
}
Expand Down
5 changes: 5 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/model/ExcelWorkbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public ExcelWorkbook() {

}

public boolean isEnableDump() {
XptWorkbookModel model = getModel();
return model == null ? false : Boolean.TRUE.equals(model.getDump());
}

public boolean shouldRemoveHiddenCell() {
XptWorkbookModel model = getModel();
return model == null ? false : model.isRemoveHiddenCell();
Expand Down
7 changes: 7 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/model/IExcelCell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.nop.excel.model;

import io.nop.core.model.table.ICellView;

public interface IExcelCell extends ICellView {
XptCellModel getModel();
}
7 changes: 7 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/model/IExcelCol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.nop.excel.model;

import io.nop.core.model.table.IColumnConfig;

public interface IExcelCol extends IColumnConfig {
ExcelColumnConfig getColModel();
}
7 changes: 7 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/model/IExcelRow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.nop.excel.model;

import io.nop.core.model.table.IRowView;

public interface IExcelRow extends IRowView {
XptRowModel getModel();
}
4 changes: 3 additions & 1 deletion nop-excel/src/main/java/io/nop/excel/model/IExcelSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
public interface IExcelSheet {
String getName();

XptSheetModel getModel();

ExcelPageSetup getPageSetup();

ExcelPageMargins getPageMargins();
Expand All @@ -29,7 +31,7 @@ public interface IExcelSheet {

Double getDefaultColumnWidth();

ITableView getTable();
IExcelTable getTable();

List<ExcelImage> getImages();

Expand Down
7 changes: 7 additions & 0 deletions nop-excel/src/main/java/io/nop/excel/model/IExcelTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.nop.excel.model;

import io.nop.core.model.table.ITableView;

public interface IExcelTable extends ITableView {
IExcelRow getRow(int index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public abstract class _XptWorkbookModel extends io.nop.core.resource.component.A
*/
private io.nop.core.lang.eval.IEvalAction _beginLoop ;

/**
*
* xml name: dump
* 如果为true,则每一步展开的中间结果都会输出为html
*/
private java.lang.Boolean _dump ;

/**
*
* xml name: dumpDir
* 配置了dumpDir,则dump的时候会输出到此目录下
*/
private java.lang.String _dumpDir ;

/**
*
* xml name: editors
Expand Down Expand Up @@ -72,6 +86,13 @@ public abstract class _XptWorkbookModel extends io.nop.core.resource.component.A
*/
private java.lang.String _loopVarName ;

/**
*
* xml name: maxSheetNameLength
*
*/
private java.lang.Integer _maxSheetNameLength ;

/**
*
* xml name: removeHiddenCell
Expand Down Expand Up @@ -143,6 +164,44 @@ public void setBeginLoop(io.nop.core.lang.eval.IEvalAction value){
}


/**
*
* xml name: dump
* 如果为true,则每一步展开的中间结果都会输出为html
*/

public java.lang.Boolean getDump(){
return _dump;
}


public void setDump(java.lang.Boolean value){
checkAllowChange();

this._dump = value;

}


/**
*
* xml name: dumpDir
* 配置了dumpDir,则dump的时候会输出到此目录下
*/

public java.lang.String getDumpDir(){
return _dumpDir;
}


public void setDumpDir(java.lang.String value){
checkAllowChange();

this._dumpDir = value;

}


/**
*
* xml name: editors
Expand Down Expand Up @@ -264,6 +323,25 @@ public void setLoopVarName(java.lang.String value){
}


/**
*
* xml name: maxSheetNameLength
*
*/

public java.lang.Integer getMaxSheetNameLength(){
return _maxSheetNameLength;
}


public void setMaxSheetNameLength(java.lang.Integer value){
checkAllowChange();

this._maxSheetNameLength = value;

}


/**
*
* xml name: removeHiddenCell
Expand Down Expand Up @@ -350,11 +428,14 @@ protected void outputJson(IJsonHandler out){
out.putNotNull("afterExpand",this.getAfterExpand());
out.putNotNull("beforeExpand",this.getBeforeExpand());
out.putNotNull("beginLoop",this.getBeginLoop());
out.putNotNull("dump",this.getDump());
out.putNotNull("dumpDir",this.getDumpDir());
out.putNotNull("editors",this.getEditors());
out.putNotNull("endLoop",this.getEndLoop());
out.putNotNull("loopIndexName",this.getLoopIndexName());
out.putNotNull("loopItemsName",this.getLoopItemsName());
out.putNotNull("loopVarName",this.getLoopVarName());
out.putNotNull("maxSheetNameLength",this.getMaxSheetNameLength());
out.putNotNull("removeHiddenCell",this.isRemoveHiddenCell());
out.putNotNull("viewers",this.getViewers());
}
Expand All @@ -371,11 +452,14 @@ protected void copyTo(XptWorkbookModel instance){
instance.setAfterExpand(this.getAfterExpand());
instance.setBeforeExpand(this.getBeforeExpand());
instance.setBeginLoop(this.getBeginLoop());
instance.setDump(this.getDump());
instance.setDumpDir(this.getDumpDir());
instance.setEditors(this.getEditors());
instance.setEndLoop(this.getEndLoop());
instance.setLoopIndexName(this.getLoopIndexName());
instance.setLoopItemsName(this.getLoopItemsName());
instance.setLoopVarName(this.getLoopVarName());
instance.setMaxSheetNameLength(this.getMaxSheetNameLength());
instance.setRemoveHiddenCell(this.isRemoveHiddenCell());
instance.setViewers(this.getViewers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@ public void initRpcContext(IGraphQLExecutionContext context, GraphQLOperationTyp
ParsedGraphQLRequest req = new ParsedGraphQLRequest();
req.setDocument(doc);
context.setRequest(req);
context.setOperation(doc.getOperation());

GraphQLOperation op = (GraphQLOperation) doc.getDefinitions().get(0);

GraphQLOperation op = doc.getOperation();
context.setOperation(op);

FieldSelectionBean fieldSelection = buildSelectionBean(operationName, op.getSelectionSet(), Collections.emptyMap());

context.setFieldSelection(fieldSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
import java.util.Map;
import java.util.UUID;

import static io.nop.ooxml.xlsx.output.XlsxGenHelper.normalizeSheetName;

public class ExcelSheetWriter extends AbstractXmlTemplate {
private final IExcelSheet sheet;
private final boolean tabSelected;
private final int sheetIndex;

private final ExcelWorkbook workbook;

private String drawingRelId;

public ExcelSheetWriter(IExcelSheet sheet, boolean tabSelected, ExcelWorkbook workbook) {
public ExcelSheetWriter(IExcelSheet sheet, boolean tabSelected, int sheetIndex, ExcelWorkbook workbook) {
this.sheet = sheet;
this.tabSelected = tabSelected;
this.sheetIndex = sheetIndex;
this.workbook = workbook;
}

Expand Down Expand Up @@ -294,7 +298,7 @@ void genLinks(IXNodeHandler out, IExcelSheet sheet) {
links.forEach(link -> {
Map<String, ValueWithLocation> attrs = new LinkedHashMap<>();
attrs.put("ref", ValueWithLocation.of(null, CellPosition.toABString(link.rowIndex, link.colIndex)));
attrs.put("location", ValueWithLocation.of(null, link.location));
attrs.put("location", ValueWithLocation.of(null, normalizeLocation(link.location)));
attrs.put("display", ValueWithLocation.of(null, link.text));
attrs.put("xr:id", ValueWithLocation.of(null, intToUUID(link.index)));
out.simpleNode(null, "hyperlink", attrs);
Expand All @@ -303,6 +307,21 @@ void genLinks(IXNodeHandler out, IExcelSheet sheet) {
}
}

private String normalizeLocation(String location) {
int pos = location.indexOf('!');
if (pos > 0) {
String abPos = location.substring(pos + 1);
try {
CellPosition.fromABString(abPos);
String sheetName = location.substring(0, pos);
return normalizeSheetName(sheetName, sheetIndex, workbook) + '!' + abPos;
} catch (Exception e) {
return location;
}
}
return location;
}

static class Link {
int index;
int rowIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Map;

import static io.nop.ooxml.common.model.PackagingURIHelper.createPartName;
import static io.nop.ooxml.xlsx.output.XlsxGenHelper.normalizeSheetName;

public class ExcelTemplate extends AbstractOfficeTemplate {

Expand Down Expand Up @@ -109,10 +110,10 @@ private void generateSheet(ExcelOfficePackage pkg, File dir, int index, IExcelSh
OfficeRelsPart rels = pkg.makeRelsForPart(workbook);
String relPath = "worksheets/sheet" + sheetId + ".xml";
String relId = rels.addRelationship(XSSFRelation.WORKSHEET.getRelation(), relPath, null);
workbook.addSheet(relId, sheetId, sheet.getName());
workbook.addSheet(relId, sheetId, normalizeSheetName(sheet.getName(), index, this.workbook));

IResource resource = new FileResource(new File(dir, sheetPath));
ExcelSheetWriter writer = new ExcelSheetWriter(sheet, index == 0, this.workbook);
ExcelSheetWriter writer = new ExcelSheetWriter(sheet, index == 0, index, this.workbook);
writer.indent(isIndent()).generateToResource(resource, context);
IOfficePackagePart sheetPart = pkg.addFile(sheetPath, resource);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.nop.ooxml.xlsx.output;

import io.nop.excel.model.ExcelWorkbook;

import static io.nop.excel.ExcelConfigs.CFG_EXCEL_MAX_SHEET_NAME_LENGTH;

public class XlsxGenHelper {
/**
* Excel中sheetName的长度不能超过31
*/
public static String normalizeSheetName(String sheetName, int index, ExcelWorkbook workbook) {
int maxSheetNameLength = CFG_EXCEL_MAX_SHEET_NAME_LENGTH.get();
if (workbook.getModel() != null && workbook.getModel().getMaxSheetNameLength() != null && workbook.getModel().getMaxSheetNameLength() > 31) {
maxSheetNameLength = workbook.getModel().getMaxSheetNameLength();
}

if (sheetName.length() <= maxSheetNameLength)
return sheetName;

String postfix = "_" + (index + 1);
return sheetName.substring(0, maxSheetNameLength - postfix.length()) + postfix;
}

}
Loading

0 comments on commit 9ca29e8

Please sign in to comment.