diff --git a/src/main/java/com/glxp/api/idc/service/FileService.java b/src/main/java/com/glxp/api/idc/service/FileService.java index d02833345..a0e7115a8 100644 --- a/src/main/java/com/glxp/api/idc/service/FileService.java +++ b/src/main/java/com/glxp/api/idc/service/FileService.java @@ -1,5 +1,6 @@ package com.glxp.api.idc.service; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -9,8 +10,10 @@ import org.springframework.web.multipart.MultipartFile; import com.glxp.api.common.res.BaseResponse; -/*文件服务*/ +/*文件服务*/ public interface FileService { + BaseResponse upload(List list); + BaseResponse download(List list); BaseResponse fileUpload(HttpServletRequest request,Map params); BaseResponse fileDownload(HttpServletRequest request,Map params); BaseResponse downloadFile(HttpServletRequest request,Map params); diff --git a/src/main/java/com/glxp/api/idc/service/impl/FileServiceImpl.java b/src/main/java/com/glxp/api/idc/service/impl/FileServiceImpl.java index deaa2d4d4..66a801ddf 100644 --- a/src/main/java/com/glxp/api/idc/service/impl/FileServiceImpl.java +++ b/src/main/java/com/glxp/api/idc/service/impl/FileServiceImpl.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -36,7 +38,7 @@ import okhttp3.RequestBody; import okhttp3.Response; -/*连通检测*/ +/*文件服务*/ @Service public class FileServiceImpl implements FileService { private static final Logger logger = LoggerFactory.getLogger(FileServiceImpl.class); @@ -52,8 +54,27 @@ public class FileServiceImpl implements FileService { @Resource private IdcService idcService; private String imagePath = "register/file/image2/"; + + @Override + public BaseResponse upload(List list) { + return fileToUpload(list); + } + @Override + public BaseResponse download(List list) { + return fileToDownload(list); + } + @Override public BaseResponse fileUpload(HttpServletRequest request,Map params) { + List list = new ArrayList<>(); + String[] strs = params.get("fileName").toString().split(","); + for(String str:strs) { + list.add(str); + } + return fileToUpload(list); + } + + private BaseResponse fileToUpload(List list) { String host=""; try { Map map = dbDao.get("select * from sync_data_set limit 1"); @@ -73,21 +94,26 @@ public class FileServiceImpl implements FileService { } if(StringUtils.isEmpty(host)) return ResultVOUtils.error(9999,"上传地址未配置,请至同步设置中进行设置"); - if(params.get("fileName")!=null) { - String fileName = params.get("fileName").toString(); - String[] strs = fileName.split(","); + if(list!=null) { + + String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/"; ArrayList files = new ArrayList<>(); boolean isExists = true; - for(String str:strs) { - if (!StringUtils.isEmpty(str) && FileUtils.isFileExist(filePath + filePathSlash + imagePath + str)) { - files.add(filePath + filePathSlash + imagePath + str); - } else { - isExists = false; + List noExitsList = new ArrayList<>(); + for(String strs:list) { + String[] str = strs.split(","); + for(String s:str) { + if (!StringUtils.isEmpty(s) && FileUtils.isFileExist(filePath + filePathSlash + imagePath + s)) { + files.add(filePath + filePathSlash + imagePath + s); + } else { + isExists = false; + noExitsList.add(s); + } } } if(!isExists) - return ResultVOUtils.error(9999,filePath + filePathSlash + imagePath + strs[0]); + return ResultVOUtils.error(9999,"以下文件不存在:\n"+JSON.toJSONString(noExitsList)); String result = relayFile(files,host); if (IDCUtils.isJson(result)) { BaseResponse baseResponse = JSON.parseObject(result,BaseResponse.class); @@ -101,6 +127,22 @@ public class FileServiceImpl implements FileService { @Override public BaseResponse fileDownload(HttpServletRequest request,Map params) { + List list = new ArrayList<>(); + String[] strs = params.get("fileName").toString().split(","); + for(String str:strs) { + list.add(str); + } + return fileToDownload(list); + } + + + private BaseResponse fileToDownload(List list) { + Map params = new HashMap(); + String fileName = ""; + for(String str:list) { + fileName +=fileName.length()>0 ? ","+str : str; + } + params.put("fileName", fileName); Map map = dbDao.get("select * from sync_data_set limit 1"); if(map!=null&&map.get("syncIp")!=null) {