| | |
| | | } |
| | | |
| | | /** |
| | | * 获取字符串日期 |
| | | */ |
| | | 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); |
| | | |
| | | 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 = DateUtils.parseDateToStr("month".equals(type) ? DateUtils.YYYYMM : DateUtils.YYYYMMDD, date); |
| | | String target = String.format("%s\\%s.xlsx", getExpPath(type), strData); |
| | | String strData = getStrDate(type, date); |
| | | String target = getTarget(type, date); |
| | | |
| | | File f = new File(target); |
| | | if (!f.exists() || f.isDirectory()) { |
| | | if (!xlsExists(type, date)) { |
| | | createExcel(source, target, list); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 记录是/否存在 |
| | | */ |
| | | private boolean recordExists(String type, Date date) { |
| | | String name = String.format("%s.xlsx", getStrDate(type, date)); |
| | | int rows = mapper.reportExists(type, name); |
| | | |
| | | return rows > 0; |
| | | } |
| | | |
| | | /** |
| | | * 保存结果 |
| | | */ |
| | | private <T> void saveResult(String type, Date date, List<T> list) throws Exception { |
| | | date = DateUtils.trimTime(date); |
| | | String filePath = createExcel(type, date, list); |
| | | String name = filePath.replace(type + "\\", ""); |
| | | if (recordExists(type, date)) return; |
| | | |
| | | int rows = mapper.reportExists(type, name); |
| | | if (rows > 0) return; |
| | | String name = filePath.replace(type + "\\", ""); |
| | | date = DateUtils.trimTime(date); |
| | | |
| | | XlsReport xls = new XlsReport(); |
| | | xls.setName(name); |
| | |
| | | */ |
| | | public void createDayReport(Date date) { |
| | | try { |
| | | String type = "day"; |
| | | Date yesterday = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE); // 2023-07-24 |
| | | if (xlsExists(type, yesterday) && recordExists(type, yesterday)) return; |
| | | |
| | | String yyyy = DateUtils.parseDateToStr(DateUtils.YYYY, yesterday); // 2023 |
| | | String yyyymmdd = DateUtils.parseDateToStr(DateUtils.YYYYMMDD, yesterday); // 20230724 |
| | | // String yyyy_mm_dd = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, yesterday); // 2023-07-24 |
| | | Integer yearStart = Integer.parseInt(yyyy + "010100"); // 2023010100 |
| | | Integer dayStart = Integer.parseInt(yyyymmdd + "00"); // 2023072400 |
| | | Integer end = Integer.parseInt(yyyymmdd + "23"); // 2023072423 |
| | |
| | | |
| | | list.add(new DayExcel("" + rjz, "" + lj, ljtb, ys, "", "", "")); |
| | | } |
| | | saveResult("day", yesterday, list); |
| | | saveResult(type, yesterday, list); |
| | | } catch (Exception ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | } |
| | |
| | | */ |
| | | public void createWeekReport(Date date) { |
| | | try { |
| | | String type = "week"; |
| | | Date mon = DateUtils.getAPeriodOfTime(date, -7, Calendar.DATE); // 2023-07-24 |
| | | Date sun = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE); // 2023-07-30 |
| | | if (xlsExists(type, sun) && recordExists(type, sun)) return; |
| | | |
| | | Date lastMon = DateUtils.getAPeriodOfTime(date, -14, Calendar.DATE); // 2023-07-17 |
| | | Date lastSun = DateUtils.getAPeriodOfTime(date, -8, Calendar.DATE); // 2023-07-23 |
| | | Date lastYear1 = DateUtils.getAPeriodOfTime(mon, -1, Calendar.YEAR); // 2022-07-24 |
| | |
| | | |
| | | list.add(new WeekExcel("" + sz, zhb, ztq, ztb, "" + lj, ljtb, syn, ys, "", "", "")); |
| | | } |
| | | saveResult("week", sun, list); |
| | | saveResult(type, sun, list); |
| | | } catch (Exception ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | } |
| | |
| | | */ |
| | | public void createMonthReport(Date date) { |
| | | try { |
| | | String type = "month"; |
| | | Date yesterday = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE); // 2023-07-31 |
| | | Date monthStart = DateUtils.getMonthStart(yesterday); // 2023-07-01 |
| | | Date monthEnd = DateUtils.getMonthEnd(yesterday); // 2023-07-31 |
| | | if (xlsExists(type, monthEnd) && recordExists(type, monthEnd)) return; |
| | | |
| | | int intMonthStart = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, monthStart) + "00"); // 2023070100 |
| | | int intMonthEnd = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, monthEnd) + "23"); // 2023073123 |
| | | Date lastMonth = DateUtils.getAPeriodOfTime(yesterday, -1, Calendar.MONTH); // 2023-06-30 |
| | |
| | | |
| | | list.add(new MonthExcel("" + sy, yhb, ytq, ytb, "" + lj, ljtb, qyn, ys, "", "", "")); |
| | | } |
| | | saveResult("month", monthEnd, list); |
| | | |
| | | saveResult(type, monthEnd, list); |
| | | } catch (Exception ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | } |