Search in sources :

Example 11 with UserFile

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

the class OfficeController method createOfficeFile.

@Operation(summary = "创建office文件", description = "创建office文件", tags = { "office" })
@ResponseBody
@RequestMapping(value = "/createofficefile", method = RequestMethod.POST)
public RestResult<Object> createOfficeFile(@RequestBody CreateOfficeFileDTO createOfficeFileDTO) {
    RestResult<Object> result = new RestResult<>();
    try {
        JwtUser loginUser = SessionUtil.getSession();
        String fileName = createOfficeFileDTO.getFileName();
        String filePath = createOfficeFileDTO.getFilePath();
        String extendName = createOfficeFileDTO.getExtendName();
        List<UserFile> userFiles = userFileService.selectSameUserFile(fileName, filePath, extendName, loginUser.getUserId());
        if (userFiles != null && !userFiles.isEmpty()) {
            return RestResult.fail().message("同名文件已存在");
        }
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String templateFilePath = "";
        if ("docx".equals(extendName)) {
            templateFilePath = "template/Word.docx";
        } else if ("xlsx".equals(extendName)) {
            templateFilePath = "template/Excel.xlsx";
        } else if ("pptx".equals(extendName)) {
            templateFilePath = "template/PowerPoint.pptx";
        }
        String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
        FileInputStream fileInputStream = new FileInputStream(url2);
        Copier copier = ufopFactory.getCopier();
        CopyFile copyFile = new CopyFile();
        copyFile.setExtendName(extendName);
        String fileUrl = copier.copy(fileInputStream, copyFile);
        FileBean fileBean = new FileBean();
        fileBean.setFileSize(0L);
        fileBean.setFileUrl(fileUrl);
        fileBean.setStorageType(storageType);
        fileBean.setIdentifier(uuid);
        fileBean.setCreateTime(DateUtil.getCurrentTime());
        fileBean.setCreateUserId(loginUser.getUserId());
        fileBean.setFileStatus(1);
        boolean saveFlag = fileService.save(fileBean);
        UserFile userFile = new UserFile();
        if (saveFlag) {
            userFile.setUserId(loginUser.getUserId());
            userFile.setFileName(fileName);
            userFile.setFilePath(filePath);
            userFile.setDeleteFlag(0);
            userFile.setIsDir(0);
            userFile.setExtendName(extendName);
            userFile.setUploadTime(DateUtil.getCurrentTime());
            userFile.setFileId(fileBean.getFileId());
            userFileService.save(userFile);
        }
        return RestResult.success().message("文件创建成功");
    } catch (Exception e) {
        log.error(e.getMessage());
        return RestResult.fail().message(e.getMessage());
    }
}
Also used : RestResult(com.qiwenshare.common.result.RestResult) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) Copier(com.qiwenshare.ufop.operation.copy.Copier) JSONObject(com.alibaba.fastjson.JSONObject) JwtUser(com.qiwenshare.common.util.security.JwtUser) CopyFile(com.qiwenshare.ufop.operation.copy.domain.CopyFile) Operation(io.swagger.v3.oas.annotations.Operation)

Example 12 with UserFile

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

the class OfficeController method previewOfficeFile.

@Operation(summary = "预览office文件", description = "预览office文件", tags = { "office" })
@RequestMapping(value = "/previewofficefile", method = RequestMethod.POST)
@ResponseBody
public RestResult<Object> previewOfficeFile(HttpServletRequest request, @RequestBody PreviewOfficeFileDTO previewOfficeFileDTO, @RequestHeader("token") String token) {
    RestResult<Object> result = new RestResult<>();
    try {
        JwtUser loginUser = SessionUtil.getSession();
        UserFile userFile = userFileService.getById(previewOfficeFileDTO.getUserFileId());
        String baseUrl = request.getScheme() + "://" + deploymentHost + ":" + port + request.getContextPath();
        FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), previewOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), "view");
        String query = "?type=show&token=" + token;
        file.editorConfig.callbackUrl = baseUrl + "/office/IndexServlet" + query;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("file", file);
        jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
        jsonObject.put("reportName", userFile.getFileName());
        result.setData(jsonObject);
        result.setCode(200);
        result.setMessage("获取报告成功!");
    } catch (Exception e) {
        log.error(e.getMessage());
        result.setCode(500);
        result.setMessage("服务器错误!");
    }
    return result;
}
Also used : FileModel(com.qiwenshare.file.util.FileModel) RestResult(com.qiwenshare.common.result.RestResult) JSONObject(com.alibaba.fastjson.JSONObject) UserFile(com.qiwenshare.file.domain.UserFile) JSONObject(com.alibaba.fastjson.JSONObject) JwtUser(com.qiwenshare.common.util.security.JwtUser) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) Operation(io.swagger.v3.oas.annotations.Operation)

Example 13 with UserFile

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

the class UserFileService method updateFileDeleteStateByFilePath.

private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) {
    executor.execute(() -> {
        List<UserFile> fileList = selectFileListLikeRightFilePath(filePath, userId);
        for (int i = 0; i < fileList.size(); i++) {
            UserFile userFileTemp = fileList.get(i);
            // 标记删除标志
            LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
            userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize)).set(UserFile::getDeleteTime, DateUtil.getCurrentTime()).set(UserFile::getDeleteBatchNum, deleteBatchNum).eq(UserFile::getUserFileId, userFileTemp.getUserFileId()).eq(UserFile::getDeleteFlag, 0);
            userFileMapper.update(null, userFileLambdaUpdateWrapper1);
        }
    });
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) UserFile(com.qiwenshare.file.domain.UserFile)

Example 14 with UserFile

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

the class UserFileService method updateFilepathByFilepath.

@Override
public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) {
    List<UserFile> userFileList = selectUserFileListByPath(newfilePath, userId);
    List<UserFile> userFileNameList = userFileList.stream().filter(o -> o.getFileName().equals(fileName) && o.getExtendName().equals(extendName)).collect(Collectors.toList());
    if (userFileNameList != null && userFileNameList.size() > 0) {
        throw new QiwenException(200000, "目的路径同名文件已存在,不能移动");
    }
    // 移动根目录
    userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
    // 移动子目录
    oldfilePath = oldfilePath + fileName + "/";
    newfilePath = newfilePath + fileName + "/";
    if (StringUtils.isEmpty(extendName)) {
        // 为空说明是目录,则需要移动子目录
        List<UserFile> list = selectFileListLikeRightFilePath(oldfilePath, userId);
        for (UserFile newUserFile : list) {
            newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(oldfilePath, newfilePath));
            userFileMapper.updateById(newUserFile);
        }
    }
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QiwenException(com.qiwenshare.common.exception.QiwenException) UserFile(com.qiwenshare.file.domain.UserFile) StringUtils(org.apache.commons.lang3.StringUtils) RecoveryFile(com.qiwenshare.file.domain.RecoveryFile) Service(org.springframework.stereotype.Service) RandomUtil(cn.hutool.core.util.RandomUtil) RecoveryFileMapper(com.qiwenshare.file.mapper.RecoveryFileMapper) IUserFileService(com.qiwenshare.file.api.IUserFileService) UFOPUtils(com.qiwenshare.ufop.util.UFOPUtils) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) FileTypeMapper(com.qiwenshare.file.mapper.FileTypeMapper) UserFileMapper(com.qiwenshare.file.mapper.UserFileMapper) DateUtil(com.qiwenshare.common.util.DateUtil) Executor(java.util.concurrent.Executor) Resource(javax.annotation.Resource) FileConstant(com.qiwenshare.common.constant.FileConstant) RestResult(com.qiwenshare.common.result.RestResult) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) FileListVo(com.qiwenshare.file.vo.file.FileListVo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SessionUtil(com.qiwenshare.common.util.security.SessionUtil) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) JwtUser(com.qiwenshare.common.util.security.JwtUser) IPage(com.baomidou.mybatisplus.core.metadata.IPage) FileMapper(com.qiwenshare.file.mapper.FileMapper) Transactional(org.springframework.transaction.annotation.Transactional) UserFile(com.qiwenshare.file.domain.UserFile) QiwenException(com.qiwenshare.common.exception.QiwenException)

Example 15 with UserFile

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

the class UserFileService method userFileList.

@Override
public IPage<FileListVo> userFileList(Long userId, String filePath, Long currentPage, Long pageCount) {
    Page<FileListVo> page = new Page<>(currentPage, pageCount);
    UserFile userFile = new UserFile();
    JwtUser sessionUserBean = SessionUtil.getSession();
    if (userId == null) {
        userFile.setUserId(sessionUserBean.getUserId());
    } else {
        userFile.setUserId(userId);
    }
    userFile.setFilePath(UFOPUtils.urlDecode(filePath));
    return userFileMapper.selectPageVo(page, userFile, null);
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) JwtUser(com.qiwenshare.common.util.security.JwtUser) FileListVo(com.qiwenshare.file.vo.file.FileListVo)

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