Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
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
fangxinjiang
yifu-mvp
Commits
867a9d30
Commit
867a9d30
authored
Sep 24, 2024
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
附件上传限流-fxj
parent
e5ba896e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
4 deletions
+55
-4
FileUploadController.java
...lus/v1/yifu/archives/controller/FileUploadController.java
+8
-4
FileUploadService.java
...loud/plus/v1/yifu/archives/service/FileUploadService.java
+3
-0
FileUploadServiceImpl.java
.../v1/yifu/archives/service/impl/FileUploadServiceImpl.java
+43
-0
ResultConstants.java
...ud/plus/v1/yifu/common/core/constant/ResultConstants.java
+1
-0
No files found.
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/controller/FileUploadController.java
View file @
867a9d30
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import
com.yifu.cloud.plus.v1.yifu.archives.entity.TAttaInfo
;
import
com.yifu.cloud.plus.v1.yifu.archives.entity.TAttaInfo
;
import
com.yifu.cloud.plus.v1.yifu.archives.service.FileUploadService
;
import
com.yifu.cloud.plus.v1.yifu.archives.service.FileUploadService
;
import
com.yifu.cloud.plus.v1.yifu.archives.service.TAttaInfoService
;
import
com.yifu.cloud.plus.v1.yifu.archives.service.TAttaInfoService
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
...
@@ -13,6 +14,7 @@ import com.yifu.cloud.plus.v1.yifu.salary.vo.SalaryAttaVo;
...
@@ -13,6 +14,7 @@ import com.yifu.cloud.plus.v1.yifu.salary.vo.SalaryAttaVo;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -61,8 +63,9 @@ public class FileUploadController {
...
@@ -61,8 +63,9 @@ public class FileUploadController {
@ApiImplicitParam(name = "domain", value = "实体id(传入就插入对应关系,用于编辑)", required = false, paramType = "form")
@ApiImplicitParam(name = "domain", value = "实体id(传入就插入对应关系,用于编辑)", required = false, paramType = "form")
})*/
})*/
@PostMapping
(
value
=
"/ossUploadFile"
)
@PostMapping
(
value
=
"/ossUploadFile"
)
public
R
<
FileVo
>
uploadImg
(
@RequestBody
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domain
)
throws
IOException
{
public
R
<
T
>
uploadImg
(
@RequestBody
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domain
)
throws
IOException
{
return
fileUploadService
.
uploadImg
(
file
,
filePath
,
type
,
domain
);
//return fileUploadService.uploadImg(file,filePath,type,domain);
return
fileUploadService
.
uploadAsso
(
file
,
filePath
,
type
,
domain
,
CommonConstants
.
ZERO_STRING
);
}
}
/**
/**
...
@@ -79,8 +82,9 @@ public class FileUploadController {
...
@@ -79,8 +82,9 @@ public class FileUploadController {
"\t\t\t@ApiImplicitParam(name = \"domain\", value = \"实体id(传入就插入对应关系,用于编辑)\", required = false, paramType = \"form\")\n"
+
"\t\t\t@ApiImplicitParam(name = \"domain\", value = \"实体id(传入就插入对应关系,用于编辑)\", required = false, paramType = \"form\")\n"
+
"\t"
)
"\t"
)
@PostMapping
(
value
=
"/uploadFileReturnAtta"
)
@PostMapping
(
value
=
"/uploadFileReturnAtta"
)
public
R
<
TAttaInfo
>
uploadFileReturnAtta
(
@RequestBody
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
{
public
R
<
T
>
uploadFileReturnAtta
(
@RequestBody
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
{
return
fileUploadService
.
uploadFileReturnAtta
(
file
,
filePath
,
type
,
domainId
);
//return fileUploadService.uploadFileReturnAtta(file,filePath,type,domainId);
return
fileUploadService
.
uploadAsso
(
file
,
filePath
,
type
,
domainId
,
CommonConstants
.
ONE_STRING
);
}
}
/**
/**
...
...
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/service/FileUploadService.java
View file @
867a9d30
...
@@ -3,6 +3,7 @@ package com.yifu.cloud.plus.v1.yifu.archives.service;
...
@@ -3,6 +3,7 @@ package com.yifu.cloud.plus.v1.yifu.archives.service;
import
com.yifu.cloud.plus.v1.yifu.archives.entity.TAttaInfo
;
import
com.yifu.cloud.plus.v1.yifu.archives.entity.TAttaInfo
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.vo.FileVo
;
import
com.yifu.cloud.plus.v1.yifu.common.core.vo.FileVo
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -20,4 +21,6 @@ public interface FileUploadService {
...
@@ -20,4 +21,6 @@ public interface FileUploadService {
R
<
TAttaInfo
>
uploadFileReturnAtta
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
;
R
<
TAttaInfo
>
uploadFileReturnAtta
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
;
R
<
FileVo
>
createQrCode
(
String
domainId
,
String
url
,
String
name
);
R
<
FileVo
>
createQrCode
(
String
domainId
,
String
url
,
String
name
);
R
<
T
>
uploadAsso
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domain
,
String
uploadType
);
}
}
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/service/impl/FileUploadServiceImpl.java
View file @
867a9d30
...
@@ -6,6 +6,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.service.FileUploadService;
...
@@ -6,6 +6,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.service.FileUploadService;
import
com.yifu.cloud.plus.v1.yifu.archives.service.TAttaInfoService
;
import
com.yifu.cloud.plus.v1.yifu.archives.service.TAttaInfoService
;
import
com.yifu.cloud.plus.v1.yifu.archives.utils.QrCodeUtil
;
import
com.yifu.cloud.plus.v1.yifu.archives.utils.QrCodeUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.ResultConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil
;
...
@@ -26,6 +27,7 @@ import java.time.LocalDateTime;
...
@@ -26,6 +27,7 @@ import java.time.LocalDateTime;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
@Service
@Service
@RequiredArgsConstructor
@RequiredArgsConstructor
...
@@ -38,6 +40,10 @@ public class FileUploadServiceImpl implements FileUploadService {
...
@@ -38,6 +40,10 @@ public class FileUploadServiceImpl implements FileUploadService {
private
final
QrCodeUtil
codeUtil
;
private
final
QrCodeUtil
codeUtil
;
private
AtomicInteger
atomicInteger
=
new
AtomicInteger
(
0
);
//初始化附件上传队列上限值
private
int
maxLimit
=
10
;
@Override
@Override
public
R
<
TAttaInfo
>
uploadFileReturnAtta
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
{
public
R
<
TAttaInfo
>
uploadFileReturnAtta
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domainId
)
throws
IOException
{
if
(
null
==
file
)
{
if
(
null
==
file
)
{
...
@@ -239,4 +245,41 @@ public class FileUploadServiceImpl implements FileUploadService {
...
@@ -239,4 +245,41 @@ public class FileUploadServiceImpl implements FileUploadService {
}
}
}
}
}
}
/**
* @Author fxj
* @Description 整合接口
* @Date 15:24 2024/9/24
* @Param
* @return
**/
@Override
public
R
uploadAsso
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domain
,
String
uploadType
){
return
getR
(
file
,
filePath
,
type
,
domain
,
uploadType
);
}
public
R
getR
(
MultipartFile
file
,
String
filePath
,
Integer
type
,
String
domain
,
String
uploadType
)
{
if
(
atomicInteger
.
intValue
()
<
maxLimit
){
try
{
atomicInteger
.
getAndAdd
(
1
);
Thread
.
sleep
(
1000
);
log
.
error
(
"atomicInteger+1:"
+
atomicInteger
.
intValue
());
if
(
CommonConstants
.
ZERO_STRING
.
equals
(
uploadType
)){
return
uploadImg
(
file
,
filePath
,
type
,
domain
);
}
else
if
(
CommonConstants
.
ONE_STRING
.
equals
(
uploadType
)){
return
uploadFileReturnAtta
(
file
,
filePath
,
type
,
domain
);
}
}
catch
(
Exception
e
){
log
.
error
(
"附件上传异常:"
,
e
);
}
finally
{
atomicInteger
.
getAndAdd
(-
1
);
log
.
error
(
"atomicInteger-1:"
+
atomicInteger
.
intValue
());
}
}
else
{
log
.
error
(
ResultConstants
.
FILE_UPLOADING_DATA
);
return
R
.
failed
(
ResultConstants
.
FILE_UPLOADING_DATA
);
}
return
null
;
}
}
}
\ No newline at end of file
yifu-common/yifu-common-core/src/main/java/com/yifu/cloud/plus/v1/yifu/common/core/constant/ResultConstants.java
View file @
867a9d30
...
@@ -23,4 +23,5 @@ public class ResultConstants {
...
@@ -23,4 +23,5 @@ public class ResultConstants {
public
static
final
String
NO_GETLOCK_DATA_SEARCH
=
"多用户同时请求中,请稍后重试!"
;
public
static
final
String
NO_GETLOCK_DATA_SEARCH
=
"多用户同时请求中,请稍后重试!"
;
public
static
final
String
NO_ID
=
"操作失败,id不能为空!"
;
public
static
final
String
NO_ID
=
"操作失败,id不能为空!"
;
public
static
final
String
FILE_UPLOADING_DATA
=
"附件排队上传中,请稍后重试!"
;
}
}
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