Commit 867a9d30 authored by fangxinjiang's avatar fangxinjiang

附件上传限流-fxj

parent e5ba896e
......@@ -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.service.FileUploadService;
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.OSSUtil;
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;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -61,8 +63,9 @@ public class FileUploadController {
@ApiImplicitParam(name = "domain", value = "实体id(传入就插入对应关系,用于编辑)", required = false, paramType = "form")
})*/
@PostMapping(value = "/ossUploadFile")
public R<FileVo> uploadImg(@RequestBody MultipartFile file, String filePath, Integer type, String domain) throws IOException {
return fileUploadService.uploadImg(file,filePath,type,domain);
public R<T> uploadImg(@RequestBody MultipartFile file, String filePath, Integer type, String domain) throws IOException {
//return fileUploadService.uploadImg(file,filePath,type,domain);
return fileUploadService.uploadAsso(file,filePath,type,domain,CommonConstants.ZERO_STRING);
}
/**
......@@ -79,8 +82,9 @@ public class FileUploadController {
"\t\t\t@ApiImplicitParam(name = \"domain\", value = \"实体id(传入就插入对应关系,用于编辑)\", required = false, paramType = \"form\")\n" +
"\t")
@PostMapping(value = "/uploadFileReturnAtta")
public R<TAttaInfo> uploadFileReturnAtta(@RequestBody MultipartFile file, String filePath, Integer type, String domainId) throws IOException {
return fileUploadService.uploadFileReturnAtta(file,filePath,type,domainId);
public R<T> uploadFileReturnAtta(@RequestBody MultipartFile file, String filePath, Integer type, String domainId) throws IOException {
//return fileUploadService.uploadFileReturnAtta(file,filePath,type,domainId);
return fileUploadService.uploadAsso(file,filePath,type,domainId,CommonConstants.ONE_STRING);
}
/**
......
......@@ -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.common.core.util.R;
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 java.io.IOException;
......@@ -20,4 +21,6 @@ public interface FileUploadService {
R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, Integer type, String domainId) throws IOException;
R<FileVo> createQrCode(String domainId, String url, String name);
R<T> uploadAsso(MultipartFile file, String filePath, Integer type, String domain, String uploadType);
}
......@@ -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.utils.QrCodeUtil;
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.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
......@@ -26,6 +27,7 @@ import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@Service
@RequiredArgsConstructor
......@@ -38,6 +40,10 @@ public class FileUploadServiceImpl implements FileUploadService {
private final QrCodeUtil codeUtil;
private AtomicInteger atomicInteger = new AtomicInteger(0);
//初始化附件上传队列上限值
private int maxLimit = 10;
@Override
public R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, Integer type, String domainId) throws IOException {
if (null == file) {
......@@ -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
......@@ -23,4 +23,5 @@ public class ResultConstants {
public static final String NO_GETLOCK_DATA_SEARCH = "多用户同时请求中,请稍后重试!";
public static final String NO_ID = "操作失败,id不能为空!";
public static final String FILE_UPLOADING_DATA = "附件排队上传中,请稍后重试!";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment