Browse Source

下载指定文件夹文件

master
han\hanst 1 month ago
parent
commit
fc328fd568
  1. 8
      src/main/java/com/spring/modules/part/controller/PartInformationController.java
  2. 2
      src/main/java/com/spring/modules/part/service/PartInformationService.java
  3. 28
      src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java

8
src/main/java/com/spring/modules/part/controller/PartInformationController.java

@ -755,6 +755,14 @@ public class PartInformationController {
partInformationService.downLoadObjectFile(id,response); partInformationService.downLoadObjectFile(id,response);
} }
/**
* 下载指定文件夹文件
*/
@PostMapping(value = "/downLoadFile2")
public void downLoadFile2(HttpServletResponse response) throws UnsupportedEncodingException {
partInformationService.downLoadObjectFile2(response);
}
/*** /***
* 根据Excel文件读取料号 * 根据Excel文件读取料号
*/ */

2
src/main/java/com/spring/modules/part/service/PartInformationService.java

@ -140,6 +140,8 @@ public interface PartInformationService {
void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException; void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException;
void downLoadObjectFile2(HttpServletResponse response) throws UnsupportedEncodingException;
List<ChangeRequestVo> getChangeRecordByPartNo2(PlmProjectPartData data); List<ChangeRequestVo> getChangeRecordByPartNo2(PlmProjectPartData data);
Map<String, Object> getPartRevisionEngChgLevel(PartRevisionVo inData); Map<String, Object> getPartRevisionEngChgLevel(PartRevisionVo inData);

28
src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java

@ -3943,6 +3943,34 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
} }
} }
/**
* 下载文件
*/
@Override
public void downLoadObjectFile2(HttpServletResponse response) {
File file = new File("D:\\plm-file\\template\\projectPart.xlsx");
if (!file.exists()) {
throw new RuntimeException("文件不存在");
}
response.reset();
response.setContentType("application/octet-stream;charset=UTF-8");
try {
String fileName = java.net.URLEncoder.encode("项目物料导入模板.xlsx", "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
ServletOutputStream os = response.getOutputStream()) {
byte[] buffer = new byte[1024];
int len;
while ((len = bis.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.flush();
}
} catch (Exception e) {
throw new RuntimeException("文件下载失败", e);
}
}
/** /**
* 获取下一个物料revision * 获取下一个物料revision
* @param inData * @param inData

Loading…
Cancel
Save