Skip to content

Commit

Permalink
tmpl better (#668)
Browse files Browse the repository at this point in the history
* be: isSame

* socketTimeout=0

* feat: front


* WordReportGenerator

* style: print

* be: common-save

* be: 本地加载PDF

* fops

* inTriggerTime2

* report 100w

* word tmpl

* word table

* style

* Update @rbv

* AppHome._InTab

* IsNullFunction

* modal onDoubleClick
  • Loading branch information
getrebuild authored Oct 18, 2023
1 parent 1486d27 commit e6b2ea8
Show file tree
Hide file tree
Showing 53 changed files with 24,798 additions and 253 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from 551b01 to 8dbf30
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.18</version>
<version>1.2.20</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
<version>8.1.0</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
Expand Down Expand Up @@ -398,15 +398,20 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
Expand Down Expand Up @@ -488,6 +493,7 @@
<version>2.4.0</version>
</dependency>


<!-- fix: CVEs -->
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
public class DataExporter extends SetUser {

/**
* 最大行数
* 最大导出行数
*/
public static final int MAX_ROWS = 65535 - 1;

public static final int MAX_ROWS = 1000000;
final private JSONObject queryData;
// 字段
private List<Field> headFields = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,31 @@ private DataReportManager() {}

public static final int TYPE_RECORD = 1;
public static final int TYPE_LIST = 2;
public static final int TYPE_HTML5 = 3;
public static final int TYPE_WORD = 4;

/**
* 获取报表列表
* 获取可用报表
*
* @param entity
* @param type
* @param type 指定类型
* @param user
* @return
*/
public JSONArray getReports(Entity entity, int type, ID user) {
JSONArray alist = new JSONArray();
for (ConfigBean e : getReportsRaw(entity)) {
if (!e.getBoolean("disabled") && e.getInteger("type") == type) {
if (e.getBoolean("disabled")) continue;

boolean can;
int aType = e.getInteger("type");
if (type == DataReportManager.TYPE_LIST) {
can = aType == type;
} else {
can = aType == DataReportManager.TYPE_RECORD || aType == DataReportManager.TYPE_WORD;
}

if (can) {
// v3.5
String vuDef = e.getString("visibleUsers");
if (StringUtils.isNotBlank(vuDef)) {
Expand Down Expand Up @@ -85,7 +97,7 @@ public ConfigBean[] getReportsRaw(Entity entity) {
}

Object[][] array = Application.createQueryNoFilter(
"select configId,name,isDisabled,templateFile,templateType,extraDefinition from DataReportConfig where belongEntity = ?")
"select configId,name,isDisabled,templateFile,templateType,extraDefinition,templateContent from DataReportConfig where belongEntity = ?")
.setParameter(1, entity.getName())
.array();

Expand All @@ -104,7 +116,8 @@ public ConfigBean[] getReportsRaw(Entity entity) {
.set("type", ObjectUtils.toInt(o[4], TYPE_RECORD))
.set("outputType", outputType)
.set("templateVersion", templateVersion)
.set("visibleUsers", visibleUsersDef);
.set("visibleUsers", visibleUsersDef)
.set("templateContent", o[6]);
alist.add(cb);
}

Expand All @@ -119,29 +132,36 @@ public ConfigBean[] getReportsRaw(Entity entity) {
* @return
*/
public TemplateFile getTemplateFile(Entity entity, ID reportId) {
String template = null;
boolean isList = false;
String templateFile = null;
String templateContent = null;
int type = DataReportManager.TYPE_RECORD;
boolean isV33 = false;

for (ConfigBean e : getReportsRaw(entity)) {
if (e.getID("id").equals(reportId)) {
template = e.getString("template");
isList = e.getInteger("type") == TYPE_LIST;
templateFile = e.getString("template");
templateContent = e.getString("templateContent");
type = e.getInteger("type");
isV33 = e.getInteger("templateVersion") == 3;
break;
}
}

if (template == null) {
// v35 HTML5
if (templateContent != null) {
return new TemplateFile(templateContent, entity);
}

if (templateFile == null) {
throw new ConfigurationException("No template of report found : " + reportId);
}

File file = RebuildConfiguration.getFileOfData(template);
File file = RebuildConfiguration.getFileOfData(templateFile);
if (!file.exists()) {
throw new ConfigurationException("File of template not extsts : " + file);
}

return new TemplateFile(file, entity, isList, isV33);
return new TemplateFile(file, entity, type, isV33);
}

/**
Expand All @@ -150,15 +170,12 @@ public TemplateFile getTemplateFile(Entity entity, ID reportId) {
* @see #getTemplateFile(Entity, ID) 性能好
*/
public TemplateFile getTemplateFile(ID reportId) {
Object[] report = Application.createQueryNoFilter(
"select belongEntity from DataReportConfig where configId = ?")
.setParameter(1, reportId)
.unique();
if (report == null || !MetadataHelper.containsEntity((String) report[0])) {
Object[] o = Application.getQueryFactory().uniqueNoFilter(reportId, "belongEntity");
if (o == null || !MetadataHelper.containsEntity((String) o[0])) {
throw new ConfigurationException("No config of report found : " + reportId);
}

return getTemplateFile(MetadataHelper.getEntity((String) report[0]), reportId);
return getTemplateFile(MetadataHelper.getEntity((String) o[0]), reportId);
}

@Override
Expand All @@ -167,6 +184,8 @@ public void clean(Object entity) {
Application.getCommonsCache().evict(cKey);
}

// --

/**
* 获取报表名称
*
Expand All @@ -176,7 +195,8 @@ public void clean(Object entity) {
* @return
*/
public static String getReportName(ID reportId, Object idOrEntity, String fileName) {
Entity be = idOrEntity instanceof ID ? MetadataHelper.getEntity(((ID) idOrEntity).getEntityCode())
final Entity be = idOrEntity instanceof ID
? MetadataHelper.getEntity(((ID) idOrEntity).getEntityCode())
: MetadataHelper.getEntity((String) idOrEntity);

String name = null;
Expand All @@ -191,6 +211,7 @@ public static String getReportName(ID reportId, Object idOrEntity, String fileNa

// suffix
if (fileName.endsWith(".pdf")) name += ".pdf";
else if (fileName.endsWith(".docx")) name += ".docx";
else name += fileName.endsWith(".xlsx") ? ".xlsx" : ".xls";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
@Slf4j
public class EasyExcelGenerator extends SetUser {

protected File template;
protected File templateFile;
protected Integer writeSheetAt = null;
protected ID recordId;

Expand All @@ -92,7 +92,7 @@ public class EasyExcelGenerator extends SetUser {
* @param recordId
*/
protected EasyExcelGenerator(File template, ID recordId) {
this.template = getFixTemplate(template);
this.templateFile = getFixTemplate(template);
this.recordId = recordId;
}

Expand All @@ -116,7 +116,7 @@ public File generate() {

FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();

try (ExcelWriter excelWriter = EasyExcel.write(target).withTemplate(template).build()) {
try (ExcelWriter excelWriter = EasyExcel.write(target).withTemplate(templateFile).build()) {
WriteSheet writeSheet = EasyExcel.writerSheet(writeSheetAt)
.registerWriteHandler(new FixsMergeStrategy())
.registerWriteHandler(new FormulaCellWriteHandler())
Expand Down Expand Up @@ -150,8 +150,13 @@ public File generate() {
* @return
*/
protected File getTargetFile() {
return RebuildConfiguration.getFileOfTemp(String.format("RBREPORT-%d.%s",
System.currentTimeMillis(), template.getName().endsWith(".xlsx") ? "xlsx" : "xls"));
String suffix = "xls";
if (templateFile.getName().endsWith(".xlsx")) suffix = "xlsx";
if (templateFile.getName().endsWith(".html")) suffix = "html";
if (templateFile.getName().endsWith(".docx")) suffix = "docx";
if (templateFile.getName().endsWith(".doc")) suffix = "doc";

return RebuildConfiguration.getFileOfTemp(String.format("RBREPORT-%d.%s", System.currentTimeMillis(), suffix));
}

/**
Expand All @@ -160,9 +165,9 @@ protected File getTargetFile() {
* @return 第一个为主记录(若有)
*/
protected List<Map<String, Object>> buildData() {
Entity entity = MetadataHelper.getEntity(this.recordId.getEntityCode());
Entity entity = MetadataHelper.getEntity(recordId.getEntityCode());

TemplateExtractor templateExtractor = new TemplateExtractor(this.template);
TemplateExtractor templateExtractor = new TemplateExtractor(templateFile);
Map<String, String> varsMap = templateExtractor.transformVars(entity);

Map<String, String> varsMapOfMain = new HashMap<>();
Expand Down Expand Up @@ -193,7 +198,7 @@ protected List<Map<String, Object>> buildData() {
}
// 无效字段
else if (validField == null) {
log.warn("Invalid field `{}` in template : {}", e.getKey(), this.template);
log.warn("Invalid field `{}` in template : {}", e.getKey(), templateFile);
continue;
}

Expand All @@ -219,9 +224,9 @@ else if (validField == null) {
entity.getPrimaryField().getName(), entity.getName(), entity.getPrimaryField().getName());

Record record = Application.createQuery(sql, this.getUser())
.setParameter(1, this.recordId)
.setParameter(1, recordId)
.record();
Assert.notNull(record, "No record found : " + this.recordId);
Assert.notNull(record, "No record found : " + recordId);

datas.add(buildData(record, varsMapOfMain));
this.hasMain = true;
Expand All @@ -236,7 +241,7 @@ else if (validField == null) {
MetadataHelper.getDetailToMainField(entity.getDetailEntity()).getName());

List<Record> list = Application.createQuery(sql, this.getUser())
.setParameter(1, this.recordId)
.setParameter(1, recordId)
.list();

phNumber = 1;
Expand All @@ -253,7 +258,7 @@ else if (validField == null) {
StringUtils.join(fieldsOfApproval, ","));

List<Record> list = Application.createQueryNoFilter(sql)
.setParameter(1, this.recordId)
.setParameter(1, recordId)
.list();

phNumber = 1;
Expand Down Expand Up @@ -519,7 +524,8 @@ public static EasyExcelGenerator create(ID reportId, List<ID> recordIds) {
if (recordIds.size() == 1) {
return create(reportId, recordId);
} else {
TemplateFile tt = DataReportManager.instance.getTemplateFile(MetadataHelper.getEntity(recordId.getEntityCode()), reportId);
TemplateFile tt = DataReportManager.instance
.getTemplateFile(MetadataHelper.getEntity(recordId.getEntityCode()), reportId);
return new EasyExcelGenerator33(tt.templateFile, recordIds);
}
}
Expand All @@ -530,7 +536,8 @@ public static EasyExcelGenerator create(ID reportId, List<ID> recordIds) {
* @return
*/
public static EasyExcelGenerator create(ID reportId, ID recordId) {
TemplateFile tt = DataReportManager.instance.getTemplateFile(MetadataHelper.getEntity(recordId.getEntityCode()), reportId);
TemplateFile tt = DataReportManager.instance
.getTemplateFile(MetadataHelper.getEntity(recordId.getEntityCode()), reportId);
return create(tt.templateFile, recordId, tt.isV33);
}

Expand Down
Loading

0 comments on commit e6b2ea8

Please sign in to comment.