[Bug修复](master): 修复了一些问题

修复了一些问题
master
土豆兄弟 3 years ago
parent f1fd8ee6c2
commit 49d0248a10

@ -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<WavDTO> 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;
}

@ -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);
}

@ -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;

@ -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);
}
}

@ -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/
# 发送加密家口需要的一些参数

Loading…
Cancel
Save