Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
YZG
yzg-util
Commits
8800de17
Commit
8800de17
authored
Jul 04, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
e713977a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
16 deletions
+29
-16
FileHelper.java
...src/main/java/com/yanzuoguang/util/helper/FileHelper.java
+22
-5
ExcelHttp.java
.../src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
+5
-0
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+2
-11
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/FileHelper.java
View file @
8800de17
...
...
@@ -37,7 +37,7 @@ public class FileHelper {
String
contentType
=
Files
.
probeContentType
(
path
);
return
contentType
;
}
catch
(
Exception
ex
)
{
throw
YzgError
.
getRuntimeException
(
ex
,
"044"
,
filePath
);
throw
YzgError
.
getRuntimeException
(
ex
,
"044"
,
filePath
);
}
}
...
...
@@ -51,7 +51,7 @@ public class FileHelper {
public
static
int
getMediaType
(
String
file
)
{
String
mimeType
=
FileHelper
.
getMimeType
(
file
);
if
(
mimeType
==
null
)
{
throw
YzgError
.
getRuntimeException
(
"008"
,
file
);
throw
YzgError
.
getRuntimeException
(
"008"
,
file
);
}
int
type
=
getMediaTypeByMime
(
mimeType
);
// System.out.println(mimeType);
...
...
@@ -102,7 +102,7 @@ public class FileHelper {
if
(
file
.
isDirectory
())
{
return
StringHelper
.
EMPTY
;
}
else
{
throw
YzgError
.
getRuntimeException
(
"010"
,
file
.
getName
());
throw
YzgError
.
getRuntimeException
(
"010"
,
file
.
getName
());
}
}
file
.
mkdirs
();
...
...
@@ -220,11 +220,11 @@ public class FileHelper {
// 删除文件
if
(
file
.
exists
())
{
if
(!
file
.
delete
())
{
throw
YzgError
.
getRuntimeException
(
"012"
,
file
.
getName
());
throw
YzgError
.
getRuntimeException
(
"012"
,
file
.
getName
());
}
}
if
(
file
.
exists
())
{
throw
YzgError
.
getRuntimeException
(
"012"
,
file
.
getName
());
throw
YzgError
.
getRuntimeException
(
"012"
,
file
.
getName
());
}
writeFileAppend
(
file
,
content
,
encoding
);
}
catch
(
RuntimeException
e
)
{
...
...
@@ -322,4 +322,21 @@ public class FileHelper {
//删除当前目录
return
dirFile
.
delete
();
}
/**
* 检查文件和文件路径
*
* @param folderFrom 文件路径
* @return 文件合法路径
*/
public
static
String
checkFolder
(
String
folderFrom
)
{
String
folder
=
StringHelper
.
getFirst
(
folderFrom
,
"temp"
);
if
(
folder
.
contains
(
".."
))
{
throw
YzgError
.
getRuntimeException
(
"075"
);
}
if
(
folder
.
contains
(
"\\u"
))
{
throw
YzgError
.
getRuntimeException
(
"076"
);
}
return
folder
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
View file @
8800de17
...
...
@@ -4,6 +4,7 @@ package com.yanzuoguang.cloud.excel;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.excel.*
;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -95,6 +96,10 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
config
.
setDownFileName
(
String
.
format
(
"%s-%s.xlsx"
,
config
.
getTitle
(),
config
.
getSubTitle
()));
}
FileHelper
.
checkFolder
(
config
.
getServerPath
());
FileHelper
.
checkFolder
(
config
.
getFileName
());
FileHelper
.
checkFolder
(
config
.
getDownFileName
());
ExcelHttp
<
M
>
excel
=
new
ExcelHttp
<>(
config
,
excelStatus
);
// 普通模式生成文件并下载
releaseExcel
(
req
,
excelDao
,
excel
);
...
...
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
8800de17
...
...
@@ -30,6 +30,8 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Objects
;
import
static
com
.
yanzuoguang
.
util
.
helper
.
FileHelper
.
checkFolder
;
/**
* 文件上传服务实现
*
...
...
@@ -457,15 +459,4 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
req
.
setTo
(
StringHelper
.
EMPTY
);
}
}
private
String
checkFolder
(
String
folderFrom
)
{
String
folder
=
StringHelper
.
getFirst
(
folderFrom
,
"temp"
);
if
(
folder
.
contains
(
".."
))
{
throw
YzgError
.
getRuntimeException
(
"075"
);
}
if
(
folder
.
contains
(
"\\u"
))
{
throw
YzgError
.
getRuntimeException
(
"076"
);
}
return
folder
;
}
}
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