燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-11 dc4ca57e049ec18d8303109d1aa332096b880a34
src/main/java/com/yssh/service/XlsReportService.java
@@ -10,6 +10,7 @@
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.DateUtils;
import com.yssh.utils.ExcelUtils;
import com.yssh.utils.WebUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -17,6 +18,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;
@@ -343,4 +345,22 @@
            logger.error(ex.getMessage(), ex);
        }
    }
    /**
     * 根据ID下载
     */
    public void downloadById(Integer id, HttpServletResponse res) {
        XlsReport xlsReport = mapper.selectById(id);
        if (null == xlsReport) return;
        String file = reportPath + File.separator + xlsReport.getPath();
        File f = new File(file);
        if (!f.exists() || f.isDirectory()) return;
        try {
            WebUtils.download(file, xlsReport.getName(), false, res);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}