|
@@ -7,8 +7,10 @@ import com.diagbot.dto.FileThumDTO;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.service.UploadService;
|
|
import com.diagbot.service.UploadService;
|
|
|
|
+import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -17,7 +19,9 @@ import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 文件上传服务接口实现
|
|
* @Description: 文件上传服务接口实现
|
|
@@ -27,6 +31,9 @@ import java.util.List;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class UploadServiceImpl implements UploadService {
|
|
public class UploadServiceImpl implements UploadService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public FileDTO singleFileUpload(MultipartFile file) {
|
|
public FileDTO singleFileUpload(MultipartFile file) {
|
|
if (file.isEmpty()) {
|
|
if (file.isEmpty()) {
|
|
@@ -46,7 +53,7 @@ public class UploadServiceImpl implements UploadService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public FileThumDTO singleFileThumUpload(MultipartFile file){
|
|
|
|
|
|
+ public FileThumDTO singleFileThumUpload(MultipartFile file) {
|
|
FileThumDTO fileThumDTO = new FileThumDTO();
|
|
FileThumDTO fileThumDTO = new FileThumDTO();
|
|
if (file.isEmpty()) {
|
|
if (file.isEmpty()) {
|
|
fileThumDTO.setSource(new FileDTO("FAILURE", "文件不能为空"));
|
|
fileThumDTO.setSource(new FileDTO("FAILURE", "文件不能为空"));
|
|
@@ -138,6 +145,54 @@ public class UploadServiceImpl implements UploadService {
|
|
return fileDTOS;
|
|
return fileDTOS;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<FileThumDTO> multiFileThumUpload2(MultipartFile[] mpfs, Integer[] type) {
|
|
|
|
+ // 上传文件返回的路径集合
|
|
|
|
+ List<FileThumDTO> fileDTOS = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ Map<String, Object> invokeParams = new HashMap<>();
|
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
|
+ int j = i + 1;
|
|
|
|
+ String fileName = "file" + j;
|
|
|
|
+ String typeName = "type" + j;
|
|
|
|
+ if (null != mpfs && null != type) {
|
|
|
|
+ if (i < mpfs.length && i < type.length
|
|
|
|
+ && null != mpfs[i] && null != type[i]) {
|
|
|
|
+ invokeParams.put(fileName, mpfs[i]);
|
|
|
|
+ invokeParams.put(typeName, type[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fileDTOS
|
|
|
|
+ = dataBeanAggregateQueryFacade.get("thumUploads", invokeParams, List.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
|
|
|
|
+ }
|
|
|
|
+ return fileDTOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public FileThumDTO singleFileThumUpload2(MultipartFile file, Integer type) {
|
|
|
|
+ FileThumDTO fileThumDTO = new FileThumDTO();
|
|
|
|
+ if (file.isEmpty()) {
|
|
|
|
+ fileThumDTO.setSource(new FileDTO("FAILURE", "文件不能为空", type));
|
|
|
|
+ return fileThumDTO;
|
|
|
|
+ }
|
|
|
|
+ //文件大小上限4M
|
|
|
|
+ if (file.getSize() > 4 * 1024 * 1024) {
|
|
|
|
+ fileThumDTO.setSource(new FileDTO("FAILURE", "文件上传失败,超出大小限制4MB", type));
|
|
|
|
+ return fileThumDTO;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ fileThumDTO = saveFileWithThum(file);
|
|
|
|
+ return fileThumDTO;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("文件上传失败", e);
|
|
|
|
+ fileThumDTO.setSource(new FileDTO("FAILURE", "文件上传失败,请重新上传", type));
|
|
|
|
+ return fileThumDTO;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param multipartFile
|
|
* @param multipartFile
|
|
* @return
|
|
* @return
|