预览接口分开
This commit is contained in:
parent
7c9343d6a6
commit
d8d28a6302
|
@ -130,6 +130,7 @@ public class SysOssPersonController extends BaseController {
|
|||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("file:person:download")
|
||||
|
@ -137,4 +138,10 @@ public class SysOssPersonController extends BaseController {
|
|||
public void download(@PathVariable Long id, HttpServletResponse response) throws Exception {
|
||||
sysOssPersonService.download(id, response);
|
||||
}
|
||||
|
||||
@SaCheckPermission("file:person:preview")
|
||||
@PostMapping("/preview/{id}")
|
||||
public void preview(@PathVariable Long id, HttpServletResponse response) throws Exception {
|
||||
sysOssPersonService.preview(id, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,4 +145,9 @@ public class SysOssResourceController extends BaseController {
|
|||
public void download(@PathVariable Long id, HttpServletResponse response) throws Exception {
|
||||
sysOssResourceService.download(id, response);
|
||||
}
|
||||
@SaCheckPermission("file:resource:preview")
|
||||
@PostMapping("/preview/{id}")
|
||||
public void preview(@PathVariable Long id, HttpServletResponse response) throws Exception {
|
||||
sysOssResourceService.preview(id, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ public class SysOssTextbookController extends BaseController {
|
|||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("file:textbook:download")
|
||||
|
@ -148,4 +149,9 @@ public class SysOssTextbookController extends BaseController {
|
|||
sysOssTextbookService.download(id, response);
|
||||
}
|
||||
|
||||
@SaCheckPermission("file:textbook:preview")
|
||||
@PostMapping("/preview/{id}")
|
||||
public void preview(@PathVariable Long id, HttpServletResponse response) throws Exception {
|
||||
sysOssTextbookService.preview(id, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,5 +72,5 @@ public interface ISysOssPersonService {
|
|||
Boolean moveByBo(SysOssPersonBo bo);
|
||||
|
||||
void download(Long id, HttpServletResponse response) throws IOException;
|
||||
|
||||
void preview(Long id, HttpServletResponse response) throws Exception;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.dromara.system.service;
|
||||
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
|
@ -87,4 +86,6 @@ public interface ISysOssResourceService {
|
|||
|
||||
void download(Long id, HttpServletResponse response) throws IOException;
|
||||
|
||||
void preview(Long id, HttpServletResponse response) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public interface ISysOssService {
|
|||
* @param ossId OSS对象ID
|
||||
* @param response HttpServletResponse对象,用于设置响应头和向客户端发送文件内容
|
||||
*/
|
||||
void download(Long ossId,String originalName,HttpServletResponse response) throws IOException;
|
||||
void download(Long ossId, String originalName, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除OSS对象存储
|
||||
|
@ -86,6 +86,13 @@ public interface ISysOssService {
|
|||
*/
|
||||
SysOssVo getByMd5(String md5);
|
||||
|
||||
|
||||
/**
|
||||
* 文件预览
|
||||
*
|
||||
* @param ossId
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
void preview(Long ossId, HttpServletResponse response) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -83,5 +83,6 @@ public interface ISysOssTextbookService {
|
|||
Boolean moveByBo(SysOssTextbookBo bo);
|
||||
|
||||
void download(Long id, HttpServletResponse response) throws IOException;
|
||||
void preview(Long id, HttpServletResponse response) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -86,9 +86,9 @@ public class SysOssPersonServiceImpl implements ISysOssPersonService {
|
|||
|
||||
private Wrapper<SysOssPerson> buildQueryWrapper(SysOssPersonBo bo) {
|
||||
QueryWrapper<SysOssPerson> wrapper = Wrappers.query();
|
||||
wrapper.eq(ObjectUtil.isNotNull(bo.getCreateBy()),"op.create_by", bo.getCreateBy())
|
||||
.eq(StringUtils.isNotEmpty(bo.getFileSuffix()),"op.file_suffix", bo.getFileSuffix())
|
||||
.like(StringUtils.isNotEmpty(bo.getFileName()),"op.file_name", bo.getFileName())
|
||||
wrapper.eq(ObjectUtil.isNotNull(bo.getCreateBy()), "op.create_by", bo.getCreateBy())
|
||||
.eq(StringUtils.isNotEmpty(bo.getFileSuffix()), "op.file_suffix", bo.getFileSuffix())
|
||||
.like(StringUtils.isNotEmpty(bo.getFileName()), "op.file_name", bo.getFileName())
|
||||
.and(ObjectUtil.isNotNull(bo.getCatalogId()), w -> {
|
||||
List<SysCatalogPerson> list = catalogService.selectList(new LambdaQueryWrapper<SysCatalogPerson>()
|
||||
.select(SysCatalogPerson::getCatalogId)
|
||||
|
@ -200,4 +200,10 @@ public class SysOssPersonServiceImpl implements ISysOssPersonService {
|
|||
String fileName = ossPerson.getFileName();
|
||||
ossService.download(ossPerson.getOssId(), fileName, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preview(Long id, HttpServletResponse response) throws Exception {
|
||||
SysOssPerson ossPerson = baseMapper.selectById(id);
|
||||
ossService.preview(ossPerson.getOssId(), response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.dromara.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
@ -14,18 +12,14 @@ import org.dromara.common.core.exception.ServiceException;
|
|||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.TreeBuildUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
||||
import org.dromara.system.domain.SysCatalogResource;
|
||||
import org.dromara.system.domain.SysCatalogTextbook;
|
||||
import org.dromara.system.domain.SysOssResource;
|
||||
import org.dromara.system.domain.SysOssTextbook;
|
||||
import org.dromara.system.domain.bo.SysCatalogTextbookBo;
|
||||
import org.dromara.system.domain.bo.SysOssResourceBo;
|
||||
import org.dromara.system.domain.vo.SysCatalogResourceVo;
|
||||
import org.dromara.system.domain.vo.SysCatalogTextbookVo;
|
||||
import org.dromara.system.domain.vo.SysOssResourceVo;
|
||||
import org.dromara.system.domain.vo.SysOssVo;
|
||||
import org.dromara.system.mapper.SysOssResourceMapper;
|
||||
|
@ -230,4 +224,10 @@ public class SysOssResourceServiceImpl implements ISysOssResourceService {
|
|||
baseMapper.addDownloadNum(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preview(Long id, HttpServletResponse response) throws Exception {
|
||||
SysOssResource ossResource = baseMapper.selectById(id);
|
||||
ossService.preview(ossResource.getOssId(), response);
|
||||
baseMapper.addPreviewNum(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.aspose.cells.Workbook;
|
||||
import com.aspose.slides.Presentation;
|
||||
import com.aspose.words.Document;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -36,9 +39,7 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -169,7 +170,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||
* @param response HttpServletResponse对象,用于设置响应头和向客户端发送文件内容
|
||||
*/
|
||||
@Override
|
||||
public void download(Long ossId,String originalName, HttpServletResponse response) throws IOException {
|
||||
public void download(Long ossId, String originalName, HttpServletResponse response) throws IOException {
|
||||
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
||||
if (ObjectUtil.isNull(sysOss)) {
|
||||
throw new ServiceException("文件数据不存在!");
|
||||
|
@ -305,4 +306,49 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysOss>().eq(SysOss::getFileMd5, md5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preview(Long ossId, HttpServletResponse response) throws Exception {
|
||||
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
||||
OssClient storage = OssFactory.instance(sysOss.getService());
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = storage.getObjectContent(sysOss.getFileName());
|
||||
os = response.getOutputStream();
|
||||
byte[] byteData = new byte[1024];
|
||||
// 前端word预览仅支持.docx,将.doc转换为.docx
|
||||
if ((".doc").equals(sysOss.getFileSuffix())) {
|
||||
Document doc = new Document(is);
|
||||
doc.save(os, com.aspose.words.SaveFormat.DOCX);
|
||||
}
|
||||
if ((".xls").equals(sysOss.getFileSuffix())) {
|
||||
Workbook xls = new Workbook(is);
|
||||
xls.save(os, com.aspose.cells.SaveFormat.XLSX);
|
||||
}
|
||||
if ((".ppt").equals(sysOss.getFileSuffix())) {
|
||||
Presentation xls = new Presentation(is);
|
||||
xls.save(os, com.aspose.slides.SaveFormat.Pdf);
|
||||
}
|
||||
int len = 0;
|
||||
while ((len = is.read(byteData)) != -1) {
|
||||
os.write(byteData, 0, len);
|
||||
}
|
||||
os.flush();
|
||||
} finally {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
//log.error("IO异常", e);
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
//log.error("IO异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,4 +223,11 @@ public class SysOssTextbookServiceImpl implements ISysOssTextbookService {
|
|||
ossService.download(ossTextbook.getOssId(), fileName, response);
|
||||
baseMapper.addDownloadNum(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preview(Long id, HttpServletResponse response) throws Exception {
|
||||
SysOssTextbook ossTextbook = baseMapper.selectById(id);
|
||||
ossService.preview(ossTextbook.getOssId(), response);
|
||||
baseMapper.addPreviewNum(id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue