Commit 6448da90 authored by “yiyousong”'s avatar “yiyousong”
parents 650c003b 87ee3328
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
> >
</el-switch> </el-switch>
</el-form-item> </el-form-item>
<!--
<el-form-item label="上传附件" prop="fileUrl"> <el-form-item label="上传附件" prop="fileUrl">
<el-upload <el-upload
class="upload-demo" class="upload-demo"
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
<el-button size="small" type="primary">上传Word文件</el-button> <el-button size="small" type="primary">上传Word文件</el-button>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="上传模板" prop="templatePath"> <el-form-item label="上传模板" prop="templatePath">
<el-upload <el-upload
class="upload-demo" class="upload-demo"
:action="api + 'sampleform/file/commonupload'" :action="api + 'sampleform/file/commonupload'"
...@@ -67,7 +68,7 @@ ...@@ -67,7 +68,7 @@
> >
<el-button size="small" type="primary">上传Word文件</el-button> <el-button size="small" type="primary">上传Word文件</el-button>
</el-upload> </el-upload>
</el-form-item> </el-form-item>-->
<el-form-item label="上传样表" prop="samplePath"> <el-form-item label="上传样表" prop="samplePath">
<el-upload <el-upload
class="upload-demo" class="upload-demo"
...@@ -144,13 +145,13 @@ export default { ...@@ -144,13 +145,13 @@ export default {
materiaFullName: [ materiaFullName: [
{ required: true, message: "请输入全称", trigger: "blur" }, { required: true, message: "请输入全称", trigger: "blur" },
], ],
fileUrl: [{ required: true, message: "请上传表单", trigger: "change" }], // fileUrl: [{ required: true, message: "请上传表单", trigger: "change" }],
samplePath: [ samplePath: [
{ required: true, message: "请上传样表", trigger: "change" }, { required: true, message: "请上传样表", trigger: "change" },
], ],
templatePath: [ // templatePath: [
{ required: true, message: "请上传模板", trigger: "change" }, // { required: true, message: "请上传模板", trigger: "change" },
], // ],
}, },
headers: { headers: {
Authorization: local.getLocal("sampleToken") Authorization: local.getLocal("sampleToken")
......
...@@ -363,9 +363,9 @@ public class MatterDatumEntity extends MatterDatumVo { ...@@ -363,9 +363,9 @@ public class MatterDatumEntity extends MatterDatumVo {
this.isRecommend = 0; this.isRecommend = 0;
this.total = null; this.total = 0 ;
this.sort = null; this.sort = 0;
this.fileName = ""; this.fileName = "";
......
...@@ -99,18 +99,11 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD ...@@ -99,18 +99,11 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
@Override @Override
protected void saveBefore(MatterDatumEntity entity, Context context) throws AppException { protected void saveBefore(MatterDatumEntity entity, Context context) throws AppException {
if(StringUtils.isEmpty(entity.getFileUrl())){
throw new AppException("填单附件不能为空");
}
if(StringUtils.isEmpty(entity.getSamplePath())){ if(StringUtils.isEmpty(entity.getSamplePath())){
throw new AppException("样表地址不能为空"); 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 rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
String samplePath = rootPath + entity.getSamplePath(); String samplePath = rootPath + entity.getSamplePath();
...@@ -126,10 +119,6 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD ...@@ -126,10 +119,6 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
WordUtil.convertWordToJPEG(samplePath, filePathAll); WordUtil.convertWordToJPEG(samplePath, filePathAll);
entity.setPreViewPath(prePath + newName); entity.setPreViewPath(prePath + newName);
//校验模板变量正确性 todo
if (!ObjectUtils.isEmpty(entity.getTemplatePath())) {
parseDocxToJson(entity);
}
super.saveBefore(entity, context); super.saveBefore(entity, context);
} }
...@@ -154,148 +143,6 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD ...@@ -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 @Override
public String mergeFormToDoc(MatterDatumEntity docFormVo, Context context) { public String mergeFormToDoc(MatterDatumEntity docFormVo, Context context) {
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/"; 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