|
|
@@ -1,19 +1,34 @@
|
|
|
package com.lc.ibps.components.verification.model2;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.lc.ibps.components.verification.model.InspectionConfigVO;
|
|
|
import com.lc.ibps.components.verification.report.ChartDTO;
|
|
|
+import com.lc.ibps.components.verification.report.EchartsFreemarkerUtils;
|
|
|
import com.lc.ibps.components.verification.report.SheetDTO;
|
|
|
import com.lc.ibps.components.verification.report.TableDTO;
|
|
|
+import freemarker.cache.StringTemplateLoader;
|
|
|
+import freemarker.template.Configuration;
|
|
|
+import freemarker.template.Template;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.math3.distribution.ChiSquaredDistribution;
|
|
|
import org.apache.commons.math3.distribution.TDistribution;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.io.Writer;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public abstract class PVModel {
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(PVModel.class);
|
|
|
|
|
|
+ Configuration cfg;
|
|
|
+ private String reportTemplate;
|
|
|
+ private Map[] chartTemplate;
|
|
|
+
|
|
|
+ private List<String> chartNames;
|
|
|
private boolean isSupportItems;
|
|
|
private String itemName;
|
|
|
private int scale;
|
|
|
@@ -32,6 +47,25 @@ public abstract class PVModel {
|
|
|
this.specimensName = configVO.getSpecimensName();
|
|
|
this.itemName = configVO.getItemName();
|
|
|
this.isSupportItems = configVO.isSupportItems();
|
|
|
+
|
|
|
+ if(configVO.isUsingReportTemplate()){
|
|
|
+ this.reportTemplate = configVO.getReportTemplate();
|
|
|
+ cfg = new Configuration(Configuration.VERSION_2_3_30);
|
|
|
+ StringTemplateLoader stringLoader = new StringTemplateLoader();
|
|
|
+ stringLoader.putTemplate(itemName+"Report", reportTemplate);
|
|
|
+ cfg.setTemplateLoader(stringLoader);
|
|
|
+ if(StringUtils.isNotEmpty(configVO.getChartOption())) {
|
|
|
+ chartTemplate = JSON.parseObject(configVO.getChartOption(), Map[].class);
|
|
|
+ chartNames = new ArrayList<>();
|
|
|
+ for (Map chart : chartTemplate) {
|
|
|
+ String value = (String) chart.get("value");
|
|
|
+ String label = (String) chart.get("label");
|
|
|
+ chartNames.add(label);
|
|
|
+ stringLoader.putTemplate( label + "Chart", value.replaceAll("\\s*|\t|\r|\n", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public double[][] getData() {
|
|
|
@@ -222,4 +256,29 @@ public abstract class PVModel {
|
|
|
}
|
|
|
return reports;
|
|
|
}
|
|
|
+
|
|
|
+ protected String renderChartTemplate(Object ctx, int index, String filePath) {
|
|
|
+ return renderTemplate(ctx,chartNames.get(index)+"Chart",filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String renderReportTemplate(Object ctx, String filePath) {
|
|
|
+ return renderTemplate(ctx,itemName+"Report",filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String renderTemplate(Object ctx, String name, String filePath) {
|
|
|
+ if(cfg != null) {
|
|
|
+ Writer out = new StringWriter(2048);
|
|
|
+
|
|
|
+ try {
|
|
|
+ Template tpl = cfg.getTemplate(name, "utf-8");
|
|
|
+ tpl.process(ctx, out);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("Get template occurs error.", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return out.toString();
|
|
|
+ } else{
|
|
|
+ return EchartsFreemarkerUtils.generate(filePath, ctx);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|