Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
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
haoban3.0
haoban-manage3.0
Commits
add00550
Commit
add00550
authored
Dec 27, 2022
by
jinxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传接口替换
parent
e240e151
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
2 deletions
+83
-2
UploadController.java
...om/gic/haoban/manage/web/controller/UploadController.java
+24
-2
UploadUtils.java
...m/gic/haoban/manage/web/utils/statistics/UploadUtils.java
+59
-0
No files found.
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/controller/UploadController.java
View file @
add00550
...
...
@@ -2,11 +2,18 @@ package com.gic.haoban.manage.web.controller;
import
cn.hutool.crypto.SecureUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.clerk.api.dto.AuthorizedUser
;
import
com.gic.commons.util.DateUtil
;
import
com.gic.haoban.common.utils.HaobanResponse
;
import
com.gic.haoban.manage.web.errCode.HaoBanErrCode
;
import
com.gic.haoban.manage.web.utils.statistics.UploadUtils
;
import
com.gic.qcloud.BucketNameEnum
;
import
com.gic.qcloud.FileUploadUtil
;
import
com.gic.thirdparty.cloudfile.CloudFileUtil
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum
;
import
com.gic.thirdparty.cloudfile.pojo.CloudFileInfo
;
import
com.gic.web.common.utils.SessionContextUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -17,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.HashSet
;
...
...
@@ -39,6 +47,8 @@ public class UploadController extends WebBaseController {
if
(
file
==
null
||
file
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
//获取登录人信息
final
AuthorizedUser
au
=
SessionContextUtils
.
getLoginUser
();
String
name
=
file
.
getOriginalFilename
();
// 未加密前文件名称
String
mediaName
=
file
.
getOriginalFilename
();
...
...
@@ -59,7 +69,19 @@ public class UploadController extends WebBaseController {
String
key
=
"haoban/"
+
dayFilePath
+
"/"
+
nameUpload
;
fileType
=
FILE_TYPE
.
contains
(
fileType
)
?
fileType
:
BucketNameEnum
.
OTHER_90000
.
getName
();
try
{
String
url
=
FileUploadUtil
.
simpleUploadFileFromLocal
(
templateFile
,
key
,
fileType
);
//替换新的上传接口
// String url = FileUploadUtil.simpleUploadFileFromLocal(templateFile, key, fileType);
CloudFileTypeEnum
cloudFileTypeEnum
=
CloudFileTypeEnum
.
OTHER
;
if
(
UploadUtils
.
isPicture
(
suffix
))
{
cloudFileTypeEnum
=
CloudFileTypeEnum
.
IMAGE
;
}
else
if
(
UploadUtils
.
isOffice
(
suffix
))
{
cloudFileTypeEnum
=
CloudFileTypeEnum
.
FILE
;
}
else
if
(
UploadUtils
.
isMusic
(
suffix
))
{
cloudFileTypeEnum
=
CloudFileTypeEnum
.
AUDIO
;
}
else
if
(
UploadUtils
.
isVedio
(
suffix
))
{
cloudFileTypeEnum
=
CloudFileTypeEnum
.
VIDEO
;
}
CloudFileInfo
cloudFileInfo
=
CloudFileUtil
.
uploadFile
(
new
FileInputStream
(
templateFile
),
suffix
,
cloudFileTypeEnum
,
au
.
getEnterpriseDTO
().
getFactoryCode
(),
CloudFileBusinessOptEnum
.
HAOBAN_COMMON
);
if
(
templateFile
!=
null
)
{
templateFile
.
delete
();
}
...
...
@@ -69,7 +91,7 @@ public class UploadController extends WebBaseController {
res
.
put
(
"ext"
,
suffix
);
res
.
put
(
"size"
,
len
);
res
.
put
(
"key"
,
key
);
res
.
put
(
"url"
,
"https://"
+
url
);
res
.
put
(
"url"
,
cloudFileInfo
.
getOrgFileUrl
()
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
res
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"异常:{}"
,
e
.
getMessage
(),
e
);
...
...
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/utils/statistics/UploadUtils.java
0 → 100644
View file @
add00550
package
com
.
gic
.
haoban
.
manage
.
web
.
utils
.
statistics
;
/**
* @Author jinxin
* @Date 2022/12/27 09:23
* 文件上传工具类
*/
public
class
UploadUtils
{
/**
* 是否是图片
* @param fileSuffix
* @return
* @throws Exception
*/
public
static
boolean
isPicture
(
String
fileSuffix
)
throws
Exception
{
//pdf 隐私文件,小程序端,只能用这个
String
[]
imageArray
=
{
"bmp"
,
"dib"
,
"gif"
,
"jfif"
,
"jpe"
,
"jpeg"
,
"jpg"
,
"png"
,
"tif"
,
"tiff"
,
"ico"
,
"10"
,
"pdf"
};
for
(
String
str
:
imageArray
)
{
if
(
str
.
equals
(
fileSuffix
.
replace
(
"."
,
""
)))
{
return
true
;
}
}
return
false
;
}
public
static
boolean
isOffice
(
String
fileSuffix
)
throws
Exception
{
String
[]
arr
=
{
"doc"
,
"docx"
,
"xls"
,
"xlsx"
,
"pptx"
,
"ppt"
};
for
(
String
str
:
arr
)
{
if
(
str
.
equals
(
fileSuffix
.
replace
(
"."
,
""
)))
{
return
true
;
}
}
return
false
;
}
public
static
boolean
isMusic
(
String
fileSuffix
)
throws
Exception
{
String
[]
arr
=
{
"wma"
,
"mpc"
,
"ogg"
,
"wav"
,
"mpeg"
,
"mp3"
};
for
(
String
str
:
arr
)
{
if
(
str
.
equals
(
fileSuffix
.
replace
(
"."
,
""
)))
{
return
true
;
}
}
return
false
;
}
public
static
boolean
isVedio
(
String
fileSuffix
)
throws
Exception
{
String
[]
arr
=
{
"rm"
,
"rmvb"
,
"mp4"
,
"wmv"
,
"asf"
,
"asx"
,
"3gp"
,
"mov"
,
"m4v"
,
"avi"
,
"dat"
,
"mkv"
,
"flv"
,
"vob"
};
for
(
String
str
:
arr
)
{
if
(
str
.
equals
(
fileSuffix
.
replace
(
"."
,
""
)))
{
return
true
;
}
}
return
false
;
}
}
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