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;
  }
  // 显示最新的cun的数据
  public void fillReport(Report r) {
    User user = (User) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ);
    if (user instanceof Org) {
      Org org = (Org) user;
      Cun cun = org.getCun();
      cun = reportDao.getEntityById(Cun.class, cun.getId());
      // Long familySum = reportDao.getEntitySum(Family.class, "cun",
      // cun);
      r.setItem1(cun.getPoorFamilyNum() == null ? "" : cun.getPoorFamilyNum() + "");
      // Long personSum = familyDao.getPersonSum(cun);
      r.setItem2(cun.getPoorPersonNum() == null ? "" : cun.getPoorPersonNum() + "");

      r.setItem3(cun.getPoorFamilyNum1() == null ? "" : cun.getPoorFamilyNum1() + "");
      r.setItem4(cun.getPoorPersonNum1() == null ? "" : cun.getPoorPersonNum1() + "");
      r.setItem5(cun.getPoorFamilyNum3() == null ? "" : cun.getPoorFamilyNum3() + "");
      r.setItem6(cun.getPoorPersonNum3() == null ? "" : cun.getPoorPersonNum3() + "");
      r.setItem7(cun.getPoorFamilyNum2() == null ? "" : cun.getPoorFamilyNum2() + "");
      r.setItem8(cun.getPoorPersonNum2() == null ? "" : cun.getPoorPersonNum2() + "");
      r.setItem9(cun.getPoorFamilyNum4() == null ? "" : cun.getPoorFamilyNum4() + "");
      r.setItem10(cun.getPoorPersonNum4() == null ? "" : cun.getPoorPersonNum4() + "");
      r.setItem11(cun.getWeiHouse() == null ? "" : cun.getWeiHouse() + "");

      // if(Util.isEmpty(r.getItem30()))
      r.setItem30(cun.getIncome() == null ? "" : cun.getIncome() + "");
      // if("0".equals(r.getItem30())){
      // r.setItem30("");
      // }
    }
  }
 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 Report getReport(String reportType, Integer year, String type, String time) {
   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, year, type, time);
     // if (report.getId() != null)
     return report;
   }
   return null;
 }
  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;
  }