From 41aa6607efe31dad452d28d78608915504a60b78 Mon Sep 17 00:00:00 2001 From: wangmingwei Date: Tue, 21 Apr 2026 17:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 76 + README | 0 README.md | 46 + allatori/allatori.xml | 36 + allatori/class-winter-maven-plugin-pom.xml | 37 + pom.xml | 114 + yunzhupaas-datareport-univer-common/pom.xml | 57 + .../java/com/yunzhupaas/consts/ApiConst.java | 12 + .../yunzhupaas/exception/ResultException.java | 208 + .../properties/ReportProperties.java | 7 + .../java/com/yunzhupaas/util/ChartUtil.java | 215 + .../java/com/yunzhupaas/util/ReportUtil.java | 96 + .../com/yunzhupaas/util/UniverConvert.java | 1195 ++++++ .../java/com/yunzhupaas/util/UniverExcel.java | 949 +++++ .../yunzhupaas/util/excel/ExcelParser.java | 16 + .../util/excel/UniverHSSFExcel.java | 597 +++ .../util/excel/UniverXSSFExcel.java | 728 ++++ yunzhupaas-datareport-univer-model/pom.xml | 36 + .../com/yunzhupaas/enums/CellDataEnum.java | 11 + .../com/yunzhupaas/enums/FormatTypeEnum.java | 22 + .../com/yunzhupaas/enums/HorizontalEnum.java | 46 + .../java/com/yunzhupaas/enums/ImageEnum.java | 11 + .../com/yunzhupaas/enums/OperatorEnum.java | 11 + .../com/yunzhupaas/enums/ResourceEnum.java | 56 + .../com/yunzhupaas/enums/StyleTypeEnum.java | 43 + .../com/yunzhupaas/enums/SubTypeEnum.java | 51 + .../com/yunzhupaas/enums/UniverDataEnum.java | 45 + .../com/yunzhupaas/enums/ValidationType.java | 52 + .../com/yunzhupaas/enums/VerticalEnum.java | 46 + .../yunzhupaas/enums/operatorTypeEnum.java | 51 + .../java/com/yunzhupaas/model/DataQuery.java | 20 + .../com/yunzhupaas/model/DataSortModel.java | 16 + .../univer/chart/UniverChartField.java | 25 + .../univer/chart/UniverChartModel.java | 18 + .../univer/data/cell/UniverCell.java | 20 + .../univer/data/cell/UniverDataConfig.java | 45 + .../univer/data/custom/UniverCustom.java | 19 + .../univer/data/resource/UniverConfig.java | 26 + .../data/resource/UniverCustomFilters.java | 19 + .../univer/data/resource/UniverDrawing.java | 33 + .../univer/data/resource/UniverFilters.java | 15 + .../univer/data/resource/UniverNum.java | 17 + .../univer/data/resource/UniverOffset.java | 17 + .../univer/data/resource/UniverRef.java | 20 + .../univer/data/resource/UniverRule.java | 23 + .../univer/data/resource/UniverTransform.java | 34 + .../univer/data/resource/UniverValue.java | 15 + .../univer/model/UniverPreview.java | 30 + .../univer/model/UniverWorkBook.java | 37 + .../univer/properties/UniverBody.java | 24 + .../univer/properties/UniverBodyConfig.java | 58 + .../properties/UniverDocumentStyle.java | 43 + .../properties/UniverDocumentStyleConfig.java | 21 + .../univer/properties/UniverProperties.java | 33 + .../univer/resources/UniverResource.java | 16 + .../univer/resources/UniverResourceData.java | 67 + .../yunzhupaas/univer/sheet/UniverSheet.java | 38 + .../univer/sheet/UniverSheetCell.java | 17 + .../univer/sheet/UniverSheetCellData.java | 45 + .../univer/sheet/UniverSheetColumnData.java | 23 + .../univer/sheet/UniverSheetColumnHeader.java | 17 + .../univer/sheet/UniverSheetFreeze.java | 19 + .../univer/sheet/UniverSheetRange.java | 47 + .../univer/sheet/UniverSheetRowData.java | 32 + .../univer/sheet/UniverSheetRowHeader.java | 17 + .../yunzhupaas/univer/style/UniverStyle.java | 98 + .../univer/style/UniverStyleBorder.java | 35 + .../univer/style/UniverStyleBorderStyle.java | 17 + .../univer/style/UniverStyleColor.java | 17 + .../univer/style/UniverStylePadding.java | 19 + .../univer/style/UniverStylePattern.java | 14 + .../style/UniverStyleTextDecoration.java | 24 + .../univer/style/UniverStyleTextRotation.java | 25 + .../java/com/yunzhupaas/ureport/Range.java | 15 + .../yunzhupaas/ureport/build/BindData.java | 15 + .../com/yunzhupaas/ureport/build/Context.java | 169 + .../yunzhupaas/ureport/build/DataCompute.java | 32 + .../com/yunzhupaas/ureport/build/Dataset.java | 14 + .../ureport/build/DatasetUtils.java | 32 + .../ureport/build/ReportBuilder.java | 60 + .../ureport/build/aggregate/Aggregate.java | 18 + .../ureport/build/aggregate/AvgAggregate.java | 40 + .../build/aggregate/CountAggregate.java | 29 + .../build/aggregate/GroupAggregate.java | 52 + .../ureport/build/aggregate/MaxAggregate.java | 37 + .../ureport/build/aggregate/MinAggregate.java | 37 + .../build/aggregate/NoneAggregate.java | 44 + .../build/aggregate/SelectAggregate.java | 41 + .../ureport/build/aggregate/SumAggregate.java | 32 + .../yunzhupaas/ureport/cell/CellBuilder.java | 11 + .../ureport/cell/DuplicateType.java | 5 + .../cell/down/CellDownDuplicateUnit.java | 80 + .../ureport/cell/down/CellDownDuplicator.java | 160 + .../ureport/cell/down/DownBlankCellApply.java | 79 + .../ureport/cell/down/DownCellbuilder.java | 262 ++ .../ureport/cell/down/DownDuplicate.java | 60 + .../cell/down/DownDuplocatorWrapper.java | 62 + .../ureport/cell/down/DownExpandBuilder.java | 133 + .../ureport/cell/none/NoneExpandBuilder.java | 35 + .../cell/right/CellRightDuplicateUnit.java | 85 + .../cell/right/CellRightDuplicator.java | 164 + .../cell/right/RightBlankCellApply.java | 74 + .../ureport/cell/right/RightCellbuilder.java | 265 ++ .../ureport/cell/right/RightDuplicate.java | 63 + .../cell/right/RightDuplocatorWrapper.java | 69 + .../cell/right/RightExpandBuilder.java | 140 + .../ureport/compute/DatasetValueCompute.java | 18 + .../compute/ExpressionValueCompute.java | 59 + .../ureport/compute/SimpleValueCompute.java | 21 + .../ureport/compute/ValueCompute.java | 11 + .../ureport/compute/ZxingValueCompute.java | 116 + .../ureport/definition/BlankCellInfo.java | 18 + .../ureport/definition/CellDefinition.java | 115 + .../ureport/definition/ColumnDefinition.java | 24 + .../yunzhupaas/ureport/definition/Expand.java | 5 + .../ureport/definition/ReportDefinition.java | 97 + .../ureport/definition/RowDefinition.java | 25 + .../definition/value/AggregateType.java | 14 + .../definition/value/DatasetValue.java | 36 + .../definition/value/ExpressionValue.java | 26 + .../ureport/definition/value/SimpleValue.java | 19 + .../ureport/definition/value/Value.java | 7 + .../ureport/definition/value/ValueType.java | 5 + .../ureport/definition/value/ZxingValue.java | 31 + .../ureport/expression/antlr/ReportLexer.java | 253 ++ .../expression/antlr/ReportListener.java | 31 + .../expression/antlr/ReportParser.java | 3605 +++++++++++++++++ .../expression/antlr/ReportVisitor.java | 230 ++ .../expression/assertor/AbstractAssertor.java | 22 + .../ureport/expression/assertor/Assertor.java | 9 + .../expression/assertor/EqualsAssertor.java | 56 + .../assertor/EqualsGreatThenAssertor.java | 42 + .../assertor/EqualsLessThenAssertor.java | 45 + .../assertor/GreatThenAssertor.java | 42 + .../expression/assertor/InAssertor.java | 58 + .../expression/assertor/LessThenAssertor.java | 42 + .../expression/assertor/LikeAssertor.java | 20 + .../assertor/NotEqualsAssertor.java | 32 + .../expression/assertor/NotInAssertor.java | 43 + .../builder/BaseExpressionBuilder.java | 128 + .../builder/BooleanExpressionBuilder.java | 22 + .../builder/CellObjectExpressionBuilder.java | 32 + .../CellPositionExpressionBuilder.java | 25 + .../CurrentCellDataExpressionBuilder.java | 27 + .../CurrentCellValueExpressionBuilder.java | 23 + .../expression/builder/ExpressionBuilder.java | 14 + .../builder/FunctionExpressionBuilder.java | 45 + .../builder/IntegerExpressionBuilder.java | 26 + .../builder/NullExpressionBuilder.java | 21 + .../builder/NumberExpressionBuilder.java | 25 + .../RelativeCellExpressionBuilder.java | 25 + .../builder/SetExpressionBuilder.java | 131 + .../builder/StringExpressionBuilder.java | 24 + .../builder/VariableExpressionBuilder.java | 23 + .../expression/condition/BaseCondition.java | 84 + .../condition/BothExpressionCondition.java | 41 + .../expression/condition/CellCoordinate.java | 21 + .../condition/CellCoordinateSet.java | 17 + .../condition/CellExpressionCondition.java | 57 + .../expression/condition/Condition.java | 13 + .../expression/condition/ConditionType.java | 9 + .../expression/condition/CoordinateType.java | 9 + .../CurrentValueExpressionCondition.java | 37 + .../PropertyExpressionCondition.java | 52 + .../data/BindDataListExpressionData.java | 22 + .../expression/data/ExpressionData.java | 9 + .../expression/data/NoneExpressionData.java | 12 + .../expression/data/ObjectExpressionData.java | 18 + .../data/ObjectListExpressionData.java | 20 + .../expression/expr/AssignExpression.java | 57 + .../expression/expr/BaseExpression.java | 58 + .../expression/expr/BlockExpression.java | 34 + .../expression/expr/BooleanExpression.java | 23 + .../expr/CellConditionExpression.java | 44 + .../expr/CellCoordinateExpression.java | 283 ++ .../expression/expr/CellDataExpression.java | 33 + .../expression/expr/CellExpression.java | 49 + .../expression/expr/CellObjectExpression.java | 39 + .../expr/CellPositionExpression.java | 113 + .../expression/expr/CellValueExpression.java | 18 + .../expression/expr/ConditionList.java | 49 + .../expression/expr/ElseExpression.java | 22 + .../expression/expr/ElseIfExpression.java | 28 + .../ureport/expression/expr/Expression.java | 15 + .../expression/expr/ExpressionCondition.java | 76 + .../expr/ExpressionConditionList.java | 49 + .../expression/expr/FromToExpression.java | 50 + .../expression/expr/FunctionExpression.java | 55 + .../ureport/expression/expr/IfExpression.java | 45 + .../expression/expr/IntegerExpression.java | 23 + .../ureport/expression/expr/Join.java | 16 + .../expression/expr/JoinExpression.java | 82 + .../expression/expr/NullExpression.java | 18 + .../expression/expr/NumberExpression.java | 25 + .../expression/expr/ParenExpression.java | 16 + .../expr/RelativeCellExpression.java | 54 + .../expression/expr/StringExpression.java | 23 + .../expression/expr/VariableExpression.java | 24 + .../expression/expr/WholeCellExpression.java | 50 + .../expression/function/AvgFunction.java | 73 + .../expression/function/ColumnFunction.java | 26 + .../expression/function/CountFunction.java | 44 + .../ureport/expression/function/Function.java | 17 + .../expression/function/FunctionType.java | 11 + .../expression/function/MaxFunction.java | 73 + .../expression/function/MinFunction.java | 73 + .../expression/function/RowFunction.java | 25 + .../expression/function/SumFunction.java | 70 + .../ureport/expression/util/ElCompute.java | 157 + .../expression/util/ExpressionUtils.java | 77 + .../expression/util/ExpressionVisitor.java | 323 ++ .../ureport/expression/util/Op.java | 50 + .../ureport/expression/util/Operator.java | 43 + .../com/yunzhupaas/ureport/model/Cell.java | 190 + .../com/yunzhupaas/ureport/model/Column.java | 42 + .../yunzhupaas/ureport/model/Functions.java | 24 + .../com/yunzhupaas/ureport/model/Report.java | 115 + .../com/yunzhupaas/ureport/model/Row.java | 45 + .../yunzhupaas/ureport/model/StyleModel.java | 22 + .../yunzhupaas/ureport/utils/BuildUtils.java | 22 + .../ureport/utils/DataComparator.java | 72 + .../yunzhupaas/ureport/utils/DataUtils.java | 256 ++ 222 files changed, 18009 insertions(+) create mode 100644 .gitignore delete mode 100644 README create mode 100644 README.md create mode 100644 allatori/allatori.xml create mode 100644 allatori/class-winter-maven-plugin-pom.xml create mode 100644 pom.xml create mode 100644 yunzhupaas-datareport-univer-common/pom.xml create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/consts/ApiConst.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/exception/ResultException.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/properties/ReportProperties.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ChartUtil.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ReportUtil.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverConvert.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverExcel.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/ExcelParser.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverHSSFExcel.java create mode 100644 yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverXSSFExcel.java create mode 100644 yunzhupaas-datareport-univer-model/pom.xml create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/CellDataEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/FormatTypeEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/HorizontalEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ImageEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/OperatorEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ResourceEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/StyleTypeEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/SubTypeEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/UniverDataEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ValidationType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/VerticalEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/operatorTypeEnum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataQuery.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataSortModel.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartField.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartModel.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverCell.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverDataConfig.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/custom/UniverCustom.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverConfig.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverCustomFilters.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverDrawing.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverFilters.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverNum.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverOffset.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRef.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRule.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverTransform.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverValue.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverPreview.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverWorkBook.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBody.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBodyConfig.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyle.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyleConfig.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverProperties.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResource.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResourceData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheet.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCell.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCellData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnHeader.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetFreeze.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRange.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowHeader.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyle.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorderStyle.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleColor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePadding.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePattern.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextDecoration.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextRotation.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/Range.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/BindData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Context.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DataCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Dataset.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DatasetUtils.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/ReportBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/Aggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/AvgAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/CountAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/GroupAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MaxAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MinAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/NoneAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SelectAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SumAggregate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/CellBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/DuplicateType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicateUnit.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicator.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownBlankCellApply.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownCellbuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplicate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplocatorWrapper.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownExpandBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/none/NoneExpandBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicateUnit.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicator.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightBlankCellApply.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightCellbuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplicate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplocatorWrapper.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightExpandBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/DatasetValueCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ExpressionValueCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/SimpleValueCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ValueCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ZxingValueCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/BlankCellInfo.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/CellDefinition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ColumnDefinition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/Expand.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ReportDefinition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/RowDefinition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/AggregateType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/DatasetValue.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ExpressionValue.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/SimpleValue.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/Value.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ValueType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ZxingValue.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportLexer.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportListener.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportParser.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportVisitor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/AbstractAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/Assertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsGreatThenAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsLessThenAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/GreatThenAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/InAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LessThenAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LikeAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotEqualsAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotInAssertor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BaseExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BooleanExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellObjectExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellPositionExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellDataExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellValueExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/ExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/FunctionExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/IntegerExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NullExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NumberExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/RelativeCellExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/SetExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/StringExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/VariableExpressionBuilder.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BaseCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BothExpressionCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinate.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinateSet.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellExpressionCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/Condition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/ConditionType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CoordinateType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CurrentValueExpressionCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/PropertyExpressionCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/BindDataListExpressionData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ExpressionData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/NoneExpressionData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectExpressionData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectListExpressionData.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/AssignExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BaseExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BlockExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BooleanExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellConditionExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellCoordinateExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellDataExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellObjectExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellPositionExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellValueExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ConditionList.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseIfExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Expression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionCondition.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionConditionList.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FromToExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FunctionExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IfExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IntegerExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Join.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/JoinExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NullExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NumberExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ParenExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/RelativeCellExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/StringExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/VariableExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/WholeCellExpression.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/AvgFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/ColumnFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/CountFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/Function.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/FunctionType.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MaxFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MinFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/RowFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/SumFunction.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ElCompute.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionUtils.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionVisitor.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Op.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Operator.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Cell.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Column.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Functions.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Report.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Row.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/StyleModel.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/BuildUtils.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataComparator.java create mode 100644 yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataUtils.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b83fbd --- /dev/null +++ b/.gitignore @@ -0,0 +1,76 @@ +# For Java +*.lck +target/ +*.json +log/ +logback-test.xml + + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# Image snapshot diff +__diff_output__/ +/jest-stare + +*.iml +.idea/ +.ipr +.iws +*~ +~* +*.diff +*.patch +*.bak +.DS_Store +Thumbs.db +.project +.*proj +.svn/ +*.swp +*.swo +*.log +*.log.* +*.json.gzip +node_modules/ +.buildpath +.settings +dist +npm-debug.log +nohup.out +_site +_data +report.html +/lib +/es +elasticsearch-* +config/base.yaml +/.vscode/ +/coverage +/.history +*.tmp +!**/nacos/target +**/nacos/data/* +**/nacos/logs/* +**/seata/bin/* diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md new file mode 100644 index 0000000..596e4a6 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +> 特别说明:源码、JDK、数据库、Redis等安装或存放路径禁止包含中文、空格、特殊字符等 + +## 一 环境要求 + +| 类目 | 版本说明或建议 | +| --- |------------------| +| 硬件 | 开发电脑建议使用I3及以上CPU,16G及以上内存 | +| 操作系统 | Windows 10/11,MacOS | +| JDK | 默认使用JDK 21,如需要切换JDK 8/11/17版本请参考文档调整代码,推荐使用 `OpenJDK`,如 `Liberica JDK`、`Eclipse Temurin`、`Alibaba Dragonwell`、`BiSheng`等发行版; | +| Maven | 依赖管理工具,推荐使用 `3.6.3` 及以上版本 | +| IDE | 代码集成开发环境,推荐使用 `IDEA2024` 及以上版本,兼容 `Eclipse`、 `Spring Tool Suite` 等IDE工具 | + +## 二 关联项目 +> 为以下项目提供基础依赖 + +| 项目 | 分支 | 说明 | +|---------------|---------------|------------| +| yunzhupaas-common | v5.2.x-stable | 项目基础依赖源码 | +| yunzhupaas-java-datareport-univer | v5.2.x-stable | Univer报表源码 | + +## 三 选择是否加密 + +> 是否加密将会影响 `yunzhupaas-java-datareport-univer` 项目的启动方式 +> 如果此项目选择加密 `yunzhupaas-java-datareport-univer` 项目也需要选择加密 + +### 3.1 不使用加密 + +在IDEA中, 展开右侧 `Maven` 中 `Profiles` 去除勾选 `encrypted` 选项, 再点击Maven `刷新` 图标刷新 Maven + +### 3.2 使用加密 + +在IDEA中, 展开右侧 `Maven` 中 `Profiles` 勾选 `encrypted` 选项, 再点击Maven `刷新` 图标刷新 Maven + +#### 3.2.1 安装加密插件 + +在IDEA中,双击右侧 `Maven` 中 `yunzhupaas-datareport-univer-core` > `clean` 将会自动安装加密打包插件 + +## 四 使用方式 + +### 4.1 本地安装 + +在IDEA中,双击右侧 `Maven` 中 `yunzhupaas-datareport-univer-core` > `Lifecycle` > `install`,将 `yunzhupaas-datareport-univer-core` 包安装至本地 + +### 4.2 发布到私服 + +在IDEA中,双击右侧 `Maven` 中 `yunzhupaas-datareport-univer-core` > `Lifecycle` > `deploy` 发布至私服。 diff --git a/allatori/allatori.xml b/allatori/allatori.xml new file mode 100644 index 0000000..45a915d --- /dev/null +++ b/allatori/allatori.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/allatori/class-winter-maven-plugin-pom.xml b/allatori/class-winter-maven-plugin-pom.xml new file mode 100644 index 0000000..b8cef5e --- /dev/null +++ b/allatori/class-winter-maven-plugin-pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + com.idea-aedi + class-winter-core + enhance-2.9.4 + + + + com.idea-aedi + class-winter-core + ${project.version} + + + + org.apache.maven + maven-plugin-api + 3.8.1 + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.6.1 + provided + + + + org.apache.maven + maven-project + 2.2.1 + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fb6d50b --- /dev/null +++ b/pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + + + com.yunzhupaas + yunzhupaas-common + 5.2.0-RELEASE + + + yunzhupaas-datareport-univer-core + 5.2.0-RELEASE + pom + + + 3.13.0 + 3.1.1 + 2.5.2 + 3.8.1 + 2.6 + 1.2.1 + enhance-2.9.4 + 5.3.0 + + + + + yunzhupaas-datareport-univer-common + yunzhupaas-datareport-univer-model + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + com.idea-aedi + class-winter-maven-plugin + ${class-winter-maven-plugin.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + + + + + + + + + maven-releases + maven-releases + https://xadev.szlecheng.cn/nexus/repository/maven-public/ + + + + + + diff --git a/yunzhupaas-datareport-univer-common/pom.xml b/yunzhupaas-datareport-univer-common/pom.xml new file mode 100644 index 0000000..a97fe0e --- /dev/null +++ b/yunzhupaas-datareport-univer-common/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + com.yunzhupaas + yunzhupaas-datareport-univer-core + 5.2.0-RELEASE + + + yunzhupaas-datareport-univer-common + + + + com.yunzhupaas + yunzhupaas-common-database + ${project.version} + + + com.yunzhupaas + yunzhupaas-common-swagger + ${project.version} + + + com.yunzhupaas + yunzhupaas-common-file + ${project.version} + + + org.apache.poi + poi + ${poi.version} + + + org.apache.poi + poi-ooxml-full + ${poi.version} + + + org.apache.poi + poi-ooxml + ${poi.version} + + + com.yunzhupaas + yunzhupaas-datareport-univer-model + ${project.version} + + + + + + + + + diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/consts/ApiConst.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/consts/ApiConst.java new file mode 100644 index 0000000..d79eefb --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/consts/ApiConst.java @@ -0,0 +1,12 @@ +package com.yunzhupaas.consts; + +public class ApiConst { + + public static String ME; + public static String DATASET_LIST; + public static String DATASET_SAVE; + public static String DATASET_DATA; + public static String SAVE_MENU; + public static String GET_MENU; + public static String PARAMETER_DATA; +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/exception/ResultException.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/exception/ResultException.java new file mode 100644 index 0000000..7b58a2c --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/exception/ResultException.java @@ -0,0 +1,208 @@ +package com.yunzhupaas.exception; + +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.exception.NotRoleException; +import cn.dev33.satoken.exception.SameTokenInvalidException; +import com.alibaba.fastjson.JSON; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import com.yunzhupaas.base.ActionResult; +import com.yunzhupaas.base.ActionResultCode; +import com.yunzhupaas.config.ConfigValueUtil; +import com.yunzhupaas.constant.MsgCode; +import com.yunzhupaas.util.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ErrorProperties; +import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; +import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author 云筑产品开发平台组 + * @version V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date 2024/3/16 10:10 + */ +@Slf4j +@Controller +@ControllerAdvice +public class ResultException extends BasicErrorController { + + @Autowired + private ConfigValueUtil configValueUtil; + + public ResultException() { + super(new DefaultErrorAttributes(), new ErrorProperties()); + } + + @ResponseBody + @ExceptionHandler(value = LoginException.class) + public ActionResult loginException(LoginException e) { + ActionResult result = ActionResult.fail(ActionResultCode.Fail.getCode(), e.getMessage()); + result.setData(e.getData()); + return result; + } + + @ResponseBody + @ExceptionHandler(value = ImportException.class) + public ActionResult loginException(ImportException e) { + ActionResult result = ActionResult.fail(ActionResultCode.Fail.getCode(), e.getMessage()); + return result; + } + + /** + * 自定义异常内容返回 + * + * @param e + * @return + */ + @ResponseBody + @ExceptionHandler(value = DataException.class) + public ActionResult dataException(DataException e) { + ActionResult result = ActionResult.fail(ActionResultCode.Fail.getCode(), e.getMessage()); + return result; + } + + /** + * 租户数据库异常 + * + * @param e + * @return + */ + @ResponseBody + @ExceptionHandler(value = TenantDatabaseException.class) + public ActionResult tenantDatabaseException(TenantDatabaseException e) { + String msg; + if (e.getMessage() == null) { + if (configValueUtil.getMultiTenancyUrl().contains("https")) { + // https 官网提示 + msg = MsgCode.LOG109.get(); + } else { + msg = MsgCode.LOG110.get(); + } + } else { + msg = e.getMessage(); + } + return ActionResult.fail(ActionResultCode.Fail.getCode(), msg); + } + + @ResponseBody + @ExceptionHandler(value = MethodArgumentNotValidException.class) + public ActionResult methodArgumentNotValidException(MethodArgumentNotValidException e) { + Map map = new HashMap<>(16); + List allErrors = e.getBindingResult().getAllErrors(); + for (int i = 0; i < allErrors.size(); i++) { + String s = allErrors.get(i).getCodes()[0]; + // 用分割的方法得到字段名 + String[] parts = s.split("\\."); + String part1 = parts[parts.length - 1]; + map.put(part1, allErrors.get(i).getDefaultMessage()); + } + String json = JSON.toJSONString(map); + ActionResult result = ActionResult.fail(ActionResultCode.ValidateError.getCode(), json); + return result; + } + + @ResponseBody + @ExceptionHandler(value = WorkFlowException.class) + public ActionResult workFlowException(WorkFlowException e) { + if (e.getCode() == 200) { + List> list = JsonUtil.getJsonToListMap(e.getMessage()); + return ActionResult.success(list); + } else { + return ActionResult.fail(e.getMessage()); + } + } + + @ResponseBody + @ExceptionHandler(value = WxErrorException.class) + public ActionResult wxErrorException(WxErrorException e) { + return ActionResult.fail(e.getError().getErrorCode(), MsgCode.AD103.get()); + } + + @ResponseBody + @ExceptionHandler(value = ServletException.class) + public void exception(ServletException e) throws Exception { + log.error("系统异常:" + e.getMessage(), e); + throw new Exception(); + } + + @ResponseBody + @ExceptionHandler(value = Exception.class) + public ActionResult exception(Exception e) { + log.error("系统异常:" + e.getMessage(), e); + if (e instanceof ConnectDatabaseException || e.getCause() instanceof ConnectDatabaseException) { + Throwable t = e; + if (e.getCause() instanceof ConnectDatabaseException) { + t = e.getCause(); + } + return ActionResult.fail(ActionResultCode.Fail.getCode(), t.getMessage()); + } + return ActionResult.fail(ActionResultCode.Fail.getCode(), MsgCode.AD102.get()); + } + + /** + * 权限码异常 + */ + @ResponseBody + @ExceptionHandler(NotPermissionException.class) + public ActionResult handleNotPermissionException(NotPermissionException e) { + return ActionResult.fail(ActionResultCode.Fail.getCode(), MsgCode.AD104.get()); + } + + /** + * 角色权限异常 + */ + @ResponseBody + @ExceptionHandler(NotRoleException.class) + public ActionResult handleNotRoleException(NotRoleException e) { + return ActionResult.fail(ActionResultCode.ValidateError.getCode(), MsgCode.AD104.get()); + } + + /** + * 认证失败 + */ + @ResponseBody + @ExceptionHandler(NotLoginException.class) + public ActionResult handleNotLoginException(NotLoginException e) { + return ActionResult.fail(ActionResultCode.SessionOverdue.getCode(), MsgCode.AD105.get()); + } + + /** + * 无效认证 + */ + @ResponseBody + @ExceptionHandler(SameTokenInvalidException.class) + public ActionResult handleIdTokenInvalidException(SameTokenInvalidException e) { + return ActionResult.fail(ActionResultCode.SessionOverdue.getCode(), MsgCode.AD106.get()); + } + + /** + * 覆盖默认的 JSON 响应 + */ + @Override + @RequestMapping + public ResponseEntity> error(HttpServletRequest request) { + HttpStatus status = getStatus(request); + + if (status == HttpStatus.NOT_FOUND) { + return new ResponseEntity<>(status); + } + return super.error(request); + } + +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/properties/ReportProperties.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/properties/ReportProperties.java new file mode 100644 index 0000000..ad1b7d9 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/properties/ReportProperties.java @@ -0,0 +1,7 @@ +package com.yunzhupaas.properties; + +public class ReportProperties { + + public static final String PREFIX = "report"; + +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ChartUtil.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ChartUtil.java new file mode 100644 index 0000000..9d19c07 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ChartUtil.java @@ -0,0 +1,215 @@ +package com.yunzhupaas.util; + +import com.yunzhupaas.univer.chart.UniverChartField; +import com.yunzhupaas.univer.chart.UniverChartModel; +import com.yunzhupaas.univer.data.cell.UniverDataConfig; +import com.yunzhupaas.ureport.definition.value.AggregateType; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午3:18 + */ +public class ChartUtil { + + public static void chart(List chartList, Map>> dataListAll, + List echartsList) { + for (UniverDataConfig model : echartsList) { + UniverChartModel chartModel = new UniverChartModel(); + chartModel.setDrawingId(model.getDrawingId()); + chartModel.setSubUnitId(model.getSubUnitId()); + chartModel.setUnitId(model.getUnitId()); + UniverDataConfig config = model.getOption() != null ? model.getOption() : new UniverDataConfig(); + // 数据 + Set datasetName = new HashSet<>(); + String classifyNameField = config.getClassifyNameField(); + config.setClassifyNameField(fieldName(classifyNameField, datasetName)); + + String seriesNameField = config.getSeriesNameField(); + config.setSeriesNameField(fieldName(seriesNameField, datasetName)); + + String seriesDataField = config.getSeriesDataField(); + config.setSeriesDataField(fieldName(seriesDataField, datasetName)); + + String maxField = config.getMaxField(); + config.setMaxField(fieldName(maxField, datasetName)); + + List> dataList = new ArrayList<>(); + for (String dataName : datasetName) { + List> data = dataListAll.get(dataName) != null ? dataListAll.get(dataName) + : new ArrayList<>(); + dataList.addAll(data); + } + UniverChartField chartField = chart(dataList, config); + chartModel.setField(chartField); + chartList.add(chartModel); + } + } + + private static UniverChartField chart(List> dataList, UniverDataConfig dataConfig) { + String classifyName = dataConfig.getClassifyNameField(); + String seriesName = dataConfig.getSeriesNameField(); + String seriesData = dataConfig.getSeriesDataField(); + String maxField = dataConfig.getMaxField(); + Map>> chartDataMap = new HashMap<>(); + Map> maxDatMap = new HashMap<>(); + for (int i = 0; i < dataList.size(); i++) { + Map data = dataList.get(i); + Object classify = data.get(classifyName); + if (classify == null) { + continue; + } + Object value = data.get(seriesData); + if (value == null) { + continue; + } + Object series = data.get(seriesName) != null ? data.get(seriesName) : ""; + Map> categoryMap = chartDataMap.get(series) != null ? chartDataMap.get(series) + : new HashMap<>(); + List valueList = categoryMap.get(classify) != null ? categoryMap.get(classify) : new ArrayList<>(); + valueList.add(value); + categoryMap.put(classify, valueList); + chartDataMap.put(series, categoryMap); + + Object max = data.get(maxField); + if (max != null) { + List maxData = maxDatMap.get(classify) != null ? maxDatMap.get(classify) : new ArrayList<>(); + maxData.add(max); + maxDatMap.put(classify, maxData); + } + } + return chartData(chartDataMap, maxDatMap, dataConfig); + } + + private static UniverChartField chartData(Map>> seriesDataMap, + Map> maxDataMap, UniverDataConfig dataConfig) { + UniverChartField chartField = new UniverChartField(); + List seriesNameList = new ArrayList<>(); + Map>> classifyMap = new HashMap<>(); + List maxCount = new ArrayList<>(); + maxCount.add(0); + for (Object series : seriesDataMap.keySet()) { + seriesNameList.add(String.valueOf(series)); + Map> classifyNameMap = seriesDataMap.get(series); + for (Object classify : classifyNameMap.keySet()) { + List> categroyList = new ArrayList<>(); + if (classifyMap.get(classify) != null) { + categroyList.addAll(classifyMap.get(classify)); + } + List valueList = classifyNameMap.get(classify); + List data = data(valueList, dataConfig); + for (int i = 0; i < data.size(); i++) { + List classifyData = new ArrayList<>(); + classifyData.add(data.get(i)); + categroyList.add(classifyData); + } + classifyMap.put(classify, categroyList); + maxCount.add(categroyList.size()); + } + } + if (StringUtil.isNotEmpty(dataConfig.getSeriesNameField())) { + chartField.setSeriesNameField(seriesNameList); + } + List maxFieldList = new ArrayList<>(); + List classifyNameList = new ArrayList<>(); + for (Object classify : classifyMap.keySet()) { + classifyNameList.add(String.valueOf(classify)); + List objects = maxDataMap.get(classify) != null ? maxDataMap.get(classify) : new ArrayList<>(); + if (objects.isEmpty()) { + objects.add(new BigDecimal(0)); + } + dataConfig.setSummaryType(AggregateType.max.name()); + List data = data(objects, dataConfig); + maxFieldList.add(data.get(0)); + } + List> seriesDataList = new ArrayList<>(); + for (int i = 0; i < Collections.max(maxCount); i++) { + List seriesData = new ArrayList<>(); + for (int k = 0; k < classifyNameList.size(); k++) { + String category = classifyNameList.get(k); + List> categoryList = classifyMap.get(category) != null ? classifyMap.get(category) + : new ArrayList<>(); + List categoryData = categoryList.size() - 1 >= i ? categoryList.get(i) : new ArrayList<>(); + String data = categoryData.size() > 0 ? categoryData.get(0) : ""; + seriesData.add(data); + } + seriesDataList.add(seriesData); + } + chartField.setClassifyNameField(classifyNameList); + chartField.setSeriesDataField(seriesDataList); + if (StringUtil.isNotEmpty(dataConfig.getMaxField())) { + chartField.setMaxField(maxFieldList); + } + return chartField; + } + + private static List data(List list, UniverDataConfig dataConfig) { + List result = new ArrayList<>(); + if (list.isEmpty()) { + return result; + } + String chartType = AggregateType.value(dataConfig.getSummaryType()) != null ? dataConfig.getSummaryType() + : AggregateType.select.name(); + DatasetValue expr = new DatasetValue(); + expr.setProperty(chartType); + AggregateType value = AggregateType.value(chartType); + List> dataList = new ArrayList<>(); + for (Object data : list) { + Map dataMap = new HashMap<>(); + dataMap.put(chartType, data); + dataList.add(dataMap); + } + List bindDataList = DataUtils.dataList(expr, dataList); + switch (value) { + case sum: + result.add(bindDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).doubleValue() + ""); + break; + case avg: + BigDecimal sumDecimal = bindDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); + if (bindDataList.isEmpty()) { + bindDataList.add(new BigDecimal(0)); + } + result.add(sumDecimal.divide(new BigDecimal(bindDataList.size()), 8, RoundingMode.HALF_UP) + .doubleValue() + ""); + break; + case max: + if (bindDataList.isEmpty()) { + bindDataList.add(new BigDecimal(0)); + } + result.add(bindDataList.stream().reduce(bindDataList.get(0), BigDecimal::max).doubleValue() + ""); + break; + case min: + if (bindDataList.isEmpty()) { + bindDataList.add(new BigDecimal(0)); + } + result.add(bindDataList.stream().reduce(bindDataList.get(0), BigDecimal::min).doubleValue() + ""); + break; + case count: + result.add(list.size() + ""); + break; + default: + for (Object data : list) { + result.add(String.valueOf(data)); + } + break; + } + return result; + } + + private static String fieldName(String field, Set datasetName) { + String fieldName = field; + if (StringUtil.isNotEmpty(fieldName)) { + String[] params = fieldName.split("\\."); + datasetName.add(params[0]); + fieldName = params.length == 2 ? params[1] : fieldName; + } + return fieldName; + } +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ReportUtil.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ReportUtil.java new file mode 100644 index 0000000..ef0b870 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/ReportUtil.java @@ -0,0 +1,96 @@ +package com.yunzhupaas.util; + +import cn.hutool.core.lang.TypeReference; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.Method; +import cn.hutool.json.JSONUtil; +import com.yunzhupaas.base.ActionResult; +import com.yunzhupaas.base.UserInfo; +import com.yunzhupaas.consts.ApiConst; +import com.yunzhupaas.database.util.TenantDataSourceUtil; +import com.yunzhupaas.model.login.MeInfoVO; +import com.yunzhupaas.model.tenant.TenantVO; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; +import java.util.Objects; + +/** + * 报表工具类 + */ +@Slf4j +public class ReportUtil { + + public static UserInfo initUserInfo(String token) { + UserInfo userInfo = UserProvider.getLocalLoginUser(); + if (userInfo == null) { + try { + HttpResponse response = HttpRequest.get(ApiConst.ME).header(Constants.AUTHORIZATION, token).execute(); + if (response.isOk()) { + String result = response.body(); + try { + ActionResult out = JSONUtil.toBean(result, + new TypeReference>() { + }, false); + if (Objects.equals(out.getCode(), Constants.SUCCESS)) { + MeInfoVO meInfoVO = out.getData(); + if (StringUtil.isNotEmpty(meInfoVO.getUserId())) { + // 构造用户信息 + String tenantId = meInfoVO.getTenantId(); + userInfo = new UserInfo(); + userInfo.setId(meInfoVO.getUserId()); + userInfo.setUserId(meInfoVO.getUserId()); + userInfo.setUserName(meInfoVO.getUserName()); + userInfo.setUserAccount(meInfoVO.getUserAccount()); + userInfo.setTenantId(tenantId); + UserProvider.setLocalLoginUser(userInfo); + // 设置租户信息 + if (TenantDataSourceUtil.isMultiTenancy()) { + // 直接从租户系统获取租户信息 + TenantVO tenantVO = TenantDataSourceUtil.getRemoteTenantInfo(tenantId); + TenantDataSourceUtil.switchTenant(tenantId, tenantVO); + userInfo.setTenantDbType(tenantVO.getType()); + // tenantDbConnectionString 已废弃,不再设置 + } + return userInfo; + } + if (log.isDebugEnabled()) { + log.debug("获取用户信息: {}", result); + } + } else { + log.error("主系统未成功返回用户信息: {}", out); + } + } catch (Exception e) { + log.error("用户信息解析失败:" + result, e); + } + } + } catch (Exception e) { + log.error("获取用户信息错误: {}", e.getMessage()); + } + } + return userInfo; + } + + public static String http(String url, Method method, Map params) { + HttpRequest request = HttpRequest.of(url).method(method); + switch (method) { + case GET: + request.form(params); + break; + default: + request.body(JsonUtil.getObjectToString(params)); + break; + } + request.header(Constants.AUTHORIZATION, UserProvider.getToken()); + request.setConnectionTimeout(50000); + request.setReadTimeout(60000); + String json = "{}"; + try { + json = request.execute().body(); + } catch (Exception e) { + log.error(e.getMessage()); + } + return json; + } +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverConvert.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverConvert.java new file mode 100644 index 0000000..30c7ad0 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverConvert.java @@ -0,0 +1,1195 @@ +package com.yunzhupaas.util; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.google.common.collect.ImmutableList; +import com.yunzhupaas.constant.DataInterfaceVarConst; +import com.yunzhupaas.constant.MsgCode; +import com.yunzhupaas.enums.*; +import com.yunzhupaas.enums.UniverDataEnum; +import com.yunzhupaas.exception.DataException; +import com.yunzhupaas.model.DataQuery; +import com.yunzhupaas.model.DataSortModel; +import com.yunzhupaas.univer.chart.UniverChartModel; +import com.yunzhupaas.univer.data.cell.UniverDataConfig; +import com.yunzhupaas.univer.data.custom.UniverCustom; +import com.yunzhupaas.univer.data.resource.UniverDrawing; +import com.yunzhupaas.univer.model.UniverPreview; +import com.yunzhupaas.univer.model.UniverWorkBook; +import com.yunzhupaas.univer.properties.UniverBody; +import com.yunzhupaas.univer.properties.UniverProperties; +import com.yunzhupaas.univer.resources.*; +import com.yunzhupaas.univer.sheet.*; +import com.yunzhupaas.ureport.build.Dataset; +import com.yunzhupaas.ureport.build.ReportBuilder; +import com.yunzhupaas.ureport.cell.down.DownCellbuilder; +import com.yunzhupaas.ureport.cell.right.RightCellbuilder; +import com.yunzhupaas.ureport.definition.*; +import com.yunzhupaas.ureport.definition.value.*; +import com.yunzhupaas.ureport.model.*; +import com.yunzhupaas.ureport.utils.DataUtils; +import com.yunzhupaas.util.type.SortType; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellReference; + +import java.math.BigDecimal; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +public class UniverConvert { + + // -------------------------------------解析数据------------------------------------------------ + + public UniverPreview transform(String snapshot, String cells, String sort, + Map>>> sheetData, + Map>> parameterData) { + UniverWorkBook univerWorkBook = StringUtil.isNotEmpty(snapshot) + ? JsonUtil.getJsonToBean(snapshot, UniverWorkBook.class) + : new UniverWorkBook(); + UniverCustom custom = StringUtil.isNotEmpty(cells) ? JsonUtil.getJsonToBean(cells, UniverCustom.class) + : new UniverCustom(); + List sortListAll = StringUtil.isNotEmpty(sort) ? JsonUtil.getJsonToList(sort, DataQuery.class) + : new ArrayList<>(); + // 排序 + Map>> sortMap = new HashMap<>(); + for (DataQuery dataQuery : sortListAll) { + String sheetId = dataQuery.getSheet(); + Map> dataBaseMap = sortMap.get(sheetId) != null ? sortMap.get(sheetId) + : new HashMap<>(); + List sortList = dataQuery.getSortList(); + for (DataSortModel dataModel : sortList) { + DataSortModel sortModel = JsonUtil.getJsonToBean(dataModel, DataSortModel.class); + String[] params = sortModel.getVModel().split("\\."); + if (params.length == 2) { + String datasetName = params[0]; + String property = params[1]; + sortModel.setVModel(property); + List dataSortModels = dataBaseMap.get(datasetName) != null + ? dataBaseMap.get(datasetName) + : new ArrayList<>(); + dataSortModels.add(sortModel); + dataBaseMap.put(datasetName, dataSortModels); + } + } + sortMap.put(sheetId, dataBaseMap); + } + // 图表 + Map floatEcharts = custom.getFloatEcharts(); + List resources = univerWorkBook.getResources(); + Map> echartMap = drawing(resources, floatEcharts); + Map sheetMap = new HashMap<>(); + List chartList = new ArrayList<>(); + for (String sheetOrder : univerWorkBook.getSheetOrder()) { + UniverSheet univerSheet = univerWorkBook.getSheets().get(sheetOrder); + Map>> dataList = sheetData.get(sheetOrder) != null + ? sheetData.get(sheetOrder) + : new HashMap<>(); + Map> sortDataMap = sortMap.get(sheetOrder) != null ? sortMap.get(sheetOrder) + : new HashMap<>(); + Map> parameterMap = parameterData.get(sheetOrder) != null + ? parameterData.get(sheetOrder) + : new HashMap<>(); + if (ObjectUtil.isNotEmpty(univerSheet)) { + List cellList = custom.getCells().stream() + .filter(t -> Objects.equals(sheetOrder, t.getSheet())).collect(Collectors.toList()); + UniverSheet sheet = buildLuckySheetDate(univerSheet, cellList, dataList, sortDataMap, parameterMap, + resources); + List echartsList = echartMap.get(sheetOrder) != null ? echartMap.get(sheetOrder) + : new ArrayList<>(); + ChartUtil.chart(chartList, dataList, echartsList); + sheetMap.put(sheet.getId(), sheet); + } + } + univerWorkBook.setSheets(sheetMap); + UniverPreview vo = new UniverPreview(); + vo.setSnapshot(JSON.toJSONString(JSON.toJSON(univerWorkBook))); + vo.setCells(cells); + + vo.setChartData(JSON.toJSONString(JSON.toJSON(chartList))); + return vo; + } + + private UniverSheet buildLuckySheetDate(UniverSheet sheet, List cell, + Map>> sheetDataMap, Map> sortDataMap, + Map> parameterDataMap, List resources) { + Map> cellData = sheet.getCellData(); + List parameterData = cell.stream() + .filter(t -> CellDataEnum.parameter.name().equals(t.getType())).collect(Collectors.toList()); + Pattern pattern = Pattern.compile("#\\{(.*?)\\}"); + for (UniverDataConfig dataConfig : parameterData) { + Integer row = dataConfig.getRow(); + Integer col = dataConfig.getCol(); + Map dataMap = cellData.get(row) != null ? cellData.get(row) : new HashMap<>(); + UniverSheetCellData sheetCellData = dataMap.get(col); + if (sheetCellData != null) { + String value = ""; + Object v = sheetCellData.getV(); + if (v != null) { + value = v + ""; + } + Object p = sheetCellData.getP(); + if (p != null) { + UniverProperties properties = JsonUtil.getJsonToBean(p, UniverProperties.class); + UniverBody body = properties.getBody(); + if (body != null) { + String dataStream = body.getDataStream(); + if (dataStream != null) { + value = dataStream; + } + } + } + Matcher matcher = pattern.matcher(value); + Map> number = new HashMap<>(); + List random = ImmutableList.of(DataInterfaceVarConst.ID_LOT); + while (matcher.find()) { + String patternText = matcher.group(1); + String[] split = patternText.split("\\."); + String datasetName = split[0]; + String property = split.length > 1 ? split[1] : split[0]; + boolean isRandom = random.contains(property); + Map data = parameterDataMap.get(datasetName) != null + ? parameterDataMap.get(datasetName) + : new HashMap<>(); + String textValue = data.get(property) != null ? data.get(property) + "" + : isRandom ? RandomUtil.uuId() : ""; + Map name = new HashMap<>(); + name.put(matcher.end(), textValue); + number.put(matcher.start(), name); + } + List colList = new ArrayList<>(number.keySet()).stream().sorted(Comparator.reverseOrder()) + .collect(Collectors.toList()); + for (Integer start : colList) { + Map name = number.get(start); + for (Integer end : name.keySet()) { + value = value.substring(0, start) + name.get(end) + value.substring(end, value.length()); + } + } + sheetCellData.setV(value); + sheetCellData.setP(null); + } + } + List datasourceData = cell.stream() + .filter(t -> CellDataEnum.dataSource.name().equals(t.getType())).collect(Collectors.toList()); + if (datasourceData.isEmpty()) { + return sheet; + } + // 处理数据 + Map>> dataList = new HashMap<>(); + for (String key : sheetDataMap.keySet()) { + List> list = sheetDataMap.get(key) != null ? sheetDataMap.get(key) : new ArrayList<>(); + List dataSortList = sortDataMap.get(key) != null ? sortDataMap.get(key) : new ArrayList<>(); + StringJoiner joiner = new StringJoiner(","); + for (DataSortModel dataSortModel : dataSortList) { + String vModel = dataSortModel.getVModel(); + boolean isDesc = Objects.equals(SortType.DESC, dataSortModel.getType()); + joiner.add((isDesc ? "-" : "") + vModel); + } + List> data = DataUtils.orderDataList(list, joiner.toString()); + dataList.put(key, data); + } + List rowMax = new ArrayList<>(); + rowMax.add(0); + List columnMax = new ArrayList<>(); + columnMax.add(0); + for (Integer rowKey : cellData.keySet()) { + rowMax.add(rowKey); + Map cellDataMap = cellData.get(rowKey); + columnMax.addAll(cellDataMap.keySet()); + } + List mergeData = sheet.getMergeData(); + Map sheetRowData = sheet.getRowData(); + Map sheetColumnData = sheet.getColumnData(); + ReportDefinition reportDefinition = new ReportDefinition(); + List rows = new ArrayList<>(); + List columns = new ArrayList<>(); + List cells = new ArrayList<>(); + reportDefinition.setRows(rows); + reportDefinition.setColumns(columns); + reportDefinition.setCells(cells); + Map datasetMap = new HashMap<>(); + for (String key : dataList.keySet()) { + Dataset dataset = new Dataset(); + dataset.setName(key); + dataset.setData(dataList.get(key)); + datasetMap.put(key, dataset); + } + reportDefinition.setDatasetMap(datasetMap); + Map functionMap = new HashMap<>(); + // 冻结 + UniverSheetFreeze freeze = sheet.getFreeze() != null ? sheet.getFreeze() : new UniverSheetFreeze(); + int freezeRow = freeze.getStartRow(); + int freezeColumn = freeze.getStartColumn(); + for (int i = 0; i <= Collections.max(rowMax); i++) { + RowDefinition rowDefinition = new RowDefinition(); + rowDefinition.setRowNumber(i); + rowDefinition.setSheetRowData(sheetRowData.get(i)); + rowDefinition.setFreeze(Objects.equals(freezeRow - 1, i)); + Map columnData = cellData.get(i) != null ? cellData.get(i) : new HashMap<>(); + for (int j = 0; j <= Collections.max(columnMax); j++) { + ColumnDefinition columnDefinition = new ColumnDefinition(); + columnDefinition.setColumnNumber(j); + columnDefinition.setFreeze(Objects.equals(freezeColumn - 1, j)); + columnDefinition.setSheetColumnData(sheetColumnData.get(j)); + UniverSheetCellData sheetCellData = columnData.get(j) != null ? columnData.get(j) + : new UniverSheetCellData(); + // 合并 + int rowSpan = 0; + int colSpan = 0; + StyleModel styleModel = new StyleModel(); + Optional range = mergeData.stream() + .filter(t -> t.getStartRow().equals(rowDefinition.getRowNumber()) + && t.getStartColumn().equals(columnDefinition.getColumnNumber())) + .findFirst(); + if (range.isPresent()) { + UniverSheetRange sheetRange = range.get(); + rowSpan = sheetRange.getEndRow() - sheetRange.getStartRow(); + colSpan = sheetRange.getEndColumn() - sheetRange.getStartColumn(); + if (rowSpan > 0) { + for (int row = sheetRange.getStartRow() + 1; row <= sheetRange.getEndRow() - 1; row++) { + Map dataMap = cellData.get(row); + if (dataMap != null) { + UniverSheetCellData startData = dataMap.get(sheetRange.getStartColumn()); + if (startData != null) { + styleModel.setL(startData.getS()); + } + UniverSheetCellData endData = dataMap.get(sheetRange.getEndColumn()); + if (endData != null) { + styleModel.setR(endData.getS()); + } + } + } + } + if (colSpan > 0) { + Map startDataMap = cellData.get(sheetRange.getStartRow()); + Map endDataMap = cellData.get(sheetRange.getEndRow()); + for (int col = sheetRange.getStartColumn() + 1; col <= sheetRange.getEndColumn() - 1; col++) { + if (startDataMap != null) { + UniverSheetCellData startData = startDataMap.get(col); + if (startData != null) { + styleModel.setT(startData.getS()); + } + } + if (endDataMap != null) { + UniverSheetCellData endData = endDataMap.get(col); + if (endData != null) { + styleModel.setB(endData.getS()); + } + } + } + } + Map startDataMap = cellData.get(sheetRange.getStartRow()); + if (startDataMap != null) { + UniverSheetCellData leftTopData = startDataMap.get(sheetRange.getStartColumn()); + if (leftTopData != null) { + styleModel.setLt(leftTopData.getS()); + } + UniverSheetCellData rightTopData = startDataMap.get(sheetRange.getEndColumn()); + if (rightTopData != null) { + styleModel.setRt(rightTopData.getS()); + } + } + Map endDataMap = cellData.get(sheetRange.getEndRow()); + if (endDataMap != null) { + UniverSheetCellData leftBodData = endDataMap.get(sheetRange.getStartColumn()); + if (leftBodData != null) { + styleModel.setLb(leftBodData.getS()); + } + UniverSheetCellData rightBodData = endDataMap.get(sheetRange.getEndColumn()); + if (rightBodData != null) { + styleModel.setRb(rightBodData.getS()); + } + } + } + CellDefinition cellDefinition = new CellDefinition(); + String definitionName = new CellReference(i, j).formatAsString(); + cellDefinition.setName(definitionName); + cellDefinition.setRowNumber(i + 1); + cellDefinition.setColumnNumber(j + 1); + cellDefinition.setRowSpan(rowSpan > 0 ? rowSpan + 1 : rowSpan); + cellDefinition.setColSpan(colSpan > 0 ? colSpan + 1 : colSpan); + cellDefinition.setSheetColumnData(sheetColumnData.get(j)); + cellDefinition.setSheetRowData(sheetRowData.get(i)); + cellDefinition.setCellData(sheetCellData); + cellDefinition.setStyleModel(styleModel); + + // 判断函数 + String function = sheetCellData.getF() != null ? sheetCellData.getF().toString() : ""; + if (StringUtil.isNotEmpty(function)) { + if (function.startsWith("=")) { + List list = new ArrayList<>(); + functionName(function, list); + Map> functionCell = new HashMap<>(); + for (CellRangeAddress rangeAddress : list) { + int startRow = rangeAddress.getFirstRow(); + int startCol = rangeAddress.getFirstColumn(); + int endRow = rangeAddress.getLastRow(); + int endCol = rangeAddress.getLastColumn(); + List cellsRange = getCellsRange(startRow, endRow, startCol, endCol); + List rangeName = new ArrayList<>(); + for (CellReference reference : cellsRange) { + int row = reference.getRow(); + int col = reference.getCol(); + Map rowMap = functionCell.get(row) != null ? functionCell.get(row) + : new HashMap<>(); + rowMap.put(col, reference.formatAsString()); + functionCell.put(row, rowMap); + rangeName.add(reference.formatAsString()); + } + if (cellsRange.size() > 1) { + function = function.replace(rangeAddress.formatAsString(), String.join(",", rangeName)); + } + } + List functionNameList = new ArrayList<>(); + List rowList = new ArrayList<>(functionCell.keySet()).stream() + .sorted(Comparator.reverseOrder()).collect(Collectors.toList()); + for (Integer row : rowList) { + Map rowMap = functionCell.get(row) != null ? functionCell.get(row) + : new HashMap<>(); + List colList = new ArrayList<>(rowMap.keySet()).stream() + .sorted(Comparator.reverseOrder()).collect(Collectors.toList()); + for (Integer col : colList) { + functionNameList.add(rowMap.get(col)); + } + } + Functions functions = new Functions(); + functions.setFunction(function); + functions.setName(definitionName); + functions.setFunctionName(functionNameList); + functionMap.put(definitionName, functions); + sheetCellData.setF(function); + sheetCellData.setV(null); + } + } + // 数据类型 + Expand expand = Expand.None; + String value = sheetCellData.getV() != null ? sheetCellData.getV().toString() : null; + Value values = new SimpleValue(value); + UniverDataConfig univerCellData = cell.stream() + .filter(t -> Objects.equals(t.getRow(), rowDefinition.getRowNumber()) + && Objects.equals(t.getCol(), columnDefinition.getColumnNumber())) + .findFirst().orElse(new UniverDataConfig()); + UniverDataConfig univerDataConfig = univerCellData.getCustom() != null ? univerCellData.getCustom() + : new UniverDataConfig(); + if (Objects.equals(CellDataEnum.dataSource.name(), univerCellData.getType())) { + String datasetName = ""; + String property = ""; + String fillDirection = univerDataConfig.getFillDirection(); + String fileName = univerDataConfig.getField(); + String summaryType = univerDataConfig.getSummaryType(); + if (StringUtils.isNotEmpty(fileName)) { + String[] params = fileName.split("\\."); + if (params.length == 2) { + datasetName = params[0]; + property = params[1]; + } + } + AggregateType aggregate = AggregateType.none; + Integer type = univerDataConfig.getPolymerizationType(); + boolean isSelect = Objects.equals(type, UniverDataEnum.select.getCode()); + boolean isGroup = Objects.equals(type, UniverDataEnum.group.getCode()); + boolean isSummary = Objects.equals(type, UniverDataEnum.summary.getCode()); + if (isSelect || isGroup) { + expand = Objects.equals(UniverDataEnum.cellDirection.getName(), fillDirection) ? Expand.Down + : Expand.Right; + aggregate = isGroup ? AggregateType.group : AggregateType.select; + } else if (isSummary) { + aggregate = AggregateType.value(summaryType); + } + DatasetValue datasetValue = new DatasetValue(); + datasetValue.setDatasetName(datasetName); + datasetValue.setProperty(property); + datasetValue.setAggregate(aggregate); + values = datasetValue; + } + + String leftName = ""; + String leftType = univerDataConfig.getLeftParentCellType(); + if (StringUtil.isNotEmpty(leftType)) { + UniverDataEnum dataType = UniverDataEnum.getData(leftType); + if (dataType != null) { + switch (dataType) { + case cellNone: + leftName = UniverDataEnum.cellRoot.getName(); + break; + case cellCustom: + leftName = univerDataConfig.getLeftParentCellCustomRowName() + + univerDataConfig.getLeftParentCellCustomColName(); + break; + case cellRoot: + case cellDirection: + case cellDefault: + case none: + case select: + case group: + case summary: + leftName = dataType.getName(); + break; + } + } + } + cellDefinition.setLeftType(leftType); + cellDefinition.setLeftParentCellName(leftName); + String topName = ""; + String topType = univerDataConfig.getTopParentCellType(); + if (StringUtil.isNotEmpty(topType)) { + UniverDataEnum dataType = UniverDataEnum.getData(topType); + if (dataType != null) { + switch (dataType) { + case cellNone: + topName = UniverDataEnum.cellRoot.getName(); + break; + case cellCustom: + topName = univerDataConfig.getTopParentCellCustomRowName() + + univerDataConfig.getTopParentCellCustomColName(); + break; + case cellRoot: + case cellDirection: + case cellDefault: + case none: + case select: + case group: + case summary: + topName = dataType.getName(); + break; + } + } + } + cellDefinition.setTopType(topType); + cellDefinition.setTopParentCellName(topName); + cellDefinition.setExpand(expand); + cellDefinition.setValue(values); + boolean notAdd = mergeData.stream() + .filter(t -> t.getStartRow() <= rowDefinition.getRowNumber() + && t.getStartColumn() <= columnDefinition.getColumnNumber() + && t.getEndRow() >= rowDefinition.getRowNumber() + && t.getEndColumn() >= columnDefinition.getColumnNumber()) + .count() > 0; + if (!notAdd || mergeData.isEmpty() || range.isPresent()) { + cells.add(cellDefinition); + } + columnDefinition.setColumnNumber(columnDefinition.getColumnNumber() + 1); + if (columns.stream() + .filter(t -> Objects.equals(t.getColumnNumber(), columnDefinition.getColumnNumber())) + .count() == 0) { + columns.add(columnDefinition); + } + } + rowDefinition.setRowNumber(rowDefinition.getRowNumber() + 1); + rows.add(rowDefinition); + } + rebuild(reportDefinition); + rebuildReportDefinition(reportDefinition); + ReportBuilder reportBuilder = new ReportBuilder(); + Report report = reportBuilder.buildReport(reportDefinition); + UniverSheet result = sheet(sheet, report, functionMap); + resource(sheet.getId(), report, resources); + return result; + } + + private UniverSheet sheet(UniverSheet sheet, Report report, Map functionMap) { + sheet.setCellData(new HashMap<>()); + sheet.setMergeData(new ArrayList<>()); + sheet.setRowData(new HashMap<>()); + sheet.setColumnData(new HashMap<>()); + Map rowData = new HashMap<>(); + Map columnData = new HashMap<>(); + UniverSheet result = JsonUtil.getJsonToBean(sheet, UniverSheet.class); + List rows = report.getRows(); + List columns = report.getColumns(); + Map> cellMap = report.getRowColCellMap(); + Map> cellData = new HashMap<>(); + Map> cellFunctionMap = new HashMap<>(); + List mergeData = new ArrayList<>(); + // 获取冻结位置 + UniverSheetFreeze sheetFreeze = sheet.getFreeze() != null ? sheet.getFreeze() : new UniverSheetFreeze(); + int freezeRow = sheetFreeze.getStartRow(); + List freezeRowList = new ArrayList<>(); + freezeRowList.add(freezeRow); + int freezeColumn = sheetFreeze.getStartColumn(); + List freezeColumnList = new ArrayList<>(); + freezeColumnList.add(freezeColumn); + // 绘制格子 + for (int i = 0; i < rows.size(); i++) { + Row row = rows.get(i); + rowData.put(i, row.getSheetRowData()); + if (row.getFreeze()) { + freezeRowList.add(i + 1); + } + for (int j = 0; j < columns.size(); j++) { + Column col = columns.get(j); + Cell cell = null; + if (cellMap.containsKey(row)) { + Map colMap = cellMap.get(row); + if (colMap.containsKey(col)) { + cell = colMap.get(col); + } + } + if (cell == null) { + continue; + } + if (col.getFreeze()) { + freezeColumnList.add(j + 1); + } + cell.setReference(new CellReference(i, j)); + UniverSheetCellData sheetCellData = JsonUtil.getJsonToBean(cell.getCellData(), + UniverSheetCellData.class); + // 获取函数格子 + String cellName = cell.getName(); + if (functionMap.get(cellName) != null) { + Map data = cellFunctionMap.get(i) != null ? cellFunctionMap.get(i) : new HashMap<>(); + data.put(j, cell); + cellFunctionMap.put(i, data); + } + + // 合并格子 + int startRow = i; + int endRow = i + (cell.getRowSpan() > 0 ? cell.getRowSpan() - 1 : cell.getRowSpan()); + int startCol = j; + int endCol = j + (cell.getColSpan() > 0 ? cell.getColSpan() - 1 : cell.getColSpan()); + int rowSpan = cell.getRowSpan(); + int colSpan = cell.getColSpan(); + StyleModel styleModel = cell.getStyleModel(); + if (colSpan > 0 || rowSpan > 0) { + // 左、右边框 + boolean isL = ObjectUtil.isNotEmpty(styleModel.getL()); + boolean isR = ObjectUtil.isNotEmpty(styleModel.getR()); + for (int rowCount = startRow; rowCount <= endRow; rowCount++) { + Map dataMap = cellData.get(rowCount) != null + ? cellData.get(rowCount) + : new HashMap<>(); + UniverSheetCellData startData = dataMap.get(startCol) != null ? dataMap.get(startCol) + : new UniverSheetCellData(); + startData.setS(isL ? styleModel.getL() : sheetCellData.getS()); + dataMap.put(startCol, startData); + + UniverSheetCellData endData = dataMap.get(endCol) != null ? dataMap.get(endCol) + : new UniverSheetCellData(); + endData.setS(isR ? styleModel.getR() : sheetCellData.getS()); + dataMap.put(endCol, endData); + + cellData.put(rowCount, dataMap); + } + + // 上、下边框 + boolean isT = ObjectUtil.isNotEmpty(styleModel.getT()); + boolean isB = ObjectUtil.isNotEmpty(styleModel.getB()); + for (int columnCount = startCol; columnCount <= endCol; columnCount++) { + Map startDataMap = cellData.get(startRow) != null + ? cellData.get(startRow) + : new HashMap<>(); + UniverSheetCellData startData = startDataMap.get(columnCount) != null + ? startDataMap.get(columnCount) + : new UniverSheetCellData(); + startData.setS(isT ? styleModel.getT() : sheetCellData.getS()); + startDataMap.put(columnCount, startData); + cellData.put(startRow, startDataMap); + + Map endDataMap = cellData.get(endRow) != null + ? cellData.get(endRow) + : new HashMap<>(); + UniverSheetCellData endData = endDataMap.get(columnCount) != null ? endDataMap.get(columnCount) + : new UniverSheetCellData(); + endData.setS(isB ? styleModel.getB() : sheetCellData.getS()); + endDataMap.put(columnCount, endData); + cellData.put(endRow, endDataMap); + } + + // 角样式 + boolean isLT = ObjectUtil.isNotEmpty(styleModel.getLt()); + boolean isRT = ObjectUtil.isNotEmpty(styleModel.getRt()); + Map startDataMap = cellData.get(startRow) != null + ? cellData.get(startRow) + : new HashMap<>(); + UniverSheetCellData leftTopData = startDataMap.get(startCol) != null ? startDataMap.get(startCol) + : new UniverSheetCellData(); + leftTopData.setS(isLT ? styleModel.getLt() : sheetCellData.getS()); + startDataMap.put(startCol, leftTopData); + UniverSheetCellData rightTopData = startDataMap.get(endCol) != null ? startDataMap.get(endCol) + : new UniverSheetCellData(); + rightTopData.setS(isRT ? styleModel.getRt() : sheetCellData.getS()); + startDataMap.put(endCol, rightTopData); + cellData.put(startRow, startDataMap); + + boolean isLB = ObjectUtil.isNotEmpty(styleModel.getLb()); + boolean isRB = ObjectUtil.isNotEmpty(styleModel.getRb()); + Map endDataMap = cellData.get(endRow) != null ? cellData.get(endRow) + : new HashMap<>(); + UniverSheetCellData leftBottomData = endDataMap.get(startCol) != null ? endDataMap.get(startCol) + : new UniverSheetCellData(); + leftBottomData.setS(isLB ? styleModel.getLb() : sheetCellData.getS()); + endDataMap.put(startCol, leftBottomData); + UniverSheetCellData rightBottomData = endDataMap.get(endCol) != null ? endDataMap.get(endCol) + : new UniverSheetCellData(); + rightBottomData.setS(isRB ? styleModel.getRb() : sheetCellData.getS()); + endDataMap.put(endCol, rightBottomData); + cellData.put(endRow, endDataMap); + + boolean notRange = mergeData.stream() + .filter(t -> t.getStartRow() <= startRow && t.getStartColumn() <= startCol + && t.getEndRow() >= startRow && t.getEndColumn() >= startCol) + .count() > 0; + if (!notRange) { + UniverSheetRange range = new UniverSheetRange(); + range.setStartRow(startRow); + range.setEndRow(endRow); + range.setStartColumn(startCol); + range.setEndColumn(endCol); + mergeData.add(range); + } + } + // 赋值 + Object sheetData = cell.getData(); + Integer dataType = 1; + try { + new BigDecimal(String.valueOf(sheetData)); + dataType = 2; + } catch (Exception e) { + } + if (sheetData instanceof Boolean) { + dataType = 3; + } + if (ObjectUtil.isNotEmpty(sheetCellData.getF())) { + dataType = 4; + } + sheetCellData.setT(dataType); + sheetCellData.setV(sheetData); + columnData.put(j, col.getSheetColumnData()); + Map cellDataMap = cellData.get(i) != null ? cellData.get(i) + : new HashMap<>(); + cellDataMap.put(j, sheetCellData); + cellData.put(i, cellDataMap); + } + } + // 修改函数 + List rowList = new ArrayList<>(cellFunctionMap.keySet()).stream().sorted(Comparator.naturalOrder()) + .collect(Collectors.toList()); + for (Integer row : rowList) { + Map rowMap = cellFunctionMap.get(row) != null ? cellFunctionMap.get(row) : new HashMap<>(); + List colList = new ArrayList<>(rowMap.keySet()).stream().sorted(Comparator.naturalOrder()) + .collect(Collectors.toList()); + for (Integer col : colList) { + Cell cell = rowMap.get(col); + Functions model = functionMap.get(cell.getName()); + if (model != null) { + model.setRowNumber(row); + model.setColNumber(col); + functionList(cell, model, report); + // 赋值 + UniverSheetCellData data = JsonUtil.getJsonToBean(cell.getCellData(), UniverSheetCellData.class); + data.setT(4); + Map cellDataMap = cellData.get(row) != null ? cellData.get(row) + : new HashMap<>(); + cellDataMap.put(col, data); + cellData.put(row, cellDataMap); + } + } + } + // 赋值数据 + result.setCellData(cellData); + result.setMergeData(mergeData); + result.setRowData(rowData); + result.setColumnData(columnData); + List rowMax = new ArrayList<>(); + rowMax.add(sheet.getRowCount()); + rowMax.add(rows.size()); + result.setRowCount(Collections.max(rowMax)); + List columnMax = new ArrayList<>(); + columnMax.add(sheet.getColumnCount()); + columnMax.add(columns.size()); + result.setColumnCount(Collections.max(columnMax)); + + // 赋值冻结数据 + UniverSheetFreeze freeze = new UniverSheetFreeze(); + freeze.setStartRow(Collections.max(freezeRowList)); + freeze.setStartColumn(Collections.max(freezeColumnList)); + freeze.setYSplit(freeze.getStartRow() > -1 ? freeze.getStartRow() : 0); + freeze.setXSplit(freeze.getStartColumn() > -1 ? freeze.getStartColumn() : 0); + result.setFreeze(freeze); + return result; + } + + private void functionList(Cell cell, Functions model, Report report) { + String function = new String(model.getFunction()); + Map> cellsMap = report.getCellsMap(); + int endRow = model.getRowNumber(); + int endCol = model.getColNumber(); + Map> functionName = new LinkedHashMap<>(); + for (String name : model.getFunctionName()) { + Map> leftTop = model.getLeftTop(); + Map> leftBottom = model.getLeftBottom(); + Map> rightTop = model.getRightTop(); + Map> rightBottom = model.getRightBottom(); + List leftTopListAll = leftTop.get(name) != null ? leftTop.get(name) : new ArrayList<>(); + List leftBottomListAll = leftBottom.get(name) != null ? leftBottom.get(name) : new ArrayList<>(); + List rightTopListAll = rightTop.get(name) != null ? rightTop.get(name) : new ArrayList<>(); + List rightBottomListAll = rightBottom.get(name) != null ? rightBottom.get(name) : new ArrayList<>(); + List leftTopList = new ArrayList<>(); + List leftBottomList = new ArrayList<>(); + List rightTopList = new ArrayList<>(); + List rightBottomList = new ArrayList<>(); + List cellList = cellsMap.get(name) != null ? cellsMap.get(name) : new ArrayList<>(); + for (Cell functionCell : cellList) { + int rowSpan = cell.getRowSpan(); + int colSpan = cell.getColSpan(); + CellReference reference = functionCell.getReference(); + if (functionCell.getReference() != null) { + int functionRow = reference.getRow(); + int functionCol = reference.getCol(); + int functionRowSpan = functionCell.getRowSpan(); + int functionColSpan = functionCell.getColSpan(); + String format = reference.formatAsString(); + // 左上角 + if (endRow >= functionRow && endCol >= functionCol) { + if (!leftTopListAll.contains(format)) { + leftTopList.add(format); + } else if (rowSpan > 0 && functionRow <= endRow && endRow <= functionRow + rowSpan - 1) { + leftTopList.add(format); + } else if (colSpan > 0 && functionCol <= endCol && endCol <= functionCol + colSpan - 1) { + leftTopList.add(format); + } else { + if (functionRowSpan > 0 && functionRow <= endRow + && endRow <= functionRow + functionRowSpan - 1) { + leftTopList.add(format); + } else if (functionColSpan > 0 && functionCol <= endCol + && endCol <= functionCol + functionColSpan - 1) { + leftTopList.add(format); + } + } + } + // 左下角 + if (endRow < functionRow && endCol >= functionCol) { + if (!leftBottomListAll.contains(format)) { + leftBottomList.add(format); + } + } + // 右上角 + if (endRow > functionRow) { + if (!rightTopListAll.contains(format)) { + rightTopList.add(format); + } + } + // 右下角 + if (endRow < functionRow || (endRow == functionRow && endCol >= functionCol)) { + if (!rightBottomListAll.contains(format)) { + rightBottomList.add(format); + } + } + } + } + List nameList = functionName.get(name) != null ? functionName.get(name) : new ArrayList<>(); + if (leftTopList.size() > 0) { + leftTopListAll.addAll(leftTopList); + nameList.addAll(leftTopList); + leftTop.put(name, leftTopListAll); + } else if (rightTopList.size() > 0) { + rightTopListAll.addAll(rightTopList); + nameList.addAll(rightTopList); + rightTop.put(name, rightTopListAll); + } else if (leftBottomList.size() > 0) { + leftBottomListAll.addAll(leftBottomList); + nameList.addAll(leftBottomList); + leftBottom.put(name, leftBottomListAll); + } else if (rightBottomList.size() > 0) { + rightBottomListAll.addAll(rightBottomList); + nameList.addAll(rightBottomList); + rightBottom.put(name, rightBottomListAll); + } else { + if (cellList.size() == 1) { + nameList.add(cellList.get(0).getReference().formatAsString()); + } + } + if (nameList.size() > 0) { + functionName.put(name, nameList); + } + } + if (!functionName.isEmpty()) { + for (String name : functionName.keySet()) { + List functionNameList = functionName.get(name); + if (functionNameList.size() > 255) { + function = function.replaceAll(name, + functionNameList.get(0) + ":" + functionNameList.get(functionNameList.size() - 1)); + } else { + function = function.replaceAll(name, String.join(",", functionNameList)); + } + } + cell.getCellData().setF(function); + } + } + + private void rebuild(ReportDefinition report) { + List cells = report.getCells(); + Map cellsMap = new HashMap<>(); + Map cellsRowColMap = new HashMap<>(); + for (CellDefinition cell : cells) { + cellsMap.put(cell.getName(), cell); + int rowNum = cell.getRowNumber(); + int colNum = cell.getColumnNumber(); + int rowSpan = cell.getRowSpan() > 0 ? cell.getRowSpan() : 1; + int colSpan = cell.getColSpan() > 0 ? cell.getColSpan() : 1; + int rowStart = rowNum; + int rowEnd = rowNum + rowSpan; + int colStart = colNum; + int colEnd = colNum + colSpan; + for (int i = rowStart; i < rowEnd; i++) { + cellsRowColMap.put(i + "," + colNum, cell); + } + for (int i = colStart; i < colEnd; i++) { + cellsRowColMap.put(rowNum + "," + i, cell); + } + } + for (CellDefinition cell : cells) { + int rowNumber = cell.getRowNumber(); + int colNumber = cell.getColumnNumber(); + Value value = cell.getValue(); + boolean isData = value instanceof DatasetValue; + + String leftType = cell.getLeftType(); + String leftParentCellName = cell.getLeftParentCellName(); + CellDefinition leftTargetCell = cellsMap.get(leftParentCellName); + if (leftTargetCell == null) { + if (colNumber > 1) { + leftTargetCell = cellsRowColMap.get(rowNumber + "," + (colNumber - 1)); + if (isData) { + boolean leftData = false; + for (int i = colNumber; i > 0; i--) { + CellDefinition definition = cellsRowColMap.get(rowNumber + "," + (i - 1)); + if (definition != null) { + Value definitionValue = definition.getValue(); + if (definitionValue instanceof DatasetValue) { + leftTargetCell = definition; + leftData = true; + break; + } + } + } + if (!leftData && Objects.equals("root", leftParentCellName)) { + leftTargetCell = null; + } + } + } + } + cell.setLeftParentCell(leftTargetCell); + + String topType = cell.getTopType(); + String topParentCellName = cell.getTopParentCellName(); + CellDefinition topTargetCell = cellsMap.get(topParentCellName); + if (topTargetCell == null) { + if (rowNumber > 1) { + topTargetCell = cellsRowColMap.get((rowNumber - 1) + "," + colNumber); + if (isData) { + boolean topData = false; + for (int i = rowNumber; i > 0; i--) { + CellDefinition definition = cellsRowColMap.get((i - 1) + "," + colNumber); + if (definition != null) { + Value definitionValue = definition.getValue(); + if (definitionValue instanceof DatasetValue) { + topTargetCell = definition; + topData = true; + break; + } + } + } + if (!topData && Objects.equals("root", topParentCellName)) { + topTargetCell = null; + } + } + } + } + cell.setTopParentCell(topTargetCell); + + if (isData) { + DatasetValue datasetValue = (DatasetValue) value; + AggregateType aggregate = datasetValue.getAggregate(); + List aggregateType = ImmutableList.of(AggregateType.select, AggregateType.group); + if (Objects.equals(topType, UniverDataEnum.cellNone.getName()) + && Objects.equals(leftType, UniverDataEnum.cellNone.getName())) { + if (!aggregateType.contains(aggregate)) { + cell.setTopParentCell(null); + cell.setLeftParentCell(null); + } + } + } + } + } + + // 赋值左、上父格 + private void rebuildReportDefinition(ReportDefinition reportDefinition) { + List cells = reportDefinition.getCells(); + for (CellDefinition cell : cells) { + List rowName = new ArrayList<>(); + addRowChildCell(cell, cell, rowName); + Set row = new HashSet<>(rowName); + List columnName = new ArrayList<>(); + addColumnChildCell(cell, cell, columnName); + Set column = new HashSet<>(columnName); + if (row.size() < rowName.size() || column.size() < columnName.size()) { + throw new DataException(MsgCode.FA106.get()); + } + } + for (CellDefinition cell : cells) { + Expand expand = cell.getExpand(); + switch (expand) { + case Down: + DownCellbuilder downCellbuilder = new DownCellbuilder(); + downCellbuilder.buildParentCell(cell, cells); + break; + case Right: + RightCellbuilder rightCellbuilder = new RightCellbuilder(); + rightCellbuilder.buildParentCell(cell, cells); + break; + case None: + // 无扩展,不做处理 + break; + } + } + } + + // 添加上父格 + private static void addRowChildCell(CellDefinition cell, CellDefinition childCell, List rowName) { + CellDefinition leftCell = cell.getLeftParentCell(); + if (leftCell == null) { + return; + } + if (rowName.contains(leftCell.getName())) { + rowName.add(leftCell.getName()); + return; + } + rowName.add(leftCell.getName()); + List childrenCells = leftCell.getRowChildrenCells(); + childrenCells.add(childCell); + addRowChildCell(leftCell, childCell, rowName); + } + + // 添加左父格 + private static void addColumnChildCell(CellDefinition cell, CellDefinition childCell, List columnName) { + CellDefinition topCell = cell.getTopParentCell(); + if (topCell == null) { + return; + } + if (columnName.contains(topCell.getName())) { + columnName.add(topCell.getName()); + return; + } + columnName.add(topCell.getName()); + List childrenCells = topCell.getColumnChildrenCells(); + childrenCells.add(childCell); + addColumnChildCell(topCell, childCell, columnName); + } + + // 解析函数,获取所在的格子 + private static void functionName(String functionText, List list) { + Stack stack = new Stack<>(); + List result = new ArrayList<>(); + for (int i = 0; i < functionText.length(); i++) { + char c = functionText.charAt(i); + if (c == '(') { + stack.push(i); + } else if (c == ')') { + if (!stack.isEmpty()) { + int start = stack.pop(); + result.add(functionText.substring(start + 1, i)); + } + } + } + List splitList = ImmutableList.of(",", "="); + for (String range : result) { + for (String split : splitList) { + String[] name = range.split(split); + for (String cell : name) { + try { + CellRangeAddress cellRange = CellRangeAddress.valueOf(cell); + if (!list.contains(cellRange)) { + list.add(cellRange); + } + } catch (Exception e) { + } + } + } + } + } + + // 函数区间的格子 + private static List getCellsRange(int startRow, int endRow, int startCol, int endCol) { + int rangeStartRow = startRow; + int rangeStartCol = startCol; + int rangeEndRow = endRow; + int rangeEndCol = endCol; + if (startRow > endRow || startCol > endCol) { + rangeStartRow = endRow; + rangeStartCol = endCol; + rangeEndRow = startRow; + rangeEndCol = startCol; + } + List referenceList = new ArrayList<>(); + if (rangeStartRow >= 0) { + for (int rowNum = rangeStartRow; rowNum <= rangeEndRow; rowNum++) { + for (int colNum = rangeStartCol; colNum <= rangeEndCol; colNum++) { + CellReference reference = new CellReference(rowNum, colNum); + referenceList.add(reference); + } + } + } + return referenceList; + } + + private static void resource(String sheet, Report report, List resources) { + Map> cellsMap = report.getCellsMap(); + // 条件 + format(sheet, cellsMap, resources); + // 数据验证 + dataValidation(sheet, cellsMap, resources); + // 筛选器 + filter(sheet, cellsMap, resources); + } + + // 调整数据格式、数据管理的所在格子 + private static List resourceRange(Map> cellsMap, + List sheetRanges) { + List rangeList = new ArrayList<>(); + for (UniverSheetRange sheetRange : sheetRanges) { + int startRow = sheetRange.getStartRow(); + int endRow = sheetRange.getEndRow(); + int startCol = sheetRange.getStartColumn(); + int endCol = sheetRange.getEndColumn(); + List cellReferenceList = getCellsRange(startRow, endRow, startCol, endCol); + for (CellReference cellReference : cellReferenceList) { + List cellList = cellsMap.get(cellReference.formatAsString()) != null + ? cellsMap.get(cellReference.formatAsString()) + : new ArrayList<>(); + for (Cell cell : cellList) { + CellReference reference = cell.getReference(); + if (reference != null) { + UniverSheetRange range = JsonUtil.getJsonToBean(sheetRange, UniverSheetRange.class); + range.setStartRow(reference.getRow()); + range.setStartColumn((int) reference.getCol()); + range.setEndRow(range.getStartRow()); + range.setEndColumn(range.getStartColumn()); + rangeList.add(range); + } + } + } + } + return rangeList.isEmpty() ? sheetRanges : rangeList; + } + + // 处理图表数据 + private static Map> drawing(List resources, + Map floatEcharts) { + UniverResource drawing = resources.stream() + .filter(t -> ResourceEnum.SHEET_DRAWING_PLUGIN.name().equals(t.getName())).findFirst().orElse(null); + Map> echartMap = new HashMap<>(); + if (ObjectUtil.isNotEmpty(drawing) && ObjectUtil.isNotEmpty(drawing.getData())) { + Map data = JsonUtil.stringToMap(drawing.getData()); + data.forEach((key, value) -> { + UniverResourceData jsonToBean = JsonUtil.getJsonToBean(value, UniverResourceData.class); + Map drawingMap = jsonToBean.getData() != null ? jsonToBean.getData() + : new HashMap<>(); + for (String id : drawingMap.keySet()) { + UniverDataConfig univerDataConfig = floatEcharts.get(id); + UniverDrawing univerDrawing = drawingMap.get(id); + if (univerDataConfig != null && univerDrawing != null) { + univerDataConfig.setDrawingId(univerDrawing.getDrawingId()); + univerDataConfig.setUnitId(univerDrawing.getUnitId()); + univerDataConfig.setSubUnitId(univerDrawing.getSubUnitId()); + List echartList = echartMap.get(key) != null ? echartMap.get(key) + : new ArrayList<>(); + echartList.add(univerDataConfig); + echartMap.put(key, echartList); + } + } + }); + } + return echartMap; + } + + // 解析数据格式 + private static void format(String sheet, Map> cellsMap, List resources) { + UniverResource formatting = resources.stream() + .filter(t -> ResourceEnum.SHEET_CONDITIONAL_FORMATTING_PLUGIN.name().equals(t.getName())).findFirst() + .orElse(null); + Map> foramtMap = new HashMap<>(); + if (formatting != null && ObjectUtil.isNotEmpty(formatting.getData())) { + Map data = JsonUtil.stringToMap(formatting.getData()); + data.forEach((key, value) -> { + foramtMap.put(key, JsonUtil.getJsonToList(value, UniverResourceData.class)); + }); + if (foramtMap.get(sheet) != null) { + List dataList = foramtMap.get(sheet); + for (UniverResourceData resourceData : dataList) { + List sheetRanges = resourceData.getRanges(); + List rangesList = resourceRange(cellsMap, sheetRanges); + resourceData.setRanges(rangesList); + } + } + formatting.setData(JSON.toJSONString(JSON.toJSON(foramtMap))); + } + } + + // 解析数据验证 + private static void dataValidation(String sheet, Map> cellsMap, List resources) { + UniverResource validation = resources.stream() + .filter(t -> ResourceEnum.SHEET_DATA_VALIDATION_PLUGIN.name().equals(t.getName())).findFirst() + .orElse(null); + Map> validationMap = new HashMap<>(); + if (validation != null && ObjectUtil.isNotEmpty(validation.getData())) { + Map data = JsonUtil.stringToMap(validation.getData()); + data.forEach((key, value) -> { + validationMap.put(key, JsonUtil.getJsonToList(value, UniverResourceData.class)); + }); + if (validationMap.get(sheet) != null) { + List dataList = validationMap.get(sheet); + for (UniverResourceData resourceData : dataList) { + List sheetRanges = resourceData.getRanges(); + List rangesList = resourceRange(cellsMap, sheetRanges); + resourceData.setRanges(rangesList); + } + } + validation.setData(JSON.toJSONString(JSON.toJSON(validationMap))); + } + } + + private static void filter(String sheet, Map> cellsMap, List resources) { + UniverResource filter = resources.stream() + .filter(t -> ResourceEnum.SHEET_FILTER_PLUGIN.name().equals(t.getName())).findFirst().orElse(null); + Map filterMap = new HashMap<>(); + if (filter != null && ObjectUtil.isNotEmpty(filter.getData())) { + Map data = JsonUtil.stringToMap(filter.getData()); + data.forEach((key, value) -> { + filterMap.put(key, JsonUtil.getJsonToBean(value, UniverResourceData.class)); + }); + if (filterMap.get(sheet) != null) { + UniverResourceData resourceData = filterMap.get(sheet); + if (resourceData != null) { + UniverSheetRange sheetRange = resourceData.getRef(); + if (sheetRange != null) { + List rangesList = resourceRange(cellsMap, ImmutableList.of(sheetRange)); + Map> rangesMap = rangesList.stream() + .collect(Collectors.groupingBy(UniverSheetRange::getStartRow)); + int startRow = Collections.min(rangesMap.keySet()); + int startCol = Collections.min(rangesMap.get(startRow).stream() + .map(UniverSheetRange::getStartColumn).collect(Collectors.toList())); + int endRow = Collections.max(rangesMap.keySet()); + int endCol = Collections.max(rangesMap.get(endRow).stream().map(UniverSheetRange::getEndColumn) + .collect(Collectors.toList())); + UniverSheetRange range = JsonUtil.getJsonToBean(sheetRange, UniverSheetRange.class); + range.setStartRow(startRow); + range.setStartColumn(startCol); + range.setEndRow(endRow); + range.setEndColumn(endCol); + resourceData.setRef(range); + } + } + filter.setData(JSON.toJSONString(JSON.toJSON(filterMap))); + } + } + } +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverExcel.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverExcel.java new file mode 100644 index 0000000..37658f1 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/UniverExcel.java @@ -0,0 +1,949 @@ +package com.yunzhupaas.util; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.Method; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.io.Files; +import com.yunzhupaas.constant.MsgCode; +import com.yunzhupaas.enums.*; +import com.yunzhupaas.exception.DataException; +import com.yunzhupaas.univer.chart.UniverChartModel; +import com.yunzhupaas.univer.data.resource.*; +import com.yunzhupaas.univer.model.UniverWorkBook; +import com.yunzhupaas.univer.properties.UniverProperties; +import com.yunzhupaas.univer.resources.UniverResource; +import com.yunzhupaas.univer.resources.UniverResourceData; +import com.yunzhupaas.univer.sheet.*; +import com.yunzhupaas.univer.style.UniverStyle; +import com.yunzhupaas.univer.style.UniverStyleBorder; +import com.yunzhupaas.univer.style.UniverStyleTextDecoration; +import com.yunzhupaas.univer.style.UniverStyleTextRotation; +import com.yunzhupaas.util.excel.ExcelParser; +import com.yunzhupaas.util.excel.UniverHSSFExcel; +import com.yunzhupaas.util.excel.UniverXSSFExcel; +import com.yunzhupaas.util.type.RequestType; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.xssf.model.StylesTable; +import org.apache.poi.xssf.usermodel.*; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; +import org.springframework.web.multipart.MultipartFile; + +import java.awt.Color; +import java.io.IOException; +import java.util.List; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/29 下午5:17 + */ +@Slf4j +public class UniverExcel { + + private static Map excelMap = ImmutableMap.of( + "xlsx", new UniverXSSFExcel(), + "xls", new UniverHSSFExcel()); + + public static UniverWorkBook formFile(MultipartFile file) throws IOException { + // todo 推荐使用 xlsx 方法 + @SuppressWarnings("null") + String fileName = file.getOriginalFilename(); + if (fileName == null) { + throw new DataException("文件名不能为空"); + } + String type = Files.getFileExtension(fileName); + ExcelParser excelParser = excelMap.get(type); + if (excelParser == null) { + throw new DataException(MsgCode.ETD110.get()); + } + UniverWorkBook univerWorkBook = excelParser.formFile(file.getInputStream()); + return univerWorkBook; + } + + public static void downExcel(String snapshot, List chartList, XSSFWorkbook workbook, + List sheetList) { + Map styleMap = new HashMap<>(); + UniverWorkBook univerWorkBook = JsonUtil.getJsonToBean(snapshot, UniverWorkBook.class); + List resources = univerWorkBook.getResources() != null ? univerWorkBook.getResources() + : new ArrayList<>(); + for (String sheetOrder : univerWorkBook.getSheetOrder()) { + UniverSheet univerSheet = univerWorkBook.getSheets().get(sheetOrder); + if (ObjectUtil.isNotEmpty(univerSheet)) { + if (!sheetList.contains(sheetOrder)) { + continue; + } + XSSFSheet sheet = workbook.createSheet(univerSheet.getName()); + workbook.setSheetHidden(workbook.getSheetIndex(sheet), Objects.equals(univerSheet.getHidden(), 1)); + Map rowData = univerSheet.getRowData(); + Map colData = univerSheet.getColumnData(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + // 冻结位置 + UniverSheetFreeze freeze = univerSheet.getFreeze() != null ? univerSheet.getFreeze() + : new UniverSheetFreeze(); + sheet.createFreezePane(freeze.getStartColumn(), freeze.getStartRow()); + + // 遍历数据 + univerSheet.getCellData().forEach((rowKey, sheetRow) -> { + XSSFRow row = sheet.createRow(rowKey); + UniverSheetRowData sheetRowData = rowData.get(rowKey); + if (ObjectUtil.isNotEmpty(sheetRowData)) { + row.setZeroHeight(Objects.equals(sheetRowData.getHd(), 1)); + if (ObjectUtil.isNotEmpty(sheetRowData.getH())) { + row.setHeightInPoints(sheetRowData.getH()); + } + } + sheetRow.forEach((colKey, sheetCol) -> { + UniverSheetRange range = univerSheet.getMergeData().stream() + .filter(t -> Objects.equals(t.getStartRow(), rowKey) + && Objects.equals(t.getStartColumn(), colKey)) + .findFirst().orElse(null); + Object value = sheetCol.getV(); + Object formula = sheetCol.getF(); + Object style = sheetCol.getS(); + XSSFCell cell = row.createCell(colKey); + UniverSheetColumnData columnData = colData.get(colKey); + if (ObjectUtil.isNotEmpty(columnData)) { + if (ObjectUtil.isNotEmpty(columnData.getW())) { + sheet.setColumnWidth(colKey, (short) (columnData.getW() * 1.33 * 35)); + } + sheet.setColumnHidden(colKey, Objects.equals(columnData.getHd(), 1)); + } + if (ObjectUtil.isNotEmpty(sheetCol.getP())) { + UniverProperties properties = JsonUtil.getJsonToBean(sheetCol.getP(), + UniverProperties.class); + if (properties.getBody() != null) { + cell.setCellType(CellType.STRING); + cell.setCellValue(properties.getBody().getDataStream()); + } + } + if (ObjectUtil.isNotEmpty(value) && ObjectUtil.isEmpty(formula)) { + if (Objects.equals(sheetCol.getT(), 2)) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(Double.valueOf(value.toString())); + } else if (Objects.equals(sheetCol.getT(), 3)) { + cell.setCellType(CellType.BOOLEAN); + cell.setCellValue(Boolean.valueOf(value.toString())); + } else { + cell.setCellType(CellType.STRING); + cell.setCellValue(value.toString()); + } + } + if (ObjectUtil.isNotEmpty(formula)) { + try { + cell.setCellFormula(formula.toString().substring(1)); + } catch (Exception e) { + cell.setCellType(CellType.STRING); + cell.setCellValue(formula.toString()); + } + } + if (ObjectUtil.isNotEmpty(style)) { + UniverStyle basicStyle = univerWorkBook.getStyles().get(style); + if (ObjectUtil.isNotEmpty(basicStyle)) { + UniverStyleBorder bd = basicStyle.getBd(); + if (ObjectUtil.isNotEmpty(styleMap.get(basicStyle))) { + bdAnchor(bd, rowKey, colKey, range, drawing); + cell.setCellStyle(styleMap.get(basicStyle)); + } else { + XSSFCellStyle cellStyle = workbook.createCellStyle(); + if (ObjectUtil.isNotEmpty(basicStyle.getBg()) + && ObjectUtil.isNotEmpty(basicStyle.getBg().getRgb())) { + String bgGrb = basicStyle.getBg().getRgb(); + XSSFColor color = color(bgGrb); + if (color != null) { + cellStyle.setFillForegroundColor(color); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + } + if (ObjectUtil.isNotEmpty(bd)) { + if (ObjectUtil.isNotEmpty(bd.getT()) + && ObjectUtil.isNotEmpty(bd.getT().getCl())) { + String bdt = bd.getT().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdt)) { + XSSFColor color = color(bdt); + if (color != null) { + cellStyle.setTopBorderColor(color); + } + } + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getT().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + cellStyle.setBorderTop(bdStyle.getBorderStyle()); + } + } + if (ObjectUtil.isNotEmpty(bd.getL()) + && ObjectUtil.isNotEmpty(bd.getL().getCl())) { + String bdl = bd.getL().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdl)) { + XSSFColor color = color(bdl); + if (color != null) { + cellStyle.setLeftBorderColor(color); + } + } + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getL().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + cellStyle.setBorderLeft(bdStyle.getBorderStyle()); + } + } + if (ObjectUtil.isNotEmpty(bd.getB()) + && ObjectUtil.isNotEmpty(bd.getB().getCl())) { + String bdb = bd.getB().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdb)) { + XSSFColor color = color(bdb); + if (color != null) { + cellStyle.setBottomBorderColor(color); + } + } + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getB().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + cellStyle.setBorderBottom(bdStyle.getBorderStyle()); + } + } + if (ObjectUtil.isNotEmpty(bd.getR()) + && ObjectUtil.isNotEmpty(bd.getR().getCl())) { + String bdr = bd.getR().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + cellStyle.setRightBorderColor(color); + } + } + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getR().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + cellStyle.setBorderRight(bdStyle.getBorderStyle()); + } + } + bdAnchor(bd, rowKey, colKey, range, drawing); + } + HorizontalAlignment alignment = ObjectUtil.isNotEmpty(basicStyle.getHt()) + ? HorizontalEnum.getHorizontalValue(basicStyle.getHt()) + : null; + if (ObjectUtil.isNotEmpty(alignment)) { + cellStyle.setAlignment(alignment); + } + VerticalAlignment verticalValue = ObjectUtil.isNotEmpty(basicStyle.getVt()) + ? VerticalEnum.getVerticalValue(basicStyle.getVt()) + : null; + if (ObjectUtil.isNotEmpty(verticalValue)) { + cellStyle.setVerticalAlignment(verticalValue); + } + if (ObjectUtil.isNotEmpty(basicStyle.getN()) + && ObjectUtil.isNotEmpty(basicStyle.getN().getPattern())) { + DataFormat format = workbook.createDataFormat(); + cellStyle.setDataFormat(format.getFormat(basicStyle.getN().getPattern())); + } + if (ObjectUtil.isNotEmpty(basicStyle.getTb()) + && Objects.equals(basicStyle.getTb(), 3)) { + cellStyle.setWrapText(true); + } + if (ObjectUtil.isNotEmpty(basicStyle.getTr())) { + UniverStyleTextRotation tr = basicStyle.getTr(); + int v = tr.getV(); + int rotation = tr.getA(); + if (Objects.equals(v, 1)) { + rotation = -255; + } + cellStyle.setRotation((short) -rotation); + } + XSSFFont font = workbook.createFont(); + if (ObjectUtil.isNotEmpty(basicStyle.getFf())) { + font.setFontName(basicStyle.getFf()); + } + if (ObjectUtil.isNotEmpty(basicStyle.getFs())) { + font.setFontHeight(basicStyle.getFs()); + } + if (ObjectUtil.isNotEmpty(basicStyle.getIt())) { + font.setItalic(Objects.equals(basicStyle.getIt(), 1)); + } + if (ObjectUtil.isNotEmpty(basicStyle.getBl())) { + font.setBold(Objects.equals(basicStyle.getBl(), 1)); + } + if (ObjectUtil.isNotEmpty(basicStyle.getCl()) + && ObjectUtil.isNotEmpty(basicStyle.getCl().getRgb())) { + XSSFColor color = color(basicStyle.getCl().getRgb()); + if (color != null) { + font.setColor(color); + } + } + if (ObjectUtil.isNotEmpty(basicStyle.getUl()) + && ObjectUtil.isNotEmpty(basicStyle.getUl().getS())) { + font.setUnderline(Objects.equals(basicStyle.getUl().getS(), 1) ? Font.U_SINGLE + : Font.U_NONE); + } + if (ObjectUtil.isNotEmpty(basicStyle.getSt()) + && ObjectUtil.isNotEmpty(basicStyle.getSt().getS())) { + font.setStrikeout(Objects.equals(basicStyle.getSt().getS(), 1)); + } + cellStyle.setFont(font); + cell.setCellStyle(cellStyle); + styleMap.put(basicStyle, cellStyle); + } + } + } + }); + }); + // 合并单元格 + for (UniverSheetRange region : new HashSet<>(univerSheet.getMergeData())) { + sheet.addMergedRegion(new CellRangeAddress(region.getStartRow(), region.getEndRow(), + region.getStartColumn(), region.getEndColumn())); + } + // 图片 + drawing(sheetOrder, resources, chartList, drawing, workbook); + // 条件 + format(sheetOrder, resources, sheet); + // 数据管理 + dataValidation(sheetOrder, resources, sheet); + // 筛选 + filter(sheetOrder, resources, sheet); + } + } + } + + private static void bdAnchor(UniverStyleBorder bd, int rowKey, int colKey, UniverSheetRange range, + XSSFDrawing drawing) { + if (ObjectUtil.isNotEmpty(bd)) { + if (ObjectUtil.isNotEmpty(bd.getTl_br()) && ObjectUtil.isNotEmpty(bd.getTl_br().getCl())) { + int startRow = rowKey; + int startCol = colKey; + int endRow = rowKey + 1; + int endCol = colKey + 1; + if (range != null) { + endRow = range.getEndRow() + 1; + endCol = range.getEndColumn() + 1; + } + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getTl_br().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getTl_br().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE); + } + if (ObjectUtil.isNotEmpty(bd.getTl_mr()) && ObjectUtil.isNotEmpty(bd.getTl_mr().getCl())) { + if (range != null) { + int startRow = rowKey; + int startCol = colKey; + int endRow = (rowKey + range.getEndRow() + 1) / 2; + int endCol = range.getEndColumn() + 1; + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getTl_mr().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getTl_mr().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE); + } + } + if (ObjectUtil.isNotEmpty(bd.getTl_bc()) && ObjectUtil.isNotEmpty(bd.getTl_bc().getCl())) { + if (range != null) { + int startRow = rowKey; + int startCol = colKey; + int endRow = range.getEndRow() + 1; + int endCol = (colKey + range.getEndColumn() + 1) / 2; + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getTl_bc().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getTl_bc().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE); + } + } + if (ObjectUtil.isNotEmpty(bd.getBl_tr()) && ObjectUtil.isNotEmpty(bd.getBl_tr().getCl())) { + int startRow = rowKey; + int startCol = colKey; + int endRow = rowKey + 1; + int endCol = colKey + 1; + if (range != null) { + endRow = range.getEndRow() + 1; + endCol = range.getEndColumn() + 1; + } + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getBl_tr().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getBl_tr().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE_INV); + } + if (ObjectUtil.isNotEmpty(bd.getBc_tr()) && ObjectUtil.isNotEmpty(bd.getBc_tr().getCl())) { + if (range != null) { + int startRow = rowKey; + int startCol = range.getStartColumn(); + int endRow = (rowKey + range.getEndRow() + 1) / 2; + int endCol = range.getEndColumn() + 1; + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getBc_tr().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getBc_tr().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE_INV); + } + } + if (ObjectUtil.isNotEmpty(bd.getMl_tr()) && ObjectUtil.isNotEmpty(bd.getMl_tr().getCl())) { + if (range != null) { + int startRow = rowKey; + int startCol = (colKey + range.getEndColumn() + 1) / 2; + int endRow = range.getEndRow() + 1; + int endCol = range.getEndColumn() + 1; + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(startRow); + anchor.setCol1(startCol); + anchor.setRow2(endRow); + anchor.setCol2(endCol); + XSSFSimpleShape shape = drawing.createSimpleShape(anchor); + StyleTypeEnum bdStyle = StyleTypeEnum.getStyle(bd.getMl_tr().getS()); + if (ObjectUtil.isNotEmpty(bdStyle)) { + shape.setShapeType(bdStyle.getBorderStyle().getCode()); + } + String bdr = bd.getMl_tr().getCl().getRgb(); + if (ObjectUtil.isNotEmpty(bdr)) { + XSSFColor color = color(bdr); + if (color != null) { + shape.setLineStyleColor(color.getRGB()[0], color.getRGB()[1], color.getRGB()[2]); + } + } + shape.setShapeType(ShapeTypes.LINE_INV); + } + } + } + } + + private static XSSFColor color(String rgbCole) { + byte[] rgb = null; + try { + Color color = new Color(Integer.parseInt(rgbCole.substring(1), 16)); + rgb = new byte[] { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() }; + } catch (Exception e) { + try { + rgbCole = rgbCole.replaceAll("rgb\\(", "").replaceAll("\\)", ""); + String[] split = rgbCole.split(","); + if (split.length >= 3) { + int red = Integer.parseInt(split[0]); + int green = Integer.parseInt(split[1]); + int blue = Integer.parseInt(split[2]); + rgb = new byte[] { (byte) red, (byte) green, (byte) blue }; + } + } catch (Exception e1) { + } + } + XSSFColor xssfColor = rgb == null ? null : new XSSFColor(rgb, new DefaultIndexedColorMap()); + return xssfColor; + } + + private static void drawing(String sheetOrder, List resources, List chartList, + XSSFDrawing drawing, XSSFWorkbook workbook) { + UniverResource univerResource = resources.stream() + .filter(t -> ResourceEnum.SHEET_DRAWING_PLUGIN.name().equals(t.getName())).findFirst().orElse(null); + Map drawingMap = new HashMap<>(); + if (ObjectUtil.isNotEmpty(univerResource) && ObjectUtil.isNotEmpty(univerResource.getData())) { + Map data = JsonUtil.stringToMap(univerResource.getData()); + data.forEach((key, value) -> { + drawingMap.put(key, JsonUtil.getJsonToBean(value, UniverResourceData.class)); + }); + } + // 导出图片 + UniverResourceData resourceData = drawingMap.get(sheetOrder); + if (ObjectUtil.isNotEmpty(resourceData)) { + List orderList = resourceData.getOrder(); + Map data = resourceData.getData(); + for (String order : orderList) { + try { + UniverDrawing univerDrawing = data.get(order); + if (ObjectUtil.isNotEmpty(univerDrawing)) { + String source = univerDrawing.getSource(); + String imageType = univerDrawing.getImageSourceType(); + byte[] bytes = null; + if (Objects.equals(ImageEnum.BASE64.name(), imageType)) { + String regex = "data:image/\\w+;base64,"; + String base64Img = source; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(source); + if (matcher.find()) { + base64Img = source.replace(matcher.group(), ""); + } + bytes = Base64.decode(base64Img); + } else { + if (source.startsWith(RequestType.HTTP)) { + HttpRequest request = HttpRequest.of(source).method(Method.GET); + bytes = request.execute().bodyBytes(); + } else { + String[] split = source.split("="); + String fileNameAll = DesUtil.aesDecode(split[split.length - 1]); + String[] fileData = fileNameAll.split("#"); + String fileName = fileData.length > 1 ? fileData[1] : ""; + String type = fileData.length > 2 ? fileData[2] : ""; + String typePath = FilePathUtil.getFilePath(type.toLowerCase()); + bytes = FileUploadUtils.downloadFileByte(typePath, fileName, false); + } + } + if (bytes != null && bytes.length > 0) { + UniverTransform sheetTransform = univerDrawing.getSheetTransform(); + UniverOffset from = sheetTransform.getFrom(); + UniverOffset to = sheetTransform.getTo(); + // 图片导出 + XSSFClientAnchor anchor = new XSSFClientAnchor(); + anchor.setRow1(from.getRow()); + anchor.setCol1(from.getColumn()); + + anchor.setRow2(to.getRow()); + anchor.setCol2(to.getColumn()); + + anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_DO_RESIZE); + int imageIndex = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG); + drawing.createPicture(anchor, imageIndex); + } + } + } catch (Exception e) { + log.error("图片导出失败:{}", e.getMessage()); + } + } + } + } + + private static void format(String sheetOrder, List resources, XSSFSheet sheet) { + StylesTable styles = sheet.getWorkbook().getStylesSource(); + UniverResource univerResource = resources.stream() + .filter(t -> ResourceEnum.SHEET_CONDITIONAL_FORMATTING_PLUGIN.name().equals(t.getName())).findFirst() + .orElse(null); + Map> foramtMap = new HashMap<>(); + if (ObjectUtil.isNotEmpty(univerResource) && ObjectUtil.isNotEmpty(univerResource.getData())) { + Map data = JsonUtil.stringToMap(univerResource.getData()); + data.forEach((key, value) -> { + foramtMap.put(key, JsonUtil.getJsonToList(value, UniverResourceData.class)); + }); + } + List data = foramtMap.get(sheetOrder) != null ? foramtMap.get(sheetOrder) + : new ArrayList<>(); + CTWorksheet ctWorksheet = sheet.getCTWorksheet(); + List conditionalList = new ArrayList<>(); + for (UniverResourceData resourceData : data) { + UniverRule rule = resourceData.getRule(); + Boolean stopIfTrue = resourceData.getStopIfTrue(); + List ranges = resourceData.getRanges(); + if (ObjectUtil.isNotEmpty(rule)) { + List ruleList = new ArrayList<>(); + List configList = new ArrayList<>(); + Object ruleConfig = rule.getConfig(); + if (ObjectUtil.isNotEmpty(ruleConfig)) { + if (ruleConfig instanceof List) { + configList.addAll(JsonUtil.getJsonToList(ruleConfig, UniverConfig.class)); + } else if (ruleConfig instanceof Map) { + configList.add(JsonUtil.getJsonToBean(ruleConfig, UniverConfig.class)); + } + } + List regions = new ArrayList<>(); + for (UniverSheetRange range : ranges) { + regions.add(new CellRangeAddress(range.getStartRow(), range.getEndRow(), range.getStartColumn(), + range.getEndColumn()).formatAsString()); + } + String type = rule.getType(); + String subType = rule.getSubType(); + Boolean showValue = rule.getIsShowValue(); + String operator = rule.getOperator(); + FormatTypeEnum formatTypeEnum = FormatTypeEnum.getFormat(type); + CTCfRule cfRule = CTCfRule.Factory.newInstance(); + cfRule.setStopIfTrue(stopIfTrue); + STCfType.Enum typeEnum = STCfType.Enum.forString(type); + cfRule.setType(typeEnum); + switch (formatTypeEnum) { + case colorScale: + CTColorScale scale = cfRule.addNewColorScale(); + for (UniverConfig univerConfig : configList) { + UniverValue univerValue = univerConfig.getValue(); + if (univerValue == null) { + continue; + } + String valueType = univerValue.getType(); + String value = univerValue.getValue() != null ? univerValue.getValue().toString() : ""; + if (Objects.equals(SubTypeEnum.expression.getCode(), valueType)) { + value = value.replace("=", ""); + } + CTCfvo ctCfvo = scale.addNewCfvo(); + ctCfvo.setType(STCfvoType.Enum.forString(valueType)); + ctCfvo.setVal(value); + XSSFColor color = color(univerConfig.getColor()); + if (color != null) { + CTColor ctColor = scale.addNewColor(); + ctColor.setRgb(color.getRGB()); + } + } + ruleList.add(cfRule); + break; + case iconSet: + CTIconSet icons = cfRule.addNewIconSet(); + icons.setShowValue(showValue); + for (int i = configList.size() - 1; i >= 0; i--) { + UniverConfig univerConfig = configList.get(i); + UniverValue value = univerConfig.getValue(); + if (value == null) { + continue; + } + String iconType = value.getType(); + String icon = univerConfig.getIconType(); + String valueOperator = univerConfig.getOperator(); + String iconValue = value.getValue() != null ? value.getValue().toString() : ""; + if (Objects.equals(SubTypeEnum.expression.getCode(), iconType)) { + iconValue = iconValue.replace("=", ""); + } + CTCfvo ctCfvo = icons.addNewCfvo(); + ctCfvo.setVal(iconValue); + ctCfvo.setGte(Objects.equals(valueOperator, OperatorEnum.greaterThanOrEqual.name())); + ctCfvo.setType(STCfvoType.Enum.forString(iconType)); + icons.setIconSet(STIconSetType.Enum.forString(icon)); + } + boolean reverse = configList.size() > 0 && !Objects.equals(configList.get(0).getIconId(), "0"); + icons.setReverse(reverse); + ruleList.add(cfRule); + break; + case dataBar: + CTDataBar bar = cfRule.addNewDataBar(); + bar.setShowValue(showValue); + for (UniverConfig config : configList) { + UniverValue min = config.getMin(); + UniverValue max = config.getMax(); + if (min != null && max != null) { + String minType = min.getType(); + String minValue = min.getValue() != null ? min.getValue().toString() : ""; + if (Objects.equals(SubTypeEnum.expression.getCode(), minType)) { + minValue = minValue.replace("=", ""); + } + String maxType = max.getType(); + String maxValue = max.getValue() != null ? max.getValue().toString() : ""; + if (Objects.equals(SubTypeEnum.expression.getCode(), maxType)) { + maxValue = maxValue.replace("=", ""); + } + List dataBarType = Lists.newArrayList(OperatorEnum.min.name(), + OperatorEnum.max.name()); + for (int i = 0; i < dataBarType.size(); i++) { + String barType = i == 0 ? minType : maxType; + String barValue = i == 0 ? minValue : maxValue; + CTCfvo ctCfvo = bar.addNewCfvo(); + ctCfvo.setType(STCfvoType.Enum.forString(barType)); + ctCfvo.setVal(barValue); + + XSSFColor positiveColor = color(config.getPositiveColor()); + if (positiveColor != null) { + CTColor ctColor = bar.addNewColor(); + ctColor.setRgb(positiveColor.getRGB()); + } + + XSSFColor nativeColor = color(config.getNativeColor()); + if (nativeColor != null) { + CTColor ctColor = bar.addNewColor(); + ctColor.setRgb(nativeColor.getRGB()); + } + } + } + } + ruleList.add(cfRule); + break; + default: + List cell = Lists.newArrayList(SubTypeEnum.cellIs.getCode(), + SubTypeEnum.equal.getCode(), + SubTypeEnum.notEqual.getCode()); + boolean isNumber = cell.contains(subType) || cell.contains(operator); + // 平均值 + boolean isAverage = Objects.equals(SubTypeEnum.aboveAverage.getCode(), subType); + // TOP + boolean isRank = Objects.equals(SubTypeEnum.top10.getCode(), subType); + // 公式 + boolean isFormula = Objects.equals(SubTypeEnum.expression.getCode(), subType); + // 日期 + boolean isTime = Objects.equals(SubTypeEnum.timePeriod.getCode(), subType); + String ruleType = operator; + if (isNumber) { + ruleType = SubTypeEnum.cellIs.getType(); + } else if (isAverage) { + ruleType = SubTypeEnum.aboveAverage.getType(); + } else if (isRank) { + ruleType = SubTypeEnum.top10.getType(); + } else if (isFormula) { + ruleType = SubTypeEnum.expression.getType(); + } else if (isTime) { + ruleType = SubTypeEnum.timePeriod.getType(); + } + if (StringUtil.isEmpty(ruleType)) { + ruleType = subType; + } + Object value = rule.getValue(); + String data1 = null; + String data2 = null; + String text = null; + Long rank = null; + Boolean bottom = null; + Boolean percent = null; + if (value != null) { + if (isNumber) { + if (value instanceof List) { + @SuppressWarnings("unchecked") + List valueList = (List) value; + for (int i = 0; i < valueList.size(); i++) { + Object numberValu = valueList.get(i); + if (numberValu != null) { + if (i == 0) { + data1 = valueList.get(i).toString(); + } else { + data2 = valueList.get(i).toString(); + } + } + } + } else { + data1 = value.toString(); + } + } else if (isRank) { + rank = Long.valueOf(value.toString()); + bottom = rule.getIsBottom(); + percent = rule.getIsPercent(); + } else if (isFormula) { + data1 = value.toString().replace("=", ""); + } else { + text = value.toString(); + } + } + cfRule.setType(STCfType.Enum.forString(ruleType)); + if (data1 != null) { + cfRule.addFormula(data1); + } + if (data2 != null) { + cfRule.addFormula(data2); + } + if (operator != null) { + STConditionalFormattingOperator.Enum anOperator = STConditionalFormattingOperator.Enum + .forString(operator); + if (anOperator != null) { + cfRule.setOperator(anOperator); + } + STTimePeriod.Enum timePeriod = STTimePeriod.Enum.forString(operator); + if (timePeriod != null) { + cfRule.setTimePeriod(timePeriod); + } + } + if (text != null) { + cfRule.setText(text); + } + if (rank != null) { + cfRule.setRank(rank); + } + if (bottom != null) { + cfRule.setBottom(bottom); + } + if (percent != null) { + cfRule.setPercent(percent); + } + if (isAverage) { + cfRule.setAboveAverage(Objects.equals(OperatorEnum.greaterThan.name(), operator)); + } + UniverStyle style = rule.getStyle(); + if (style != null) { + CTDxf ctDxf = CTDxf.Factory.newInstance(); + XSSFColor bgColor = color(style.getBg().getRgb() != null ? style.getBg().getRgb() : ""); + if (bgColor != null) { + CTFill ctFill = CTFill.Factory.newInstance(); + CTPatternFill patternFill = CTPatternFill.Factory.newInstance(); + patternFill.setBgColor(bgColor.getCTColor()); + ctFill.setPatternFill(patternFill); + ctDxf.setFill(ctFill); + } + + CTFont ctFont = CTFont.Factory.newInstance(); + XSSFColor fontColor = color(style.getCl().getRgb() != null ? style.getCl().getRgb() : ""); + if (fontColor != null) { + CTColor ctColor = fontColor.getCTColor(); + ctFont.setColorArray(new CTColor[] { ctColor }); + } + CTUnderlineProperty underline = CTUnderlineProperty.Factory.newInstance(); + underline.setVal(style.getUl() != null && Objects.equals(style.getUl().getS(), 1) + ? STUnderlineValues.SINGLE + : STUnderlineValues.NONE); + ctFont.setUArray(new CTUnderlineProperty[] { underline }); + + CTBooleanProperty italic = CTBooleanProperty.Factory.newInstance(); + italic.setVal(Objects.equals(style.getIt(), 1)); + ctFont.setIArray(new CTBooleanProperty[] { italic }); + + CTBooleanProperty bold = CTBooleanProperty.Factory.newInstance(); + bold.setVal(Objects.equals(style.getBl(), 1)); + ctFont.setBArray(new CTBooleanProperty[] { bold }); + + UniverStyleTextDecoration st = style.getSt(); + CTBooleanProperty strike = CTBooleanProperty.Factory.newInstance(); + strike.setVal(st != null && Objects.equals(st.getS(), 1)); + ctFont.setStrikeArray(new CTBooleanProperty[] { strike }); + ctDxf.setFont(ctFont); + int dxfId = styles.putDxf(ctDxf); + cfRule.setDxfId(dxfId - 1); + } + ruleList.add(cfRule); + break; + } + CTConditionalFormatting conditionalFormatting = ctWorksheet.addNewConditionalFormatting(); + conditionalFormatting.setCfRuleArray(ruleList.toArray(new CTCfRule[ruleList.size()])); + conditionalFormatting.setSqref(regions); + conditionalList.add(conditionalFormatting); + } + } + ctWorksheet.setConditionalFormattingArray( + conditionalList.toArray(new CTConditionalFormatting[conditionalList.size()])); + } + + private static void dataValidation(String sheetOrder, List resources, XSSFSheet sheet) { + UniverResource univerResource = resources.stream() + .filter(t -> ResourceEnum.SHEET_DATA_VALIDATION_PLUGIN.name().equals(t.getName())).findFirst() + .orElse(null); + Map> dataValidationMap = new HashMap<>(); + if (ObjectUtil.isNotEmpty(univerResource) && ObjectUtil.isNotEmpty(univerResource.getData())) { + Map data = JsonUtil.stringToMap(univerResource.getData()); + data.forEach((key, value) -> { + dataValidationMap.put(key, JsonUtil.getJsonToList(value, UniverResourceData.class)); + }); + } + XSSFDataValidationHelper dataValidation = new XSSFDataValidationHelper(sheet); + List data = dataValidationMap.get(sheetOrder) != null ? dataValidationMap.get(sheetOrder) + : new ArrayList<>(); + for (UniverResourceData resourceData : data) { + CellRangeAddressList addressList = new CellRangeAddressList(); + for (UniverSheetRange range : resourceData.getRanges()) { + addressList.addCellRangeAddress(new CellRangeAddress(range.getStartRow(), range.getEndRow(), + range.getStartColumn(), range.getEndColumn())); + } + String formula1 = resourceData.getFormula1() != null ? resourceData.getFormula1() : ""; + String formula2 = resourceData.getFormula2() != null ? resourceData.getFormula2() : ""; + ValidationType validationType = ValidationType.getValidationType(resourceData.getType()); + String value1 = Objects.equals(validationType, ValidationType.checkbox) ? formula1 + "," + formula2 + : formula1; + String value2 = formula2; + operatorTypeEnum operator = operatorTypeEnum.getOperator(resourceData.getOperator()); + XSSFDataValidationConstraint constraint = new XSSFDataValidationConstraint( + validationType.getValidationType(), operator.getOperator(), value1, value2); + constraint.setExplicitListValues(value1.split(",")); + DataValidation validation = dataValidation.createValidation(constraint, addressList); + validation.setErrorStyle(resourceData.getErrorStyle() != null ? 0 : 1); + validation.setEmptyCellAllowed(resourceData.getAllowBlank() != null ? resourceData.getAllowBlank() : true); + if (resourceData.getError() != null) { + validation.createErrorBox(resourceData.getError(), ""); + } + if (resourceData.getRenderMode() != null) { + validation.setSuppressDropDownArrow(!Objects.equals(resourceData.getRenderMode(), 0)); + } + validation.setShowErrorBox( + resourceData.getShowErrorMessage() != null ? resourceData.getShowErrorMessage() : false); + sheet.addValidationData(validation); + } + } + + private static void filter(String sheetOrder, List resources, XSSFSheet sheet) { + UniverResource univerResource = resources.stream() + .filter(t -> ResourceEnum.SHEET_FILTER_PLUGIN.name().equals(t.getName())).findFirst().orElse(null); + Map filterMap = new HashMap<>(); + if (ObjectUtil.isNotEmpty(univerResource) && ObjectUtil.isNotEmpty(univerResource.getData())) { + Map data = JsonUtil.stringToMap(univerResource.getData()); + data.forEach((key, value) -> { + filterMap.put(key, JsonUtil.getJsonToBean(value, UniverResourceData.class)); + }); + } + UniverResourceData data = filterMap.get(sheetOrder) != null ? filterMap.get(sheetOrder) + : new UniverResourceData(); + UniverSheetRange ref = data.getRef(); + if (ref != null) { + sheet.setAutoFilter( + new CellRangeAddress(ref.getStartRow(), ref.getEndRow(), ref.getStartColumn(), ref.getEndColumn())); + List filterColumns = new ArrayList<>(); + CTAutoFilter autoFilter = sheet.getCTWorksheet().getAutoFilter(); + for (UniverFilters filters : data.getFilterColumns()) { + Long colId = filters.getColId(); + UniverCustomFilters customFilters = filters.getCustomFilters(); + // poi方法 + CTFilterColumn column = autoFilter.addNewFilterColumn(); + column.setColId(colId); + CTCustomFilters ctCustomFilters = column.addNewCustomFilters(); + ctCustomFilters.setAnd(Objects.equals(customFilters.getAnd(), 1)); + for (UniverCustomFilters customFilter : customFilters.getCustomFilters()) { + CTCustomFilter ctCustomFilter = ctCustomFilters.addNewCustomFilter(); + String val = customFilter.getVal(); + if (val != null) { + ctCustomFilter.setVal(val); + } + String operator = customFilter.getOperator(); + if (operator != null) { + ctCustomFilter.setOperator(STFilterOperator.Enum.forString(operator)); + } + } + filterColumns.add(column); + } + // 筛选隐藏 + List cachedFilteredOut = data.getCachedFilteredOut(); + for (Integer rowIndex : cachedFilteredOut) { + XSSFRow row = sheet.getRow(rowIndex); + row.setZeroHeight(true); + } + autoFilter.setFilterColumnArray(filterColumns.toArray(new CTFilterColumn[filterColumns.size()])); + } + } + +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/ExcelParser.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/ExcelParser.java new file mode 100644 index 0000000..711e119 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/ExcelParser.java @@ -0,0 +1,16 @@ +package com.yunzhupaas.util.excel; + +import com.yunzhupaas.univer.model.UniverWorkBook; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/30 下午3:10 + */ +public abstract class ExcelParser { + public abstract UniverWorkBook formFile(InputStream inputStream) throws IOException; +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverHSSFExcel.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverHSSFExcel.java new file mode 100644 index 0000000..d9b6ebb --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverHSSFExcel.java @@ -0,0 +1,597 @@ +package com.yunzhupaas.util.excel; + +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.json.JSONUtil; +import com.google.common.collect.ImmutableList; +import com.yunzhupaas.enums.*; +import com.yunzhupaas.univer.data.resource.*; +import com.yunzhupaas.univer.model.UniverWorkBook; +import com.yunzhupaas.univer.resources.UniverResource; +import com.yunzhupaas.univer.resources.UniverResourceData; +import com.yunzhupaas.univer.sheet.*; +import com.yunzhupaas.univer.style.*; +import org.apache.poi.hssf.model.HSSFFormulaParser; +import org.apache.poi.hssf.model.InternalWorkbook; +import org.apache.poi.hssf.record.NameRecord; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.ss.util.PaneInformation; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/6/20 下午4:30 + */ +public class UniverHSSFExcel extends ExcelParser { + + @Override + public UniverWorkBook formFile(InputStream inputStream) throws IOException { + HSSFWorkbook workbook = new HSSFWorkbook(inputStream); + UniverWorkBook univerWorkBook = new UniverWorkBook(); + String unitId = RandomUtil.randomString(10); + univerWorkBook.setId(unitId); + univerWorkBook.setName(""); + Map styleMap = new HashMap<>(); + Map sheets = new HashMap<>(); + List sheetOrder = new ArrayList<>(); + Map drawingMap = new HashMap<>(); + Map> formattingMap = new HashMap<>(); + Map> dataValidationMap = new HashMap<>(); + Map filterMap = new HashMap<>(); + for (int i = 0; i < workbook.getNumberOfSheets(); i++) { + String sheetId = RandomUtil.randomString(10); + sheetOrder.add(sheetId); + HSSFSheet sheet = workbook.getSheetAt(i); + UniverSheet univerSheet = new UniverSheet(); + univerSheet.setId(sheetId); + univerSheet.setName(sheet.getSheetName()); + univerSheet.setHidden(!workbook.isSheetHidden(i) ? 0 : 1); + univerSheet.setTabColor(""); + + // 冻结位置 + UniverSheetFreeze sheetFreeze = new UniverSheetFreeze(); + PaneInformation freeze = sheet.getPaneInformation(); + if (freeze != null) { + int freezeColumn = freeze.getVerticalSplitLeftColumn(); + int freezeRow = freeze.getHorizontalSplitTopRow(); + if (freezeColumn > 0) { + sheetFreeze.setStartColumn(freezeColumn); + sheetFreeze.setXSplit(freezeColumn); + } + if (freezeRow > 0) { + sheetFreeze.setStartRow(freezeRow); + sheetFreeze.setYSplit(freezeRow); + } + } + univerSheet.setFreeze(sheetFreeze); + + Map rowData = new HashMap<>(); + Map columnData = new HashMap<>(); + Map> cellData = new HashMap<>(); + for (int rowCount = 0; rowCount <= sheet.getLastRowNum(); rowCount++) { + HSSFRow row = sheet.getRow(rowCount); + Map cells = new HashMap<>(); + if (null != row) { + for (int columnCount = 0; columnCount <= row.getLastCellNum(); columnCount++) { + HSSFCell cell = row.getCell(columnCount); + UniverSheetCellData univerSheetCellData = new UniverSheetCellData(); + if (null != cell) { + // 数据 + Object value = ""; + String formula = null; + CellType cellType = cell.getCellType(); + Integer type = null; + switch (cellType) { + case STRING: + value = cell.getStringCellValue(); + type = 1; + break; + case BOOLEAN: + value = cell.getBooleanCellValue(); + type = 3; + break; + case NUMERIC: + value = cell.getNumericCellValue(); + type = 2; + break; + case FORMULA: + value = cell.getCellFormula(); + formula = "=" + value; + type = 4; + break; + case BLANK: + value = ""; + type = 1; + break; + case ERROR: + value = "#ERROR"; + type = 1; + break; + case _NONE: + value = ""; + type = 1; + break; + } + univerSheetCellData.setV(value); + univerSheetCellData.setF(formula); + univerSheetCellData.setT(type); + // 样式 + HSSFCellStyle cellStyle = cell.getCellStyle(); + UniverStyle style = getUniverStyle(cellStyle, workbook); + String styleName = styleMap.get(style) != null ? styleMap.get(style) + : RandomUtil.randomString(6); + if (styleMap.get(style) == null) { + styleMap.put(style, styleName); + } + univerSheetCellData.setS(styleName); + cells.put(columnCount, univerSheetCellData); + UniverSheetColumnData univerSheetColumnData = new UniverSheetColumnData(); + univerSheetColumnData.setHd(!sheet.isColumnHidden(columnCount) ? 0 : 1); + List colHeight = new ArrayList<>(); + colHeight.add(100); + colHeight.add((int) sheet.getColumnWidthInPixels(columnCount)); + univerSheetColumnData.setW(Collections.max(colHeight)); + columnData.put(columnCount, univerSheetColumnData); + } + } + cellData.put(rowCount, cells); + UniverSheetRowData univerSheetRowData = new UniverSheetRowData(); + univerSheetRowData.setHd(!row.getZeroHeight() ? 0 : 1); + List rowHeight = new ArrayList<>(); + rowHeight.add(50); + rowHeight.add((int) row.getHeightInPoints()); + univerSheetRowData.setH(Collections.max(rowHeight)); + univerSheetRowData.setIa(0); + rowData.put(rowCount, univerSheetRowData); + } + } + univerSheet.setCellData(cellData); + univerSheet.setRowData(rowData); + univerSheet.setColumnData(columnData); + + List mergeData = new ArrayList<>(); + for (CellRangeAddress region : sheet.getMergedRegions()) { + UniverSheetRange univerSheetRange = new UniverSheetRange(); + univerSheetRange.setStartRow(region.getFirstRow()); + univerSheetRange.setStartColumn(region.getFirstColumn()); + univerSheetRange.setEndRow(region.getLastRow()); + univerSheetRange.setEndColumn(region.getLastColumn()); + mergeData.add(univerSheetRange); + } + univerSheet.setMergeData(mergeData); + + // 图片 + drawing(sheet, sheetId, unitId, drawingMap); + // 条件 + format(sheet, sheetId, unitId, formattingMap); + // 数据管理 + dataValidation(sheet, sheetId, unitId, dataValidationMap); + // 筛选器 + filter(sheet, sheetId, unitId, filterMap); + + UniverSheetRowHeader univerSheetRowHeader = new UniverSheetRowHeader(); + univerSheetRowHeader.setHidden(0); + univerSheetRowHeader.setWidth(46); + univerSheet.setRowHeader(univerSheetRowHeader); + + UniverSheetColumnHeader univerSheetColumnHeader = new UniverSheetColumnHeader(); + univerSheetColumnHeader.setHidden(0); + univerSheetColumnHeader.setHeight(20); + univerSheet.setColumnHeader(univerSheetColumnHeader); + + univerSheet.setZoomRatio(1); + univerSheet.setScrollTop(0); + univerSheet.setScrollLeft(0); + univerSheet.setDefaultColumnWidth(88); + univerSheet.setDefaultRowHeight(24); + List rowCount = new ArrayList<>(); + rowCount.add(100); + rowCount.add(rowData.size()); + univerSheet.setRowCount(Collections.max(rowCount)); + List columnCount = new ArrayList<>(); + columnCount.add(30); + columnCount.add(columnData.size()); + univerSheet.setColumnCount(Collections.max(columnCount)); + univerSheet.setShowGridlines(sheet.isDisplayGridlines() ? 1 : 0); + + univerSheet.setSelections(ImmutableList.of("A1")); + univerSheet.setRightToLeft(0); + sheets.put(sheetId, univerSheet); + } + + Map styles = styleMap.entrySet().stream() + .collect(Collectors.toMap(t -> t.getValue(), t -> t.getKey())); + univerWorkBook.setStyles(styles); + univerWorkBook.setSheetOrder(sheetOrder); + univerWorkBook.setSheets(sheets); + Map resourceMap = new HashMap<>(); + resourceMap.put(ResourceEnum.SHEET_DRAWING_PLUGIN.name(), JSONUtil.toJsonStr(drawingMap)); + resourceMap.put(ResourceEnum.SHEET_CONDITIONAL_FORMATTING_PLUGIN.name(), JSONUtil.toJsonStr(formattingMap)); + resourceMap.put(ResourceEnum.SHEET_DATA_VALIDATION_PLUGIN.name(), JSONUtil.toJsonStr(dataValidationMap)); + resourceMap.put(ResourceEnum.SHEET_FILTER_PLUGIN.name(), JSONUtil.toJsonStr(filterMap)); + univerWorkBook.setResources(getUniverResources(resourceMap)); + return univerWorkBook; + } + + private UniverStyle getUniverStyle(HSSFCellStyle cellStyle, HSSFWorkbook workbook) { + UniverStyle univerStyle = new UniverStyle(); + univerStyle.setHt(HorizontalEnum.getHorizontalCode(cellStyle.getAlignment())); + univerStyle.setVt(VerticalEnum.getVerticalCode(cellStyle.getVerticalAlignment())); + + HSSFFont font = cellStyle.getFont(workbook); + if (null != font) { + univerStyle.setFf(font.getFontName()); + univerStyle.setFs((int) font.getFontHeightInPoints()); + univerStyle.setIt(font.getItalic() ? 1 : 0); + univerStyle.setBl(font.getBold() ? 1 : 0); + HSSFColor color = font.getHSSFColor(workbook); + if (null != color) { + UniverStyleColor cl = new UniverStyleColor(); + cl.setRgb(rgb(color.getTriplet())); + univerStyle.setCl(cl); + } + if (Objects.equals(font.getUnderline(), Font.U_SINGLE)) { + UniverStyleTextDecoration ul = new UniverStyleTextDecoration(); + ul.setS(1); + univerStyle.setUl(ul); + } + if (font.getStrikeout()) { + UniverStyleTextDecoration st = new UniverStyleTextDecoration(); + st.setS(1); + univerStyle.setSt(st); + } + } + if (null != cellStyle.getDataFormatString()) { + UniverStylePattern pattern = new UniverStylePattern(); + pattern.setPattern(cellStyle.getDataFormatString()); + univerStyle.setN(pattern); + } + univerStyle.setBd(getUniverStyleBorder(cellStyle, workbook)); + + HSSFColor bgColor = cellStyle.getFillForegroundColorColor(); + FillPatternType pattern = cellStyle.getFillPattern(); + if (null != bgColor && Objects.equals(pattern, FillPatternType.SOLID_FOREGROUND)) { + UniverStyleColor background = new UniverStyleColor(); + background.setRgb(rgb(bgColor.getTriplet())); + univerStyle.setBg(background); + } + + UniverStyleTextRotation univerStyleTextRotation = new UniverStyleTextRotation(); + univerStyleTextRotation.setA(cellStyle.getRotation()); + univerStyle.setTr(univerStyleTextRotation); + return univerStyle; + } + + private String rgb(short[] color) { + String rgb = null; + if (null != color && color.length == 3) { + rgb = String.format("#%02X%02X%02X", color[0], color[1], color[2]); + } + return rgb; + } + + private String rgb(byte[] color) { + String rgb = null; + if (ObjectUtil.isNotEmpty(color)) { + rgb = String.format("#%02X%02X%02X", color[0], color[1], color[2]); + } + return rgb; + } + + private UniverStyleBorder getUniverStyleBorder(HSSFCellStyle cellStyle, HSSFWorkbook workbook) { + UniverStyleBorder univerStyleBorder = new UniverStyleBorder(); + int num = 0; + HSSFPalette palette = workbook.getCustomPalette(); + HSSFColor leftBorder = palette.getColor(cellStyle.getLeftBorderColor()); + if (null != leftBorder) { + UniverStyleBorderStyle left = new UniverStyleBorderStyle(); + UniverStyleColor leftColor = new UniverStyleColor(); + leftColor.setRgb(rgb(leftBorder.getTriplet())); + left.setCl(leftColor); + univerStyleBorder.setL(left); + num++; + } + HSSFColor topBorder = palette.getColor(cellStyle.getTopBorderColor()); + if (null != topBorder) { + UniverStyleBorderStyle top = new UniverStyleBorderStyle(); + UniverStyleColor topColor = new UniverStyleColor(); + topColor.setRgb(rgb(topBorder.getTriplet())); + top.setCl(topColor); + univerStyleBorder.setT(top); + num++; + } + HSSFColor rightBorder = palette.getColor(cellStyle.getRightBorderColor()); + if (null != rightBorder) { + UniverStyleBorderStyle right = new UniverStyleBorderStyle(); + UniverStyleColor rightColor = new UniverStyleColor(); + rightColor.setRgb(rgb(rightBorder.getTriplet())); + right.setCl(rightColor); + univerStyleBorder.setR(right); + num++; + } + HSSFColor bottomBorder = palette.getColor(cellStyle.getBottomBorderColor()); + if (null != bottomBorder) { + UniverStyleBorderStyle bottom = new UniverStyleBorderStyle(); + UniverStyleColor bottomColor = new UniverStyleColor(); + bottomColor.setRgb(rgb(bottomBorder.getTriplet())); + bottom.setCl(bottomColor); + univerStyleBorder.setB(bottom); + num++; + } + return num > 0 ? univerStyleBorder : null; + } + + private List getUniverResources(Map resourceMap) { + List resourcesList = new ArrayList<>(); + for (ResourceEnum resource : ResourceEnum.values()) { + UniverResource model = new UniverResource(); + String name = resource.name(); + model.setName(name); + model.setData(resourceMap.get(name) != null ? resourceMap.get(name) : "{}"); + resourcesList.add(model); + } + return resourcesList; + } + + private void drawing(HSSFSheet sheet, String sheetId, String unitId, Map drawingMap) { + List order = new ArrayList<>(); + Map data = new HashMap<>(); + HSSFPatriarch drawing = sheet.getDrawingPatriarch(); + if (drawing != null) { + List shapes = drawing.getChildren(); + for (HSSFShape shape : shapes) { + if (shape instanceof HSSFPicture) { + HSSFPicture picture = (HSSFPicture) shape; + byte[] pictureData = picture.getPictureData().getData(); + if (pictureData.length > 0) { + String drawingId = RandomUtil.randomString(10); + order.add(drawingId); + BufferedImage image = ImgUtil.toImage(pictureData); + UniverTransform sheetTransform = new UniverTransform(); + HSSFClientAnchor anchor = picture.getClientAnchor(); + UniverOffset univerFrom = new UniverOffset(); + univerFrom.setRow(anchor.getRow1()); + univerFrom.setColumn((int) anchor.getCol1()); + sheetTransform.setFrom(univerFrom); + UniverOffset univerTo = new UniverOffset(); + univerTo.setRow(anchor.getRow2()); + univerTo.setColumn((int) anchor.getCol2()); + sheetTransform.setTo(univerTo); + UniverDrawing univerDrawing = new UniverDrawing(); + univerDrawing.setSheetTransform(sheetTransform); + univerDrawing.setDrawingType(0); + univerDrawing.setUnitId(unitId); + univerDrawing.setSubUnitId(sheetId); + univerDrawing.setDrawingId(drawingId); + univerDrawing.setImageSourceType(ImageEnum.BASE64.name()); + univerDrawing.setSource("data:image/jpeg;base64," + ImgUtil.toBase64(image, "jpeg")); + data.put(drawingId, univerDrawing); + } + } + } + } + if (!order.isEmpty()) { + UniverResourceData resourceData = new UniverResourceData(); + resourceData.setData(data); + resourceData.setOrder(order); + drawingMap.put(sheetId, resourceData); + } + } + + private void format(HSSFSheet sheet, String sheetId, String unitId, + Map> formattingMap) { + // todo 提供色阶、数据条、色阶方法,其他方法获取的数据有问题 + List formatList = new ArrayList<>(); + HSSFSheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting(); + if (null != formatting) { + for (int i = 0; i < formatting.getNumConditionalFormattings(); i++) { + HSSFConditionalFormatting format = formatting.getConditionalFormattingAt(i); + UniverResourceData resourceData = new UniverResourceData(); + resourceData.setCfId(RandomUtil.randomString(10)); + CellRangeAddress[] formattingRanges = format.getFormattingRanges(); + List ranges = new ArrayList<>(); + resourceData.setRanges(ranges); + for (CellRangeAddress rangeAddress : formattingRanges) { + UniverSheetRange range = new UniverSheetRange(); + range.setStartRow(rangeAddress.getFirstRow()); + range.setStartColumn(rangeAddress.getFirstColumn()); + range.setEndRow(rangeAddress.getLastRow()); + range.setEndColumn(rangeAddress.getLastColumn()); + range.setUnitId(unitId); + range.setSheetId(sheetId); + ranges.add(range); + } + for (int num = 0; num < format.getNumberOfRules(); num++) { + HSSFConditionalFormattingRule formatRule = format.getRule(num); + HSSFIconMultiStateFormatting iconSet = formatRule.getMultiStateFormatting(); + if (iconSet != null) { + boolean reverse = iconSet.isReversed(); + UniverRule rule = new UniverRule(); + List univerConfig = new ArrayList<>(); + rule.setType(FormatTypeEnum.iconSet.name()); + rule.setConfig(univerConfig); + // 显示数据条没有属性 + rule.setIsShowValue(false); + String iconType = iconSet.getIconSet().name; + HSSFConditionalFormattingThreshold[] cfvoList = iconSet.getThresholds(); + int iconId = 0; + for (int k = cfvoList.length - 1; k >= 0; k--) { + HSSFConditionalFormattingThreshold cfvo = cfvoList[k]; + UniverValue value = new UniverValue(); + String type = cfvo.getRangeType().name; + String val = Objects.equals(SubTypeEnum.expression.getCode(), type) + ? "=" + cfvo.getFormula().replaceAll("\"", "") + : cfvo.getValue() + ""; + value.setValue(val); + value.setType(type); + UniverConfig config = new UniverConfig(); + config.setOperator(OperatorEnum.greaterThan.name()); + config.setIconId((reverse ? k : iconId) + ""); + config.setIconType(iconType); + config.setValue(value); + univerConfig.add(config); + iconId++; + } + resourceData.setRule(rule); + } + + HSSFDataBarFormatting dataBar = formatRule.getDataBarFormatting(); + if (dataBar != null) { + UniverRule rule = new UniverRule(); + UniverConfig config = new UniverConfig(); + rule.setConfig(config); + rule.setType(FormatTypeEnum.dataBar.name()); + // 显示数据条没有属性 + rule.setIsShowValue(false); + HSSFConditionalFormattingThreshold minThreshold = dataBar.getMinThreshold(); + UniverValue min = new UniverValue(); + min.setType(minThreshold.getRangeType().name); + min.setValue(Objects.equals(SubTypeEnum.expression.getCode(), min.getType()) + ? "=" + minThreshold.getFormula().replaceAll("\"", "") + : minThreshold.getValue() + ""); + config.setMin(min); + HSSFConditionalFormattingThreshold maxThreshold = dataBar.getMaxThreshold(); + UniverValue max = new UniverValue(); + max.setType(maxThreshold.getRangeType().name); + max.setValue(Objects.equals(SubTypeEnum.expression.getCode(), max.getType()) + ? "=" + maxThreshold.getFormula().replaceAll("\"", "") + : maxThreshold.getValue() + ""); + config.setMax(max); + config.setIsGradient(true); + byte[] rgb = dataBar.getColor().getRGB(); + config.setPositiveColor(rgb(rgb)); + config.setNativeColor(rgb(rgb)); + resourceData.setRule(rule); + } + + HSSFColorScaleFormatting colorScale = formatRule.getColorScaleFormatting(); + if (colorScale != null) { + UniverRule rule = new UniverRule(); + List univerConfig = new ArrayList<>(); + rule.setType(FormatTypeEnum.colorScale.name()); + rule.setConfig(univerConfig); + Map colorValue = new HashMap<>(); + HSSFConditionalFormattingThreshold[] cfvoList = colorScale.getThresholds(); + for (int k = 0; k < cfvoList.length; k++) { + HSSFConditionalFormattingThreshold cfvo = cfvoList[k]; + UniverValue value = new UniverValue(); + String type = cfvo.getRangeType().name; + String val = Objects.equals(SubTypeEnum.expression.getCode(), type) + ? "=" + cfvo.getFormula().replaceAll("\"", "") + : cfvo.getValue() + ""; + value.setType(type); + value.setValue(val); + colorValue.put(k, value); + } + HSSFExtendedColor[] colorList = colorScale.getColors(); + Map colorColor = new HashMap<>(); + for (int k = 0; k < colorList.length; k++) { + HSSFExtendedColor ctColor = colorList[k]; + colorColor.put(k, rgb(ctColor.getRGB())); + } + for (Integer k : colorValue.keySet()) { + UniverConfig config = new UniverConfig(); + config.setValue(colorValue.get(k)); + config.setColor(colorColor.get(k)); + config.setIndex(k); + univerConfig.add(config); + } + resourceData.setRule(rule); + } + + resourceData.setStopIfTrue(formatRule.getStopIfTrue()); + if (resourceData.getRule() == null) { + continue; + } + formatList.add(resourceData); + } + } + } + formattingMap.put(sheetId, formatList); + } + + private void filter(HSSFSheet sheet, String sheetId, String unitId, Map filterMap) { + // todo 只有获取筛选的格子,没有提供筛选的内容 + int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet) + 1; + UniverResourceData data = new UniverResourceData(); + InternalWorkbook workbook = sheet.getWorkbook().getWorkbook(); + if (workbook != null) { + NameRecord name = workbook.getSpecificBuiltinRecord((byte) 13, sheetIndex); + if (name != null) { + Ptg[] nameDefinition = name.getNameDefinition(); + String formulaString = HSSFFormulaParser.toFormulaString(sheet.getWorkbook(), nameDefinition); + CellRangeAddress addresses = CellRangeAddress.valueOf(formulaString); + UniverSheetRange ref = new UniverSheetRange(); + ref.setStartRow(addresses.getFirstRow()); + ref.setStartColumn(addresses.getFirstColumn()); + ref.setEndRow(addresses.getLastRow()); + ref.setEndColumn(addresses.getLastColumn()); + data.setRef(ref); + List filterColumns = new ArrayList<>(); + data.setFilterColumns(filterColumns); + List cachedFilteredOut = new ArrayList<>(); + data.setCachedFilteredOut(cachedFilteredOut); + filterMap.put(sheetId, data); + } + } + } + + private static void dataValidation(HSSFSheet sheet, String sheetId, String unitId, + Map> dataValidationMap) { + List dataValidationList = new ArrayList<>(); + List dataValidations = sheet.getDataValidations(); + for (HSSFDataValidation dataValidation : dataValidations) { + UniverResourceData resourceData = new UniverResourceData(); + List ranges = new ArrayList<>(); + resourceData.setRanges(ranges); + resourceData.setUid(RandomUtil.randomString(10)); + CellRangeAddressList addressList = dataValidation.getRegions(); + for (CellRangeAddress address : addressList.getGenericChildren()) { + UniverSheetRange sheetRange = new UniverSheetRange(); + sheetRange.setStartRow(address.getFirstRow()); + sheetRange.setStartColumn(address.getFirstColumn()); + sheetRange.setEndRow(address.getLastRow()); + sheetRange.setEndColumn(address.getLastColumn()); + sheetRange.setSheetId(sheetId); + sheetRange.setUnitId(unitId); + ranges.add(sheetRange); + } + DVConstraint constraint = (DVConstraint) dataValidation.getValidationConstraint(); + ValidationType validationType = ValidationType.getType(constraint.getValidationType()); + resourceData.setType(validationType.getType()); + operatorTypeEnum operator = Objects.equals(validationType, ValidationType.none) ? null + : operatorTypeEnum.getOperator(constraint.getOperator()); + resourceData.setOperator(operator != null ? operator.getOperatorType() : null); + String value1 = constraint.getValue1() != null ? constraint.getValue1().toString() + : constraint.getFormula1(); + String value2 = constraint.getValue2() != null ? constraint.getValue2().toString() + : constraint.getFormula2(); + resourceData.setFormula1(value1 != null ? value1.replaceAll("\"", "") : value1); + resourceData.setFormula2(value2 != null ? value2.replaceAll("\"", "") : value2); + if (dataValidation.getShowErrorBox()) { + resourceData.setShowErrorMessage(true); + resourceData.setError(dataValidation.getErrorBoxTitle()); + resourceData.setErrorStyle(Objects.equals(dataValidation.getErrorStyle(), 0) ? 1 : 2); + } + resourceData.setAllowBlank(dataValidation.getEmptyCellAllowed()); + resourceData.setRenderMode(dataValidation.getSuppressDropDownArrow() ? null : 0); + dataValidationList.add(resourceData); + } + dataValidationMap.put(sheetId, dataValidationList); + } +} diff --git a/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverXSSFExcel.java b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverXSSFExcel.java new file mode 100644 index 0000000..69651b7 --- /dev/null +++ b/yunzhupaas-datareport-univer-common/src/main/java/com/yunzhupaas/util/excel/UniverXSSFExcel.java @@ -0,0 +1,728 @@ +package com.yunzhupaas.util.excel; + +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.json.JSONUtil; +import com.google.common.collect.ImmutableList; +import com.yunzhupaas.enums.*; +import com.yunzhupaas.univer.data.resource.*; +import com.yunzhupaas.univer.model.UniverWorkBook; +import com.yunzhupaas.univer.resources.UniverResource; +import com.yunzhupaas.univer.resources.UniverResourceData; +import com.yunzhupaas.univer.sheet.*; +import com.yunzhupaas.univer.style.*; +import com.yunzhupaas.util.StringUtil; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.DataValidationConstraint; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.ss.util.PaneInformation; +import org.apache.poi.xssf.model.StylesTable; +import org.apache.poi.xssf.usermodel.*; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/6/20 下午4:30 + */ +public class UniverXSSFExcel extends ExcelParser { + + @Override + public UniverWorkBook formFile(InputStream inputStream) throws IOException { + try (XSSFWorkbook workbook = new XSSFWorkbook(inputStream)) { + UniverWorkBook univerWorkBook = new UniverWorkBook(); + String unitId = RandomUtil.randomString(10); + univerWorkBook.setId(unitId); + univerWorkBook.setName(""); + Map styleMap = new HashMap<>(); + Map sheets = new HashMap<>(); + List sheetOrder = new ArrayList<>(); + Map drawingMap = new HashMap<>(); + Map> formattingMap = new HashMap<>(); + Map> dataValidationMap = new HashMap<>(); + for (int i = 0; i < workbook.getNumberOfSheets(); i++) { + String sheetId = RandomUtil.randomString(10); + sheetOrder.add(sheetId); + XSSFSheet sheet = workbook.getSheetAt(i); + UniverSheet univerSheet = new UniverSheet(); + univerSheet.setId(sheetId); + univerSheet.setName(sheet.getSheetName()); + univerSheet.setHidden(!workbook.isSheetHidden(i) ? 0 : 1); + univerSheet.setTabColor(""); + + // 冻结位置 + UniverSheetFreeze sheetFreeze = new UniverSheetFreeze(); + PaneInformation freeze = sheet.getPaneInformation(); + if (freeze != null) { + int freezeColumn = freeze.getVerticalSplitLeftColumn(); + if (freezeColumn > 0) { + sheetFreeze.setStartColumn(freezeColumn); + sheetFreeze.setXSplit(freezeColumn); + } + int freezeRow = freeze.getHorizontalSplitTopRow(); + if (freezeRow > 0) { + sheetFreeze.setStartRow(freezeRow); + sheetFreeze.setYSplit(freezeRow); + } + } + univerSheet.setFreeze(sheetFreeze); + + Map rowData = new HashMap<>(); + Map columnData = new HashMap<>(); + Map> cellData = new HashMap<>(); + for (int rowCount = 0; rowCount <= sheet.getLastRowNum(); rowCount++) { + XSSFRow row = sheet.getRow(rowCount); + Map cells = new HashMap<>(); + if (null != row) { + for (int columnCount = 0; columnCount <= row.getLastCellNum(); columnCount++) { + XSSFCell cell = row.getCell(columnCount); + UniverSheetCellData univerSheetCellData = new UniverSheetCellData(); + if (null != cell) { + // 数据 + Object value = ""; + String formula = null; + CellType cellType = cell.getCellType(); + Integer type = null; + switch (cellType) { + case STRING: + value = cell.getStringCellValue(); + type = 1; + break; + case BOOLEAN: + value = cell.getBooleanCellValue(); + type = 3; + break; + case NUMERIC: + value = cell.getNumericCellValue(); + type = 2; + break; + case FORMULA: + value = cell.getCellFormula(); + formula = "=" + value; + type = 4; + break; + case BLANK: + value = ""; + type = 1; + break; + case ERROR: + value = cell.getErrorCellValue(); + type = 5; + break; + case _NONE: + value = ""; + type = 1; + break; + } + univerSheetCellData.setV(value); + univerSheetCellData.setF(formula); + univerSheetCellData.setT(type); + // 样式 + XSSFCellStyle cellStyle = cell.getCellStyle(); + UniverStyle style = getUniverStyle(cellStyle); + String styleName = styleMap.get(style) != null ? styleMap.get(style) + : RandomUtil.randomString(6); + if (styleMap.get(style) == null) { + styleMap.put(style, styleName); + } + univerSheetCellData.setS(styleName); + cells.put(columnCount, univerSheetCellData); + UniverSheetColumnData univerSheetColumnData = new UniverSheetColumnData(); + univerSheetColumnData.setHd(!sheet.isColumnHidden(columnCount) ? 0 : 1); + List colHeight = new ArrayList<>(); + colHeight.add(100); + colHeight.add((int) sheet.getColumnWidthInPixels(columnCount)); + univerSheetColumnData.setW(Collections.max(colHeight)); + columnData.put(columnCount, univerSheetColumnData); + } + } + cellData.put(rowCount, cells); + UniverSheetRowData univerSheetRowData = new UniverSheetRowData(); + univerSheetRowData.setHd(!row.getZeroHeight() ? 0 : 1); + List rowHeight = new ArrayList<>(); + rowHeight.add(50); + rowHeight.add((int) row.getHeightInPoints()); + univerSheetRowData.setH(Collections.max(rowHeight)); + univerSheetRowData.setIa(0); + rowData.put(rowCount, univerSheetRowData); + } + } + univerSheet.setCellData(cellData); + univerSheet.setRowData(rowData); + univerSheet.setColumnData(columnData); + + List mergeData = new ArrayList<>(); + for (CellRangeAddress region : sheet.getMergedRegions()) { + UniverSheetRange univerSheetRange = new UniverSheetRange(); + univerSheetRange.setStartRow(region.getFirstRow()); + univerSheetRange.setStartColumn(region.getFirstColumn()); + univerSheetRange.setEndRow(region.getLastRow()); + univerSheetRange.setEndColumn(region.getLastColumn()); + mergeData.add(univerSheetRange); + } + univerSheet.setMergeData(mergeData); + + // 图片 + drawing(sheet, sheetId, unitId, drawingMap); + // 条件 + format(sheet, sheetId, unitId, formattingMap); + // 数据管理 + dataValidation(sheet, sheetId, unitId, dataValidationMap); + // 筛选 + filter(sheet, sheetId, unitId, drawingMap); + + UniverSheetRowHeader univerSheetRowHeader = new UniverSheetRowHeader(); + univerSheetRowHeader.setHidden(0); + univerSheetRowHeader.setWidth(46); + univerSheet.setRowHeader(univerSheetRowHeader); + + UniverSheetColumnHeader univerSheetColumnHeader = new UniverSheetColumnHeader(); + univerSheetColumnHeader.setHidden(0); + univerSheetColumnHeader.setHeight(20); + univerSheet.setColumnHeader(univerSheetColumnHeader); + + univerSheet.setZoomRatio(1); + univerSheet.setScrollTop(0); + univerSheet.setScrollLeft(0); + univerSheet.setDefaultColumnWidth(88); + univerSheet.setDefaultRowHeight(24); + List rowCount = new ArrayList<>(); + rowCount.add(100); + rowCount.add(rowData.size()); + univerSheet.setRowCount(Collections.max(rowCount)); + List columnCount = new ArrayList<>(); + columnCount.add(30); + columnCount.add(columnData.size()); + univerSheet.setColumnCount(Collections.max(columnCount)); + univerSheet.setShowGridlines(sheet.isDisplayGridlines() ? 1 : 0); + + univerSheet.setSelections(ImmutableList.of("A1")); + univerSheet.setRightToLeft(0); + sheets.put(sheetId, univerSheet); + } + + Map styles = styleMap.entrySet().stream() + .collect(Collectors.toMap(t -> t.getValue(), t -> t.getKey())); + univerWorkBook.setStyles(styles); + univerWorkBook.setSheetOrder(sheetOrder); + univerWorkBook.setSheets(sheets); + Map resourceMap = new HashMap<>(); + resourceMap.put(ResourceEnum.SHEET_DRAWING_PLUGIN.name(), JSONUtil.toJsonStr(drawingMap)); + resourceMap.put(ResourceEnum.SHEET_CONDITIONAL_FORMATTING_PLUGIN.name(), JSONUtil.toJsonStr(formattingMap)); + resourceMap.put(ResourceEnum.SHEET_DATA_VALIDATION_PLUGIN.name(), JSONUtil.toJsonStr(dataValidationMap)); + univerWorkBook.setResources(getUniverResources(resourceMap)); + return univerWorkBook; + } + } + + private UniverStyle getUniverStyle(XSSFCellStyle cellStyle) { + UniverStyle univerStyle = new UniverStyle(); + univerStyle.setHt(HorizontalEnum.getHorizontalCode(cellStyle.getAlignment())); + univerStyle.setVt(VerticalEnum.getVerticalCode(cellStyle.getVerticalAlignment())); + + XSSFFont font = cellStyle.getFont(); + if (null != font) { + univerStyle.setFf(font.getFontName()); + univerStyle.setFs((int) font.getFontHeightInPoints()); + univerStyle.setIt(font.getItalic() ? 1 : 0); + univerStyle.setBl(font.getBold() ? 1 : 0); + if (null != font.getXSSFColor()) { + UniverStyleColor cl = new UniverStyleColor(); + cl.setRgb(rgb(font.getXSSFColor().getARGBHex())); + univerStyle.setCl(cl); + } + if (Objects.equals(font.getUnderline(), Font.U_SINGLE)) { + UniverStyleTextDecoration ul = new UniverStyleTextDecoration(); + ul.setS(1); + univerStyle.setUl(ul); + } + if (font.getStrikeout()) { + UniverStyleTextDecoration st = new UniverStyleTextDecoration(); + st.setS(1); + univerStyle.setSt(st); + } + } + if (null != cellStyle.getDataFormatString()) { + UniverStylePattern pattern = new UniverStylePattern(); + pattern.setPattern(cellStyle.getDataFormatString()); + univerStyle.setN(pattern); + } + univerStyle.setBd(getUniverStyleBorder(cellStyle)); + + XSSFColor bgColor = cellStyle.getFillForegroundColorColor(); + FillPatternType pattern = cellStyle.getFillPattern(); + if (null != bgColor && Objects.equals(pattern, FillPatternType.SOLID_FOREGROUND)) { + UniverStyleColor background = new UniverStyleColor(); + background.setRgb(rgb(cellStyle.getFillForegroundColorColor().getARGBHex())); + univerStyle.setBg(background); + } + + UniverStyleTextRotation univerStyleTextRotation = new UniverStyleTextRotation(); + univerStyleTextRotation.setA(cellStyle.getRotation()); + univerStyle.setTr(univerStyleTextRotation); + return univerStyle; + } + + private String rgb(String color) { + String rgb = null; + if (StringUtil.isNotEmpty(color)) { + rgb = "#" + color.substring(2, 8); + } + return rgb; + } + + private String rgb(byte[] color) { + String rgb = null; + if (ObjectUtil.isNotEmpty(color)) { + XSSFColor xssfColor = new XSSFColor(color); + rgb = rgb(xssfColor.getARGBHex()); + } + return rgb; + } + + private UniverStyleBorder getUniverStyleBorder(XSSFCellStyle cellStyle) { + UniverStyleBorder univerStyleBorder = new UniverStyleBorder(); + int num = 0; + if (null != cellStyle.getLeftBorderXSSFColor()) { + UniverStyleBorderStyle left = new UniverStyleBorderStyle(); + UniverStyleColor leftColor = new UniverStyleColor(); + leftColor.setRgb(rgb(cellStyle.getLeftBorderXSSFColor().getARGBHex())); + left.setCl(leftColor); + univerStyleBorder.setL(left); + num++; + } + if (null != cellStyle.getTopBorderXSSFColor()) { + UniverStyleBorderStyle top = new UniverStyleBorderStyle(); + UniverStyleColor topColor = new UniverStyleColor(); + topColor.setRgb(rgb(cellStyle.getTopBorderXSSFColor().getARGBHex())); + top.setCl(topColor); + univerStyleBorder.setT(top); + num++; + } + if (null != cellStyle.getRightBorderXSSFColor()) { + UniverStyleBorderStyle right = new UniverStyleBorderStyle(); + UniverStyleColor rightColor = new UniverStyleColor(); + rightColor.setRgb(rgb(cellStyle.getRightBorderXSSFColor().getARGBHex())); + right.setCl(rightColor); + univerStyleBorder.setR(right); + num++; + } + if (null != cellStyle.getBottomBorderXSSFColor()) { + UniverStyleBorderStyle bottom = new UniverStyleBorderStyle(); + UniverStyleColor bottomColor = new UniverStyleColor(); + bottomColor.setRgb(rgb(cellStyle.getBottomBorderXSSFColor().getARGBHex())); + bottom.setCl(bottomColor); + univerStyleBorder.setB(bottom); + num++; + } + return num > 0 ? univerStyleBorder : null; + } + + private List getUniverResources(Map resourceMap) { + List resourcesList = new ArrayList<>(); + for (ResourceEnum resource : ResourceEnum.values()) { + UniverResource model = new UniverResource(); + String name = resource.name(); + model.setName(name); + model.setData(resourceMap.get(name) != null ? resourceMap.get(name) : "{}"); + resourcesList.add(model); + } + return resourcesList; + } + + private void drawing(XSSFSheet sheet, String sheetId, String unitId, Map drawingMap) { + List order = new ArrayList<>(); + Map data = new HashMap<>(); + XSSFDrawing drawing = sheet.getDrawingPatriarch(); + if (drawing != null) { + List shapes = drawing.getShapes(); + for (XSSFShape shape : shapes) { + if (shape instanceof XSSFPicture) { + XSSFPicture picture = (XSSFPicture) shape; + byte[] pictureData = picture.getPictureData().getData(); + if (pictureData.length > 0) { + String drawingId = RandomUtil.randomString(10); + order.add(drawingId); + BufferedImage image = ImgUtil.toImage(pictureData); + UniverTransform sheetTransform = new UniverTransform(); + XSSFClientAnchor anchor = picture.getClientAnchor(); + UniverOffset univerFrom = new UniverOffset(); + univerFrom.setRow(anchor.getRow1()); + univerFrom.setColumn((int) anchor.getCol1()); + sheetTransform.setFrom(univerFrom); + UniverOffset univerTo = new UniverOffset(); + univerTo.setRow(anchor.getRow2()); + univerTo.setColumn((int) anchor.getCol2()); + sheetTransform.setTo(univerTo); + UniverDrawing univerDrawing = new UniverDrawing(); + univerDrawing.setSheetTransform(sheetTransform); + univerDrawing.setDrawingType(0); + univerDrawing.setUnitId(unitId); + univerDrawing.setSubUnitId(sheetId); + univerDrawing.setDrawingId(drawingId); + univerDrawing.setImageSourceType(ImageEnum.BASE64.name()); + univerDrawing.setSource("data:image/jpeg;base64," + ImgUtil.toBase64(image, "jpeg")); + data.put(drawingId, univerDrawing); + } + } + } + } + if (!order.isEmpty()) { + UniverResourceData resourceData = new UniverResourceData(); + resourceData.setData(data); + resourceData.setOrder(order); + drawingMap.put(sheetId, resourceData); + } + } + + private void format(XSSFSheet sheet, String sheetId, String unitId, + Map> formattingMap) { + StylesTable styles = sheet.getWorkbook().getStylesSource(); + List formatList = new ArrayList<>(); + List conditionalFormatting = sheet.getCTWorksheet().getConditionalFormattingList(); + for (CTConditionalFormatting conditional : conditionalFormatting) { + UniverResourceData resourceData = new UniverResourceData(); + resourceData.setCfId(RandomUtil.randomString(10)); + List ranges = new ArrayList<>(); + resourceData.setRanges(ranges); + @SuppressWarnings("unchecked") + List formattingRanges = conditional.getSqref(); + for (String range : formattingRanges) { + UniverSheetRange sheetRange = new UniverSheetRange(); + CellRangeAddress rangeAddress = CellRangeAddress.valueOf(range); + sheetRange.setStartRow(rangeAddress.getFirstRow()); + sheetRange.setStartColumn(rangeAddress.getFirstColumn()); + sheetRange.setEndRow(rangeAddress.getLastRow()); + sheetRange.setEndColumn(rangeAddress.getLastColumn()); + sheetRange.setUnitId(unitId); + sheetRange.setSheetId(sheetId); + ranges.add(sheetRange); + } + List cfRuleList = conditional.getCfRuleList(); + for (CTCfRule cfRule : cfRuleList) { + CTIconSet iconSet = cfRule.getIconSet(); + if (iconSet != null) { + boolean reverse = iconSet.getReverse(); + UniverRule rule = new UniverRule(); + List univerConfig = new ArrayList<>(); + rule.setType(FormatTypeEnum.iconSet.name()); + rule.setConfig(univerConfig); + rule.setIsShowValue(iconSet.getShowValue()); + String iconType = iconSet.getIconSet().toString(); + List cfvoList = iconSet.getCfvoList(); + int iconId = 0; + for (int k = cfvoList.size() - 1; k >= 0; k--) { + CTCfvo cfvo = cfvoList.get(k); + UniverValue value = new UniverValue(); + String type = cfvo.getType().toString(); + String cfValue = cfvo.getVal() != null ? cfvo.getVal().toString() : ""; + String val = (Objects.equals(SubTypeEnum.expression.getType(), type) ? "=" : "") + + cfValue.replaceAll("\"", ""); + value.setValue(val); + value.setType(type); + UniverConfig config = new UniverConfig(); + config.setOperator(cfvo.getGte() ? OperatorEnum.greaterThanOrEqual.name() + : OperatorEnum.greaterThan.name()); + config.setIconId((reverse ? k : iconId) + ""); + config.setIconType(iconType); + config.setValue(value); + univerConfig.add(config); + iconId++; + } + resourceData.setRule(rule); + } + CTDataBar dataBar = cfRule.getDataBar(); + if (dataBar != null) { + UniverRule rule = new UniverRule(); + UniverConfig config = new UniverConfig(); + rule.setConfig(config); + rule.setType(FormatTypeEnum.dataBar.name()); + rule.setIsShowValue(dataBar.getShowValue()); + List cfvoList = dataBar.getCfvoList(); + UniverValue min = new UniverValue(); + min.setType(OperatorEnum.min.name()); + config.setMin(min); + UniverValue max = new UniverValue(); + max.setType(OperatorEnum.max.name()); + config.setMax(max); + for (int k = 0; k < cfvoList.size(); k++) { + CTCfvo cfvo = cfvoList.get(k); + String type = cfvo.getType().toString(); + String cfValue = cfvo.getVal() != null ? cfvo.getVal().toString() : ""; + String val = (Objects.equals(SubTypeEnum.expression.getType(), type) ? "=" : "") + + cfValue.replaceAll("\"", ""); + if (k == 0) { + min.setValue(val); + min.setType(type); + } else { + max.setValue(val); + max.setType(Objects.equals(type, OperatorEnum.min.name()) ? max.getType() : type); + } + } + config.setIsGradient(false); + CTColor color = dataBar.getColor(); + if (color != null) { + String colorRgb = rgb(color.getRgb()); + config.setPositiveColor(colorRgb); + config.setNativeColor(colorRgb); + } + resourceData.setRule(rule); + } + CTColorScale colorScale = cfRule.getColorScale(); + if (colorScale != null) { + UniverRule rule = new UniverRule(); + List univerConfig = new ArrayList<>(); + rule.setType(FormatTypeEnum.colorScale.name()); + rule.setConfig(univerConfig); + Map colorValue = new HashMap<>(); + List cfvoList = colorScale.getCfvoList(); + for (int k = 0; k < cfvoList.size(); k++) { + CTCfvo cfvo = cfvoList.get(k); + UniverValue value = new UniverValue(); + String type = cfvo.getType().toString(); + String cfValue = cfvo.getVal() != null ? cfvo.getVal().toString() : ""; + String val = (Objects.equals(SubTypeEnum.expression.getType(), type) ? "=" : "") + + cfValue.replaceAll("\"", ""); + value.setType(type); + value.setValue(val); + colorValue.put(k, value); + } + List colorList = colorScale.getColorList(); + Map colorColor = new HashMap<>(); + for (int k = 0; k < colorList.size(); k++) { + CTColor color = colorList.get(k); + String colorRgb = rgb(color.getRgb()); + colorColor.put(k, colorRgb); + } + for (Integer k : colorValue.keySet()) { + UniverConfig config = new UniverConfig(); + config.setValue(colorValue.get(k)); + config.setColor(colorColor.get(k)); + config.setIndex(k); + univerConfig.add(config); + } + resourceData.setRule(rule); + } + CTCfRule highlightCell = cfRule; + if (highlightCell != null) { + String type = highlightCell.getType().toString(); + SubTypeEnum subTypeEnum = SubTypeEnum.getType(type); + if (subTypeEnum != null) { + UniverRule rule = new UniverRule(); + rule.setType(FormatTypeEnum.highlightCell.name()); + boolean isUnique = Arrays + .asList(SubTypeEnum.uniqueValues.getType(), SubTypeEnum.duplicateValues.getType()) + .contains(subTypeEnum.getType()); + boolean isNumber = Objects.equals(SubTypeEnum.cellIs.getType(), subTypeEnum.getType()); + boolean isAverage = Objects.equals(SubTypeEnum.aboveAverage.getType(), subTypeEnum.getType()); + boolean isRank = Objects.equals(SubTypeEnum.top10.getType(), subTypeEnum.getType()); + boolean isFormula = Objects.equals(SubTypeEnum.expression.getType(), subTypeEnum.getType()); + boolean isTime = Objects.equals(SubTypeEnum.timePeriod.getType(), subTypeEnum.getType()); + List dataList = highlightCell.getFormulaList() != null ? highlightCell.getFormulaList() + : new ArrayList<>(); + List numberDataList = new ArrayList<>(); + BigDecimal numberData = null; + String textValue = ""; + for (String data : dataList) { + try { + BigDecimal bigDecimal = new BigDecimal(data); + numberDataList.add(bigDecimal); + numberData = bigDecimal; + } catch (Exception e) { + textValue = data; + } + } + if (isNumber) { + if (highlightCell.getOperator() != null) { + rule.setOperator(highlightCell.getOperator().toString()); + } + boolean isText = numberDataList.isEmpty(); + rule.setSubType(isText ? SubTypeEnum.text.getCode() : SubTypeEnum.cellIs.getCode()); + rule.setValue(isText ? textValue : numberDataList.size() > 1 ? numberDataList : numberData); + } else if (isAverage) { + rule.setSubType(subTypeEnum.getCode()); + rule.setOperator(highlightCell.getAboveAverage() ? OperatorEnum.greaterThan.name() + : OperatorEnum.lessThan.name()); + } else if (isRank) { + rule.setSubType(subTypeEnum.getCode()); + rule.setIsPercent(highlightCell.getPercent()); + rule.setIsBottom(highlightCell.getBottom()); + rule.setValue(highlightCell.getRank() + ""); + } else if (isFormula) { + rule.setSubType(SubTypeEnum.expression.getCode()); + rule.setValue("=" + textValue.replaceAll("\"", "")); + } else if (isTime) { + rule.setSubType(subTypeEnum.getCode()); + rule.setOperator(highlightCell.getTimePeriod().toString()); + } else if (isUnique) { + rule.setSubType(subTypeEnum.getType()); + } else { + rule.setSubType(SubTypeEnum.text.getCode()); + rule.setOperator( + highlightCell.getOperator() != null ? highlightCell.getOperator().toString() + : subTypeEnum.getType()); + if (highlightCell.getText() != null) { + rule.setValue(highlightCell.getText()); + } + } + UniverStyle style = new UniverStyle(); + CTDxf dxf = highlightCell.isSetDxfId() ? styles.getDxfAt((int) highlightCell.getDxfId()) : null; + if (dxf != null) { + CTFill ctFill = dxf.getFill(); + if (ctFill != null) { + CTPatternFill patternFill = ctFill.getPatternFill(); + if (patternFill != null) { + XSSFColor baColor = XSSFColor.from(patternFill.getBgColor()); + if (baColor != null) { + UniverStyleColor bg = new UniverStyleColor(); + bg.setRgb(rgb(baColor.getARGBHex())); + style.setBg(bg); + } + } + } + CTFont ctFont = dxf.getFont(); + if (ctFont != null) { + XSSFColor fontColor = ctFont.sizeOfColorArray() > 0 + ? XSSFColor.from(ctFont.getColorArray(0)) + : null; + if (fontColor != null) { + UniverStyleColor cl = new UniverStyleColor(); + cl.setRgb(rgb(fontColor.getARGBHex())); + style.setCl(cl); + } + STUnderlineValues.Enum underlineType = ctFont.sizeOfUArray() == 1 + ? ctFont.getUArray(0).getVal() + : STUnderlineValues.NONE; + if (Objects.equals(underlineType, STUnderlineValues.SINGLE)) { + UniverStyleTextDecoration ul = new UniverStyleTextDecoration(); + ul.setS(1); + style.setUl(ul); + } + boolean strike = ctFont.sizeOfStrikeArray() > 0 && ctFont.getStrikeArray(0).getVal(); + if (strike) { + UniverStyleTextDecoration st = new UniverStyleTextDecoration(); + st.setS(1); + style.setSt(st); + } + boolean isItalic = ctFont.sizeOfIArray() == 1 && ctFont.getIArray(0).getVal(); + boolean isBold = ctFont.sizeOfBArray() == 1 && ctFont.getBArray(0).getVal(); + style.setIt(isItalic ? 1 : 0); + style.setBl(isBold ? 1 : 0); + } + } + rule.setStyle(style); + resourceData.setRule(rule); + } + } + resourceData.setStopIfTrue(cfRule.getStopIfTrue()); + if (resourceData.getRule() == null) { + continue; + } + formatList.add(resourceData); + } + } + formattingMap.put(sheetId, formatList); + } + + private static void dataValidation(XSSFSheet sheet, String sheetId, String unitId, + Map> dataValidationMap) { + List dataValidationList = new ArrayList<>(); + List dataValidations = sheet.getDataValidations(); + for (XSSFDataValidation dataValidation : dataValidations) { + UniverResourceData resourceData = new UniverResourceData(); + List ranges = new ArrayList<>(); + resourceData.setRanges(ranges); + resourceData.setUid(RandomUtil.randomString(10)); + CellRangeAddressList addressList = dataValidation.getRegions(); + for (CellRangeAddress address : addressList.getGenericChildren()) { + UniverSheetRange sheetRange = new UniverSheetRange(); + sheetRange.setStartRow(address.getFirstRow()); + sheetRange.setStartColumn(address.getFirstColumn()); + sheetRange.setEndRow(address.getLastRow()); + sheetRange.setEndColumn(address.getLastColumn()); + sheetRange.setSheetId(sheetId); + sheetRange.setUnitId(unitId); + ranges.add(sheetRange); + } + DataValidationConstraint constraint = dataValidation.getValidationConstraint(); + ValidationType validationType = ValidationType.getType(constraint.getValidationType()); + resourceData.setType(validationType.getType()); + operatorTypeEnum operator = Objects.equals(validationType, ValidationType.none) ? null + : operatorTypeEnum.getOperator(constraint.getOperator()); + resourceData.setOperator(operator != null ? operator.getOperatorType() : null); + String value1 = constraint.getFormula1(); + String value2 = constraint.getFormula2(); + resourceData.setFormula1(value1 != null ? value1.replaceAll("\"", "") : value1); + resourceData.setFormula2(value2 != null ? value2.replaceAll("\"", "") : value2); + if (dataValidation.getShowErrorBox()) { + resourceData.setShowErrorMessage(true); + resourceData.setError(dataValidation.getErrorBoxTitle()); + resourceData.setErrorStyle(Objects.equals(dataValidation.getErrorStyle(), 0) ? 1 : 2); + } + resourceData.setAllowBlank(dataValidation.getEmptyCellAllowed()); + resourceData.setRenderMode(dataValidation.getSuppressDropDownArrow() ? null : 0); + dataValidationList.add(resourceData); + } + dataValidationMap.put(sheetId, dataValidationList); + } + + private void filter(XSSFSheet sheet, String sheetId, String unitId, Map filterMap) { + CTAutoFilter autoFilter = sheet.getCTWorksheet().getAutoFilter(); + UniverResourceData data = new UniverResourceData(); + if (autoFilter != null && StringUtil.isNotEmpty(autoFilter.getRef())) { + CellRangeAddress addresses = CellRangeAddress.valueOf(autoFilter.getRef()); + UniverSheetRange ref = new UniverSheetRange(); + ref.setStartRow(addresses.getFirstRow()); + ref.setStartColumn(addresses.getFirstColumn()); + ref.setEndRow(addresses.getLastRow()); + ref.setEndColumn(addresses.getLastColumn()); + data.setRef(ref); + List cachedFilteredOut = new ArrayList<>(); + // 隐藏行 + for (int rowIndex = addresses.getFirstRow(); rowIndex <= addresses.getLastRow(); rowIndex++) { + XSSFRow row = sheet.getRow(rowIndex); + if (row != null && row.getZeroHeight()) { + cachedFilteredOut.add(rowIndex); + } + } + // 筛选条件 + List filterColumnList = autoFilter.getFilterColumnList(); + List filterColumns = new ArrayList<>(); + for (CTFilterColumn filterColumn : filterColumnList) { + UniverFilters univerFilters = new UniverFilters(); + univerFilters.setColId(filterColumn.getColId()); + UniverCustomFilters customFilters = new UniverCustomFilters(); + univerFilters.setCustomFilters(customFilters); + List customFilterList = new ArrayList<>(); + customFilters.setCustomFilters(customFilterList); + // poi方法 + CTCustomFilters filters = filterColumn.getCustomFilters(); + customFilters.setAnd(filters.getAnd() ? 1 : null); + List filterList = filters.getCustomFilterList(); + for (CTCustomFilter filter : filterList) { + UniverCustomFilters univerCustomFilters = new UniverCustomFilters(); + univerCustomFilters.setVal(filter.getVal()); + univerCustomFilters + .setOperator(filter.getOperator() != null ? filter.getOperator().toString() : null); + customFilterList.add(univerCustomFilters); + } + filterColumns.add(univerFilters); + } + data.setFilterColumns(filterColumns); + data.setCachedFilteredOut(cachedFilteredOut); + filterMap.put(sheetId, data); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/pom.xml b/yunzhupaas-datareport-univer-model/pom.xml new file mode 100644 index 0000000..2645d7f --- /dev/null +++ b/yunzhupaas-datareport-univer-model/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.yunzhupaas + yunzhupaas-datareport-univer-core + 5.2.0-RELEASE + + + yunzhupaas-datareport-univer-model + + + + com.yunzhupaas + yunzhupaas-common-core + + + org.antlr + antlr4-runtime + 4.5.3 + + + com.google.zxing + javase + ${zxing.version} + + + + + + + + + diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/CellDataEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/CellDataEnum.java new file mode 100644 index 0000000..d47950d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/CellDataEnum.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.enums; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午4:28 + */ +public enum CellDataEnum { + text, chart, dataSource, parameter, expression +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/FormatTypeEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/FormatTypeEnum.java new file mode 100644 index 0000000..eaaf777 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/FormatTypeEnum.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.enums; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/26 下午12:06 + */ +public enum FormatTypeEnum { + highlightCell, colorScale, iconSet, dataBar; + + public static FormatTypeEnum getFormat(String name) { + for (FormatTypeEnum status : FormatTypeEnum.values()) { + if (Objects.equals(status.name(), name)) { + return status; + } + } + return FormatTypeEnum.highlightCell; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/HorizontalEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/HorizontalEnum.java new file mode 100644 index 0000000..521e990 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/HorizontalEnum.java @@ -0,0 +1,46 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; +import org.apache.poi.ss.usermodel.HorizontalAlignment; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2025/1/6 下午6:00 + */ +@Getter +public enum HorizontalEnum { + GENERAL(0, HorizontalAlignment.GENERAL), + LEFT(1, HorizontalAlignment.LEFT), + CENTER(2, HorizontalAlignment.CENTER), + RIGHT(3, HorizontalAlignment.RIGHT); + + private Integer code; + private HorizontalAlignment horizontal; + + HorizontalEnum(Integer code, HorizontalAlignment horizontal) { + this.code = code; + this.horizontal = horizontal; + } + + public static HorizontalAlignment getHorizontalValue(Integer code) { + for (HorizontalEnum status : HorizontalEnum.values()) { + if (Objects.equals(status.getCode(), code)) { + return status.getHorizontal(); + } + } + return HorizontalAlignment.GENERAL; + } + + public static Integer getHorizontalCode(HorizontalAlignment horizontal) { + for (HorizontalEnum status : HorizontalEnum.values()) { + if (Objects.equals(status.getHorizontal(), horizontal)) { + return status.getCode(); + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ImageEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ImageEnum.java new file mode 100644 index 0000000..52289ee --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ImageEnum.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.enums; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/25 下午3:29 + */ +public enum ImageEnum { + BASE64, URL +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/OperatorEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/OperatorEnum.java new file mode 100644 index 0000000..6970938 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/OperatorEnum.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.enums; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/12/4 下午4:40 + */ +public enum OperatorEnum { + lessThan, greaterThan, greaterThanOrEqual, min, max, middle +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ResourceEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ResourceEnum.java new file mode 100644 index 0000000..f8fe62e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ResourceEnum.java @@ -0,0 +1,56 @@ +package com.yunzhupaas.enums; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/6/20 下午5:12 + */ +public enum ResourceEnum { + + /** + * 注释 + */ + SHEET_THREAD_COMMENT_PLUGIN, + /** + * 工作表权限 + */ + SHEET_WORKSHEET_PROTECTION_PLUGIN, + /** + * 工作表单元权限 + */ + SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN, + /** + * 区域保护 + */ + SHEET_RANGE_PROTECTION_PLUGIN, + /** + * 图片 + */ + SHEET_DRAWING_PLUGIN, + /** + * 条件格式 + */ + SHEET_CONDITIONAL_FORMATTING_PLUGIN, + /** + * 超链接 + */ + SHEET_HYPER_LINK_PLUGIN, + /** + * 名称定义 + */ + SHEET_DEFINED_NAME_PLUGIN, + /** + * 数据验证 + */ + SHEET_DATA_VALIDATION_PLUGIN, + /** + * 过滤器 + */ + SHEET_FILTER_PLUGIN, + /** + * 授权服务 + */ + SHEET_AuthzIoMockService_PLUGIN + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/StyleTypeEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/StyleTypeEnum.java new file mode 100644 index 0000000..fb8218c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/StyleTypeEnum.java @@ -0,0 +1,43 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; +import org.apache.poi.ss.usermodel.BorderStyle; + +import java.util.Objects; + +@Getter +public enum StyleTypeEnum { + + NONE(0, BorderStyle.NONE), + THIN(1, BorderStyle.THIN), + HAIR(2, BorderStyle.HAIR), + DOTTED(3, BorderStyle.DOTTED), + DASHED(4, BorderStyle.DASHED), + DASH_DOT(5, BorderStyle.DASH_DOT), + DASH_DOT_DOT(6, BorderStyle.DASH_DOT_DOT), + DOUBLE(7, BorderStyle.DOUBLE), + MEDIUM(8, BorderStyle.MEDIUM), + MEDIUM_DASHED(9, BorderStyle.MEDIUM_DASHED), + MEDIUM_DASH_DOT(10, BorderStyle.MEDIUM_DASH_DOT), + MEDIUM_DASH_DOT_DOT(11, BorderStyle.MEDIUM_DASH_DOT_DOT), + SLANT_DASH_DOT(12, BorderStyle.SLANTED_DASH_DOT), + THICK(13, BorderStyle.THICK); + + private Integer code; + private BorderStyle borderStyle; + + StyleTypeEnum(Integer code, BorderStyle borderStyle) { + this.code = code; + this.borderStyle = borderStyle; + } + + public static StyleTypeEnum getStyle(Integer code) { + for (StyleTypeEnum status : StyleTypeEnum.values()) { + if (Objects.equals(status.getCode(), code)) { + return status; + } + } + return null; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/SubTypeEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/SubTypeEnum.java new file mode 100644 index 0000000..1c7b4c6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/SubTypeEnum.java @@ -0,0 +1,51 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/27 上午11:46 + */ +@Getter +public enum SubTypeEnum { + + cellIs("number", "cellIs"), + equal("equal", "equal"), + notEqual("notEqual", "notEqual"), + top10("rank", "top10"), + uniqueValues("uniqueValues", "uniqueValues"), + duplicateValues("duplicateValues", "duplicateValues"), + containsText("containsText", "containsText"), + notContainsText("notContainsText", "notContainsText"), + beginsWith("beginsWith", "beginsWith"), + endsWith("endsWith", "endsWith"), + containsBlanks("containsBlanks", "containsBlanks"), + notContainsBlanks("notContainsBlanks", "notContainsBlanks"), + containsErrors("containsErrors", "containsErrors"), + notContainsErrors("notContainsErrors", "notContainsErrors"), + expression("formula", "expression"), + aboveAverage("average", "aboveAverage"), + timePeriod("timePeriod", "timePeriod"), + text("text", "text"); + + private String code; + private String type; + + SubTypeEnum(String code, String type) { + this.code = code; + this.type = type; + } + + public static SubTypeEnum getType(String type) { + for (SubTypeEnum status : SubTypeEnum.values()) { + if (Objects.equals(status.getType(), type)) { + return status; + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/UniverDataEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/UniverDataEnum.java new file mode 100644 index 0000000..95b0b5e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/UniverDataEnum.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/21 下午3:15 + */ +@Getter +public enum UniverDataEnum { + + // 汇总方式 + none(0, "无"), + select(1, "列表"), + group(2, "分组"), + summary(3, "汇总"), + + // 填充方向 + cellDirection(4, "portrait"), + cellDefault(5, "default"), + cellNone(6, "none"), + cellCustom(7, "custom"), + cellRoot(8, "root"); + + private Integer code; + private String name; + + UniverDataEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + + public static UniverDataEnum getData(String name) { + for (UniverDataEnum status : UniverDataEnum.values()) { + if (Objects.equals(status.getName(), name)) { + return status; + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ValidationType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ValidationType.java new file mode 100644 index 0000000..fed980a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/ValidationType.java @@ -0,0 +1,52 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/12/11 上午9:41 + */ +@Getter +public enum ValidationType { + + none("any", 0), + whole("whole", 1), + decimal("decimal", 2), + list("list", 3), + checkbox("checkbox", 3), + listMultiple("listMultiple", 3), + date("date", 4), + textLength("textLength", 6), + custom("custom", 7); + + private String type; + private Integer validationType; + + ValidationType(String type, Integer validationType) { + this.type = type; + this.validationType = validationType; + } + + public static ValidationType getValidationType(String type) { + for (ValidationType status : ValidationType.values()) { + if (Objects.equals(status.getType(), type)) { + return status; + } + } + return ValidationType.none; + } + + public static ValidationType getType(Integer validationType) { + for (ValidationType status : ValidationType.values()) { + if (Objects.equals(status.getValidationType(), validationType)) { + return status; + } + } + return ValidationType.none; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/VerticalEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/VerticalEnum.java new file mode 100644 index 0000000..2175214 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/VerticalEnum.java @@ -0,0 +1,46 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; +import org.apache.poi.ss.usermodel.VerticalAlignment; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2025/1/6 下午5:54 + */ +@Getter +public enum VerticalEnum { + TOP(1, VerticalAlignment.TOP), + CENTER(2, VerticalAlignment.CENTER), + BOTTOM(3, VerticalAlignment.BOTTOM); + + private Integer code; + private VerticalAlignment vertical; + + VerticalEnum(Integer code, VerticalAlignment vertical) { + this.code = code; + this.vertical = vertical; + } + + public static VerticalAlignment getVerticalValue(Integer code) { + for (VerticalEnum status : VerticalEnum.values()) { + if (Objects.equals(status.getCode(), code)) { + return status.getVertical(); + } + } + return null; + } + + public static Integer getVerticalCode(VerticalAlignment vertical) { + for (VerticalEnum status : VerticalEnum.values()) { + if (Objects.equals(status.getVertical(), vertical)) { + return status.getCode(); + } + } + return null; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/operatorTypeEnum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/operatorTypeEnum.java new file mode 100644 index 0000000..c3c150c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/enums/operatorTypeEnum.java @@ -0,0 +1,51 @@ +package com.yunzhupaas.enums; + +import lombok.Getter; + +import java.util.Objects; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/12/11 下午3:15 + */ +@Getter +public enum operatorTypeEnum { + + none("none", -1), + between("between", 0), + notBetween("notBetween", 1), + equal("equal", 2), + NOT_EQUAL("notEqual", 3), + greaterThan("greaterThan", 4), + lessThan("lessThan", 5), + greaterThanOrEqual("greaterThanOrEqual", 6), + lessThanOrEqual("lessThanOrEqual", 7); + + private String operatorType; + private Integer operator; + + operatorTypeEnum(String operatorType, Integer operator) { + this.operatorType = operatorType; + this.operator = operator; + } + + public static operatorTypeEnum getOperator(String operatorType) { + for (operatorTypeEnum status : operatorTypeEnum.values()) { + if (Objects.equals(status.getOperatorType(), operatorType)) { + return status; + } + } + return operatorTypeEnum.none; + } + + public static operatorTypeEnum getOperator(Integer operator) { + for (operatorTypeEnum status : operatorTypeEnum.values()) { + if (Objects.equals(status.getOperator(), operator)) { + return status; + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataQuery.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataQuery.java new file mode 100644 index 0000000..9bd0975 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataQuery.java @@ -0,0 +1,20 @@ +package com.yunzhupaas.model; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/26 上午11:31 + */ +@Data +public class DataQuery { + private String sheet; + private String sheetName; + private List queryList = new ArrayList<>(); + private List sortList = new ArrayList<>(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataSortModel.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataSortModel.java new file mode 100644 index 0000000..b864af2 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/model/DataSortModel.java @@ -0,0 +1,16 @@ +package com.yunzhupaas.model; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/12/6 下午2:12 + */ +@Data +public class DataSortModel { + private String id; + private String vModel; + private String type; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartField.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartField.java new file mode 100644 index 0000000..c28e541 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartField.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.univer.chart; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午1:29 + */ +@Data +public class UniverChartField { + // 维度 + private List seriesNameField = new ArrayList<>(); + // 系列 + private List classifyNameField = new ArrayList<>(); + // 值 + private List> seriesDataField = new ArrayList<>(); + // 最大值 + private List maxField = new ArrayList<>(); + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartModel.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartModel.java new file mode 100644 index 0000000..93f7478 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/chart/UniverChartModel.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.univer.chart; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午1:26 + */ +@Data +public class UniverChartModel { + private String unitId; + private String subUnitId; + private String drawingId; + private UniverChartField field = new UniverChartField(); + private String source; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverCell.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverCell.java new file mode 100644 index 0000000..26d9e7a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverCell.java @@ -0,0 +1,20 @@ +package com.yunzhupaas.univer.data.cell; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/8/1 下午8:54 + */ +@Data +public class UniverCell implements Serializable { + private String sheet; + private Integer row; + private Integer col; + private String drawingId; + private String domId; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverDataConfig.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverDataConfig.java new file mode 100644 index 0000000..fdd98a9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/cell/UniverDataConfig.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.univer.data.cell; + +import com.yunzhupaas.enums.CellDataEnum; +import com.yunzhupaas.enums.UniverDataEnum; +import com.yunzhupaas.ureport.definition.value.AggregateType; +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverDataConfig { + // dataSource + private Integer col; + private Integer row; + private String sheet; + private String type = CellDataEnum.text.name(); + private UniverDataConfig custom; + private String field; + // 0.无 1.列表 2. 分组 3.汇总 + private Integer polymerizationType = 1; + // 汇总方式 + private String summaryType = AggregateType.sum.name(); + private String fillDirection = UniverDataEnum.cellDirection.getName(); + private String leftParentCellType = UniverDataEnum.cellNone.getName(); + private String leftParentCellCustomRowName; + private String leftParentCellCustomColName; + private String topParentCellType = UniverDataEnum.cellNone.getName(); + private String topParentCellCustomRowName; + private String topParentCellCustomColName; + + // echarts + private String drawingId; + private String unitId; + private String subUnitId; + private UniverDataConfig option; + private String classifyNameField; + private String seriesNameField; + private String seriesDataField; + private String maxField; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/custom/UniverCustom.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/custom/UniverCustom.java new file mode 100644 index 0000000..d17544c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/custom/UniverCustom.java @@ -0,0 +1,19 @@ +package com.yunzhupaas.univer.data.custom; + +import com.yunzhupaas.univer.data.cell.UniverDataConfig; +import lombok.Data; + +import java.util.*; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/25 下午2:49 + */ +@Data +public class UniverCustom { + private List cells = new ArrayList<>(); + private Map floatEcharts = new HashMap<>(); + private Map floatImages = new HashMap<>(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverConfig.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverConfig.java new file mode 100644 index 0000000..1be4469 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverConfig.java @@ -0,0 +1,26 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/21 上午11:06 + */ +@Data +public class UniverConfig { + private String operator; + private UniverValue value; + private String iconType; + private String iconId; + private Integer index; + private String color; + + private UniverValue min; + private UniverValue max; + private Boolean isGradient; + private String positiveColor; + private String nativeColor; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverCustomFilters.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverCustomFilters.java new file mode 100644 index 0000000..66c7646 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverCustomFilters.java @@ -0,0 +1,19 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +import java.util.List; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/10/18 下午1:58 + */ +@Data +public class UniverCustomFilters { + private List customFilters; + private String val; + private String operator; + private Integer and; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverDrawing.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverDrawing.java new file mode 100644 index 0000000..f968419 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverDrawing.java @@ -0,0 +1,33 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +import java.io.Serializable; + +/** + * + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverDrawing implements Serializable { + private String unitId; + private String subUnitId; + private String drawingId; + private Integer drawingType; + private String imageSourceType; + private String source; + // 悬浮图片 + private UniverTransform sheetTransform; + // 单元格图片 + private UniverTransform docTransform; + private Integer behindDoc; + private Integer layoutType; + private Integer wrapText; + private Integer distB; + private Integer distL; + private Integer distR; + private Integer distT; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverFilters.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverFilters.java new file mode 100644 index 0000000..6549bc3 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverFilters.java @@ -0,0 +1,15 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/10/18 下午1:58 + */ +@Data +public class UniverFilters { + private UniverCustomFilters customFilters; + private Long colId; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverNum.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverNum.java new file mode 100644 index 0000000..260dbf4 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverNum.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/24 下午1:31 + */ +@Data +public class UniverNum { + private String i; + private Integer row; + private Integer col; + private String sheet; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverOffset.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverOffset.java new file mode 100644 index 0000000..c670a02 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverOffset.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午6:12 + */ +@Data +public class UniverOffset { + private Integer column; + private Integer columnOffset; + private Integer row; + private Integer rowOffset; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRef.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRef.java new file mode 100644 index 0000000..bab4213 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRef.java @@ -0,0 +1,20 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/22 上午11:41 + */ +@Data +public class UniverRef implements Serializable { + private Integer count; + private String i; + private String pattern; + private String type; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRule.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRule.java new file mode 100644 index 0000000..10b76ff --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverRule.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.univer.data.resource; + +import com.yunzhupaas.univer.style.UniverStyle; +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/22 上午11:33 + */ +@Data +public class UniverRule { + private String type; + private String subType; + private String operator; + private UniverStyle style; + private Object value; + private Boolean isShowValue; + private Object config; + private Boolean isPercent; + private Boolean isBottom; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverTransform.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverTransform.java new file mode 100644 index 0000000..d3fa9de --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverTransform.java @@ -0,0 +1,34 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/10 下午6:09 + */ +@Data +public class UniverTransform { + // 悬浮图片 + private Boolean flipY; + private Boolean flipX; + private Integer skewX; + private Integer skewY; + private UniverOffset from; + private UniverOffset to; + + // 单元格图片 + private Integer relativeFrom; + private Integer posOffset; + private UniverTransform size; + private UniverTransform positionH; + private UniverTransform positionV; + + // 图片公共 + private Integer angle; + private Integer left; + private Integer top; + private Integer width; + private Integer height; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverValue.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverValue.java new file mode 100644 index 0000000..98cad1d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/data/resource/UniverValue.java @@ -0,0 +1,15 @@ +package com.yunzhupaas.univer.data.resource; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/21 上午11:09 + */ +@Data +public class UniverValue { + private Object value; + private String type; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverPreview.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverPreview.java new file mode 100644 index 0000000..aa7b2e3 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverPreview.java @@ -0,0 +1,30 @@ +package com.yunzhupaas.univer.model; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/7/4 下午4:12 + */ +@Data +public class UniverPreview { + + private String cells; + + private String snapshot; + + private String queryList; + + private String chartData; + + private String fullName; + + private String versionId; + + private Integer allowExport; + + private Integer allowPrint; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverWorkBook.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverWorkBook.java new file mode 100644 index 0000000..591b980 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/model/UniverWorkBook.java @@ -0,0 +1,37 @@ +package com.yunzhupaas.univer.model; + +import com.yunzhupaas.univer.resources.UniverResource; +import com.yunzhupaas.univer.sheet.UniverSheet; +import com.yunzhupaas.univer.style.UniverStyle; +import lombok.Data; + +import java.io.Serializable; +import java.util.*; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverWorkBook implements Serializable { + private String id; + private Integer rev; + private String name; + /** + * Univer版本 + */ + private String appVersion = "0.4.1"; + /** + * Univer语言 + */ + private String locale = "zhCN"; + /** + * 样式列表 + */ + private Map styles = new HashMap<>(); + private List sheetOrder = new ArrayList<>(); + private Map sheets = new HashMap<>(); + private List resources = new ArrayList<>(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBody.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBody.java new file mode 100644 index 0000000..80f1ec9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBody.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.univer.properties; + +import lombok.Data; + +import java.util.List; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/5 下午3:58 + */ +@Data +public class UniverBody { + private String dataStream; + private List textRuns; + private List tables; + private List sectionBreaks; + private List paragraphs; + private List customDecorations; + private List customBlocks; + private List customRanges; + private UniverBodyConfig settings; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBodyConfig.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBodyConfig.java new file mode 100644 index 0000000..cba1694 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverBodyConfig.java @@ -0,0 +1,58 @@ +package com.yunzhupaas.univer.properties; + +import com.yunzhupaas.univer.style.UniverStyle; +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/5 下午4:08 + */ +@Data +public class UniverBodyConfig { + private Integer startIndex; + private UniverBodyConfig paragraphStyle; + private Integer horizontalAlign; + private Integer rangeType; + private String rangeId; + private String url; + private UniverBodyConfig properties; + + private Integer ed; + private String sId; + private String id; + private Integer st; + private UniverStyle ts; + + private Integer endIndex; + private String tableId; + + private Integer charSpace; + private Integer paddingEnd; + private Integer width; + + private String defaultFooterId; + private String defaultHeaderId; + private String evenPageFooterId; + private String evenPageHeaderId; + private String firstPageFooterId; + private String firstPageHeaderId; + + private Integer linePitch; + private Integer marginBottom; + private Integer marginFooter; + private Integer marginHeader; + private Integer marginLeft; + private Integer marginRight; + private Integer marginTop; + private Integer pageNumberStart; + private Integer useFirstPageHeaderFooter; + + private Integer zoomRatio; + + private String blockId; + private Integer blockType; + private Integer type; + private Boolean wholeEntity; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyle.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyle.java new file mode 100644 index 0000000..064809d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyle.java @@ -0,0 +1,43 @@ +package com.yunzhupaas.univer.properties; + +import com.yunzhupaas.univer.style.UniverStyle; +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/5 下午3:55 + */ +@Data +public class UniverDocumentStyle { + + private Integer autoHyphenation; + private Integer characterSpacingControl; + private Integer consecutiveHyphenLimit; + private String defaultFooterId; + private String defaultHeaderId; + private Integer defaultTabStop; + private Integer doNotHyphenateCaps; + private Integer documentFlavor; + private Integer evenAndOddHeaders; + private String evenPageFooterId; + private String evenPageHeaderId; + private String firstPageFooterId; + private String firstPageHeaderId; + private Integer hyphenationZone; + private Integer marginBottom; + private Integer marginFooter; + private Integer marginHeader; + private Integer marginLeft; + private Integer marginRight; + private Integer marginTop; + private Integer pageNumberStart; + private Integer pageOrient; + private UniverDocumentStyleConfig pageSize; + private Integer paragraphLineGapDefault; + private UniverDocumentStyleConfig renderConfig; + private Boolean spaceWidthEastAsian; + private UniverStyle textStyle; + private Boolean useFirstPageHeaderFooter; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyleConfig.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyleConfig.java new file mode 100644 index 0000000..6fd5f06 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverDocumentStyleConfig.java @@ -0,0 +1,21 @@ +package com.yunzhupaas.univer.properties; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/5 下午3:55 + */ +@Data +public class UniverDocumentStyleConfig { + private Integer width; + private Integer height; + private Integer background; + private Integer horizontalAlign; + private Integer verticalAlign; + private Integer centerAngle; + private Integer vertexAngle; + private Integer wrapStrategy; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverProperties.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverProperties.java new file mode 100644 index 0000000..cebed72 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/properties/UniverProperties.java @@ -0,0 +1,33 @@ +package com.yunzhupaas.univer.properties; + +import com.yunzhupaas.univer.data.resource.UniverDrawing; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/5 下午5:54 + */ +@Data +public class UniverProperties { + private UniverBody body; + private Boolean disabled; + private UniverDocumentStyle documentStyle; + private Map drawings; + private List drawingsOrder; + private Map footers; + private List headerFooterDrawingsOrder; + private Map headers; + private String id; + private Map lists; + private String locale; + private Map resources; + private Integer rev; + private UniverBodyConfig settings; + private Map tableSource; + private String title; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResource.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResource.java new file mode 100644 index 0000000..14201b9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResource.java @@ -0,0 +1,16 @@ +package com.yunzhupaas.univer.resources; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverResource { + private String id; + private String name; + private String data; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResourceData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResourceData.java new file mode 100644 index 0000000..df2d8f0 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/resources/UniverResourceData.java @@ -0,0 +1,67 @@ +package com.yunzhupaas.univer.resources; + +import com.yunzhupaas.univer.data.resource.*; +import com.yunzhupaas.univer.sheet.UniverSheetRange; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/22 下午2:10 + */ +@Data +public class UniverResourceData { + // SHEET_DATA_VALIDATION + private String uid; + private String operator; + private String formula1; + private String formula2; + private String error; + private Integer renderMode; + private Boolean allowBlank; + private Integer errorStyle; + private Boolean showErrorMessage; + + // SHEET_NUMFMT_PLUGIN + private Map>> model; + private List refModel; + private List numModel; + + // SHEET_CONDITIONAL_FORMATTING_PLUGIN + private String cfId; + private UniverRule rule; + private Boolean stopIfTrue; + + // SHEET_CONDITIONAL_FORMATTING_PLUGIN、SHEET_DATA_VALIDATION、SHEET_RANGE_PROTECTION + private List ranges; + + // SHEET_NUMFMT_PLUGIN、SHEET_DATA_VALIDATION + private String type; + + // SHEET_DEFINED_NAME_PLUGIN + private String id; + private String name; + private String formulaOrRefString; + private String comment; + private String localSheetId; + + // SHEET_RANGE_PROTECTION + private String permissionId; + private String unitType; + private String unitId; + private String subUnitId; + + // SHEET_DRAWING_PLUGIN + private List order; + private Map data; + + // SHEET_FILTER_PLUGIN + private UniverSheetRange ref; + private List filterColumns; + private List cachedFilteredOut; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheet.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheet.java new file mode 100644 index 0000000..8c4f731 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheet.java @@ -0,0 +1,38 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheet implements Serializable { + private String id; + private String name; + private String tabColor; + private Integer hidden; + private UniverSheetFreeze freeze; + private Integer rowCount; + private Integer columnCount; + private Integer zoomRatio; + private Integer scrollTop; + private Integer scrollLeft; + private Integer defaultColumnWidth; + private Integer defaultRowHeight; + private List mergeData; + private Map> cellData; + private Map rowData; + private Map columnData; + private UniverSheetRowHeader rowHeader; + private UniverSheetColumnHeader columnHeader; + private Integer showGridlines; + private List selections; + private Integer rightToLeft; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCell.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCell.java new file mode 100644 index 0000000..9b5afbc --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCell.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetCell implements Serializable { + private Integer row; + private Integer column; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCellData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCellData.java new file mode 100644 index 0000000..97a8241 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetCellData.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetCellData implements Serializable { + /** + * The unique key, a random string, is used for the plug-in to associate the + * cell. When the cell information changes, + * the plug-in does not need to change the data, reducing the pressure on the + * back-end interface id?: string. + */ + private Object p; + + /** + * style id + * UniverStyle | String + */ + private Object s; + + /** + * Origin value + * String | Integer | Boolean + */ + private Object v; + + // Usually the type is automatically determined based on the data, or the user + // directly specifies + // 1 string, 2 number, 3 boolean, 4 force string, green icon, set null for cell + // clear all + private Integer t; + + /** + * Raw formula string. For example `=SUM(A1:B4)`. + */ + private String f; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnData.java new file mode 100644 index 0000000..3b37765 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnData.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetColumnData implements Serializable { + /** + * width + */ + private Integer w; + /** + * hidden + */ + private Integer hd; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnHeader.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnHeader.java new file mode 100644 index 0000000..a5b6415 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetColumnHeader.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetColumnHeader implements Serializable { + private Integer height; + private Integer hidden; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetFreeze.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetFreeze.java new file mode 100644 index 0000000..a600102 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetFreeze.java @@ -0,0 +1,19 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetFreeze implements Serializable { + private Integer xSplit = 0; + private Integer ySplit = 0; + private Integer startRow = -1; + private Integer startColumn = -1; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRange.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRange.java new file mode 100644 index 0000000..6391c46 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRange.java @@ -0,0 +1,47 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetRange implements Serializable { + /** + * The start row (inclusive) of the range + * startRow + */ + private Integer startRow; + + /** + * The end row (exclusive) of the range + * endRow + */ + private Integer endRow; + /** + * The start column (inclusive) of the range + * startColumn + */ + private Integer startColumn; + + /** + * The end column (exclusive) of the range + * endColumn + */ + private Integer endColumn; + + private Integer rangeType; + + private Integer startAbsoluteRefType; + + private Integer endAbsoluteRefType; + + private String unitId; + + private String sheetId; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowData.java new file mode 100644 index 0000000..d51f6e1 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowData.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetRowData implements Serializable { + /** + * height in pixel + */ + private Integer h; + /** + * is current row self-adaptive to its content, use `ah` to set row height when + * true, else use `h`. + */ + private Integer ia; // pre name `isAutoHeight` + /** + * auto height + */ + private Integer ah; + /** + * hidden + */ + private Integer hd; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowHeader.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowHeader.java new file mode 100644 index 0000000..5544560 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/sheet/UniverSheetRowHeader.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.sheet; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverSheetRowHeader implements Serializable { + private Integer width; + private Integer hidden; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyle.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyle.java new file mode 100644 index 0000000..d9652ff --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyle.java @@ -0,0 +1,98 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyle implements Serializable { + /** + * fontFamily + */ + private String ff; + /** + * fontSize + *

+ * pt + */ + private Integer fs; + /** + * italic + * 0: false + * 1: true + */ + private Integer it; + /** + * bold + * 0: false + * 1: true + */ + private Integer bl; + + /** + * underline + */ + private UniverStyleTextDecoration ul; + /** + * strikethrough + */ + private UniverStyleTextDecoration st; + /** + * overline + */ + private UniverStyleTextDecoration ol; + + /** + * background + */ + private UniverStyleColor bg; + + /** + * border + */ + private UniverStyleBorder bd; + + /** + * foreground + */ + private UniverStyleColor cl; + + /** + * (1.正常 2.Subscript 下标 3.Superscript上标 ) + */ + private Integer va; + /** + * textRotation + */ + private UniverStyleTextRotation tr; + /** + * textDirection + */ + private Integer td; + /** + * horizontalAlignment + */ + private Integer ht; + /** + * verticalAlignment + */ + private Integer vt; + /** + * wrapStrategy + */ + private Integer tb; + /** + * padding + */ + private UniverStylePadding pd; + /** + * dataFormat + */ + private UniverStylePattern n; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorder.java new file mode 100644 index 0000000..a8cc77d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorder.java @@ -0,0 +1,35 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * Style properties of top, bottom, left and right border + * TLBR = 'tlbr', //START_TOP_LEFT_END_BOTTOM_RIGHT + * TLBC = 'tlbc', // START_TOP_LEFT_END_BOTTOM_CENTER + * TLMR = 'tlmr', // START_TOP_LEFT_END_MIDDLE_RIGHT + * BLTR = 'bltr', // START_BOTTOM_LEFT_END_TOP_RIGHT + * MLTR = 'mltr', // START_MIDDLE_LEFT_END_TOP_RIGHT + * BCTR = 'bctr', // START_BOTTOM_CENTER_END_TOP_RIGHT + * + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyleBorder implements Serializable { + private UniverStyleBorderStyle t; + private UniverStyleBorderStyle r; + private UniverStyleBorderStyle b; + private UniverStyleBorderStyle l; + + private UniverStyleBorderStyle tl_br; + private UniverStyleBorderStyle tl_bc; + private UniverStyleBorderStyle tl_mr; + + private UniverStyleBorderStyle bl_tr; + private UniverStyleBorderStyle ml_tr; + private UniverStyleBorderStyle bc_tr; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorderStyle.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorderStyle.java new file mode 100644 index 0000000..17b5514 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleBorderStyle.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyleBorderStyle implements Serializable { + private Integer s; + private UniverStyleColor cl; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleColor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleColor.java new file mode 100644 index 0000000..e3a0079 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleColor.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyleColor implements Serializable { + private String rgb; + private Object th; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePadding.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePadding.java new file mode 100644 index 0000000..6bcbf28 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePadding.java @@ -0,0 +1,19 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStylePadding implements Serializable { + private Integer t; + private Integer r; + private Integer b; + private Integer l; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePattern.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePattern.java new file mode 100644 index 0000000..5a2c8f8 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStylePattern.java @@ -0,0 +1,14 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/6 上午9:00 + */ +@Data +public class UniverStylePattern { + private String pattern; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextDecoration.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextDecoration.java new file mode 100644 index 0000000..8fc22b7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextDecoration.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyleTextDecoration implements Serializable { + // show + private Integer s; + // color is follow the font color. the default value is TRUE, it's also TRUE if + // it is undefined. the cl has no effect when `c` is TRUE. + private Integer c; + // color + private UniverStyleColor cl; + // lineType + private Object t; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextRotation.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextRotation.java new file mode 100644 index 0000000..abd92bd --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/univer/style/UniverStyleTextRotation.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.univer.style; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/5/11 下午4:35 + */ +@Data +public class UniverStyleTextRotation implements Serializable { + /** + * angle + */ + private int a; + /** + * vertical + * true : 1 + * false : 0 + */ + private int v; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/Range.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/Range.java new file mode 100644 index 0000000..d6041cb --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/Range.java @@ -0,0 +1,15 @@ +package com.yunzhupaas.ureport; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class Range { + private int start = -1; + private int end; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/BindData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/BindData.java new file mode 100644 index 0000000..dcd0b03 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/BindData.java @@ -0,0 +1,15 @@ +package com.yunzhupaas.ureport.build; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +@Setter +@Getter +public class BindData { + private Object value; + private List> dataList; + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Context.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Context.java new file mode 100644 index 0000000..01323f3 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Context.java @@ -0,0 +1,169 @@ +package com.yunzhupaas.ureport.build; + +import com.yunzhupaas.ureport.definition.value.SimpleValue; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.expression.util.ElCompute; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.model.Report; +import com.yunzhupaas.ureport.model.Row; +import lombok.Getter; +import lombok.Setter; + +import java.util.*; + +@Getter +@Setter +public class Context { + private Report report; + private Cell rootCell; + private ReportBuilder reportBuilder; + private Map datasetMap; + private Map variableMap = new HashMap<>(); + private Map> currentPageRowsMap = new HashMap<>(); + private Map> blankCellsMap = new HashMap<>(); + private Map> unprocessedCellsMap = new HashMap<>(); + + public Context(ReportBuilder reportBuilder, Report report, Map datasetMap) { + this.reportBuilder = reportBuilder; + this.report = report; + report.setContext(this); + this.datasetMap = datasetMap; + Map> cellsMap = report.getCellsMap(); + for (String key : cellsMap.keySet()) { + if (key.equals(report.getRootCell().getName())) { + continue; + } + List list = new ArrayList<>(); + list.addAll(cellsMap.get(key)); + unprocessedCellsMap.put(key, list); + } + this.rootCell = new Cell(); + this.rootCell.setName("ROOT"); + } + + public List nextUnprocessedCells() { + if (unprocessedCellsMap.size() == 0) { + return null; + } + List targetCellsList = null; + String targetCellName = null; + Set keySet = unprocessedCellsMap.keySet(); + for (String cellName : keySet) { + List cells = unprocessedCellsMap.get(cellName); + Cell cell = cells.get(0); + Value value = cell.getValue(); + Cell leftParent = cell.getLeftParentCell(); + Cell topParent = cell.getTopParentCell(); + if ((leftParent == null || leftParent.isProcessed()) && (topParent == null || topParent.isProcessed())) { + targetCellsList = cells; + targetCellName = cellName; + break; + } + if (value instanceof SimpleValue) { + targetCellsList = cells; + targetCellName = cellName; + break; + } + } + unprocessedCellsMap.remove(targetCellName); + return targetCellsList; + } + + public List buildCellData(Cell cell) { + return DataCompute.buildCellData(cell, this); + } + + public void addReportCell(Cell newCell) { + report.addCell(newCell); + } + + public void addCell(Cell newCell) { + addReportCell(newCell); + addUnprocessedCell(newCell); + } + + public void addUnprocessedCell(Cell cell) { + String cellName = cell.getName(); + List cells = null; + if (unprocessedCellsMap.containsKey(cellName)) { + cells = unprocessedCellsMap.get(cellName); + } else { + cells = new ArrayList<>(); + unprocessedCellsMap.put(cellName, cells); + } + + int lastIdx = report.findSameLeftCell(cells, cell, 0); + if (lastIdx > -1 && lastIdx < cells.size() - 1) { + cells.add(lastIdx + 1, cell); + } else { + cells.add(cell); + } + } + + public List> getDatasetData(String name) { + List> list = new ArrayList<>(); + if (datasetMap.containsKey(name)) { + list.addAll(datasetMap.get(name).getData()); + } + return list; + } + + public Row getRow(int rowNumber) { + return report.getRow(rowNumber); + } + + public Column getColumn(int columnNumber) { + return report.getColumn(columnNumber); + } + + public void addBlankCell(Cell cell) { + cell.setBlankCell(true); + Row row = cell.getRow(); + Column column = cell.getColumn(); + Map cellMap = blankCellsMap.get(row); + if (cellMap == null) { + cellMap = new HashMap<>(); + blankCellsMap.put(row, cellMap); + } + cellMap.put(column, cell); + addReportCell(cell); + } + + public Cell getBlankCell(Row row, Column column) { + Map colCellMap = blankCellsMap.get(row); + if (colCellMap == null) { + return null; + } + Cell targetCell = colCellMap.get(column); + return targetCell; + } + + public void removeBlankCell(Cell blankCell) { + Row row = blankCell.getRow(); + Column col = blankCell.getColumn(); + Map colCellMap = blankCellsMap.get(row); + colCellMap.remove(col); + } + + public void putVariable(String key, Object value) { + variableMap.put(key, value); + } + + public Object evalExpr(String expression) { + return new ElCompute().doCompute(expression); + } + + public boolean isCellPocessed(String cellName) { + return !unprocessedCellsMap.containsKey(cellName); + } + + public List getCurrentPageRows(int index) { + return currentPageRowsMap.get(index); + } + + public Object getVariable(String key) { + return variableMap.get(key); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DataCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DataCompute.java new file mode 100644 index 0000000..d40a7b5 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DataCompute.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.ureport.build; + +import com.google.common.collect.ImmutableMap; +import com.yunzhupaas.ureport.compute.DatasetValueCompute; +import com.yunzhupaas.ureport.compute.SimpleValueCompute; +import com.yunzhupaas.ureport.compute.ValueCompute; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.definition.value.ValueType; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class DataCompute { + + @SuppressWarnings("null") + private static Map valueComputesMap = ImmutableMap.of( + ValueType.simple.name(), new SimpleValueCompute(), + ValueType.dataset.name(), new DatasetValueCompute()); + + public static List buildCellData(Cell cell, Context context) { + Value value = cell.getValue(); + ValueCompute valueCompute = valueComputesMap.get(value.getType()); + if (valueCompute == null) { + valueCompute = valueComputesMap.get(ValueType.simple.name()); + } + List list = valueCompute.compute(cell, context); + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Dataset.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Dataset.java new file mode 100644 index 0000000..a486276 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/Dataset.java @@ -0,0 +1,14 @@ +package com.yunzhupaas.ureport.build; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +@Setter +@Getter +public class Dataset { + private String name; + private List> data; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DatasetUtils.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DatasetUtils.java new file mode 100644 index 0000000..512f8d7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/DatasetUtils.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.ureport.build; + +import com.google.common.collect.ImmutableMap; +import com.yunzhupaas.ureport.build.aggregate.*; +import com.yunzhupaas.ureport.definition.value.AggregateType; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; +import java.util.Map; + +public class DatasetUtils { + + private static Map aggregates = ImmutableMap.of( + AggregateType.group, new GroupAggregate(), + AggregateType.select, new SelectAggregate(), + AggregateType.avg, new AvgAggregate(), + AggregateType.count, new CountAggregate(), + AggregateType.sum, new SumAggregate(), + AggregateType.min, new MinAggregate(), + AggregateType.max, new MaxAggregate(), + AggregateType.none, new NoneAggregate()); + + public static List computeDatasetExpression(DatasetValue datasetValue, Cell cell, Context context) { + AggregateType type = datasetValue.getAggregate(); + Aggregate aggregate = aggregates.get(type); + if (aggregate == null) { + aggregate = aggregates.get(AggregateType.select); + } + return aggregate.aggregate(datasetValue, cell, context); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/ReportBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/ReportBuilder.java new file mode 100644 index 0000000..7779b99 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/ReportBuilder.java @@ -0,0 +1,60 @@ +package com.yunzhupaas.ureport.build; + +import com.yunzhupaas.ureport.cell.CellBuilder; +import com.yunzhupaas.ureport.cell.down.DownExpandBuilder; +import com.yunzhupaas.ureport.cell.none.NoneExpandBuilder; +import com.yunzhupaas.ureport.cell.right.RightExpandBuilder; +import com.yunzhupaas.ureport.definition.Expand; +import com.yunzhupaas.ureport.definition.ReportDefinition; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Report; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReportBuilder { + private Map cellBuildersMap = new HashMap<>(); + + public ReportBuilder() { + cellBuildersMap.put(Expand.Down, new DownExpandBuilder()); + cellBuildersMap.put(Expand.None, new NoneExpandBuilder()); + cellBuildersMap.put(Expand.Right, new RightExpandBuilder()); + } + + public Report buildReport(ReportDefinition reportDefinition) { + Report report = reportDefinition.newReport(); + Map datasetMap = reportDefinition.getDatasetMap(); + Context context = new Context(this, report, datasetMap); + List cells = new ArrayList<>(); + cells.add(report.getRootCell()); + do { + buildCell(context, cells); + cells = context.nextUnprocessedCells(); + } while (cells != null); + return report; + } + + public void buildCell(Context context, List cells) { + if (cells == null) { + cells = context.nextUnprocessedCells(); + } + if (cells == null) { + return; + } + CellBuilder noneExpandBuilder = new NoneExpandBuilder(); + for (Cell cell : cells) { + List dataList = context.buildCellData(cell); + cell.setProcessed(true); + int size = dataList.size(); + if (size == 1) { + noneExpandBuilder.buildCell(dataList, cell, context); + } else if (size > 1) { + CellBuilder cellBuilder = cellBuildersMap.get(cell.getExpand()); + cellBuilder.buildCell(dataList, cell, context); + } + } + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/Aggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/Aggregate.java new file mode 100644 index 0000000..c2aca48 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/Aggregate.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.*; + +/** + * @author + * @since 2016年12月21日 + */ +public abstract class Aggregate { + + public abstract List aggregate(DatasetValue expr, Cell cell, Context context); + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/AvgAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/AvgAggregate.java new file mode 100644 index 0000000..07fe87e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/AvgAggregate.java @@ -0,0 +1,40 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 1月20日 + */ +public class AvgAggregate extends Aggregate { + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List bindDataList = DataUtils.dataList(expr, objList); + BigDecimal result = bindDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); + if (!objList.isEmpty()) { + result = result.divide(new BigDecimal(objList.size()), RoundingMode.HALF_UP); + } + BindData bindData = new BindData(); + bindData.setValue(result.doubleValue()); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/CountAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/CountAggregate.java new file mode 100644 index 0000000..754a3fe --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/CountAggregate.java @@ -0,0 +1,29 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class CountAggregate extends Aggregate { + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + BindData bindData = new BindData(); + bindData.setValue(objList.size()); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/GroupAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/GroupAggregate.java new file mode 100644 index 0000000..cc346b1 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/GroupAggregate.java @@ -0,0 +1,52 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.text.Collator; +import java.util.*; + +public class GroupAggregate extends Aggregate { + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List list = new ArrayList<>(); + String property = expr.getProperty(); + Map>> map = new LinkedHashMap<>(); + for (Map obj : objList) { + List> rowList = new ArrayList<>(); + Object value = obj.get(property) != null ? obj.get(property) : ""; + if (map.containsKey(value)) { + rowList = map.get(value); + } + rowList.add(obj); + map.put(value, rowList); + } + for (Object key : map.keySet()) { + BindData bindData = new BindData(); + bindData.setValue(key); + bindData.setDataList(map.get(key)); + list.add(bindData); + } + if (list.size() == 0) { + List> rowList = new ArrayList<>(); + rowList.add(new HashMap<>()); + BindData bindData = new BindData(); + bindData.setValue(""); + bindData.setDataList(rowList); + list.add(bindData); + } + Collator collator = Collator.getInstance(Locale.CHINA); + list.sort(Comparator.comparing(BindData::getValue, collator)); + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MaxAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MaxAggregate.java new file mode 100644 index 0000000..30b5335 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MaxAggregate.java @@ -0,0 +1,37 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class MaxAggregate extends Aggregate { + + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List bindDataList = DataUtils.dataList(expr, objList); + if (bindDataList.isEmpty()) { + bindDataList.add(new BigDecimal(0)); + } + BigDecimal result = bindDataList.stream().reduce(bindDataList.get(0), BigDecimal::max); + BindData bindData = new BindData(); + bindData.setValue(result.doubleValue()); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MinAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MinAggregate.java new file mode 100644 index 0000000..e7ff682 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/MinAggregate.java @@ -0,0 +1,37 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class MinAggregate extends Aggregate { + + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List bindDataList = DataUtils.dataList(expr, objList); + if (bindDataList.isEmpty()) { + bindDataList.add(new BigDecimal(0)); + } + BigDecimal result = bindDataList.stream().reduce(bindDataList.get(0), BigDecimal::min); + BindData bindData = new BindData(); + bindData.setValue(result.doubleValue()); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/NoneAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/NoneAggregate.java new file mode 100644 index 0000000..99668a7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/NoneAggregate.java @@ -0,0 +1,44 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/13 下午5:17 + */ +public class NoneAggregate extends Aggregate { + + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List dataList = new ArrayList<>(); + String property = expr.getProperty(); + for (Map o : objList) { + Object data = o.get(property); + dataList.add(data != null ? data.toString() : ""); + } + BindData bindData = new BindData(); + bindData.setDataList(objList); + bindData.setValue(String.join(",", dataList)); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SelectAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SelectAggregate.java new file mode 100644 index 0000000..93878c2 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SelectAggregate.java @@ -0,0 +1,41 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.*; + +public class SelectAggregate extends Aggregate { + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + return doAggregate(expr, cell, context, objList); + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List list = new ArrayList<>(); + String property = expr.getProperty(); + for (Map o : objList) { + List> bindList = new ArrayList<>(); + bindList.add(o); + Object data = o.get(property); + BindData bindData = new BindData(); + bindData.setDataList(bindList); + bindData.setValue(data); + list.add(bindData); + } + if (list.size() == 0) { + List> rowList = new ArrayList<>(); + rowList.add(new HashMap<>()); + BindData bindData = new BindData(); + bindData.setValue(""); + bindData.setDataList(rowList); + list.add(bindData); + } + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SumAggregate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SumAggregate.java new file mode 100644 index 0000000..e5a3244 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/build/aggregate/SumAggregate.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.ureport.build.aggregate; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class SumAggregate extends Aggregate { + @Override + public List aggregate(DatasetValue expr, Cell cell, Context context) { + List> objList = DataUtils.fetchData(cell, context, expr.getDatasetName()); + List list = doAggregate(expr, cell, context, objList); + return list; + } + + protected List doAggregate(DatasetValue expr, Cell cell, Context context, + List> objList) { + List bindDataList = DataUtils.dataList(expr, objList); + BigDecimal result = bindDataList.stream().reduce(BigDecimal.YUNZHUPAAS, BigDecimal::add); + BindData bindData = new BindData(); + bindData.setValue(result.doubleValue()); + List list = new ArrayList<>(); + list.add(bindData); + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/CellBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/CellBuilder.java new file mode 100644 index 0000000..f25e735 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/CellBuilder.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.ureport.cell; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; + +public interface CellBuilder { + Cell buildCell(List dataList, Cell cell, Context context); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/DuplicateType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/DuplicateType.java new file mode 100644 index 0000000..e6c44dc --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/DuplicateType.java @@ -0,0 +1,5 @@ +package com.yunzhupaas.ureport.cell; + +public enum DuplicateType { + Duplicate, IncreaseSpan, Blank, Self; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicateUnit.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicateUnit.java new file mode 100644 index 0000000..f1f6a1e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicateUnit.java @@ -0,0 +1,80 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Row; +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Setter +@Getter +public class CellDownDuplicateUnit { + private Cell mainCell; + private int mainCellRowNumber; + private Context context; + private String groupId; + private DownDuplicate downDuplicate; + private DownDuplocatorWrapper downDuplocatorWrapper; + + public CellDownDuplicateUnit(Context context, DownDuplocatorWrapper downDuplocatorWrapper, Cell mainCell, + int mainCellRowNumber, int rowSize) { + this.context = context; + this.downDuplocatorWrapper = downDuplocatorWrapper; + this.mainCell = mainCell; + this.mainCellRowNumber = mainCellRowNumber; + this.downDuplicate = new DownDuplicate(mainCell, rowSize, context); + } + + public void duplicate(Cell cell, int index) { + Map newCellMap = new HashMap<>(); + newCellMap.put(mainCell, cell); + downDuplicate.setIndex(index); + for (CellDownDuplicator childDuplicator : downDuplocatorWrapper.getMainCellChildren()) { + Cell newCell = childDuplicator.duplicateChildrenCell(downDuplicate, cell, mainCell, false); + newCell.setDataList(cell.getDataList()); + newCell.setLeftGroupId(groupId); + newCellMap.put(childDuplicator.getCell(), newCell); + processChildrenCells(newCell, childDuplicator.getCell(), newCellMap, downDuplicate, + childDuplicator.isNonChild()); + childDuplicator.setNonChild(false); + } + for (CellDownDuplicator cellDownDuplicator : downDuplocatorWrapper.getCellDuplicators()) { + cellDownDuplicator.duplicate(downDuplicate, cell); + } + Row newRow = downDuplicate.newRow(cell.getRow(), mainCellRowNumber); + cell.setRow(newRow); + newRow.getCells().add(cell); + cell.getColumn().getCells().add(cell); + context.addReportCell(cell); + downDuplicate.reset(); + for (Cell newCell : newCellMap.values()) { + Cell originTopCell = newCell.getTopParentCell(); + if (originTopCell != null && newCellMap.containsKey(originTopCell)) { + newCell.setTopParentCell(newCellMap.get(originTopCell)); + } + } + } + + public void complete() { + downDuplicate.complete(); + } + + private void processChildrenCells(Cell cell, Cell originalCell, Map newCellMap, + DownDuplicate downDuplicate, boolean parentNonChild) { + List childCellDownDuplicators = downDuplocatorWrapper.fetchChildrenDuplicator(originalCell); + if (childCellDownDuplicators == null) { + return; + } + for (CellDownDuplicator duplicator : childCellDownDuplicators) { + Cell newCell = duplicator.duplicateChildrenCell(downDuplicate, cell, originalCell, parentNonChild); + newCell.setLeftGroupId(groupId); + newCellMap.put(duplicator.getCell(), newCell); + processChildrenCells(newCell, duplicator.getCell(), newCellMap, downDuplicate, duplicator.isNonChild()); + duplicator.setNonChild(false); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicator.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicator.java new file mode 100644 index 0000000..b4cd03f --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/CellDownDuplicator.java @@ -0,0 +1,160 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.enums.UniverDataEnum; +import com.yunzhupaas.univer.sheet.UniverSheetCellData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.definition.value.SimpleValue; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Row; +import com.yunzhupaas.ureport.utils.DataUtils; +import lombok.Getter; +import lombok.Setter; + +import java.util.Objects; + +@Getter +@Setter +public class CellDownDuplicator { + private Cell cell; + private int cellRowNumber; + private DuplicateType duplicateType; + private BlankCellInfo blankCellInfo; + private boolean nonChild = false; + + public CellDownDuplicator(Cell cell, DuplicateType duplicateType, int cellRowNumber) { + this.cell = cell; + this.cellRowNumber = cellRowNumber; + this.duplicateType = duplicateType; + } + + public CellDownDuplicator(Cell cell, DuplicateType duplicateType, BlankCellInfo blankCellInfo, int cellRowNumber) { + this.cell = cell; + if (cellRowNumber == 0) { + this.cellRowNumber = cell.getRow().getRowNumber(); + } else { + this.cellRowNumber = cellRowNumber; + } + this.duplicateType = duplicateType; + this.blankCellInfo = blankCellInfo; + } + + public Cell duplicateChildrenCell(DownDuplicate downDuplicate, Cell leftParent, Cell originalCell, + boolean parentNonChild) { + Cell newCell = cell.newCell(); + Row newRow = downDuplicate.newRow(newCell.getRow(), cellRowNumber); + newRow.getCells().add(newCell); + newCell.getColumn().getCells().add(newCell); + newCell.setRow(newRow); + if (newCell.getLeftParentCell() == originalCell) { + newCell.setLeftParentCell(leftParent); + if (parentNonChild) { + nonChild = true; + } + } else { + nonChild = true; + } + Cell leftParentCell = newCell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newCell); + } + Cell topParentCell = newCell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newCell); + } + Value value = newCell.getValue(); + Context context = downDuplicate.getContext(); + String leftType = newCell.getLeftType(); + String topType = newCell.getTopType(); + DataUtils.cellList(newCell, true, true); + if (value instanceof SimpleValue) { + newCell.setData(value.getValue()); + newCell.setProcessed(true); + context.addReportCell(newCell); + if (isSimpleValue(value, leftType, topType)) { + newCell.setData(""); + // newCell.setCellData(new UniverSheetCellData()); + } + } else { + if (nonChild) { + newCell.setValue(new SimpleValue("")); + } else { + context.addCell(newCell); + } + } + return newCell; + } + + public Cell duplicate(DownDuplicate downDuplicate, Cell newMainCell) { + switch (duplicateType) { + case Blank: + processBlankCell(downDuplicate, newMainCell); + break; + case Self: + processSelfBlankCell(downDuplicate); + break; + case IncreaseSpan: + processIncreaseSpanCell(downDuplicate); + break; + } + return null; + } + + private void processBlankCell(DownDuplicate downDuplicate, Cell newMainCell) { + Context context = downDuplicate.getContext(); + Cell newBlankCell = cell.newRowBlankCell(context, blankCellInfo, downDuplicate.getMainCell()); + if (blankCellInfo.isParent() && newMainCell.getLeftParentCell() == cell) { + newMainCell.setLeftParentCell(newBlankCell); + } + Row newRow = downDuplicate.newRow(newBlankCell.getRow(), cellRowNumber); + newRow.getCells().add(newBlankCell); + newBlankCell.getColumn().getCells().add(newBlankCell); + newBlankCell.setRow(newRow); + context.addReportCell(newBlankCell); + } + + private void processSelfBlankCell(DownDuplicate downDuplicate) { + Cell newBlankCell = cell.newCell(); + newBlankCell.setValue(new SimpleValue("")); + Row newRow = downDuplicate.newRow(newBlankCell.getRow(), cellRowNumber); + newRow.getCells().add(newBlankCell); + newBlankCell.getColumn().getCells().add(newBlankCell); + newBlankCell.setRow(newRow); + Cell leftParentCell = newBlankCell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newBlankCell); + } + Cell topParentCell = newBlankCell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newBlankCell); + } + Context context = downDuplicate.getContext(); + context.addBlankCell(newBlankCell); + } + + private void processIncreaseSpanCell(DownDuplicate downDuplicate) { + int rowSpan = cell.getRowSpan(); + Value value = cell.getValue(); + String leftType = cell.getLeftType(); + String topType = cell.getTopType(); + if (isSimpleValue(value, leftType, topType)) { + return; + } + rowSpan += downDuplicate.getRowSize(); + if (rowSpan == 1) { + rowSpan++; + } + cell.setRowSpan(rowSpan); + } + + private boolean isSimpleValue(Value value, String leftType, String topType) { + // 判断文本类型是否要合并格子 + boolean isSimpleValue = value instanceof SimpleValue; + boolean isLeftNone = Objects.equals(leftType, UniverDataEnum.cellNone.getName()); + boolean isTopNone = Objects.equals(topType, UniverDataEnum.cellNone.getName()); + return isSimpleValue && isLeftNone && isTopNone; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownBlankCellApply.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownBlankCellApply.java new file mode 100644 index 0000000..9498fab --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownBlankCellApply.java @@ -0,0 +1,79 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.model.Row; + +import java.util.List; + +/** + * @author + * @since 3月2日 + */ +public class DownBlankCellApply { + private int rowSize; + private Cell cell; + private Context context; + private DownDuplocatorWrapper downDuplocatorWrapper; + + public DownBlankCellApply(int rowSize, Cell cell, Context context, DownDuplocatorWrapper downDuplocatorWrapper) { + this.rowSize = rowSize; + this.cell = cell; + this.context = context; + this.downDuplocatorWrapper = downDuplocatorWrapper; + } + + public boolean useBlankCell(int index, BindData bindData) { + if (context.getBlankCellsMap().size() == 0) { + return false; + } + int nextRowNumber = cell.getRow().getRowNumber() + rowSize * (index - 1) + rowSize; + Row nextRow = context.getRow(nextRowNumber); + Cell blankCell = null; + if (nextRow != null) { + blankCell = context.getBlankCell(nextRow, cell.getColumn()); + } + if (blankCell == null) { + return false; + } + context.removeBlankCell(blankCell); + blankCell.setValue(cell.getValue()); + blankCell.setProcessed(true); + blankCell.setData(bindData.getValue()); + blankCell.setBindData(bindData.getDataList()); + processChildrenCell(cell, blankCell, index); + return true; + } + + private void processChildrenCell(Cell originalCell, Cell leftParentCell, int index) { + List children = downDuplocatorWrapper.fetchChildrenDuplicator(originalCell); + if (children == null) { + return; + } + for (CellDownDuplicator child : children) { + Cell childCell = child.getCell(); + Cell targetCell = getChildBlankCell(childCell, index); + if (targetCell == null) { + continue; + } + context.removeBlankCell(targetCell); + targetCell.setLeftParentCell(leftParentCell); + targetCell.setValue(childCell.getValue()); + if (targetCell.getTopParentCell() == originalCell) { + targetCell.setTopParentCell(leftParentCell); + } + context.addUnprocessedCell(targetCell); + processChildrenCell(childCell, targetCell, index); + } + } + + private Cell getChildBlankCell(Cell childCell, int index) { + int nextChildRowNumber = childCell.getRow().getRowNumber() + rowSize * (index - 1) + rowSize; + Row nextChildRow = context.getRow(nextChildRowNumber); + Column col = childCell.getColumn(); + Cell targetCell = context.getBlankCell(nextChildRow, col); + return targetCell; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownCellbuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownCellbuilder.java new file mode 100644 index 0000000..9bc17c1 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownCellbuilder.java @@ -0,0 +1,262 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.definition.CellDefinition; +import com.yunzhupaas.ureport.utils.BuildUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class DownCellbuilder { + + public void buildParentCell(CellDefinition cell, List cells) { + List rangeList = new ArrayList<>(); + Range range = buildChildrenCellRange(cell); + List parentCells = new ArrayList<>(); + collectParentCells(cell, parentCells); + buildParents(cell, parentCells, range, rangeList); + + Range childRange = buildChildrenCells(cell, rangeList); + buildChildrenBlankCells(cell, cells, childRange); + Range rowRange = buildRowRange(rangeList); + buildRowsBlankCells(cell, cells, rowRange); + int start = rowRange.getStart(); + int end = rowRange.getEnd(); + int rowNumberStart = cell.getRowNumber(); + int rowNumberEnd = cell.getRowNumber(); + int rowSpan = cell.getRowSpan(); + if (rowSpan > 0) { + rowNumberEnd += rowSpan - 1; + } + int rangeStart = 0; + int rangeEnd = 0; + if (start != -1) { + rangeStart = start - rowNumberStart; + } + if (end > rowNumberStart && end > rowNumberEnd) { + rangeEnd = end - rowNumberStart; + } else { + rangeEnd = rowNumberEnd - rowNumberStart; + } + Range duplicateRange = new Range(rangeStart, rangeEnd); + cell.setDuplicateRange(duplicateRange); + } + + private void buildRowsBlankCells(CellDefinition cell, List cells, Range range) { + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + int start = range.getStart(); + int end = range.getEnd(); + int nextEnd = 0; + for (int i = start; i <= end; i++) { + for (CellDefinition cellDef : cells) { + String name = cellDef.getName(); + if (cellPrcessed(cell, name)) { + continue; + } + int rowNumber = cellDef.getRowNumber(); + if (rowNumber == i) { + int offset = rowNumber - cell.getRowNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, cellDef.getRowSpan(), false)); + } else if (rowNumber < i) { + int endRowNumber = BuildUtils.buildRowNumberEnd(cellDef, rowNumber); + if (endRowNumber >= i) { + int offset = rowNumber - cell.getRowNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, cellDef.getRowSpan(), false)); + } + } + } + } + if (nextEnd > end) { + buildRowsBlankCells(cell, cells, new Range(end, nextEnd)); + } + } + + private Range buildRowRange(List rangeList) { + Range rowRange = new Range(); + for (Range range : rangeList) { + for (int i = range.getStart(); i <= range.getEnd(); i++) { + if (rowRange.getStart() == -1 || i < rowRange.getStart()) { + rowRange.setStart(i); + } + if (rowRange.getEnd() < i) { + rowRange.setEnd(i); + } + } + } + return rowRange; + } + + private Range buildChildrenCells(CellDefinition cell, List rangeList) { + Range range = new Range(); + List rowChildrenCells = cell.getRowChildrenCells(); + for (CellDefinition childCell : rowChildrenCells) { + cell.getNewCellNames().add(childCell.getName()); + int rowNumber = childCell.getRowNumber(); + int endRowNumber = BuildUtils.buildRowNumberEnd(childCell, rowNumber); + rangeList.add(new Range(rowNumber, endRowNumber)); + if (endRowNumber > range.getEnd()) { + range.setEnd(endRowNumber); + } + if (range.getStart() == -1 || rowNumber < range.getStart()) { + range.setStart(rowNumber); + } + } + return range; + } + + private void buildChildrenBlankCells(CellDefinition cell, List cells, Range childRange) { + int startRowNumber = cell.getRowNumber(); + int endRowNumber = BuildUtils.buildRowNumberEnd(cell, startRowNumber); + int start = childRange.getStart(); + int end = childRange.getEnd(); + if (start != -1 && start < startRowNumber) { + startRowNumber = start; + } + if (end > endRowNumber) { + endRowNumber = end; + } + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + for (int i = startRowNumber; i <= endRowNumber; i++) { + for (CellDefinition c : cells) { + if (c.getRowNumber() != i) { + continue; + } + if (c.equals(cell)) { + continue; + } + String name = c.getName(); + boolean contain = cellPrcessed(cell, name); + if (contain) { + continue; + } + int offset = c.getRowNumber() - cell.getRowNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, c.getRowSpan(), false)); + } + } + } + + private boolean cellPrcessed(CellDefinition cell, String name) { + List newCellNames = cell.getNewCellNames(); + List increaseCellNames = cell.getIncreaseSpanCellNames(); + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + boolean contain = cell.getName().equals(name); + if (newCellNames.contains(name)) { + contain = true; + } + if (increaseCellNames.contains(name)) { + contain = true; + } + if (blankCellNamesMap.containsKey(name)) { + contain = true; + } + return contain; + } + + private void collectParentCells(CellDefinition cell, List parentCells) { + CellDefinition leftParentCell = cell.getLeftParentCell(); + if (leftParentCell == null) { + return; + } + parentCells.add(leftParentCell); + collectParentCells(leftParentCell, parentCells); + } + + private void buildParents(CellDefinition mainCell, List parentCells, Range childRange, + List rangeList) { + int rowNumberStart = mainCell.getRowNumber(); + int rowNumberEnd = BuildUtils.buildRowNumberEnd(mainCell, rowNumberStart); + rangeList.add(new Range(rowNumberStart, rowNumberEnd)); + + int start = childRange.getStart(); + int end = childRange.getEnd(); + Map newBlankCellsMap = mainCell.getNewBlankCellsMap(); + boolean increase = true; + for (CellDefinition parentCell : parentCells) { + String parentCellName = parentCell.getName(); + int parentRowNumberStart = parentCell.getRowNumber(); + int parentRowNumberEnd = BuildUtils.buildRowNumberEnd(parentCell, parentRowNumberStart); + int offset = parentRowNumberStart - rowNumberStart; + int parentRowSpan = parentCell.getRowSpan(); + boolean isOut = assertOut(parentCell, mainCell, childRange); + if (isOut) { + increase = false; + boolean doBlank = assertDoBlank(parentCell.getLeftParentCell(), parentCell, mainCell, childRange); + if (doBlank) { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentRowSpan, true)); + rangeList.add(new Range(parentRowNumberStart, parentRowNumberEnd)); + } + continue; + } + if ((start != -1 && start < parentRowNumberStart) || end > parentRowNumberEnd) { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentRowSpan, true)); + rangeList.add(new Range(parentRowNumberStart, parentRowNumberEnd)); + increase = false; + continue; + } + if (increase) { + mainCell.getIncreaseSpanCellNames().add(parentCellName); + } else { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentRowSpan, true)); + rangeList.add(new Range(parentRowNumberStart, parentRowNumberEnd)); + } + } + } + + private boolean assertDoBlank(CellDefinition nextParentCell, CellDefinition parentCell, CellDefinition mainCell, + Range childRange) { + if (nextParentCell == null) { + return false; + } + boolean isOut = assertOut(nextParentCell, mainCell, childRange); + if (isOut) { + return assertDoBlank(nextParentCell.getLeftParentCell(), parentCell, mainCell, childRange); + } + int start = parentCell.getRowNumber(); + int end = BuildUtils.buildRowNumberEnd(parentCell, start); + int nextStart = nextParentCell.getRowNumber(); + if (nextStart <= end) { + return true; + } + return assertDoBlank(nextParentCell.getLeftParentCell(), parentCell, mainCell, childRange); + } + + private boolean assertOut(CellDefinition parentCell, CellDefinition mainCell, Range childRange) { + int start = parentCell.getRowNumber(); + int end = BuildUtils.buildRowNumberEnd(parentCell, start); + int rangeStart = childRange.getStart(); + int rangeEnd = childRange.getEnd(); + if (rangeStart != -1) { + if ((start >= rangeStart && start <= rangeEnd) || (end >= rangeStart && end <= rangeEnd)) { + return false; + } + } + int rowStart = mainCell.getRowNumber(); + int rowEnd = BuildUtils.buildRowNumberEnd(mainCell, rowStart); + if ((start >= rowStart && start <= rowEnd) || (end >= rowStart && end <= rowEnd) + || (start <= rowStart && end >= rowEnd)) { + return false; + } + return true; + } + + private Range buildChildrenCellRange(CellDefinition mainCell) { + Range range = new Range(); + List childrenCells = mainCell.getRowChildrenCells(); + for (CellDefinition childCell : childrenCells) { + int childRowNumberStart = childCell.getRowNumber(); + int childRowSpan = childCell.getRowSpan(); + childRowSpan = childRowSpan > 0 ? childRowSpan - 1 : childRowSpan; + int childRowNumberEnd = childRowNumberStart + childRowSpan; + if (range.getStart() == -1 || childRowNumberStart < range.getStart()) { + range.setStart(childRowNumberStart); + } + if (childRowNumberEnd > range.getEnd()) { + range.setEnd(childRowNumberEnd); + } + } + return range; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplicate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplicate.java new file mode 100644 index 0000000..5f66689 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplicate.java @@ -0,0 +1,60 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Report; +import com.yunzhupaas.ureport.model.Row; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Setter +@Getter +public class DownDuplicate { + private int index; + private Cell mainCell; + private int rowSize; + private Context context; + private int minRowNumber = -1; + private Map rowMap = new HashMap<>(); + private List newRowList = new ArrayList<>(); + + public DownDuplicate(Cell mainCell, int rowSize, Context context) { + this.mainCell = mainCell; + this.rowSize = rowSize; + this.context = context; + } + + public Row newRow(Row row, int currentRowNumber) { + if (rowMap.containsKey(row)) { + return rowMap.get(row); + } else { + int rowNumber = currentRowNumber; + Row newRow = row.newRow(); + rowNumber = rowNumber + rowSize * (index - 1) + rowSize; + if (minRowNumber == -1 || minRowNumber > rowNumber) { + minRowNumber = rowNumber; + } + newRow.setTempRowNumber(rowNumber); + newRowList.add(newRow); + rowMap.put(row, newRow); + return newRow; + } + } + + public void complete() { + if (minRowNumber < 1) { + return; + } + Report report = context.getReport(); + report.insertRows(minRowNumber, newRowList); + } + + public void reset() { + rowMap.clear(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplocatorWrapper.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplocatorWrapper.java new file mode 100644 index 0000000..48536af --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownDuplocatorWrapper.java @@ -0,0 +1,62 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Setter +@Getter +public class DownDuplocatorWrapper { + private String mainCellName; + private List mainCellChildren = new ArrayList<>(); + private List cellDuplicators = new ArrayList<>(); + private Map> createNewDuplicatorsMap = new HashMap<>(); + private List duplicatorCells = new ArrayList<>(); + + public DownDuplocatorWrapper(String mainCellName) { + this.mainCellName = mainCellName; + } + + public void addCellDownDuplicator(CellDownDuplicator duplicator) { + if (duplicator.getDuplicateType().equals(DuplicateType.Duplicate)) { + addCellDownDuplicatorToMap(duplicator); + } else { + cellDuplicators.add(duplicator); + duplicatorCells.add(duplicator.getCell()); + } + } + + private void addCellDownDuplicatorToMap(CellDownDuplicator duplicator) { + Cell leftParentCell = duplicator.getCell().getLeftParentCell(); + if (leftParentCell.getName().equals(mainCellName)) { + mainCellChildren.add(duplicator); + } + List list = null; + if (createNewDuplicatorsMap.containsKey(leftParentCell)) { + list = createNewDuplicatorsMap.get(leftParentCell); + } else { + list = new ArrayList<>(); + createNewDuplicatorsMap.put(leftParentCell, list); + } + list.add(duplicator); + } + + public boolean contains(Cell cell) { + return duplicatorCells.contains(cell); + } + + public List getMainCellChildren() { + return mainCellChildren; + } + + public List fetchChildrenDuplicator(Cell leftParentCell) { + return createNewDuplicatorsMap.get(leftParentCell); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownExpandBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownExpandBuilder.java new file mode 100644 index 0000000..5b000f1 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/down/DownExpandBuilder.java @@ -0,0 +1,133 @@ +package com.yunzhupaas.ureport.cell.down; + +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.cell.CellBuilder; +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Row; +import com.yunzhupaas.ureport.utils.DataUtils; +import com.yunzhupaas.util.RandomUtil; + +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月1日 + */ +public class DownExpandBuilder implements CellBuilder { + @Override + public Cell buildCell(List dataList, Cell cell, Context context) { + Range duplicateRange = cell.getDuplicateRange(); + int mainCellRowNumber = cell.getRow().getRowNumber(); + Range rowRange = buildRowRange(mainCellRowNumber, duplicateRange); + DownDuplocatorWrapper downDuplocatorWrapper = buildCellDownDuplicator(cell, context, rowRange); + int rowSize = rowRange.getEnd() - rowRange.getStart() + 1; + DownBlankCellApply downBlankCellApply = new DownBlankCellApply(rowSize, cell, context, downDuplocatorWrapper); + CellDownDuplicateUnit unit = new CellDownDuplicateUnit(context, downDuplocatorWrapper, cell, mainCellRowNumber, + rowSize); + Cell lastCell = cell; + String groupId = RandomUtil.uuId(); + for (int i = 0; i < dataList.size(); i++) { + BindData bindData = dataList.get(i); + if (i == 0) { + cell.setData(bindData.getValue()); + cell.setBindData(bindData.getDataList()); + cell.setDataList(dataList); + cell.setLeftGroupId(groupId); + DataUtils.cellList(cell, true, true); + continue; + } + boolean useBlankCell = downBlankCellApply.useBlankCell(i, bindData); + if (useBlankCell) { + continue; + } + Cell newCell = cell.newCell(); + newCell.setRowNumber(newCell.getRowNumber() + i); + newCell.setData(bindData.getValue()); + newCell.setBindData(bindData.getDataList()); + newCell.setDataList(dataList); + newCell.setLeftGroupId(groupId); + newCell.setProcessed(true); + Cell leftParentCell = cell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newCell); + } + Cell topParentCell = cell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newCell); + } + DataUtils.cellList(newCell, true, true); + unit.setGroupId(RandomUtil.uuId()); + unit.duplicate(newCell, i); + lastCell = newCell; + } + unit.complete(); + return lastCell; + } + + private Range buildRowRange(int mainCellRowNumber, Range range) { + int start = mainCellRowNumber + range.getStart(); + int end = mainCellRowNumber + range.getEnd(); + Range ranges = new Range(); + ranges.setStart(start); + ranges.setEnd(end); + return ranges; + } + + private DownDuplocatorWrapper buildCellDownDuplicator(Cell cell, Context context, Range range) { + DownDuplocatorWrapper duplicatorWrapper = new DownDuplocatorWrapper(cell.getName()); + buildParentCellDuplicators(cell, cell, duplicatorWrapper); + for (int i = range.getStart(); i <= range.getEnd(); i++) { + Row row = context.getRow(i); + List rowCells = row.getCells(); + for (Cell rowCell : rowCells) { + rowCell.setLeftGroupId(RandomUtil.uuId()); + buildDuplicator(duplicatorWrapper, cell, rowCell, i); + } + } + return duplicatorWrapper; + } + + private void buildParentCellDuplicators(Cell cell, Cell mainCell, DownDuplocatorWrapper duplicatorWrapper) { + Cell leftParentCell = cell.getLeftParentCell(); + if (leftParentCell == null) { + return; + } + buildDuplicator(duplicatorWrapper, mainCell, leftParentCell, 0); + buildParentCellDuplicators(leftParentCell, mainCell, duplicatorWrapper); + } + + private void buildDuplicator(DownDuplocatorWrapper duplicatorWrapper, Cell mainCell, Cell currentCell, + int rowNumber) { + if (currentCell == mainCell) { + return; + } + String name = currentCell.getName(); + Map newBlankCellNamesMap = mainCell.getNewBlankCellsMap(); + List increaseCellNames = mainCell.getIncreaseSpanCellNames(); + List newCellNames = mainCell.getNewCellNames(); + if (newBlankCellNamesMap.containsKey(name)) { + if (!duplicatorWrapper.contains(currentCell)) { + CellDownDuplicator cellDuplicator = new CellDownDuplicator(currentCell, DuplicateType.Blank, + newBlankCellNamesMap.get(name), rowNumber); + duplicatorWrapper.addCellDownDuplicator(cellDuplicator); + } + } else if (increaseCellNames.contains(name)) { + if (!duplicatorWrapper.contains(currentCell)) { + CellDownDuplicator cellDuplicator = new CellDownDuplicator(currentCell, DuplicateType.IncreaseSpan, + rowNumber); + duplicatorWrapper.addCellDownDuplicator(cellDuplicator); + } + } else if (newCellNames.contains(name)) { + CellDownDuplicator cellDuplicator = new CellDownDuplicator(currentCell, DuplicateType.Duplicate, rowNumber); + duplicatorWrapper.addCellDownDuplicator(cellDuplicator); + } else if (mainCell.getName().equals(name)) { + CellDownDuplicator cellDuplicator = new CellDownDuplicator(currentCell, DuplicateType.Self, rowNumber); + duplicatorWrapper.addCellDownDuplicator(cellDuplicator); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/none/NoneExpandBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/none/NoneExpandBuilder.java new file mode 100644 index 0000000..6475974 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/none/NoneExpandBuilder.java @@ -0,0 +1,35 @@ +package com.yunzhupaas.ureport.cell.none; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.cell.CellBuilder; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; +import java.util.Map; + +public class NoneExpandBuilder implements CellBuilder { + + @Override + public Cell buildCell(List dataList, Cell cell, Context context) { + if (dataList.size() == 1) { + BindData bindData = dataList.get(0); + cell.setData(bindData.getValue()); + cell.setBindData(bindData.getDataList()); + } else { + Object obj = null; + List> bindData = null; + for (BindData data : dataList) { + if (obj == null) { + obj = data.getValue(); + } else { + obj = obj + "," + data.getValue(); + } + bindData = data.getDataList(); + } + cell.setData(obj); + cell.setBindData(bindData); + } + return cell; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicateUnit.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicateUnit.java new file mode 100644 index 0000000..df09c29 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicateUnit.java @@ -0,0 +1,85 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月7日 + */ +@Setter +@Getter +public class CellRightDuplicateUnit { + private Cell mainCell; + private int mainCellColNumber; + private Context context; + private String groupId; + private RightDuplicate rightDuplicate; + private RightDuplocatorWrapper rightDuplocatorWrapper; + + public CellRightDuplicateUnit(Context context, RightDuplocatorWrapper rightDuplocatorWrapper, Cell mainCell, + int mainCellColNumber, int colSize) { + this.context = context; + this.rightDuplocatorWrapper = rightDuplocatorWrapper; + this.mainCell = mainCell; + this.mainCellColNumber = mainCellColNumber; + this.rightDuplicate = new RightDuplicate(mainCell, colSize, context); + } + + public void duplicate(Cell cell, int index) { + Map newCellMap = new HashMap<>(); + newCellMap.put(mainCell, cell); + rightDuplicate.setIndex(index); + for (CellRightDuplicator childDuplicator : rightDuplocatorWrapper.getMainCellChildren()) { + Cell newCell = childDuplicator.duplicateChildrenCell(rightDuplicate, cell, mainCell, false); + newCell.setDataList(cell.getDataList()); + newCell.setTopGroupId(groupId); + newCellMap.put(childDuplicator.getCell(), newCell); + processChildrenCells(newCell, childDuplicator.getCell(), newCellMap, rightDuplicate, + childDuplicator.isNonChild()); + childDuplicator.setNonChild(false); + } + for (CellRightDuplicator cellDownDuplicator : rightDuplocatorWrapper.getCellDuplicators()) { + cellDownDuplicator.duplicate(rightDuplicate, cell); + } + Column newCol = rightDuplicate.newColumn(cell.getColumn(), mainCellColNumber); + cell.setColumn(newCol); + newCol.getCells().add(cell); + cell.getRow().getCells().add(cell); + context.addReportCell(cell); + rightDuplicate.reset(); + for (Cell newCell : newCellMap.values()) { + Cell originLeftCell = newCell.getLeftParentCell(); + if (originLeftCell != null && newCellMap.containsKey(originLeftCell)) { + newCell.setLeftParentCell(newCellMap.get(originLeftCell)); + } + } + } + + public void complete() { + rightDuplicate.complete(); + } + + private void processChildrenCells(Cell cell, Cell originalCell, Map newCellMap, + RightDuplicate rightDuplicate, boolean parentNonChild) { + List childCellRightDuplicators = rightDuplocatorWrapper + .fetchChildrenDuplicator(originalCell); + if (childCellRightDuplicators == null) { + return; + } + for (CellRightDuplicator duplicator : childCellRightDuplicators) { + Cell newCell = duplicator.duplicateChildrenCell(rightDuplicate, cell, originalCell, parentNonChild); + newCell.setTopGroupId(groupId); + newCellMap.put(duplicator.getCell(), newCell); + processChildrenCells(newCell, duplicator.getCell(), newCellMap, rightDuplicate, duplicator.isNonChild()); + duplicator.setNonChild(false); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicator.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicator.java new file mode 100644 index 0000000..edb031c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/CellRightDuplicator.java @@ -0,0 +1,164 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.enums.UniverDataEnum; +import com.yunzhupaas.univer.sheet.UniverSheetCellData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.definition.value.SimpleValue; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.utils.DataUtils; +import lombok.Getter; +import lombok.Setter; + +import java.util.Objects; + +/** + * @author + * @since 2016年11月7日 + */ +@Getter +@Setter +public class CellRightDuplicator { + private Cell cell; + private int cellColNumber; + private DuplicateType duplicateType; + private BlankCellInfo blankCellInfo; + private boolean nonChild = false; + + public CellRightDuplicator(Cell cell, DuplicateType duplicateType, int cellColNumber) { + this.cell = cell; + this.duplicateType = duplicateType; + this.cellColNumber = cellColNumber; + } + + public CellRightDuplicator(Cell cell, DuplicateType duplicateType, BlankCellInfo blankCellInfo, int cellColNumber) { + this.cell = cell; + this.duplicateType = duplicateType; + this.blankCellInfo = blankCellInfo; + if (cellColNumber > 0) { + this.cellColNumber = cellColNumber; + } else { + this.cellColNumber = cell.getColumn().getColumnNumber(); + } + } + + public Cell duplicateChildrenCell(RightDuplicate rightDuplicate, Cell topParent, Cell originalCell, + boolean parentNonChild) { + Cell newCell = cell.newCell(); + Column newCol = rightDuplicate.newColumn(newCell.getColumn(), cellColNumber); + newCol.getCells().add(newCell); + newCell.getRow().getCells().add(newCell); + newCell.setColumn(newCol); + if (newCell.getTopParentCell() == originalCell) { + newCell.setTopParentCell(topParent); + if (parentNonChild) { + nonChild = true; + } + } else { + nonChild = true; + } + Cell leftParentCell = newCell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newCell); + } + Cell topParentCell = newCell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newCell); + } + Value value = newCell.getValue(); + Context context = rightDuplicate.getContext(); + String leftType = newCell.getLeftType(); + String topType = newCell.getTopType(); + DataUtils.cellList(newCell, true, true); + if (value instanceof SimpleValue) { + newCell.setData(value.getValue()); + newCell.setProcessed(true); + context.addReportCell(newCell); + if (isSimpleValue(value, leftType, topType)) { + newCell.setData(""); + // newCell.setCellData(new UniverSheetCellData()); + } + } else { + if (nonChild) { + newCell.setValue(new SimpleValue("")); + } else { + context.addCell(newCell); + } + } + return newCell; + } + + public Cell duplicate(RightDuplicate rightDuplicate, Cell newMainCell) { + switch (duplicateType) { + case Blank: + processBlankCell(rightDuplicate, newMainCell); + break; + case Self: + processSelfBlankCell(rightDuplicate); + break; + case IncreaseSpan: + processIncreaseSpanCell(rightDuplicate); + break; + } + return null; + } + + private void processBlankCell(RightDuplicate rightDuplicate, Cell newMainCell) { + Context context = rightDuplicate.getContext(); + Cell newBlankCell = cell.newColumnBlankCell(context, blankCellInfo, rightDuplicate.getMainCell()); + if (blankCellInfo.isParent() && newMainCell.getTopParentCell() == cell) { + newMainCell.setTopParentCell(newBlankCell); + } + Column col = rightDuplicate.newColumn(newBlankCell.getColumn(), cellColNumber); + col.getCells().add(newBlankCell); + newBlankCell.getRow().getCells().add(newBlankCell); + newBlankCell.setColumn(col); + context.addReportCell(newBlankCell); + } + + private void processSelfBlankCell(RightDuplicate rightDuplicate) { + Cell newBlankCell = cell.newCell(); + newBlankCell.setValue(new SimpleValue("")); + Column newCol = rightDuplicate.newColumn(newBlankCell.getColumn(), cellColNumber); + newCol.getCells().add(newBlankCell); + newBlankCell.getRow().getCells().add(newBlankCell); + newBlankCell.setColumn(newCol); + Cell leftParentCell = newBlankCell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newBlankCell); + } + Cell topParentCell = newBlankCell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newBlankCell); + } + Context context = rightDuplicate.getContext(); + context.addBlankCell(newBlankCell); + } + + private void processIncreaseSpanCell(RightDuplicate rightDuplicate) { + int colSpan = cell.getColSpan(); + Value value = cell.getValue(); + String leftType = cell.getLeftType(); + String topType = cell.getTopType(); + if (isSimpleValue(value, leftType, topType)) { + return; + } + colSpan += rightDuplicate.getColumnSize(); + if (colSpan == 1) { + colSpan++; + } + cell.setColSpan(colSpan); + } + + private boolean isSimpleValue(Value value, String leftType, String topType) { + // 判断文本类型是否要合并格子 + boolean isSimpleValue = value instanceof SimpleValue; + boolean isLeftNone = Objects.equals(leftType, UniverDataEnum.cellNone.getName()); + boolean isTopNone = Objects.equals(topType, UniverDataEnum.cellNone.getName()); + return isSimpleValue && isLeftNone && isTopNone; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightBlankCellApply.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightBlankCellApply.java new file mode 100644 index 0000000..15bf11b --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightBlankCellApply.java @@ -0,0 +1,74 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.model.Row; + +import java.util.List; + +/** + * @author + * @since 3月2日 + */ +public class RightBlankCellApply { + private int colSize; + private Cell cell; + private Context context; + private RightDuplocatorWrapper rightDuplocatorWrapper; + + public RightBlankCellApply(int colSize, Cell cell, Context context, RightDuplocatorWrapper rightDuplocatorWrapper) { + this.colSize = colSize; + this.cell = cell; + this.context = context; + this.rightDuplocatorWrapper = rightDuplocatorWrapper; + } + + public boolean useBlankCell(int index, BindData bindData) { + if (context.getBlankCellsMap().size() == 0) { + return false; + } + int nextColNumber = cell.getColumn().getColumnNumber() + colSize * (index - 1) + colSize; + Column nextCol = context.getColumn(nextColNumber); + Cell blankCell = null; + if (nextCol != null) { + blankCell = context.getBlankCell(cell.getRow(), nextCol); + } + if (blankCell == null) { + return false; + } + context.removeBlankCell(blankCell); + blankCell.setValue(cell.getValue()); + blankCell.setProcessed(true); + blankCell.setData(bindData.getValue()); + blankCell.setBindData(bindData.getDataList()); + processChildrenCell(cell, blankCell, index); + return true; + } + + private void processChildrenCell(Cell originalCell, Cell topParentCell, int index) { + List children = rightDuplocatorWrapper.fetchChildrenDuplicator(originalCell); + if (children == null) { + return; + } + for (CellRightDuplicator child : children) { + Cell childCell = child.getCell(); + int nextChildColNumber = childCell.getColumn().getColumnNumber() + colSize * (index - 1) + colSize; + Column nextChildCol = context.getColumn(nextChildColNumber); + Row row = childCell.getRow(); + Cell targetCell = context.getBlankCell(row, nextChildCol); + if (targetCell == null) { + continue; + } + context.removeBlankCell(targetCell); + targetCell.setTopParentCell(topParentCell); + targetCell.setValue(childCell.getValue()); + if (originalCell == targetCell.getLeftParentCell()) { + targetCell.setLeftParentCell(topParentCell); + } + context.addUnprocessedCell(targetCell); + processChildrenCell(childCell, targetCell, index); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightCellbuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightCellbuilder.java new file mode 100644 index 0000000..f17d03a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightCellbuilder.java @@ -0,0 +1,265 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.definition.CellDefinition; +import com.yunzhupaas.ureport.utils.BuildUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2月24日 + */ +public class RightCellbuilder { + + public void buildParentCell(CellDefinition cell, List cells) { + List rangeList = new ArrayList<>(); + Range range = buildChildrenCellRange(cell); + List parentCells = new ArrayList<>(); + collectParentCells(cell, parentCells); + buildParents(cell, parentCells, range, rangeList); + + Range childRange = buildChildrenCells(cell, rangeList); + buildChildrenBlankCells(cell, cells, childRange); + Range colRange = buildColumnRange(rangeList); + buildColumnsBlankCells(cell, cells, colRange); + int start = colRange.getStart(); + int end = colRange.getEnd(); + int colNumberStart = cell.getColumnNumber(); + int colNumberEnd = cell.getColumnNumber(); + int colSpan = cell.getColSpan(); + if (colSpan > 0) { + colNumberEnd += colSpan - 1; + } + int rangeStart = 0; + int rangeEnd = 0; + if (start != -1) { + rangeStart = start - colNumberStart; + } + if (end > colNumberStart && end > colNumberEnd) { + rangeEnd = end - colNumberStart; + } else { + rangeEnd = colNumberEnd - colNumberStart; + } + Range duplicateRange = new Range(rangeStart, rangeEnd); + cell.setDuplicateRange(duplicateRange); + } + + private void buildColumnsBlankCells(CellDefinition cell, List cells, Range range) { + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + int start = range.getStart(); + int end = range.getEnd(); + int nextEnd = 0; + for (int i = start; i <= end; i++) { + for (CellDefinition cellDef : cells) { + String name = cellDef.getName(); + if (cellPrcessed(cell, name)) { + continue; + } + int colNumber = cellDef.getColumnNumber(); + if (colNumber == i) { + int offset = colNumber - cell.getColumnNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, cellDef.getColSpan(), false)); + } else if (colNumber < i) { + int endColNumber = BuildUtils.buildColNumberEnd(cellDef, colNumber); + if (endColNumber >= i) { + int offset = colNumber - cell.getColumnNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, cellDef.getColSpan(), false)); + } + } + } + } + if (nextEnd > end) { + buildColumnsBlankCells(cell, cells, new Range(end, nextEnd)); + } + } + + private Range buildColumnRange(List rangeList) { + Range colRange = new Range(); + for (Range range : rangeList) { + for (int i = range.getStart(); i <= range.getEnd(); i++) { + if (colRange.getStart() == -1 || i < colRange.getStart()) { + colRange.setStart(i); + } + if (colRange.getEnd() < i) { + colRange.setEnd(i); + } + } + } + return colRange; + } + + private Range buildChildrenCells(CellDefinition cell, List rangeList) { + Range range = new Range(); + List childrenCells = cell.getColumnChildrenCells(); + for (CellDefinition childCell : childrenCells) { + cell.getNewCellNames().add(childCell.getName()); + int colNumber = childCell.getColumnNumber(); + int endColNumber = BuildUtils.buildColNumberEnd(childCell, colNumber); + rangeList.add(new Range(colNumber, endColNumber)); + if (endColNumber > range.getEnd()) { + range.setEnd(endColNumber); + } + if (range.getStart() == -1 || colNumber < range.getStart()) { + range.setStart(colNumber); + } + } + return range; + } + + private void buildChildrenBlankCells(CellDefinition cell, List cells, Range childRange) { + int startColNumber = cell.getColumnNumber(); + int endColNumber = BuildUtils.buildColNumberEnd(cell, startColNumber); + int start = childRange.getStart(); + int end = childRange.getEnd(); + if (start != -1 && start < startColNumber) { + startColNumber = start; + } + if (end > endColNumber) { + endColNumber = end; + } + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + for (int i = startColNumber; i <= endColNumber; i++) { + for (CellDefinition c : cells) { + if (c.getColumnNumber() != i) { + continue; + } + if (c.equals(cell)) { + continue; + } + String name = c.getName(); + boolean contain = cellPrcessed(cell, name); + if (contain) { + continue; + } + int offset = c.getColumnNumber() - cell.getColumnNumber(); + blankCellNamesMap.put(name, new BlankCellInfo(offset, c.getColSpan(), false)); + } + } + } + + private boolean cellPrcessed(CellDefinition cell, String name) { + List newCellNames = cell.getNewCellNames(); + List increaseCellNames = cell.getIncreaseSpanCellNames(); + Map blankCellNamesMap = cell.getNewBlankCellsMap(); + boolean contain = cell.getName().equals(name); + if (newCellNames.contains(name)) { + contain = true; + } + if (increaseCellNames.contains(name)) { + contain = true; + } + if (blankCellNamesMap.containsKey(name)) { + contain = true; + } + return contain; + } + + private void collectParentCells(CellDefinition cell, List parentCells) { + CellDefinition topParentCell = cell.getTopParentCell(); + if (topParentCell == null) { + return; + } + parentCells.add(topParentCell); + collectParentCells(topParentCell, parentCells); + } + + private void buildParents(CellDefinition mainCell, List parentCells, Range childRange, + List rangeList) { + int colNumberStart = mainCell.getColumnNumber(); + int colNumberEnd = BuildUtils.buildColNumberEnd(mainCell, colNumberStart); + rangeList.add(new Range(colNumberStart, colNumberEnd)); + + int start = childRange.getStart(); + int end = childRange.getEnd(); + Map newBlankCellsMap = mainCell.getNewBlankCellsMap(); + boolean increase = true; + for (CellDefinition parentCell : parentCells) { + String parentCellName = parentCell.getName(); + int parentColNumberStart = parentCell.getColumnNumber(); + int parentColNumberEnd = BuildUtils.buildColNumberEnd(parentCell, parentColNumberStart); + int offset = parentColNumberStart - colNumberStart; + int parentColSpan = parentCell.getColSpan(); + boolean isOut = assertOut(parentCell, mainCell, childRange); + if (isOut) { + increase = false; + boolean doBlank = assertDoBlank(parentCell.getTopParentCell(), parentCell, mainCell, childRange); + if (doBlank) { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentColSpan, true)); + rangeList.add(new Range(parentColNumberStart, parentColNumberEnd)); + } + continue; + } + if ((start != -1 && start < parentColNumberStart) || end > parentColNumberEnd) { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentColSpan, true)); + rangeList.add(new Range(parentColNumberStart, parentColNumberEnd)); + increase = false; + continue; + } + if (increase) { + mainCell.getIncreaseSpanCellNames().add(parentCellName); + } else { + newBlankCellsMap.put(parentCellName, new BlankCellInfo(offset, parentColSpan, true)); + rangeList.add(new Range(parentColNumberStart, parentColNumberEnd)); + } + } + } + + private boolean assertDoBlank(CellDefinition nextParentCell, CellDefinition parentCell, CellDefinition mainCell, + Range childRange) { + if (nextParentCell == null) { + return false; + } + boolean isOut = assertOut(nextParentCell, mainCell, childRange); + if (isOut) { + return assertDoBlank(nextParentCell.getTopParentCell(), parentCell, mainCell, childRange); + } + int start = parentCell.getColumnNumber(); + int end = BuildUtils.buildColNumberEnd(parentCell, start); + int nextStart = nextParentCell.getColumnNumber(); + if (nextStart <= end) { + return true; + } + return assertDoBlank(nextParentCell.getTopParentCell(), parentCell, mainCell, childRange); + } + + private boolean assertOut(CellDefinition parentCell, CellDefinition mainCell, Range childRange) { + int start = parentCell.getColumnNumber(); + int end = BuildUtils.buildColNumberEnd(parentCell, start); + int rangeStart = childRange.getStart(); + int rangeEnd = childRange.getEnd(); + if (rangeStart != -1) { + if ((start >= rangeStart && start <= rangeEnd) || (end >= rangeStart && end <= rangeEnd)) { + return false; + } + } + int colStart = mainCell.getColumnNumber(); + int colEnd = BuildUtils.buildColNumberEnd(mainCell, colStart); + if ((start >= colStart && start <= colEnd) || (end >= colStart && end <= colEnd) + || (start <= colStart && end >= colEnd)) { + return false; + } + return true; + } + + private Range buildChildrenCellRange(CellDefinition mainCell) { + Range range = new Range(); + List childrenCells = mainCell.getColumnChildrenCells(); + for (CellDefinition childCell : childrenCells) { + int childColumnNumberStart = childCell.getColumnNumber(); + int childColSpan = childCell.getColSpan(); + childColSpan = childColSpan > 0 ? childColSpan - 1 : childColSpan; + int childColumnNumberEnd = childColumnNumberStart + childColSpan; + if (range.getStart() == -1 || childColumnNumberStart < range.getStart()) { + range.setStart(childColumnNumberStart); + } + if (childColumnNumberEnd > range.getEnd()) { + range.setEnd(childColumnNumberEnd); + } + } + return range; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplicate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplicate.java new file mode 100644 index 0000000..ad29080 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplicate.java @@ -0,0 +1,63 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.model.Report; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月10日 + */ +@Setter +@Getter +public class RightDuplicate { + private int index; + private int columnSize; + private Context context; + private Cell mainCell; + private int minColNumber = -1; + private Map colMap = new HashMap<>(); + private List newColList = new ArrayList<>(); + + public RightDuplicate(Cell mainCell, int columnSize, Context context) { + this.mainCell = mainCell; + this.columnSize = columnSize; + this.context = context; + } + + public Column newColumn(Column col, int colNumber) { + if (colMap.containsKey(col)) { + return colMap.get(col); + } else { + Column newCol = col.newColumn(); + colNumber = colNumber + columnSize * (index - 1) + columnSize; + if (minColNumber == -1 || minColNumber > colNumber) { + minColNumber = colNumber; + } + newCol.setTempColumnNumber(colNumber); + newColList.add(newCol); + colMap.put(col, newCol); + return newCol; + } + } + + public void complete() { + if (minColNumber < 1) { + return; + } + Report report = context.getReport(); + report.insertColumns(minColNumber, newColList); + } + + public void reset() { + colMap.clear(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplocatorWrapper.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplocatorWrapper.java new file mode 100644 index 0000000..6e900a4 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightDuplocatorWrapper.java @@ -0,0 +1,69 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2月25日 + */ +@Setter +@Getter +public class RightDuplocatorWrapper { + private String mainCellName; + private List mainCellChildren = new ArrayList<>(); + private List cellDuplicators = new ArrayList<>(); + private Map> createNewDuplicatorsMap = new HashMap<>(); + private List duplicatorCells = new ArrayList<>(); + + public RightDuplocatorWrapper(String mainCellName) { + this.mainCellName = mainCellName; + } + + public void addCellRightDuplicator(CellRightDuplicator duplicator) { + if (duplicator.getDuplicateType().equals(DuplicateType.Duplicate)) { + addCellRightDuplicatorToMap(duplicator); + } else { + cellDuplicators.add(duplicator); + duplicatorCells.add(duplicator.getCell()); + } + } + + private void addCellRightDuplicatorToMap(CellRightDuplicator duplicator) { + Cell topParentCell = duplicator.getCell().getTopParentCell(); + if (topParentCell.getName().equals(mainCellName)) { + mainCellChildren.add(duplicator); + } + List list = null; + if (createNewDuplicatorsMap.containsKey(topParentCell)) { + list = createNewDuplicatorsMap.get(topParentCell); + } else { + list = new ArrayList<>(); + createNewDuplicatorsMap.put(topParentCell, list); + } + list.add(duplicator); + } + + public boolean contains(Cell cell) { + return duplicatorCells.contains(cell); + } + + public List getMainCellChildren() { + return mainCellChildren; + } + + public List fetchChildrenDuplicator(Cell topParentCell) { + return createNewDuplicatorsMap.get(topParentCell); + } + + public List getCellDuplicators() { + return cellDuplicators; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightExpandBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightExpandBuilder.java new file mode 100644 index 0000000..7f07d24 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/cell/right/RightExpandBuilder.java @@ -0,0 +1,140 @@ +package com.yunzhupaas.ureport.cell.right; + +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.cell.CellBuilder; +import com.yunzhupaas.ureport.cell.DuplicateType; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.utils.DataUtils; +import com.yunzhupaas.util.RandomUtil; + +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月1日 + */ + +public class RightExpandBuilder implements CellBuilder { + + @Override + public Cell buildCell(List dataList, Cell cell, Context context) { + Range duplicateRange = cell.getDuplicateRange(); + int mainCellColNumber = cell.getColumn().getColumnNumber(); + Range colRange = buildColRange(mainCellColNumber, duplicateRange); + + RightDuplocatorWrapper rightDuplocatorWrapper = buildCellRightDuplicator(cell, context, colRange); + + int colSize = colRange.getEnd() - colRange.getStart() + 1; + RightBlankCellApply rightBlankCellApply = new RightBlankCellApply(colSize, cell, context, + rightDuplocatorWrapper); + CellRightDuplicateUnit unit = new CellRightDuplicateUnit(context, rightDuplocatorWrapper, cell, + mainCellColNumber, colSize); + Cell lastCell = cell; + String groupId = RandomUtil.uuId(); + for (int i = 0; i < dataList.size(); i++) { + BindData bindData = dataList.get(i); + if (i == 0) { + cell.setData(bindData.getValue()); + cell.setBindData(bindData.getDataList()); + cell.setDataList(dataList); + cell.setTopGroupId(groupId); + DataUtils.cellList(cell, true, true); + continue; + } + boolean useBlank = rightBlankCellApply.useBlankCell(i, bindData); + if (useBlank) { + continue; + } + Cell newCell = cell.newCell(); + newCell.setColumnNumber(cell.getColumnNumber() + i); + newCell.setData(bindData.getValue()); + newCell.setBindData(bindData.getDataList()); + newCell.setDataList(dataList); + newCell.setTopGroupId(groupId); + newCell.setProcessed(true); + Cell topParentCell = cell.getTopParentCell(); + if (topParentCell != null) { + topParentCell.addColumnChild(newCell); + } + Cell leftParentCell = cell.getLeftParentCell(); + if (leftParentCell != null) { + leftParentCell.addRowChild(newCell); + } + DataUtils.cellList(newCell, true, true); + unit.setGroupId(RandomUtil.uuId()); + unit.duplicate(newCell, i); + lastCell = newCell; + } + unit.complete(); + return lastCell; + } + + private Range buildColRange(int mainCellRowNumber, Range range) { + int start = mainCellRowNumber + range.getStart(); + int end = mainCellRowNumber + range.getEnd(); + Range ranges = new Range(); + ranges.setStart(start); + ranges.setEnd(end); + return ranges; + } + + private RightDuplocatorWrapper buildCellRightDuplicator(Cell cell, Context context, Range range) { + RightDuplocatorWrapper duplicatorWrapper = new RightDuplocatorWrapper(cell.getName()); + buildParentCellDuplicators(cell, cell, duplicatorWrapper); + for (int i = range.getStart(); i <= range.getEnd(); i++) { + Column col = context.getColumn(i); + List colCells = col.getCells(); + for (Cell colCell : colCells) { + colCell.setTopGroupId(RandomUtil.uuId()); + buildDuplicator(duplicatorWrapper, cell, colCell, i); + } + } + return duplicatorWrapper; + } + + private void buildParentCellDuplicators(Cell cell, Cell mainCell, RightDuplocatorWrapper duplicatorWrapper) { + Cell topParentCell = cell.getTopParentCell(); + if (topParentCell == null) { + return; + } + buildDuplicator(duplicatorWrapper, mainCell, topParentCell, 0); + buildParentCellDuplicators(topParentCell, mainCell, duplicatorWrapper); + } + + private void buildDuplicator(RightDuplocatorWrapper duplicatorWrapper, Cell mainCell, Cell currentCell, + int currentCellColNumber) { + if (mainCell.equals(currentCell)) { + return; + } + String name = currentCell.getName(); + Map newBlankCellNamesMap = mainCell.getNewBlankCellsMap(); + List increaseCellNames = mainCell.getIncreaseSpanCellNames(); + List newCellNames = mainCell.getNewCellNames(); + if (newBlankCellNamesMap.containsKey(name)) { + if (!duplicatorWrapper.contains(currentCell)) { + CellRightDuplicator cellDuplicator = new CellRightDuplicator(currentCell, DuplicateType.Blank, + newBlankCellNamesMap.get(name), currentCellColNumber); + duplicatorWrapper.addCellRightDuplicator(cellDuplicator); + } + } else if (increaseCellNames.contains(name)) { + if (!duplicatorWrapper.contains(currentCell)) { + CellRightDuplicator cellDuplicator = new CellRightDuplicator(currentCell, DuplicateType.IncreaseSpan, + currentCellColNumber); + duplicatorWrapper.addCellRightDuplicator(cellDuplicator); + } + } else if (newCellNames.contains(name)) { + CellRightDuplicator cellDuplicator = new CellRightDuplicator(currentCell, DuplicateType.Duplicate, + currentCellColNumber); + duplicatorWrapper.addCellRightDuplicator(cellDuplicator); + } else if (mainCell.getName().equals(name)) { + CellRightDuplicator cellDuplicator = new CellRightDuplicator(currentCell, DuplicateType.Self, + currentCellColNumber); + duplicatorWrapper.addCellRightDuplicator(cellDuplicator); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/DatasetValueCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/DatasetValueCompute.java new file mode 100644 index 0000000..d73b010 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/DatasetValueCompute.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.compute; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.build.DatasetUtils; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; + +public class DatasetValueCompute implements ValueCompute { + @Override + public List compute(Cell cell, Context context) { + DatasetValue expr = (DatasetValue) cell.getValue(); + return DatasetUtils.computeDatasetExpression(expr, cell, context); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ExpressionValueCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ExpressionValueCompute.java new file mode 100644 index 0000000..1c12f16 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ExpressionValueCompute.java @@ -0,0 +1,59 @@ +package com.yunzhupaas.ureport.compute; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.ExpressionValue; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年12月27日 + */ +public class ExpressionValueCompute implements ValueCompute { + @Override + public List compute(Cell cell, Context context) { + ExpressionValue exprValue = (ExpressionValue) cell.getValue(); + Expression expr = exprValue.getExpression(); + List list = new ArrayList<>(); + if (expr != null) { + ExpressionData data = expr.execute(cell, cell, context); + if (data instanceof BindDataListExpressionData) { + BindDataListExpressionData exprData = (BindDataListExpressionData) data; + list.addAll(exprData.getData()); + } + Object obj = data.getData(); + if (obj instanceof List) { + List listData = (List) obj; + for (Object o : listData) { + BindData bindData = new BindData(); + bindData.setValue(o); + list.add(bindData); + } + } else { + if (obj != null) { + BindData bindData = new BindData(); + bindData.setValue(obj); + list.add(bindData); + } + } + } + if (list.isEmpty()) { + List> rowList = new ArrayList<>(); + rowList.add(new HashMap<>()); + BindData bindData = new BindData(); + bindData.setValue(""); + bindData.setDataList(rowList); + list.add(bindData); + } + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/SimpleValueCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/SimpleValueCompute.java new file mode 100644 index 0000000..27076b6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/SimpleValueCompute.java @@ -0,0 +1,21 @@ +package com.yunzhupaas.ureport.compute; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleValueCompute implements ValueCompute { + + @Override + public List compute(Cell cell, Context context) { + List list = new ArrayList<>(); + BindData bindData = new BindData(); + bindData.setValue(cell.getValue().getValue()); + list.add(bindData); + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ValueCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ValueCompute.java new file mode 100644 index 0000000..9d30ab6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ValueCompute.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.ureport.compute; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; + +public interface ValueCompute { + List compute(Cell cell, Context context); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ZxingValueCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ZxingValueCompute.java new file mode 100644 index 0000000..96ab83b --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/compute/ZxingValueCompute.java @@ -0,0 +1,116 @@ +package com.yunzhupaas.ureport.compute; + +import cn.hutool.core.img.ImgUtil; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.client.j2se.MatrixToImageConfig; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.ZxingValue; +import com.yunzhupaas.ureport.model.Cell; +import org.apache.commons.lang3.StringUtils; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +public class ZxingValueCompute implements ValueCompute { + @Override + public List compute(Cell cell, Context context) { + List list = new ArrayList<>(); + ZxingValue value = (ZxingValue) cell.getValue(); + String format = value.getFormat(); + BarcodeFormat barcodeForamt = BarcodeFormat.QR_CODE; + if (StringUtils.isNotBlank(format)) { + barcodeForamt = BarcodeFormat.valueOf(format); + } + String image = base64Image(barcodeForamt, value); + BindData data = new BindData(); + data.setValue(image); + list.add(data); + return list; + } + + public String base64Image(BarcodeFormat format, ZxingValue zxingValue) { + String baset64 = ""; + try { + String value = zxingValue.getValue(); + int height = zxingValue.getHeight(); + int width = zxingValue.getWidth(); + boolean remark = zxingValue.isRemark(); + // 编码内容, 编码类型, 宽度, 高度, 设置参数 + Map hints = new Hashtable<>(); + hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); + // 设置容错等级 + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + // 设置边距 + hints.put(EncodeHintType.MARGIN, 0); + BitMatrix matrix = new MultiFormatWriter().encode(value, format, width, height, hints); + + // 动态计算增加的高度用于备注文本 + int textHeight = remark ? 30 : 0; + + String backgroundColor = zxingValue.getBackgroundColor(); + int background = rgb(backgroundColor, MatrixToImageConfig.WHITE); + String foregroundColor = zxingValue.getForegroundColor(); + int foreground = rgb(foregroundColor, MatrixToImageConfig.BLACK); + MatrixToImageConfig config = new MatrixToImageConfig(background, foreground); + // 创建带有二维码和备注文本的 + BufferedImage image = new BufferedImage(width, height + textHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setColor(new Color(background)); + g.fillRect(0, 0, width, height + textHeight); + + // 绘制二维码到 BufferedImage + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, matrix.get(x, y) ? foreground : background); + } + } + // 添加备注文本 + if (remark) { + addText(image, value, width, height, textHeight, config); + } + baset64 = "data:image/jpeg;base64," + ImgUtil.toBase64(image, "jpeg"); + } catch (Exception e) { + } + return baset64; + } + + private int rgb(String rgbCole, int imageColor) { + Color color = null; + try { + color = new Color(Integer.parseInt(rgbCole.substring(1), 16)); + } catch (Exception e) { + } + return color == null ? imageColor : color.getRGB(); + } + + // 底部添加文本 + private static void addText(BufferedImage image, String text, int width, int height, int textHeight, + MatrixToImageConfig config) { + Graphics2D g2 = image.createGraphics(); + g2.setColor(new Color(config.getPixelOffColor())); + g2.setFont(new Font("Arial", Font.PLAIN, 20)); // 设置字体 + + // 获取文本的宽度以便居中对齐 + FontMetrics fm = g2.getFontMetrics(); + int textWidth = fm.stringWidth(text); + int x = (width - textWidth) / 2; + + // 调整 y 坐标位置,将文本稍微上移 + int padding = 5; // 增加一个 padding 值,让文本上移一点,避免贴得太近 + int y = height + (textHeight - fm.getHeight()) / 2 + fm.getAscent() - padding; + + // 绘制文本 + g2.drawString(text, x, y); + g2.dispose(); // 释放资源 + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/BlankCellInfo.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/BlankCellInfo.java new file mode 100644 index 0000000..81f3e98 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/BlankCellInfo.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.definition; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class BlankCellInfo { + private int offset; + private int span; + private boolean parent; + + public BlankCellInfo(int offset, int span, boolean parent) { + this.offset = offset; + this.span = span; + this.parent = parent; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/CellDefinition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/CellDefinition.java new file mode 100644 index 0000000..8a3d240 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/CellDefinition.java @@ -0,0 +1,115 @@ +package com.yunzhupaas.ureport.definition; + +import com.yunzhupaas.univer.sheet.UniverSheetCellData; +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.model.Cell; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.yunzhupaas.univer.sheet.UniverSheetColumnData; +import com.yunzhupaas.univer.sheet.UniverSheetRowData; +import com.yunzhupaas.ureport.model.StyleModel; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class CellDefinition { + private int rowNumber; + private int columnNumber; + private int rowSpan; + private int colSpan; + private String name; + private Value value; + private StyleModel styleModel; + private UniverSheetRowData sheetRowData; + private UniverSheetColumnData sheetColumnData; + + private String linkUrl; + private String linkTargetWindow; + + private boolean fillBlankRows; + /** + * 允许填充空白行时fillBlankRows=true,要求当前数据行数必须是multiple定义的行数的倍数,否则就补充空白行 + */ + private int multiple; + + private Expand expand = Expand.None; + + @JsonIgnore + private Range duplicateRange; + @JsonIgnore + private List increaseSpanCellNames = new ArrayList<>(); + @JsonIgnore + private Map newBlankCellsMap = new HashMap<>(); + @JsonIgnore + private List newCellNames = new ArrayList<>(); + + private UniverSheetCellData cellData; + + /** + * 左父格类型 + */ + private String leftType; + /** + * 上父格类型 + */ + private String topType; + /** + * 当前单元格左父格名 + */ + private String leftParentCellName; + /** + * 当前单元格上父格名 + */ + private String topParentCellName; + /** + * 当前单元格左父格 + */ + @JsonIgnore + private CellDefinition leftParentCell; + /** + * 当前单元格上父格 + */ + @JsonIgnore + private CellDefinition topParentCell; + /** + * 当前单无格所在行的所有子格 + */ + @JsonIgnore + private List rowChildrenCells = new ArrayList<>(); + /** + * 当前单无格所在列的所有子格 + */ + @JsonIgnore + private List columnChildrenCells = new ArrayList<>(); + + protected Cell newCell() { + Cell cell = new Cell(); + cell.setValue(value); + cell.setName(name); + cell.setRowSpan(rowSpan); + cell.setColSpan(colSpan); + cell.setExpand(expand); + cell.setDuplicateRange(duplicateRange); + cell.setRowNumber(rowNumber); + cell.setColumnNumber(columnNumber); + cell.setStyleModel(styleModel); + cell.setSheetRowData(sheetRowData); + cell.setSheetColumnData(sheetColumnData); + cell.setCellData(cellData); + cell.setNewBlankCellsMap(newBlankCellsMap); + cell.setIncreaseSpanCellNames(increaseSpanCellNames); + cell.setNewCellNames(newCellNames); + cell.setFillBlankRows(fillBlankRows); + cell.setMultiple(multiple); + cell.setLeftType(leftType); + cell.setTopType(topType); + return cell; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ColumnDefinition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ColumnDefinition.java new file mode 100644 index 0000000..8ad1747 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ColumnDefinition.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.ureport.definition; + +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.univer.sheet.UniverSheetColumnData; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Setter +@Getter +public class ColumnDefinition { + private int columnNumber; + private boolean freeze; + private UniverSheetColumnData sheetColumnData; + + protected Column newColumn(List columns) { + Column col = new Column(columns); + col.setFreeze(freeze); + col.setSheetColumnData(sheetColumnData); + return col; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/Expand.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/Expand.java new file mode 100644 index 0000000..d7697ca --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/Expand.java @@ -0,0 +1,5 @@ +package com.yunzhupaas.ureport.definition; + +public enum Expand { + Right, Down, None +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ReportDefinition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ReportDefinition.java new file mode 100644 index 0000000..6853045 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/ReportDefinition.java @@ -0,0 +1,97 @@ +package com.yunzhupaas.ureport.definition; + +import com.yunzhupaas.ureport.build.Dataset; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; +import com.yunzhupaas.ureport.model.Report; +import com.yunzhupaas.ureport.model.Row; +import com.yunzhupaas.ureport.utils.DataUtils; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class ReportDefinition { + private String reportFullName; + private CellDefinition rootCell; + private List cells; + private List rows; + private List columns; + private Map datasetMap; + + public Report newReport() { + Report report = new Report(); + report.setReportFullName(reportFullName); + List reportRows = new ArrayList<>(); + List reportColumns = new ArrayList<>(); + report.setRows(reportRows); + report.setColumns(reportColumns); + Map rowMap = new HashMap<>(); + for (RowDefinition rowDef : rows) { + Row newRow = rowDef.newRow(reportRows); + report.insertRow(newRow, rowDef.getRowNumber()); + rowMap.put(rowDef.getRowNumber(), newRow); + } + Map columnMap = new HashMap<>(); + for (ColumnDefinition columnDef : columns) { + Column newColumn = columnDef.newColumn(reportColumns); + report.insertColumn(newColumn, columnDef.getColumnNumber()); + columnMap.put(columnDef.getColumnNumber(), newColumn); + } + Map cellMap = new HashMap<>(); + for (CellDefinition cellDef : cells) { + Cell cell = cellDef.newCell(); + cellMap.put(cellDef, cell); + Row targetRow = rowMap.get(cellDef.getRowNumber()); + cell.setRow(targetRow); + targetRow.getCells().add(cell); + Column targetColumn = columnMap.get(cellDef.getColumnNumber()); + cell.setColumn(targetColumn); + targetColumn.getCells().add(cell); + + if (cellDef.getLeftParentCell() == null && cellDef.getTopParentCell() == null) { + report.setRootCell(cell); + } + report.addCell(cell); + } + for (CellDefinition cellDef : cells) { + Cell targetCell = cellMap.get(cellDef); + CellDefinition leftParentCellDef = cellDef.getLeftParentCell(); + if (leftParentCellDef != null) { + targetCell.setLeftParentCell(cellMap.get(leftParentCellDef)); + } else { + targetCell.setLeftParentCell(null); + } + CellDefinition topParentCellDef = cellDef.getTopParentCell(); + if (topParentCellDef != null) { + targetCell.setTopParentCell(cellMap.get(topParentCellDef)); + } else { + targetCell.setTopParentCell(null); + } + DataUtils.cellList(targetCell, true, true); + } + // for (CellDefinition cellDef : cells) { + // Cell targetCell = cellMap.get(cellDef); + // + // List rowChildrenCellDefinitions = + // cellDef.getRowChildrenCells(); + // for (CellDefinition childCellDef : rowChildrenCellDefinitions) { + // Cell childCell = cellMap.get(childCellDef); + // targetCell.addRowChild(childCell); + // } + // List columnChildrenCellDefinitions = + // cellDef.getColumnChildrenCells(); + // for (CellDefinition childCellDef : columnChildrenCellDefinitions) { + // Cell childCell = cellMap.get(childCellDef); + // targetCell.addColumnChild(childCell); + // } + // } + return report; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/RowDefinition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/RowDefinition.java new file mode 100644 index 0000000..37d6fb2 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/RowDefinition.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.definition; + +import com.yunzhupaas.ureport.model.Row; +import com.yunzhupaas.univer.sheet.UniverSheetRowData; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class RowDefinition { + private int rowNumber; + private boolean freeze; + private UniverSheetRowData sheetRowData; + + protected Row newRow(List rows) { + Row row = new Row(rows); + row.setRowKey("r" + rowNumber); + row.setFreeze(freeze); + row.setSheetRowData(sheetRowData); + return row; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/AggregateType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/AggregateType.java new file mode 100644 index 0000000..b86166b --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/AggregateType.java @@ -0,0 +1,14 @@ +package com.yunzhupaas.ureport.definition.value; + +public enum AggregateType { + group, select, sum, avg, max, min, count, none; + + public static AggregateType value(String value) { + for (AggregateType aggregate : AggregateType.values()) { + if (aggregate.name().equalsIgnoreCase(value)) { + return aggregate; + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/DatasetValue.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/DatasetValue.java new file mode 100644 index 0000000..f2c8809 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/DatasetValue.java @@ -0,0 +1,36 @@ +package com.yunzhupaas.ureport.definition.value; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class DatasetValue implements Value { + + private String datasetName; + private AggregateType aggregate; + private String property; + + @Override + public String getValue() { + StringBuffer sb = new StringBuffer(); + sb.append(getDatasetName()); + sb.append("."); + sb.append(getAggregate().name()); + sb.append("("); + String prop = getProperty(); + if (prop != null) { + if (prop.length() > 13) { + prop = prop.substring(0, 10) + "..."; + } + sb.append(prop); + } + sb.append(")"); + return sb.toString(); + } + + @Override + public String getType() { + return ValueType.dataset.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ExpressionValue.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ExpressionValue.java new file mode 100644 index 0000000..949a11a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ExpressionValue.java @@ -0,0 +1,26 @@ +package com.yunzhupaas.ureport.definition.value; + +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.expression.util.ExpressionUtils; +import lombok.Getter; +import lombok.Setter; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/10/31 下午5:48 + */ +@Setter +@Getter +public class ExpressionValue { + + private String text; + private Expression expression; + + public ExpressionValue(String text) { + this.text = text; + expression = ExpressionUtils.parseExpression(text); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/SimpleValue.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/SimpleValue.java new file mode 100644 index 0000000..b7f75da --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/SimpleValue.java @@ -0,0 +1,19 @@ +package com.yunzhupaas.ureport.definition.value; + +public class SimpleValue implements Value { + private String value; + + public SimpleValue(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getType() { + return ValueType.simple.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/Value.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/Value.java new file mode 100644 index 0000000..0508dd4 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/Value.java @@ -0,0 +1,7 @@ +package com.yunzhupaas.ureport.definition.value; + +public interface Value { + String getValue(); + + String getType(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ValueType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ValueType.java new file mode 100644 index 0000000..86f0c6f --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ValueType.java @@ -0,0 +1,5 @@ +package com.yunzhupaas.ureport.definition.value; + +public enum ValueType { + simple, zxing, dataset, expression +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ZxingValue.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ZxingValue.java new file mode 100644 index 0000000..6ef5855 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/definition/value/ZxingValue.java @@ -0,0 +1,31 @@ +package com.yunzhupaas.ureport.definition.value; + +import lombok.Data; + +/** + * @author + * @since 3月26日 + */ +@Data +public class ZxingValue implements Value { + private int width; + private int height; + private String text; + private String format; + // 背景色 + private String backgroundColor; + // 前景色 + private String foregroundColor; + // 是否显示文字 + private boolean remark; + + @Override + public String getValue() { + return text; + } + + @Override + public String getType() { + return ValueType.zxing.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportLexer.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportLexer.java new file mode 100644 index 0000000..62f9c2d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportLexer.java @@ -0,0 +1,253 @@ +package com.yunzhupaas.ureport.expression.antlr; + +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.ATN; +import org.antlr.v4.runtime.atn.ATNDeserializer; +import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.dfa.DFA; + +public class ReportLexer extends Lexer { + public static final int T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, T__7 = 8, T__8 = 9, + T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14, T__14 = 15, T__15 = 16, T__16 = 17, + T__17 = 18, T__18 = 19, Cell = 20, Operator = 21, OP = 22, ORDER = 23, BOOLEAN = 24, + COLON = 25, COMMA = 26, NULL = 27, LeftParen = 28, RightParen = 29, STRING = 30, AND = 31, + OR = 32, INTEGER = 33, NUMBER = 34, EXCLAMATION = 35, EXP = 36, Identifier = 37, LETTER = 38, + Char = 39, DIGIT = 40, WS = 41, NL = 42; + public static final String[] ruleNames = { + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", + "T__17", "T__18", "Cell", "Operator", "OP", "ORDER", "BOOLEAN", "COLON", + "COMMA", "NULL", "LeftParen", "RightParen", "STRING", "AND", "OR", "INTEGER", + "NUMBER", "EXCLAMATION", "EXP", "Identifier", "LETTER", "Char", "DIGIT", + "STRING_CONTENT", "EscapeSequence", "OctalEscape", "UnicodeEscape", "HEX", + "StartChar", "WS", "NL" + }; + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + public static final String _serializedATN = "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2,\u0177\b\1\4\2\t" + + + "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13" + + "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22" + + "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31" + + "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!" + + "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4'\t'\4(\t(\4)\t)\4*\t*\4+\t+\4" + + ",\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\3\2\3\2\3\3\3\3\3\3\3\3\3\3" + + "\3\4\3\4\3\5\3\5\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3" + + "\b\3\b\3\t\3\t\3\n\3\n\3\n\3\n\3\13\3\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17" + + "\3\17\3\20\3\20\3\20\3\20\3\20\3\21\3\21\3\22\3\22\3\23\3\23\3\23\3\24" + + "\3\24\3\25\3\25\6\25\u009e\n\25\r\25\16\25\u009f\3\26\3\26\3\27\3\27\3" + + "\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3" + + "\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\5\27\u00c0" + + "\n\27\3\30\3\30\3\30\3\30\3\30\3\30\3\30\5\30\u00c9\n\30\3\31\3\31\3\31" + + "\3\31\3\31\3\31\3\31\3\31\3\31\5\31\u00d4\n\31\3\32\3\32\3\33\3\33\3\34" + + "\3\34\3\34\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3\37\3\37\3\37\3\37" + + "\3\37\3\37\5\37\u00eb\n\37\3 \3 \3 \3 \3 \5 \u00f2\n \3!\3!\3!\3!\5!\u00f8" + + "\n!\3\"\5\"\u00fb\n\"\3\"\6\"\u00fe\n\"\r\"\16\"\u00ff\3#\5#\u0103\n#" + + "\3#\6#\u0106\n#\r#\16#\u0107\3#\3#\6#\u010c\n#\r#\16#\u010d\3#\5#\u0111" + + "\n#\3#\5#\u0114\n#\3#\6#\u0117\n#\r#\16#\u0118\3#\3#\3#\5#\u011e\n#\3" + + "#\6#\u0121\n#\r#\16#\u0122\5#\u0125\n#\3$\3$\3%\3%\5%\u012b\n%\3%\6%\u012e" + + "\n%\r%\16%\u012f\3&\3&\7&\u0134\n&\f&\16&\u0137\13&\3'\6'\u013a\n'" + + "\r'\16'\u013b\3(\3(\3(\3(\5(\u0142\n(\3)\3)\3*\3*\7*\u0148\n*\f*\16" + + "*\u014b\13*\3+\3+\3+\3+\5+\u0151\n+\3,\3,\3,\3,\3,\3,\3,\3,\3,\5,\u015c" + + "\n,\3-\3-\3-\3-\3-\3-\3-\3.\3.\3/\5/\u0168\n/\3\60\6\60\u016b\n\60\r\60" + + "\16\60\u016c\3\60\3\60\3\61\5\61\u0172\n\61\3\61\3\61\3\61\3\61\2\2\62" + + "\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35\20" + + "\37\21!\22#\23%\24'\25)\26+\27-\30/\31\61\32\63\33\65\34\67\359\36;\37" + + "= ?!A\"C#E$G%I&K'M(O)Q*S\2U\2W\2Y\2[\2]\2_+a,\3\2\17\6\2'',-//\61\61" + + "\4\2>>@@\4\2GGgg\4\2--//\3\2C\\\4\2//aa\5\2\u00b9\u00b9\u0302\u0371\u2041" + + "\u2042\3\2\62;\4\2$$))\n\2$$))^^ddhhppttvv\5\2\62;CHch\t\2C\\c|\u2072" + + "\u2191\u2c02\u2ff1\u3003\ud801\uf902\ufdd1\ufdf2\uffff\5\2\13\f\17\17" + + "\"\"\u0199\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2" + + "\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27" + + "\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2" + + "\2\2#\3\2\2\2\2%\3\2\2\2\2'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2" + + "\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2" + + "\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2" + + "\2G\3\2\2\2\2I\3\2\2\2\2K\3\2\2\2\2M\3\2\2\2\2O\3\2\2\2\2Q\3\2\2\2\2_" + + "\3\2\2\2\2a\3\2\2\2\3c\3\2\2\2\5e\3\2\2\2\7j\3\2\2\2\tl\3\2\2\2\13n\3" + + "\2\2\2\rq\3\2\2\2\17v\3\2\2\2\21}\3\2\2\2\23\177\3\2\2\2\25\u0083\3\2" + + "\2\2\27\u0085\3\2\2\2\31\u0087\3\2\2\2\33\u0089\3\2\2\2\35\u008b\3\2\2" + + "\2\37\u008d\3\2\2\2!\u0092\3\2\2\2#\u0094\3\2\2\2%\u0096\3\2\2\2'\u0099" + + "\3\2\2\2)\u009b\3\2\2\2+\u00a1\3\2\2\2-\u00bf\3\2\2\2/\u00c8\3\2\2\2\61" + + "\u00d3\3\2\2\2\63\u00d5\3\2\2\2\65\u00d7\3\2\2\2\67\u00d9\3\2\2\29\u00de" + + "\3\2\2\2;\u00e0\3\2\2\2=\u00ea\3\2\2\2?\u00f1\3\2\2\2A\u00f7\3\2\2\2C" + + "\u00fa\3\2\2\2E\u0124\3\2\2\2G\u0126\3\2\2\2I\u0128\3\2\2\2K\u0131\3\2" + + "\2\2M\u0139\3\2\2\2O\u0141\3\2\2\2Q\u0143\3\2\2\2S\u0149\3\2\2\2U\u0150" + + "\3\2\2\2W\u015b\3\2\2\2Y\u015d\3\2\2\2[\u0164\3\2\2\2]\u0167\3\2\2\2_" + + "\u016a\3\2\2\2a\u0171\3\2\2\2cd\7A\2\2d\4\3\2\2\2ef\7e\2\2fg\7c\2\2gh" + + "\7u\2\2hi\7g\2\2i\6\3\2\2\2jk\7}\2\2k\b\3\2\2\2lm\7\177\2\2m\n\3\2\2\2" + + "no\7k\2\2op\7h\2\2p\f\3\2\2\2qr\7g\2\2rs\7n\2\2st\7u\2\2tu\7g\2\2u\16" + + "\3\2\2\2vw\7t\2\2wx\7g\2\2xy\7v\2\2yz\7w\2\2z{\7t\2\2{|\7p\2\2|\20\3\2" + + "\2\2}~\7=\2\2~\22\3\2\2\2\177\u0080\7x\2\2\u0080\u0081\7c\2\2\u0081\u0082" + + "\7t\2\2\u0082\24\3\2\2\2\u0083\u0084\7?\2\2\u0084\26\3\2\2\2\u0085\u0086" + + "\7(\2\2\u0086\30\3\2\2\2\u0087\u0088\7&\2\2\u0088\32\3\2\2\2\u0089\u008a" + + "\7%\2\2\u008a\34\3\2\2\2\u008b\u008c\7\60\2\2\u008c\36\3\2\2\2\u008d\u008e" + + "\7e\2\2\u008e\u008f\7g\2\2\u008f\u0090\7n\2\2\u0090\u0091\7n\2\2\u0091" + + " \3\2\2\2\u0092\u0093\7]\2\2\u0093\"\3\2\2\2\u0094\u0095\7_\2\2\u0095" + + "$\3\2\2\2\u0096\u0097\7v\2\2\u0097\u0098\7q\2\2\u0098&\3\2\2\2\u0099\u009a" + + "\7B\2\2\u009a(\3\2\2\2\u009b\u009d\5M'\2\u009c\u009e\5Q)\2\u009d\u009c" + + "\3\2\2\2\u009e\u009f\3\2\2\2\u009f\u009d\3\2\2\2\u009f\u00a0\3\2\2\2\u00a0" + + "*\3\2\2\2\u00a1\u00a2\t\2\2\2\u00a2,\3\2\2\2\u00a3\u00c0\t\3\2\2\u00a4" + + "\u00a5\7?\2\2\u00a5\u00c0\7?\2\2\u00a6\u00a7\7#\2\2\u00a7\u00c0\7?\2\2" + + "\u00a8\u00a9\7@\2\2\u00a9\u00c0\7?\2\2\u00aa\u00ab\7>\2\2\u00ab\u00c0" + + "\7?\2\2\u00ac\u00ad\7k\2\2\u00ad\u00c0\7p\2\2\u00ae\u00af\7p\2\2\u00af" + + "\u00b0\7q\2\2\u00b0\u00b1\7v\2\2\u00b1\u00b2\7\"\2\2\u00b2\u00b3\7k\2" + + "\2\u00b3\u00c0\7p\2\2\u00b4\u00b5\7p\2\2\u00b5\u00b6\7q\2\2\u00b6\u00b7" + + "\7v\2\2\u00b7\u00b8\7\"\2\2\u00b8\u00b9\7\"\2\2\u00b9\u00ba\7k\2\2\u00ba" + + "\u00c0\7p\2\2\u00bb\u00bc\7n\2\2\u00bc\u00bd\7k\2\2\u00bd\u00be\7m\2\2" + + "\u00be\u00c0\7g\2\2\u00bf\u00a3\3\2\2\2\u00bf\u00a4\3\2\2\2\u00bf\u00a6" + + "\3\2\2\2\u00bf\u00a8\3\2\2\2\u00bf\u00aa\3\2\2\2\u00bf\u00ac\3\2\2\2\u00bf" + + "\u00ae\3\2\2\2\u00bf\u00b4\3\2\2\2\u00bf\u00bb\3\2\2\2\u00c0.\3\2\2\2" + + "\u00c1\u00c2\7f\2\2\u00c2\u00c3\7g\2\2\u00c3\u00c4\7u\2\2\u00c4\u00c9" + + "\7e\2\2\u00c5\u00c6\7c\2\2\u00c6\u00c7\7u\2\2\u00c7\u00c9\7e\2\2\u00c8" + + "\u00c1\3\2\2\2\u00c8\u00c5\3\2\2\2\u00c9\60\3\2\2\2\u00ca\u00cb\7v\2\2" + + "\u00cb\u00cc\7t\2\2\u00cc\u00cd\7w\2\2\u00cd\u00d4\7g\2\2\u00ce\u00cf" + + "\7h\2\2\u00cf\u00d0\7c\2\2\u00d0\u00d1\7n\2\2\u00d1\u00d2\7u\2\2\u00d2" + + "\u00d4\7g\2\2\u00d3\u00ca\3\2\2\2\u00d3\u00ce\3\2\2\2\u00d4\62\3\2\2\2" + + "\u00d5\u00d6\7<\2\2\u00d6\64\3\2\2\2\u00d7\u00d8\7.\2\2\u00d8\66\3\2\2" + + "\2\u00d9\u00da\7p\2\2\u00da\u00db\7w\2\2\u00db\u00dc\7n\2\2\u00dc\u00dd" + + "\7n\2\2\u00dd8\3\2\2\2\u00de\u00df\7*\2\2\u00df:\3\2\2\2\u00e0\u00e1\7" + + "+\2\2\u00e1<\3\2\2\2\u00e2\u00e3\7$\2\2\u00e3\u00e4\5S*\2\u00e4\u00e5" + + "\7$\2\2\u00e5\u00eb\3\2\2\2\u00e6\u00e7\7)\2\2\u00e7\u00e8\5S*\2\u00e8" + + "\u00e9\7)\2\2\u00e9\u00eb\3\2\2\2\u00ea\u00e2\3\2\2\2\u00ea\u00e6\3\2" + + "\2\2\u00eb>\3\2\2\2\u00ec\u00ed\7c\2\2\u00ed\u00ee\7p\2\2\u00ee\u00f2" + + "\7f\2\2\u00ef\u00f0\7(\2\2\u00f0\u00f2\7(\2\2\u00f1\u00ec\3\2\2\2\u00f1" + + "\u00ef\3\2\2\2\u00f2@\3\2\2\2\u00f3\u00f4\7q\2\2\u00f4\u00f8\7t\2\2\u00f5" + + "\u00f6\7~\2\2\u00f6\u00f8\7~\2\2\u00f7\u00f3\3\2\2\2\u00f7\u00f5\3\2\2" + + "\2\u00f8B\3\2\2\2\u00f9\u00fb\7/\2\2\u00fa\u00f9\3\2\2\2\u00fa\u00fb\3" + + "\2\2\2\u00fb\u00fd\3\2\2\2\u00fc\u00fe\5Q)\2\u00fd\u00fc\3\2\2\2\u00fe" + + "\u00ff\3\2\2\2\u00ff\u00fd\3\2\2\2\u00ff\u0100\3\2\2\2\u0100D\3\2\2\2" + + "\u0101\u0103\7/\2\2\u0102\u0101\3\2\2\2\u0102\u0103\3\2\2\2\u0103\u0105" + + "\3\2\2\2\u0104\u0106\5Q)\2\u0105\u0104\3\2\2\2\u0106\u0107\3\2\2\2\u0107" + + "\u0105\3\2\2\2\u0107\u0108\3\2\2\2\u0108\u0109\3\2\2\2\u0109\u010b\7\60" + + "\2\2\u010a\u010c\5Q)\2\u010b\u010a\3\2\2\2\u010c\u010d\3\2\2\2\u010d\u010b" + + "\3\2\2\2\u010d\u010e\3\2\2\2\u010e\u0110\3\2\2\2\u010f\u0111\5I%\2\u0110" + + "\u010f\3\2\2\2\u0110\u0111\3\2\2\2\u0111\u0125\3\2\2\2\u0112\u0114\7/" + + "\2\2\u0113\u0112\3\2\2\2\u0113\u0114\3\2\2\2\u0114\u0116\3\2\2\2\u0115" + + "\u0117\5Q)\2\u0116\u0115\3\2\2\2\u0117\u0118\3\2\2\2\u0118\u0116\3\2\2" + + "\2\u0118\u0119\3\2\2\2\u0119\u011a\3\2\2\2\u011a\u011b\5I%\2\u011b\u0125" + + "\3\2\2\2\u011c\u011e\7/\2\2\u011d\u011c\3\2\2\2\u011d\u011e\3\2\2\2\u011e" + + "\u0120\3\2\2\2\u011f\u0121\5Q)\2\u0120\u011f\3\2\2\2\u0121\u0122\3\2\2" + + "\2\u0122\u0120\3\2\2\2\u0122\u0123\3\2\2\2\u0123\u0125\3\2\2\2\u0124\u0102" + + "\3\2\2\2\u0124\u0113\3\2\2\2\u0124\u011d\3\2\2\2\u0125F\3\2\2\2\u0126" + + "\u0127\7#\2\2\u0127H\3\2\2\2\u0128\u012a\t\4\2\2\u0129\u012b\t\5\2\2\u012a" + + "\u0129\3\2\2\2\u012a\u012b\3\2\2\2\u012b\u012d\3\2\2\2\u012c\u012e\5Q" + + ")\2\u012d\u012c\3\2\2\2\u012e\u012f\3\2\2\2\u012f\u012d\3\2\2\2\u012f" + + "\u0130\3\2\2\2\u0130J\3\2\2\2\u0131\u0135\5]/\2\u0132\u0134\5O(\2\u0133" + + "\u0132\3\2\2\2\u0134\u0137\3\2\2\2\u0135\u0133\3\2\2\2\u0135\u0136\3\2" + + "\2\2\u0136L\3\2\2\2\u0137\u0135\3\2\2\2\u0138\u013a\t\6\2\2\u0139\u0138" + + "\3\2\2\2\u013a\u013b\3\2\2\2\u013b\u0139\3\2\2\2\u013b\u013c\3\2\2\2\u013c" + + "N\3\2\2\2\u013d\u0142\5]/\2\u013e\u0142\t\7\2\2\u013f\u0142\5Q)\2\u0140" + + "\u0142\t\b\2\2\u0141\u013d\3\2\2\2\u0141\u013e\3\2\2\2\u0141\u013f\3\2" + + "\2\2\u0141\u0140\3\2\2\2\u0142P\3\2\2\2\u0143\u0144\t\t\2\2\u0144R\3\2" + + "\2\2\u0145\u0148\5U+\2\u0146\u0148\n\n\2\2\u0147\u0145\3\2\2\2\u0147\u0146" + + "\3\2\2\2\u0148\u014b\3\2\2\2\u0149\u0147\3\2\2\2\u0149\u014a\3\2\2\2\u014a" + + "T\3\2\2\2\u014b\u0149\3\2\2\2\u014c\u014d\7^\2\2\u014d\u0151\t\13\2\2" + + "\u014e\u0151\5Y-\2\u014f\u0151\5W,\2\u0150\u014c\3\2\2\2\u0150\u014e\3" + + "\2\2\2\u0150\u014f\3\2\2\2\u0151V\3\2\2\2\u0152\u0153\7^\2\2\u0153\u0154" + + "\4\62\65\2\u0154\u0155\4\629\2\u0155\u015c\4\629\2\u0156\u0157\7^\2\2" + + "\u0157\u0158\4\629\2\u0158\u015c\4\629\2\u0159\u015a\7^\2\2\u015a\u015c" + + "\4\629\2\u015b\u0152\3\2\2\2\u015b\u0156\3\2\2\2\u015b\u0159\3\2\2\2\u015c" + + "X\3\2\2\2\u015d\u015e\7^\2\2\u015e\u015f\7w\2\2\u015f\u0160\5[.\2\u0160" + + "\u0161\5[.\2\u0161\u0162\5[.\2\u0162\u0163\5[.\2\u0163Z\3\2\2\2\u0164" + + "\u0165\t\f\2\2\u0165\\\3\2\2\2\u0166\u0168\t\r\2\2\u0167\u0166\3\2\2\2" + + "\u0168^\3\2\2\2\u0169\u016b\t\16\2\2\u016a\u0169\3\2\2\2\u016b\u016c\3" + + "\2\2\2\u016c\u016a\3\2\2\2\u016c\u016d\3\2\2\2\u016d\u016e\3\2\2\2\u016e" + + "\u016f\b\60\2\2\u016f`\3\2\2\2\u0170\u0172\7\17\2\2\u0171\u0170\3\2\2" + + "\2\u0171\u0172\3\2\2\2\u0172\u0173\3\2\2\2\u0173\u0174\7\f\2\2\u0174\u0175" + + "\3\2\2\2\u0175\u0176\b\61\2\2\u0176b\3\2\2\2!\2\u009f\u00bf\u00c8\u00d3" + + "\u00ea\u00f1\u00f7\u00fa\u00ff\u0102\u0107\u010d\u0110\u0113\u0118\u011d" + + "\u0122\u0124\u012a\u012f\u0135\u013b\u0141\u0147\u0149\u0150\u015b\u0167" + + "\u016c\u0171\3\2\3\2"; + public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); + private static final String[] _LITERAL_NAMES = { + null, "'?'", "'case'", "'{'", "'}'", "'if'", "'else'", "'return'", "';'", + "'var'", "'='", "'&'", "'$'", "'#'", "'.'", "'cell'", "'['", "']'", "'to'", + "'@'", null, null, null, null, null, "':'", "','", "'null'", "'('", "')'", + null, null, null, null, null, "'!'" + }; + private static final String[] _SYMBOLIC_NAMES = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, "Cell", "Operator", "OP", + "ORDER", "BOOLEAN", "COLON", "COMMA", "NULL", "LeftParen", "RightParen", + "STRING", "AND", "OR", "INTEGER", "NUMBER", "EXCLAMATION", "EXP", "Identifier", + "LETTER", "Char", "DIGIT", "WS", "NL" + }; + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + static { + RuntimeMetaData.checkVersion("4.5.3", RuntimeMetaData.VERSION); + } + + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } + + public ReportLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache); + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { + return "ReportParser.g4"; + } + + @Override + public String[] getRuleNames() { + return ruleNames; + } + + @Override + public String getSerializedATN() { + return _serializedATN; + } + + @Override + public String[] getModeNames() { + return modeNames; + } + + @Override + public ATN getATN() { + return _ATN; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportListener.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportListener.java new file mode 100644 index 0000000..3b6ee97 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportListener.java @@ -0,0 +1,31 @@ +package com.yunzhupaas.ureport.expression.antlr; + +import org.antlr.v4.runtime.BaseErrorListener; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.Recognizer; + +/** + * @author + * @since 2016年12月6日 + */ +public class ReportListener extends BaseErrorListener { + private StringBuffer sb; + + @Override + public void syntaxError(Recognizer recognizer, Object offendingSymbol, + int line, int charPositionInLine, + String msg, RecognitionException e) { + if (sb == null) { + sb = new StringBuffer(); + } + sb.append("[" + offendingSymbol + "] is invalid:" + msg); + sb.append("\r\n"); + } + + public String getErrorMessage() { + if (sb == null) { + return null; + } + return sb.toString(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportParser.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportParser.java new file mode 100644 index 0000000..cbfa829 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportParser.java @@ -0,0 +1,3605 @@ +package com.yunzhupaas.ureport.expression.antlr; + +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.ATN; +import org.antlr.v4.runtime.atn.ATNDeserializer; +import org.antlr.v4.runtime.atn.ParserATNSimulator; +import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.tree.ParseTreeVisitor; +import org.antlr.v4.runtime.tree.TerminalNode; + +import java.util.List; + +public class ReportParser extends Parser { + public static final int T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, T__7 = 8, T__8 = 9, + T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14, T__14 = 15, T__15 = 16, T__16 = 17, + T__17 = 18, T__18 = 19, Cell = 20, Operator = 21, OP = 22, ORDER = 23, BOOLEAN = 24, + COLON = 25, COMMA = 26, NULL = 27, LeftParen = 28, RightParen = 29, STRING = 30, AND = 31, + OR = 32, INTEGER = 33, NUMBER = 34, EXCLAMATION = 35, EXP = 36, Identifier = 37, LETTER = 38, + Char = 39, DIGIT = 40, WS = 41, NL = 42; + public static final int RULE_entry = 0, RULE_expression = 1, RULE_exprComposite = 2, RULE_ternaryExpr = 3, + RULE_caseExpr = 4, RULE_casePart = 5, RULE_ifExpr = 6, RULE_ifPart = 7, + RULE_elseIfPart = 8, RULE_elsePart = 9, RULE_block = 10, RULE_exprBlock = 11, + RULE_returnExpr = 12, RULE_expr = 13, RULE_ifCondition = 14, RULE_variableAssign = 15, + RULE_item = 16, RULE_unit = 17, RULE_variable = 18, RULE_cellPosition = 19, + RULE_relativeCell = 20, RULE_currentCellValue = 21, RULE_currentCellData = 22, + RULE_cell = 23, RULE_dataset = 24, RULE_function = 25, RULE_functionParameter = 26, + RULE_set = 27, RULE_cellCoordinate = 28, RULE_coordinate = 29, RULE_cellIndicator = 30, + RULE_conditions = 31, RULE_condition = 32, RULE_property = 33, RULE_currentValue = 34, + RULE_simpleValue = 35, RULE_join = 36, RULE_aggregate = 37; + public static final String[] ruleNames = { + "entry", "expression", "exprComposite", "ternaryExpr", "caseExpr", "casePart", + "ifExpr", "ifPart", "elseIfPart", "elsePart", "block", "exprBlock", "returnExpr", + "expr", "ifCondition", "variableAssign", "item", "unit", "variable", "cellPosition", + "relativeCell", "currentCellValue", "currentCellData", "cell", "dataset", + "function", "functionParameter", "set", "cellCoordinate", "coordinate", + "cellIndicator", "conditions", "condition", "property", "currentValue", + "simpleValue", "join", "aggregate" + }; + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + public static final String _serializedATN = "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3,\u01bb\4\2\t\2\4" + + + "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t" + + "\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22" + + "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31" + + "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!" + + "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4'\t'\3\2\6\2P\n\2\r\2\16\2Q\3\2" + + "\3\2\3\3\3\3\3\3\3\3\3\3\5\3[\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\5\4d\n\4" + + "\3\4\3\4\3\4\7\4i\n\4\f\4\16\4l\13\4\3\5\3\5\3\5\3\5\7\5r\n\5\f\5\16\5" + + "u\13\5\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\7\6\u0081\n\6\f\6\16\6" + + "\u0084\13\6\3\6\3\6\3\7\3\7\3\7\3\7\7\7\u008c\n\7\f\7\16\7\u008f\13\7" + + "\3\7\5\7\u0092\n\7\3\7\3\7\3\b\3\b\7\b\u0098\n\b\f\b\16\b\u009b\13\b\3" + + "\b\5\b\u009e\n\b\3\t\3\t\3\t\3\t\3\t\3\t\7\t\u00a6\n\t\f\t\16\t\u00a9" + + "\13\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\7\n\u00b7\n\n\f" + + "\n\16\n\u00ba\13\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\13\3\13\3\f\7" + + "\f\u00c7\n\f\f\f\16\f\u00ca\13\f\3\f\5\f\u00cd\n\f\3\r\3\r\3\r\5\r\u00d2" + + "\n\r\3\16\5\16\u00d5\n\16\3\16\3\16\5\16\u00d9\n\16\3\17\3\17\3\17\7\17" + + "\u00de\n\17\f\17\16\17\u00e1\13\17\3\20\3\20\3\20\3\20\3\21\5\21\u00e8" + + "\n\21\3\21\3\21\3\21\3\21\5\21\u00ee\n\21\3\22\3\22\3\22\7\22\u00f3\n" + + "\22\f\22\16\22\u00f6\13\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\6\22" + + "\u0100\n\22\r\22\16\22\u0101\3\22\3\22\5\22\u0106\n\22\3\23\3\23\3\23" + + "\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\5\23\u0116\n\23" + + "\3\24\3\24\3\25\3\25\3\25\3\26\3\26\3\26\3\27\3\27\3\30\3\30\3\30\3\30" + + "\3\31\3\31\3\31\5\31\u0129\n\31\3\32\3\32\3\32\3\32\3\32\5\32\u0130\n" + + "\32\3\32\3\32\5\32\u0134\n\32\3\32\3\32\5\32\u0138\n\32\3\32\3\32\3\33" + + "\3\33\3\33\5\33\u013f\n\33\3\33\3\33\3\34\3\34\5\34\u0145\n\34\3\34\7" + + "\34\u0148\n\34\f\34\16\34\u014b\13\34\3\35\3\35\3\35\3\35\3\35\3\35\3" + + "\35\3\35\3\35\3\35\5\35\u0157\n\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35" + + "\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35" + + "\5\35\u016e\n\35\3\35\3\35\3\35\7\35\u0173\n\35\f\35\16\35\u0176\13\35" + + "\3\36\3\36\3\36\5\36\u017b\n\36\3\37\3\37\3\37\7\37\u0180\n\37\f\37\16" + + "\37\u0183\13\37\3 \3 \3 \3 \5 \u0189\n \3 \5 \u018c\n \3!\3!\3!\3!\7!" + + "\u0192\n!\f!\16!\u0195\13!\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"" + + "\3\"\3\"\3\"\3\"\5\"\u01a6\n\"\3#\3#\3#\3#\3#\3#\7#\u01ae\n#\f#\16#\u01b1" + + "\13#\3$\3$\3%\3%\3&\3&\3'\3'\3'\2\5\68D(\2\4\6\b\n\f\16\20\22\24\26" + + "\30\32\34\36 \"$&(*,.\60\62\64\668:<>@BDFHJL\2\4\6\2\32\32\35\35 #$\3" + + "\2!\"\u01d6\2O\3\2\2\2\4Z\3\2\2\2\6c\3\2\2\2\bm\3\2\2\2\n{\3\2\2\2\f\u0087" + + "\3\2\2\2\16\u0095\3\2\2\2\20\u009f\3\2\2\2\22\u00af\3\2\2\2\24\u00c0\3" + + "\2\2\2\26\u00c8\3\2\2\2\30\u00d1\3\2\2\2\32\u00d4\3\2\2\2\34\u00da\3\2" + + "\2\2\36\u00e2\3\2\2\2 \u00e7\3\2\2\2\"\u0105\3\2\2\2$\u0115\3\2\2\2&\u0117" + + "\3\2\2\2(\u0119\3\2\2\2*\u011c\3\2\2\2,\u011f\3\2\2\2.\u0121\3\2\2\2\60" + + "\u0125\3\2\2\2\62\u012a\3\2\2\2\64\u013b\3\2\2\2\66\u0142\3\2\2\28\u016d" + + "\3\2\2\2:\u0177\3\2\2\2<\u017c\3\2\2\2>\u018b\3\2\2\2@\u018d\3\2\2\2B" + + "\u01a5\3\2\2\2D\u01a7\3\2\2\2F\u01b2\3\2\2\2H\u01b4\3\2\2\2J\u01b6\3\2" + + "\2\2L\u01b8\3\2\2\2NP\5\4\3\2ON\3\2\2\2PQ\3\2\2\2QO\3\2\2\2QR\3\2\2\2" + + "RS\3\2\2\2ST\7\2\2\3T\3\3\2\2\2U[\5\6\4\2V[\5\16\b\2W[\5\n\6\2X[\5\32" + + "\16\2Y[\5 \21\2ZU\3\2\2\2ZV\3\2\2\2ZW\3\2\2\2ZX\3\2\2\2ZY\3\2\2\2[\5\3" + + "\2\2\2\\]\b\4\1\2]d\5\34\17\2^d\5\b\5\2_`\7\36\2\2`a\5\6\4\2ab\7\37\2" + + "\2bd\3\2\2\2c\\\3\2\2\2c^\3\2\2\2c_\3\2\2\2dj\3\2\2\2ef\f\3\2\2fg\7\27" + + "\2\2gi\5\6\4\4he\3\2\2\2il\3\2\2\2jh\3\2\2\2jk\3\2\2\2k\7\3\2\2\2lj\3" + + "\2\2\2ms\5\36\20\2no\5J&\2op\5\36\20\2pr\3\2\2\2qn\3\2\2\2ru\3\2\2\2s" + + "q\3\2\2\2st\3\2\2\2tv\3\2\2\2us\3\2\2\2vw\7\3\2\2wx\5\26\f\2xy\7\33\2" + + "\2yz\5\26\f\2z\t\3\2\2\2{|\7\4\2\2|}\7\5\2\2}\u0082\5\f\7\2~\177\7\34" + + "\2\2\177\u0081\5\f\7\2\u0080~\3\2\2\2\u0081\u0084\3\2\2\2\u0082\u0080" + + "\3\2\2\2\u0082\u0083\3\2\2\2\u0083\u0085\3\2\2\2\u0084\u0082\3\2\2\2\u0085" + + "\u0086\7\6\2\2\u0086\13\3\2\2\2\u0087\u008d\5\36\20\2\u0088\u0089\5J&" + + "\2\u0089\u008a\5\36\20\2\u008a\u008c\3\2\2\2\u008b\u0088\3\2\2\2\u008c" + + "\u008f\3\2\2\2\u008d\u008b\3\2\2\2\u008d\u008e\3\2\2\2\u008e\u0091\3\2" + + "\2\2\u008f\u008d\3\2\2\2\u0090\u0092\7\33\2\2\u0091\u0090\3\2\2\2\u0091" + + "\u0092\3\2\2\2\u0092\u0093\3\2\2\2\u0093\u0094\5\26\f\2\u0094\r\3\2\2" + + "\2\u0095\u0099\5\20\t\2\u0096\u0098\5\22\n\2\u0097\u0096\3\2\2\2\u0098" + + "\u009b\3\2\2\2\u0099\u0097\3\2\2\2\u0099\u009a\3\2\2\2\u009a\u009d\3\2" + + "\2\2\u009b\u0099\3\2\2\2\u009c\u009e\5\24\13\2\u009d\u009c\3\2\2\2\u009d" + + "\u009e\3\2\2\2\u009e\17\3\2\2\2\u009f\u00a0\7\7\2\2\u00a0\u00a1\7\36\2" + + "\2\u00a1\u00a7\5\36\20\2\u00a2\u00a3\5J&\2\u00a3\u00a4\5\36\20\2\u00a4" + + "\u00a6\3\2\2\2\u00a5\u00a2\3\2\2\2\u00a6\u00a9\3\2\2\2\u00a7\u00a5\3\2" + + "\2\2\u00a7\u00a8\3\2\2\2\u00a8\u00aa\3\2\2\2\u00a9\u00a7\3\2\2\2\u00aa" + + "\u00ab\7\37\2\2\u00ab\u00ac\7\5\2\2\u00ac\u00ad\5\26\f\2\u00ad\u00ae\7" + + "\6\2\2\u00ae\21\3\2\2\2\u00af\u00b0\7\b\2\2\u00b0\u00b1\7\7\2\2\u00b1" + + "\u00b2\7\36\2\2\u00b2\u00b8\5\36\20\2\u00b3\u00b4\5J&\2\u00b4\u00b5\5" + + "\36\20\2\u00b5\u00b7\3\2\2\2\u00b6\u00b3\3\2\2\2\u00b7\u00ba\3\2\2\2\u00b8" + + "\u00b6\3\2\2\2\u00b8\u00b9\3\2\2\2\u00b9\u00bb\3\2\2\2\u00ba\u00b8\3\2" + + "\2\2\u00bb\u00bc\7\37\2\2\u00bc\u00bd\7\5\2\2\u00bd\u00be\5\26\f\2\u00be" + + "\u00bf\7\6\2\2\u00bf\23\3\2\2\2\u00c0\u00c1\7\b\2\2\u00c1\u00c2\7\5\2" + + "\2\u00c2\u00c3\5\26\f\2\u00c3\u00c4\7\6\2\2\u00c4\25\3\2\2\2\u00c5\u00c7" + + "\5\30\r\2\u00c6\u00c5\3\2\2\2\u00c7\u00ca\3\2\2\2\u00c8\u00c6\3\2\2\2" + + "\u00c8\u00c9\3\2\2\2\u00c9\u00cc\3\2\2\2\u00ca\u00c8\3\2\2\2\u00cb\u00cd" + + "\5\32\16\2\u00cc\u00cb\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd\27\3\2\2\2\u00ce" + + "\u00d2\5 \21\2\u00cf\u00d2\5\16\b\2\u00d0\u00d2\5\n\6\2\u00d1\u00ce\3" + + "\2\2\2\u00d1\u00cf\3\2\2\2\u00d1\u00d0\3\2\2\2\u00d2\31\3\2\2\2\u00d3" + + "\u00d5\7\t\2\2\u00d4\u00d3\3\2\2\2\u00d4\u00d5\3\2\2\2\u00d5\u00d6\3\2" + + "\2\2\u00d6\u00d8\5\34\17\2\u00d7\u00d9\7\n\2\2\u00d8\u00d7\3\2\2\2\u00d8" + + "\u00d9\3\2\2\2\u00d9\33\3\2\2\2\u00da\u00df\5\"\22\2\u00db\u00dc\7\27" + + "\2\2\u00dc\u00de\5\"\22\2\u00dd\u00db\3\2\2\2\u00de\u00e1\3\2\2\2\u00df" + + "\u00dd\3\2\2\2\u00df\u00e0\3\2\2\2\u00e0\35\3\2\2\2\u00e1\u00df\3\2\2" + + "\2\u00e2\u00e3\5\34\17\2\u00e3\u00e4\7\30\2\2\u00e4\u00e5\5\34\17\2\u00e5" + + "\37\3\2\2\2\u00e6\u00e8\7\13\2\2\u00e7\u00e6\3\2\2\2\u00e7\u00e8\3\2\2" + + "\2\u00e8\u00e9\3\2\2\2\u00e9\u00ea\5&\24\2\u00ea\u00eb\7\f\2\2\u00eb\u00ed" + + "\5\"\22\2\u00ec\u00ee\7\n\2\2\u00ed\u00ec\3\2\2\2\u00ed\u00ee\3\2\2\2" + + "\u00ee!\3\2\2\2\u00ef\u00f4\5$\23\2\u00f0\u00f1\7\27\2\2\u00f1\u00f3\5" + + "$\23\2\u00f2\u00f0\3\2\2\2\u00f3\u00f6\3\2\2\2\u00f4\u00f2\3\2\2\2\u00f4" + + "\u00f5\3\2\2\2\u00f5\u0106\3\2\2\2\u00f6\u00f4\3\2\2\2\u00f7\u00f8\7\36" + + "\2\2\u00f8\u00f9\5\"\22\2\u00f9\u00fa\7\37\2\2\u00fa\u0106\3\2\2\2\u00fb" + + "\u00fc\7\36\2\2\u00fc\u00ff\5\"\22\2\u00fd\u00fe\7\27\2\2\u00fe\u0100" + + "\5\"\22\2\u00ff\u00fd\3\2\2\2\u0100\u0101\3\2\2\2\u0101\u00ff\3\2\2\2" + + "\u0101\u0102\3\2\2\2\u0102\u0103\3\2\2\2\u0103\u0104\7\37\2\2\u0104\u0106" + + "\3\2\2\2\u0105\u00ef\3\2\2\2\u0105\u00f7\3\2\2\2\u0105\u00fb\3\2\2\2\u0106" + + "#\3\2\2\2\u0107\u0116\5\62\32\2\u0108\u0116\5\64\33\2\u0109\u0116\58\35" + + "\2\u010a\u0116\5(\25\2\u010b\u0116\5*\26\2\u010c\u0116\5,\27\2\u010d\u0116" + + "\5.\30\2\u010e\u0116\5\60\31\2\u010f\u0116\5&\24\2\u0110\u0116\7#\2\2" + + "\u0111\u0116\7\32\2\2\u0112\u0116\7 \2\2\u0113\u0116\7$\2\2\u0114\u0116" + + "\7\35\2\2\u0115\u0107\3\2\2\2\u0115\u0108\3\2\2\2\u0115\u0109\3\2\2\2" + + "\u0115\u010a\3\2\2\2\u0115\u010b\3\2\2\2\u0115\u010c\3\2\2\2\u0115\u010d" + + "\3\2\2\2\u0115\u010e\3\2\2\2\u0115\u010f\3\2\2\2\u0115\u0110\3\2\2\2\u0115" + + "\u0111\3\2\2\2\u0115\u0112\3\2\2\2\u0115\u0113\3\2\2\2\u0115\u0114\3\2" + + "\2\2\u0116%\3\2\2\2\u0117\u0118\7'\2\2\u0118'\3\2\2\2\u0119\u011a\7" + + "\r\2\2\u011a\u011b\7\26\2\2\u011b)\3\2\2\2\u011c\u011d\7\16\2\2\u011d" + + "\u011e\7\26\2\2\u011e+\3\2\2\2\u011f\u0120\7\17\2\2\u0120-\3\2\2\2\u0121" + + "\u0122\7\17\2\2\u0122\u0123\7\20\2\2\u0123\u0124\5D#\2\u0124/\3\2\2\2" + + "\u0125\u0128\7\21\2\2\u0126\u0127\7\20\2\2\u0127\u0129\5D#\2\u0128\u0126" + + "\3\2\2\2\u0128\u0129\3\2\2\2\u0129\61\3\2\2\2\u012a\u012b\7'\2\2\u012b" + + "\u012c\7\20\2\2\u012c\u012d\5L'\2\u012d\u012f\7\36\2\2\u012e\u0130\5" + + "D#\2\u012f\u012e\3\2\2\2\u012f\u0130\3\2\2\2\u0130\u0133\3\2\2\2\u0131" + + "\u0132\7\34\2\2\u0132\u0134\5@!\2\u0133\u0131\3\2\2\2\u0133\u0134\3\2" + + "\2\2\u0134\u0137\3\2\2\2\u0135\u0136\7\34\2\2\u0136\u0138\7\31\2\2\u0137" + + "\u0135\3\2\2\2\u0137\u0138\3\2\2\2\u0138\u0139\3\2\2\2\u0139\u013a\7\37" + + "\2\2\u013a\63\3\2\2\2\u013b\u013c\7'\2\2\u013c\u013e\7\36\2\2\u013d\u013f" + + "\5\66\34\2\u013e\u013d\3\2\2\2\u013e\u013f\3\2\2\2\u013f\u0140\3\2\2\2" + + "\u0140\u0141\7\37\2\2\u0141\65\3\2\2\2\u0142\u0149\5\"\22\2\u0143\u0145" + + "\7\34\2\2\u0144\u0143\3\2\2\2\u0144\u0145\3\2\2\2\u0145\u0146\3\2\2\2" + + "\u0146\u0148\5\"\22\2\u0147\u0144\3\2\2\2\u0148\u014b\3\2\2\2\u0149\u0147" + + "\3\2\2\2\u0149\u014a\3\2\2\2\u014a\67\3\2\2\2\u014b\u0149\3\2\2\2\u014c" + + "\u014d\b\35\1\2\u014d\u016e\5H%\2\u014e\u016e\7\26\2\2\u014f\u0150\7\26" + + "\2\2\u0150\u0151\7\22\2\2\u0151\u0156\7\23\2\2\u0152\u0153\7\5\2\2\u0153" + + "\u0154\5@!\2\u0154\u0155\7\6\2\2\u0155\u0157\3\2\2\2\u0156\u0152\3\2\2" + + "\2\u0156\u0157\3\2\2\2\u0157\u016e\3\2\2\2\u0158\u0159\7\26\2\2\u0159" + + "\u015a\7\33\2\2\u015a\u016e\7\26\2\2\u015b\u015c\7\26\2\2\u015c\u015d" + + "\7\5\2\2\u015d\u015e\5@!\2\u015e\u015f\7\6\2\2\u015f\u016e\3\2\2\2\u0160" + + "\u0161\7\26\2\2\u0161\u0162\7\22\2\2\u0162\u0163\5:\36\2\u0163\u0164\7" + + "\23\2\2\u0164\u016e\3\2\2\2\u0165\u0166\7\26\2\2\u0166\u0167\7\22\2\2" + + "\u0167\u0168\5:\36\2\u0168\u0169\7\23\2\2\u0169\u016a\7\5\2\2\u016a\u016b" + + "\5@!\2\u016b\u016c\7\6\2\2\u016c\u016e\3\2\2\2\u016d\u014c\3\2\2\2\u016d" + + "\u014e\3\2\2\2\u016d\u014f\3\2\2\2\u016d\u0158\3\2\2\2\u016d\u015b\3\2" + + "\2\2\u016d\u0160\3\2\2\2\u016d\u0165\3\2\2\2\u016e\u0174\3\2\2\2\u016f" + + "\u0170\f\3\2\2\u0170\u0171\7\24\2\2\u0171\u0173\58\35\4\u0172\u016f\3" + + "\2\2\2\u0173\u0176\3\2\2\2\u0174\u0172\3\2\2\2\u0174\u0175\3\2\2\2\u0175" + + "9\3\2\2\2\u0176\u0174\3\2\2\2\u0177\u017a\5<\37\2\u0178\u0179\7\n\2\2" + + "\u0179\u017b\5<\37\2\u017a\u0178\3\2\2\2\u017a\u017b\3\2\2\2\u017b;\3" + + "\2\2\2\u017c\u0181\5> \2\u017d\u017e\7\34\2\2\u017e\u0180\5> \2\u017f" + + "\u017d\3\2\2\2\u0180\u0183\3\2\2\2\u0181\u017f\3\2\2\2\u0181\u0182\3\2" + + "\2\2\u0182=\3\2\2\2\u0183\u0181\3\2\2\2\u0184\u018c\7\26\2\2\u0185\u0186" + + "\7\26\2\2\u0186\u0188\7\33\2\2\u0187\u0189\7%\2\2\u0188\u0187\3\2\2\2" + + "\u0188\u0189\3\2\2\2\u0189\u018a\3\2\2\2\u018a\u018c\7#\2\2\u018b\u0184" + + "\3\2\2\2\u018b\u0185\3\2\2\2\u018c?\3\2\2\2\u018d\u0193\5B\"\2\u018e\u018f" + + "\5J&\2\u018f\u0190\5B\"\2\u0190\u0192\3\2\2\2\u0191\u018e\3\2\2\2\u0192" + + "\u0195\3\2\2\2\u0193\u0191\3\2\2\2\u0193\u0194\3\2\2\2\u0194A\3\2\2\2" + + "\u0195\u0193\3\2\2\2\u0196\u0197\7\26\2\2\u0197\u0198\7\30\2\2\u0198\u01a6" + + "\5\34\17\2\u0199\u019a\5D#\2\u019a\u019b\7\30\2\2\u019b\u019c\5\34\17" + + "\2\u019c\u01a6\3\2\2\2\u019d\u019e\5F$\2\u019e\u019f\7\30\2\2\u019f\u01a0" + + "\5\34\17\2\u01a0\u01a6\3\2\2\2\u01a1\u01a2\5\34\17\2\u01a2\u01a3\7\30" + + "\2\2\u01a3\u01a4\5\34\17\2\u01a4\u01a6\3\2\2\2\u01a5\u0196\3\2\2\2\u01a5" + + "\u0199\3\2\2\2\u01a5\u019d\3\2\2\2\u01a5\u01a1\3\2\2\2\u01a6C\3\2\2\2" + + "\u01a7\u01a8\b#\1\2\u01a8\u01a9\7'\2\2\u01a9\u01af\3\2\2\2\u01aa\u01ab" + + "\f\3\2\2\u01ab\u01ac\7\20\2\2\u01ac\u01ae\5D#\4\u01ad\u01aa\3\2\2\2\u01ae" + + "\u01b1\3\2\2\2\u01af\u01ad\3\2\2\2\u01af\u01b0\3\2\2\2\u01b0E\3\2\2\2" + + "\u01b1\u01af\3\2\2\2\u01b2\u01b3\7\25\2\2\u01b3G\3\2\2\2\u01b4\u01b5\t" + + "\2\2\2\u01b5I\3\2\2\2\u01b6\u01b7\t\3\2\2\u01b7K\3\2\2\2\u01b8\u01b9\7" + + "'\2\2\u01b9M\3\2\2\2+QZcjs\u0082\u008d\u0091\u0099\u009d\u00a7\u00b8" + + "\u00c8\u00cc\u00d1\u00d4\u00d8\u00df\u00e7\u00ed\u00f4\u0101\u0105\u0115" + + "\u0128\u012f\u0133\u0137\u013e\u0144\u0149\u0156\u016d\u0174\u017a\u0181" + + "\u0188\u018b\u0193\u01a5\u01af"; + public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); + private static final String[] _LITERAL_NAMES = { + null, "'?'", "'case'", "'{'", "'}'", "'if'", "'else'", "'return'", "';'", + "'var'", "'='", "'&'", "'$'", "'#'", "'.'", "'cell'", "'['", "']'", "'to'", + "'@'", null, null, null, null, null, "':'", "','", "'null'", "'('", "')'", + null, null, null, null, null, "'!'" + }; + private static final String[] _SYMBOLIC_NAMES = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, "Cell", "Operator", "OP", + "ORDER", "BOOLEAN", "COLON", "COMMA", "NULL", "LeftParen", "RightParen", + "STRING", "AND", "OR", "INTEGER", "NUMBER", "EXCLAMATION", "EXP", "Identifier", + "LETTER", "Char", "DIGIT", "WS", "NL" + }; + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + static { + RuntimeMetaData.checkVersion("4.5.3", RuntimeMetaData.VERSION); + } + + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } + + public ReportParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache); + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { + return "ReportParser.g4"; + } + + @Override + public String[] getRuleNames() { + return ruleNames; + } + + @Override + public String getSerializedATN() { + return _serializedATN; + } + + @Override + public ATN getATN() { + return _ATN; + } + + public final EntryContext entry() throws RecognitionException { + EntryContext _localctx = new EntryContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_entry); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(77); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(76); + expression(); + } + } + setState(79); + _errHandler.sync(this); + _la = _input.LA(1); + } while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__1) | (1L << T__4) | (1L << T__6) + | (1L << T__8) | (1L << T__10) | (1L << T__11) | (1L << T__12) | (1L << T__14) | (1L << Cell) + | (1L << BOOLEAN) | (1L << NULL) | (1L << LeftParen) | (1L << STRING) | (1L << INTEGER) + | (1L << NUMBER) | (1L << Identifier))) != 0)); + setState(81); + match(EOF); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ExpressionContext expression() throws RecognitionException { + ExpressionContext _localctx = new ExpressionContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_expression); + try { + setState(88); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 1, _ctx)) { + case 1: + enterOuterAlt(_localctx, 1); { + setState(83); + exprComposite(0); + } + break; + case 2: + enterOuterAlt(_localctx, 2); { + setState(84); + ifExpr(); + } + break; + case 3: + enterOuterAlt(_localctx, 3); { + setState(85); + caseExpr(); + } + break; + case 4: + enterOuterAlt(_localctx, 4); { + setState(86); + returnExpr(); + } + break; + case 5: + enterOuterAlt(_localctx, 5); { + setState(87); + variableAssign(); + } + break; + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ExprCompositeContext exprComposite() throws RecognitionException { + return exprComposite(0); + } + + private ExprCompositeContext exprComposite(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + ExprCompositeContext _localctx = new ExprCompositeContext(_ctx, _parentState); + ExprCompositeContext _prevctx = _localctx; + int _startState = 4; + enterRecursionRule(_localctx, 4, RULE_exprComposite, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(97); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 2, _ctx)) { + case 1: { + _localctx = new SingleExprCompositeContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + + setState(91); + expr(); + } + break; + case 2: { + _localctx = new TernaryExprCompositeContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(92); + ternaryExpr(); + } + break; + case 3: { + _localctx = new ParenExprCompositeContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(93); + match(LeftParen); + setState(94); + exprComposite(0); + setState(95); + match(RightParen); + } + break; + } + _ctx.stop = _input.LT(-1); + setState(104); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 3, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + if (_parseListeners != null) + triggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new ComplexExprCompositeContext( + new ExprCompositeContext(_parentctx, _parentState)); + pushNewRecursionContext(_localctx, _startState, RULE_exprComposite); + setState(99); + if (!(precpred(_ctx, 1))) + throw new FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(100); + match(Operator); + setState(101); + exprComposite(2); + } + } + } + setState(106); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 3, _ctx); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + public final TernaryExprContext ternaryExpr() throws RecognitionException { + TernaryExprContext _localctx = new TernaryExprContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_ternaryExpr); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(107); + ifCondition(); + setState(113); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == AND || _la == OR) { + { + { + setState(108); + join(); + setState(109); + ifCondition(); + } + } + setState(115); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(116); + match(T__0); + setState(117); + block(); + setState(118); + match(COLON); + setState(119); + block(); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CaseExprContext caseExpr() throws RecognitionException { + CaseExprContext _localctx = new CaseExprContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_caseExpr); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(121); + match(T__1); + setState(122); + match(T__2); + setState(123); + casePart(); + setState(128); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == COMMA) { + { + { + setState(124); + match(COMMA); + setState(125); + casePart(); + } + } + setState(130); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(131); + match(T__3); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CasePartContext casePart() throws RecognitionException { + CasePartContext _localctx = new CasePartContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_casePart); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(133); + ifCondition(); + setState(139); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == AND || _la == OR) { + { + { + setState(134); + join(); + setState(135); + ifCondition(); + } + } + setState(141); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(143); + _la = _input.LA(1); + if (_la == COLON) { + { + setState(142); + match(COLON); + } + } + + setState(145); + block(); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final IfExprContext ifExpr() throws RecognitionException { + IfExprContext _localctx = new IfExprContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_ifExpr); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(147); + ifPart(); + setState(151); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 8, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + { + { + setState(148); + elseIfPart(); + } + } + } + setState(153); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 8, _ctx); + } + setState(155); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 9, _ctx)) { + case 1: { + setState(154); + elsePart(); + } + break; + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final IfPartContext ifPart() throws RecognitionException { + IfPartContext _localctx = new IfPartContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_ifPart); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(157); + match(T__4); + setState(158); + match(LeftParen); + setState(159); + ifCondition(); + setState(165); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == AND || _la == OR) { + { + { + setState(160); + join(); + setState(161); + ifCondition(); + } + } + setState(167); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(168); + match(RightParen); + setState(169); + match(T__2); + setState(170); + block(); + setState(171); + match(T__3); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ElseIfPartContext elseIfPart() throws RecognitionException { + ElseIfPartContext _localctx = new ElseIfPartContext(_ctx, getState()); + enterRule(_localctx, 16, RULE_elseIfPart); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(173); + match(T__5); + setState(174); + match(T__4); + setState(175); + match(LeftParen); + setState(176); + ifCondition(); + setState(182); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == AND || _la == OR) { + { + { + setState(177); + join(); + setState(178); + ifCondition(); + } + } + setState(184); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(185); + match(RightParen); + setState(186); + match(T__2); + setState(187); + block(); + setState(188); + match(T__3); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ElsePartContext elsePart() throws RecognitionException { + ElsePartContext _localctx = new ElsePartContext(_ctx, getState()); + enterRule(_localctx, 18, RULE_elsePart); + try { + enterOuterAlt(_localctx, 1); + { + setState(190); + match(T__5); + setState(191); + match(T__2); + setState(192); + block(); + setState(193); + match(T__3); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final BlockContext block() throws RecognitionException { + BlockContext _localctx = new BlockContext(_ctx, getState()); + enterRule(_localctx, 20, RULE_block); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(198); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 12, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + { + { + setState(195); + exprBlock(); + } + } + } + setState(200); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 12, _ctx); + } + setState(202); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 13, _ctx)) { + case 1: { + setState(201); + returnExpr(); + } + break; + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ExprBlockContext exprBlock() throws RecognitionException { + ExprBlockContext _localctx = new ExprBlockContext(_ctx, getState()); + enterRule(_localctx, 22, RULE_exprBlock); + try { + setState(207); + switch (_input.LA(1)) { + case T__8: + case Identifier: + enterOuterAlt(_localctx, 1); { + setState(204); + variableAssign(); + } + break; + case T__4: + enterOuterAlt(_localctx, 2); { + setState(205); + ifExpr(); + } + break; + case T__1: + enterOuterAlt(_localctx, 3); { + setState(206); + caseExpr(); + } + break; + default: + throw new NoViableAltException(this); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ReturnExprContext returnExpr() throws RecognitionException { + ReturnExprContext _localctx = new ReturnExprContext(_ctx, getState()); + enterRule(_localctx, 24, RULE_returnExpr); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(210); + _la = _input.LA(1); + if (_la == T__6) { + { + setState(209); + match(T__6); + } + } + + setState(212); + expr(); + setState(214); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 16, _ctx)) { + case 1: { + setState(213); + match(T__7); + } + break; + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ExprContext expr() throws RecognitionException { + ExprContext _localctx = new ExprContext(_ctx, getState()); + enterRule(_localctx, 26, RULE_expr); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(216); + item(); + setState(221); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 17, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + { + { + setState(217); + match(Operator); + setState(218); + item(); + } + } + } + setState(223); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 17, _ctx); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final IfConditionContext ifCondition() throws RecognitionException { + IfConditionContext _localctx = new IfConditionContext(_ctx, getState()); + enterRule(_localctx, 28, RULE_ifCondition); + try { + enterOuterAlt(_localctx, 1); + { + setState(224); + expr(); + setState(225); + match(OP); + setState(226); + expr(); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final VariableAssignContext variableAssign() throws RecognitionException { + VariableAssignContext _localctx = new VariableAssignContext(_ctx, getState()); + enterRule(_localctx, 30, RULE_variableAssign); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(229); + _la = _input.LA(1); + if (_la == T__8) { + { + setState(228); + match(T__8); + } + } + + setState(231); + variable(); + setState(232); + match(T__9); + setState(233); + item(); + setState(235); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 19, _ctx)) { + case 1: { + setState(234); + match(T__7); + } + break; + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ItemContext item() throws RecognitionException { + ItemContext _localctx = new ItemContext(_ctx, getState()); + enterRule(_localctx, 32, RULE_item); + int _la; + try { + int _alt; + setState(259); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 22, _ctx)) { + case 1: + _localctx = new SimpleJoinContext(_localctx); + enterOuterAlt(_localctx, 1); { + setState(237); + unit(); + setState(242); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 20, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + { + { + setState(238); + match(Operator); + setState(239); + unit(); + } + } + } + setState(244); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 20, _ctx); + } + } + break; + case 2: + _localctx = new SingleParenJoinContext(_localctx); + enterOuterAlt(_localctx, 2); { + setState(245); + match(LeftParen); + setState(246); + item(); + setState(247); + match(RightParen); + } + break; + case 3: + _localctx = new ParenJoinContext(_localctx); + enterOuterAlt(_localctx, 3); { + setState(249); + match(LeftParen); + setState(250); + item(); + setState(253); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(251); + match(Operator); + setState(252); + item(); + } + } + setState(255); + _errHandler.sync(this); + _la = _input.LA(1); + } while (_la == Operator); + setState(257); + match(RightParen); + } + break; + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final UnitContext unit() throws RecognitionException { + UnitContext _localctx = new UnitContext(_ctx, getState()); + enterRule(_localctx, 34, RULE_unit); + try { + setState(275); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 23, _ctx)) { + case 1: + enterOuterAlt(_localctx, 1); { + setState(261); + dataset(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); { + setState(262); + function(); + } + break; + case 3: + enterOuterAlt(_localctx, 3); { + setState(263); + set(0); + } + break; + case 4: + enterOuterAlt(_localctx, 4); { + setState(264); + cellPosition(); + } + break; + case 5: + enterOuterAlt(_localctx, 5); { + setState(265); + relativeCell(); + } + break; + case 6: + enterOuterAlt(_localctx, 6); { + setState(266); + currentCellValue(); + } + break; + case 7: + enterOuterAlt(_localctx, 7); { + setState(267); + currentCellData(); + } + break; + case 8: + enterOuterAlt(_localctx, 8); { + setState(268); + cell(); + } + break; + case 9: + enterOuterAlt(_localctx, 9); { + setState(269); + variable(); + } + break; + case 10: + enterOuterAlt(_localctx, 10); { + setState(270); + match(INTEGER); + } + break; + case 11: + enterOuterAlt(_localctx, 11); { + setState(271); + match(BOOLEAN); + } + break; + case 12: + enterOuterAlt(_localctx, 12); { + setState(272); + match(STRING); + } + break; + case 13: + enterOuterAlt(_localctx, 13); { + setState(273); + match(NUMBER); + } + break; + case 14: + enterOuterAlt(_localctx, 14); { + setState(274); + match(NULL); + } + break; + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final VariableContext variable() throws RecognitionException { + VariableContext _localctx = new VariableContext(_ctx, getState()); + enterRule(_localctx, 36, RULE_variable); + try { + enterOuterAlt(_localctx, 1); + { + setState(277); + match(Identifier); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CellPositionContext cellPosition() throws RecognitionException { + CellPositionContext _localctx = new CellPositionContext(_ctx, getState()); + enterRule(_localctx, 38, RULE_cellPosition); + try { + enterOuterAlt(_localctx, 1); + { + setState(279); + match(T__10); + setState(280); + match(Cell); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final RelativeCellContext relativeCell() throws RecognitionException { + RelativeCellContext _localctx = new RelativeCellContext(_ctx, getState()); + enterRule(_localctx, 40, RULE_relativeCell); + try { + enterOuterAlt(_localctx, 1); + { + setState(282); + match(T__11); + setState(283); + match(Cell); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CurrentCellValueContext currentCellValue() throws RecognitionException { + CurrentCellValueContext _localctx = new CurrentCellValueContext(_ctx, getState()); + enterRule(_localctx, 42, RULE_currentCellValue); + try { + enterOuterAlt(_localctx, 1); + { + setState(285); + match(T__12); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CurrentCellDataContext currentCellData() throws RecognitionException { + CurrentCellDataContext _localctx = new CurrentCellDataContext(_ctx, getState()); + enterRule(_localctx, 44, RULE_currentCellData); + try { + enterOuterAlt(_localctx, 1); + { + setState(287); + match(T__12); + setState(288); + match(T__13); + setState(289); + property(0); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CellContext cell() throws RecognitionException { + CellContext _localctx = new CellContext(_ctx, getState()); + enterRule(_localctx, 46, RULE_cell); + try { + enterOuterAlt(_localctx, 1); + { + setState(291); + match(T__14); + setState(294); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 24, _ctx)) { + case 1: { + setState(292); + match(T__13); + setState(293); + property(0); + } + break; + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final DatasetContext dataset() throws RecognitionException { + DatasetContext _localctx = new DatasetContext(_ctx, getState()); + enterRule(_localctx, 48, RULE_dataset); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(296); + match(Identifier); + setState(297); + match(T__13); + setState(298); + aggregate(); + setState(299); + match(LeftParen); + setState(301); + _la = _input.LA(1); + if (_la == Identifier) { + { + setState(300); + property(0); + } + } + + setState(305); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 26, _ctx)) { + case 1: { + setState(303); + match(COMMA); + setState(304); + conditions(); + } + break; + } + setState(309); + _la = _input.LA(1); + if (_la == COMMA) { + { + setState(307); + match(COMMA); + setState(308); + match(ORDER); + } + } + + setState(311); + match(RightParen); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final FunctionContext function() throws RecognitionException { + FunctionContext _localctx = new FunctionContext(_ctx, getState()); + enterRule(_localctx, 50, RULE_function); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(313); + match(Identifier); + setState(314); + match(LeftParen); + setState(316); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << T__12) + | (1L << T__14) | (1L << Cell) | (1L << BOOLEAN) | (1L << NULL) | (1L << LeftParen) + | (1L << STRING) | (1L << INTEGER) | (1L << NUMBER) | (1L << Identifier))) != 0)) { + { + setState(315); + functionParameter(); + } + } + + setState(318); + match(RightParen); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final FunctionParameterContext functionParameter() throws RecognitionException { + FunctionParameterContext _localctx = new FunctionParameterContext(_ctx, getState()); + enterRule(_localctx, 52, RULE_functionParameter); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(320); + item(); + setState(327); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 + && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << T__12) | (1L << T__14) | (1L << Cell) + | (1L << BOOLEAN) | (1L << COMMA) | (1L << NULL) | (1L << LeftParen) | (1L << STRING) + | (1L << INTEGER) | (1L << NUMBER) | (1L << Identifier))) != 0)) { + { + { + setState(322); + _la = _input.LA(1); + if (_la == COMMA) { + { + setState(321); + match(COMMA); + } + } + + setState(324); + item(); + } + } + setState(329); + _errHandler.sync(this); + _la = _input.LA(1); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final SetContext set() throws RecognitionException { + return set(0); + } + + private SetContext set(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + SetContext _localctx = new SetContext(_ctx, _parentState); + SetContext _prevctx = _localctx; + int _startState = 54; + enterRecursionRule(_localctx, 54, RULE_set, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(363); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 32, _ctx)) { + case 1: { + _localctx = new SimpleDataContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + + setState(331); + simpleValue(); + } + break; + case 2: { + _localctx = new SingleCellContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(332); + match(Cell); + } + break; + case 3: { + _localctx = new WholeCellContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(333); + match(Cell); + setState(334); + match(T__15); + setState(335); + match(T__16); + setState(340); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 31, _ctx)) { + case 1: { + setState(336); + match(T__2); + setState(337); + conditions(); + setState(338); + match(T__3); + } + break; + } + } + break; + case 4: { + _localctx = new CellPairContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(342); + match(Cell); + setState(343); + match(COLON); + setState(344); + match(Cell); + } + break; + case 5: { + _localctx = new SingleCellConditionContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(345); + match(Cell); + setState(346); + match(T__2); + setState(347); + conditions(); + setState(348); + match(T__3); + } + break; + case 6: { + _localctx = new SingleCellCoordinateContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(350); + match(Cell); + setState(351); + match(T__15); + setState(352); + cellCoordinate(); + setState(353); + match(T__16); + } + break; + case 7: { + _localctx = new CellCoordinateConditionContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(355); + match(Cell); + setState(356); + match(T__15); + setState(357); + cellCoordinate(); + setState(358); + match(T__16); + setState(359); + match(T__2); + setState(360); + conditions(); + setState(361); + match(T__3); + } + break; + } + _ctx.stop = _input.LT(-1); + setState(370); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 33, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + if (_parseListeners != null) + triggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new RangeContext(new SetContext(_parentctx, _parentState)); + pushNewRecursionContext(_localctx, _startState, RULE_set); + setState(365); + if (!(precpred(_ctx, 1))) + throw new FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(366); + match(T__17); + setState(367); + set(2); + } + } + } + setState(372); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 33, _ctx); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + public final CellCoordinateContext cellCoordinate() throws RecognitionException { + CellCoordinateContext _localctx = new CellCoordinateContext(_ctx, getState()); + enterRule(_localctx, 56, RULE_cellCoordinate); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(373); + coordinate(); + setState(376); + _la = _input.LA(1); + if (_la == T__7) { + { + setState(374); + match(T__7); + setState(375); + coordinate(); + } + } + + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CoordinateContext coordinate() throws RecognitionException { + CoordinateContext _localctx = new CoordinateContext(_ctx, getState()); + enterRule(_localctx, 58, RULE_coordinate); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(378); + cellIndicator(); + setState(383); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == COMMA) { + { + { + setState(379); + match(COMMA); + setState(380); + cellIndicator(); + } + } + setState(385); + _errHandler.sync(this); + _la = _input.LA(1); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final CellIndicatorContext cellIndicator() throws RecognitionException { + CellIndicatorContext _localctx = new CellIndicatorContext(_ctx, getState()); + enterRule(_localctx, 60, RULE_cellIndicator); + int _la; + try { + setState(393); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 37, _ctx)) { + case 1: + _localctx = new RelativeContext(_localctx); + enterOuterAlt(_localctx, 1); { + setState(386); + match(Cell); + } + break; + case 2: + _localctx = new AbsoluteContext(_localctx); + enterOuterAlt(_localctx, 2); { + setState(387); + match(Cell); + setState(388); + match(COLON); + setState(390); + _la = _input.LA(1); + if (_la == EXCLAMATION) { + { + setState(389); + match(EXCLAMATION); + } + } + + setState(392); + match(INTEGER); + } + break; + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ConditionsContext conditions() throws RecognitionException { + ConditionsContext _localctx = new ConditionsContext(_ctx, getState()); + enterRule(_localctx, 62, RULE_conditions); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(395); + condition(); + setState(401); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la == AND || _la == OR) { + { + { + setState(396); + join(); + setState(397); + condition(); + } + } + setState(403); + _errHandler.sync(this); + _la = _input.LA(1); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final ConditionContext condition() throws RecognitionException { + ConditionContext _localctx = new ConditionContext(_ctx, getState()); + enterRule(_localctx, 64, RULE_condition); + try { + setState(419); + _errHandler.sync(this); + switch (getInterpreter().adaptivePredict(_input, 39, _ctx)) { + case 1: + _localctx = new CellNameExprConditionContext(_localctx); + enterOuterAlt(_localctx, 1); { + setState(404); + match(Cell); + setState(405); + match(OP); + setState(406); + expr(); + } + break; + case 2: + _localctx = new PropertyConditionContext(_localctx); + enterOuterAlt(_localctx, 2); { + setState(407); + property(0); + setState(408); + match(OP); + setState(409); + expr(); + } + break; + case 3: + _localctx = new CurrentValueConditionContext(_localctx); + enterOuterAlt(_localctx, 3); { + setState(411); + currentValue(); + setState(412); + match(OP); + setState(413); + expr(); + } + break; + case 4: + _localctx = new ExprConditionContext(_localctx); + enterOuterAlt(_localctx, 4); { + setState(415); + expr(); + setState(416); + match(OP); + setState(417); + expr(); + } + break; + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final PropertyContext property() throws RecognitionException { + return property(0); + } + + private PropertyContext property(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + PropertyContext _localctx = new PropertyContext(_ctx, _parentState); + PropertyContext _prevctx = _localctx; + int _startState = 66; + enterRecursionRule(_localctx, 66, RULE_property, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + { + setState(422); + match(Identifier); + } + _ctx.stop = _input.LT(-1); + setState(429); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 40, _ctx); + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if (_alt == 1) { + if (_parseListeners != null) + triggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new PropertyContext(_parentctx, _parentState); + pushNewRecursionContext(_localctx, _startState, RULE_property); + setState(424); + if (!(precpred(_ctx, 1))) + throw new FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(425); + match(T__13); + setState(426); + property(2); + } + } + } + setState(431); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input, 40, _ctx); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + public final CurrentValueContext currentValue() throws RecognitionException { + CurrentValueContext _localctx = new CurrentValueContext(_ctx, getState()); + enterRule(_localctx, 68, RULE_currentValue); + try { + enterOuterAlt(_localctx, 1); + { + setState(432); + match(T__18); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final SimpleValueContext simpleValue() throws RecognitionException { + SimpleValueContext _localctx = new SimpleValueContext(_ctx, getState()); + enterRule(_localctx, 70, RULE_simpleValue); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(434); + _la = _input.LA(1); + if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BOOLEAN) | (1L << NULL) | (1L << STRING) + | (1L << INTEGER) | (1L << NUMBER))) != 0))) { + _errHandler.recoverInline(this); + } else { + consume(); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final JoinContext join() throws RecognitionException { + JoinContext _localctx = new JoinContext(_ctx, getState()); + enterRule(_localctx, 72, RULE_join); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(436); + _la = _input.LA(1); + if (!(_la == AND || _la == OR)) { + _errHandler.recoverInline(this); + } else { + consume(); + } + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public final AggregateContext aggregate() throws RecognitionException { + AggregateContext _localctx = new AggregateContext(_ctx, getState()); + enterRule(_localctx, 74, RULE_aggregate); + try { + enterOuterAlt(_localctx, 1); + { + setState(438); + match(Identifier); + } + } catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } finally { + exitRule(); + } + return _localctx; + } + + public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { + switch (ruleIndex) { + case 2: + return exprComposite_sempred((ExprCompositeContext) _localctx, predIndex); + case 27: + return set_sempred((SetContext) _localctx, predIndex); + case 33: + return property_sempred((PropertyContext) _localctx, predIndex); + } + return true; + } + + private boolean exprComposite_sempred(ExprCompositeContext _localctx, int predIndex) { + switch (predIndex) { + case 0: + return precpred(_ctx, 1); + } + return true; + } + + private boolean set_sempred(SetContext _localctx, int predIndex) { + switch (predIndex) { + case 1: + return precpred(_ctx, 1); + } + return true; + } + + private boolean property_sempred(PropertyContext _localctx, int predIndex) { + switch (predIndex) { + case 2: + return precpred(_ctx, 1); + } + return true; + } + + public static class EntryContext extends ParserRuleContext { + public EntryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode EOF() { + return getToken(ReportParser.EOF, 0); + } + + public List expression() { + return getRuleContexts(ExpressionContext.class); + } + + public ExpressionContext expression(int i) { + return getRuleContext(ExpressionContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_entry; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitEntry(this); + else + return visitor.visitChildren(this); + } + } + + public static class ExpressionContext extends ParserRuleContext { + public ExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public ExprCompositeContext exprComposite() { + return getRuleContext(ExprCompositeContext.class, 0); + } + + public IfExprContext ifExpr() { + return getRuleContext(IfExprContext.class, 0); + } + + public CaseExprContext caseExpr() { + return getRuleContext(CaseExprContext.class, 0); + } + + public ReturnExprContext returnExpr() { + return getRuleContext(ReturnExprContext.class, 0); + } + + public VariableAssignContext variableAssign() { + return getRuleContext(VariableAssignContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_expression; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitExpression(this); + else + return visitor.visitChildren(this); + } + } + + public static class ExprCompositeContext extends ParserRuleContext { + public ExprCompositeContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public ExprCompositeContext() { + } + + @Override + public int getRuleIndex() { + return RULE_exprComposite; + } + + public void copyFrom(ExprCompositeContext ctx) { + super.copyFrom(ctx); + } + } + + public static class ComplexExprCompositeContext extends ExprCompositeContext { + public ComplexExprCompositeContext(ExprCompositeContext ctx) { + copyFrom(ctx); + } + + public List exprComposite() { + return getRuleContexts(ExprCompositeContext.class); + } + + public ExprCompositeContext exprComposite(int i) { + return getRuleContext(ExprCompositeContext.class, i); + } + + public TerminalNode Operator() { + return getToken(ReportParser.Operator, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitComplexExprComposite(this); + else + return visitor.visitChildren(this); + } + } + + public static class SingleExprCompositeContext extends ExprCompositeContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class, 0); + } + + public SingleExprCompositeContext(ExprCompositeContext ctx) { + copyFrom(ctx); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSingleExprComposite(this); + else + return visitor.visitChildren(this); + } + } + + public static class ParenExprCompositeContext extends ExprCompositeContext { + public ParenExprCompositeContext(ExprCompositeContext ctx) { + copyFrom(ctx); + } + + public TerminalNode LeftParen() { + return getToken(ReportParser.LeftParen, 0); + } + + public ExprCompositeContext exprComposite() { + return getRuleContext(ExprCompositeContext.class, 0); + } + + public TerminalNode RightParen() { + return getToken(ReportParser.RightParen, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitParenExprComposite(this); + else + return visitor.visitChildren(this); + } + } + + public static class TernaryExprCompositeContext extends ExprCompositeContext { + public TernaryExprCompositeContext(ExprCompositeContext ctx) { + copyFrom(ctx); + } + + public TernaryExprContext ternaryExpr() { + return getRuleContext(TernaryExprContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitTernaryExprComposite(this); + else + return visitor.visitChildren(this); + } + } + + public static class TernaryExprContext extends ParserRuleContext { + public TernaryExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List ifCondition() { + return getRuleContexts(IfConditionContext.class); + } + + public IfConditionContext ifCondition(int i) { + return getRuleContext(IfConditionContext.class, i); + } + + public List block() { + return getRuleContexts(BlockContext.class); + } + + public BlockContext block(int i) { + return getRuleContext(BlockContext.class, i); + } + + public List join() { + return getRuleContexts(JoinContext.class); + } + + public JoinContext join(int i) { + return getRuleContext(JoinContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_ternaryExpr; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitTernaryExpr(this); + else + return visitor.visitChildren(this); + } + } + + public static class CaseExprContext extends ParserRuleContext { + public CaseExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List casePart() { + return getRuleContexts(CasePartContext.class); + } + + public CasePartContext casePart(int i) { + return getRuleContext(CasePartContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_caseExpr; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCaseExpr(this); + else + return visitor.visitChildren(this); + } + } + + public static class CasePartContext extends ParserRuleContext { + public CasePartContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List ifCondition() { + return getRuleContexts(IfConditionContext.class); + } + + public IfConditionContext ifCondition(int i) { + return getRuleContext(IfConditionContext.class, i); + } + + public BlockContext block() { + return getRuleContext(BlockContext.class, 0); + } + + public List join() { + return getRuleContexts(JoinContext.class); + } + + public JoinContext join(int i) { + return getRuleContext(JoinContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_casePart; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCasePart(this); + else + return visitor.visitChildren(this); + } + } + + public static class IfExprContext extends ParserRuleContext { + public IfExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public IfPartContext ifPart() { + return getRuleContext(IfPartContext.class, 0); + } + + public List elseIfPart() { + return getRuleContexts(ElseIfPartContext.class); + } + + public ElseIfPartContext elseIfPart(int i) { + return getRuleContext(ElseIfPartContext.class, i); + } + + public ElsePartContext elsePart() { + return getRuleContext(ElsePartContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_ifExpr; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitIfExpr(this); + else + return visitor.visitChildren(this); + } + } + + public static class IfPartContext extends ParserRuleContext { + public IfPartContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List ifCondition() { + return getRuleContexts(IfConditionContext.class); + } + + public IfConditionContext ifCondition(int i) { + return getRuleContext(IfConditionContext.class, i); + } + + public BlockContext block() { + return getRuleContext(BlockContext.class, 0); + } + + public List join() { + return getRuleContexts(JoinContext.class); + } + + public JoinContext join(int i) { + return getRuleContext(JoinContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_ifPart; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitIfPart(this); + else + return visitor.visitChildren(this); + } + } + + public static class ElseIfPartContext extends ParserRuleContext { + public ElseIfPartContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List ifCondition() { + return getRuleContexts(IfConditionContext.class); + } + + public IfConditionContext ifCondition(int i) { + return getRuleContext(IfConditionContext.class, i); + } + + public BlockContext block() { + return getRuleContext(BlockContext.class, 0); + } + + public List join() { + return getRuleContexts(JoinContext.class); + } + + public JoinContext join(int i) { + return getRuleContext(JoinContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_elseIfPart; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitElseIfPart(this); + else + return visitor.visitChildren(this); + } + } + + public static class ElsePartContext extends ParserRuleContext { + public ElsePartContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public BlockContext block() { + return getRuleContext(BlockContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_elsePart; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitElsePart(this); + else + return visitor.visitChildren(this); + } + } + + public static class BlockContext extends ParserRuleContext { + public BlockContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List exprBlock() { + return getRuleContexts(ExprBlockContext.class); + } + + public ExprBlockContext exprBlock(int i) { + return getRuleContext(ExprBlockContext.class, i); + } + + public ReturnExprContext returnExpr() { + return getRuleContext(ReturnExprContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_block; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitBlock(this); + else + return visitor.visitChildren(this); + } + } + + public static class ExprBlockContext extends ParserRuleContext { + public ExprBlockContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public VariableAssignContext variableAssign() { + return getRuleContext(VariableAssignContext.class, 0); + } + + public IfExprContext ifExpr() { + return getRuleContext(IfExprContext.class, 0); + } + + public CaseExprContext caseExpr() { + return getRuleContext(CaseExprContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_exprBlock; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitExprBlock(this); + else + return visitor.visitChildren(this); + } + } + + public static class ReturnExprContext extends ParserRuleContext { + public ReturnExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public ExprContext expr() { + return getRuleContext(ExprContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_returnExpr; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitReturnExpr(this); + else + return visitor.visitChildren(this); + } + } + + public static class ExprContext extends ParserRuleContext { + public ExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List item() { + return getRuleContexts(ItemContext.class); + } + + public ItemContext item(int i) { + return getRuleContext(ItemContext.class, i); + } + + public List Operator() { + return getTokens(ReportParser.Operator); + } + + public TerminalNode Operator(int i) { + return getToken(ReportParser.Operator, i); + } + + @Override + public int getRuleIndex() { + return RULE_expr; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitExpr(this); + else + return visitor.visitChildren(this); + } + } + + public static class IfConditionContext extends ParserRuleContext { + public IfConditionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List expr() { + return getRuleContexts(ExprContext.class); + } + + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class, i); + } + + public TerminalNode OP() { + return getToken(ReportParser.OP, 0); + } + + @Override + public int getRuleIndex() { + return RULE_ifCondition; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitIfCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class VariableAssignContext extends ParserRuleContext { + public VariableAssignContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public VariableContext variable() { + return getRuleContext(VariableContext.class, 0); + } + + public ItemContext item() { + return getRuleContext(ItemContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_variableAssign; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitVariableAssign(this); + else + return visitor.visitChildren(this); + } + } + + public static class ItemContext extends ParserRuleContext { + public ItemContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public ItemContext() { + } + + @Override + public int getRuleIndex() { + return RULE_item; + } + + public void copyFrom(ItemContext ctx) { + super.copyFrom(ctx); + } + } + + public static class SingleParenJoinContext extends ItemContext { + public SingleParenJoinContext(ItemContext ctx) { + copyFrom(ctx); + } + + public TerminalNode LeftParen() { + return getToken(ReportParser.LeftParen, 0); + } + + public ItemContext item() { + return getRuleContext(ItemContext.class, 0); + } + + public TerminalNode RightParen() { + return getToken(ReportParser.RightParen, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSingleParenJoin(this); + else + return visitor.visitChildren(this); + } + } + + public static class ParenJoinContext extends ItemContext { + public ParenJoinContext(ItemContext ctx) { + copyFrom(ctx); + } + + public TerminalNode LeftParen() { + return getToken(ReportParser.LeftParen, 0); + } + + public List item() { + return getRuleContexts(ItemContext.class); + } + + public ItemContext item(int i) { + return getRuleContext(ItemContext.class, i); + } + + public TerminalNode RightParen() { + return getToken(ReportParser.RightParen, 0); + } + + public List Operator() { + return getTokens(ReportParser.Operator); + } + + public TerminalNode Operator(int i) { + return getToken(ReportParser.Operator, i); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitParenJoin(this); + else + return visitor.visitChildren(this); + } + } + + public static class SimpleJoinContext extends ItemContext { + public SimpleJoinContext(ItemContext ctx) { + copyFrom(ctx); + } + + public List unit() { + return getRuleContexts(UnitContext.class); + } + + public UnitContext unit(int i) { + return getRuleContext(UnitContext.class, i); + } + + public List Operator() { + return getTokens(ReportParser.Operator); + } + + public TerminalNode Operator(int i) { + return getToken(ReportParser.Operator, i); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSimpleJoin(this); + else + return visitor.visitChildren(this); + } + } + + public static class UnitContext extends ParserRuleContext { + public UnitContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public DatasetContext dataset() { + return getRuleContext(DatasetContext.class, 0); + } + + public FunctionContext function() { + return getRuleContext(FunctionContext.class, 0); + } + + public SetContext set() { + return getRuleContext(SetContext.class, 0); + } + + public CellPositionContext cellPosition() { + return getRuleContext(CellPositionContext.class, 0); + } + + public RelativeCellContext relativeCell() { + return getRuleContext(RelativeCellContext.class, 0); + } + + public CurrentCellValueContext currentCellValue() { + return getRuleContext(CurrentCellValueContext.class, 0); + } + + public CurrentCellDataContext currentCellData() { + return getRuleContext(CurrentCellDataContext.class, 0); + } + + public CellContext cell() { + return getRuleContext(CellContext.class, 0); + } + + public VariableContext variable() { + return getRuleContext(VariableContext.class, 0); + } + + public TerminalNode INTEGER() { + return getToken(ReportParser.INTEGER, 0); + } + + public TerminalNode BOOLEAN() { + return getToken(ReportParser.BOOLEAN, 0); + } + + public TerminalNode STRING() { + return getToken(ReportParser.STRING, 0); + } + + public TerminalNode NUMBER() { + return getToken(ReportParser.NUMBER, 0); + } + + public TerminalNode NULL() { + return getToken(ReportParser.NULL, 0); + } + + @Override + public int getRuleIndex() { + return RULE_unit; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitUnit(this); + else + return visitor.visitChildren(this); + } + } + + public static class VariableContext extends ParserRuleContext { + public VariableContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Identifier() { + return getToken(ReportParser.Identifier, 0); + } + + @Override + public int getRuleIndex() { + return RULE_variable; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitVariable(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellPositionContext extends ParserRuleContext { + public CellPositionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + @Override + public int getRuleIndex() { + return RULE_cellPosition; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCellPosition(this); + else + return visitor.visitChildren(this); + } + } + + public static class RelativeCellContext extends ParserRuleContext { + public RelativeCellContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + @Override + public int getRuleIndex() { + return RULE_relativeCell; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitRelativeCell(this); + else + return visitor.visitChildren(this); + } + } + + public static class CurrentCellValueContext extends ParserRuleContext { + public CurrentCellValueContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + @Override + public int getRuleIndex() { + return RULE_currentCellValue; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCurrentCellValue(this); + else + return visitor.visitChildren(this); + } + } + + public static class CurrentCellDataContext extends ParserRuleContext { + public CurrentCellDataContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public PropertyContext property() { + return getRuleContext(PropertyContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_currentCellData; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCurrentCellData(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellContext extends ParserRuleContext { + public CellContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public PropertyContext property() { + return getRuleContext(PropertyContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_cell; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCell(this); + else + return visitor.visitChildren(this); + } + } + + public static class DatasetContext extends ParserRuleContext { + public DatasetContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Identifier() { + return getToken(ReportParser.Identifier, 0); + } + + public AggregateContext aggregate() { + return getRuleContext(AggregateContext.class, 0); + } + + public PropertyContext property() { + return getRuleContext(PropertyContext.class, 0); + } + + public ConditionsContext conditions() { + return getRuleContext(ConditionsContext.class, 0); + } + + public TerminalNode ORDER() { + return getToken(ReportParser.ORDER, 0); + } + + @Override + public int getRuleIndex() { + return RULE_dataset; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitDataset(this); + else + return visitor.visitChildren(this); + } + } + + public static class FunctionContext extends ParserRuleContext { + public FunctionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Identifier() { + return getToken(ReportParser.Identifier, 0); + } + + public FunctionParameterContext functionParameter() { + return getRuleContext(FunctionParameterContext.class, 0); + } + + @Override + public int getRuleIndex() { + return RULE_function; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitFunction(this); + else + return visitor.visitChildren(this); + } + } + + public static class FunctionParameterContext extends ParserRuleContext { + public FunctionParameterContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List item() { + return getRuleContexts(ItemContext.class); + } + + public ItemContext item(int i) { + return getRuleContext(ItemContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_functionParameter; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitFunctionParameter(this); + else + return visitor.visitChildren(this); + } + } + + public static class SetContext extends ParserRuleContext { + public SetContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public SetContext() { + } + + @Override + public int getRuleIndex() { + return RULE_set; + } + + public void copyFrom(SetContext ctx) { + super.copyFrom(ctx); + } + } + + public static class CellPairContext extends SetContext { + public CellPairContext(SetContext ctx) { + copyFrom(ctx); + } + + public List Cell() { + return getTokens(ReportParser.Cell); + } + + public TerminalNode Cell(int i) { + return getToken(ReportParser.Cell, i); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCellPair(this); + else + return visitor.visitChildren(this); + } + } + + public static class WholeCellContext extends SetContext { + public WholeCellContext(SetContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public ConditionsContext conditions() { + return getRuleContext(ConditionsContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitWholeCell(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellCoordinateConditionContext extends SetContext { + public CellCoordinateConditionContext(SetContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public CellCoordinateContext cellCoordinate() { + return getRuleContext(CellCoordinateContext.class, 0); + } + + public ConditionsContext conditions() { + return getRuleContext(ConditionsContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCellCoordinateCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class SingleCellConditionContext extends SetContext { + public SingleCellConditionContext(SetContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public ConditionsContext conditions() { + return getRuleContext(ConditionsContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSingleCellCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class SingleCellContext extends SetContext { + public SingleCellContext(SetContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSingleCell(this); + else + return visitor.visitChildren(this); + } + } + + public static class SimpleDataContext extends SetContext { + public SimpleDataContext(SetContext ctx) { + copyFrom(ctx); + } + + public SimpleValueContext simpleValue() { + return getRuleContext(SimpleValueContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSimpleData(this); + else + return visitor.visitChildren(this); + } + } + + public static class RangeContext extends SetContext { + public RangeContext(SetContext ctx) { + copyFrom(ctx); + } + + public List set() { + return getRuleContexts(SetContext.class); + } + + public SetContext set(int i) { + return getRuleContext(SetContext.class, i); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitRange(this); + else + return visitor.visitChildren(this); + } + } + + public static class SingleCellCoordinateContext extends SetContext { + public SingleCellCoordinateContext(SetContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public CellCoordinateContext cellCoordinate() { + return getRuleContext(CellCoordinateContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSingleCellCoordinate(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellCoordinateContext extends ParserRuleContext { + public CellCoordinateContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List coordinate() { + return getRuleContexts(CoordinateContext.class); + } + + public CoordinateContext coordinate(int i) { + return getRuleContext(CoordinateContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_cellCoordinate; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCellCoordinate(this); + else + return visitor.visitChildren(this); + } + } + + public static class CoordinateContext extends ParserRuleContext { + public CoordinateContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List cellIndicator() { + return getRuleContexts(CellIndicatorContext.class); + } + + public CellIndicatorContext cellIndicator(int i) { + return getRuleContext(CellIndicatorContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_coordinate; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCoordinate(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellIndicatorContext extends ParserRuleContext { + public CellIndicatorContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public CellIndicatorContext() { + } + + @Override + public int getRuleIndex() { + return RULE_cellIndicator; + } + + public void copyFrom(CellIndicatorContext ctx) { + super.copyFrom(ctx); + } + } + + public static class AbsoluteContext extends CellIndicatorContext { + public AbsoluteContext(CellIndicatorContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public TerminalNode INTEGER() { + return getToken(ReportParser.INTEGER, 0); + } + + public TerminalNode EXCLAMATION() { + return getToken(ReportParser.EXCLAMATION, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitAbsolute(this); + else + return visitor.visitChildren(this); + } + } + + public static class RelativeContext extends CellIndicatorContext { + public RelativeContext(CellIndicatorContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitRelative(this); + else + return visitor.visitChildren(this); + } + } + + public static class ConditionsContext extends ParserRuleContext { + public ConditionsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public List condition() { + return getRuleContexts(ConditionContext.class); + } + + public ConditionContext condition(int i) { + return getRuleContext(ConditionContext.class, i); + } + + public List join() { + return getRuleContexts(JoinContext.class); + } + + public JoinContext join(int i) { + return getRuleContext(JoinContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_conditions; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitConditions(this); + else + return visitor.visitChildren(this); + } + } + + public static class ConditionContext extends ParserRuleContext { + public ConditionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public ConditionContext() { + } + + @Override + public int getRuleIndex() { + return RULE_condition; + } + + public void copyFrom(ConditionContext ctx) { + super.copyFrom(ctx); + } + } + + public static class ExprConditionContext extends ConditionContext { + public ExprConditionContext(ConditionContext ctx) { + copyFrom(ctx); + } + + public List expr() { + return getRuleContexts(ExprContext.class); + } + + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class, i); + } + + public TerminalNode OP() { + return getToken(ReportParser.OP, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitExprCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class CurrentValueConditionContext extends ConditionContext { + public CurrentValueConditionContext(ConditionContext ctx) { + copyFrom(ctx); + } + + public CurrentValueContext currentValue() { + return getRuleContext(CurrentValueContext.class, 0); + } + + public TerminalNode OP() { + return getToken(ReportParser.OP, 0); + } + + public ExprContext expr() { + return getRuleContext(ExprContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCurrentValueCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class PropertyConditionContext extends ConditionContext { + public PropertyConditionContext(ConditionContext ctx) { + copyFrom(ctx); + } + + public PropertyContext property() { + return getRuleContext(PropertyContext.class, 0); + } + + public TerminalNode OP() { + return getToken(ReportParser.OP, 0); + } + + public ExprContext expr() { + return getRuleContext(ExprContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitPropertyCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class CellNameExprConditionContext extends ConditionContext { + public CellNameExprConditionContext(ConditionContext ctx) { + copyFrom(ctx); + } + + public TerminalNode Cell() { + return getToken(ReportParser.Cell, 0); + } + + public TerminalNode OP() { + return getToken(ReportParser.OP, 0); + } + + public ExprContext expr() { + return getRuleContext(ExprContext.class, 0); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCellNameExprCondition(this); + else + return visitor.visitChildren(this); + } + } + + public static class PropertyContext extends ParserRuleContext { + public PropertyContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Identifier() { + return getToken(ReportParser.Identifier, 0); + } + + public List property() { + return getRuleContexts(PropertyContext.class); + } + + public PropertyContext property(int i) { + return getRuleContext(PropertyContext.class, i); + } + + @Override + public int getRuleIndex() { + return RULE_property; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitProperty(this); + else + return visitor.visitChildren(this); + } + } + + public static class CurrentValueContext extends ParserRuleContext { + public CurrentValueContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + @Override + public int getRuleIndex() { + return RULE_currentValue; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitCurrentValue(this); + else + return visitor.visitChildren(this); + } + } + + public static class SimpleValueContext extends ParserRuleContext { + public SimpleValueContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode INTEGER() { + return getToken(ReportParser.INTEGER, 0); + } + + public TerminalNode NUMBER() { + return getToken(ReportParser.NUMBER, 0); + } + + public TerminalNode STRING() { + return getToken(ReportParser.STRING, 0); + } + + public TerminalNode BOOLEAN() { + return getToken(ReportParser.BOOLEAN, 0); + } + + public TerminalNode NULL() { + return getToken(ReportParser.NULL, 0); + } + + @Override + public int getRuleIndex() { + return RULE_simpleValue; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitSimpleValue(this); + else + return visitor.visitChildren(this); + } + } + + public static class JoinContext extends ParserRuleContext { + public JoinContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode AND() { + return getToken(ReportParser.AND, 0); + } + + public TerminalNode OR() { + return getToken(ReportParser.OR, 0); + } + + @Override + public int getRuleIndex() { + return RULE_join; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitJoin(this); + else + return visitor.visitChildren(this); + } + } + + public static class AggregateContext extends ParserRuleContext { + public AggregateContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + + public TerminalNode Identifier() { + return getToken(ReportParser.Identifier, 0); + } + + @Override + public int getRuleIndex() { + return RULE_aggregate; + } + + @Override + public T accept(ParseTreeVisitor visitor) { + if (visitor instanceof ReportVisitor) + return ((ReportVisitor) visitor).visitAggregate(this); + else + return visitor.visitChildren(this); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportVisitor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportVisitor.java new file mode 100644 index 0000000..40919b7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/antlr/ReportVisitor.java @@ -0,0 +1,230 @@ +package com.yunzhupaas.ureport.expression.antlr; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.*; +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/1 上午9:46 + */ +public class ReportVisitor extends AbstractParseTreeVisitor { + + public T visitEntry(EntryContext ctx) { + return visitChildren(ctx); + } + + public T visitExpression(ExpressionContext ctx) { + return visitChildren(ctx); + } + + public T visitComplexExprComposite(ComplexExprCompositeContext ctx) { + return visitChildren(ctx); + } + + public T visitSingleExprComposite(SingleExprCompositeContext ctx) { + return visitChildren(ctx); + } + + public T visitParenExprComposite(ParenExprCompositeContext ctx) { + return visitChildren(ctx); + } + + public T visitTernaryExprComposite(TernaryExprCompositeContext ctx) { + return visitChildren(ctx); + } + + public T visitTernaryExpr(TernaryExprContext ctx) { + return visitChildren(ctx); + } + + public T visitCaseExpr(CaseExprContext ctx) { + return visitChildren(ctx); + } + + public T visitCasePart(CasePartContext ctx) { + return visitChildren(ctx); + } + + public T visitIfExpr(IfExprContext ctx) { + return visitChildren(ctx); + } + + public T visitIfPart(IfPartContext ctx) { + return visitChildren(ctx); + } + + public T visitElseIfPart(ElseIfPartContext ctx) { + return visitChildren(ctx); + } + + public T visitElsePart(ElsePartContext ctx) { + return visitChildren(ctx); + } + + public T visitBlock(BlockContext ctx) { + return visitChildren(ctx); + } + + public T visitExprBlock(ExprBlockContext ctx) { + return visitChildren(ctx); + } + + public T visitReturnExpr(ReturnExprContext ctx) { + return visitChildren(ctx); + } + + public T visitExpr(ExprContext ctx) { + return visitChildren(ctx); + } + + public T visitIfCondition(IfConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitVariableAssign(VariableAssignContext ctx) { + return visitChildren(ctx); + } + + public T visitSimpleJoin(SimpleJoinContext ctx) { + return visitChildren(ctx); + } + + public T visitSingleParenJoin(SingleParenJoinContext ctx) { + return visitChildren(ctx); + } + + public T visitParenJoin(ParenJoinContext ctx) { + return visitChildren(ctx); + } + + public T visitUnit(UnitContext ctx) { + return visitChildren(ctx); + } + + public T visitVariable(VariableContext ctx) { + return visitChildren(ctx); + } + + public T visitCellPosition(CellPositionContext ctx) { + return visitChildren(ctx); + } + + public T visitRelativeCell(RelativeCellContext ctx) { + return visitChildren(ctx); + } + + public T visitCurrentCellValue(CurrentCellValueContext ctx) { + return visitChildren(ctx); + } + + public T visitCurrentCellData(CurrentCellDataContext ctx) { + return visitChildren(ctx); + } + + public T visitCell(CellContext ctx) { + return visitChildren(ctx); + } + + public T visitDataset(DatasetContext ctx) { + return visitChildren(ctx); + } + + public T visitFunction(FunctionContext ctx) { + return visitChildren(ctx); + } + + public T visitFunctionParameter(FunctionParameterContext ctx) { + return visitChildren(ctx); + } + + public T visitCellPair(CellPairContext ctx) { + return visitChildren(ctx); + } + + public T visitWholeCell(WholeCellContext ctx) { + return visitChildren(ctx); + } + + public T visitCellCoordinateCondition(CellCoordinateConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitSingleCellCondition(SingleCellConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitSingleCell(SingleCellContext ctx) { + return visitChildren(ctx); + } + + public T visitSimpleData(SimpleDataContext ctx) { + return visitChildren(ctx); + } + + public T visitRange(RangeContext ctx) { + return visitChildren(ctx); + } + + public T visitSingleCellCoordinate(SingleCellCoordinateContext ctx) { + return visitChildren(ctx); + } + + public T visitCellCoordinate(CellCoordinateContext ctx) { + return visitChildren(ctx); + } + + public T visitCoordinate(CoordinateContext ctx) { + return visitChildren(ctx); + } + + public T visitRelative(RelativeContext ctx) { + return visitChildren(ctx); + } + + public T visitAbsolute(AbsoluteContext ctx) { + return visitChildren(ctx); + } + + public T visitConditions(ConditionsContext ctx) { + return visitChildren(ctx); + } + + public T visitCellNameExprCondition(CellNameExprConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitPropertyCondition(PropertyConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitCurrentValueCondition(CurrentValueConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitExprCondition(ExprConditionContext ctx) { + return visitChildren(ctx); + } + + public T visitProperty(PropertyContext ctx) { + return visitChildren(ctx); + } + + public T visitCurrentValue(CurrentValueContext ctx) { + return visitChildren(ctx); + } + + public T visitSimpleValue(SimpleValueContext ctx) { + return visitChildren(ctx); + } + + public T visitJoin(JoinContext ctx) { + return visitChildren(ctx); + } + + public T visitAggregate(AggregateContext ctx) { + return visitChildren(ctx); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/AbstractAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/AbstractAssertor.java new file mode 100644 index 0000000..7a80e59 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/AbstractAssertor.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import java.util.List; + +/** + * @author + * @since 9月15日 + */ +public abstract class AbstractAssertor implements Assertor { + protected Object buildObject(Object obj) { + if (obj == null) { + return obj; + } + if (obj instanceof List) { + List list = (List) obj; + if (list.size() == 1) { + return list.get(0); + } + } + return obj; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/Assertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/Assertor.java new file mode 100644 index 0000000..f8d1513 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/Assertor.java @@ -0,0 +1,9 @@ +package com.yunzhupaas.ureport.expression.assertor; + +/** + * @author + * @since 1月12日 + */ +public interface Assertor { + boolean eval(Object left, Object right); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsAssertor.java new file mode 100644 index 0000000..7b9e35f --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsAssertor.java @@ -0,0 +1,56 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author + * @since 1月12日 + */ +public class EqualsAssertor extends AbstractAssertor { + @Override + public boolean eval(Object left, Object right) { + if (left == null && right == null) { + return true; + } + if (left == null || right == null) { + return false; + } + if (left instanceof java.sql.Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((Date) left) + .compareTo(new java.sql.Time(datetime.hour(true), datetime.minute(), datetime.second())) == 0; + } else if (left instanceof Date) { + return ((Date) left).compareTo(DateUtil.parse(right.toString())) == 0; + } else if (left instanceof Number && right instanceof Number) { + BigDecimal b1 = new BigDecimal(String.valueOf(left)); + BigDecimal b2 = new BigDecimal(String.valueOf(right)); + return b1.compareTo(b2) == 0; + } else if (left instanceof Number) { + BigDecimal b1 = new BigDecimal(String.valueOf(left)); + BigDecimal b2 = null; + try { + b2 = new BigDecimal(String.valueOf(right)); + } catch (Exception ex) { + } + if (b2 != null) { + return b1.compareTo(b2) == 0; + } + } else if (right instanceof Number) { + BigDecimal b1 = new BigDecimal(String.valueOf(right)); + BigDecimal b2 = null; + try { + b2 = new BigDecimal(String.valueOf(left)); + } catch (Exception ex) { + } + if (b2 != null) { + return b1.compareTo(b2) == 0; + } + } + right = buildObject(right); + return left.equals(right); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsGreatThenAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsGreatThenAssertor.java new file mode 100644 index 0000000..66d4195 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsGreatThenAssertor.java @@ -0,0 +1,42 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.sql.Time; + +/** + * @author + * @since 1月12日 + */ +public class EqualsGreatThenAssertor extends AbstractAssertor { + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())) { + return false; + } + if (left instanceof Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((java.util.Date) left) + .compareTo(new Time(datetime.hour(true), datetime.minute(), datetime.second())) > -1; + } else if (left instanceof java.util.Date) { + return ((java.util.Date) left).compareTo(DateUtil.parse(right.toString())) > -1; + } else if (left instanceof String) { + return ((String) left).compareTo(right.toString()) > -1; + } else { + try { + BigDecimal leftObj = new BigDecimal(String.valueOf(left)); + right = buildObject(right); + BigDecimal rightObj = new BigDecimal(String.valueOf(right)); + return leftObj.compareTo(rightObj) > -1; + } catch (Exception e) { + return false; + } + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsLessThenAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsLessThenAssertor.java new file mode 100644 index 0000000..9722013 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/EqualsLessThenAssertor.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; + +/** + * @author + * @since 1月12日 + */ +public class EqualsLessThenAssertor extends AbstractAssertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())) { + return false; + } + if (StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())) { + return false; + } + if (left instanceof java.sql.Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((java.util.Date) left) + .compareTo(new java.sql.Time(datetime.hour(true), datetime.minute(), datetime.second())) < 1; + } else if (left instanceof java.util.Date) { + return ((java.util.Date) left).compareTo(DateUtil.parse(right.toString())) < 1; + } else if (left instanceof String) { + return ((String) left).compareTo(right.toString()) < 1; + } else { + try { + BigDecimal leftObj = new BigDecimal(String.valueOf(left)); + right = buildObject(right); + BigDecimal rightObj = new BigDecimal(String.valueOf(right)); + return leftObj.compareTo(rightObj) < -1; + } catch (Exception e) { + return false; + } + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/GreatThenAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/GreatThenAssertor.java new file mode 100644 index 0000000..17f5a6e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/GreatThenAssertor.java @@ -0,0 +1,42 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; + +/** + * @author + * @since 1月12日 + */ +public class GreatThenAssertor extends AbstractAssertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())) { + return false; + } + if (left instanceof java.sql.Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((java.util.Date) left) + .compareTo(new java.sql.Time(datetime.hour(true), datetime.minute(), datetime.second())) == 1; + } else if (left instanceof java.util.Date) { + return ((java.util.Date) left).compareTo(DateUtil.parse(right.toString())) == 1; + } else if (left instanceof String) { + return ((String) left).compareTo(right.toString()) == 1; + } else { + try { + BigDecimal leftObj = new BigDecimal(String.valueOf(left)); + right = buildObject(right); + BigDecimal rightObj = new BigDecimal(String.valueOf(right)); + return leftObj.compareTo(rightObj) == 1; + } catch (Exception e) { + return false; + } + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/InAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/InAssertor.java new file mode 100644 index 0000000..9f669f6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/InAssertor.java @@ -0,0 +1,58 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; + +import java.sql.Time; +import java.util.Date; +import java.util.List; + +/** + * @author + * @since 1月12日 + */ +public class InAssertor implements Assertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (right instanceof List) { + List list = (List) right; + for (Object obj : list) { + if (left.equals(obj)) { + return true; + } + } + return false; + } else if (right instanceof Object[]) { + Object[] objs = (Object[]) right; + for (Object obj : objs) { + if (left.equals(obj)) { + return true; + } + } + return false; + } else if (right instanceof String) { + String[] array = right.toString().split(","); + for (String str : array) { + if (left instanceof Time) { + DateTime datetime = DateUtil.parse(str); + if (((Time) left) + .compareTo(new Time(datetime.hour(true), datetime.minute(), datetime.second())) == 0) { + return true; + } + } else if (left instanceof Date) { + if (((Date) left).compareTo(DateUtil.parse(str)) == 0) { + return true; + } + } else if (left.equals(str)) { + return true; + } + } + return false; + } + return left.equals(right); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LessThenAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LessThenAssertor.java new file mode 100644 index 0000000..6ea15cf --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LessThenAssertor.java @@ -0,0 +1,42 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; + +/** + * @author + * @since 1月12日 + */ +public class LessThenAssertor extends AbstractAssertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())) { + return false; + } + if (left instanceof java.sql.Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((java.util.Date) left) + .compareTo(new java.sql.Time(datetime.hour(true), datetime.minute(), datetime.second())) == -1; + } else if (left instanceof java.util.Date) { + return ((java.util.Date) left).compareTo(DateUtil.parse(right.toString())) == -1; + } else if (left instanceof String) { + return ((String) left).compareTo(right.toString()) == -1; + } else { + try { + BigDecimal leftObj = new BigDecimal(String.valueOf(left)); + right = buildObject(right); + BigDecimal rightObj = new BigDecimal(String.valueOf(right)); + return leftObj.compareTo(rightObj) == -1; + } catch (Exception e) { + return false; + } + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LikeAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LikeAssertor.java new file mode 100644 index 0000000..742a41a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/LikeAssertor.java @@ -0,0 +1,20 @@ +package com.yunzhupaas.ureport.expression.assertor; + +/** + * @author + * @since 1月12日 + */ +public class LikeAssertor implements Assertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (left.equals(right)) { + return true; + } + return left.toString().indexOf(right.toString()) > -1; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotEqualsAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotEqualsAssertor.java new file mode 100644 index 0000000..3cb21b9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotEqualsAssertor.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; + +import java.util.Date; + +/** + * @author + * @since 1月12日 + */ +public class NotEqualsAssertor extends AbstractAssertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null && right == null) { + return false; + } + if (left == null || right == null) { + return true; + } + if (left instanceof java.sql.Time) { + DateTime datetime = DateUtil.parse(right.toString()); + return ((Date) left) + .compareTo(new java.sql.Time(datetime.hour(true), datetime.minute(), datetime.second())) == 0; + } else if (left instanceof Date) { + return ((Date) left).compareTo(DateUtil.parse(right.toString())) == 0; + } + right = buildObject(right); + return !left.equals(right); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotInAssertor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotInAssertor.java new file mode 100644 index 0000000..953df69 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/assertor/NotInAssertor.java @@ -0,0 +1,43 @@ +package com.yunzhupaas.ureport.expression.assertor; + +import java.util.List; + +/** + * @author + * @since 1月12日 + */ +public class NotInAssertor implements Assertor { + + @Override + public boolean eval(Object left, Object right) { + if (left == null || right == null) { + return false; + } + if (right instanceof List) { + List list = (List) right; + for (Object obj : list) { + if (!left.equals(obj)) { + return true; + } + } + return false; + } else if (right instanceof Object[]) { + Object[] objs = (Object[]) right; + for (Object obj : objs) { + if (!left.equals(obj)) { + return true; + } + } + return false; + } else if (right instanceof String) { + String[] array = right.toString().split(","); + for (String str : array) { + if (!left.equals(str)) { + return true; + } + } + return false; + } + return !left.equals(right); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BaseExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BaseExpressionBuilder.java new file mode 100644 index 0000000..d45115b --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BaseExpressionBuilder.java @@ -0,0 +1,128 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.*; +import com.yunzhupaas.ureport.expression.condition.*; +import com.yunzhupaas.ureport.expression.expr.*; +import com.yunzhupaas.ureport.expression.util.ExpressionUtils; +import com.yunzhupaas.ureport.expression.util.Op; +import com.yunzhupaas.ureport.utils.DataUtils; +import org.antlr.v4.runtime.tree.TerminalNode; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author + * @since 2016年12月26日 + */ +public abstract class BaseExpressionBuilder implements ExpressionBuilder { + protected BaseExpression parseSimpleValueContext(SimpleValueContext valueContext) { + if (valueContext.BOOLEAN() != null) { + return new BooleanExpression(Boolean.valueOf(valueContext.getText())); + } else if (valueContext.INTEGER() != null) { + return new IntegerExpression(Integer.valueOf(valueContext.INTEGER().getText())); + } else if (valueContext.STRING() != null) { + String text = valueContext.STRING().getText(); + text = text.substring(1, text.length() - 1); + return new StringExpression(text); + } else if (valueContext.NUMBER() != null) { + BigDecimal number = DataUtils.toBigDecimal(valueContext.NUMBER().getText()); + return new NumberExpression(number); + } else if (valueContext.NULL() != null) { + return new NullExpression(); + } + return new StringExpression(""); + } + + protected BaseCondition buildConditions(ConditionsContext conditionsContext) { + List conditionContextList = conditionsContext.condition(); + List joins = conditionsContext.join(); + BaseCondition condition = null; + BaseCondition topCondition = null; + int opIndex = 0; + for (ConditionContext conditionCtx : conditionContextList) { + if (condition == null) { + condition = parseCondition(conditionCtx); + topCondition = condition; + } else { + BaseCondition nextCondition = parseCondition(conditionCtx); + condition.setNextCondition(nextCondition); + condition.setJoin(Join.parse(joins.get(opIndex).getText())); + opIndex++; + condition = nextCondition; + } + } + return topCondition; + } + + private BaseCondition parseCondition(ConditionContext context) { + if (context instanceof ExprConditionContext) { + ExprConditionContext ctx = (ExprConditionContext) context; + BothExpressionCondition condition = new BothExpressionCondition(); + List exprContexts = ctx.expr(); + String left = exprContexts.get(0).getText(); + condition.setLeft(left); + Expression leftExpr = ExpressionUtils.parseExpression(left); + condition.setLeftExpression(leftExpr); + String rightExpr = exprContexts.get(1).getText(); + condition.setRight(rightExpr); + condition.setRightExpression(ExpressionUtils.parseExpression(rightExpr)); + condition.setOp(parseOp(ctx.OP())); + condition.setOperation(ctx.OP().getText()); + return condition; + } else if (context instanceof CurrentValueConditionContext) { + CurrentValueConditionContext ctx = (CurrentValueConditionContext) context; + CurrentValueExpressionCondition condition = new CurrentValueExpressionCondition(); + String rightExpr = ctx.expr().getText(); + condition.setRight(rightExpr); + condition.setRightExpression(ExpressionUtils.parseExpression(rightExpr)); + condition.setOp(parseOp(ctx.OP())); + return condition; + } else if (context instanceof PropertyConditionContext) { + PropertyConditionContext ctx = (PropertyConditionContext) context; + PropertyExpressionCondition condition = new PropertyExpressionCondition(); + String left = ctx.property().getText(); + condition.setLeft(left); + condition.setLeftProperty(left); + String rightExpr = ctx.expr().getText(); + condition.setRight(rightExpr); + condition.setRightExpression(ExpressionUtils.parseExpression(rightExpr)); + condition.setOp(parseOp(ctx.OP())); + return condition; + } else if (context instanceof CellNameExprConditionContext) { + CellNameExprConditionContext ctx = (CellNameExprConditionContext) context; + CellExpressionCondition condition = new CellExpressionCondition(); + String left = ctx.Cell().getText(); + condition.setLeft(left); + condition.setCellName(left); + String rightExpr = ctx.expr().getText(); + condition.setRight(rightExpr); + condition.setRightExpression(ExpressionUtils.parseExpression(rightExpr)); + condition.setOp(parseOp(ctx.OP())); + return condition; + } + return null; + } + + private Op parseOp(TerminalNode opNode) { + if (opNode.getText().equals(">")) { + return Op.GreatThen; + } + if (opNode.getText().equals("<")) { + return Op.LessThen; + } + if (opNode.getText().equals(">=")) { + return Op.EqualsGreatThen; + } + if (opNode.getText().equals("<=")) { + return Op.EqualsLessThen; + } + if (opNode.getText().equals("==")) { + return Op.Equals; + } + if (opNode.getText().equals("!=")) { + return Op.NotEquals; + } + return Op.Equals; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BooleanExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BooleanExpressionBuilder.java new file mode 100644 index 0000000..bc9e881 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/BooleanExpressionBuilder.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.BooleanExpression; + +/** + * @author + * @since 2016年12月25日 + */ +public class BooleanExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + String text = unitContext.BOOLEAN().getText(); + return new BooleanExpression(Boolean.valueOf(text)); + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.BOOLEAN() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellObjectExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellObjectExpressionBuilder.java new file mode 100644 index 0000000..a0a25f0 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellObjectExpressionBuilder.java @@ -0,0 +1,32 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.CellContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.PropertyContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.CellObjectExpression; + +/** + * @author + * @since 1月20日 + */ +public class CellObjectExpressionBuilder implements ExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + CellContext ctx = unitContext.cell(); + String property = null; + PropertyContext propCtx = ctx.property(); + if (propCtx != null) { + property = propCtx.getText(); + } + CellObjectExpression expr = new CellObjectExpression(property); + expr.setExpr(ctx.getText()); + return expr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.cell() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellPositionExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellPositionExpressionBuilder.java new file mode 100644 index 0000000..ba3df01 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CellPositionExpressionBuilder.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.CellPositionContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.CellPositionExpression; + +/** + * @author + * @since 1月21日 + */ +public class CellPositionExpressionBuilder implements ExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + CellPositionContext ctx = unitContext.cellPosition(); + CellPositionExpression expr = new CellPositionExpression(ctx.Cell().getText()); + return expr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.cellPosition() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellDataExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellDataExpressionBuilder.java new file mode 100644 index 0000000..37af903 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellDataExpressionBuilder.java @@ -0,0 +1,27 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.CurrentCellDataContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.CellDataExpression; + +/** + * @author + * @since 7月11日 + */ +public class CurrentCellDataExpressionBuilder implements ExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + CurrentCellDataContext context = unitContext.currentCellData(); + CellDataExpression expr = new CellDataExpression(); + expr.setProperty(context.property().getText()); + return expr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.currentCellData() != null; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellValueExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellValueExpressionBuilder.java new file mode 100644 index 0000000..33e2081 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/CurrentCellValueExpressionBuilder.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.CellValueExpression; + +/** + * @author + * @since 7月11日 + */ +public class CurrentCellValueExpressionBuilder implements ExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + return new CellValueExpression(); + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.currentCellValue() != null; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/ExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/ExpressionBuilder.java new file mode 100644 index 0000000..5555694 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/ExpressionBuilder.java @@ -0,0 +1,14 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; + +/** + * @author + * @since 2016年12月23日 + */ +public interface ExpressionBuilder { + BaseExpression build(UnitContext unitContext); + + boolean support(UnitContext unitContext); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/FunctionExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/FunctionExpressionBuilder.java new file mode 100644 index 0000000..c261662 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/FunctionExpressionBuilder.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.FunctionContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.FunctionParameterContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.ItemContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.FunctionExpression; +import com.yunzhupaas.ureport.expression.util.ExpressionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月26日 + */ +public class FunctionExpressionBuilder extends BaseExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + FunctionContext ctx = unitContext.function(); + FunctionExpression expr = new FunctionExpression(); + expr.setExpr(ctx.getText()); + expr.setName(ctx.Identifier().getText()); + FunctionParameterContext functionParameterContext = ctx.functionParameter(); + if (functionParameterContext != null) { + List exprList = new ArrayList<>(); + List itemContexts = functionParameterContext.item(); + if (itemContexts != null) { + for (int i = 0; i < itemContexts.size(); i++) { + ItemContext itemContext = itemContexts.get(i); + BaseExpression baseExpr = ExpressionUtils.getExprVisitor().parseItemContext(itemContext); + exprList.add(baseExpr); + } + } + expr.setExpressions(exprList); + } + return expr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.function() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/IntegerExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/IntegerExpressionBuilder.java new file mode 100644 index 0000000..51961dc --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/IntegerExpressionBuilder.java @@ -0,0 +1,26 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.IntegerExpression; + +/** + * @author + * @since 2016年12月24日 + */ +public class IntegerExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + Integer value = null; + if (unitContext.INTEGER() != null) { + value = Integer.valueOf(unitContext.INTEGER().getText()); + } + return new IntegerExpression(value); + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.INTEGER() != null; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NullExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NullExpressionBuilder.java new file mode 100644 index 0000000..03ab524 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NullExpressionBuilder.java @@ -0,0 +1,21 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.NullExpression; + +/** + * @author + * @since 2016年12月25日 + */ +public class NullExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + return new NullExpression(); + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.NULL() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NumberExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NumberExpressionBuilder.java new file mode 100644 index 0000000..bbf4e65 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/NumberExpressionBuilder.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.NumberExpression; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.math.BigDecimal; + +/** + * @author + * @since 2016年12月25日 + */ +public class NumberExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + BigDecimal number = DataUtils.toBigDecimal(unitContext.NUMBER().getText()); + return new NumberExpression(number); + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.NUMBER() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/RelativeCellExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/RelativeCellExpressionBuilder.java new file mode 100644 index 0000000..682ffb6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/RelativeCellExpressionBuilder.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.RelativeCellContext; +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.RelativeCellExpression; + +/** + * @author + * @since 1月21日 + */ +public class RelativeCellExpressionBuilder implements ExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + RelativeCellContext ctx = unitContext.relativeCell(); + RelativeCellExpression expr = new RelativeCellExpression(ctx.Cell().getText()); + return expr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.relativeCell() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/SetExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/SetExpressionBuilder.java new file mode 100644 index 0000000..b41d6a6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/SetExpressionBuilder.java @@ -0,0 +1,131 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.*; +import com.yunzhupaas.ureport.expression.condition.BaseCondition; +import com.yunzhupaas.ureport.expression.condition.CellCoordinate; +import com.yunzhupaas.ureport.expression.condition.CellCoordinateSet; +import com.yunzhupaas.ureport.expression.condition.CoordinateType; +import com.yunzhupaas.ureport.expression.expr.*; +import org.antlr.v4.runtime.tree.TerminalNode; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月25日 + */ +public class SetExpressionBuilder extends BaseExpressionBuilder { + + @Override + public BaseExpression build(UnitContext unitContext) { + SetContext context = unitContext.set(); + BaseExpression setExpr = buildSetExpression(context); + if (setExpr != null) { + setExpr.setExpr(context.getText()); + } + return setExpr; + } + + public BaseExpression buildSetExpression(SetContext context) { + if (context instanceof SingleCellContext) { + TerminalNode cellNode = ((SingleCellContext) context).Cell(); + return new CellExpression(cellNode.getText()); + } else if (context instanceof WholeCellContext) { + WholeCellContext ctx = (WholeCellContext) context; + WholeCellExpression wholeCellExpression = new WholeCellExpression(ctx.Cell().getText()); + ConditionsContext conditionsContext = ctx.conditions(); + if (conditionsContext != null) { + BaseCondition condition = buildConditions(conditionsContext); + wholeCellExpression.setExpressionCondition(condition); + } + return wholeCellExpression; + } else if (context instanceof SingleCellConditionContext) { + SingleCellConditionContext ctx = (SingleCellConditionContext) context; + BaseCondition condition = buildConditions(ctx.conditions()); + return new CellConditionExpression(ctx.Cell().getText(), condition); + } else if (context instanceof SingleCellCoordinateContext) { + SingleCellCoordinateContext ctx = (SingleCellCoordinateContext) context; + String cellName = null; + if (ctx.Cell() != null) { + cellName = ctx.Cell().getText(); + } + CellCoordinateContext cellCoordinateContext = ctx.cellCoordinate(); + List coordinateContexts = cellCoordinateContext.coordinate(); + CellCoordinateSet leftCoordinate = parseCellCoordinateSet(coordinateContexts.get(0)); + CellCoordinateSet topCoordinate = null; + if (coordinateContexts.size() > 1) { + topCoordinate = parseCellCoordinateSet(coordinateContexts.get(1)); + } + CellCoordinateExpression cellCoordinate = new CellCoordinateExpression(cellName); + cellCoordinate.setTopCoordinate(topCoordinate); + cellCoordinate.setLeftCoordinate(leftCoordinate); + return cellCoordinate; + } else if (context instanceof CellCoordinateConditionContext) { + CellCoordinateConditionContext ctx = (CellCoordinateConditionContext) context; + String cellName = null; + if (ctx.Cell() != null) { + cellName = ctx.Cell().getText(); + } + CellCoordinateContext cellCoordinateContext = ctx.cellCoordinate(); + List coordinateContexts = cellCoordinateContext.coordinate(); + CellCoordinateSet leftCoordinate = parseCellCoordinateSet(coordinateContexts.get(0)); + CellCoordinateSet topCoordinate = null; + if (coordinateContexts.size() > 1) { + topCoordinate = parseCellCoordinateSet(coordinateContexts.get(1)); + } + BaseCondition condition = buildConditions(ctx.conditions()); + CellCoordinateExpression cellCoordinate = new CellCoordinateExpression(cellName); + cellCoordinate.setTopCoordinate(topCoordinate); + cellCoordinate.setLeftCoordinate(leftCoordinate); + cellCoordinate.setCondition(condition); + return cellCoordinate; + } else if (context instanceof RangeContext) { + RangeContext ctx = (RangeContext) context; + List sets = ctx.set(); + if (sets.size() != 2) { + return null; + } + BaseExpression fromExpr = buildSetExpression(sets.get(0)); + BaseExpression toExpr = buildSetExpression(sets.get(1)); + FromToExpression expr = new FromToExpression(fromExpr, toExpr); + return expr; + } else if (context instanceof SimpleDataContext) { + SimpleDataContext ctx = (SimpleDataContext) context; + SimpleValueContext valueContext = ctx.simpleValue(); + return parseSimpleValueContext(valueContext); + } + return null; + } + + private CellCoordinateSet parseCellCoordinateSet(CoordinateContext ctx) { + List coordinates = new ArrayList<>(); + for (CellIndicatorContext indicatorContext : ctx.cellIndicator()) { + if (indicatorContext instanceof RelativeContext) { + RelativeContext context = (RelativeContext) indicatorContext; + String cellName = context.Cell().getText(); + CellCoordinate coordinate = new CellCoordinate(cellName, CoordinateType.relative); + coordinates.add(coordinate); + } else { + AbsoluteContext context = (AbsoluteContext) indicatorContext; + String cellName = context.Cell().getText(); + String pos = context.INTEGER().getText(); + int position = Integer.valueOf(pos); + CellCoordinate coordinate = new CellCoordinate(cellName, CoordinateType.absolute); + coordinate.setPosition(position); + if (context.EXCLAMATION() != null) { + coordinate.setReverse(true); + } + coordinates.add(coordinate); + } + } + CellCoordinateSet coordinateSet = new CellCoordinateSet(); + coordinateSet.setCellCoordinates(coordinates); + return coordinateSet; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.set() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/StringExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/StringExpressionBuilder.java new file mode 100644 index 0000000..b00a3fc --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/StringExpressionBuilder.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.StringExpression; + +/** + * @author + * @since 2016年12月23日 + */ +public class StringExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + String text = unitContext.STRING().getText(); + text = text.substring(1, text.length() - 1); + StringExpression stringExpr = new StringExpression(text); + return stringExpr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.STRING() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/VariableExpressionBuilder.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/VariableExpressionBuilder.java new file mode 100644 index 0000000..c0f89a4 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/builder/VariableExpressionBuilder.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.ureport.expression.builder; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.UnitContext; +import com.yunzhupaas.ureport.expression.expr.BaseExpression; +import com.yunzhupaas.ureport.expression.expr.VariableExpression; + +/** + * @author + * @since 2018年7月15日 + */ +public class VariableExpressionBuilder implements ExpressionBuilder { + @Override + public BaseExpression build(UnitContext unitContext) { + String text = unitContext.variable().Identifier().getText(); + VariableExpression varExpr = new VariableExpression(text); + return varExpr; + } + + @Override + public boolean support(UnitContext unitContext) { + return unitContext.variable() != null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BaseCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BaseCondition.java new file mode 100644 index 0000000..5cb02fb --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BaseCondition.java @@ -0,0 +1,84 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.*; +import com.yunzhupaas.ureport.expression.expr.Join; +import com.yunzhupaas.ureport.expression.util.ExpressionUtils; +import com.yunzhupaas.ureport.expression.util.Op; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年11月22日 + */ +@Getter +@Setter +public abstract class BaseCondition implements Condition { + private Op op; + private String operation; + private Join join; + private Condition nextCondition; + private String left; + private String right; + + @Override + public final boolean filter(Cell cell, Cell currentCell, Object obj, Context context) { + Object left = computeLeft(cell, currentCell, obj, context); + Object right = computeRight(cell, currentCell, obj, context); + boolean result = ExpressionUtils.conditionEval(op, left, right); + if (join != null && nextCondition != null) { + if (result) { + if (join.equals(Join.and)) { + return nextCondition.filter(cell, currentCell, obj, context); + } else { + return result; + } + } else { + if (join.equals(Join.and)) { + return result; + } else { + return nextCondition.filter(cell, currentCell, obj, context); + } + } + } + return result; + } + + abstract Object computeLeft(Cell cell, Cell currentCell, Object obj, Context context); + + abstract Object computeRight(Cell cell, Cell currentCell, Object obj, Context context); + + public abstract ConditionType getType(); + + protected Object extractExpressionData(ExpressionData data) { + if (data instanceof ObjectExpressionData) { + return data.getData(); + } else if (data instanceof ObjectListExpressionData) { + ObjectListExpressionData listData = (ObjectListExpressionData) data; + List list = listData.getData(); + return list; + } else if (data instanceof BindDataListExpressionData) { + BindDataListExpressionData bindData = (BindDataListExpressionData) data; + List bindDataList = bindData.getData(); + List list = new ArrayList<>(); + for (BindData bd : bindDataList) { + Object v = bd.getValue(); + list.add(v); + } + if (list.size() == 1) { + return list.get(0); + } else if (list.size() == 0) { + return null; + } + return list; + } + return new NoneExpressionData().getData(); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BothExpressionCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BothExpressionCondition.java new file mode 100644 index 0000000..1a82501 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/BothExpressionCondition.java @@ -0,0 +1,41 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +/** + * @author + * @since 2016年11月22日 + */ +@Setter +@Getter +public class BothExpressionCondition extends BaseCondition { + private ConditionType type = ConditionType.expression; + @JsonIgnore + private Expression leftExpression; + @JsonIgnore + private Expression rightExpression; + + @Override + Object computeLeft(Cell cell, Cell currentCell, Object obj, Context context) { + ExpressionData exprData = leftExpression.execute(cell, currentCell, context); + return extractExpressionData(exprData); + } + + @Override + Object computeRight(Cell cell, Cell currentCell, Object obj, Context context) { + ExpressionData exprData = rightExpression.execute(cell, currentCell, context); + return extractExpressionData(exprData); + } + + @Override + public ConditionType getType() { + return type; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinate.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinate.java new file mode 100644 index 0000000..cb0e7c6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinate.java @@ -0,0 +1,21 @@ +package com.yunzhupaas.ureport.expression.condition; + +import lombok.Data; + +/** + * @author + * @since 4月2日 + */ +@Data +public class CellCoordinate { + private String cellName; + private int position; + private boolean reverse; + private CoordinateType coordinateType; + + public CellCoordinate(String cellName, CoordinateType coordinateType) { + this.cellName = cellName; + this.coordinateType = coordinateType; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinateSet.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinateSet.java new file mode 100644 index 0000000..18f5b0e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellCoordinateSet.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.ureport.expression.condition; + +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 4月2日 + */ +@Setter +@Getter +public class CellCoordinateSet { + private List cellCoordinates = new ArrayList<>(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellExpressionCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellExpressionCondition.java new file mode 100644 index 0000000..f3c137f --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CellExpressionCondition.java @@ -0,0 +1,57 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.StringJoiner; + +/** + * @author + * @since 4月7日 + */ +@Setter +@Getter +public class CellExpressionCondition extends BaseCondition { + private ConditionType type = ConditionType.cell; + private String cellName; + private Expression rightExpression; + + @Override + Object computeLeft(Cell cell, Cell currentCell, Object obj, Context context) { + if (cellName.equals(currentCell.getName())) { + return currentCell.getData(); + } else { + List cells = DataUtils.fetchTargetCells(cell, context, cellName); + for (Cell c : cells) { + if (c.getRow() == cell.getRow() || c.getColumn() == cell.getColumn()) { + return c.getData(); + } + } + StringJoiner joiner = new StringJoiner(","); + for (Cell c : cells) { + if (c.getData() != null) { + joiner.add(c.getData().toString()); + } + } + return joiner; + } + } + + @Override + Object computeRight(Cell cell, Cell currentCell, Object obj, Context context) { + ExpressionData exprData = rightExpression.execute(cell, currentCell, context); + return extractExpressionData(exprData); + } + + @Override + public ConditionType getType() { + return type; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/Condition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/Condition.java new file mode 100644 index 0000000..376ceb6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/Condition.java @@ -0,0 +1,13 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2016年11月18日 + */ +public interface Condition { + + boolean filter(Cell cell, Cell currentCell, Object obj, Context context); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/ConditionType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/ConditionType.java new file mode 100644 index 0000000..942bb6a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/ConditionType.java @@ -0,0 +1,9 @@ +package com.yunzhupaas.ureport.expression.condition; + +/** + * @author + * @since 4月24日 + */ +public enum ConditionType { + property, expression, cell, current; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CoordinateType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CoordinateType.java new file mode 100644 index 0000000..d53ddd5 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CoordinateType.java @@ -0,0 +1,9 @@ +package com.yunzhupaas.ureport.expression.condition; + +/** + * @author + * @since 4月6日 + */ +public enum CoordinateType { + relative, absolute; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CurrentValueExpressionCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CurrentValueExpressionCondition.java new file mode 100644 index 0000000..dacc603 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/CurrentValueExpressionCondition.java @@ -0,0 +1,37 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +/** + * @author + * @since 12月8日 + */ +@Setter +@Getter +public class CurrentValueExpressionCondition extends BaseCondition { + private ConditionType type = ConditionType.current; + @JsonIgnore + private Expression rightExpression; + + @Override + Object computeLeft(Cell cell, Cell currentCell, Object obj, Context context) { + return obj; + } + + @Override + Object computeRight(Cell cell, Cell currentCell, Object obj, Context context) { + ExpressionData exprData = rightExpression.execute(cell, currentCell, context); + return extractExpressionData(exprData); + } + + @Override + public ConditionType getType() { + return type; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/PropertyExpressionCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/PropertyExpressionCondition.java new file mode 100644 index 0000000..94dba9d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/condition/PropertyExpressionCondition.java @@ -0,0 +1,52 @@ +package com.yunzhupaas.ureport.expression.condition; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.expr.Expression; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.StringUtils; + +import java.util.Map; + +/** + * @author + * @since 2016年11月22日 + */ +@Setter +@Getter +public class PropertyExpressionCondition extends BaseCondition { + private ConditionType type = ConditionType.property; + @JsonIgnore + private String leftProperty; + @JsonIgnore + private Expression rightExpression; + + @Override + Object computeLeft(Cell cell, Cell currentCell, Object obj, Context context) { + Object data = cell.getData(); + try { + if (StringUtils.isNotBlank(leftProperty) && obj instanceof Map) { + Map map = (Map) obj; + data = map.get(leftProperty); + } + } catch (Exception e) { + + } + return data; + } + + @Override + Object computeRight(Cell cell, Cell currentCell, Object obj, Context context) { + ExpressionData exprData = rightExpression.execute(cell, currentCell, context); + return extractExpressionData(exprData); + } + + @Override + public ConditionType getType() { + return type; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/BindDataListExpressionData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/BindDataListExpressionData.java new file mode 100644 index 0000000..adc42d7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/BindDataListExpressionData.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.expression.data; + +import com.yunzhupaas.ureport.build.BindData; + +import java.util.List; + +/** + * @author + * @since 4月28日 + */ +public class BindDataListExpressionData implements ExpressionData { + private List list; + + public BindDataListExpressionData(List list) { + this.list = list; + } + + @Override + public List getData() { + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ExpressionData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ExpressionData.java new file mode 100644 index 0000000..56b7e87 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ExpressionData.java @@ -0,0 +1,9 @@ +package com.yunzhupaas.ureport.expression.data; + +/** + * @author + * @since 1月1日 + */ +public interface ExpressionData { + T getData(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/NoneExpressionData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/NoneExpressionData.java new file mode 100644 index 0000000..0cb9c85 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/NoneExpressionData.java @@ -0,0 +1,12 @@ +package com.yunzhupaas.ureport.expression.data; + +/** + * @author + * @since 5月5日 + */ +public class NoneExpressionData implements ExpressionData { + @Override + public Object getData() { + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectExpressionData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectExpressionData.java new file mode 100644 index 0000000..e344d33 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectExpressionData.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.expression.data; + +/** + * @author + * @since 1月1日 + */ +public class ObjectExpressionData implements ExpressionData { + private Object data; + + public ObjectExpressionData(Object data) { + this.data = data; + } + + @Override + public Object getData() { + return data; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectListExpressionData.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectListExpressionData.java new file mode 100644 index 0000000..10e7d6e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/data/ObjectListExpressionData.java @@ -0,0 +1,20 @@ +package com.yunzhupaas.ureport.expression.data; + +import java.util.List; + +/** + * @author + * @since 1月3日 + */ +public class ObjectListExpressionData implements ExpressionData { + private List list; + + public ObjectListExpressionData(List list) { + this.list = list; + } + + @Override + public List getData() { + return list; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/AssignExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/AssignExpression.java new file mode 100644 index 0000000..593d0e3 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/AssignExpression.java @@ -0,0 +1,57 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 2018年7月13日 + */ +@Getter +@Setter +public class AssignExpression extends BaseExpression { + private String variable; + private Expression expression; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + ExpressionData data = expression.execute(cell, currentCell, context); + Object obj = null; + if (data instanceof ObjectExpressionData) { + ObjectExpressionData d = (ObjectExpressionData) data; + obj = d.getData(); + } else if (data instanceof ObjectListExpressionData) { + ObjectListExpressionData d = (ObjectListExpressionData) data; + obj = d.getData(); + } else if (data instanceof BindDataListExpressionData) { + BindDataListExpressionData dataList = (BindDataListExpressionData) data; + List bindList = dataList.getData(); + if (bindList.size() == 1) { + BindData bindData = bindList.get(0); + obj = bindData.getValue(); + } else { + StringBuilder sb = new StringBuilder(); + for (BindData bd : bindList) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(bd.getValue()); + } + obj = sb.toString(); + } + } + if (obj != null) { + context.putVariable(variable, obj); + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BaseExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BaseExpression.java new file mode 100644 index 0000000..9d5f4c7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BaseExpression.java @@ -0,0 +1,58 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.condition.Condition; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月18日 + */ +@Getter +@Setter +public abstract class BaseExpression implements Expression { + protected String expr; + + @Override + public ExpressionData execute(Cell cell, Cell currentCell, Context context) { + ExpressionData data = compute(cell, currentCell, context); + return data; + } + + protected abstract ExpressionData compute(Cell cell, Cell currentCell, Context context); + + protected List filterCells(Cell cell, Context context, Condition condition, List targetCells) { + if (condition == null) { + return targetCells; + } + List list = new ArrayList<>(); + for (Cell targetCell : targetCells) { + boolean conditionResult = true; + List> dataList = targetCell.getBindData(); + if (dataList == null) { + conditionResult = false; + } else { + for (Map obj : dataList) { + boolean result = condition.filter(cell, targetCell, obj, context); + if (!result) { + conditionResult = false; + break; + } + } + } + if (!conditionResult) { + continue; + } + list.add(targetCell); + } + return list; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BlockExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BlockExpression.java new file mode 100644 index 0000000..0269c59 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BlockExpression.java @@ -0,0 +1,34 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 2018年7月13日 + */ +@Getter +@Setter +public class BlockExpression extends BaseExpression { + private List expressionList; + private Expression returnExpression; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + ExpressionData data = null; + if (expressionList != null) { + for (Expression expr : expressionList) { + data = expr.execute(cell, currentCell, context); + } + } + if (returnExpression != null) { + data = returnExpression.execute(cell, currentCell, context); + } + return data; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BooleanExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BooleanExpression.java new file mode 100644 index 0000000..6f41222 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/BooleanExpression.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2016年12月23日 + */ +public class BooleanExpression extends BaseExpression { + private Boolean value; + + public BooleanExpression(Boolean value) { + this.value = value; + } + + @Override + public ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new ObjectExpressionData(value); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellConditionExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellConditionExpression.java new file mode 100644 index 0000000..5c17a90 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellConditionExpression.java @@ -0,0 +1,44 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.condition.Condition; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.NoneExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月1日 + */ +public class CellConditionExpression extends CellExpression { + protected Condition condition; + + public CellConditionExpression(String cellName, Condition condition) { + super(cellName); + this.condition = condition; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + List targetCells = filterCells(cell, context, condition, + DataUtils.fetchTargetCells(cell, context, cellName)); + if (targetCells.size() > 1) { + List list = new ArrayList<>(); + for (Cell targetCell : targetCells) { + list.add(targetCell.getData()); + } + return new ObjectListExpressionData(list); + } else if (targetCells.size() == 1) { + return new ObjectExpressionData(targetCells.get(0).getData()); + } else { + return new NoneExpressionData(); + } + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellCoordinateExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellCoordinateExpression.java new file mode 100644 index 0000000..8d06951 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellCoordinateExpression.java @@ -0,0 +1,283 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.condition.CellCoordinate; +import com.yunzhupaas.ureport.expression.condition.CellCoordinateSet; +import com.yunzhupaas.ureport.expression.condition.Condition; +import com.yunzhupaas.ureport.expression.condition.CoordinateType; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import com.yunzhupaas.util.StringUtil; +import lombok.Getter; +import lombok.Setter; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author + * @since 1月1日 + */ +@Setter +@Getter +public class CellCoordinateExpression extends CellExpression { + private Condition condition; + private CellCoordinateSet leftCoordinate; + private CellCoordinateSet topCoordinate; + + public CellCoordinateExpression(String cellName) { + super(cellName); + } + + @Override + public boolean supportPaging() { + return false; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + // todo + while (!context.isCellPocessed(cellName)) { + context.getReportBuilder().buildCell(context, null); + } + List leftCellList = buildLeftCells(cell, context); + List topCellList = buildTopCells(cell, context); + List list = new ArrayList<>(); + if (leftCellList == null) { + if (topCellList != null) { + topCellList = filterCells(cell, context, condition, topCellList); + for (Cell c : topCellList) { + list.add(c.getData()); + } + } else { + List cells = context.getReport().getCellsMap().get(cellName); + cells = filterCells(cell, context, condition, cells); + for (Cell c : cells) { + list.add(c.getData()); + } + } + } else { + if (topCellList != null) { + leftCellList = filterCells(cell, context, condition, leftCellList); + topCellList = filterCells(cell, context, condition, topCellList); + for (Cell c : topCellList) { + if (leftCellList.contains(c)) { + list.add(c.getData()); + } + } + } else { + leftCellList = filterCells(cell, context, condition, leftCellList); + for (Cell c : leftCellList) { + list.add(c.getData()); + } + } + } + if (list.size() == 1) { + return new ObjectExpressionData(list.get(0)); + } else { + return new ObjectListExpressionData(list); + } + } + + private List buildLeftCells(Cell cell, Context context) { + if (leftCoordinate == null) { + return null; + } + List cellList = null; + Cell targetLeftCell = null; + int number = cell.getRow().getRowNumber(); + List leftCoordinates = leftCoordinate.getCellCoordinates(); + Map> cellsMap = context.getReport().getCellsMap(); + for (CellCoordinate coordinate : leftCoordinates) { + String name = coordinate.getCellName(); + int position = coordinate.getPosition(); + while (!context.isCellPocessed(name)) { + context.getReportBuilder().buildCell(context, null); + } + if (coordinate.getCoordinateType().equals(CoordinateType.relative)) { + cellList = DataUtils.fetchTargetCells(cell, context, name); + } else { + Cell leftCell = left(cell, name); + cellList = new ArrayList<>(); + if (leftCell != null) { + number = leftCell.getRow().getRowNumber() + position; + for (Cell left : cellsMap.get(name)) { + int rowNumber = left.getRow().getRowNumber(); + if (Objects.equals(rowNumber, number)) { + cellList = leftCell(left, cellsMap, name); + break; + } + int rowSpan = leftCell.getRowSpan(); + if (rowSpan > 0) { + int numberStart = rowNumber; + int numberEnd = rowNumber + rowSpan - 1; + if (numberStart <= number && numberEnd >= number) { + cellList = leftCell(left, cellsMap, name); + break; + } + } + } + } + } + for (Cell leftCell : cellList) { + int rowNumber = leftCell.getRow().getRowNumber(); + if (Objects.equals(rowNumber, number)) { + targetLeftCell = leftCell; + break; + } + int rowSpan = leftCell.getRowSpan(); + if (rowSpan > 0) { + int numberStart = rowNumber; + int numberEnd = numberStart + rowSpan - 1; + if (numberStart <= number && numberEnd >= number) { + targetLeftCell = leftCell; + break; + } + } + } + } + List childCellList = cellsMap.get(cellName) != null ? cellsMap.get(cellName) : new ArrayList<>(); + Set leftCellList = new HashSet<>(); + if (targetLeftCell != null) { + for (Cell childCell : childCellList) { + Cell left = left(childCell, targetLeftCell.getName()); + if (Objects.equals(left, targetLeftCell)) { + leftCellList.add(childCell); + } + } + } + return leftCellList.isEmpty() ? null : new ArrayList<>(leftCellList); + } + + private List buildTopCells(Cell cell, Context context) { + if (topCoordinate == null) { + return null; + } + List cellList = null; + Cell targetTopCell = null; + int number = cell.getColumn().getColumnNumber(); + List topCoordinates = topCoordinate.getCellCoordinates(); + Map> cellsMap = context.getReport().getCellsMap(); + for (CellCoordinate coordinate : topCoordinates) { + String name = coordinate.getCellName(); + int position = coordinate.getPosition(); + while (!context.isCellPocessed(name)) { + context.getReportBuilder().buildCell(context, null); + } + if (coordinate.getCoordinateType().equals(CoordinateType.relative)) { + cellList = DataUtils.fetchTargetCells(cell, context, name); + } else { + Cell topCell = top(cell, name); + cellList = new ArrayList<>(); + if (topCell != null) { + number = topCell.getColumn().getColumnNumber() + position; + for (Cell left : cellsMap.get(name)) { + int columnNumber = left.getColumn().getColumnNumber(); + if (Objects.equals(columnNumber, number)) { + cellList = topCell(left, cellsMap, name); + break; + } + int colSpan = topCell.getColSpan(); + if (colSpan > 0) { + int numberStart = columnNumber; + int childRowNumberEnd = columnNumber + colSpan - 1; + if (numberStart <= number && childRowNumberEnd >= number) { + cellList = topCell(left, cellsMap, name); + break; + } + } + } + } + } + for (Cell topCell : cellList) { + int columnNumber = topCell.getColumn().getColumnNumber(); + if (Objects.equals(columnNumber, number)) { + targetTopCell = topCell; + break; + } + int rowSpan = topCell.getRowSpan(); + if (rowSpan > 0) { + int numberStart = columnNumber; + int numberEnd = numberStart + rowSpan - 1; + if (numberStart <= number && numberEnd >= number) { + targetTopCell = topCell; + break; + } + } + } + } + List childCellList = cellsMap.get(cellName) != null ? cellsMap.get(cellName) : new ArrayList<>(); + Set leftCellList = new HashSet<>(); + if (targetTopCell != null) { + for (Cell childCell : childCellList) { + Cell top = top(childCell, targetTopCell.getName()); + if (Objects.equals(top, targetTopCell)) { + leftCellList.add(childCell); + } + } + } + return leftCellList.isEmpty() ? null : new ArrayList<>(leftCellList); + } + + private List leftCell(Cell cell, Map> cellMap, String cellName) { + List cellList = new ArrayList<>(); + if (cell == null) { + return cellList; + } + if (Objects.equals(cell.getName(), cellName)) { + List cellNameList = cellMap.get(cellName) != null ? cellMap.get(cellName) : new ArrayList<>(); + Map> map = cellNameList.stream().filter(t -> StringUtil.isNotEmpty(t.getLeftGroupId())) + .collect(Collectors.groupingBy(Cell::getLeftGroupId)); + if (StringUtil.isNotEmpty(cell.getLeftGroupId())) { + if (map.get(cell.getLeftGroupId()) != null) { + cellList.addAll(map.get(cell.getLeftGroupId())); + } + } + return cellList; + } + return leftCell(cell.getLeftParentCell(), cellMap, cellName); + } + + private List topCell(Cell cell, Map> cellMap, String cellName) { + List cellList = new ArrayList<>(); + if (cell == null) { + return cellList; + } + if (Objects.equals(cell.getName(), cellName)) { + List cellNameList = cellMap.get(cellName) != null ? cellMap.get(cellName) : new ArrayList<>(); + Map> map = cellNameList.stream().filter(t -> StringUtil.isNotEmpty(t.getTopGroupId())) + .collect(Collectors.groupingBy(Cell::getTopGroupId)); + if (StringUtil.isNotEmpty(cell.getTopGroupId())) { + if (map.get(cell.getTopGroupId()) != null) { + cellList.addAll(map.get(cell.getTopGroupId())); + } + } + return cellList; + } + return topCell(cell.getTopParentCell(), cellMap, cellName); + } + + private Cell top(Cell cell, String cellName) { + if (cell == null) { + return null; + } + if (Objects.equals(cell.getName(), cellName)) { + return cell; + } + return top(cell.getTopParentCell(), cellName); + } + + private Cell left(Cell cell, String cellName) { + if (cell == null) { + return null; + } + if (Objects.equals(cell.getName(), cellName)) { + return cell; + } + return left(cell.getLeftParentCell(), cellName); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellDataExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellDataExpression.java new file mode 100644 index 0000000..a9ad7b8 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellDataExpression.java @@ -0,0 +1,33 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.NoneExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 7月11日 + */ +public class CellDataExpression extends BaseExpression { + private String property; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + List> bindDataList = cell.getBindData(); + if (bindDataList == null || bindDataList.size() == 0) { + return new NoneExpressionData(); + } + Map obj = bindDataList.get(0); + Object data = obj.get(property); + return new ObjectExpressionData(data); + } + + public void setProperty(String property) { + this.property = property; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellExpression.java new file mode 100644 index 0000000..f95ec95 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellExpression.java @@ -0,0 +1,49 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.NoneExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月1日 + */ +@Setter +@Getter +public class CellExpression extends BaseExpression { + protected String cellName; + + public CellExpression(String cellName) { + this.cellName = cellName; + } + + public boolean supportPaging() { + return true; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + List targetCells = DataUtils.fetchTargetCells(cell, context, cellName); + if (targetCells.size() > 1) { + List list = new ArrayList<>(); + for (Cell targetCell : targetCells) { + list.add(targetCell.getData()); + } + return new ObjectListExpressionData(list); + } else if (targetCells.size() == 1) { + return new ObjectExpressionData(targetCells.get(0).getData()); + } else { + return new NoneExpressionData(); + } + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellObjectExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellObjectExpression.java new file mode 100644 index 0000000..bb5f2bc --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellObjectExpression.java @@ -0,0 +1,39 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 1月20日 + */ +public class CellObjectExpression extends BaseExpression { + private String property; + + public CellObjectExpression(String property) { + this.property = property; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + while (!context.isCellPocessed(cell.getName())) { + context.getReportBuilder().buildCell(context, null); + } + if (StringUtils.isNotBlank(property)) { + List> bindData = cell.getBindData(); + Object obj = null; + if (bindData != null && bindData.size() > 0) { + obj = bindData.get(0).get(property); + } + return new ObjectExpressionData(obj); + } + return new ObjectExpressionData(cell); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellPositionExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellPositionExpression.java new file mode 100644 index 0000000..7966c27 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellPositionExpression.java @@ -0,0 +1,113 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 4月5日 + */ +public class CellPositionExpression extends CellExpression { + + public CellPositionExpression(String cellName) { + super(cellName); + } + + @Override + public boolean supportPaging() { + return false; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + // todo + List cellList = new ArrayList<>(); + Cell targetCell = leftCell(cell, cellName); + if (targetCell == null) { + targetCell = topCell(cell, cellName); + } + if (targetCell != null && targetCell.getRowChildrenCellsMap().get(cellName) != null) { + cellList.addAll(targetCell.getRowChildrenCellsMap().get(cellName)); + } else { + if (context.getReport().getCellsMap().get(cellName) != null) { + cellList.addAll(context.getReport().getCellsMap().get(cellName)); + } + } + int index = -1; + if (cellList.isEmpty()) { + return new ObjectExpressionData(index); + } + int rowNumber = cell.getRow().getRowNumber(); + for (int i = 0; i < cellList.size(); i++) { + Cell target = cellList.get(i); + if (target.getRow() == cell.getRow()) { + index = i; + break; + } + int rowSpan = target.getRowSpan(); + if (rowSpan > 0) { + int targetRowStart = target.getRow().getRowNumber(); + int targetRowEnd = targetRowStart + rowSpan - 1; + if (targetRowStart <= rowNumber && targetRowEnd >= rowNumber) { + index = i; + break; + } + } + } + if (index > -1) { + index++; + return new ObjectExpressionData(index); + } + int colNumber = cell.getColumn().getColumnNumber(); + for (int i = 0; i < cellList.size(); i++) { + Cell target = cellList.get(i); + if (target.getColumn() == cell.getColumn()) { + index = i; + break; + } + int colSpan = target.getColSpan(); + if (colSpan > 0) { + int targetColStart = target.getColumn().getColumnNumber(); + int targetColEnd = targetColStart + colSpan - 1; + if (targetColStart <= colNumber && targetColEnd >= colNumber) { + index = i; + break; + } + } + } + index++; + return new ObjectExpressionData(index); + } + + private Cell leftCell(Cell cell, String cellName) { + Cell leftParentCell = cell.getLeftParentCell(); + if (leftParentCell == null) { + return null; + } + List cellNameList = leftParentCell.getNewCellNames() != null ? leftParentCell.getNewCellNames() + : new ArrayList<>(); + if (cellNameList.contains(cellName)) { + return leftParentCell; + } + return leftCell(leftParentCell, cellName); + } + + private Cell topCell(Cell cell, String cellName) { + Cell topParentCell = cell.getTopParentCell(); + if (topParentCell == null) { + return null; + } + List cellNameList = topParentCell.getNewCellNames() != null ? topParentCell.getNewCellNames() + : new ArrayList<>(); + if (cellNameList.contains(cellName)) { + return topParentCell; + } + return topCell(topParentCell, cellName); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellValueExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellValueExpression.java new file mode 100644 index 0000000..4ac338c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/CellValueExpression.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 7月11日 + */ +public class CellValueExpression extends BaseExpression { + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new ObjectExpressionData(cell.getData()); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ConditionList.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ConditionList.java new file mode 100644 index 0000000..b0a7b6d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ConditionList.java @@ -0,0 +1,49 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class ConditionList { + private List expressionConditions; + private List joins; + + public ConditionList(List expressionConditions, List joins) { + this.expressionConditions = expressionConditions; + this.joins = joins; + } + + public boolean eval(Context context, Cell cell, Cell currentCell) { + if (expressionConditions.size() == 1) { + return expressionConditions.get(0).eval(context, cell, currentCell); + } + for (int i = 0; i < expressionConditions.size(); i++) { + ExpressionCondition expressionCondition = expressionConditions.get(i); + boolean result = expressionCondition.eval(context, cell, currentCell); + Join join = null; + if (i < joins.size()) { + join = joins.get(i); + } + if (join == null) { + return result; + } else { + if (join.equals(Join.and) && !result) { + return false; + } + if (join.equals(Join.or) && result) { + return true; + } + } + } + return true; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseExpression.java new file mode 100644 index 0000000..ee7dc69 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseExpression.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class ElseExpression extends BaseExpression { + private BlockExpression expression; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return expression.execute(cell, currentCell, context); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseIfExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseIfExpression.java new file mode 100644 index 0000000..585706a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ElseIfExpression.java @@ -0,0 +1,28 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class ElseIfExpression extends BaseExpression { + private ExpressionConditionList expressionConditionList; + + private BlockExpression expression; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return expression.execute(cell, currentCell, context); + } + + public boolean conditionsEval(Cell cell, Cell currentCell, Context context) { + return expressionConditionList.eval(context, cell, currentCell); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Expression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Expression.java new file mode 100644 index 0000000..1a23cf6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Expression.java @@ -0,0 +1,15 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.io.Serializable; + +/** + * @author + * @since 2016年11月18日 + */ +public interface Expression extends Serializable { + ExpressionData execute(Cell cell, Cell currentCell, Context context); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionCondition.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionCondition.java new file mode 100644 index 0000000..65274c7 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionCondition.java @@ -0,0 +1,76 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.*; +import com.yunzhupaas.ureport.expression.util.ExpressionUtils; +import com.yunzhupaas.ureport.expression.util.Op; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class ExpressionCondition { + private Expression left; + private Op op; + private Expression right; + + public ExpressionCondition(Expression left, Op op, Expression right) { + this.left = left; + this.op = op; + this.right = right; + } + + public boolean eval(Context context, Cell cell, Cell currentCell) { + ExpressionData leftData = left.execute(cell, currentCell, context); + ExpressionData rightData = right.execute(cell, currentCell, context); + Object leftObj = getData(leftData); + Object rightObj = getData(rightData); + return ExpressionUtils.conditionEval(op, leftObj, rightObj); + } + + private Object getData(ExpressionData data) { + if (data instanceof ObjectExpressionData) { + ObjectExpressionData objData = (ObjectExpressionData) data; + return objData.getData(); + } else if (data instanceof ObjectListExpressionData) { + ObjectListExpressionData exprData = (ObjectListExpressionData) data; + List list = exprData.getData(); + StringBuffer sb = new StringBuffer(); + for (Object obj : list) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(obj); + } + return sb.toString(); + } else if (data instanceof NoneExpressionData) { + NoneExpressionData noneData = (NoneExpressionData) data; + return noneData.getData(); + } else if (data instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) data; + List list = bindDataList.getData(); + if (list.size() == 1) { + return list.get(0).getValue(); + } else { + StringBuffer sb = new StringBuffer(); + for (BindData bindData : list) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(bindData.getValue()); + } + return sb.toString(); + } + } + return ""; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionConditionList.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionConditionList.java new file mode 100644 index 0000000..8e4a090 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ExpressionConditionList.java @@ -0,0 +1,49 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class ExpressionConditionList { + private List conditions; + private List joins; + + public ExpressionConditionList(List expressionConditions, List joins) { + this.conditions = expressionConditions; + this.joins = joins; + } + + public boolean eval(Context context, Cell cell, Cell currentCell) { + if (conditions.size() == 1) { + return conditions.get(0).eval(context, cell, currentCell); + } + for (int i = 0; i < conditions.size(); i++) { + ExpressionCondition expressionCondition = conditions.get(i); + boolean result = expressionCondition.eval(context, cell, currentCell); + Join join = null; + if (i < joins.size()) { + join = joins.get(i); + } + if (join == null) { + return result; + } else { + if (join.equals(Join.and) && !result) { + return false; + } + if (join.equals(Join.or) && result) { + return true; + } + } + } + return true; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FromToExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FromToExpression.java new file mode 100644 index 0000000..751bab0 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FromToExpression.java @@ -0,0 +1,50 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月1日 + */ +public class FromToExpression extends BaseExpression { + private BaseExpression fromExpression; + private BaseExpression toExpression; + + public FromToExpression(BaseExpression fromExpression, BaseExpression toExpression) { + this.fromExpression = fromExpression; + this.toExpression = toExpression; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + Object fromData = fromExpression.execute(cell, currentCell, context); + Object toData = toExpression.execute(cell, currentCell, context); + int from = convertFloatData(fromData), to = convertFloatData(toData); + List list = new ArrayList<>(); + for (int i = from; i <= to; i++) { + list.add(i); + } + return new ObjectListExpressionData(list); + } + + private int convertFloatData(Object data) { + int value = 0; + if (data instanceof ObjectExpressionData) { + Object obj = ((ObjectExpressionData) data).getData(); + try { + value = DataUtils.toBigDecimal(String.valueOf(obj)).intValue(); + } catch (Exception e) { + } + } + return value; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FunctionExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FunctionExpression.java new file mode 100644 index 0000000..d13cf77 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/FunctionExpression.java @@ -0,0 +1,55 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.google.common.collect.ImmutableMap; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.expression.function.*; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年11月18日 + */ +@Setter +@Getter +public class FunctionExpression extends BaseExpression { + private String name; + private List expressions; + + @Override + public ExpressionData compute(Cell cell, Cell currentCell, Context context) { + Map functions = ImmutableMap.of( + FunctionType.avg.name(), new AvgFunction(), + FunctionType.column.name(), new ColumnFunction(), + FunctionType.count.name(), new CountFunction(), + FunctionType.max.name(), new MaxFunction(), + FunctionType.min.name(), new MinFunction(), + FunctionType.row.name(), new RowFunction(), + FunctionType.sum.name(), new SumFunction()); + Function targetFunction = functions.get(name); + if (targetFunction == null) { + return new ObjectExpressionData(""); + } + List dataList = new ArrayList<>(); + if (expressions != null) { + for (BaseExpression expr : expressions) { + ExpressionData data = expr.execute(cell, currentCell, context); + dataList.add(data); + } + } + Object obj = targetFunction.execute(dataList, context, currentCell); + if (obj instanceof List) { + return new ObjectListExpressionData((List) obj); + } + return new ObjectExpressionData(obj); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IfExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IfExpression.java new file mode 100644 index 0000000..946cb4a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IfExpression.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author + * @since 1月16日 + */ +@Getter +@Setter +public class IfExpression extends BaseExpression { + private ExpressionConditionList expressionConditionList; + private BlockExpression expression; + private List elseIfExpressions; + private ElseExpression elseExpression; + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + if (expressionConditionList != null) { + boolean result = expressionConditionList.eval(context, cell, currentCell); + if (result) { + return expression.execute(cell, currentCell, context); + } + } + if (elseIfExpressions != null) { + for (ElseIfExpression elseIfExpr : elseIfExpressions) { + if (elseIfExpr.conditionsEval(cell, currentCell, context)) { + return elseIfExpr.execute(cell, currentCell, context); + } + } + } + if (elseExpression != null) { + return elseExpression.execute(cell, currentCell, context); + } + return new ObjectExpressionData(null); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IntegerExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IntegerExpression.java new file mode 100644 index 0000000..a9d2736 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/IntegerExpression.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2016年12月23日 + */ +public class IntegerExpression extends BaseExpression { + private Integer value; + + public IntegerExpression(Integer value) { + this.value = value; + } + + @Override + public ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new ObjectExpressionData(value); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Join.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Join.java new file mode 100644 index 0000000..0dd190e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/Join.java @@ -0,0 +1,16 @@ +package com.yunzhupaas.ureport.expression.expr; + +/** + * @author + * @since 2016年12月1日 + */ +public enum Join { + and, or; + + public static Join parse(String join) { + if (join.equals("and") || join.equals("&&")) { + return and; + } + return or; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/JoinExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/JoinExpression.java new file mode 100644 index 0000000..e21f25c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/JoinExpression.java @@ -0,0 +1,82 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.expression.util.Operator; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月15日 + */ +@Getter +@Setter +public class JoinExpression extends BaseExpression { + private List operators; + private List expressions; + + public JoinExpression(List operators, List expressions) { + this.operators = operators; + this.expressions = expressions; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + if (expressions.size() == 1) { + return expressions.get(0).compute(cell, currentCell, context); + } + List list = new ArrayList<>(); + for (int i = 0; i < expressions.size(); i++) { + BaseExpression expression = expressions.get(i); + ExpressionData data = expression.execute(cell, currentCell, context); + Object obj = null; + if (data instanceof ObjectExpressionData) { + ObjectExpressionData d = (ObjectExpressionData) data; + obj = d.getData(); + } else if (data instanceof ObjectListExpressionData) { + ObjectListExpressionData d = (ObjectListExpressionData) data; + obj = d.getData(); + } else if (data instanceof BindDataListExpressionData) { + BindDataListExpressionData dataList = (BindDataListExpressionData) data; + List bindList = dataList.getData(); + if (bindList.size() == 1) { + BindData bindData = bindList.get(0); + obj = bindData.getValue(); + } else { + StringBuilder sb = new StringBuilder(); + for (BindData bd : bindList) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(bd.getValue()); + } + obj = sb.toString(); + } + } + + list.add(obj); + } + String str = null; + for (int i = 0; i < list.size(); i++) { + Object data = list.get(i); + if (str == null) { + str = "" + data; + } else { + Operator op = operators.get(i - 1); + str += "" + op + data; + } + } + // todo + Object obj = context.evalExpr(str); + return new ObjectExpressionData(obj); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NullExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NullExpression.java new file mode 100644 index 0000000..d6e53a2 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NullExpression.java @@ -0,0 +1,18 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.NoneExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2016年12月23日 + */ +public class NullExpression extends BaseExpression { + + @Override + public ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new NoneExpressionData(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NumberExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NumberExpression.java new file mode 100644 index 0000000..f62a944 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/NumberExpression.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.math.BigDecimal; + +/** + * @author + * @since 2016年12月23日 + */ +public class NumberExpression extends BaseExpression { + private BigDecimal value; + + public NumberExpression(BigDecimal value) { + this.value = value; + } + + @Override + public ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new ObjectExpressionData(value.floatValue()); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ParenExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ParenExpression.java new file mode 100644 index 0000000..06c5ea8 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/ParenExpression.java @@ -0,0 +1,16 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.expression.util.Operator; + +import java.util.List; + +/** + * @author + * @since 2016年11月18日 + */ +public class ParenExpression extends JoinExpression { + + public ParenExpression(List operators, List expressions) { + super(operators, expressions); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/RelativeCellExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/RelativeCellExpression.java new file mode 100644 index 0000000..92832a9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/RelativeCellExpression.java @@ -0,0 +1,54 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月21日 + */ +public class RelativeCellExpression extends CellExpression { + public RelativeCellExpression(String cellName) { + super(cellName); + } + + @Override + public boolean supportPaging() { + return false; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + List targetCells = DataUtils.fetchTargetCells(currentCell, context, cellName); + int size = targetCells.size(); + if (size == 0) { + return new ObjectListExpressionData(new ArrayList<>()); + } else if (size == 1) { + return new ObjectExpressionData(targetCells.get(0).getData()); + } else { + Cell targetCell = null; + for (Cell c : targetCells) { + if (c.getRow() == currentCell.getRow() || c.getColumn() == currentCell.getColumn()) { + targetCell = c; + break; + } + } + if (targetCell != null) { + return new ObjectExpressionData(targetCell.getData()); + } else { + List list = new ArrayList<>(); + for (Cell c : targetCells) { + list.add(c.getData()); + } + return new ObjectListExpressionData(list); + } + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/StringExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/StringExpression.java new file mode 100644 index 0000000..ab2439d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/StringExpression.java @@ -0,0 +1,23 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2016年12月23日 + */ +public class StringExpression extends BaseExpression { + private String text; + + public StringExpression(String text) { + this.text = text; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + return new ObjectExpressionData(text); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/VariableExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/VariableExpression.java new file mode 100644 index 0000000..ea3a489 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/VariableExpression.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +/** + * @author + * @since 2018年7月15日 + */ +public class VariableExpression extends BaseExpression { + private String text; + + public VariableExpression(String text) { + this.text = text; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + Object obj = context.getVariable(text); + return new ObjectExpressionData(obj); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/WholeCellExpression.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/WholeCellExpression.java new file mode 100644 index 0000000..dbd627a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/expr/WholeCellExpression.java @@ -0,0 +1,50 @@ +package com.yunzhupaas.ureport.expression.expr; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.condition.Condition; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 4月6日 + */ +@Getter +@Setter +public class WholeCellExpression extends CellExpression { + private Condition expressionCondition; + + public WholeCellExpression(String cellName) { + super(cellName); + } + + @Override + public boolean supportPaging() { + return false; + } + + @Override + protected ExpressionData compute(Cell cell, Cell currentCell, Context context) { + while (!context.isCellPocessed(cellName)) { + context.getReportBuilder().buildCell(context, null); + } + List cells = context.getReport().getCellsMap().get(cellName); + List list = new ArrayList<>(); + for (Cell c : cells) { + Object obj = c.getData(); + list.add(obj); + } + if (list.size() == 1) { + return new ObjectExpressionData(list.get(0)); + } else { + return new ObjectListExpressionData(list); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/AvgFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/AvgFunction.java new file mode 100644 index 0000000..ca86a1e --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/AvgFunction.java @@ -0,0 +1,73 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 1月20日 + */ +public class AvgFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + List list = new ArrayList<>(); + for (ExpressionData exprData : dataList) { + if (exprData instanceof ObjectListExpressionData) { + ObjectListExpressionData listExpr = (ObjectListExpressionData) exprData; + List objectList = listExpr.getData() != null ? listExpr.getData() : new ArrayList<>(); + for (Object obj : objectList) { + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof ObjectExpressionData) { + Object obj = exprData.getData(); + if (obj != null && StringUtils.isNotBlank(obj.toString())) { + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) exprData; + List objectList = bindDataList.getData(); + for (BindData bindData : objectList) { + Object obj = bindData.getValue(); + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } + } + BigDecimal result = list.stream().reduce(BigDecimal.YUNZHUPAAS, BigDecimal::add); + if (!list.isEmpty()) { + result = result.divide(new BigDecimal(list.size()), 8, BigDecimal.ROUND_HALF_UP); + } + return result; + } + + @Override + public String name() { + return FunctionType.avg.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/ColumnFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/ColumnFunction.java new file mode 100644 index 0000000..364f684 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/ColumnFunction.java @@ -0,0 +1,26 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Column; + +import java.util.List; + +/** + * @author + * @since 4月25日 + */ +public class ColumnFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + Column col = currentCell.getColumn(); + return col.getColumnNumber(); + } + + @Override + public String name() { + return FunctionType.column.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/CountFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/CountFunction.java new file mode 100644 index 0000000..b3e05d4 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/CountFunction.java @@ -0,0 +1,44 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月27日 + */ +public class CountFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + List list = new ArrayList<>(); + for (ExpressionData exprData : dataList) { + if (exprData instanceof ObjectListExpressionData) { + ObjectListExpressionData listExpr = (ObjectListExpressionData) exprData; + List objectList = listExpr.getData() != null ? listExpr.getData() : new ArrayList<>(); + list.addAll(objectList); + } else if (exprData instanceof ObjectExpressionData) { + Object obj = exprData.getData(); + list.add(obj); + } else if (exprData instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) exprData; + List objectList = bindDataList.getData(); + list.addAll(objectList); + } + } + return list.size(); + } + + @Override + public String name() { + return FunctionType.count.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/Function.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/Function.java new file mode 100644 index 0000000..ea934d6 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/Function.java @@ -0,0 +1,17 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; + +import java.util.List; + +/** + * @author + * @since 2016年12月27日 + */ +public interface Function { + Object execute(List dataList, Context context, Cell currentCell); + + String name(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/FunctionType.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/FunctionType.java new file mode 100644 index 0000000..6933c66 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/FunctionType.java @@ -0,0 +1,11 @@ +package com.yunzhupaas.ureport.expression.function; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/11/13 下午4:04 + */ +public enum FunctionType { + avg, column, row, count, max, min, sum +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MaxFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MaxFunction.java new file mode 100644 index 0000000..685678a --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MaxFunction.java @@ -0,0 +1,73 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月27日 + */ +public class MaxFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + List list = new ArrayList<>(); + for (ExpressionData exprData : dataList) { + if (exprData instanceof ObjectListExpressionData) { + ObjectListExpressionData listExpr = (ObjectListExpressionData) exprData; + List objectList = listExpr.getData() != null ? listExpr.getData() : new ArrayList<>(); + for (Object obj : objectList) { + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof ObjectExpressionData) { + Object obj = exprData.getData(); + if (obj != null && StringUtils.isNotBlank(obj.toString())) { + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) exprData; + List objectList = bindDataList.getData(); + for (BindData bindData : objectList) { + Object obj = bindData.getValue(); + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } + } + if (list.isEmpty()) { + list.add(new BigDecimal(0)); + } + BigDecimal result = list.stream().reduce(list.get(0), BigDecimal::max); + return result; + } + + @Override + public String name() { + return FunctionType.max.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MinFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MinFunction.java new file mode 100644 index 0000000..770a5b9 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/MinFunction.java @@ -0,0 +1,73 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月27日 + */ +public class MinFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + List list = new ArrayList<>(); + for (ExpressionData exprData : dataList) { + if (exprData instanceof ObjectListExpressionData) { + ObjectListExpressionData listExpr = (ObjectListExpressionData) exprData; + List objectList = listExpr.getData() != null ? listExpr.getData() : new ArrayList<>(); + for (Object obj : objectList) { + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof ObjectExpressionData) { + Object obj = exprData.getData(); + if (obj != null && StringUtils.isNotBlank(obj.toString())) { + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) exprData; + List objectList = bindDataList.getData(); + for (BindData bindData : objectList) { + Object obj = bindData.getValue(); + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } + } + if (list.isEmpty()) { + list.add(new BigDecimal(0)); + } + BigDecimal result = list.stream().reduce(list.get(0), BigDecimal::min); + return result; + } + + @Override + public String name() { + return FunctionType.min.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/RowFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/RowFunction.java new file mode 100644 index 0000000..2921bbd --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/RowFunction.java @@ -0,0 +1,25 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Row; + +import java.util.List; + +/** + * @author + * @since 4月25日 + */ +public class RowFunction implements Function { + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + Row row = currentCell.getRow(); + return row.getRowNumber(); + } + + @Override + public String name() { + return FunctionType.row.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/SumFunction.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/SumFunction.java new file mode 100644 index 0000000..8755a64 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/function/SumFunction.java @@ -0,0 +1,70 @@ +package com.yunzhupaas.ureport.expression.function; + +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.expression.data.BindDataListExpressionData; +import com.yunzhupaas.ureport.expression.data.ExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectExpressionData; +import com.yunzhupaas.ureport.expression.data.ObjectListExpressionData; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.utils.DataUtils; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年12月27日 + */ +public class SumFunction implements Function { + + @Override + public Object execute(List dataList, Context context, Cell currentCell) { + List list = new ArrayList<>(); + for (ExpressionData exprData : dataList) { + if (exprData instanceof ObjectListExpressionData) { + ObjectListExpressionData listExpr = (ObjectListExpressionData) exprData; + List objectList = listExpr.getData() != null ? listExpr.getData() : new ArrayList<>(); + for (Object obj : objectList) { + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof ObjectExpressionData) { + Object obj = exprData.getData(); + if (obj != null && StringUtils.isNotBlank(obj.toString())) { + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } else if (exprData instanceof BindDataListExpressionData) { + BindDataListExpressionData bindDataList = (BindDataListExpressionData) exprData; + List objectList = bindDataList.getData(); + for (BindData bindData : objectList) { + Object obj = bindData.getValue(); + if (obj == null || StringUtils.isBlank(obj.toString())) { + continue; + } + BigDecimal bigData = DataUtils.toBigDecimal(obj); + if (bigData != null) { + list.add(bigData); + } + } + } + } + BigDecimal result = list.stream().reduce(BigDecimal.YUNZHUPAAS, BigDecimal::add); + return result; + } + + @Override + public String name() { + return FunctionType.sum.name(); + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ElCompute.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ElCompute.java new file mode 100644 index 0000000..141d04d --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ElCompute.java @@ -0,0 +1,157 @@ +package com.yunzhupaas.ureport.expression.util; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Stack; + +/** + * @author + * @since 2018年6月28日 + */ +public class ElCompute { + private Stack dataStack = new Stack<>(); + private Stack operateStack = new Stack<>(); + + public Object doCompute(String expr) { + init(expr); + return dataStack.pop(); + } + + private void init(String expr) { + StringBuilder dataSb = new StringBuilder(); + char prevChar = ' '; + for (int i = 0; i < expr.length(); i++) { + char c = expr.charAt(i); + if (prevChar == '\\') { + dataSb.append(c); + prevChar = c; + continue; + } + switch (c) { + case '+': + doOp(dataSb, c, prevChar); + break; + case '-': + doOp(dataSb, c, prevChar); + break; + case '*': + doOp(dataSb, c, prevChar); + break; + case '/': + doOp(dataSb, c, prevChar); + break; + case '%': + doOp(dataSb, c, prevChar); + break; + case '(': + operateStack.push(c); + break; + case ')': + addDataStack(dataSb); + doCalculate(1); + break; + default: + dataSb.append(c); + } + prevChar = c; + } + if (dataSb.length() > 0) { + addDataStack(dataSb); + } + doCalculate(0); + } + + private void doOp(StringBuilder dataSb, char op, char prevChar) { + if (dataSb.length() == 0 && prevChar != ')' && prevChar != '\"') { + dataSb.append(op); + } else { + addDataStack(dataSb); + if (op == '+' || op == '-') { + doCalculate(0); + } else { + doCalculate(2); + } + operateStack.push(op); + } + } + + private void doCalculate(int current) { + if (operateStack.empty()) { + return; + } + char prevOp = operateStack.peek(); + if (prevOp == '(') { + operateStack.pop(); + return; + } + if (current == 0 || current == 1) { + char op = operateStack.pop(); + do { + Object right = dataStack.pop(); + Object left = dataStack.pop(); + Object result = calculate(left, op, right); + dataStack.push(result); + if (operateStack.isEmpty()) { + break; + } + op = operateStack.pop(); + } while (op != '('); + } else if (current == 2) { + while (prevOp == '*' || prevOp == '/' || prevOp == '%') { + Object right = dataStack.pop(); + Object left = dataStack.pop(); + char op = operateStack.pop(); + Object result = calculate(left, op, right); + dataStack.push(result); + if (operateStack.isEmpty()) { + break; + } + prevOp = operateStack.peek(); + if (prevOp == '(') { + break; + } + } + } + } + + private Object calculate(Object left, char op, Object right) { + if ((op == '*' || op == '/' || op == '%' || op == '-')) { + if (right instanceof String || left instanceof String) { + return left.toString() + op + right.toString(); + } + BigDecimal b1 = (BigDecimal) left; + BigDecimal b2 = (BigDecimal) right; + if (op == '*') { + return b1.multiply(b2); + } else if (op == '/') { + return b1.divide(b2, 10, RoundingMode.HALF_UP).stripTrailingZeros(); + } else if (op == '%') { + return b1.divideAndRemainder(b2)[1]; + } else if (op == '-') { + return b1.subtract(b2); + } + } else if (op == '+') { + if (right instanceof String || left instanceof String) { + return left.toString() + right.toString(); + } else { + BigDecimal b1 = (BigDecimal) left; + BigDecimal b2 = (BigDecimal) right; + return b1.add(b2); + } + } + return new BigDecimal(0); + } + + private void addDataStack(StringBuilder dataSb) { + if (dataSb.length() == 0) + return; + String data = dataSb.toString(); + dataSb.setLength(0); + try { + BigDecimal bd = new BigDecimal(data); + dataStack.push(bd); + } catch (Exception ex) { + dataStack.push(data); + } + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionUtils.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionUtils.java new file mode 100644 index 0000000..a2c6a24 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionUtils.java @@ -0,0 +1,77 @@ +package com.yunzhupaas.ureport.expression.util; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.yunzhupaas.ureport.expression.antlr.ReportLexer; +import com.yunzhupaas.ureport.expression.antlr.ReportListener; +import com.yunzhupaas.ureport.expression.antlr.ReportParser; +import com.yunzhupaas.ureport.expression.assertor.*; +import com.yunzhupaas.ureport.expression.builder.*; +import com.yunzhupaas.ureport.expression.expr.Expression; +import lombok.Getter; +import lombok.Setter; +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; + +import java.util.List; +import java.util.Map; + +/** + * @author + * @since 2016年12月24日 + */ +@Getter +@Setter +public class ExpressionUtils { + public static final String EXPR_PREFIX = "${"; + public static final String EXPR_SUFFIX = "}"; + private static ExpressionVisitor exprVisitor; + private static Map assertorsMap = ImmutableMap.of( + Op.Equals, new EqualsAssertor(), + Op.EqualsGreatThen, new EqualsGreatThenAssertor(), + Op.EqualsLessThen, new EqualsLessThenAssertor(), + Op.GreatThen, new GreatThenAssertor(), + Op.LessThen, new LessThenAssertor(), + Op.NotEquals, new NotEqualsAssertor(), + Op.In, new InAssertor(), + Op.NotIn, new NotInAssertor(), + Op.Like, new LikeAssertor()); + private static List expressionBuilders = ImmutableList.of( + new StringExpressionBuilder(), + new VariableExpressionBuilder(), + new BooleanExpressionBuilder(), + new IntegerExpressionBuilder(), + new FunctionExpressionBuilder(), + new NumberExpressionBuilder(), + new CellPositionExpressionBuilder(), + new RelativeCellExpressionBuilder(), + new SetExpressionBuilder(), + new CellObjectExpressionBuilder(), + new NullExpressionBuilder(), + new CurrentCellValueExpressionBuilder(), + new CurrentCellDataExpressionBuilder()); + + public static boolean conditionEval(Op op, Object left, Object right) { + Assertor assertor = assertorsMap.get(op); + boolean result = assertor.eval(left, right); + return result; + } + + public static Expression parseExpression(String text) { + ANTLRInputStream antlrInputStream = new ANTLRInputStream(text); + ReportLexer lexer = new ReportLexer(antlrInputStream); + CommonTokenStream tokenStream = new CommonTokenStream(lexer); + ReportParser parser = new ReportParser(tokenStream); + ReportListener errorListener = new ReportListener(); + parser.addErrorListener(errorListener); + exprVisitor = new ExpressionVisitor(expressionBuilders); + Expression expression = exprVisitor.visitEntry(parser.entry()); + String error = errorListener.getErrorMessage(); + return error == null ? expression : null; + } + + public static ExpressionVisitor getExprVisitor() { + return exprVisitor; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionVisitor.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionVisitor.java new file mode 100644 index 0000000..dffee95 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/ExpressionVisitor.java @@ -0,0 +1,323 @@ +package com.yunzhupaas.ureport.expression.util; + +import com.yunzhupaas.ureport.expression.antlr.ReportParser.*; +import com.yunzhupaas.ureport.expression.antlr.ReportVisitor; +import com.yunzhupaas.ureport.expression.builder.ExpressionBuilder; +import com.yunzhupaas.ureport.expression.expr.*; +import org.antlr.v4.runtime.tree.TerminalNode; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author + * @since 2016年11月18日 + */ +public class ExpressionVisitor extends ReportVisitor { + private List expressionBuilders; + + public ExpressionVisitor(List expressionBuilders) { + this.expressionBuilders = expressionBuilders; + } + + @Override + public Expression visitEntry(EntryContext ctx) { + StringBuilder sb = new StringBuilder(); + List exprs = ctx.expression(); + List list = new ArrayList<>(); + for (ExpressionContext exprContext : exprs) { + sb.append(exprContext.getText()); + Expression expr = visitExpression(exprContext); + list.add(expr); + } + BlockExpression block = new BlockExpression(); + block.setExpressionList(list); + block.setExpr(sb.toString()); + return block; + } + + @Override + public Expression visitExpression(ExpressionContext ctx) { + ExprCompositeContext exprCompositeContext = ctx.exprComposite(); + IfExprContext ifExprContext = ctx.ifExpr(); + CaseExprContext caseExprContext = ctx.caseExpr(); + VariableAssignContext assignCtx = ctx.variableAssign(); + ReturnExprContext returnCtx = ctx.returnExpr(); + if (exprCompositeContext != null) { + return parseExprComposite(exprCompositeContext); + } else if (ifExprContext != null) { + IfExpression expr = parseIfExprContext(ifExprContext); + return expr; + } else if (caseExprContext != null) { + IfExpression expr = parseCaseExprContext(caseExprContext); + return expr; + } else if (assignCtx != null) { + AssignExpression expr = new AssignExpression(); + expr.setExpr(assignCtx.getText()); + expr.setVariable(assignCtx.variable().Identifier().getText()); + expr.setExpression(parseItemContext(assignCtx.item())); + return expr; + } else if (returnCtx != null) { + return parseExpr(returnCtx.expr()); + } + return null; + } + + private Expression parseExprComposite(ExprCompositeContext exprCompositeContext) { + if (exprCompositeContext instanceof SingleExprCompositeContext) { + SingleExprCompositeContext singleExprCompositeContext = (SingleExprCompositeContext) exprCompositeContext; + ExprContext exprContext = singleExprCompositeContext.expr(); + return parseExpr(exprContext); + } else if (exprCompositeContext instanceof ParenExprCompositeContext) { + ParenExprCompositeContext parenExprCompositeContext = (ParenExprCompositeContext) exprCompositeContext; + ExprCompositeContext childExprCompositeContext = parenExprCompositeContext.exprComposite(); + return parseExprComposite(childExprCompositeContext); + } else if (exprCompositeContext instanceof TernaryExprCompositeContext) { + TernaryExprCompositeContext ternaryExprCompositeContext = (TernaryExprCompositeContext) exprCompositeContext; + TernaryExprContext ternaryExprContext = ternaryExprCompositeContext.ternaryExpr(); + List ifConditionContexts = ternaryExprContext.ifCondition(); + IfExpression expr = new IfExpression(); + expr.setExpressionConditionList(parseCondtionList(ifConditionContexts, ternaryExprContext.join())); + BlockContext firstBlockContext = ternaryExprContext.block(0); + expr.setExpression(parseBlock(firstBlockContext)); + BlockContext secondBlockContext = ternaryExprContext.block(1); + ElseExpression elseExpr = new ElseExpression(); + elseExpr.setExpression(parseBlock(secondBlockContext)); + expr.setElseExpression(elseExpr); + return expr; + } else if (exprCompositeContext instanceof ComplexExprCompositeContext) { + ComplexExprCompositeContext complexExprCompositeContext = (ComplexExprCompositeContext) exprCompositeContext; + ExprCompositeContext leftExprCompositeContext = complexExprCompositeContext.exprComposite(0); + Expression leftExpression = parseExprComposite(leftExprCompositeContext); + ExprCompositeContext rightExprCompositeContext = complexExprCompositeContext.exprComposite(1); + Expression rightExpression = parseExprComposite(rightExprCompositeContext); + String op = complexExprCompositeContext.Operator().getText(); + Operator operator = Operator.parse(op); + List expressions = new ArrayList<>(); + expressions.add((BaseExpression) leftExpression); + expressions.add((BaseExpression) rightExpression); + List operators = new ArrayList<>(); + operators.add(operator); + ParenExpression expression = new ParenExpression(operators, expressions); + expression.setExpr(complexExprCompositeContext.getText()); + return expression; + } + return null; + } + + private BlockExpression parseExpressionBlock(List contexts) { + StringBuilder sb = new StringBuilder(); + List expressionList = new ArrayList<>(); + for (ExprBlockContext ctx : contexts) { + sb.append(ctx.getText()); + VariableAssignContext assignContext = ctx.variableAssign(); + if (assignContext != null) { + VariableContext varCtx = assignContext.variable(); + String variableName = varCtx.Identifier().getText(); + AssignExpression assignExpr = new AssignExpression(); + assignExpr.setExpr(assignContext.getText()); + assignExpr.setVariable(variableName); + ItemContext itemCtx = assignContext.item(); + BaseExpression itemExpr = parseItemContext(itemCtx); + assignExpr.setExpression(itemExpr); + expressionList.add(assignExpr); + } + IfExprContext ifCtx = ctx.ifExpr(); + if (ifCtx != null) { + IfExpression ifExpr = parseIfExprContext(ifCtx); + expressionList.add(ifExpr); + } + CaseExprContext caseCtx = ctx.caseExpr(); + if (caseCtx != null) { + IfExpression caseExpr = parseCaseExprContext(caseCtx); + expressionList.add(caseExpr); + } + } + BlockExpression blockExpr = new BlockExpression(); + blockExpr.setExpressionList(expressionList); + blockExpr.setExpr(sb.toString()); + return blockExpr; + } + + private IfExpression parseIfExprContext(IfExprContext ifExprContext) { + IfExpression expr = new IfExpression(); + expr.setExpr(ifExprContext.getText()); + IfPartContext ifPartContext = ifExprContext.ifPart(); + List ifConditionContexts = ifPartContext.ifCondition(); + List joinContexts = ifPartContext.join(); + expr.setExpressionConditionList(parseCondtionList(ifConditionContexts, joinContexts)); + BlockExpression blockExpr = parseBlock(ifPartContext.block()); + expr.setExpression(blockExpr); + List elseIfPartContexts = ifExprContext.elseIfPart(); + if (elseIfPartContexts != null && elseIfPartContexts.size() > 0) { + List elseIfExpressionList = new ArrayList<>(); + for (ElseIfPartContext elseIfContext : elseIfPartContexts) { + ifConditionContexts = elseIfContext.ifCondition(); + joinContexts = elseIfContext.join(); + ElseIfExpression elseIfExpr = new ElseIfExpression(); + elseIfExpr.setExpressionConditionList(parseCondtionList(ifConditionContexts, joinContexts)); + elseIfExpr.setExpression(parseBlock(elseIfContext.block())); + elseIfExpressionList.add(elseIfExpr); + } + expr.setElseIfExpressions(elseIfExpressionList); + } + ElsePartContext elsePartContext = ifExprContext.elsePart(); + if (elsePartContext != null) { + ElseExpression elseExpression = new ElseExpression(); + elseExpression.setExpression(parseBlock(elsePartContext.block())); + expr.setElseExpression(elseExpression); + } + return expr; + } + + private BlockExpression parseBlock(BlockContext blockCtx) { + List exprBlockCtxs = blockCtx.exprBlock(); + ReturnExprContext returnCtx = blockCtx.returnExpr(); + BlockExpression block = null; + if (exprBlockCtxs != null) { + block = parseExpressionBlock(exprBlockCtxs); + } + if (returnCtx != null) { + if (block == null) + block = new BlockExpression(); + block.setReturnExpression(parseExpr(returnCtx.expr())); + } + return block; + } + + private IfExpression parseCaseExprContext(CaseExprContext caseExprContext) { + IfExpression expr = new IfExpression(); + List elseIfExpressionList = new ArrayList<>(); + expr.setElseIfExpressions(elseIfExpressionList); + List casePartContexts = caseExprContext.casePart(); + for (CasePartContext casePartContext : casePartContexts) { + List ifConditionContexts = casePartContext.ifCondition(); + List joinContexts = casePartContext.join(); + ElseIfExpression elseIfExpr = new ElseIfExpression(); + elseIfExpr.setExpressionConditionList(parseCondtionList(ifConditionContexts, joinContexts)); + elseIfExpr.setExpr(casePartContext.getText()); + BlockExpression blockExpr = parseBlock(casePartContext.block()); + elseIfExpr.setExpression(blockExpr); + elseIfExpressionList.add(elseIfExpr); + } + return expr; + } + + private Expression parseExpr(ExprContext exprContext) { + List expressions = new ArrayList<>(); + List operators = new ArrayList<>(); + List itemContexts = exprContext.item(); + List operatorNodes = exprContext.Operator(); + for (int i = 0; i < itemContexts.size(); i++) { + ItemContext itemContext = itemContexts.get(i); + BaseExpression expr = parseItemContext(itemContext); + expressions.add(expr); + if (i > 0) { + TerminalNode operatorNode = operatorNodes.get(i - 1); + String op = operatorNode.getText(); + operators.add(Operator.parse(op)); + } + } + ParenExpression expression = new ParenExpression(operators, expressions); + expression.setExpr(exprContext.getText()); + return expression; + } + + private ExpressionConditionList parseCondtionList(List ifConditionContexts, + List joinContexts) { + List list = new ArrayList<>(); + List joins = new ArrayList<>(); + for (int i = 0; i < ifConditionContexts.size(); i++) { + IfConditionContext context = ifConditionContexts.get(i); + ExprContext left = context.expr(0); + ExprContext right = context.expr(1); + Expression leftExpr = parseExpr(left); + Expression rightExpr = parseExpr(right); + Op op = Op.parse(context.OP().getText()); + ExpressionCondition expressionCondition = new ExpressionCondition(leftExpr, op, rightExpr); + list.add(expressionCondition); + if (i > 0) { + JoinContext joinContext = joinContexts.get(i - 1); + String text = joinContext.getText(); + Join join = Join.and; + if (text.equals("or") || text.equals("||")) { + join = Join.or; + } + joins.add(join); + } + } + return new ExpressionConditionList(list, joins); + } + + public BaseExpression parseItemContext(ItemContext itemContext) { + BaseExpression expression = null; + if (itemContext instanceof SimpleJoinContext) { + SimpleJoinContext simpleJoinContext = (SimpleJoinContext) itemContext; + expression = visitSimpleJoin(simpleJoinContext); + } else if (itemContext instanceof ParenJoinContext) { + ParenJoinContext parenJoinContext = (ParenJoinContext) itemContext; + expression = visitParenJoin(parenJoinContext); + } else if (itemContext instanceof SingleParenJoinContext) { + SingleParenJoinContext singleContext = (SingleParenJoinContext) itemContext; + ItemContext childItemContext = singleContext.item(); + expression = parseItemContext(childItemContext); + } + return expression; + } + + @Override + public BaseExpression visitSimpleJoin(SimpleJoinContext ctx) { + List expressions = new ArrayList<>(); + List operators = new ArrayList<>(); + List unitContexts = ctx.unit(); + List operatorNodes = ctx.Operator(); + for (int i = 0; i < unitContexts.size(); i++) { + UnitContext unitContext = unitContexts.get(i); + BaseExpression expr = buildExpression(unitContext); + if (expr != null) { + expressions.add(expr); + if (i > 0) { + TerminalNode operatorNode = operatorNodes.get(i - 1); + String op = operatorNode.getText(); + operators.add(Operator.parse(op)); + } + } + } + if (operators.size() == 0 && expressions.size() == 1) { + return expressions.get(0); + } + JoinExpression expression = new JoinExpression(operators, expressions); + expression.setExpr(ctx.getText()); + return expression; + } + + @Override + public BaseExpression visitParenJoin(ParenJoinContext ctx) { + List expressions = new ArrayList<>(); + List operators = new ArrayList<>(); + List itemContexts = ctx.item(); + List operatorNodes = ctx.Operator(); + for (int i = 0; i < itemContexts.size(); i++) { + ItemContext itemContext = itemContexts.get(i); + BaseExpression expr = parseItemContext(itemContext); + expressions.add(expr); + if (i > 0) { + TerminalNode operatorNode = operatorNodes.get(i - 1); + String op = operatorNode.getText(); + operators.add(Operator.parse(op)); + } + } + ParenExpression expression = new ParenExpression(operators, expressions); + expression.setExpr(ctx.getText()); + return expression; + } + + private BaseExpression buildExpression(UnitContext unitContext) { + for (ExpressionBuilder builder : expressionBuilders) { + if (builder.support(unitContext)) { + return builder.build(unitContext); + } + } + return null; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Op.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Op.java new file mode 100644 index 0000000..9992e21 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Op.java @@ -0,0 +1,50 @@ +package com.yunzhupaas.ureport.expression.util; + +import java.util.Objects; + +/** + * @author + * @since 2016年11月22日 + */ +public enum Op { + GreatThen, EqualsGreatThen, LessThen, EqualsLessThen, Equals, NotEquals, In, NotIn, Like; + + public static Op parse(String op) { + return getOp(op); + } + + public static Op getOp(String op) { + for (Op status : Op.values()) { + if (Objects.equals(status.name(), op.trim())) { + return status; + } + } + return Op.Equals; + } + + @Override + public String toString() { + switch (this) { + case GreatThen: + return ">"; + case EqualsGreatThen: + return ">="; + case LessThen: + return "<"; + case EqualsLessThen: + return "<="; + case Equals: + return "=="; + case NotEquals: + return "!="; + case In: + return " in "; + case NotIn: + return " not in "; + case Like: + return " like "; + } + return super.toString(); + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Operator.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Operator.java new file mode 100644 index 0000000..5fbcbaa --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/expression/util/Operator.java @@ -0,0 +1,43 @@ +package com.yunzhupaas.ureport.expression.util; + +/** + * @author + * @since 2016年11月18日 + */ +public enum Operator { + Add, Subtract, Multiply, Divide, Complementation; + + public static Operator parse(String op) { + if (op.equals("+")) { + return Add; + } else if (op.equals("-")) { + return Subtract; + } else if (op.equals("*")) { + return Multiply; + } else if (op.equals("/")) { + return Divide; + } else if (op.equals("%")) { + return Complementation; + } + return Add; + } + + @Override + public String toString() { + switch (this) { + case Add: + return "+"; + case Divide: + return "/"; + case Multiply: + return "*"; + case Subtract: + return "-"; + case Complementation: + return "%"; + default: + return "+"; + } + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Cell.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Cell.java new file mode 100644 index 0000000..6ff64ad --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Cell.java @@ -0,0 +1,190 @@ +package com.yunzhupaas.ureport.model; + +import com.yunzhupaas.univer.sheet.UniverSheetCellData; +import com.yunzhupaas.ureport.Range; +import com.yunzhupaas.ureport.build.BindData; +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.BlankCellInfo; +import com.yunzhupaas.ureport.definition.Expand; +import com.yunzhupaas.ureport.definition.value.SimpleValue; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.univer.sheet.UniverSheetColumnData; +import com.yunzhupaas.univer.sheet.UniverSheetRowData; +import lombok.Getter; +import lombok.Setter; +import org.apache.poi.ss.util.CellReference; + +import java.util.*; + +@Getter +@Setter +public class Cell { + private String name; + + private int rowNumber; + private int columnNumber; + + private int rowSpan; + private int colSpan; + + private Range duplicateRange; + + /** + * 当前单元格计算后的实际值 + */ + private Object data; + private String leftGroupId; + private String topGroupId; + + private CellReference reference; + + private StyleModel styleModel; + + private UniverSheetRowData sheetRowData; + private UniverSheetColumnData sheetColumnData; + + private UniverSheetCellData cellData; + + private Value value; + private Row row; + private Column column; + private Expand expand; + private boolean processed; + private boolean blankCell; + private boolean existPageFunction; + private List> bindData; + private List dataList; + + private boolean fillBlankRows; + /** + * 允许填充空白行时fillBlankRows=true,要求当前数据行数必须是multiple定义的行数的倍数,否则就补充空白行 + */ + private int multiple; + + /** + * 当前单元格左父格 + */ + private String leftType; + private Cell leftParentCell; + private List leftParentList = new ArrayList<>(); + /** + * 当前单元格上父格 + */ + private String topType; + private Cell topParentCell; + private List topParentList = new ArrayList<>(); + + /** + * 当前单元格所在行所有子格 + */ + private Map> rowChildrenCellsMap = new HashMap<>(); + /** + * 当前单元格所在列所有子格 + */ + private Map> columnChildrenCellsMap = new HashMap<>(); + + private List increaseSpanCellNames; + private Map newBlankCellsMap; + private List newCellNames; + + public Cell newCell() { + Cell cell = new Cell(); + cell.setColumn(column); + cell.setRowNumber(rowNumber); + cell.setColumnNumber(columnNumber); + cell.setRow(row); + cell.setLeftParentCell(leftParentCell); + cell.setTopParentCell(topParentCell); + cell.setValue(value); + cell.setLeftGroupId(leftGroupId); + cell.setTopGroupId(topGroupId); + cell.setDataList(dataList); + cell.setRowSpan(rowSpan); + cell.setColSpan(colSpan); + cell.setExpand(expand); + cell.setName(name); + cell.setDuplicateRange(duplicateRange); + cell.setCellData(cellData); + cell.setStyleModel(styleModel); + cell.setNewBlankCellsMap(newBlankCellsMap); + cell.setNewCellNames(newCellNames); + cell.setIncreaseSpanCellNames(increaseSpanCellNames); + cell.setFillBlankRows(fillBlankRows); + cell.setMultiple(multiple); + cell.setLeftType(leftType); + cell.setTopType(topType); + return cell; + } + + public void addRowChild(Cell child) { + String name = child.getName(); + List cells = rowChildrenCellsMap.get(name); + if (cells == null) { + cells = new ArrayList<>(); + rowChildrenCellsMap.put(name, cells); + } + if (!cells.contains(child)) { + cells.add(child); + } + if (leftParentCell != null) { + leftParentCell.addRowChild(child); + } + } + + public void addColumnChild(Cell child) { + String name = child.getName(); + List cells = columnChildrenCellsMap.get(name); + if (cells == null) { + cells = new ArrayList<>(); + columnChildrenCellsMap.put(name, cells); + } + if (!cells.contains(child)) { + cells.add(child); + } + if (topParentCell != null) { + topParentCell.addColumnChild(child); + } + } + + public Cell newColumnBlankCell(Context context, BlankCellInfo blankCellInfo, Cell mainCell) { + Cell blankCell = newCell(); + blankCell.setBlankCell(true); + blankCell.setValue(new SimpleValue("")); + blankCell.setExpand(Expand.None); + blankCell.setBindData(null); + + int offset = blankCellInfo.getOffset(); + int mainColNumber = mainCell.getColumn().getColumnNumber(); + if (offset == 0) { + blankCell.setColumn(mainCell.getColumn()); + } else { + int colNumber = mainColNumber + offset; + Column col = context.getColumn(colNumber); + blankCell.setColumn(col); + } + blankCell.setColSpan(blankCellInfo.getSpan()); + return blankCell; + } + + public Cell newRowBlankCell(Context context, BlankCellInfo blankCellInfo, Cell mainCell) { + Cell blankCell = newCell(); + blankCell.setBlankCell(true); + blankCell.setValue(new SimpleValue("")); + blankCell.setExpand(Expand.None); + blankCell.setBindData(null); + if (blankCellInfo != null) { + int offset = blankCellInfo.getOffset(); + int mainRowNumber = mainCell.getRow().getRowNumber(); + if (offset == 0) { + blankCell.setRow(mainCell.getRow()); + } else { + int rowNumber = mainRowNumber + offset; + Row row = context.getRow(rowNumber); + blankCell.setRow(row); + } + blankCell.setRowSpan(blankCellInfo.getSpan()); + } + return blankCell; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Column.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Column.java new file mode 100644 index 0000000..ab08315 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Column.java @@ -0,0 +1,42 @@ +package com.yunzhupaas.ureport.model; + +import com.yunzhupaas.univer.sheet.UniverSheetColumnData; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Setter +@Getter +public class Column { + /** + * 是否冻结 + */ + private Boolean freeze = false; + /** + * 一个用来临时存放当前列号的属性,只在构建报表时创建新列时使用 + */ + private int tempColumnNumber; + private List columns; + + private List cells = new ArrayList<>(); + + private UniverSheetColumnData sheetColumnData; + + public Column(List columns) { + this.columns = columns; + } + + public Column newColumn() { + Column col = new Column(columns); + col.setFreeze(freeze); + col.setSheetColumnData(sheetColumnData); + return col; + } + + public int getColumnNumber() { + return this.columns.indexOf(this) + 1; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Functions.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Functions.java new file mode 100644 index 0000000..dd3e445 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Functions.java @@ -0,0 +1,24 @@ +package com.yunzhupaas.ureport.model; + +import lombok.Data; + +import java.util.*; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/8/23 上午8:53 + */ +@Data +public class Functions { + private String name; + private int rowNumber; + private int colNumber; + private String function; + private List functionName = new ArrayList<>(); + private Map> leftTop = new HashMap<>(); + private Map> rightTop = new HashMap<>(); + private Map> leftBottom = new HashMap<>(); + private Map> rightBottom = new HashMap<>(); +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Report.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Report.java new file mode 100644 index 0000000..c79548c --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Report.java @@ -0,0 +1,115 @@ +package com.yunzhupaas.ureport.model; + +import com.yunzhupaas.ureport.build.Context; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class Report { + private Cell rootCell; + private Context context; + private List rows; + private List columns; + private String reportFullName; + private List lazyComputeCells = new ArrayList<>(); + private Map> rowColCellMap = new HashMap<>(); + private Map> cellsMap = new HashMap<>(); + + public void insertRow(Row row, int rowNumber) { + int pos = rowNumber - 1; + rows.add(pos, row); + } + + public void insertRows(int firstRowIndex, List insertRows) { + int pos = firstRowIndex - 1; + rows.addAll(pos, insertRows); + } + + public void insertColumn(Column column, int columnNumber) { + int pos = columnNumber - 1; + columns.add(pos, column); + } + + public void insertColumns(int firstColumnIndex, List insertColumns) { + int pos = firstColumnIndex - 1; + columns.addAll(pos, insertColumns); + } + + public Row getRow(int rowNumber) { + if (rowNumber > rows.size()) { + return null; + } + return rows.get(rowNumber - 1); + } + + public Column getColumn(int columnNumber) { + if (columnNumber > columns.size()) { + return null; + } + return columns.get(columnNumber - 1); + } + + public boolean addCell(Cell cell) { + String cellName = cell.getName(); + List cells = null; + if (cellsMap.containsKey(cellName)) { + cells = cellsMap.get(cellName); + } else { + cells = new ArrayList<>(); + cellsMap.put(cellName, cells); + } + int lastIdx = findSameLeftCell(cells, cell, 0); + if (lastIdx > -1 && lastIdx < cells.size() - 1) { + cells.add(lastIdx + 1, cell); + } else { + cells.add(cell); + } + Row row = cell.getRow(); + Column col = cell.getColumn(); + Map colMap = null; + if (rowColCellMap.containsKey(row)) { + colMap = rowColCellMap.get(row); + } else { + colMap = new HashMap<>(); + rowColCellMap.put(row, colMap); + } + colMap.put(col, cell); + return addLazyCell(cell); + } + + public int findSameLeftCell(List cells, Cell nowCell, int deep) { + int lastIdx = -1; + // todo + // nowCell = nowCell.getLeftParentCell(); + // if (nowCell == null) { + // return lastIdx; + // } + // for (int i = cells.size() - 1; i >= 0; i--) { + // Cell left = cells.get(i).getLeftParentCell(); + // for (int j = 0; j < deep; j++) { + // if (left == null) { + // return lastIdx; + // } + // left = left.getLeftParentCell(); + // } + // if (left != null && left.equals(nowCell)) { + // return i; + // } + // } + // if (lastIdx == -1 && nowCell.getLeftParentCell() != null) { + // return findSameLeftCell(cells, nowCell, deep + 1); + // } + return lastIdx; + } + + public boolean addLazyCell(Cell cell) { + return false; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Row.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Row.java new file mode 100644 index 0000000..16c13b8 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/Row.java @@ -0,0 +1,45 @@ +package com.yunzhupaas.ureport.model; + +import com.yunzhupaas.univer.sheet.UniverSheetRowData; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Setter +@Getter +public class Row { + private String rowKey; + /** + * 一个用来临时存放当前行号的属性,只在构建报表时创建新行时使用 + */ + private int tempRowNumber; + /** + * 是否冻结 + */ + private Boolean freeze = false; + + private List rows; + + private List cells = new ArrayList<>(); + + private UniverSheetRowData sheetRowData; + + public Row(List rows) { + this.rows = rows; + } + + public Row newRow() { + Row row = new Row(rows); + row.setFreeze(freeze); + row.setRowKey(rowKey); + row.setSheetRowData(sheetRowData); + return row; + } + + public int getRowNumber() { + return rows.indexOf(this) + 1; + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/StyleModel.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/StyleModel.java new file mode 100644 index 0000000..90d4693 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/model/StyleModel.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.model; + +import lombok.Data; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/9/11 上午9:12 + */ +@Data +public class StyleModel { + public Object l; + public Object r; + public Object t; + public Object b; + + public Object lt; + public Object rt; + public Object lb; + public Object rb; +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/BuildUtils.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/BuildUtils.java new file mode 100644 index 0000000..4c80c99 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/BuildUtils.java @@ -0,0 +1,22 @@ +package com.yunzhupaas.ureport.utils; + +import com.yunzhupaas.ureport.definition.CellDefinition; + +/** + * @author + * @since 2月27日 + */ +public class BuildUtils { + + public static int buildRowNumberEnd(CellDefinition cell, int rowNumber) { + int rowSpan = cell.getRowSpan(); + rowSpan = rowSpan > 0 ? rowSpan - 1 : rowSpan; + return rowNumber + rowSpan; + } + + public static int buildColNumberEnd(CellDefinition cell, int colNumber) { + int colSpan = cell.getColSpan(); + colSpan = colSpan > 0 ? colSpan - 1 : colSpan; + return colNumber + colSpan; + } +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataComparator.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataComparator.java new file mode 100644 index 0000000..4325205 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataComparator.java @@ -0,0 +1,72 @@ +package com.yunzhupaas.ureport.utils; + +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.Date; +import java.util.Map; + +/** + * @author :云筑产品开发平台组 + * @version: V3.1.0 + * @copyright 深圳市乐程软件有限公司 + * @date :2024/12/16 下午3:26 + */ +@Setter +@Getter +public class DataComparator implements Comparator> { + + private String order; + + @Override + public int compare(Map data1, Map data2) { + if (order == null) { + return 0; + } + Object object1 = data1.get(order); + Object object2 = data2.get(order); + if (object1 == null && object2 == null) { + return 0; + } + int comparison = comparison(object1, object2); + return comparison; + } + + private int comparison(Object object1, Object object2) { + Date date1 = null; + Date date2 = null; + BigDecimal bigDecimal1 = null; + BigDecimal bigDecimal2 = null; + String string1 = null; + String string2 = null; + if (object1 instanceof Date && object2 instanceof Date) { + date1 = (Date) object1; + date2 = (Date) object2; + } else if (object1 instanceof Number && object2 instanceof Number) { + bigDecimal1 = DataUtils.toBigDecimal(object1); + bigDecimal2 = DataUtils.toBigDecimal(object2); + } else { + string1 = String.valueOf(object1); + string2 = String.valueOf(object2); + } + if (date1 != null) { + return date1.compareTo(date2); + } else if (bigDecimal1 != null && bigDecimal2 != null) { + return bigDecimal1.compareTo(bigDecimal2); + } else { + if (string1 == null) { + if (string2 == null) { + return 0; + } + return 1; + } + if (string2 == null) { + return -1; + } + return string1.compareTo(string2); + } + } + +} diff --git a/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataUtils.java b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataUtils.java new file mode 100644 index 0000000..aeffc14 --- /dev/null +++ b/yunzhupaas-datareport-univer-model/src/main/java/com/yunzhupaas/ureport/utils/DataUtils.java @@ -0,0 +1,256 @@ +package com.yunzhupaas.ureport.utils; + +import com.yunzhupaas.ureport.build.Context; +import com.yunzhupaas.ureport.definition.value.DatasetValue; +import com.yunzhupaas.ureport.definition.value.Value; +import com.yunzhupaas.ureport.model.Cell; +import com.yunzhupaas.ureport.model.Report; +import com.yunzhupaas.util.StringUtil; +import org.apache.commons.collections4.CollectionUtils; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +public class DataUtils { + + public static List> fetchData(Cell cell, Context context, String datasetName) { + Cell leftCell = fetchLeftCell(cell, context, datasetName); + Cell topCell = fetchTopCell(cell, context, datasetName); + List> leftList = null; + List> topList = null; + if (leftCell != null) { + leftList = leftCell.getBindData(); + } + if (topCell != null) { + topList = topCell.getBindData(); + } + if (leftList == null && topList == null) { + List> data = context.getDatasetData(datasetName); + return data; + } else if (leftList == null) { + return topList; + } else if (topList == null) { + return leftList; + } else if (leftCell != null && topCell != null) { + String leftProp = ((DatasetValue) leftCell.getValue()).getProperty(); + Object leftValue = leftCell.getData(); + String topProp = ((DatasetValue) topCell.getValue()).getProperty(); + Object topValue = topCell.getData(); + List> topDataList = new ArrayList<>(); + for (Map data : topList) { + if (Objects.equals(data.get(leftProp), leftValue)) { + topDataList.add(data); + } + } + List> leftDataList = new ArrayList<>(); + for (Map data : leftList) { + if (Objects.equals(data.get(topProp), topValue)) { + leftDataList.add(data); + } + } + List> result = leftDataList.size() > topDataList.size() ? topDataList : leftDataList; + return result; + } else { + return Collections.emptyList(); + } + } + + public static Cell fetchLeftCell(Cell cell, Context context, String datasetName) { + Cell targetCell = null; + Cell parentCell = cell.getLeftParentCell(); + if (parentCell != null) { + Value cellValue = parentCell.getValue(); + if (cellValue instanceof DatasetValue) { + DatasetValue datasetValue = (DatasetValue) cellValue; + if (datasetValue != null) { + String dataName = datasetValue.getDatasetName(); + if (Objects.equals(dataName, datasetName)) { + if (parentCell.getBindData() != null) { + targetCell = parentCell; + } + } + } + } + } + return targetCell; + } + + public static Cell fetchTopCell(Cell cell, Context context, String datasetName) { + Cell targetCell = null; + Cell parentCell = cell.getTopParentCell(); + if (parentCell != null) { + Value cellValue = parentCell.getValue(); + if (cellValue instanceof DatasetValue) { + DatasetValue datasetValue = (DatasetValue) cellValue; + if (datasetValue != null) { + String dataName = datasetValue.getDatasetName(); + if (Objects.equals(dataName, datasetName)) { + if (parentCell.getBindData() != null) { + targetCell = parentCell; + } + } + } + } + } + return targetCell; + } + + public static void cellList(Cell cell, boolean left, boolean top) { + if (cell != null) { + if (left && cell.getLeftParentCell() != null) { + List leftList = new ArrayList<>(); + cell.setLeftParentList(leftList); + } + if (top && cell.getTopParentCell() != null) { + List topList = new ArrayList<>(); + cell.setTopParentList(topList); + } + } + } + + public static List dataList(DatasetValue expr, List> objList) { + List result = new ArrayList<>(); + String property = expr.getProperty(); + for (Map o : objList) { + Object data = o.get(property); + try { + BigDecimal bigDecimal = new BigDecimal(String.valueOf(data)); + result.add(bigDecimal); + } catch (Exception e) { + } + } + return result; + } + + public static List fetchTargetCells(Cell cell, Context context, String cellName) { + while (!context.isCellPocessed(cellName)) { + context.getReportBuilder().buildCell(context, null); + } + List leftCells = fetchCellsByLeftParent(context, cell, cellName); + List topCells = fetchCellsByTopParent(context, cell, cellName); + if (leftCells != null && topCells != null) { + int leftSize = leftCells.size(); + int topSize = topCells.size(); + if (leftSize == 1 || topSize == 0) { + return leftCells; + } + if (topSize == 1 || leftSize == 0) { + return topCells; + } + List list = new ArrayList<>(CollectionUtils.intersection(leftCells, topCells)); + return list; + } else if (leftCells != null && topCells == null) { + return leftCells; + } else if (leftCells == null && topCells != null) { + return topCells; + } else { + Report report = context.getReport(); + return report.getCellsMap().get(cellName); + } + } + + private static List fetchCellsByLeftParent(Context context, Cell cell, String cellName) { + Cell leftParentCell = cell.getLeftParentCell(); + if (leftParentCell == null) { + return null; + } + if (leftParentCell.getName().equals(cellName)) { + List list = new ArrayList<>(); + list.add(leftParentCell); + return list; + } + // todo + // Map> childrenCellsMap = + // leftParentCell.getRowChildrenCellsMap(); + // List targetCells = childrenCellsMap.get(cellName); + // if (targetCells != null) { + // return targetCells; + // } + return fetchCellsByLeftParent(context, leftParentCell, cellName); + } + + private static List fetchCellsByTopParent(Context context, Cell cell, String cellName) { + Cell topParentCell = cell.getTopParentCell(); + if (topParentCell == null) { + return null; + } + if (topParentCell.getName().equals(cellName)) { + List list = new ArrayList<>(); + list.add(topParentCell); + return list; + } + // todo + // Map> childrenCellsMap = + // topParentCell.getColumnChildrenCellsMap(); + // List targetCells = childrenCellsMap.get(cellName); + // if (targetCells != null) { + // return targetCells; + // } + return fetchCellsByTopParent(context, topParentCell, cellName); + } + + public static BigDecimal toBigDecimal(Object obj) { + BigDecimal bigDecimal = null; + if (obj == null) { + return bigDecimal; + } + if (obj instanceof BigDecimal) { + bigDecimal = (BigDecimal) obj; + } else if (obj instanceof String) { + if (obj.toString().trim().equals("")) { + bigDecimal = new BigDecimal(0); + } + try { + String str = obj.toString().trim(); + bigDecimal = new BigDecimal(str); + } catch (Exception ex) { + + } + } else if (obj instanceof Number) { + Number n = (Number) obj; + bigDecimal = new BigDecimal(n.doubleValue()); + } + return bigDecimal; + } + + public static List> orderDataList(List> list, String order) { + List> dataList = new ArrayList<>(list); + if (StringUtil.isEmpty(order)) { + return dataList; + } + Map>> comparatorMap = getComparatorMap(order); + Comparator> comparator = null; + List comparatorList = new ArrayList<>(comparatorMap.keySet()).stream() + .sorted(Comparator.naturalOrder()).collect(Collectors.toList()); + for (int i = 0; i < comparatorList.size(); i++) { + Comparator> current = comparatorMap.get(comparatorList.get(i)); + if (current == null) { + continue; + } + comparator = comparator == null ? current : comparator.thenComparing(current); + } + if (comparator != null) { + dataList.sort(comparator); + } + return dataList; + } + + private static Map>> getComparatorMap(String order) { + List orderList = Arrays.asList(order.split(",")); + Map>> comparatorMap = new HashMap<>(); + for (int i = 0; i < orderList.size(); i++) { + String vModel = orderList.get(i); + boolean isDesc = vModel.startsWith("-"); + if (isDesc) { + vModel = vModel.substring(1); + } + DataComparator dataComparator = new DataComparator(); + dataComparator.setOrder(vModel); + Comparator> comparator = isDesc ? dataComparator.reversed() : dataComparator; + comparatorMap.put(i, comparator); + } + return comparatorMap; + } + +}