コード例 #1
0
  @RequestMapping("download")
  public void download(ReportVo reportVo, HttpServletResponse response, HttpServletRequest request)
      throws IOException {
    if (reportVo != null) {
      String template = "config/templates/" + reportVo.getReportType() + ".html";
      PdfDocumentGenerator pdfGenerator = new PdfDocumentGenerator();
      List<User> users = userService.findAll();
      if (users != null) {
        List<DocumentVo> employeeReportVos = new ArrayList<DocumentVo>();
        for (User user : users) {
          EmployeeReportVo employeeReportVo = new EmployeeReportVo(user, reportVo.getReportType());
          if (employeeReportVo.getIsEmployee() != null && employeeReportVo.getIsEmployee()) {
            employeeReportVos.add(employeeReportVo);
          }
        }
        try {
          if (reportVo.getReportType().equals(ReportType.TimeCardReport.name())
              || reportVo.getReportType().equals(ReportType.ExceptionsReport.name())) {
            try {
              pdfGenerator.generate(
                  createTimeCardReport(reportVo, employeeReportVos), response.getOutputStream());
            } catch (Exception e) {
              e.printStackTrace();
            }
          } else {
            pdfGenerator.generate(template, employeeReportVos, response.getOutputStream());
          }

        } catch (DocumentGeneratingException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #2
0
  private String createTimeCardReport(ReportVo reportVo, List<DocumentVo> documentVos) {
    if (documentVos == null) return "";
    HtmlGenerator htmlGenerator = new HtmlGenerator();
    Map<String, Object> variables = new HashMap<String, Object>();
    String timeCardReportHead = null;
    Template timeCardReportTable = null;
    Template timeCardReportTr = null;
    StringBuffer timeCardReportTableStrs = new StringBuffer();

    int index = 0;
    String templateHead = "config/templates/" + reportVo.getReportType() + "_head.html";
    String templateTable = "config/templates/" + reportVo.getReportType() + "_table.html";
    String templateTr = "config/templates/" + reportVo.getReportType() + "_tr.html";
    try {
      for (DocumentVo documentVo : documentVos) {
        variables = documentVo.fillDataMap();
        if (index == 0) {
          timeCardReportHead = htmlGenerator.generate(templateHead, variables);
          timeCardReportTable = htmlGenerator.generate(templateTable);
          timeCardReportTr = htmlGenerator.generate(templateTr);
        }
        String timeCardReportTableStr = htmlGenerator.generate(timeCardReportTable, variables);
        timeCardReportTableStrs.append(
            timeCardReportTableStr.replace(
                "#tr#", createTimeCardTrReport(timeCardReportTr, documentVo, htmlGenerator)));
      }
      return timeCardReportHead.replace("#table#", timeCardReportTableStrs.toString());
    } catch (IOException e) {
      e.printStackTrace();
    } catch (TemplateException e) {
      e.printStackTrace();
    }
    return "";
  }
コード例 #3
0
 @RequestMapping("/save")
 public ModelAndView saveReport(
     ReportVo reportVo, HttpServletResponse response, HttpServletRequest request)
     throws Exception {
   User user = SessionUtils.getUser(request);
   ModelAndView view = new ModelAndView();
   Report report = new Report();
   if (StringUtils.isNotEmpty(reportVo.getId())) {
     report = reportLogService.findById(reportVo.getId());
   }
   if (StringUtils.isNotEmpty(reportVo.getPaging())) {
     report.setPaging(reportVo.getPaging());
   }
   if (StringUtils.isNotEmpty(reportVo.getSort())) {
     report.setSort(reportVo.getSort());
   }
   if (StringUtils.isNotEmpty(reportVo.getPayGroupId())) {
     PayGroup payGroup = tmsService.findPayGroupById(reportVo.getPayGroupId());
     if (payGroup != null) {
       report.setPayGroup(payGroup);
     }
   }
   if (StringUtils.isNotEmpty(reportVo.getReportType())) {
     report.setReportType(ReportType.valueOf(reportVo.getReportType()));
   }
   report.setUpdateTime(new Date());
   if (StringUtils.isNotEmpty(reportVo.getId())) {
     reportLogService.update(report);
   } else {
     report.setUser(user);
     report.setCompany(user.getCompany());
     reportLogService.save(report);
   }
   view.getModel().put("message", "success");
   return view;
 }