Browse Source

[feat]

修改文件下载类的获取文件相对路径的方法
新增 获取文件附件配置类
Shiro过滤器配置新增 过滤 /attachments/文件夹
修改销售出货单的所有导出方法,统一调用文件下载类的获取文件相对路径的方法
修改/attachments/文件路径: 由resources下面->移动到static下面
dev
liuxiaoxu 3 months ago
parent
commit
6b5251da83
  1. 8
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java
  2. 0
      ruoyi-admin/src/main/resources/static/attachments/FinancialReceiptVoucherTemplate.xlsx
  3. 0
      ruoyi-admin/src/main/resources/static/attachments/test.docx
  4. 0
      ruoyi-admin/src/main/resources/static/attachments/出货通知单.xlsx
  5. 0
      ruoyi-admin/src/main/resources/static/attachments/采购合同.docx
  6. 0
      ruoyi-admin/src/main/resources/static/attachments/销售出货单1.xlsx
  7. 0
      ruoyi-admin/src/main/resources/static/attachments/销售出货单2.xlsx
  8. 0
      ruoyi-admin/src/main/resources/static/attachments/销售出货箱单1.xlsx
  9. 0
      ruoyi-admin/src/main/resources/static/attachments/销售出货箱单2.xlsx
  10. 15
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileDownloadUtils.java
  11. 20
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilePathConfig.java
  12. 3
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/ShiroConfig.java

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

@ -393,7 +393,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try { try {
String fileAbsolutePath = fileDownloadUtils.getFileAbsolutePath(fileName); String fileAbsolutePath = fileDownloadUtils.getFileRelativePath(fileName);
SysSalesShippingInform salesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode); SysSalesShippingInform salesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode);
@ -462,7 +462,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try { try {
String fileAbsolutePath = fileDownloadUtils.getFileAbsolutePath(fileName); String fileAbsolutePath = fileDownloadUtils.getFileRelativePath(fileName);
SysSalesShippingInform salesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode); SysSalesShippingInform salesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode);
@ -535,7 +535,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try { try {
String fileRelativePath = fileDownloadUtils.getFileAbsolutePath(fileName); String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
SysSalesShippingInform sysSalesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode); SysSalesShippingInform sysSalesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode);
@ -606,7 +606,7 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor
FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); FileDownloadUtils fileDownloadUtils = new FileDownloadUtils();
try { try {
String fileRelativePath = fileDownloadUtils.getFileAbsolutePath(fileName); String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName);
SysSalesShippingInform sysSalesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode); SysSalesShippingInform sysSalesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode);

0
ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx → ruoyi-admin/src/main/resources/static/attachments/FinancialReceiptVoucherTemplate.xlsx

0
ruoyi-admin/src/main/resources/attachments/test.docx → ruoyi-admin/src/main/resources/static/attachments/test.docx

0
ruoyi-admin/src/main/resources/attachments/出货通知单.xlsx → ruoyi-admin/src/main/resources/static/attachments/出货通知单.xlsx

0
ruoyi-admin/src/main/resources/attachments/采购合同.docx → ruoyi-admin/src/main/resources/static/attachments/采购合同.docx

0
ruoyi-admin/src/main/resources/attachments/销售出货单1.xlsx → ruoyi-admin/src/main/resources/static/attachments/销售出货单1.xlsx

0
ruoyi-admin/src/main/resources/attachments/销售出货单2.xlsx → ruoyi-admin/src/main/resources/static/attachments/销售出货单2.xlsx

0
ruoyi-admin/src/main/resources/attachments/销售出货箱单1.xlsx → ruoyi-admin/src/main/resources/static/attachments/销售出货箱单1.xlsx

0
ruoyi-admin/src/main/resources/attachments/销售出货箱单2.xlsx → ruoyi-admin/src/main/resources/static/attachments/销售出货箱单2.xlsx

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

@ -14,6 +14,8 @@ import java.nio.file.Paths;
public class FileDownloadUtils { public class FileDownloadUtils {
private static final String FILE_PATH_PATH = "/static/attachments/";
// 获取文件绝对路径 // 获取文件绝对路径
public String getFileAbsolutePath(String fileName) throws IOException { public String getFileAbsolutePath(String fileName) throws IOException {
@ -25,13 +27,14 @@ public class FileDownloadUtils {
//获取文件的相对路径 //获取文件的相对路径
public String getFileRelativePath(String fileName) throws IOException { public String getFileRelativePath(String fileName){
ClassPathResource resource = new ClassPathResource("attachments/" + fileName); ClassPathResource resource = new ClassPathResource(FILE_PATH_PATH + fileName);
Path path = Paths.get(resource.getURI()); try {
File file = path.toFile(); return resource.getFile().getAbsolutePath();
return file.getPath(); } catch (IOException e) {
throw new RuntimeException("无法获取文件绝对路径", e);
}
} }

20
ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilePathConfig.java

@ -0,0 +1,20 @@
package com.ruoyi.framework.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 获取文件附件配置类
* */
@Configuration
public class FilePathConfig implements WebMvcConfigurer{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//附件文件都在静态目录static下存放
registry.addResourceHandler("/attachments/**").addResourceLocations("classpath:/static/attachments/");
}
}

3
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ShiroConfig.java

@ -255,6 +255,9 @@ public class ShiroConfig
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 对静态资源设置匿名访问 // 对静态资源设置匿名访问
filterChainDefinitionMap.put("/favicon.ico**", "anon"); filterChainDefinitionMap.put("/favicon.ico**", "anon");
filterChainDefinitionMap.put("/attachments/**", "anon");
filterChainDefinitionMap.put("/ruoyi.png**", "anon"); filterChainDefinitionMap.put("/ruoyi.png**", "anon");
filterChainDefinitionMap.put("/html/**", "anon"); filterChainDefinitionMap.put("/html/**", "anon");
filterChainDefinitionMap.put("/css/**", "anon"); filterChainDefinitionMap.put("/css/**", "anon");

Loading…
Cancel
Save