燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-13 2f55cebbad3dea187a5f91d16ec80a9677dab699
src/main/java/com/yssh/service/XlsReportService.java
@@ -23,11 +23,6 @@
import java.io.IOException;
import java.util.*;
/**
 * Excel导出服务类
 * @author WWW
 * @author 2023-08-05
 */
@Service
public class XlsReportService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -62,9 +57,6 @@
    @Value("${report.templates}")
    private String templates;
    /**
     * 获取导出路径
     */
    private String getExpPath(String type) {
        String path = reportPath + File.separator + type;
@@ -76,9 +68,6 @@
        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;
@@ -86,9 +75,6 @@
        return String.format(templates + File.separator + type + ".xlsx");
    }
    /**
     * 创建Excel
     */
    private <T> void createExcel(String source, String target, List<T> list) {
        Map<String, List<T>> map = new HashMap<>();
        map.put("data", list);
@@ -96,25 +82,16 @@
        ExcelUtils.writeToTemplate(source, target, map);
    }
    /**
     * 获取字符串日期
     */
    private String getStrDate(String type, Date date) {
        return DateUtils.parseDateToStr("month".equals(type) ? DateUtils.YYYYMM : DateUtils.YYYYMMDD, date);
    }
    /**
     * 获取目标文件
     */
    private String getTarget(String type, Date date) {
        String strData = getStrDate(type, date);
        return String.format("%s\\%s.xlsx", getExpPath(type), strData);
    }
    /**
     * Excel是/否存在
     */
    private boolean xlsExists(String type, Date date) {
        String target = getTarget(type, date);
        File f = new File(target);
@@ -122,9 +99,6 @@
        return f.exists() && !f.isDirectory();
    }
    /**
     * 创建Excel
     */
    private <T> String createExcel(String type, Date date, List<T> list) throws Exception {
        String source = getXslTemplate(type);
        String strData = getStrDate(type, date);
@@ -137,9 +111,6 @@
        return String.format("%s\\%s.xlsx", type, strData);
    }
    /**
     * 记录是/否存在
     */
    private boolean recordExists(String type, Date date) {
        String name = String.format("%s.xlsx", getStrDate(type, date));
        int rows = mapper.reportExists(type, name);
@@ -147,9 +118,6 @@
        return rows > 0;
    }
    /**
     * 保存结果
     */
    private <T> void saveResult(String type, Date date, List<T> list) throws Exception {
        String filePath = createExcel(type, date, list);
        if (recordExists(type, date)) return;
@@ -166,9 +134,6 @@
        mapper.insertReport(xls);
    }
    /**
     * 获取受影响因素及原因
     */
    public String getYs(List<SuYuan700> suList) {
        if (null == suList || 0 == suList.size()) return "";
@@ -353,9 +318,6 @@
        }
    }
    /**
     * 根据ID下载
     */
    public void downloadById(Integer id, HttpServletResponse res) {
        XlsReport xlsReport = mapper.selectById(id);
        if (null == xlsReport) return;