From 7151950387b07d8ef9ebfc6e57dc3499e5d80b9b Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 09 八月 2023 09:45:42 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/entity/xls/DayExcel.java | 10 +++++ src/main/java/com/yssh/service/XlsExportService.java | 62 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/yssh/entity/xls/DayExcel.java b/src/main/java/com/yssh/entity/xls/DayExcel.java index fac400e..4231dc5 100644 --- a/src/main/java/com/yssh/entity/xls/DayExcel.java +++ b/src/main/java/com/yssh/entity/xls/DayExcel.java @@ -44,6 +44,16 @@ public DayExcel() { } + public DayExcel(String rjz, String lj, String ljtb, String ys, String fs, String fx, String wd) { + this.rjz = rjz; + this.lj = lj; + this.ljtb = ljtb; + this.ys = ys; + this.fs = fs; + this.fx = fx; + this.wd = wd; + } + public String getRjz() { return rjz; } diff --git a/src/main/java/com/yssh/service/XlsExportService.java b/src/main/java/com/yssh/service/XlsExportService.java index 57556f1..fc38802 100644 --- a/src/main/java/com/yssh/service/XlsExportService.java +++ b/src/main/java/com/yssh/service/XlsExportService.java @@ -1,9 +1,17 @@ package com.yssh.service; +import com.yssh.entity.xls.DayExcel; +import com.yssh.utils.ExcelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Excel瀵煎嚭鏈嶅姟绫� @@ -12,6 +20,8 @@ */ @Service public class XlsExportService { + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + /** * 鑾峰彇Excel妯℃澘 */ @@ -21,4 +31,56 @@ return resource.exists() ? resource.getFile().getPath() : null; } + /** + * 鍒涘缓Excel + */ + private <T> void createExcel(String source, String target, List<T> list) { + Map<String, List<T>> map = new HashMap<>(); + map.put("data", list); + + ExcelUtils.writeToTemplate(source, target, map); + } + + /** + * 鍒涘缓鏃ユ姤 + */ + public void createDayReport() { + try { + List<DayExcel> list = new ArrayList<>(); + for (int i = 1; i < 47; i++) { + DayExcel day = new DayExcel("AI-" + (i < 10 ? "0" : "") + i, "lj", "ljtb", "ys", "fs", "fx", "wd"); + list.add(day); + } + + String source = getXslTemplate("day"); + String target = ""; + createExcel(source, target, list); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + /** + * 鍒涘缓鍛ㄦ姤 + */ + public void createWeekReport() { + try { + String source = getXslTemplate("week"); + + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + + /** + * 鍒涘缓鏈堟姤 + */ + public void createMonthReport() { + try { + String source = getXslTemplate("month"); + + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } } -- Gitblit v1.9.3