|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.migao.config.authority.LoginUtils;
|
|
|
+import com.migao.config.properties.SystemProperties;
|
|
|
import com.migao.config.response.*;
|
|
|
import com.migao.entity.po.*;
|
|
|
import com.migao.entity.vo.req.DocumentSharingInsertReq;
|
|
@@ -23,6 +24,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
/**
|
|
@@ -44,6 +50,8 @@ public class DocumentSharingServiceImpl extends ServiceImpl<DocumentSharingMappe
|
|
|
FileInfoMapper fileInfoMapper;
|
|
|
@Resource
|
|
|
UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private SystemProperties systemProperties;
|
|
|
|
|
|
@Override
|
|
|
public ResponseBean<?> insert(DocumentSharingInsertReq doc) {
|
|
@@ -295,5 +303,38 @@ public class DocumentSharingServiceImpl extends ServiceImpl<DocumentSharingMappe
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseBean<?> download(HttpServletResponse response, String id) {
|
|
|
+ Integer idInt = Integer.parseInt(id);
|
|
|
+ DocumentSharing documentSharing = documentSharingMa.selectById(idInt);
|
|
|
+ FileInfo fileInfo = fileInfoMapper.selectById(documentSharing);
|
|
|
+ String filePath = StringUtils.join(systemProperties.getDownloadPrefix(), fileInfo.getUri());
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ // 取得文件名。
|
|
|
+ String fileName = file.getName();
|
|
|
+ InputStream fis = null;
|
|
|
+ try {
|
|
|
+ fis = new FileInputStream(file);
|
|
|
+ response.reset();
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/force-download");
|
|
|
+ response.addHeader("Content-Disposition",
|
|
|
+ "attachment;filename=" + new String(fileName.getBytes("utf-8"), "iso8859-1"));
|
|
|
+ response.setHeader("Content-Length", String.valueOf(file.length()));
|
|
|
+
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int len;
|
|
|
+ while ((len = fis.read(b)) != -1) {
|
|
|
+ response.getOutputStream().write(b, 0, len);
|
|
|
+ }
|
|
|
+ response.flushBuffer();
|
|
|
+ fis.close();
|
|
|
+ return ResponseBuilder.ok();
|
|
|
+ }catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|