Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
5615f0ac
Commit
5615f0ac
authored
Oct 09, 2019
by
hanfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
峰会图片压缩包上传
parent
126e6cc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
32 deletions
+58
-32
RedisKey.java
...n/java/com/xxfc/platform/universal/constant/RedisKey.java
+5
-0
UploadController.java
.../xxfc/platform/universal/controller/UploadController.java
+3
-3
UploadZipService.java
...com/xxfc/platform/universal/service/UploadZipService.java
+1
-1
UploadZipServiceImpl.java
...platform/universal/service/impl/UploadZipServiceImpl.java
+49
-28
No files found.
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/constant/RedisKey.java
View file @
5615f0ac
...
...
@@ -98,4 +98,9 @@ public class RedisKey {
public
static
final
String
CACHE_DICTIONARY_ALL
=
CACHE_DICTIONARY_PREFIX
+
"all:"
;
public
static
final
String
CACHE_DICTIONARY_ALL_MAP
=
CACHE_DICTIONARY_ALL
+
"map:"
;
public
static
final
String
ILLEGAL_VEHICLE_ENQUIRIES
=
"cache:violation"
;
/**
* 服务器上传压缩包文件序号
*/
public
static
final
String
UPLOAD_ZIP_NO_PREFIX
=
"upload:zip:no:"
;
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/controller/UploadController.java
View file @
5615f0ac
...
...
@@ -183,9 +183,9 @@ public class UploadController{
@PostMapping
(
value
=
"/app/unauth/pictureZip"
)
public
ObjectRestResponse
pictureZip
(
@Request
Body
MultipartFile
file
,
@Request
Body
String
password
)
throws
Exception
{
return
uploadZipService
.
uploadPictureZip
(
file
,
p
assword
);
@Request
Param
(
"file"
)
MultipartFile
file
,
@Request
Param
(
value
=
"prefix"
,
defaultValue
=
"summit"
)
String
prefix
)
throws
Exception
{
return
uploadZipService
.
uploadPictureZip
(
file
,
p
refix
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/UploadZipService.java
View file @
5615f0ac
...
...
@@ -7,5 +7,5 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.IOException
;
public
interface
UploadZipService
{
ObjectRestResponse
uploadPictureZip
(
MultipartFile
file
,
String
p
assword
)
throws
IOException
;
ObjectRestResponse
uploadPictureZip
(
MultipartFile
file
,
String
p
refix
)
throws
IOException
;
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/impl/UploadZipServiceImpl.java
View file @
5615f0ac
package
com
.
xxfc
.
platform
.
universal
.
service
.
impl
;
import
com.alibaba.druid.sql.visitor.functions.If
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.github.wxiaoqi.security.common.util.process.SystemConfig
;
import
com.xxfc.platform.universal.constant.RedisKey
;
import
com.xxfc.platform.universal.constant.enumerate.FileTypeEnum
;
import
com.xxfc.platform.universal.service.UploadZipService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.FileUtils
;
import
org.codehaus.plexus.util.IOUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.nio.charset.Charset
;
import
java.util.Enumeration
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
...
...
@@ -22,60 +29,74 @@ public class UploadZipServiceImpl implements UploadZipService {
@Value
(
"${universal.uploadPath}"
)
private
String
uploadPath
;
@Value
(
"${universal.url}"
)
private
String
xx_url
;
private
static
final
String
APK_SUFFIX
=
".apk"
;
private
static
final
String
APK_NAME
=
"xxfc.apk"
;
private
static
final
String
JPG
=
".jpg"
;
private
static
final
String
PNG
=
".png"
;
@Value
(
"${photo.format}"
)
private
String
PHOTO_FORMAT
=
".png/.jpg/.git/.bmp"
;
@Autowired
RedisTemplate
redisTemplate
;
@Override
public
ObjectRestResponse
uploadPictureZip
(
MultipartFile
file
,
String
password
)
throws
IOException
{
if
(
Objects
.
isNull
(
f
ile
))
{
public
ObjectRestResponse
uploadPictureZip
(
MultipartFile
uFile
,
String
prefix
)
throws
IOException
{
if
(
Objects
.
isNull
(
uF
ile
))
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"请上传压缩文件!"
);
}
String
fileContentType
=
file
.
getContentType
();
String
fileContentType
=
uFile
.
getContentType
();
//将压缩包保存在指定路径
String
packFilePath
=
uploadPath
+
File
.
separator
+
f
ile
.
getName
();
String
packFilePath
=
uploadPath
+
File
.
separator
+
uF
ile
.
getName
();
if
(
FileTypeEnum
.
FILE_TYPE_ZIP
.
type
.
equals
(
fileContentType
)||
FileTypeEnum
.
FILE_TYPE_X_ZIP
.
type
.
equals
(
fileContentType
))
{
//zip解压缩处理
packFilePath
+=
FileTypeEnum
.
FILE_TYPE_ZIP
.
fileStufix
;
}
else
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"上传的压缩包格式不正确,仅支持zip压缩文件!"
);
}
File
fi
=
new
File
(
packFilePath
);
File
fi
le
=
new
File
(
packFilePath
);
try
{
file
.
transferTo
(
fi
);
//保存压缩包
FileOutputStream
os
=
new
FileOutputStream
(
file
);
IOUtil
.
copy
(
uFile
.
getInputStream
(),
os
);
os
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"zip file save to "
+
uploadPath
+
" error"
,
e
.
getMessage
(),
e
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"保存压缩文件到:"
+
uploadPath
+
" 失败!"
);
}
//zip压缩包
return
unPackZip
(
fi
,
password
,
uploadPath
);
//zip压缩包
解压
return
unPackZip
(
fi
le
,
prefix
);
}
public
ObjectRestResponse
unPackZip
(
File
file
,
String
password
,
String
destPath
)
throws
IOException
{
ZipFile
zipFile
=
new
ZipFile
(
file
);
public
ObjectRestResponse
<
String
>
unPackZip
(
File
file
,
String
prefix
)
throws
IOException
{
ZipFile
zipFile
=
new
ZipFile
(
file
,
Charset
.
forName
(
"GBK"
)
);
Enumeration
<?
extends
ZipEntry
>
entries
=
zipFile
.
entries
();
long
millis
=
System
.
currentTimeMillis
();
String
dirPathToday
=
prefix
+
File
.
separator
+
millis
;
String
redisNoKey
=
RedisKey
.
UPLOAD_FILE_NO_PREFIX
+
millis
;
StringBuffer
result
=
new
StringBuffer
();
Integer
index
=
0
;
while
(
entries
.
hasMoreElements
())
{
ZipEntry
entry
=
entries
.
nextElement
();
if
(
entry
.
isDirectory
())
{
destPath
=
destPath
+
File
.
separator
+
entry
.
getName
();
File
dir
=
new
File
(
destPath
);
if
(
entry
.
isDirectory
()
&&
index
++
==
0
)
{
File
dir
=
new
File
(
uploadPath
+
dirPathToday
);
dir
.
mkdir
();
}
else
{
File
targetFile
=
new
File
(
destPath
+
File
.
separator
+
entry
.
getName
());
if
(
targetFile
.
getParentFile
().
exists
()){
}
}
}
else
if
(!
entry
.
isDirectory
())
{
Long
no
=
redisTemplate
.
opsForValue
().
increment
(
redisNoKey
);
if
(
no
.
equals
(
1
l
)){
redisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
}
String
name
=
entry
.
getName
();
String
format
=
name
.
substring
(
name
.
lastIndexOf
(
"."
));
if
(
PHOTO_FORMAT
.
contains
(
format
))
{
String
realFileRelPath
=
dirPathToday
+
File
.
separator
+
no
+
format
;
File
targetFile
=
new
File
(
uploadPath
+
realFileRelPath
);
FileUtils
.
copyInputStreamToFile
(
zipFile
.
getInputStream
(
entry
),
targetFile
);
realFileRelPath
=
xx_url
+
SystemConfig
.
XXMP_URL
+
realFileRelPath
;
result
.
append
(
realFileRelPath
+
","
);
}
}
}
return
null
;
return
ObjectRestResponse
.
succ
(
result
.
substring
(
0
,
result
.
length
()-
1
));
}
}
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