燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-09 7151950387b07d8ef9ebfc6e57dc3499e5d80b9b
1
已修改2个文件
72 ■■■■■ 文件已修改
src/main/java/com/yssh/entity/xls/DayExcel.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/service/XlsExportService.java 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    }
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);
        }
    }
}