| | |
| | | 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; |
| | |
| | | @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模板 |
| | |
| | | */ |
| | | 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("day"); |
| | | String target = ""; |
| | | 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); |