Search in sources :

Example 16 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class QiwenFileUtil method getQiwenFile.

public static UserFile getQiwenFile(long userId, long fileId, String filePath, String fileName, String extendName) {
    UserFile userFile = new UserFile();
    userFile.setUserId(userId);
    userFile.setFileId(fileId);
    userFile.setFileName(fileName);
    userFile.setFilePath(filePath);
    userFile.setExtendName(extendName);
    userFile.setIsDir(0);
    userFile.setUploadTime(DateUtil.getCurrentTime());
    userFile.setDeleteFlag(0);
    userFile.setDeleteBatchNum(null);
    return userFile;
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile)

Example 17 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class QiwenFileUtil method getQiwenDir.

public static UserFile getQiwenDir(long userId, String filePath, String fileName) {
    UserFile userFile = new UserFile();
    userFile.setUserId(userId);
    userFile.setFileId(null);
    userFile.setFileName(fileName);
    userFile.setFilePath(filePath);
    userFile.setExtendName(null);
    userFile.setIsDir(1);
    userFile.setUploadTime(DateUtil.getCurrentTime());
    userFile.setDeleteFlag(0);
    userFile.setDeleteBatchNum(null);
    return userFile;
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile)

Example 18 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class OfficeController method IndexServlet.

@RequestMapping(value = "/IndexServlet", method = RequestMethod.POST)
@ResponseBody
public void IndexServlet(HttpServletResponse response, HttpServletRequest request) throws IOException {
    String token = request.getParameter("token");
    Long userId = userService.getUserIdByToken(token);
    if (userId == null) {
        throw new NotLoginException();
    }
    PrintWriter writer = response.getWriter();
    Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
    String body = scanner.hasNext() ? scanner.next() : "";
    JSONObject jsonObj = JSON.parseObject(body);
    log.info("===saveeditedfile:" + jsonObj.get("status"));
    ;
    String status = jsonObj != null ? jsonObj.get("status").toString() : "";
    if ("2".equals(status) || "6".equals(status)) {
        String type = request.getParameter("type");
        String downloadUri = (String) jsonObj.get("url");
        if ("edit".equals(type)) {
            // 修改报告
            String userFileId = request.getParameter("userFileId");
            UserFile userFile = userFileService.getById(userFileId);
            FileBean fileBean = fileService.getById(userFile.getFileId());
            Long pointCount = fileService.getFilePointCount(userFile.getFileId());
            if (pointCount > 1) {
                // 该场景,暂不支持编辑修改
                writer.write("{\"error\":1}");
                return;
            }
            URL url = new URL(downloadUri);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            int fileLength = 0;
            try {
                InputStream stream = connection.getInputStream();
                Writer writer1 = ufopFactory.getWriter(fileBean.getStorageType());
                WriteFile writeFile = new WriteFile();
                writeFile.setFileUrl(fileBean.getFileUrl());
                writeFile.setFileSize(connection.getContentLength());
                writer1.write(stream, writeFile);
            } catch (Exception e) {
                log.error(e.getMessage());
            } finally {
                if ("2".equals(status)) {
                    LambdaUpdateWrapper<UserFile> userFileUpdateWrapper = new LambdaUpdateWrapper<>();
                    userFileUpdateWrapper.set(UserFile::getUploadTime, DateUtil.getCurrentTime()).eq(UserFile::getUserFileId, userFileId);
                    userFileService.update(userFileUpdateWrapper);
                }
                LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
                fileLength = connection.getContentLength();
                log.info("当前修改文件大小为:" + Long.valueOf(fileLength));
                DownloadFile downloadFile = new DownloadFile();
                downloadFile.setFileUrl(fileBean.getFileUrl());
                InputStream inputStream = ufopFactory.getDownloader(fileBean.getStorageType()).getInputStream(downloadFile);
                String md5Str = DigestUtils.md5Hex(inputStream);
                lambdaUpdateWrapper.set(FileBean::getIdentifier, md5Str).set(FileBean::getFileSize, Long.valueOf(fileLength)).set(FileBean::getModifyTime, DateUtil.getCurrentTime()).set(FileBean::getModifyUserId, userId).eq(FileBean::getFileId, fileBean.getFileId());
                fileService.update(lambdaUpdateWrapper);
                connection.disconnect();
            }
        }
    }
    if ("3".equals(status) || "7".equals(status)) {
        // 不强制手动保存时为6,"6".equals(status)
        log.debug("====保存失败:");
        writer.write("{\"error\":1}");
    } else {
        log.debug("状态为:0");
        writer.write("{\"error\":" + "0" + "}");
    }
}
Also used : Scanner(java.util.Scanner) WriteFile(com.qiwenshare.ufop.operation.write.domain.WriteFile) DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URL(java.net.URL) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) HttpURLConnection(java.net.HttpURLConnection) JSONObject(com.alibaba.fastjson.JSONObject) NotLoginException(com.qiwenshare.common.exception.NotLoginException) UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) Writer(com.qiwenshare.ufop.operation.write.Writer) PrintWriter(java.io.PrintWriter) PrintWriter(java.io.PrintWriter)

Example 19 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class ShareController method shareFile.

@Operation(summary = "分享文件", description = "分享文件统一接口", tags = { "share" })
@PostMapping(value = "/sharefile")
@MyLog(operation = "分享文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<ShareFileVO> shareFile(@RequestBody ShareFileDTO shareSecretDTO) {
    ShareFileVO shareSecretVO = new ShareFileVO();
    JwtUser sessionUserBean = SessionUtil.getSession();
    String uuid = UUID.randomUUID().toString().replace("-", "");
    Share share = new Share();
    BeanUtil.copyProperties(shareSecretDTO, share);
    share.setShareTime(DateUtil.getCurrentTime());
    share.setUserId(sessionUserBean.getUserId());
    share.setShareStatus(0);
    if (shareSecretDTO.getShareType() == 1) {
        String extractionCode = RandomUtil.randomNumbers(6);
        share.setExtractionCode(extractionCode);
        shareSecretVO.setExtractionCode(share.getExtractionCode());
    }
    share.setShareBatchNum(uuid);
    shareService.save(share);
    List<ShareFile> fileList = JSON.parseArray(shareSecretDTO.getFiles(), ShareFile.class);
    List<ShareFile> saveFileList = new ArrayList<>();
    for (ShareFile shareFile : fileList) {
        UserFile userFile = userFileService.getById(shareFile.getUserFileId());
        if (userFile.getUserId().compareTo(sessionUserBean.getUserId()) != 0) {
            return RestResult.fail().message("您只能分享自己的文件");
        }
        if (userFile.getIsDir() == 1) {
            List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
            for (UserFile userFile1 : userfileList) {
                ShareFile shareFile1 = new ShareFile();
                shareFile1.setUserFileId(userFile1.getUserFileId());
                shareFile1.setShareBatchNum(uuid);
                shareFile1.setShareFilePath(userFile1.getFilePath().replaceFirst(userFile.getFilePath(), "/"));
                saveFileList.add(shareFile1);
            }
        }
        shareFile.setShareFilePath("/");
        shareFile.setShareBatchNum(uuid);
        saveFileList.add(shareFile);
    }
    shareFileService.batchInsertShareFile(saveFileList);
    shareSecretVO.setShareBatchNum(uuid);
    return RestResult.success().data(shareSecretVO);
}
Also used : ShareFile(com.qiwenshare.file.domain.ShareFile) ShareFileVO(com.qiwenshare.file.vo.share.ShareFileVO) UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Share(com.qiwenshare.file.domain.Share) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 20 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class ShareController method saveShareFile.

@Operation(summary = "保存分享文件", description = "用来将别人分享的文件保存到自己的网盘中", tags = { "share" })
@PostMapping(value = "/savesharefile")
@MyLog(operation = "保存分享文件", module = CURRENT_MODULE)
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public RestResult saveShareFile(@RequestBody SaveShareFileDTO saveShareFileDTO) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    List<ShareFile> fileList = JSON.parseArray(saveShareFileDTO.getFiles(), ShareFile.class);
    String savefilePath = saveShareFileDTO.getFilePath();
    Long userId = sessionUserBean.getUserId();
    List<UserFile> saveUserFileList = new ArrayList<>();
    for (ShareFile shareFile : fileList) {
        UserFile userFile = userFileService.getById(shareFile.getUserFileId());
        String fileName = userFile.getFileName();
        String savefileName = fileDealComp.getRepeatFileName(userFile, savefilePath);
        if (userFile.getIsDir() == 1) {
            List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId());
            log.info("查询文件列表:" + JSON.toJSONString(userfileList));
            String filePath = userFile.getFilePath();
            userfileList.forEach(p -> {
                p.setUserFileId(null);
                p.setUserId(userId);
                p.setFilePath(p.getFilePath().replaceFirst(filePath + fileName, savefilePath + savefileName));
                saveUserFileList.add(p);
                log.info("当前文件:" + JSON.toJSONString(p));
            });
        }
        userFile.setUserFileId(null);
        userFile.setUserId(userId);
        userFile.setFilePath(savefilePath);
        userFile.setFileName(savefileName);
        saveUserFileList.add(userFile);
    }
    log.info("----------" + JSON.toJSONString(saveUserFileList));
    userFileService.saveBatch(saveUserFileList);
    return RestResult.success();
}
Also used : ShareFile(com.qiwenshare.file.domain.ShareFile) UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserFile (com.qiwenshare.file.domain.UserFile)26 Operation (io.swagger.v3.oas.annotations.Operation)15 JwtUser (com.qiwenshare.common.util.security.JwtUser)14 MyLog (com.qiwenshare.common.anno.MyLog)8 IOException (java.io.IOException)8 FileBean (com.qiwenshare.file.domain.FileBean)7 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)5 RestResult (com.qiwenshare.common.result.RestResult)5 JSONObject (com.alibaba.fastjson.JSONObject)4 NotLoginException (com.qiwenshare.common.exception.NotLoginException)4 FileListVo (com.qiwenshare.file.vo.file.FileListVo)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 QiwenException (com.qiwenshare.common.exception.QiwenException)3 DownloadFile (com.qiwenshare.ufop.operation.download.domain.DownloadFile)3 FileInputStream (java.io.FileInputStream)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 RecoveryFile (com.qiwenshare.file.domain.RecoveryFile)2 ShareFile (com.qiwenshare.file.domain.ShareFile)2 FileModel (com.qiwenshare.file.util.FileModel)2