Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspect
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
inspect
Commits
a5135806
提交
a5135806
authored
4月 17, 2020
作者:
孙洁清
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
v1.1
上级
2b430f18
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
216 行增加
和
0 行删除
+216
-0
DocumentService.java
src/main/java/com/zjty/inspect/service/DocumentService.java
+8
-0
DocumentServiceImpl.java
...va/com/zjty/inspect/service/impl/DocumentServiceImpl.java
+74
-0
FreeMakerUtils.java
src/main/java/com/zjty/inspect/utils/FreeMakerUtils.java
+82
-0
SpringContextHolder.java
...main/java/com/zjty/inspect/utils/SpringContextHolder.java
+52
-0
没有找到文件。
src/main/java/com/zjty/inspect/service/DocumentService.java
0 → 100644
浏览文件 @
a5135806
package
com
.
zjty
.
inspect
.
service
;
import
com.zjty.inspect.entity.DocumentPage
;
public
interface
DocumentService
{
String
createDocument
(
DocumentPage
documentPage
);
}
src/main/java/com/zjty/inspect/service/impl/DocumentServiceImpl.java
0 → 100644
浏览文件 @
a5135806
package
com
.
zjty
.
inspect
.
service
.
impl
;
import
com.zjty.inspect.entity.DocumentContent
;
import
com.zjty.inspect.entity.DocumentPage
;
import
com.zjty.inspect.entity.TitleHead
;
import
com.zjty.inspect.service.DocumentService
;
import
com.zjty.inspect.utils.DocumentWordUtil
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
@Service
public
class
DocumentServiceImpl
implements
DocumentService
{
@Override
public
String
createDocument
(
DocumentPage
documentPage
)
{
StringBuilder
sb
=
new
StringBuilder
();
//前面部分内容
String
standard
=
DocumentWordUtil
.
standard
();
String
enddard
=
DocumentWordUtil
.
enddard
();
//标题内容
String
maintitle
=
DocumentWordUtil
.
Maintitle
();
String
subheading
=
DocumentWordUtil
.
subheading
();
//标题下的内容
String
standContent
=
DocumentWordUtil
.
content
();
//表格内容
//页眉
String
header
=
documentPage
.
getHeader
();
String
s1
=
maintitle
.
replaceAll
(
"#title#"
,
header
);
sb
.
append
(
standard
);
sb
.
append
(
s1
);
List
<
TitleHead
>
titleHeads
=
documentPage
.
getTitleHeads
();
if
(
titleHeads
!=
null
&&
titleHeads
.
size
()>
0
){
for
(
TitleHead
titleHead
:
titleHeads
)
{
String
titleContent
=
subheading
;
//标题名称
String
name
=
titleHead
.
getName
();
if
(!
StringUtils
.
isEmpty
(
name
))
{
//标题级别
int
parentId
=
titleHead
.
getParentId
();
String
s
=
titleContent
.
replaceAll
(
"#title#"
,
name
)
.
replaceAll
(
"#parentId#"
,
String
.
valueOf
(
parentId
));
sb
.
append
(
s
);
}
List
<
DocumentContent
>
documentContents
=
titleHead
.
getDocumentContents
();
if
(
documentContents
!=
null
&&
documentContents
.
size
()>
0
){
for
(
DocumentContent
documentContent
:
documentContents
)
{
if
(
documentContent
!=
null
){
String
content
=
documentContent
.
getContent
();
String
baseUrl
=
documentContent
.
getBaseUrl
();
String
documentTable
=
documentContent
.
getDocumentTable
();
if
(!
StringUtils
.
isEmpty
(
content
)){
String
c
=
standContent
;
String
s
=
c
.
replaceAll
(
"#content#"
,
content
);
sb
.
append
(
s
);
}
if
(!
StringUtils
.
isEmpty
(
baseUrl
)){
}
if
(!
StringUtils
.
isEmpty
(
documentTable
)){
sb
.
append
(
documentTable
);
}
}
}
}
}
}
sb
.
append
(
enddard
);
return
sb
.
toString
();
}
}
src/main/java/com/zjty/inspect/utils/FreeMakerUtils.java
0 → 100644
浏览文件 @
a5135806
package
com
.
zjty
.
inspect
.
utils
;
import
com.zjty.inspect.entity.TechnologyContent
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
java.io.*
;
import
java.util.List
;
import
java.util.Map
;
public
class
FreeMakerUtils
{
public
static
String
parseTpl
(
String
viewName
,
Map
<
String
,
List
<
TechnologyContent
>>
params
)
{
Configuration
cfg
=
SpringContextHolder
.
getBean
(
Configuration
.
class
);
String
html
=
null
;
Template
t
=
null
;
try
{
t
=
cfg
.
getTemplate
(
viewName
+
".ftl"
);
createWord
(
t
,
params
);
// html = FreeMarkerTemplateUtils.processTemplateIntoString(t, params);
System
.
out
.
println
(
html
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
html
;
}
public
static
String
createWord
(
Template
template
,
Map
<
String
,
List
<
TechnologyContent
>>
dataMap
){
try
{
//文件路径
String
filePath
=
"E://doc"
;
//文件名称
String
fileName
=
System
.
currentTimeMillis
()+
".doc"
;
// 输出文件
File
outFile
=
new
File
(
filePath
+
File
.
separator
+
fileName
);
// 如果输出目标文件夹不存在,则创建
if
(!
outFile
.
getParentFile
().
exists
())
{
outFile
.
getParentFile
().
mkdirs
();
}
// 将模板和数据模型合并生成文件
Writer
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
outFile
),
"UTF-8"
));
// 生成文件
template
.
process
(
dataMap
,
out
);
// 关闭流
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
public
static
void
writeFile
(
String
file
,
String
conent
)
{
// Log4jBean.logger.info("开始以追加的形式写文件到:["+file+"]");
BufferedWriter
out
=
null
;
try
{
File
outFile
=
new
File
(
file
);
// 如果输出目标文件夹不存在,则创建
if
(!
outFile
.
getParentFile
().
exists
())
{
outFile
.
getParentFile
().
mkdirs
();
}
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
outFile
,
false
)));
out
.
write
(
conent
);
// Log4jBean.logger.info("写文件:["+file+"]完成");
}
catch
(
Exception
e
)
{
// Log4jBean.logger.error("写文件:["+file+"]异常,异常信息为:["+e.getMessage()+"]");
}
finally
{
// Log4jBean.logger.info("开始关闭输出流");
try
{
out
.
close
();
}
catch
(
IOException
e
)
{
// Log4jBean.logger.info("关闭输出流异常,异常信息为:["+e.getMessage()+"]");
}
}
}
}
src/main/java/com/zjty/inspect/utils/SpringContextHolder.java
0 → 100644
浏览文件 @
a5135806
package
com
.
zjty
.
inspect
.
utils
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
@Component
public
class
SpringContextHolder
implements
ApplicationContextAware
{
private
static
ApplicationContext
appContext
=
null
;
/**
* 通过name获取 Bean.
*
* @param name
* @return
*/
public
static
Object
getBean
(
String
name
)
{
return
appContext
.
getBean
(
name
);
}
/**
* 通过class获取Bean.
*
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
getBean
(
Class
<
T
>
clazz
)
{
return
appContext
.
getBean
(
clazz
);
}
/**
* 通过name,以及Clazz返回指定的Bean
*
* @param name
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
)
{
return
appContext
.
getBean
(
name
,
clazz
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
if
(
appContext
==
null
)
{
appContext
=
applicationContext
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论