Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fill-system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
廖旭伟
fill-system
Commits
046c6fdf
Commit
046c6fdf
authored
Oct 08, 2022
by
廖旭伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改接口文档,增加主页接口
parent
0421bb2c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
426 additions
and
257 deletions
+426
-257
fill-manager/pom.xml
fill-manager/pom.xml
+6
-0
fill-manager/src/main/java/com/mortals/xhx/common/utils/ExportDocUtil.java
...main/java/com/mortals/xhx/common/utils/ExportDocUtil.java
+11
-149
fill-manager/src/main/java/com/mortals/xhx/common/utils/WordUtil.java
.../src/main/java/com/mortals/xhx/common/utils/WordUtil.java
+45
-43
fill-manager/src/main/java/com/mortals/xhx/module/home/web/HomeController.java
.../java/com/mortals/xhx/module/home/web/HomeController.java
+30
-0
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/MatterDatumService.java
...mortals/xhx/module/matter/service/MatterDatumService.java
+9
-0
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
...hx/module/matter/service/impl/MatterDatumServiceImpl.java
+325
-64
fill-manager/src/main/java/com/mortals/xhx/module/matter/web/MatterDatumController.java
.../mortals/xhx/module/matter/web/MatterDatumController.java
+0
-1
No files found.
fill-manager/pom.xml
View file @
046c6fdf
...
@@ -134,6 +134,12 @@
...
@@ -134,6 +134,12 @@
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-mock
</artifactId>
<version>
2.0.8
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.aspose.words
</groupId>
<groupId>
com.aspose.words
</groupId>
<artifactId>
aspose-words
</artifactId>
<artifactId>
aspose-words
</artifactId>
...
...
fill-manager/src/main/java/com/mortals/xhx/common/utils/ExportDocUtil.java
View file @
046c6fdf
...
@@ -410,156 +410,18 @@ public class ExportDocUtil {
...
@@ -410,156 +410,18 @@ public class ExportDocUtil {
//log.info("deletePathList:" + JSON.toJSONString(deletePathList));
//log.info("deletePathList:" + JSON.toJSONString(deletePathList));
}
}
public
static
String
createCheckBoxStrOther
(
Boolean
checked
,
String
label
)
{
StringBuilder
sb
=
new
StringBuilder
();
if
(
checked
)
{
String
ckHeader
=
"☑"
;
@SneakyThrows
sb
.
append
(
ckHeader
);
public
static
void
main
(
String
[]
args
)
{
}
else
{
//解析xml文档,修改非法的$表达式为合法
String
ckHeader
=
"□"
;
File
file
=
new
File
(
"E:\\pic\\doc\\临时占用城市道路申请表(样表).xml"
);
sb
.
append
(
ckHeader
);
}
Document
document
=
XmlUtil
.
readXML
(
file
);
sb
.
append
(
label
);
return
sb
.
toString
();
List
<
NodeEntity
>
list
=
new
ArrayList
<>();
ExportDocUtil
.
parseXMLFile
(
list
,
"E:\\pic\\doc\\临时占用城市道路申请表(样表).xml"
);
//log.info(JSON.toJSONString(list));
//list.stream().filter(f -> "3".equals(f.get("NodeType")) && !"".equals(f.get("content"))).peek(item -> log.info(item.get("content"))).count();
ExportDocUtil
.
checkAndUpdateExpressionByDocument
(
document
,
list
);
XmlUtil
.
toFile
(
document
,
"E:\\pic\\doc\\临时占用城市道路申请表(样表)修正.xml"
);
//System.out.println(XmlUtil.format(document));
// Map root = new HashMap();
// root.put(
// "doc",
// freemarker.ext.dom.NodeModel.parse(new File("the/path/of/the.xml")));
//
//
// String ckStr=" <#list><w:r>\n" +
// "\t\t\t\t\t\t\t\t\t\t<w:rPr>\n" +
// "\t\t\t\t\t\t\t\t\t\t\t<w:rFonts w:ascii=\"宋体\" w:h-ansi=\"宋体\"/>\n" +
// "\t\t\t\t\t\t\t\t\t\t\t<wx:font wx:val=\"宋体\"/>\n" +
// "\t\t\t\t\t\t\t\t\t\t</w:rPr>\n" +
// "\t\t\t\t\t\t\t\t\t\t<w:sym w:font=\"Wingdings 2\" w:char=\"0052\"/>\n" +
// "\t\t\t\t\t\t\t\t\t</w:r></#list>";
//
// XmlUtil.parseXml(ckStr);
//<#list columns as column>
// Document xml = XmlUtil.createXml();
// Element element = xml.createElement("#list");
// xml.appendChild(element);
// Element elementPr = xml.createElement("w:rPr");
// element.appendChild(elementPr);
//
// Element elementFonts = xml.createElement("w:rFonts");
// elementFonts.setAttribute("w:ascii","宋体");
// elementFonts.setAttribute("w:h-ansi","宋体");
// elementPr.appendChild(elementFonts);
// Element elementFont = xml.createElement("wx:font");
// elementFont.setAttribute("wx:val","宋体");
// elementPr.appendChild(elementFont);
// System.out.println(ExportDocUtil.getStringFromDocument(xml));
// System.out.println(XmlUtil.format(xml));
// System.out.println(XmlUtil.toStr(element,"utf-8",true,false));
// String imagepath="E:\\pic\\1.png";
//
// BufferedImage image = ImgUtil.read(imagepath);
//
// String png = ImgUtil.toBase64(image, "png");
//
// System.out.println(png);
//
// String path = "E:\\新建文件夹\\测试.doc";
//
//// String path = "E:\\pic\\doc\\附件1-四川省危险废物经营许可证申请表(补办)空白.xml";
////
// List<Map<String, String>> list = new ArrayList<>();
//
// ExportDocUtil.parseXMLFile(list, path);
//
// //查找w:binData的节点路径
//
// //1.
// String id = "";
// List<String> paths = new ArrayList<>();
// for (Map<String, String> map : list) {
// if ("w:binData".equals(map.get("TagName"))) {
// System.out.println("id:" + map.get("id"));
// System.out.println("parentId:" + map.get("parentId"));
// id = map.get("parentId");
// paths.add(map.get("TagName"));
// break;
// }
// }
// ExportDocUtil.getPath(paths, list, id);
// System.out.println(JSON.toJSONString(paths));
// Document document = XmlUtil.readXML(new File(path));
// NamespaceContext ns = ExportDocUtil.buildNsByDocument(document);
// paths = CollUtil.reverse(paths);
//
// String xpath = "/" + paths.stream().collect(Collectors.joining("/"));
//
// System.out.println("xpath:" + xpath);
//
// Node byXPath = (Node) XmlUtil.getByXPath(xpath, document, XPathConstants.NODE, ns);
// byXPath.setTextContent("${image1}");
//
// System.out.println(XmlUtil.toStr(document));
//System.out.println("xPath"+byXPath.setTextContent(););
// xpath="//*[name()='wordml://02000001.jpg']";
// document.getElementById()
//List<Element> nodeList = document.selectNodes(xpath).selectNodes("//w:tbl//w:tr//w:tc//w:p//w:r//w:t");
//DefaultNamespaceContext defaultNamespaceContext = DefaultNamespaceContext.create(document);
//通过dom xpath 获取节点值 并修改
//Element elementByXPath = XmlUtil.getRootElement(document).getElementsByTagName(document., "w:binData");
//System.out.println("xpath element:"+elementByXPath.getTextContent());
//System.out.println(JSON.toJSONString(list));
// File file = new File("E:\\pic\\doc\\doc.xml");
//
// Document document = XmlUtil.readXML(file);
//
// Element element = document.getDocumentElement();
//
// // 第一次调用,就是第一级,parent_id 就给空
// ExportDocUtil.parseElement(list,element,"");
//
// NodeList childNodes = document.getChildNodes();
// System.out.println("size:"+childNodes.getLength());
// for(int i=0;i<childNodes.getLength();i++){
// Node item = childNodes.item(i);
//
// if(!"".equals(item.getTextContent().trim())){
// //System.out.println(item.getNodeValue());
//
// System.out.println(item.getTextContent().trim());
// }
// }
}
}
}
}
fill-manager/src/main/java/com/mortals/xhx/common/utils/WordUtil.java
View file @
046c6fdf
...
@@ -3,6 +3,9 @@ package com.mortals.xhx.common.utils;
...
@@ -3,6 +3,9 @@ package com.mortals.xhx.common.utils;
//import com.aspose.words.Document;
//import com.aspose.words.Document;
//import com.aspose.words.ImageSaveOptions;
//import com.aspose.words.ImageSaveOptions;
//import com.aspose.words.SaveFormat;
//import com.aspose.words.SaveFormat;
import
com.aspose.words.Document
;
import
com.aspose.words.ImageSaveOptions
;
import
com.aspose.words.SaveFormat
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.util.DateUtils
;
import
com.mortals.framework.util.DateUtils
;
import
freemarker.template.Configuration
;
import
freemarker.template.Configuration
;
...
@@ -89,49 +92,48 @@ public class WordUtil {
...
@@ -89,49 +92,48 @@ public class WordUtil {
}
}
public
static
String
convertWordToJPEG
(
String
inputFile
,
String
jpegPath
)
{
public
static
String
convertWordToJPEG
(
String
inputFile
,
String
jpegPath
)
{
// try {
try
{
// System.out.println(String.format("文件转换开始:%s", DateUtils.getCurrStrDateTime()));
System
.
out
.
println
(
String
.
format
(
"文件转换开始:%s"
,
DateUtils
.
getCurrStrDateTime
()));
// // 转换开始前时间
// 转换开始前时间
// long old = System.currentTimeMillis();
long
old
=
System
.
currentTimeMillis
();
// // 新建的PDF文件路径
// 新建的PDF文件路径
// File file = new File(jpegPath);
File
file
=
new
File
(
jpegPath
);
// //FileOutputStream os = new FileOutputStream(file);
//FileOutputStream os = new FileOutputStream(file);
// // 要转换的word文档的路径
// 要转换的word文档的路径
// Document doc = new Document(inputFile);
Document
doc
=
new
Document
(
inputFile
);
//
// // 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
// //doc.save(os, SaveFormat.JPEG);
//doc.save(os, SaveFormat.JPEG);
//
//
//
// ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
ImageSaveOptions
options
=
new
ImageSaveOptions
(
SaveFormat
.
JPEG
);
// options.setPrettyFormat(true);
options
.
setPrettyFormat
(
true
);
// options.setUseAntiAliasing(true);
options
.
setUseAntiAliasing
(
true
);
// options.setUseHighQualityRendering(true);
options
.
setUseHighQualityRendering
(
true
);
// int pageCount = doc.getPageCount();
int
pageCount
=
doc
.
getPageCount
();
//
// List<BufferedImage> imageList = new ArrayList<BufferedImage>();
List
<
BufferedImage
>
imageList
=
new
ArrayList
<
BufferedImage
>();
// for (int i = 0; i < pageCount; i++) {
for
(
int
i
=
0
;
i
<
pageCount
;
i
++)
{
// OutputStream output = new ByteArrayOutputStream();
OutputStream
output
=
new
ByteArrayOutputStream
();
// options.setPageIndex(i);
options
.
setPageIndex
(
i
);
// doc.save(output, options);
doc
.
save
(
output
,
options
);
// ImageInputStream imageInputStream = ImageIO.createImageInputStream(parse(output));
ImageInputStream
imageInputStream
=
ImageIO
.
createImageInputStream
(
parse
(
output
));
// imageList.add(ImageIO.read(imageInputStream));
imageList
.
add
(
ImageIO
.
read
(
imageInputStream
));
// }
}
//
// BufferedImage mergeImage = mergeImage(false, imageList);
BufferedImage
mergeImage
=
mergeImage
(
false
,
imageList
);
//
// ImageIO.write(mergeImage, "png", file);
ImageIO
.
write
(
mergeImage
,
"png"
,
file
);
// // 转换结束后时间
// 转换结束后时间
// long now = System.currentTimeMillis();
long
now
=
System
.
currentTimeMillis
();
// //os.close();
//os.close();
// System.out.println("文件转换结束,共耗时:" + ((now - old) / 1000.0) + "秒");
System
.
out
.
println
(
"文件转换结束,共耗时:"
+
((
now
-
old
)
/
1000.0
)
+
"秒"
);
// return jpegPath;
return
jpegPath
;
// } catch (Exception e) {
}
catch
(
Exception
e
)
{
// e.printStackTrace();
e
.
printStackTrace
();
// throw new AppException(String.format("文件转换异常!", e.getMessage()));
throw
new
AppException
(
String
.
format
(
"文件转换异常!"
,
e
.
getMessage
()));
// }
}
return
""
;
}
}
...
...
fill-manager/src/main/java/com/mortals/xhx/module/home/web/HomeController.java
View file @
046c6fdf
...
@@ -21,6 +21,8 @@ import com.mortals.xhx.feign.device.IApiDeviceFeign;
...
@@ -21,6 +21,8 @@ import com.mortals.xhx.feign.device.IApiDeviceFeign;
import
com.mortals.xhx.feign.device.pdu.DevicePdu
;
import
com.mortals.xhx.feign.device.pdu.DevicePdu
;
import
com.mortals.xhx.feign.rsp.ApiResp
;
import
com.mortals.xhx.feign.rsp.ApiResp
;
import
com.mortals.xhx.module.home.pdu.HomeQueryPdu
;
import
com.mortals.xhx.module.home.pdu.HomeQueryPdu
;
import
com.mortals.xhx.module.matter.model.MatterDatumEntity
;
import
com.mortals.xhx.module.matter.service.MatterDatumService
;
import
org.checkerframework.checker.units.qual.A
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
@@ -38,6 +40,8 @@ public class HomeController extends BaseJsonBodyController {
...
@@ -38,6 +40,8 @@ public class HomeController extends BaseJsonBodyController {
private
IApiBaseManagerFeign
iApiBaseManagerFeign
;
private
IApiBaseManagerFeign
iApiBaseManagerFeign
;
@Autowired
@Autowired
private
IApiDeviceFeign
iApiDeviceFeign
;
private
IApiDeviceFeign
iApiDeviceFeign
;
@Autowired
private
MatterDatumService
matterDatumService
;
@PostMapping
({
"site/list"
})
@PostMapping
({
"site/list"
})
public
Rest
<
Object
>
list
()
{
public
Rest
<
Object
>
list
()
{
...
@@ -171,4 +175,30 @@ public class HomeController extends BaseJsonBodyController {
...
@@ -171,4 +175,30 @@ public class HomeController extends BaseJsonBodyController {
ret
.
setMsg
(
model
.
get
(
"message_info"
)
==
null
?
""
:
model
.
remove
(
"message_info"
).
toString
());
ret
.
setMsg
(
model
.
get
(
"message_info"
)
==
null
?
""
:
model
.
remove
(
"message_info"
).
toString
());
return
ret
;
return
ret
;
}
}
/**
* 合成表单与模板
*/
@PostMapping
(
value
=
"mergeFormToDocx"
)
@UnAuth
public
String
mergeFormToDocx
(
@RequestBody
MatterDatumEntity
docFormVo
)
{
JSONObject
jsonObject
=
new
JSONObject
();
try
{
String
paths
=
matterDatumService
.
mergeFormToDoc
(
docFormVo
,
getContext
());
String
[]
vals
=
paths
.
split
(
";"
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
jsonObject
.
put
(
"mergeDoc"
,
vals
[
0
]);
jsonObject
.
put
(
"preview"
,
vals
[
1
]);
//todo 保存表单数据
// docFormVo.setCreateTime(new Date());
// docFormVo.setCreateUserId(getContextUserId(getContext()));
// docFormVo.setCreateUser("");
// docFormService.save(docFormVo, getContext());
}
catch
(
Exception
e
)
{
log
.
error
(
"合成表单异常"
,
e
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
jsonObject
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
}
return
jsonObject
.
toJSONString
();
}
}
}
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/MatterDatumService.java
View file @
046c6fdf
package
com.mortals.xhx.module.matter.service
;
package
com.mortals.xhx.module.matter.service
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.xhx.module.matter.model.MatterDatumEntity
;
import
com.mortals.xhx.module.matter.model.MatterDatumEntity
;
/**
/**
...
@@ -11,4 +12,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity;
...
@@ -11,4 +12,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity;
*/
*/
public
interface
MatterDatumService
extends
ICRUDService
<
MatterDatumEntity
,
Long
>{
public
interface
MatterDatumService
extends
ICRUDService
<
MatterDatumEntity
,
Long
>{
/**
* 合成doc数据模板
* @param context
* @return
*/
String
mergeFormToDoc
(
MatterDatumEntity
docFormVo
,
Context
context
);
}
}
\ No newline at end of file
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
View file @
046c6fdf
package
com.mortals.xhx.module.matter.service.impl
;
package
com.mortals.xhx.module.matter.service.impl
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.text.StrSplitter
;
import
cn.hutool.core.text.StrSplitter
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.deepoove.poi.XWPFTemplate
;
import
com.deepoove.poi.XWPFTemplate
;
import
com.deepoove.poi.config.Configure
;
import
com.deepoove.poi.config.Configure
;
import
com.deepoove.poi.config.ConfigureBuilder
;
import
com.deepoove.poi.config.ConfigureBuilder
;
import
com.deepoove.poi.data.PictureRenderData
;
import
com.deepoove.poi.data.PictureType
;
import
com.deepoove.poi.data.Pictures
;
import
com.deepoove.poi.plugin.table.MultipleRowTableRenderPolicy
;
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.databind.ObjectMapper
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.xhx.base.system.upload.service.UploadService
;
import
com.mortals.xhx.common.code.ComponentEnum
;
import
com.mortals.xhx.common.code.ComponentEnum
;
import
com.mortals.xhx.common.formdesign.*
;
import
com.mortals.xhx.common.formdesign.*
;
import
com.mortals.xhx.common.pdu.gen.component.ComponentCons
;
import
com.mortals.xhx.common.pdu.gen.component.ComponentCons
;
import
com.mortals.xhx.common.utils.ExportDocUtil
;
import
com.mortals.xhx.common.utils.WordUtil
;
import
com.mortals.xhx.common.utils.WordUtil
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.http.entity.ContentType
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
...
@@ -23,10 +38,12 @@ import com.mortals.xhx.module.matter.dao.MatterDatumDao;
...
@@ -23,10 +38,12 @@ import com.mortals.xhx.module.matter.dao.MatterDatumDao;
import
com.mortals.xhx.module.matter.model.MatterDatumEntity
;
import
com.mortals.xhx.module.matter.model.MatterDatumEntity
;
import
com.mortals.xhx.module.matter.service.MatterDatumService
;
import
com.mortals.xhx.module.matter.service.MatterDatumService
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* MatterDatumService
* MatterDatumService
* 事项申请材料 service实现
* 事项申请材料 service实现
...
@@ -36,10 +53,13 @@ import java.util.List;
...
@@ -36,10 +53,13 @@ import java.util.List;
*/
*/
@Service
(
"matterDatumService"
)
@Service
(
"matterDatumService"
)
public
class
MatterDatumServiceImpl
extends
AbstractCRUDServiceImpl
<
MatterDatumDao
,
MatterDatumEntity
,
Long
>
implements
MatterDatumService
{
public
class
MatterDatumServiceImpl
extends
AbstractCRUDServiceImpl
<
MatterDatumDao
,
MatterDatumEntity
,
Long
>
implements
MatterDatumService
{
@Value
(
"${upload.path}"
)
@Value
(
"${upload.path}"
)
private
String
filePath
;
private
String
filePath
;
@Value
(
"${upload.url:http://localhost:1
8001
/fsm/file/commonupload?prePath=/file/uploadfile}"
)
@Value
(
"${upload.url:http://localhost:1
7215
/fsm/file/commonupload?prePath=/file/uploadfile}"
)
private
String
uploadUrl
;
private
String
uploadUrl
;
@Autowired
private
UploadService
uploadService
;
@Override
@Override
protected
void
saveBefore
(
MatterDatumEntity
entity
,
Context
context
)
throws
AppException
{
protected
void
saveBefore
(
MatterDatumEntity
entity
,
Context
context
)
throws
AppException
{
...
@@ -138,73 +158,314 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
...
@@ -138,73 +158,314 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
}
}
public
static
void
main
(
String
[]
arg
){
// public static void main(String[] arg){
String
filepath
=
"D:\\mortals\\app\\data\\file\\uploadfile\\1663917302157.docx"
;
// String filepath = "D:\\mortals\\app\\data\\file\\uploadfile\\1663917302157.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
)
{
//转换表单参数为map集合
ObjectMapper
mapper
=
new
ObjectMapper
();
ConfigureBuilder
builder
=
Configure
.
builder
();
ConfigureBuilder
builder
=
Configure
.
builder
();
builder
.
setValidErrorHandler
(
new
Configure
.
DiscardHandler
());
builder
.
useDefaultEL
(
false
);
builder
.
buildGrammerRegex
(
RegexUtils
.
createGeneral
(
"{{"
,
"}}"
));
builder
.
buildGrammerRegex
(
RegexUtils
.
createGeneral
(
"{{"
,
"}}"
));
//builder.buildGramer("[","]");
try
{
XWPFTemplate
template
=
XWPFTemplate
.
compile
(
filepath
,
builder
.
build
());
Map
<
String
,
Object
>
data
=
mapper
.
readValue
(
docFormVo
.
getFormContent
(),
Map
.
class
);
System
.
out
.
println
(
template
.
getElementTemplates
().
toString
());
//遍历查看是否有图片数据,多选框
FormDesignRoot
root
=
new
FormDesignRoot
();
data
.
entrySet
().
stream
().
forEach
(
entry
->
{
FormDesignConfig
config
=
new
FormDesignConfig
();
if
(
entry
.
getKey
().
indexOf
(
"@image"
)
!=
-
1
)
{
config
.
initAttribute
();
//获取值 读取本地图片
root
.
setConfig
(
config
);
String
imagepath
=
uploadService
.
getFilePath
(
entry
.
getValue
().
toString
());
List
<
ListItem
>
collect
=
new
ArrayList
<>();
log
.
info
(
"Image path: "
+
imagepath
);
for
(
MetaTemplate
item
:
template
.
getElementTemplates
())
{
try
{
//识别简单输入
PictureRenderData
pictureRenderData
=
Pictures
.
ofStream
(
new
FileInputStream
(
imagepath
),
PictureType
.
JPEG
)
String
val
=
StrUtil
.
strip
(
item
.
variable
(),
"{{"
,
"}}"
);
.
size
(
100
,
120
).
create
();
List
<
String
>
keys
=
StrSplitter
.
split
(
val
,
"_"
,
true
,
true
);
data
.
put
(
StrUtil
.
removePrefixIgnoreCase
(
entry
.
getKey
(),
"@"
),
pictureRenderData
);
//切分分隔符后动态 创建组件 i_1_姓名(第一个代表类型,第二个如果是多个累加,第三个显示label)
//entry.setValue(pictureRenderData);
if
(
keys
.
size
()
>
2
)
{
}
catch
(
FileNotFoundException
e
)
{
String
label
=
keys
.
get
(
2
);
log
.
error
(
"error"
,
e
);
String
type
=
keys
.
get
(
0
);
}
ComponentCons
cons
=
new
ComponentCons
();
}
cons
.
setLabel
(
label
);
//构建填充复选框值
cons
.
setVal
(
val
);
if
(
entry
.
getKey
().
indexOf
(
"ck_"
)
!=
-
1
&&
entry
.
getKey
().
indexOf
(
"<"
)
!=
-
1
)
{
cons
.
setEl
(
item
.
variable
());
//获取复选框选项,并渲染值
cons
.
setUploadFileUrl
(
""
);
String
ckStr
=
StringUtils
.
substringBetween
(
entry
.
getKey
(),
"<"
,
">"
);
//获取所有选项
List
<
String
>
checkboxs
=
StrUtil
.
splitTrim
(
ckStr
,
"-"
,
-
1
);
//选中的项
List
<
String
>
ckList
=
Convert
.
toList
(
String
.
class
,
entry
.
getValue
());
//合并
String
ckStrs
=
checkboxs
.
stream
().
map
(
item
->
{
for
(
String
checked
:
ckList
)
{
if
(
checked
.
equals
(
item
))
{
Map
<
Boolean
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
true
,
item
);
return
map
;
}
}
Map
<
Boolean
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
false
,
item
);
return
map
;
}).
map
(
m
->
m
.
entrySet
().
stream
().
map
(
m1
->
ExportDocUtil
.
createCheckBoxStrOther
(
m1
.
getKey
(),
m1
.
getValue
())).
findFirst
().
orElseGet
(()
->
""
)
).
collect
(
Collectors
.
joining
(
""
));
entry
.
setValue
(
ckStrs
);
}
//TODO 单选
//绑定动态表单
if
(
entry
.
getKey
().
indexOf
(
"dt_"
)
!=
-
1
)
{
builder
.
bind
(
entry
.
getKey
(),
new
MultipleRowTableRenderPolicy
());
}
});
//查询是否有多选框,
//获取模板文件地址
MatterDatumEntity
docTemplateEntity
=
this
.
get
(
docFormVo
.
getId
(),
context
);
if
(!
ObjectUtils
.
isEmpty
(
docTemplateEntity
))
{
String
path
=
filePath
+
docTemplateEntity
.
getTemplatePath
();
String
templateName
=
FileUtil
.
getName
(
path
);
Configure
config
=
builder
.
build
();
XWPFTemplate
template
=
null
;
ByteArrayOutputStream
byteArrayOutputStream
=
null
;
try
{
template
=
XWPFTemplate
.
compile
(
path
,
config
).
render
(
data
);
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
template
.
write
(
byteArrayOutputStream
);
if
(
type
.
equalsIgnoreCase
(
ComponentEnum
.
DYNAMIC_TABLE
.
getValue
()))
{
MultipartFile
multipartFile
=
new
MockMultipartFile
(
templateName
,
templateName
,
List
<
TableColItem
>
colList
=
new
ArrayList
<>();
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
byteArrayOutputStream
.
toByteArray
());
//表格 结构化绑定数据
String
mergedocPath
=
uploadService
.
saveFileUpload
(
multipartFile
,
"/mergedoc"
,
context
.
getUser
());
ConfigureBuilder
builderTable
=
Configure
.
builder
();
log
.
info
(
"mergedocPath:"
+
mergedocPath
);
builderTable
.
setValidErrorHandler
(
new
Configure
.
DiscardHandler
());
String
mergedoc
=
this
.
filePath
+
mergedocPath
;
builderTable
.
useDefaultEL
(
false
);
//转换预览图片
builderTable
.
buildGramer
(
"["
,
"]"
);
String
fileName
=
RandomUtil
.
randomNumbers
(
12
)
+
".jpg"
;
XWPFTemplate
templateTable
=
XWPFTemplate
.
compile
(
filepath
,
builderTable
.
build
());
String
preView
=
this
.
filePath
+
"/preview/"
+
fileName
;
WordUtil
.
convertWordToJPEG
(
mergedoc
,
preView
);
log
.
info
(
"preView:"
+
mergedocPath
);
//下载地址拼装
String
returnStr
=
mergedocPath
+
";"
+
"/preview/"
+
fileName
;
return
returnStr
;
}
catch
(
Exception
e
)
{
log
.
error
(
"渲染模板失败:"
,
e
);
}
finally
{
try
{
template
.
close
();
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"ioEx:"
,
e
);
}
}
}
}
catch
(
JsonProcessingException
e
)
{
log
.
error
(
"转换异常"
,
e
);
throw
new
AppException
(
"表单参数转换异常:"
+
e
.
getMessage
());
}
return
""
;
}
for
(
MetaTemplate
col
:
templateTable
.
getElementTemplates
())
{
String
colVal
=
StrUtil
.
strip
(
col
.
variable
(),
"["
,
"]"
);
public
static
void
main
(
String
[]
args
){
if
(!
StrUtil
.
startWith
(
colVal
,
label
))
{
String
filePath
=
"D:\\mortals\\app\\data\\file\\uploadfile\\1663917302157.docx"
;
continue
;
String
formContent
=
"{\n"
+
}
" \"i_1_班级\": \"432432\",\n"
+
List
<
String
>
colKeys
=
StrSplitter
.
split
(
colVal
,
"_"
,
true
,
true
);
" \"i_2_姓名\": \"324\",\n"
+
//提取当前table中的列元素
" \"i_3_监护人\": \"234\",\n"
+
if
(
colKeys
.
size
()
>
3
)
{
" \"i_4_电话\": \"324\",\n"
+
String
colLabel
=
colKeys
.
get
(
3
);
" \"dt_1_汇报\": [\n"
+
String
colType
=
colKeys
.
get
(
1
);
" {\n"
+
TableColItem
tableColItem
=
new
TableColItem
();
" \"汇报_date_1_日期\": \"2022-09-06\",\n"
+
tableColItem
.
setLabel
(
colLabel
);
" \"汇报_i_4_有无出现呕吐\": \"543\",\n"
+
tableColItem
.
setColType
(
colType
);
" \"汇报_i_5_有无其他\": \"435\",\n"
+
tableColItem
.
setVal
(
colVal
);
" \"汇报_i_6_有无接触\": \"345\",\n"
+
colList
.
add
(
tableColItem
);
" \"index\": 0\n"
+
//System.out.println("列元素" + col.variable());
" },\n"
+
" {\n"
+
" \"汇报_date_1_日期\": \"\",\n"
+
" \"汇报_i_4_有无出现呕吐\": \"\",\n"
+
" \"汇报_i_5_有无其他\": \"\",\n"
+
" \"汇报_i_6_有无接触\": \"\",\n"
+
" \"index\": 1\n"
+
" },\n"
+
" {\n"
+
" \"汇报_date_1_日期\": null,\n"
+
" \"汇报_i_4_有无出现呕吐\": \"\",\n"
+
" \"汇报_i_5_有无其他\": \"\",\n"
+
" \"汇报_i_6_有无接触\": \"\",\n"
+
" \"index\": 2\n"
+
" }\n"
+
" ],\n"
+
" \"i_5_誉抄\": \"435\",\n"
+
" \"date_1_填表年月日\": \"2022年09月07日\"\n"
+
"}"
;
//转换表单参数为map集合
ObjectMapper
mapper
=
new
ObjectMapper
();
ConfigureBuilder
builder
=
Configure
.
builder
();
builder
.
buildGrammerRegex
(
RegexUtils
.
createGeneral
(
"{{"
,
"}}"
));
try
{
Map
<
String
,
Object
>
data
=
mapper
.
readValue
(
formContent
,
Map
.
class
);
//遍历查看是否有图片数据,多选框
data
.
entrySet
().
stream
().
forEach
(
entry
->
{
// if (entry.getKey().indexOf("@image") != -1) {
// //获取值 读取本地图片
// String imagepath = uploadService.getFilePath(entry.getValue().toString());
// log.info("Image path: " + imagepath);
// try {
// PictureRenderData pictureRenderData = Pictures.ofStream(new FileInputStream(imagepath), PictureType.JPEG)
// .size(100, 120).create();
// data.put(StrUtil.removePrefixIgnoreCase(entry.getKey(),"@"),pictureRenderData);
// //entry.setValue(pictureRenderData);
// } catch (FileNotFoundException e) {
// log.error("error", e);
// }
// }
//构建填充复选框值
if
(
entry
.
getKey
().
indexOf
(
"ck_"
)
!=
-
1
&&
entry
.
getKey
().
indexOf
(
"<"
)
!=
-
1
)
{
//获取复选框选项,并渲染值
String
ckStr
=
StringUtils
.
substringBetween
(
entry
.
getKey
(),
"<"
,
">"
);
//获取所有选项
List
<
String
>
checkboxs
=
StrUtil
.
splitTrim
(
ckStr
,
"-"
,
-
1
);
//选中的项
List
<
String
>
ckList
=
Convert
.
toList
(
String
.
class
,
entry
.
getValue
());
//合并
String
ckStrs
=
checkboxs
.
stream
().
map
(
item
->
{
for
(
String
checked
:
ckList
)
{
if
(
checked
.
equals
(
item
))
{
Map
<
Boolean
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
true
,
item
);
return
map
;
}
}
}
}
Map
<
Boolean
,
String
>
map
=
new
HashMap
<>();
cons
.
setColList
(
colList
);
map
.
put
(
false
,
item
);
DesignComponent
designComponent
=
DesignComponent
.
createType
(
type
);
return
map
;
ListItem
listItem
=
designComponent
.
buildDefaultComponent
(
cons
);
}).
map
(
m
->
m
.
entrySet
().
stream
().
map
(
m1
->
ExportDocUtil
.
createCheckBoxStrOther
(
m1
.
getKey
(),
m1
.
getValue
())).
findFirst
().
orElseGet
(()
->
""
)
collect
.
add
(
listItem
);
).
collect
(
Collectors
.
joining
(
""
));
continue
;
entry
.
setValue
(
ckStrs
);
}
//TODO 单选
//绑定动态表单
if
(
entry
.
getKey
().
indexOf
(
"dt_"
)
!=
-
1
)
{
builder
.
bind
(
entry
.
getKey
(),
new
MultipleRowTableRenderPolicy
());
}
});
//查询是否有多选框,
String
path
=
filePath
;
String
templateName
=
FileUtil
.
getName
(
path
);
Configure
config
=
builder
.
build
();
XWPFTemplate
template
=
null
;
ByteArrayOutputStream
byteArrayOutputStream
=
null
;
try
{
template
=
XWPFTemplate
.
compile
(
path
,
config
).
render
(
data
);
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
template
.
write
(
byteArrayOutputStream
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
templateName
,
templateName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
byteArrayOutputStream
.
toByteArray
());
//String mergedocPath = uploadService.saveFileUpload(multipartFile, "/mergedoc", context.getUser());
File
pathDir
=
new
File
(
filePath
);
if
(!
pathDir
.
exists
())
{
pathDir
.
mkdirs
();
}
String
fileName
=
multipartFile
.
getOriginalFilename
();
String
extension
=
FilenameUtils
.
getExtension
(
fileName
);
String
newName
=
new
Date
().
getTime
()
+
"."
+
extension
;
//String newName = IdUtil.fastSimpleUUID() + "." + extension;
String
filePathAll
=
"D:\\mortals\\app\\data\\file\\uploadfile\\"
+
newName
;
File
uploadFile
=
new
File
(
filePathAll
);
try
{
multipartFile
.
transferTo
(
uploadFile
);
}
catch
(
Exception
e
)
{
throw
new
AppException
(
e
.
getMessage
());
}
//转换预览图片
String
fileName1
=
RandomUtil
.
randomNumbers
(
12
)
+
".jpg"
;
String
preView
=
"D:\\mortals\\app\\data\\preview\\"
+
fileName1
;
WordUtil
.
convertWordToJPEG
(
filePathAll
,
preView
);
System
.
out
.
println
(
"returnStr:"
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"渲染模板失败:"
+
e
.
getMessage
());
e
.
printStackTrace
();
}
finally
{
try
{
template
.
close
();
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
}
}
DesignComponent
designComponent
=
DesignComponent
.
createType
(
type
);
ListItem
listItem
=
designComponent
.
buildDefaultComponent
(
cons
);
collect
.
add
(
listItem
);
}
}
}
catch
(
JsonProcessingException
e
)
{
System
.
out
.
println
(
"表单参数转换异常:"
+
e
.
getMessage
());
}
}
root
.
setList
(
collect
);
System
.
out
.
println
(
JSON
.
toJSONString
(
root
));
}
}
}
}
\ No newline at end of file
fill-manager/src/main/java/com/mortals/xhx/module/matter/web/MatterDatumController.java
View file @
046c6fdf
...
@@ -47,5 +47,4 @@ public class MatterDatumController extends BaseCRUDJsonBodyMappingController<Mat
...
@@ -47,5 +47,4 @@ public class MatterDatumController extends BaseCRUDJsonBodyMappingController<Mat
super
.
init
(
model
,
context
);
super
.
init
(
model
,
context
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment