Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RuoYi-Vue-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
融通安全管理系统
RuoYi-Vue-master
Commits
42ee8357
Commit
42ee8357
authored
Jul 24, 2023
by
周昊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、修改pc端导出项目风险清单表excel列表
2、修改pc端导出风险告知卡图片
parent
7f366b42
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1172 additions
and
1863 deletions
+1172
-1863
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/controller/RiskPlanController.java
...ensoft/censoftrongtong/controller/RiskPlanController.java
+9
-5
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/domain/dto/RiskNotificationExportWordDto.java
...oftrongtong/domain/dto/RiskNotificationExportWordDto.java
+0
-1
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/service/impl/RiskPlanInherentListServiceImpl.java
...ongtong/service/impl/RiskPlanInherentListServiceImpl.java
+7
-1
censoft-rongtong/src/main/resources/mapper/system/RiskPlanInherentListMapper.xml
...in/resources/mapper/system/RiskPlanInherentListMapper.xml
+4
-2
ruoyi-admin/src/main/resources/templates/ftl/word.ftl
ruoyi-admin/src/main/resources/templates/ftl/word.ftl
+1034
-0
ruoyi-admin/src/main/resources/templates/word.xml
ruoyi-admin/src/main/resources/templates/word.xml
+0
-1798
ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java
...common/src/main/java/com/ruoyi/common/utils/WordUtil.java
+117
-55
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
.../main/java/com/ruoyi/framework/config/SecurityConfig.java
+1
-1
No files found.
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/controller/RiskPlanController.java
View file @
42ee8357
...
...
@@ -132,18 +132,22 @@ public class RiskPlanController extends BaseController
RiskNotificationExportWordDto
exportWordDto
=
riskPlanInherentListService
.
getRiskNotificationExportWordDto
(
inherentId
);
Map
<
String
,
Object
>
dataMap
=
Convert
.
convert
(
Map
.
class
,
exportWordDto
);
WordUtil
word
=
new
WordUtil
();
word
.
exportWord
(
request
,
response
,
dataMap
,
"风险告知卡"
);
dataMap
.
put
(
"title"
,
"风险告知卡"
);
dataMap
.
put
(
"path"
,
"D:/ruoyi/uploadPath/upload/"
);
// 数据填装至模板,保存文件
String
name
=
WordUtil
.
createDoc
(
dataMap
,
"word.ftl"
);
// word导出
WordUtil
.
responseDownloadFile
(
request
,
response
,
"D:/ruoyi/uploadPath/upload/"
,
name
);
}
/**
* 导出项目风险清单表
*/
@PostMapping
(
"/exportExcel/InherentList/{
inherent
Id}"
)
public
void
export
(
@PathVariable
Long
inherent
Id
,
HttpServletResponse
response
)
{
@PostMapping
(
"/exportExcel/InherentList/{
plan
Id}"
)
public
void
export
(
@PathVariable
Long
plan
Id
,
HttpServletResponse
response
)
{
try
{
List
<
RiskInherentListExportDto
>
dtos
=
riskPlanInherentListService
.
getPlanInherentListByPlanId
(
inherent
Id
);
List
<
RiskInherentListExportDto
>
dtos
=
riskPlanInherentListService
.
getPlanInherentListByPlanId
(
plan
Id
);
riskPlanInherentListService
.
exportPlanInherentList
(
response
,
dtos
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/domain/dto/RiskNotificationExportWordDto.java
View file @
42ee8357
...
...
@@ -59,6 +59,5 @@ public class RiskNotificationExportWordDto {
/**
* 应急措施
*/
@TableField
(
"measures_emergency"
)
private
String
measuresEmergency
;
}
censoft-rongtong/src/main/java/com/censoft/censoftrongtong/service/impl/RiskPlanInherentListServiceImpl.java
View file @
42ee8357
...
...
@@ -16,6 +16,7 @@ import com.censoft.censoftrongtong.mapper.RiskPlanTaskMapper;
import
com.censoft.censoftrongtong.service.IRiskPlanInherentListService
;
import
com.censoft.censoftrongtong.service.IRiskPlanTaskService
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.WordUtil
;
import
com.ruoyi.system.service.ISysUploadFileService
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Workbook
;
...
...
@@ -29,6 +30,7 @@ import java.io.IOException;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -235,7 +237,11 @@ public class RiskPlanInherentListServiceImpl
@Override
public
RiskNotificationExportWordDto
getRiskNotificationExportWordDto
(
Long
inherentId
)
{
return
riskPlanInherentListMapper
.
getRiskNotificationExportWordDto
(
inherentId
);
RiskNotificationExportWordDto
dto
=
riskPlanInherentListMapper
.
getRiskNotificationExportWordDto
(
inherentId
);
if
(
StrUtil
.
isNotBlank
(
dto
.
getSafetyWarningSigns
())){
dto
.
setSafetyWarningSigns
(
WordUtil
.
getImageStr
(
"D:\\ruoyi\\uploadPath\\upload\\警告标志\\"
+
dto
.
getSafetyWarningSigns
()+
".png"
));
}
return
dto
;
}
@Override
...
...
censoft-rongtong/src/main/resources/mapper/system/RiskPlanInherentListMapper.xml
View file @
42ee8357
...
...
@@ -423,7 +423,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN risk_plan_inherent_list rpil ON rpil.room_id = lr.id
LEFT JOIN risk_plan_existing_list rpel ON rpel.inherent_id = rpil.id
WHERE
rp.id = #{planId}
AND rpil.id IS NOT NULL
-- rp.id = #{planId}
rpil.plan_id = #{planId}
AND rpil.id IS NOT NULL
GROUP BY rpel.id
</select>
</mapper>
\ No newline at end of file
ruoyi-admin/src/main/resources/templates/ftl/word.ftl
0 → 100644
View file @
42ee8357
This diff is collapsed.
Click to expand it.
ruoyi-admin/src/main/resources/templates/word.xml
deleted
100644 → 0
View file @
7f366b42
This source diff could not be displayed because it is too large. You can
view the blob
instead.
ruoyi-common/src/main/java/com/ruoyi/common/utils/WordUtil.java
View file @
42ee8357
...
...
@@ -3,84 +3,146 @@ package com.ruoyi.common.utils;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.TemplateException
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
sun.misc.BASE64Encoder
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
import
static
freemarker
.
template
.
Configuration
.
DEFAULT_INCOMPATIBLE_IMPROVEMENTS
;
/**
* @
author 笑小枫
* @
date 2022/7/27
* @
see <a href="https://www.xiaoxiaofeng.com">https://www.xiaoxiaofeng.com</a>
* @
created: 2020/10/16 16:49
* @
author: winston
* @
description: 导出Word工具类
*/
@Component
public
class
WordUtil
{
private
final
Configuration
configuration
;
@Autowired
private
static
Logger
logger
=
LogManager
.
getLogger
(
WordUtil
.
class
);
/**
* 模板路径
*/
private
static
final
String
FTL_FP
=
"/templates/ftl/"
;
public
WordUtil
()
{
configuration
=
new
Configuration
(
DEFAULT_INCOMPATIBLE_IMPROVEMENTS
);
configuration
.
setDefaultEncoding
(
"UTF-8"
);
private
static
Configuration
configuration
=
null
;
static
{
configuration
=
new
Configuration
();
//设置默认的编码
configuration
.
setDefaultEncoding
(
"utf-8"
);
}
public
void
createWord
(
Map
<
String
,
Object
>
dataMap
,
String
templateName
,
String
fileName
)
{
// 模板文件所在路径
configuration
.
setClassForTemplateLoading
(
this
.
getClass
(),
"/templates"
);
Template
t
=
null
;
/**
* @param dataMap 数据库数据
* @param ftl 替换的模板
* @return
* @throws IOException
*/
public
static
String
createDoc
(
Map
dataMap
,
String
ftl
)
throws
IOException
{
configuration
.
setClassForTemplateLoading
(
WordUtil
.
class
,
FTL_FP
);
String
path
=
(
String
)
dataMap
.
get
(
"path"
);
Template
template
=
null
;
try
{
// 获取模板文件
t
=
configuration
.
getTemplate
(
templateName
,
"UTF-8"
);
// yxkj.ftl为要装载的模板
template
=
configuration
.
getTemplate
(
ftl
);
template
.
setEncoding
(
"utf-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 导出文件
File
outFile
=
new
File
(
fileName
);
try
(
Writer
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
outFile
),
StandardCharsets
.
UTF_8
)))
{
if
(
t
!=
null
)
{
// 将填充数据填入模板文件并输出到目标文件
t
.
process
(
dataMap
,
out
);
}
}
catch
(
IOException
|
TemplateException
e1
)
{
e1
.
printStackTrace
();
// 输出文档路径及名称
String
fileName
=
dataMap
.
get
(
"title"
)
+
".doc"
;
File
outFile
=
new
File
(
path
+
fileName
);
Writer
out
=
null
;
try
{
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
outFile
),
"utf-8"
));
}
catch
(
Exception
e1
)
{
logger
.
error
(
e1
);
fileName
=
""
;
}
try
{
template
.
process
(
dataMap
,
out
);
out
.
close
();
}
catch
(
TemplateException
e2
)
{
logger
.
error
(
e2
);
fileName
=
""
;
}
catch
(
IOException
e
)
{
logger
.
error
(
e
);
fileName
=
""
;
}
return
fileName
;
}
public
void
exportWord
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Map
<
String
,
Object
>
dataMap
,
String
exportName
)
throws
IOException
{
// 1.创建临时文件夹
String
rootPath
=
request
.
getSession
().
getServletContext
().
getRealPath
(
"/"
);
String
fileName
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
// 加载word中的数据信息
WordUtil
word
=
new
WordUtil
();
word
.
createWord
(
dataMap
,
"word.xml"
,
rootPath
+
"/"
+
fileName
+
".doc"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"application/msword"
);
// 设置浏览器以下载的方式处理该文件名
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
.
concat
(
String
.
valueOf
(
URLEncoder
.
encode
(
exportName
+
".doc"
,
"UTF-8"
))));
File
file
=
new
File
(
rootPath
+
"/"
+
fileName
+
".doc"
);
try
(
InputStream
fin
=
new
FileInputStream
(
file
);
ServletOutputStream
out
=
response
.
getOutputStream
())
{
// 缓冲区
byte
[]
buffer
=
new
byte
[
512
];
int
bytesToRead
;
// 通过循环将读入的Word文件的内容输出到浏览器中
while
((
bytesToRead
=
fin
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
bytesToRead
);
}
/**
* 通用文件下载方法
*
* @param response
* @param filePath 文件绝对路径
* this.getClass().getClassLoader().getResource("file").getPath
* ();
* @param fileName 文件名
* @throws IOException
*/
public
static
void
responseDownloadFile
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
filePath
,
String
fileName
)
throws
IOException
{
// 读到流中
InputStream
inStream
=
new
FileInputStream
(
filePath
+
fileName
);
String
agent
=
request
.
getHeader
(
"User-Agent"
).
toUpperCase
();
String
encodedfileName
=
""
;
// IE
if
(
agent
.
indexOf
(
"MSIE"
)
!=
-
1
||
agent
.
indexOf
(
"TRIDENT"
)
!=
-
1
)
{
encodedfileName
=
URLEncoder
.
encode
(
fileName
,
"utf-8"
);
// 谷歌或火狐
}
else
if
(
agent
.
indexOf
(
"CHROME"
)
!=
-
1
||
agent
.
indexOf
(
"FIREFOX"
)
!=
-
1
)
{
encodedfileName
=
new
String
(
fileName
.
getBytes
(
"utf-8"
),
"ISO8859-1"
);
}
else
{
encodedfileName
=
new
String
(
fileName
.
getBytes
(
"utf-8"
),
"ISO8859-1"
);
}
// 设置输出的格式
response
.
reset
();
response
.
setContentType
(
"bin"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
encodedfileName
+
"\""
);
// 循环取出流中的数据
byte
[]
b
=
new
byte
[
100
];
int
len
;
while
((
len
=
inStream
.
read
(
b
))
>
0
)
{
response
.
getOutputStream
().
write
(
b
,
0
,
len
);
}
inStream
.
close
();
}
public
static
String
getImageStr
(
String
imgFile
)
{
InputStream
in
=
null
;
byte
[]
data
=
null
;
try
{
in
=
new
FileInputStream
(
imgFile
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
try
{
data
=
new
byte
[
in
.
available
()];
//注:FileInputStream.available()方法可以从输入流中阻断由下一个方法调用这个输入流中读取的剩余字节数
in
.
read
(
data
);
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
// 删除临时文件
file
.
delete
();
}
BASE64Encoder
encoder
=
new
BASE64Encoder
();
return
encoder
.
encode
(
data
);
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
getImageStr
(
"C:/aqpt/uploadPath/upload/signature/20220114095137.png"
));
}
}
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
View file @
42ee8357
...
...
@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.
authorizeRequests
()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.
antMatchers
(
"/login"
,
"/app-api/login"
,
"/app-api/risk/plan/test"
,
"/register"
,
"/captchaImage"
).
permitAll
()
.
antMatchers
(
"/login"
,
"/app-api/login"
,
"/register"
,
"/captchaImage"
).
permitAll
()
// 静态资源,可匿名访问
.
antMatchers
(
HttpMethod
.
GET
,
"/"
,
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/profile/**"
).
permitAll
()
.
antMatchers
(
"/swagger-ui.html"
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/*/api-docs"
,
"/druid/**"
).
permitAll
()
...
...
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