|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.crypto.digest.MD5;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -18,20 +19,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.*;
|
|
import com.fdkankan.common.constant.*;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.DateExtUtil;
|
|
import com.fdkankan.common.util.DateExtUtil;
|
|
|
-import com.fdkankan.common.util.FileMd5Util;
|
|
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.common.util.SnowflakeIdGenerator;
|
|
import com.fdkankan.common.util.SnowflakeIdGenerator;
|
|
|
import com.fdkankan.contro.constant.RedisConstants;
|
|
import com.fdkankan.contro.constant.RedisConstants;
|
|
|
import com.fdkankan.contro.entity.*;
|
|
import com.fdkankan.contro.entity.*;
|
|
|
import com.fdkankan.contro.enums.CameraTypeEnum;
|
|
import com.fdkankan.contro.enums.CameraTypeEnum;
|
|
|
import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
|
|
import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
|
|
|
-import com.fdkankan.contro.service.ICommonService;
|
|
|
|
|
import com.fdkankan.contro.service.*;
|
|
import com.fdkankan.contro.service.*;
|
|
|
import com.fdkankan.contro.vo.ResponseSceneFile;
|
|
import com.fdkankan.contro.vo.ResponseSceneFile;
|
|
|
import com.fdkankan.contro.vo.ScenePlusVO;
|
|
import com.fdkankan.contro.vo.ScenePlusVO;
|
|
|
import com.fdkankan.fyun.config.FYunFileConfig;
|
|
import com.fdkankan.fyun.config.FYunFileConfig;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
-import com.fdkankan.fyun.local.constant.LocalConstants;
|
|
|
|
|
import com.fdkankan.image.MatrixToImageWriterUtil;
|
|
import com.fdkankan.image.MatrixToImageWriterUtil;
|
|
|
import com.fdkankan.model.constants.ConstantFilePath;
|
|
import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
@@ -2253,11 +2251,10 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ResultData uploadFile(MultipartFile file, String params) throws Exception {
|
|
public ResultData uploadFile(MultipartFile file, String params) throws Exception {
|
|
|
-
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
- log.info("upload-params: "+params);
|
|
|
|
|
- if (StringUtils.isEmpty(params)){
|
|
|
|
|
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
|
|
|
|
|
|
|
+ log.info("uploadFile-params: "+params);
|
|
|
|
|
+ if (StrUtil.isEmpty(params)){
|
|
|
|
|
+ throw new BusinessException(ServerCode.PARAM_REQUIRED.code(), "params");
|
|
|
}
|
|
}
|
|
|
params = params.replaceAll("%2B", "+");
|
|
params = params.replaceAll("%2B", "+");
|
|
|
Base64 base64 = new Base64();
|
|
Base64 base64 = new Base64();
|
|
@@ -2313,116 +2310,58 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
|
|
|
String fileName = file.getOriginalFilename();
|
|
String fileName = file.getOriginalFilename();
|
|
|
log.info("上传的文件名为:" + fileName);
|
|
log.info("上传的文件名为:" + fileName);
|
|
|
// 获取文件的后缀名
|
|
// 获取文件的后缀名
|
|
|
- String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
|
|
|
|
|
- if(StringUtils.isEmpty(folderName)){
|
|
|
|
|
|
|
+ String unicode = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
|
|
|
|
|
+ if(StringUtils.isEmpty(unicode)){
|
|
|
SceneFileBuild fileBuild = findByFileId(fileId);
|
|
SceneFileBuild fileBuild = findByFileId(fileId);
|
|
|
if(ObjectUtils.isEmpty(fileBuild)){
|
|
if(ObjectUtils.isEmpty(fileBuild)){
|
|
|
log.error("数据不正常,fileBuild没找到");
|
|
log.error("数据不正常,fileBuild没找到");
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
}
|
|
}
|
|
|
- folderName = fileBuild.getUnicode();
|
|
|
|
|
- redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
|
|
|
|
|
|
|
+ unicode = fileBuild.getUnicode();
|
|
|
|
|
+ redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), unicode,2 * 24 * 60 * 60);
|
|
|
}
|
|
}
|
|
|
// 1. 判断该文件是否已经上传过
|
|
// 1. 判断该文件是否已经上传过
|
|
|
// 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
|
|
// 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
|
|
|
// 3. 如果未上传过,需要上传。
|
|
// 3. 如果未上传过,需要上传。
|
|
|
- String filePath = mac.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
|
|
|
|
|
-
|
|
|
|
|
- String yunFilePath = LocalConstants.BASE_PATH.concat(fYunFileConfig.getBucket()).concat(File.separator).concat(ConstantFilePath.OSS_PREFIX)
|
|
|
|
|
- .concat(filePath).concat(File.separator).concat(fileName);
|
|
|
|
|
- log.info("yunFilePath:{}", yunFilePath);
|
|
|
|
|
|
|
+ String filePath = mac.concat(File.separator).concat(fileId).concat(File.separator).concat(unicode);
|
|
|
|
|
+ String objectName = ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(fileName);
|
|
|
|
|
+ log.info("objectName:{}", objectName);
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("uuid", uuid);
|
|
map.put("uuid", uuid);
|
|
|
map.put("params", params);
|
|
map.put("params", params);
|
|
|
- map.put("yunFilePath", yunFilePath);
|
|
|
|
|
|
|
+ map.put("yunFilePath", objectName);
|
|
|
map.put("mac", mac);
|
|
map.put("mac", mac);
|
|
|
map.put("fileId", fileId);
|
|
map.put("fileId", fileId);
|
|
|
map.put("picNum", picNum);
|
|
map.put("picNum", picNum);
|
|
|
map.put("md5", md5);
|
|
map.put("md5", md5);
|
|
|
map.put("chunk", chunk);
|
|
map.put("chunk", chunk);
|
|
|
-
|
|
|
|
|
- boolean needUpload = false;
|
|
|
|
|
- File yunFile = new File(yunFilePath);
|
|
|
|
|
- if (yunFile.exists()){
|
|
|
|
|
- String fileMD5 = FileMd5Util.getFileMD5(yunFile);
|
|
|
|
|
- if (md5.equals(fileMD5) && yunFile.length() == size){
|
|
|
|
|
- log.info("文件已存在,MD5和文件大小一致。");
|
|
|
|
|
- SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
|
|
|
|
|
- if (uploadEntity != null){
|
|
|
|
|
- uploadEntity.setSize((int) size);
|
|
|
|
|
- uploadEntity.setMd5(md5);
|
|
|
|
|
- uploadEntity.setFilePath(yunFilePath);
|
|
|
|
|
- uploadEntity.setFileSourceName(fileName);
|
|
|
|
|
- uploadEntity.setUploadStatus(1);
|
|
|
|
|
- sceneFileUploadService.updateById(uploadEntity);
|
|
|
|
|
- }else{
|
|
|
|
|
- SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
|
|
|
|
|
- sceneFileUploadEntity.setSize((int) size);
|
|
|
|
|
- sceneFileUploadEntity.setMd5(md5);
|
|
|
|
|
- sceneFileUploadEntity.setFilePath(yunFilePath.toString());
|
|
|
|
|
- sceneFileUploadEntity.setFileSourceName(fileName);
|
|
|
|
|
- sceneFileUploadEntity.setUploadStatus(1);
|
|
|
|
|
- sceneFileUploadEntity.setFileId(fileId);
|
|
|
|
|
- sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
|
|
|
|
|
- sceneFileUploadService.save(sceneFileUploadEntity);
|
|
|
|
|
- }
|
|
|
|
|
- map.put("needUpload",false);
|
|
|
|
|
- result = ResultData.ok(map);
|
|
|
|
|
- }else if (!md5.equals(fileMD5)) {
|
|
|
|
|
- log.info("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。需要重新上传");
|
|
|
|
|
- FileUtils.delFile(yunFilePath.toString());
|
|
|
|
|
- needUpload = true;
|
|
|
|
|
- }else if (yunFile.length() != size){
|
|
|
|
|
- log.info("文件已上传,文件大小不一致。需要重新上传");
|
|
|
|
|
- FileUtils.delFile(yunFilePath);
|
|
|
|
|
- needUpload = true;
|
|
|
|
|
- }
|
|
|
|
|
- }else {
|
|
|
|
|
- log.info("文件不存在,需要重新上传");
|
|
|
|
|
- needUpload = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 4. 上传成功后,校验MD5和文件大小是否相等
|
|
|
|
|
- // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
|
|
|
|
|
|
|
+ String fileMD5 = MD5.create().digestHex(file.getInputStream());
|
|
|
|
|
+ SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
|
|
|
try {
|
|
try {
|
|
|
- if (needUpload){
|
|
|
|
|
-
|
|
|
|
|
- map.put("needUpload", true);
|
|
|
|
|
-
|
|
|
|
|
- fYunFileService.uploadFile(file.getInputStream(),ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(fileName));
|
|
|
|
|
- File uploadFile = new File(yunFilePath);
|
|
|
|
|
- String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
|
|
|
|
|
-
|
|
|
|
|
- SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
|
|
|
|
|
- sceneFileUploadEntity.setSize((int) size);
|
|
|
|
|
- sceneFileUploadEntity.setMd5(md5);
|
|
|
|
|
- sceneFileUploadEntity.setFilePath(yunFilePath);
|
|
|
|
|
- sceneFileUploadEntity.setFileSourceName(fileName);
|
|
|
|
|
- sceneFileUploadEntity.setFileId(fileId);
|
|
|
|
|
- sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
|
|
|
|
|
-
|
|
|
|
|
- if (md5.equals(fileMD5) && uploadFile.length() == size){
|
|
|
|
|
- log.info("文件已上传,MD5和文件大小一致。上传成功");
|
|
|
|
|
- sceneFileUploadEntity.setUploadStatus(1);
|
|
|
|
|
- sceneFileUploadService.save(sceneFileUploadEntity);
|
|
|
|
|
- result = ResultData.ok(map);
|
|
|
|
|
- }else if (!md5.equals(fileMD5)) {
|
|
|
|
|
- log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
|
|
|
|
|
- sceneFileUploadEntity.setUploadStatus(-1);
|
|
|
|
|
- sceneFileUploadService.save(sceneFileUploadEntity);
|
|
|
|
|
- result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
|
|
|
|
|
- }else if (uploadFile.length() != size){
|
|
|
|
|
- log.error("文件已上传,文件大小不一致。上传失败");
|
|
|
|
|
- sceneFileUploadEntity.setUploadStatus(-1);
|
|
|
|
|
- sceneFileUploadService.save(sceneFileUploadEntity);
|
|
|
|
|
- result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ fYunFileService.uploadFile(file.getInputStream(), objectName);
|
|
|
|
|
+ sceneFileUploadEntity.setSize((int) size);
|
|
|
|
|
+ sceneFileUploadEntity.setMd5(md5);
|
|
|
|
|
+ sceneFileUploadEntity.setFilePath(objectName);
|
|
|
|
|
+ sceneFileUploadEntity.setFileSourceName(fileName);
|
|
|
|
|
+ sceneFileUploadEntity.setFileId(fileId);
|
|
|
|
|
+ sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
|
|
|
|
|
+
|
|
|
|
|
+ if(!fileMD5.equals(md5)){
|
|
|
|
|
+ log.error("参数MD5:"+md5+",文件MD5:"+fileMD5+"。不一致。上传失败:" + fileName);
|
|
|
|
|
+ sceneFileUploadEntity.setUploadStatus(-1);
|
|
|
|
|
+ return ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传: " + fileName);
|
|
|
}
|
|
}
|
|
|
- }catch (IllegalStateException | IOException e) {
|
|
|
|
|
- log.error("上传失败, 请重新上传,md5:{},chunk:{}", md5, chunk);
|
|
|
|
|
- log.error("上传失败", e);
|
|
|
|
|
- result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ sceneFileUploadEntity.setUploadStatus(1);
|
|
|
|
|
+ result = ResultData.ok(map);
|
|
|
|
|
+
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ log.error("上传失败, filename, md5:{}", fileName, md5, e);
|
|
|
|
|
+ sceneFileUploadEntity.setUploadStatus(1);
|
|
|
|
|
+ result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传:" + fileName);
|
|
|
|
|
+ }finally{
|
|
|
|
|
+ sceneFileUploadService.save(sceneFileUploadEntity);
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|