Commit b318119e authored by 赵啸非's avatar 赵啸非

动态表单添加组件

parent 34e59e10
Pipeline #2885 canceled with stages
...@@ -16,6 +16,7 @@ import com.deepoove.poi.data.PictureRenderData; ...@@ -16,6 +16,7 @@ import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.data.PictureType; import com.deepoove.poi.data.PictureType;
import com.deepoove.poi.data.Pictures; import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.plugin.table.MultipleRowTableRenderPolicy; import com.deepoove.poi.plugin.table.MultipleRowTableRenderPolicy;
import com.deepoove.poi.render.RenderContext;
import com.deepoove.poi.template.MetaTemplate; import com.deepoove.poi.template.MetaTemplate;
import com.deepoove.poi.util.RegexUtils; import com.deepoove.poi.util.RegexUtils;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
...@@ -596,8 +597,96 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD ...@@ -596,8 +597,96 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
} }
public static FormDesignRoot parseLocalDocxToJson(String filepath) {
ConfigureBuilder builder = Configure.builder();
builder.setValidErrorHandler(new Configure.DiscardHandler());
builder.useDefaultEL(false);
builder.buildGrammerRegex(RegexUtils.createGeneral("{{", "}}"));
//builder.buildGramer("[","]");
XWPFTemplate template = XWPFTemplate.compile(filepath, builder.build());
FormDesignRoot root = new FormDesignRoot();
FormDesignConfig config = new FormDesignConfig();
config.initAttribute();
root.setConfig(config);
List<ListItem> collect = new ArrayList<>();
HashSet<String> hs = new HashSet<>(); //去除重复标签
for (MetaTemplate item : template.getElementTemplates()) {
if (hs.contains(item.variable())) {
continue;
} else {
hs.add(item.variable());
}
//识别简单输入
String val = StrUtil.strip(item.variable(), "{{", "}}");
List<String> keys = StrSplitter.split(val, "_", true, true);
//切分分隔符后动态 创建组件 i_1_姓名(第一个代表类型,第二个如果是多个累加,第三个显示label)
if (keys.size() > 2) {
String label = keys.get(2);
String type = keys.get(0);
ComponentCons cons = new ComponentCons();
cons.setLabel(label);
cons.setVal(val);
cons.setEl(item.variable());
if (type.equalsIgnoreCase(ComponentEnum.DYNAMIC_TABLE.getValue())) {
HashSet<String> dhs = new HashSet<>(); //去除重复标签
List<TableColItem> colList = new ArrayList<>();
//表格 结构化绑定数据
ConfigureBuilder builderTable = Configure.builder();
builderTable.setValidErrorHandler(new Configure.ValidErrorHandler() {
@Override
public void handler(RenderContext<?> context) {
log.info("111111111111111");
}
});
builderTable.useDefaultEL(false);
builderTable.buildGramer("[", "]");
builderTable.useSpringEL();
XWPFTemplate templateTable = XWPFTemplate.compile(filepath, builderTable.build());
for (MetaTemplate col : templateTable.getElementTemplates()) {
if (dhs.contains(col.variable())) {
continue;
} else {
dhs.add(col.variable());
}
String colVal = StrUtil.strip(col.variable(), "[", "]");
if (!StrUtil.startWith(colVal, label)) {
continue;
}
List<String> colKeys = StrSplitter.split(colVal, "_", true, true);
//提取当前table中的列元素
if (colKeys.size() > 3) {
String colLabel = colKeys.get(3);
String colType = colKeys.get(1);
TableColItem tableColItem = new TableColItem();
tableColItem.setLabel(colLabel);
tableColItem.setColType(colType);
tableColItem.setVal(colVal);
colList.add(tableColItem);
log.info("列元素" + col.variable());
}
}
cons.setColList(colList);
DesignComponent designComponent = DesignComponent.createType(type);
ListItem listItem = designComponent.buildDefaultComponent(cons);
collect.add(listItem);
continue;
}
DesignComponent designComponent = DesignComponent.createType(type);
ListItem listItem = designComponent.buildDefaultComponent(cons);
collect.add(listItem);
}
}
root.setList(collect);
return root;
}
public static void main(String[] args) { public static void main(String[] args) {
String colVal = "i_1_变更登记事项"; /* String colVal = "i_1_变更登记事项";
List<String> colKeys = StrSplitter.split(colVal, "_", true, true); List<String> colKeys = StrSplitter.split(colVal, "_", true, true);
System.out.println(colKeys.size()); System.out.println(colKeys.size());
...@@ -609,12 +698,21 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD ...@@ -609,12 +698,21 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
List<String> strings1 = splitIter.toList(true); List<String> strings1 = splitIter.toList(true);
strings1.forEach(item -> { strings1.forEach(item -> {
System.out.println(item); System.out.println(item);
}); });*/
// String[] strings = StrSplitter.splitByLength(colVal, 1); // String[] strings = StrSplitter.splitByLength(colVal, 1);
// for (int i = 0; i <strings.length ; i++) { // for (int i = 0; i <strings.length ; i++) {
// System.out.println(strings[i]); // System.out.println(strings[i]);
// } // }
String filePath="F:\\1.docx";
FormDesignRoot formDesignRoot = parseLocalDocxToJson(filePath);
System.out.println(JSON.toJSONString(formDesignRoot));
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment