Ejemplo n.º 1
0
  /**
   * This method will export historical report to pdf format
   *
   * @param List<HistoricReportDTO>
   * @return boolean
   * @throws Exception
   */
  public JasperReportBuilder exportHistoricalReport(
      List<HistoricReportDTO> historicalReportdtoList) {
    logger.info("HistoricReportServiceImpl >> exportHistoricalReport");

    JasperReportBuilder report = DynamicReports.report();

    StyleBuilder boldStyle = stl.style().bold();
    StyleBuilder boldCenteredStyle =
        stl.style(boldStyle).setHorizontalAlignment(HorizontalAlignment.CENTER);

    StyleBuilder titleStyle =
        stl.style(boldCenteredStyle)
            .setBorder(stl.pen1Point())
            .setBackgroundColor(Color.LIGHT_GRAY);

    report
        .columns(
            Columns.column("Date", "dateStamp", DataTypes.stringType())
                .setHorizontalAlignment(HorizontalAlignment.LEFT),
            Columns.column("Time", "timeStamp", DataTypes.stringType()),
            Columns.column("Feeder Name", "feederName", DataTypes.stringType()),
            Columns.column("Parameter Name", "parameterName", DataTypes.stringType()),
            Columns.column("Value", "value", DataTypes.stringType()))
        .title(
            Components.text("Historical Report Results")
                .setHorizontalAlignment(HorizontalAlignment.CENTER)
                .setStyle(titleStyle))
        .pageFooter(Components.pageXofY())
        .setDataSource(historicalReportdtoList);

    return report;
  }
Ejemplo n.º 2
0
 @Action(
     value = "exportQdtgXLS",
     results = {
       @Result(
           name = "xls",
           type = "stream",
           params = {
             "contentType",
             "application/octet-stream;charset=ISO8859-1",
             "inputName",
             "inputStream",
             "contentDisposition",
             "attachment;filename=\"${downloadFileName}\"",
             "bufferSize",
             "4096"
           })
     })
 public String exportQdtgXLS() {
   String title = "";
   HttpServletResponse response = ServletActionContext.getResponse();
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   try {
     if (statCondition.getStatType() == SysConfig.QDTG_STAT_DAY) {
       title = "对帐单-按日";
       statRecords = qdtgRecordModel.statQdtgRecordByDay(statCondition, start, limit);
     } else {
       title = "对帐单-按月";
       statRecords = qdtgRecordModel.statQdtgRecordByMonth(statCondition);
     }
     setDownloadFileName(title);
     JasperReportBuilder report = DynamicReports.report(); // 创建空报表
     JasperXlsExporterBuilder xlsExporter =
         DynamicReports.export
             .xlsExporter(buffer)
             .setDetectCellType(true)
             .setIgnorePageMargins(true)
             .setWhitePageBackground(false)
             .setRemoveEmptySpaceBetweenColumns(true);
     report
         .setColumnTitleStyle(ReportConfig.getColumnTitleStl())
         .addProperty(JasperProperty.EXPORT_XLS_FREEZE_ROW, "2")
         .ignorePageWidth()
         .ignorePagination()
         .columns(
             Columns.column("日期", "recordTime", DataTypes.stringType()),
             Columns.column("产品", "productName", DataTypes.stringType()),
             Columns.column("渠道号", "channelNo", DataTypes.stringType()),
             Columns.column("文件名", "fileName", DataTypes.stringType()),
             Columns.column("单价", "unitPrice", DataTypes.floatType()),
             Columns.column(
                 "激活",
                 "activateQt_Net",
                 statCondition.getStatType() == SysConfig.QDTG_STAT_DAY
                     ? DataTypes.integerType()
                     : DataTypes.longType()),
             Columns.column(
                 "小计",
                 "totalPrice_Net",
                 statCondition.getStatType() == SysConfig.QDTG_STAT_DAY
                     ? DataTypes.floatType()
                     : DataTypes.doubleType()))
         .title(Components.text(title).setStyle(ReportConfig.getTitleStl())); // 标题
     if (statRecords == null || statRecords.size() <= 0) {
       report.setDataSource(new JREmptyDataSource());
     } else {
       report.setDataSource(statRecords); // 数据源
     }
     report.toXls(xlsExporter);
     byte[] bytes = buffer.toByteArray();
     response.setContentLength(bytes.length);
     if (bytes != null) {
       inputStream = new ByteArrayInputStream(bytes);
     }
     return "xls";
   } catch (Exception e) {
     setErrorMessage(e);
     log.error(e.getMessage(), e);
     statRecords = null;
     return JSON;
   } finally {
     try {
       buffer.close();
       if (inputStream != null) inputStream.close();
     } catch (Exception e) {
       log.error(e.getMessage(), e);
     }
   }
 }