This commit is contained in:
wwb 2026-01-06 10:18:20 +08:00
parent c7a1eaca9d
commit d260383ba6
2 changed files with 54 additions and 5 deletions

View File

@ -222,14 +222,11 @@ public class StatementAccountController {
// 填充list 的时候还要注意 模板中{.} 多了个点 表示list
// 如果填充list的对象是map,必须包涵所有list的key,哪怕数据为null必须使用map.put(key,null)
//docker生成路径
//URL templateFileUrl = ResourceUtil.getResource("templates/dzd_excel_templates.xlsx");
// org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:templates/dzd_excel_templates.xlsx"); // 例如获取index.html
// String templateFileUrl = resource.getURI().toString();
InputStream resourceAsStream = this.getClass().getResourceAsStream("templates/dzd_excel_templates.xlsx");
InputStream stream = ResourceUtil.getStream("templates/dzd_excel_templates.xlsx");
String pathUrl = System.getProperty("user.dir") + "/pdffile";
String fileName = pathUrl+"/对账单-"+customer.getName()+"-"+DateUtil.date(statementAccount.getDate().toLocalDate()).toString("YYYYMM")+".xlsx";
try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(resourceAsStream).build()) {
try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(stream).build()) {
WriteSheet writeSheet = EasyExcel.writerSheet().build();
// 直接写入数据
excelWriter.fill(models, writeSheet);

View File

@ -0,0 +1,52 @@
package cn.hangtag.module.oms.util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.File;
import java.net.URL;
import java.util.Properties;
@Slf4j
@Component
public class ModuleResourceUtil {
/**
* 获取当前模块ruoyi-system resources 目录路径
*/
public String getModuleResourcePath() {
try {
// 获取当前模块的 classpath
URL resourceUrl = getClass().getClassLoader().getResource("");
if (resourceUrl != null) {
String classpath = resourceUrl.getPath();
// 向上找到 resources 目录
return classpath.replace("/target/classes/", "/src/main/resources/");
}
} catch (Exception e) {
log.warn("无法获取模块资源路径,可能在生产环境");
}
return null;
}
/**
* 读取模块配置文件
*/
public Properties getModuleProperties(String propName) {
String propPath = "config/" + (propName.endsWith(".properties") ? propName : propName + ".properties");
return loadProperties(propPath);
}
/**
* 检查是否是开发环境
*/
public boolean isDevelopment() {
File resourcesDir = new File(getModuleResourcePath());
return resourcesDir.exists() && resourcesDir.isDirectory();
}
private Properties loadProperties(String path) {
// 实现省略
return new Properties();
}
}