8/7,ybb文件夹和文件都实现了记录Id功能。
This commit is contained in:
parent
50659ef1a7
commit
e356368b62
|
@ -161,6 +161,13 @@
|
||||||
<artifactId>opencv</artifactId>
|
<artifactId>opencv</artifactId>
|
||||||
<version>4.7.0-0</version>
|
<version>4.7.0-0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -33,5 +33,7 @@ public class BusinessDataFileEntity {
|
||||||
private String uploaderId = null;
|
private String uploaderId = null;
|
||||||
//是否删除
|
//是否删除
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
// //有效日期
|
||||||
|
// private Date validDate = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,10 @@ import java.util.List;
|
||||||
|
|
||||||
@ApiOperation("商务资料文件对象")
|
@ApiOperation("商务资料文件对象")
|
||||||
public interface BusinessDataFileMapper {
|
public interface BusinessDataFileMapper {
|
||||||
|
|
||||||
|
// 新增文件预览方法
|
||||||
|
|
||||||
|
|
||||||
public List<BusinessDataFileEntity> List(@Param("folderId") Long folderId, @Param("fileName") String fileName);
|
public List<BusinessDataFileEntity> List(@Param("folderId") Long folderId, @Param("fileName") String fileName);
|
||||||
void delete(@Param("fileId") Long fileId,@Param("folderId") Long folderId);
|
void delete(@Param("fileId") Long fileId,@Param("folderId") Long folderId);
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.core.injector.methods.SelectList;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,7 +16,8 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("商务资料文件夹对象")
|
@ApiOperation("商务资料文件夹对象")
|
||||||
public interface BusinessDataMapper {
|
@Mapper
|
||||||
|
public interface BusinessDataMapper {
|
||||||
public String getPath(Long parentId);
|
public String getPath(Long parentId);
|
||||||
|
|
||||||
public List<BusinessDataEntity> List();
|
public List<BusinessDataEntity> List();
|
||||||
|
|
|
@ -36,6 +36,6 @@ public interface BusinessDataFileService {
|
||||||
@ApiOperation("上传文件")
|
@ApiOperation("上传文件")
|
||||||
Result addfile(MultipartFile file, Long folderId);
|
Result addfile(MultipartFile file, Long folderId);
|
||||||
|
|
||||||
// 在接口中添加预览方法
|
@ApiOperation("预览文件")
|
||||||
// Result preview(Long fileId, HttpServletResponse response);
|
Result preview(Long fileId, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,22 @@
|
||||||
package com.dite.znpt.service.impl;
|
package com.dite.znpt.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
//
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
||||||
|
@ -82,8 +97,6 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("增加文件")
|
@ApiOperation("增加文件")
|
||||||
|
@ -239,4 +252,231 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
return Result.error("上传失败");
|
return Result.error("上传失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("文件预览")
|
||||||
|
public Result preview(Long fileId, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
// 获取文件路径
|
||||||
|
String filePath = businessDataFileMapper.getPath(fileId);
|
||||||
|
if (filePath == null || filePath.isEmpty()) {
|
||||||
|
return Result.error("文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
return Result.error("文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件扩展名
|
||||||
|
String extension = getFileExtension(filePath);
|
||||||
|
|
||||||
|
// 根据文件类型处理预览
|
||||||
|
switch (extension) {
|
||||||
|
case "pdf":
|
||||||
|
return previewPdf(file, response);
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
case "png":
|
||||||
|
case "gif":
|
||||||
|
case "bmp":
|
||||||
|
case "webp":
|
||||||
|
return previewImage(file, response);
|
||||||
|
case "txt":
|
||||||
|
case "md":
|
||||||
|
case "log":
|
||||||
|
return previewText(file, response);
|
||||||
|
case "doc":
|
||||||
|
case "docx":
|
||||||
|
case "xls":
|
||||||
|
case "xlsx":
|
||||||
|
case "ppt":
|
||||||
|
case "pptx":
|
||||||
|
return previewOffice(file, response);
|
||||||
|
case "mp4":
|
||||||
|
case "avi":
|
||||||
|
case "mov":
|
||||||
|
case "wmv":
|
||||||
|
case "flv":
|
||||||
|
return previewVideo(file, response);
|
||||||
|
case "mp3":
|
||||||
|
case "wav":
|
||||||
|
case "flac":
|
||||||
|
case "aac":
|
||||||
|
return previewAudio(file, response);
|
||||||
|
default:
|
||||||
|
return Result.error("暂不支持该文件类型的预览");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("文件预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFileExtension(String fileName) {
|
||||||
|
if (fileName == null || fileName.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
int lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
if (lastDotIndex == -1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return fileName.substring(lastDotIndex + 1).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewPdf(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/pdf");
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + file.getName());
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok("PDF预览成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("PDF预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewImage(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getImageContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + file.getName());
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok("图片预览成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("图片预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewText(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
response.setContentType("text/plain; charset=UTF-8");
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + file.getName());
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok("文本预览成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("文本预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewOffice(File file, HttpServletResponse response) {
|
||||||
|
// Office文件预览比较复杂,这里返回提示信息
|
||||||
|
return Result.error("Office文件预览功能暂未实现,请下载后查看");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewVideo(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getVideoContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + file.getName());
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok("视频预览成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("视频预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result previewAudio(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getAudioContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + file.getName());
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok("音频预览成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("音频预览失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getImageContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
return "image/jpeg";
|
||||||
|
case "png":
|
||||||
|
return "image/png";
|
||||||
|
case "gif":
|
||||||
|
return "image/gif";
|
||||||
|
case "bmp":
|
||||||
|
return "image/bmp";
|
||||||
|
case "webp":
|
||||||
|
return "image/webp";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getVideoContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "mp4":
|
||||||
|
return "video/mp4";
|
||||||
|
case "avi":
|
||||||
|
return "video/x-msvideo";
|
||||||
|
case "mov":
|
||||||
|
return "video/quicktime";
|
||||||
|
case "wmv":
|
||||||
|
return "video/x-ms-wmv";
|
||||||
|
case "flv":
|
||||||
|
return "video/x-flv";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAudioContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "mp3":
|
||||||
|
return "audio/mpeg";
|
||||||
|
case "wav":
|
||||||
|
return "audio/wav";
|
||||||
|
case "flac":
|
||||||
|
return "audio/flac";
|
||||||
|
case "aac":
|
||||||
|
return "audio/aac";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Description: 商务资料管理,文件夹层
|
* @Description: 商务资料管理,文件夹层
|
||||||
|
* 袁彬彬写的,其他人合并的时候,不允许改我的部分。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Api(tags = "文件接口")
|
@Api(tags = "文件接口")
|
||||||
|
@ -78,4 +79,10 @@ public class BusinessDataFileController {
|
||||||
return businessDataFileService.reName(fileId, newFileName);
|
return businessDataFileService.reName(fileId, newFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "文件预览")
|
||||||
|
@GetMapping("/preview")
|
||||||
|
public Result preview(@RequestParam("fileId") Long fileId, HttpServletResponse response) {
|
||||||
|
return businessDataFileService.preview(fileId, response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ spring:
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
# 单个文件大小
|
# 单个文件大小
|
||||||
max-file-size: 100MB
|
max-file-size: 1000MB
|
||||||
# 设置总上传的文件大小
|
# 设置总上传的文件大小
|
||||||
max-request-size: 200MB
|
max-request-size: 2000MB
|
||||||
application:
|
application:
|
||||||
name: znpt
|
name: znpt
|
||||||
mvc:
|
mvc:
|
||||||
|
@ -27,4 +27,4 @@ flowable:
|
||||||
# true 会对数据库中所有表进行更新操作。如果表不存在,则自动创建(建议开发时使用)
|
# true 会对数据库中所有表进行更新操作。如果表不存在,则自动创建(建议开发时使用)
|
||||||
database-schema-update: false
|
database-schema-update: false
|
||||||
# 关闭定时任务JOB
|
# 关闭定时任务JOB
|
||||||
async-executor-activate: false
|
async-executor-activate: false
|
||||||
|
|
Loading…
Reference in New Issue