Browse Source

[fix] 销售管理

修改统一的文件下载工具类,修复本地windows系统和服务器linux系统文件路径不一致导致导出模板找不到文件问题。
修改导出销售出货单1后端接口、修改导出销售出货单2后端接口、修改导出销售出货箱单1后端接口、修改导出销售出货箱单2后端接口、修改导出销售出货发票1后端接口、修改导出销售出货发票2后端接口、修改导出出货通知单后端接口,采用新的查找文件方法
dev
liuxiaoxu 1 week ago
parent
commit
b5e9e5a82a
  1. 37
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java
  2. 27
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileDownloadUtils.java

37
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java

@ -399,10 +399,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
public void exportShippingOrderOne(String outOrderCode, HttpServletResponse response) {
String fileName = "销售出货单1.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileAbsolutePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出库单号为空:{}",outOrderCode);
@ -482,10 +481,10 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
public void exportShippingOrderTwo(String outOrderCode, HttpServletResponse response) {
String fileName = "销售出货单2.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileAbsolutePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出库单号为空:{}",outOrderCode);
@ -564,9 +563,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
String fileName = "销售出货箱单1.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出库单号为空:{}",outOrderCode);
throw new RuntimeException("出库单号为空,请检查");
@ -616,7 +615,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
}
//构建模板
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build();
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build();
WriteSheet sheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
@ -639,9 +638,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
public void exportShippingPackingTwo(String outOrderCode, HttpServletResponse response) {
String fileName = "销售出货箱单2.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出库单号为空:{}",outOrderCode);
throw new RuntimeException("出库单号为空,请检查");
@ -697,7 +696,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
}
//构建模板
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build();
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build();
WriteSheet sheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
@ -718,9 +717,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
@Override
public void exportShippingInvoiceOne(String outOrderCode, HttpServletResponse response) {
String fileName = "销售出货发票1.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出货单号为空,请检查:{}", outOrderCode);
throw new RuntimeException("出货单号为空,请检查");
@ -786,7 +785,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
}
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build();
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build();
WriteSheet sheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
workBook.fill(map, sheet);
@ -806,9 +805,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
@Override
public void exportShippingInvoiceTwo(String outOrderCode, HttpServletResponse response) {
String fileName = "销售出货发票2.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出货单号为空,请检查:{}", outOrderCode);
throw new RuntimeException("出货单号为空,请检查");
@ -874,7 +873,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
}
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build();
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build();
WriteSheet sheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
workBook.fill(map, sheet);
@ -894,9 +893,9 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
public void exportShippingInformOrder(String outOrderCode, HttpServletResponse response) {
String fileName = "出货通知单.xlsx";
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try {
String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
String fileAbsolutePath = FileDownloadUtils.getFileAbsolutePath(fileName);
if (StringUtils.isEmpty(outOrderCode)){
log.warn("出货单号为空,请检查:{}", outOrderCode);
throw new RuntimeException("出货单号为空,请检查");
@ -940,7 +939,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
map.put("customerName",sysSalesShippingInform.getCustomerName());
map.put("businessMembers",sysSalesShippingInform.getBusinessMembers());
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build();
ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build();
WriteSheet sheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();

27
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileDownloadUtils.java

@ -1,12 +1,17 @@
package com.ruoyi.common.utils.file;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/**
* 文件下载类
@ -18,13 +23,24 @@ public class FileDownloadUtils {
// 获取文件绝对路径
public String getFileAbsolutePath(String fileName) throws IOException {
ClassPathResource resource = new ClassPathResource("attachments/" + fileName);
File file = resource.getFile();
return file.getPath();
}
public static String getFileAbsolutePath(String fileName) throws IOException {
Resource resource = new ClassPathResource(FILE_PATH_PATH + fileName);
// 确认资源存在
if (!resource.exists()) {
throw new FileNotFoundException("找不到文件: " + fileName);
}
// 创建临时文件
File tempFile = File.createTempFile("temp", null);
tempFile.deleteOnExit(); // 确保程序结束时删除临时文件
// 将资源复制到临时文件
Files.copy(resource.getInputStream(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
// 返回临时文件的绝对路径
return tempFile.getAbsolutePath();
}
//获取文件的相对路径
@ -37,5 +53,4 @@ public class FileDownloadUtils {
}
}
}

Loading…
Cancel
Save