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
18799502
Commit
18799502
authored
Jan 06, 2023
by
jinxin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/origin/feature/上传接口替换' into developer
parents
4e739477
9479b912
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
9 deletions
+103
-9
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
UploadController.java
...om/gic/haoban/manage/web/controller/UploadController.java
+20
-7
No files found.
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/controller/UploadController.java
View file @
18799502
...
...
@@ -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 @
18799502
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
;
}
}
haoban-manage3-wx/src/main/java/com/gic/haoban/manage/web/controller/UploadController.java
View file @
18799502
package
com
.
gic
.
haoban
.
manage
.
web
.
controller
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -10,6 +11,7 @@ import java.util.Map;
import
javax.servlet.http.HttpServletRequest
;
import
com.gic.clerk.api.dto.AuthorizedUser
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -45,12 +47,20 @@ public class UploadController extends WebBaseController {
@RequestMapping
(
"upload-img"
)
@IgnoreLogin
public
HaobanResponse
imgUpload
(
HttpServletRequest
request
)
throws
Exception
{
public
HaobanResponse
imgUpload
(
HttpServletRequest
request
,
String
enterpriseId
)
throws
Exception
{
EnterpriseDTO
enterprise
=
this
.
enterpriseService
.
getEnterpriseById
(
enterpriseId
)
;
if
(
null
==
enterprise
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_OTHER
,
"商户不存在"
)
;
}
String
factoryCode
=
enterprise
.
getFactoryCode
()
;
MultipartHttpServletRequest
multiRequest
=
(
MultipartHttpServletRequest
)
request
;
Iterator
<
String
>
iter
=
multiRequest
.
getFileNames
();
java
.
util
.
List
<
Map
<
String
,
Object
>>
picList
=
new
ArrayList
<>();
while
(
iter
.
hasNext
())
{
String
fileName
=
iter
.
next
();
//获取文件名后缀
String
suffix
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
);
logger
.
info
(
"文件的后缀为:{}"
,
suffix
);
List
<
MultipartFile
>
list
=
multiRequest
.
getMultiFileMap
().
get
(
fileName
);
Map
<
String
,
Object
>
map
=
null
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
...
...
@@ -63,12 +73,15 @@ public class UploadController extends WebBaseController {
fileBuffer
=
new
byte
[
len
];
in
.
read
(
fileBuffer
);
}
PicUploadResDTO
picUploadResDTO
=
qqCloudPicService
.
uploadPic
(
GlobalVar
.
ctxPropertiesMap
.
get
(
GlobalInfo
.
QQPIC_KEY_ENTERPRISE
),
fileBuffer
);
if
(
picUploadResDTO
!=
null
)
{
picUploadResDTO
.
print
();
map
.
put
(
"qcloudImageUrl"
,
picUploadResDTO
.
downloadUrl
);
map
.
put
(
"imageFiledCode"
,
picUploadResDTO
.
fileId
);
//上传接口替换
// PicUploadResDTO picUploadResDTO = qqCloudPicService.uploadPic(
// GlobalVar.ctxPropertiesMap.get(GlobalInfo.QQPIC_KEY_ENTERPRISE), fileBuffer);
CloudFileTypeEnum
cloudFileTypeEnum
=
CloudFileTypeEnum
.
IMAGE
;
CloudFileInfo
cloudFileInfo
=
CloudFileUtil
.
uploadFile
(
fileBuffer
,
suffix
,
cloudFileTypeEnum
,
factoryCode
,
CloudFileBusinessOptEnum
.
HAOBAN_COMMON
);
logger
.
info
(
"上传返回的实体信息为:{}"
,
cloudFileInfo
);
if
(
cloudFileInfo
!=
null
)
{
map
.
put
(
"qcloudImageUrl"
,
cloudFileInfo
.
getOrgFileUrl
());
map
.
put
(
"imageFiledCode"
,
cloudFileInfo
.
getFileId
());
}
picList
.
add
(
map
);
}
...
...
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