Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sample-form-platform
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
赵啸非
sample-form-platform
Commits
b1fc4893
Commit
b1fc4893
authored
2 years ago
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加公共庫
parent
99bb1321
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
103 deletions
+0
-103
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/MatterDatumService.java
...mortals/xhx/module/matter/service/MatterDatumService.java
+0
-6
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
...hx/module/matter/service/impl/MatterDatumServiceImpl.java
+0
-97
No files found.
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/MatterDatumService.java
View file @
b1fc4893
...
...
@@ -12,12 +12,6 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity;
*/
public
interface
MatterDatumService
extends
ICRUDService
<
MatterDatumEntity
,
Long
>{
/**
* 合成doc数据模板
* @param context
* @return
*/
String
mergeFormToDoc
(
MatterDatumEntity
docFormVo
,
Context
context
);
/**
* 推荐or取消推荐
...
...
This diff is collapsed.
Click to expand it.
sample-form-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
View file @
b1fc4893
...
...
@@ -143,104 +143,7 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
}
}
@Override
public
String
mergeFormToDoc
(
MatterDatumEntity
docFormVo
,
Context
context
)
{
String
rootPath
=
this
.
filePath
.
endsWith
(
"/"
)
?
this
.
filePath
:
this
.
filePath
+
"/"
;
//转换表单参数为map集合
ObjectMapper
mapper
=
new
ObjectMapper
();
ConfigureBuilder
builder
=
Configure
.
builder
();
builder
.
buildGrammerRegex
(
RegexUtils
.
createGeneral
(
"{{"
,
"}}"
));
try
{
Map
<
String
,
Object
>
data
=
mapper
.
readValue
(
docFormVo
.
getFormContent
(),
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
<>();
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
=
rootPath
+
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
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
templateName
,
templateName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
byteArrayOutputStream
.
toByteArray
());
String
mergedocPath
=
uploadService
.
saveFileUpload
(
multipartFile
,
"/mergedoc"
,
context
.
getUser
());
log
.
info
(
"mergedocPath:"
+
mergedocPath
);
String
mergedoc
=
rootPath
+
mergedocPath
;
//转换预览图片
String
fileName
=
RandomUtil
.
randomNumbers
(
12
)
+
".jpg"
;
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
""
;
}
@Override
public
void
recommend
(
Long
id
)
{
...
...
This diff is collapsed.
Click to expand it.
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