@@ -29,10 +29,7 @@ import com.sdm.common.feign.impl.system.SysUserFeignClientImpl;
import com.sdm.common.feign.inter.project.ISimulationNodeFeignClient ;
import com.sdm.common.feign.inter.system.IApproveFeignClient ;
import com.sdm.common.log.CoreLogger ;
import com.sdm.common.utils.CidApproveUtil ;
import com.sdm.common.utils.CidSysUserUtil ;
import com.sdm.common.utils.PageUtils ;
import com.sdm.common.utils.ProjectUtil ;
import com.sdm.common.utils.* ;
import com.sdm.common.utils.excel.ExcelUtil ;
import com.sdm.data.model.bo.ApprovalFileDataContentsModel ;
import com.sdm.data.model.entity.FileMetadataExtension ;
@@ -59,6 +56,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
import org.springframework.http.ResponseEntity ;
import org.springframework.mock.web.MockMultipartFile ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.Assert ;
@@ -71,6 +69,9 @@ import java.io.IOException;
import java.io.InputStream ;
import java.net.URLEncoder ;
import java.nio.charset.StandardCharsets ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
import java.text.SimpleDateFormat ;
import java.util.* ;
import java.util.concurrent.CompletableFuture ;
@@ -148,6 +149,10 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
// return type;
// }
private static final String TEMP_FILE_PATH = " D: \\ nginx-1.28.0 \\ html \\ static \\ " ;
private static final String TEMP_NG_URL = " http://192.168.65.199:10031/static/ " ;
@Override
@Transactional ( rollbackFor = Exception . class )
public SdmResponse createDir ( CreateDirReq req ) {
@@ -2394,7 +2399,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
@Override
public ResponseEntity < Object > onlyOfficeCallback ( CallbackData callbackData ) {
log . info ( " 调用回调接口,userdata : {} " , callbackData . getKey ( ) ) ;
log . info ( " 调用回调接口,url : {} " , callbackData . getUrl ( ) ) ;
//状态监听
//参见https://api.onlyoffice.com/editors/callback
Integer status = callbackData . getStatus ( ) ;
@@ -2409,7 +2414,6 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
String url = callbackData . getUrl ( ) ;
log . info ( " 回调地址为:{} " , url ) ;
try {
// saveFile(url); //保存文件
System . out . println ( callbackData ) ;
} catch ( Exception e ) {
System . out . println ( " 保存文件异常 " ) ;
@@ -2429,12 +2433,20 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
case 6 : {
//document is being edited, but the current document state is saved,编辑保存
String prefixUrl = " D: \\ software \\ docker_file \\ onlyoffice-de \\ lib \\ documentserver \\ App_Data \\ cache \\ files \\ data " ;
String url = callbackData . getUrl ( ) ;
url = url . substring ( url . indexOf ( " data " ) + 5 , url . indexOf ( " output.docx " ) - 1 ) ;
log . info ( " 动态路径为:{} " , url ) ;
url = prefixUrl + File . separator + url + File . separator + " output.docx " ;
log . info ( " 最终路径为:{} " , url ) ;
String fileId = callbackData . getKey ( ) ;
try {
// saveFile(url); //保存文件
Path path = Paths . get ( url ) ;
uploadNewFile ( fileId , path ) ;
System . out . println ( callbackData ) ;
} catch ( Exception e ) {
System . out . println ( " 保存文件异常 " ) ;
return ResponseEntity . < Object > ok ( Collections . singletonMap ( " error " , 1 ) ) ;
}
System . out . println ( " save success. " ) ;
break ;
@@ -2451,4 +2463,59 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
return ResponseEntity . < Object > ok ( Collections . singletonMap ( " error " , 0 ) ) ;
}
private boolean uploadNewFile ( String fileId , Path path ) {
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService . lambdaQuery ( ) . eq ( FileMetadataInfo : : getId , fileId ) . one ( ) ;
if ( fileMetadataInfo = = null ) {
return false ;
}
// 文件夹
FileMetadataInfo dirMetadataInfo = fileMetadataInfoService . lambdaQuery ( ) . eq ( FileMetadataInfo : : getId , fileMetadataInfo . getParentId ( ) ) . eq ( FileMetadataInfo : : getDataType , DataTypeEnum . DIRECTORY . getValue ( ) ) . one ( ) ;
boolean hasUploadPermission = fileUserPermissionService . hasFilePermission ( fileMetadataInfo . getId ( ) , ThreadLocalContext . getUserId ( ) , FilePermissionEnum . UPLOAD ) ;
if ( ! hasUploadPermission ) {
return false ;
}
String contentType = " text/plain " ;
byte [ ] content = null ;
try {
content = Files . readAllBytes ( path ) ;
} catch ( final IOException e ) {
}
MultipartFile file = new MockMultipartFile ( fileMetadataInfo . getOriginalName ( ) , fileMetadataInfo . getOriginalName ( ) , contentType , content ) ;
// minioService.uploadFile(file, fileMetadataInfo.getObjectKey(), null);
return true ;
}
@Override
public SdmResponse downloadFileForEdit ( Long fileId ) {
String randomId = RandomUtil . generateString ( 16 ) ;
String path = TEMP_FILE_PATH + randomId ;
try {
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService . lambdaQuery ( ) . eq ( FileMetadataInfo : : getId , fileId ) . one ( ) ;
if ( ObjectUtils . isEmpty ( fileMetadataInfo ) ) {
return SdmResponse . failed ( " 未查询到文件的元数据信息 " ) ;
}
String fileObjectKey = fileMetadataInfo . getObjectKey ( ) ;
boolean hasDownloadPermission = fileUserPermissionService . hasFilePermission ( fileMetadataInfo . getId ( ) , ThreadLocalContext . getUserId ( ) , FilePermissionEnum . DOWNLOAD ) ;
if ( ! hasDownloadPermission ) {
return SdmResponse . failed ( " 用户对该文件无下载权限 " ) ;
}
// 从MinIO下载文件
byte [ ] fileData = minioService . downloadFile ( fileObjectKey ) ;
// 写入响应流
File folder = new File ( path ) ;
folder . mkdir ( ) ;
FileOutputStream outputStream = new FileOutputStream ( path + File . separator + fileMetadataInfo . getOriginalName ( ) ) ;
outputStream . write ( fileData ) ;
outputStream . flush ( ) ;
outputStream . close ( ) ;
JSONObject jsonObject = new JSONObject ( ) ;
jsonObject . put ( " url " , TEMP_NG_URL + randomId + " / " + fileMetadataInfo . getOriginalName ( ) ) ;
return SdmResponse . success ( jsonObject ) ;
} catch ( Exception e ) {
log . error ( " onlyoffice编辑文件失败 " , e ) ;
}
return SdmResponse . failed ( " onlyoffice编辑文件失败 " ) ;
}
}