From 49d0248a102bc6344390d34e8dd3209efe6af59e Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Mon, 9 Aug 2021 11:37:48 +0800 Subject: [PATCH] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](master):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了一些问题 --- .../service/impl/FormdataServiceImpl.java | 27 ++++++++++--------- .../rest/TbUploadFileNewController.java | 21 ++++++++++----- .../service/impl/BuildPathUtils.java | 8 +++--- .../uploadnew/task/TransFormDataTask.java | 10 ++++--- .../src/main/resources/config/application.yml | 2 +- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java index aafac54..5876922 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java @@ -18,7 +18,6 @@ package me.zhengjie.modules.formdata.service.impl; import com.alibaba.excel.EasyExcelFactory; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; -import com.aliyun.oss.model.PutObjectResult; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.modules.formdata.domain.Formdata; @@ -31,8 +30,8 @@ import me.zhengjie.modules.uploadnew.listener.EasyExcelListener; import me.zhengjie.modules.uploadnew.service.dto.ExcelDataDTO; import me.zhengjie.modules.uploadnew.service.dto.OosDTO; import me.zhengjie.modules.uploadnew.service.dto.WavDTO; -import me.zhengjie.modules.uploadnew.task.TransFormDataTask; import me.zhengjie.modules.uploadnew.service.impl.BuildPathUtils; +import me.zhengjie.modules.uploadnew.task.TransFormDataTask; import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; @@ -49,7 +48,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.nio.charset.Charset; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -154,15 +156,16 @@ public class FormdataServiceImpl implements FormdataService { try { InputStream inputStream = file.getInputStream(); EasyExcelListener listener = new EasyExcelListener(); - EasyExcelFactory.read(inputStream, ExcelDataDTO.class, listener).sheet().doRead(); + // 忽略首行 + EasyExcelFactory.read(inputStream, ExcelDataDTO.class, listener).sheet().headRowNumber(1).doRead(); //获取到解析后的数据 formData = listener.getData(); // 2. 把解析后的结果进行入库 formdataRepository.saveAll(formData); return formdataMapper.toDto(formData); } catch (Exception e) { - log.error("解析失败"); - throw new RuntimeException(""); + log.error("数据入库失败 , "); + throw new RuntimeException("error : {} -> ", e); } } @@ -174,11 +177,11 @@ public class FormdataServiceImpl implements FormdataService { */ @Override public String parseMediaFileToLocal(MultipartFile file) { - // todo 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录 + // 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录 //文件名 String fileName = file.getOriginalFilename(); //文件保存地址 - String path = buildPathUtils.buildFilePath(); + String path = buildPathUtils.buildFilePath(fileName); OutputStream os = null; InputStream inputStream = null; try { @@ -208,7 +211,7 @@ public class FormdataServiceImpl implements FormdataService { os.close(); inputStream.close(); } catch (IOException e) { - e.printStackTrace(); + log.error("ERROR FormdataServiceImpl|parseMediaFileToLocal ",e); } } return path; @@ -232,7 +235,7 @@ public class FormdataServiceImpl implements FormdataService { //上传路径 String newFileName = buildPathUtils.buildFileOosPath(subFixFile); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); - PutObjectResult putObjectResult = ossClient.putObject(bucketName, newFileName, wavDTO.getLine()); + ossClient.putObject(bucketName, newFileName, wavDTO.getLine()); ossClient.shutdown(); OosDTO oosDTO = toBean(info, newFileName); //发送下游 @@ -247,7 +250,7 @@ public class FormdataServiceImpl implements FormdataService { List wavDTOS = new ArrayList<>(); String zipFileName = null; try { - ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName("GBK")); + ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.defaultCharset()); BufferedInputStream bs = new BufferedInputStream(zipInputStream); ZipEntry zipEntry; byte[] bytes = null; @@ -262,7 +265,7 @@ public class FormdataServiceImpl implements FormdataService { wavDTOS.add(wavDTO); } } catch (Exception e) { - log.error("读取部署包文件内容失败,请确认部署包格式正确:" + zipFileName, e); + log.error("读取部署包文件内容失败,请确认部署包格式正确: {} ", zipFileName, e); } return wavDTOS; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java index dfa779a..b374168 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/rest/TbUploadFileNewController.java @@ -189,10 +189,10 @@ public class TbUploadFileNewController { } if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename) || ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) { - // TODO: 2021/8/5 0005 以 压缩文件结尾的格式 则直接进行保存文件到指定文件夹目录下 + // 以 压缩文件结尾的格式 则直接进行保存文件到指定文件夹目录下 String localSavePath = formdataService.parseMediaFileToLocal(file); if (StringUtils.isNotBlank(localSavePath)) { - // todo 记录保存位置 + // 记录保存位置 resourcesDto.setLocalSavePath(localSavePath); resourcesDto.setFileFormat(subOriginalFilename); finishTag += 1; @@ -206,25 +206,32 @@ public class TbUploadFileNewController { String subOriginalFilename = StringUtils.substringAfterLast(file.getOriginalFilename(), SPLIT_FILE_SYMBOL); if (CollectionUtil.isNotEmpty(list)) { if (RAR_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename) || ZIP_FILE_SUB_NAME.equalsIgnoreCase(subOriginalFilename)) { - // 3. todo 上传oos 并 异步发送给 下游接口 + // 3. 上传oos 并 异步发送给 下游接口 formdataService.uploadOOS(file, list); } } } + // 确保所有文件都经过了响应的处理 if (finishTag != files.length) { - // todo 上传完成更新文件上传记录 + // 上传完成更新文件上传记录 + resourcesDto.setUploadTag(DefaultConstant.TWO_NUMBER); + resourcesDto.setGmtModified(DateUtil.date().toTimestamp()); + TbUploadFileNew tbUploadFileNew = new TbUploadFileNew(); + BeanUtils.copyProperties(resourcesDto, tbUploadFileNew); + tbUploadFileNewService.update(tbUploadFileNew); + log.error("TbUploadFileNewController:newFileUpload | taskName : {} fail ", taskName); return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.FILE_HANDLE_FAIL), HttpStatus.OK); } - // todo 上传完成更新文件上传记录 + // 上传完成更新文件上传记录 resourcesDto.setUploadTag(DefaultConstant.ZERO_NUMBER); resourcesDto.setGmtModified(DateUtil.date().toTimestamp()); TbUploadFileNew tbUploadFileNew = new TbUploadFileNew(); - BeanUtils.copyProperties(resourcesDto, tbUploadFileNew); - tbUploadFileNewService.create(tbUploadFileNew); + tbUploadFileNewService.update(tbUploadFileNew); + return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java index c98fc84..bfb1c41 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java @@ -37,7 +37,7 @@ public class BuildPathUtils { /** * 构建文件上传保存路径 */ - public String buildFilePath() { + public String buildFilePath(String fileName) { // 获取环境配置信息 OsInfo osInfo = SystemUtil.getOsInfo(); // 定义的时间格式 @@ -45,18 +45,18 @@ public class BuildPathUtils { String dirPath; if (osInfo.isWindows()) { - dirPath = fileBasePathWindows + timeFormate; + dirPath = fileBasePathWindows + timeFormate + File.separator + fileName; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isLinux()) { - dirPath = fileBasePathLinux + timeFormate; + dirPath = fileBasePathLinux + timeFormate + File.separator + fileName; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isMac()) { - dirPath = fileBasePathMac + timeFormate; + dirPath = fileBasePathMac + timeFormate + File.separator + fileName; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/TransFormDataTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/TransFormDataTask.java index 825ed1a..8d00675 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/TransFormDataTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/TransFormDataTask.java @@ -18,6 +18,7 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; + @Component @Scope("prototype") @Slf4j @@ -48,13 +49,14 @@ public class TransFormDataTask { private void runTask(OosDTO oosDTO) { String newUrl = url + "formId=3" + "&token=" + TOKEN; String jsonStr = JSONUtil.toJsonStr(oosDTO); + log.info("========================== [jsonStr is {}] ==========================", jsonStr); int count = 0; while (count < DefaultConstant.THREE_NUMBER) { // 调用HTTP请求发送数据 HttpResponse httpResponse = sendPostReq(jsonStr, newUrl); JSONObject object = JSONUtil.parseObj(httpResponse.body()); if (httpResponse.isOk() && object.get("retcode").equals(DefaultConstant.ZERO_NUMBER)) { - log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", object); + log.info("========== [TransFormDataTask|runTask request success, response is {} ] ==========", object); break; } else { count++; @@ -62,14 +64,14 @@ public class TransFormDataTask { // 重新发送前休眠3秒 Thread.sleep(3_0000); } catch (InterruptedException e) { - log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e); + log.error("TransFormDataTask|runTask sleep ERROR. message is {}", e.getMessage(), e); throw new BadRequestException("请求异常!!!"); } - log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body()); + log.error("========== [TransFormDataTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body()); } } if (count >= DefaultConstant.THREE_NUMBER) { - log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", newUrl); + log.error("========== [TransFormDataTask|runTask update send status fail, url is {} ] ==========", newUrl); } } diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index bf23194..6ececa7 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -57,7 +57,7 @@ rsa: remote: link: address: 'http://47.110.11.213:8000/api/temp/file/download' - file-base-path-linux: ~/home/eladmin/file/temp/ + file-base-path-linux: /home/eladmin/file/temp/ file-base-path-windows: C:\eladmin\file\temp\ file-base-path-mac: ~/file/eladmin/temp/ # 发送加密家口需要的一些参数