燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-09 2c786593c62d1a97cfc531b35106798047279042
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * Excel导出服务类
 * @author WWW
 * @author 2023-08-05
 */
@Service
public class XlsExportService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
 
    @Value("${report.path}")
    private String reportPath;
 
    /**
     * 获取导出路径
     */
    private String getExpPath(String type) {
        String path = reportPath + File.separator + type;
 
        File f = new File(path);
        if (!f.exists() || !f.isDirectory()) {
            f.mkdirs();
        }
 
        return path;
    }
 
    /**
     * 获取Excel模板
     */
    private String getXslTemplate(String type) throws IOException {
        ClassPathResource resource = new ClassPathResource(String.format("templates/%s.xlsx", type));
 
        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 {
            String type = "day";
            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(type);
            String target = String.format("%s\\%d.xlsx", getExpPath(type), 20230808);
 
            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);
        }
    }
}