Commit 2bfbba99 authored by 赵啸非's avatar 赵啸非

修改配置文件1

parent bdcf1443
......@@ -30,6 +30,7 @@
>
</el-switch>
</el-form-item>
<!--
<el-form-item label="上传附件" prop="fileUrl">
<el-upload
class="upload-demo"
......@@ -45,7 +46,7 @@
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
</el-form-item>
<el-form-item label="上传模板" prop="templatePath">
<el-form-item label="上传模板" prop="templatePath">
<el-upload
class="upload-demo"
:action="api + 'sampleform/file/commonupload'"
......@@ -59,7 +60,7 @@
>
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
</el-form-item>
</el-form-item>-->
<el-form-item label="上传样表" prop="samplePath">
<el-upload
class="upload-demo"
......@@ -136,13 +137,13 @@ export default {
materiaFullName: [
{ required: true, message: "请输入全称", trigger: "blur" },
],
fileUrl: [{ required: true, message: "请上传表单", trigger: "change" }],
// fileUrl: [{ required: true, message: "请上传表单", trigger: "change" }],
samplePath: [
{ required: true, message: "请上传样表", trigger: "change" },
],
templatePath: [
{ required: true, message: "请上传模板", trigger: "change" },
],
// templatePath: [
// { required: true, message: "请上传模板", trigger: "change" },
// ],
},
headers: {
Authorization: local.getLocal("sampleToken")
......
......@@ -363,9 +363,9 @@ public class MatterDatumEntity extends MatterDatumVo {
this.isRecommend = 0;
this.total = null;
this.total = 0 ;
this.sort = null;
this.sort = 0;
this.fileName = "";
......
......@@ -99,18 +99,11 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
@Override
protected void saveBefore(MatterDatumEntity entity, Context context) throws AppException {
if(StringUtils.isEmpty(entity.getFileUrl())){
throw new AppException("填单附件不能为空");
}
if(StringUtils.isEmpty(entity.getSamplePath())){
throw new AppException("样表地址不能为空");
}
if(StringUtils.isEmpty(entity.getTemplatePath())){
throw new AppException("样表模板地址不能为空");
}
entity.setTotal(0);
entity.setSort(0);
entity.setIsRecommend(0);
//生成样表预览图片
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
String samplePath = rootPath + entity.getSamplePath();
......@@ -126,10 +119,6 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
WordUtil.convertWordToJPEG(samplePath, filePathAll);
entity.setPreViewPath(prePath + newName);
//校验模板变量正确性 todo
if (!ObjectUtils.isEmpty(entity.getTemplatePath())) {
parseDocxToJson(entity);
}
super.saveBefore(entity, context);
}
......@@ -154,148 +143,6 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
}
}
private void parseDocxToJson(MatterDatumEntity entity) {
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
String filepath = rootPath + entity.getTemplatePath();
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<>();
for (MetaTemplate item : template.getElementTemplates()) {
//识别简单输入
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());
cons.setUploadFileUrl(uploadUrl);
if (type.equalsIgnoreCase(ComponentEnum.DYNAMIC_TABLE.getValue())) {
List<TableColItem> colList = new ArrayList<>();
//表格 结构化绑定数据
ConfigureBuilder builderTable = Configure.builder();
builderTable.setValidErrorHandler(new Configure.DiscardHandler());
builderTable.useDefaultEL(false);
builderTable.buildGramer("[", "]");
XWPFTemplate templateTable = XWPFTemplate.compile(filepath, builderTable.build());
for (MetaTemplate col : templateTable.getElementTemplates()) {
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);
//System.out.println("列元素" + 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);
entity.setFormContent(JSON.toJSONString(root));
}
// public static void main(String[] arg){
// String filepath = "D:\\mortals\\app\\data\\file\\uploadfile\\1665472289712.docx";
// 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());
// System.out.println(template.getElementTemplates().toString());
// FormDesignRoot root = new FormDesignRoot();
// FormDesignConfig config = new FormDesignConfig();
// config.initAttribute();
// root.setConfig(config);
// List<ListItem> collect = new ArrayList<>();
// for (MetaTemplate item : template.getElementTemplates()) {
// //识别简单输入
// 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());
// cons.setUploadFileUrl("");
//
// if (type.equalsIgnoreCase(ComponentEnum.DYNAMIC_TABLE.getValue())) {
// List<TableColItem> colList = new ArrayList<>();
// //表格 结构化绑定数据
// ConfigureBuilder builderTable = Configure.builder();
// builderTable.setValidErrorHandler(new Configure.DiscardHandler());
// builderTable.useDefaultEL(false);
// builderTable.buildGramer("[", "]");
// XWPFTemplate templateTable = XWPFTemplate.compile(filepath, builderTable.build());
//
// for (MetaTemplate col : templateTable.getElementTemplates()) {
// 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);
// //System.out.println("列元素" + 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);
// System.out.println(JSON.toJSONString(root));
// }
@Override
public String mergeFormToDoc(MatterDatumEntity docFormVo, Context context) {
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
......
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