派生自 projectDept/qhighschool

yn147
2023-10-26 3970ced88b5b456f03fe277c254ca761f05492e0
src/main/java/com/qxueyou/scc/teach/res/service/impl/FileService.java
@@ -26,8 +26,8 @@
import com.qxueyou.scc.teach.res.service.IFileService;
/**
 * 所有文件上传的操作,单独到文件上传工程后,后续业务操作需要下载文件调用的方法
 *
 * 所有文件上传的操作,单独到文件上传工程后,后续业务操作需要下载文件调用的方法
 *
 * @author xiadehu
 *
 */
@@ -37,7 +37,7 @@
   private final Logger log = LogManager.getLogger(FileService.class);
   /*
    * 文件类型:目前支持四种
    * 文件类型:目前支持四种
    */
   public final static String FILE_TYPE_VIDEO = "video";
@@ -75,13 +75,17 @@
         String destPath = getDestPath(name);
         String fullPath = config.getResRootPath() + "/" + destPath;
         //截取上传华为云的编码
         File fileRoot = new File(fullPath.substring(0, fullPath.lastIndexOf("/")));
         if (!fileRoot.exists()) {
            fileRoot.mkdirs();
         }
         //压缩
         FileUtils.copyInputStreamToFile(in, new File(fullPath));
         //华为云编码存入数据库
         ResFile file = insertFileToDB(name, fullPath, destPath, getFileType(name));
         return new Result(true, "success",
@@ -95,18 +99,18 @@
   }
   /**
    * 插入文件信息到数据库
    *
    * 插入文件信息到数据库
    *
    * @param name
    * @param fullPath
    *            全路径
    *            全路径
    * @param relativePath
    *            相对路径
    *            相对路径
    * @param type
    *            文件类型,非文件格式
    *            文件类型,非文件格式
    * @return
    */
   private ResFile insertFileToDB(String name, String fullPath, String relativePath, String type) {
   public ResFile insertFileToDB(String name, String fullPath, String relativePath, String type) {
      ResFile file = new ResFile();
@@ -127,10 +131,41 @@
      return file;
   }
   /**
    * 插入文件信息到数据库
    *
    * @param name
    * @param relativePath
    *            相对路径
    * @param type
    *            文件类型,非文件格式
    * @return
    */
   public ResFile insertFileToDBTwo(String name, Long Size, String relativePath, String type) {
      ResFile file = new ResFile();
      TraceUtils.setCreateTrace(file);
      file.setFileName(name);
      file.setFileFormat(QFileUtils.getFileFormat(name));
      file.setFileType(type);
      // TODO
      file.setMd5Hash(null);
      file.setPath(relativePath);
      file.setSize(Size);
      // TODO
      file.setTenantId(null);
      file.setDeleteFlag(false);
      save(file);
      return file;
   }
   /**
    * 获取文件类型
    *
    * 获取文件类型
    *
    * @param name
    * @return
    */
@@ -140,8 +175,8 @@
   }
   /**
    * 获取文件目标路径
    *
    * 获取文件目标路径
    *
    * @param name
    * @return
    */
@@ -208,4 +243,32 @@
      }
      return null;
   }
   @Override
   public Result checkMd5(String md5, String fileName) {
//      if(StringUtils.isBlank(md5)){
//         return Result.FAIL;
//      }
//
//
//         Boolean objectExist;
//         objectExist = authOssService.doseObjectExist(resFile.getPath());
//
//         if (objectExist) {
//
//            ResFileDO resFileToDB = new ResFileDO();
//            BeanUtils.copyProperties(resFile, resFileToDB);
//            resFileToDB.setId(null);
//            TraceUtils.setCreateTrace(resFileToDB);
//            ResFileDO resFileDB = save(resFileToDB);
//
//            Result result = new Result(true, "fileId", resFileDB.getId(), "path", resFileDB.getPath(),"fileName",fileName,
//                  "fileSize",resFileToDB.getSize(),"fileType",resFileToDB.getFileType(),"hit",true);
//            result.setResultCode(201);
//            return result;
//
//      }
      return Result.FAIL;
   }
}