public Report saveReport(Report r, String reportType) { if ("year".equals(r.getType())) { r.setTime(null); } User user = (User) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ); if (user instanceof Org) { Org org = (Org) user; Cun cun = org.getCun(); Report report = reportDao.getReport(reportType, org, cun, r.getYear(), r.getType(), r.getTime()); for (int i = 1; i <= 60; i++) { report.setItem(i, r.getItem(i)); } report.setCun(cun); report.setOrg(org); report.setYear(r.getYear()); report.setType(r.getType()); report.setTime(r.getTime()); report.setLock(1); // 1表示已经锁定 reportDao.saveOrUpdate(report); // 如果是月份的报表,则生成季度和年份的报表 if ("month".equals(r.getType())) { generateSeasonAndYear(reportType, org, cun, r); } return report; } return null; }
private void generateSeasonAndYear(String reportType, Org org, Cun cun, Report r) { // 生成季度的 int month = Integer.valueOf(r.getTime()); int time = month % 3 == 0 ? month / 3 : month / 3 + 1; Report reportSeason = reportDao.getReport(reportType, org, cun, r.getYear(), "season", time + ""); int minMonth = time * 3 - 2; int maxMonth = time * 3; clearItems(reportSeason); for (int m = minMonth; m <= maxMonth; m++) { Report mReport = reportDao.getReport(reportType, org, cun, r.getYear(), "month", m + ""); addItems(reportSeason, mReport); // 特殊字段处理 if (maxMonth == m && "1".equals(reportType)) { reportSeason.setItem13(mReport.getItem13()); reportSeason.setItem14(mReport.getItem14()); reportSeason.setItem31(mReport.getItem31()); fillReport(reportSeason); } else if (maxMonth == m && "2".equals(reportType)) { reportSeason.setItem1(mReport.getItem1()); } else { reportSeason.setItem13(""); reportSeason.setItem14(""); } } clearItemsZero(reportSeason); reportDao.saveOrUpdate(reportSeason); // 生成年度的 Report reportYear = reportDao.getReport(reportType, org, cun, r.getYear(), "year", null); clearItems(reportYear); for (int m = 1; m <= 12; m++) { Report mReport = reportDao.getReport(reportType, org, cun, r.getYear(), "month", m + ""); addItems(reportYear, mReport); // 特殊字段处理 if (12 == m && "1".equals(reportType)) { reportYear.setItem13(mReport.getItem13()); reportYear.setItem14(mReport.getItem14()); reportYear.setItem31(mReport.getItem31()); fillReport(reportYear); } else if (12 == m && "2".equals(reportType)) { reportYear.setItem1(mReport.getItem1()); } else { reportYear.setItem13(""); reportYear.setItem14(""); } } clearItemsZero(reportYear); reportDao.saveOrUpdate(reportYear); }
public void requestUnlock(Report r, String reportType) { User user = (User) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ); if (user instanceof Org) { Org org = (Org) user; Cun cun = org.getCun(); Report report = reportDao.getReport(reportType, org, cun, r.getYear(), r.getType(), r.getTime()); report.setLock(2); // 2表示请求解锁 reportDao.saveOrUpdate(report); } }
public String getExcelReportFilePath(Report r, String reportType) throws Exception { // 获取参数 Integer year = r.getYear(); String type = r.getType(); String time = r.getTime(); // 文件拷贝 String path = Thread.currentThread().getContextClassLoader().getResource("/").getPath(); path = path.substring(0, path.indexOf("WEB-INF")); path += "excel"; String sourceFile = path + File.separator + "report" + reportType + ".xls"; String targetFile = path + File.separator + "report" + reportType + "_" + year + type + time + ".xls"; // 获取数据 Org org = (Org) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ); Cun cun = org.getCun(); Report report = reportDao.getReport(reportType, org, cun, year, type, time); if (report != null && report.getId() != null) { // 打开excel文件 Workbook rw = Workbook.getWorkbook(new File(sourceFile)); WritableWorkbook workbook = Workbook.createWorkbook(new File(targetFile), rw); if ("1".equals(reportType)) { // 重新更新一下季度和年度的数据 if ("year".equals(report.getType()) || "season".equals(report.getType())) { generateSeasonAndYear( "1", org, cun, reportDao.getReport("1", org, cun, year, "month", "6")); } // 日期类型 String str = year + "年"; if ("season".equals(report.getType())) { str += time + "季"; } else if ("month".equals(report.getType())) { str += time + "月"; } WritableSheet sheet1 = workbook.getSheet(0); WritableSheet sheet2 = workbook.getSheet(1); sheet1.addCell(new Label(0, 2, str)); sheet2.addCell(new Label(0, 2, str)); fillReportRow1(7, workbook, org, cun, report, false); if (!"year".equals(report.getType())) { Report leijiReport = reportDao.getReport(reportType, org, cun, year, "year", null); // 特殊字段处理 if ("season".equals(report.getType())) { leijiReport.setItem13(report.getItem13()); leijiReport.setItem14(report.getItem14()); leijiReport.setItem31(report.getItem31()); } // fillReportRow1(8, workbook, org, cun, leijiReport,true); } } else if ("2".equals(reportType)) { // 重新更新一下季度和年度的数据 if ("year".equals(report.getType()) || "season".equals(report.getType())) { generateSeasonAndYear( "2", org, cun, reportDao.getReport("2", org, cun, year, "month", "6")); } // 日期类型 String str = year + "年"; if ("season".equals(report.getType())) { str += time + "季"; } else if ("month".equals(report.getType())) { str += time + "月"; } WritableSheet sheet1 = workbook.getSheet(0); sheet1.addCell(new Label(0, 2, str)); fillReportRow2(6, workbook, org, cun, report, false); if (!"year".equals(report.getType())) { // fillReportRow2(7, workbook, org, cun, // reportDao.getReport(reportType, org, cun, year, "year", // null),true); } } // 关闭 workbook.write(); workbook.close(); rw.close(); return targetFile; } return null; }