|
@@ -3,17 +3,16 @@ package com.boman.file.service;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.utils.poi.ExcelUtil;
|
|
|
-import com.boman.domain.dto.AjaxResult;
|
|
|
+import com.boman.domain.dto.*;
|
|
|
import com.boman.common.redis.RedisKey;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
import com.boman.domain.GenTable;
|
|
|
import com.boman.domain.GenTableColumn;
|
|
|
import com.boman.domain.constant.MaskConstant;
|
|
|
-import com.boman.domain.dto.ExportExcelDto;
|
|
|
-import com.boman.domain.dto.FormDataDto;
|
|
|
-import com.boman.domain.dto.ImportExcelDto;
|
|
|
import com.boman.file.utils.FileUploadUtils;
|
|
|
import com.boman.web.core.api.RemoteObjService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -25,7 +24,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URL;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.map;
|
|
@@ -74,12 +74,12 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
- public String uploadFile(MultipartFile file) throws Exception
|
|
|
- {
|
|
|
+ public List<String> uploadFile(MultipartFile file) throws Exception {
|
|
|
String name = FileUploadUtils.upload(localFilePath, file);
|
|
|
- String url = domain + localFilePrefix + name;
|
|
|
- LOGGER.info("上传的路径为: {}", url);
|
|
|
- return url;
|
|
|
+ String absolutePath = localFilePath + "\\" + name;
|
|
|
+ String staticUrl = domain + localFilePrefix + name;
|
|
|
+ LOGGER.info("上传静态路径路径为: {}, 绝对路径为: {}", staticUrl, absolutePath);
|
|
|
+ return Lists.newArrayList(staticUrl, absolutePath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -89,12 +89,13 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
* @return java.lang.String
|
|
|
*/
|
|
|
@Override
|
|
|
- public String uploadFileBase64(String base64) throws IOException {
|
|
|
+ public List<String> uploadFileBase64(String base64) throws IOException {
|
|
|
MultipartFile multipartFile = FileUploadUtils.base64ToMultipart(base64);
|
|
|
String name = FileUploadUtils.upload(localFilePath, multipartFile);
|
|
|
- String path = domain + localFilePrefix + name;
|
|
|
- LOGGER.info("上传的路径为: {}", path);
|
|
|
- return path;
|
|
|
+ String absolutePath = localFilePath + "\\" + name;
|
|
|
+ String staticUrl = domain + localFilePrefix + name;
|
|
|
+ LOGGER.info("上传静态路径路径为: {}, 绝对路径为: {}", staticUrl, absolutePath);
|
|
|
+ return Lists.newArrayList(staticUrl, absolutePath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -175,6 +176,48 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 查看BooleanUtils.isTrue(dto.getPreview())
|
|
|
+ * 下载BooleanUtils.isFalse(dto.getPreview())
|
|
|
+ *
|
|
|
+ * @param dto absolutePath preview
|
|
|
+ * @param response response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void previewAndDownload(FileDto dto, HttpServletResponse response) throws RuntimeException, IOException {
|
|
|
+ String filePath = dto.getAbsolutePath();
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ response.sendError(404, "file is not exist, filePath = " + filePath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ response.reset();
|
|
|
+ if (BooleanUtils.isTrue(dto.getPreview())) {
|
|
|
+ // 查看
|
|
|
+ URL url = new URL("file:///" + filePath);
|
|
|
+ String contentType = url.openConnection().getContentType();
|
|
|
+ response.setContentType(contentType);
|
|
|
+ response.setHeader("Content-Disposition", "inline;filename=test.pdf");
|
|
|
+ } else {
|
|
|
+ // 下载
|
|
|
+ response.setContentType("application/x-msdownload");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=test.pdf");
|
|
|
+ }
|
|
|
+
|
|
|
+ int len;
|
|
|
+ byte[] bs = new byte[1024];
|
|
|
+ BufferedInputStream br = new BufferedInputStream(new FileInputStream(file));
|
|
|
+ OutputStream out = response.getOutputStream();
|
|
|
+ while ((len = br.read(bs)) > 0) {
|
|
|
+ out.write(bs, 0, len);
|
|
|
+ }
|
|
|
+
|
|
|
+ out.flush();
|
|
|
+ IOUtils.closeQuietly(out);
|
|
|
+ IOUtils.closeQuietly(br);
|
|
|
+ }
|
|
|
+
|
|
|
public void handleNullColumnValue(List<Map<String, Object>> result, List<String> showData) {
|
|
|
for (Map<String, Object> map : result) {
|
|
|
Set<String> resultKeySet = map.keySet();
|