| | |
| | | import vip.xiaonuo.core.util.HttpServletUtil; |
| | | import vip.xiaonuo.core.util.LibreOfficeUtil; |
| | | import vip.xiaonuo.sys.modular.file.entity.SysFileInfo; |
| | | import vip.xiaonuo.sys.modular.file.enums.SysFileLocationEnum; |
| | | import vip.xiaonuo.sys.modular.file.enums.SysFileInfoExceptionEnum; |
| | | import vip.xiaonuo.sys.modular.file.enums.SysFileLocationEnum; |
| | | import vip.xiaonuo.sys.modular.file.mapper.SysFileInfoMapper; |
| | | import vip.xiaonuo.sys.modular.file.param.SysFileInfoParam; |
| | | import vip.xiaonuo.sys.modular.file.result.SysFileInfoResult; |
| | |
| | | |
| | | @Override |
| | | public SysOnlineFileInfoResult onlineAddOrUpdate(SysFileInfoParam sysFileInfoParam) { |
| | | if(fileOperator instanceof LocalFileOperator) { |
| | | if (fileOperator instanceof LocalFileOperator) { |
| | | //文件后缀 |
| | | String fileSuffix = sysFileInfoParam.getFileSuffix(); |
| | | //文件名称 |
| | |
| | | //文件id |
| | | Long id = sysFileInfoParam.getId(); |
| | | //参数错误 |
| | | if(ObjectUtil.isAllEmpty(fileSuffix, fileOriginName, id)) { |
| | | if (ObjectUtil.isAllEmpty(fileSuffix, fileOriginName, id)) { |
| | | throw new ServiceException(SysFileInfoExceptionEnum.ONLINE_EDIT_PARAM_ERROR); |
| | | } |
| | | //获取登录用户 |
| | |
| | | SysFileInfo sysFileInfo; |
| | | SysOnlineFileInfoResult sysOnlineFileInfoResult; |
| | | //文件id不为空则表示编辑 |
| | | if(ObjectUtil.isNotEmpty(id)) { |
| | | if (ObjectUtil.isNotEmpty(id)) { |
| | | sysFileInfo = this.getById(id); |
| | | sysOnlineFileInfoResult= new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), sysFileInfo.getFileOriginName(), Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); |
| | | sysOnlineFileInfoResult = new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), sysFileInfo.getFileOriginName(), Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); |
| | | } else { |
| | | //否则表示新增 |
| | | Boolean sample = sysFileInfoParam.getSample(); |
| | | sysFileInfo = createDemo(fileSuffix, fileOriginName, sample, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); |
| | | sysOnlineFileInfoResult= new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), fileOriginName + SymbolConstant.PERIOD + fileSuffix, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); |
| | | sysOnlineFileInfoResult = new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), fileOriginName + SymbolConstant.PERIOD + fileSuffix, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); |
| | | |
| | | } |
| | | //设置history |
| | | sysOnlineFileInfoResult.history = OnlineDocumentUtil.getHistory(sysOnlineFileInfoResult); |
| | | if(ObjectUtil.isAllNotEmpty(sysFileInfoParam.getMode(), sysFileInfoParam.getType())) { |
| | | if (ObjectUtil.isAllNotEmpty(sysFileInfoParam.getMode(), sysFileInfoParam.getType())) { |
| | | sysOnlineFileInfoResult.changeType(sysFileInfoParam.getMode(), sysFileInfoParam.getType()); |
| | | } |
| | | return sysOnlineFileInfoResult; |
| | |
| | | } |
| | | |
| | | // 根据后缀查询 |
| | | if(ObjectUtil.isNotEmpty(sysFileInfoParam.getFileSuffix())) { |
| | | if(sysFileInfoParam.getFileSuffix().contains(SymbolConstant.COMMA)) { |
| | | if (ObjectUtil.isNotEmpty(sysFileInfoParam.getFileSuffix())) { |
| | | if (sysFileInfoParam.getFileSuffix().contains(SymbolConstant.COMMA)) { |
| | | queryWrapper.in(SysFileInfo::getFileSuffix, Arrays.asList(sysFileInfoParam.getFileSuffix().split(SymbolConstant.COMMA))); |
| | | } else { |
| | | queryWrapper.eq(SysFileInfo::getFileSuffix, sysFileInfoParam.getFileSuffix()); |
| | |
| | | |
| | | @Override |
| | | public Long uploadFile(MultipartFile file) { |
| | | return this.uploadFileBlog(file, DEFAULT_BUCKET); |
| | | } |
| | | |
| | | @Override |
| | | public Long uploadFileBlog(MultipartFile file, String bucket) { |
| | | |
| | | // 生成文件的唯一id |
| | | Long fileId = IdWorker.getId(); |
| | |
| | | byte[] bytes; |
| | | try { |
| | | bytes = file.getBytes(); |
| | | fileOperator.storageFile(DEFAULT_BUCKET, finalName, bytes); |
| | | fileOperator.storageFile(bucket, finalName, bytes); |
| | | } catch (IOException e) { |
| | | throw new ServiceException(SysFileInfoExceptionEnum.ERROR_FILE); |
| | | } |
| | |
| | | SysFileInfo sysFileInfo = new SysFileInfo(); |
| | | sysFileInfo.setId(fileId); |
| | | sysFileInfo.setFileLocation(SysFileLocationEnum.LOCAL.getCode()); |
| | | sysFileInfo.setFileBucket(DEFAULT_BUCKET); |
| | | sysFileInfo.setFileBucket(bucket); |
| | | sysFileInfo.setFileObjectName(finalName); |
| | | sysFileInfo.setFileOriginName(originalFilename); |
| | | sysFileInfo.setFileSuffix(fileSuffix); |
| | |
| | | } |
| | | |
| | | int status = (int) jsonObj.get("status"); |
| | | String downloadUri = (String) jsonObj.get("url"); |
| | | String downloadUri = (String) jsonObj.get("url"); |
| | | String changesUri = (String) jsonObj.get("changesurl"); |
| | | String key = (String) jsonObj.get("key"); |
| | | |
| | |
| | | //MustSave, Corrupted |
| | | try { |
| | | String histDir = OnlineDocumentUtil.getHistoryDir(OnlineDocumentUtil.getStoragePath(id)); |
| | | String versionDir = OnlineDocumentUtil.getVersionDir(histDir, OnlineDocumentUtil.getFileVersion(histDir) + 1); |
| | | String versionDir = OnlineDocumentUtil.getVersionDir(histDir, OnlineDocumentUtil.getFileVersion(histDir) + 1); |
| | | File ver = new File(versionDir); |
| | | File toSave = new File(storagePath); |
| | | if (!ver.exists()) ver.mkdirs(); |
| | |
| | | /** |
| | | * 创建模板文件 |
| | | * |
| | | * @param fileSuffix 文件后缀 |
| | | * @param fileSuffix 文件后缀 |
| | | * @param originalFilename 文件原始名称 |
| | | * @param sample 是否创建相同文件内容的模板文件 |
| | | * @param userId 用户id |
| | | * @param userName 用户名称 |
| | | * @param sample 是否创建相同文件内容的模板文件 |
| | | * @param userId 用户id |
| | | * @param userName 用户名称 |
| | | * @author xuyuxiang |
| | | * @date 2021/3/24 11:01 |
| | | */ |
| | |
| | | /** |
| | | * 创建元数据信息 |
| | | * |
| | | * @param fileId 文件id |
| | | * @param userId 用户id |
| | | * @param fileId 文件id |
| | | * @param userId 用户id |
| | | * @param userName 用户名称 |
| | | * @author xuyuxiang |
| | | * @date 2021/3/24 11:19 |
| | |
| | | public void createMeta(String fileId, String userId, String userName) { |
| | | // 仅限本地文件 |
| | | Object localClient = fileOperator.getClient(); |
| | | if(ObjectUtil.isNull(localClient)) { |
| | | if (ObjectUtil.isNull(localClient)) { |
| | | throw new ServiceException(SysFileInfoExceptionEnum.CLIENT_INIT_ERROR); |
| | | } |
| | | Dict localClientDict = (Dict) localClient; |
| | | // 拼接获取文档历史路径 |
| | | String histDir = localClientDict.getStr("currentSavePath") + File.separator + DEFAULT_BUCKET + File.separator + fileId + "-hist"; |
| | | if(!FileUtil.exist(histDir)) { |
| | | if (!FileUtil.exist(histDir)) { |
| | | // 历史路径不存在则创建 |
| | | File dir = new File(histDir); |
| | | dir.mkdir(); |