mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
报表基础模块:新增模版接口-解析表达式、校验表达式
This commit is contained in:
+55
@@ -3,10 +3,15 @@ package com.cf.imes.module.report.controller.admin.template;
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.bstek.designer.excel.ExcelParserUtils;
|
||||
import com.bstek.ureport.definition.ReportDefinition;
|
||||
import com.bstek.ureport.dsl.ReportParserLexer;
|
||||
import com.bstek.ureport.dsl.ReportParserParser;
|
||||
import com.bstek.ureport.export.ExportUtils;
|
||||
import com.bstek.ureport.export.ProducerEnum;
|
||||
import com.bstek.ureport.export.html.HtmlReport;
|
||||
import com.bstek.ureport.expression.ErrorInfo;
|
||||
import com.bstek.ureport.expression.ScriptErrorListener;
|
||||
import com.bstek.ureport.model.Report;
|
||||
import com.bstek.ureport.utils.StringUtils;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
@@ -20,8 +25,12 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -32,7 +41,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@@ -126,4 +137,48 @@ public class ReportTemplateController {
|
||||
}
|
||||
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "文件未识别");
|
||||
}
|
||||
|
||||
@GetMapping("/scriptValidation")
|
||||
@Operation(summary = "校验表达式")
|
||||
@Parameter(name = "content", description = "表达式", required = true)
|
||||
public List<ErrorInfo> scriptValidation(@Param("content") String content) {
|
||||
content = StringUtils.decode(content);
|
||||
ANTLRInputStream antlrInputStream = new ANTLRInputStream(content);
|
||||
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||
ReportParserParser parser = new ReportParserParser(tokenStream);
|
||||
ScriptErrorListener errorListener = new ScriptErrorListener();
|
||||
parser.removeErrorListeners();
|
||||
parser.addErrorListener(errorListener);
|
||||
parser.expression();
|
||||
return errorListener.getInfos();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析表达式中的数据集
|
||||
*
|
||||
* @param expr
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/parseDataSet")
|
||||
@Operation(summary = "解析表达式中的数据集")
|
||||
@Parameter(name = "expr", description = "表达式", required = true)
|
||||
public Map<String, String> parseDatasetName(@Param("expr") String expr) {
|
||||
ANTLRInputStream antlrInputStream = new ANTLRInputStream(expr);
|
||||
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||
ReportParserParser parser = new ReportParserParser(tokenStream);
|
||||
parser.removeErrorListeners();
|
||||
|
||||
Map<String, String> result = new HashMap<>();
|
||||
ReportParserParser.DatasetContext ctx = parser.dataset();
|
||||
if (ctx != null) {
|
||||
TerminalNode node = ctx.Identifier();
|
||||
if (node != null) {
|
||||
String datasetName = ctx.Identifier().getText();
|
||||
result.put("datasetName", datasetName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user