Example #1
0
  /**
   * 导出SIM卡信息
   *
   * @return
   */
  public String exportSim() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("simNumber", simNumber);
    map.put("phoneNumber", phoneNumber);
    List<SimInfo> list = new ArrayList<SimInfo>();
    try {
      list = (List<SimInfo>) service.getObjects("SimManage.getSimInfos", map);
    } catch (BusinessException e) {
      setMessage("info.db.error");
      log.error("Export sim error:" + e.getMessage());
      return ERROR;
    } catch (Exception e) {
      setMessage("info.db.error");
      log.error("Export sim error:" + e.getMessage());
      return ERROR;
    }

    String filePath = "";
    OutputStream outputStream = null;
    try {
      // String realPath =
      // ServletActionContext.getServletContext().getRealPath("/");
      // realPath = realPath.replace("\\", "/");
      // realPath = realPath + "exportfile/";

      filePath = "/tmp/" + UUIDGenerator.getUUID() + "Sim.xls";

      File file = new File(filePath);
      if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
      }

      outputStream = new FileOutputStream(filePath);
      // 使用Excel导出器IEExcelExporter
      IEExcelExporter excelExporter = new IEExcelExporter(outputStream);
      excelExporter.setTitle("SIM卡信息");

      excelExporter.putAutoExtendSheets("exportSim", 0, list);
      // 将Excel写入到指定的流中
      excelExporter.write();
    } catch (FileNotFoundException e) {
      setMessage("file.export.error");
      log.error("Export sim error:" + e.getMessage());
      return ERROR;
    } catch (Exception e) {
      setMessage("file.export.error");
      log.error("Export sim error:" + e.getMessage());
      return ERROR;
    } finally {
      // 关闭流
      if (null != outputStream) {
        try {
          outputStream.close();
        } catch (IOException e) {;
        }
      }
    }

    // 设置下载文件属性
    HttpServletResponse response = ServletActionContext.getResponse();
    response.setHeader("Content-disposition", "attachment;filename=Sim.xls");
    response.setContentType("application/msexcel; charset=\"utf-8\"");

    FileInputStream fileInputStream = null;
    OutputStream out = null;
    try {
      // 下载刚生成的文件
      fileInputStream = new FileInputStream(filePath);
      out = response.getOutputStream();
      int i = 0;
      while ((i = fileInputStream.read()) != -1) {
        out.write(i);
      }
    } catch (FileNotFoundException e) {
      setMessage("file.export.error");
      log.error("Export sim error:" + e.getMessage());
      return ERROR;
    } catch (Exception e) {
      setMessage("file.export.error");
      log.error("Export sim error:" + e.getMessage());
      return null;
    } finally {
      // 关闭流
      if (null != fileInputStream) {
        try {
          fileInputStream.close();
        } catch (IOException e) {;
        }
      }
      if (null != out) {
        try {
          out.close();
        } catch (IOException e) {;
        }
      }
      setOperationType(Constants.EXPORT, ModuleId.CLW_M_CS_SIM_EXPORT_MID);
      addOperationLog("导出SIM卡信息");
    }
    // 导出文件成功
    return null;
  }
Example #2
0
  /** 导出 */
  public String exportList(String title, String sheetName, List<AlarmEntity> exportList) {
    String filePath = "";
    OutputStream outputStream = null;
    try {

      filePath = "/tmp/" + UUIDGenerator.getUUID() + sheetName + ".xls";

      File file = new File(filePath);
      if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
      }
      outputStream = new FileOutputStream(filePath);
      // 使用Excel导出器IEExcelExporter
      IEExcelExporter excelExporter = new IEExcelExporter(outputStream);
      excelExporter.setTitle(
          title + "(" + searchVO.getBeginTime() + "~" + searchVO.getEndTime() + ")");

      excelExporter.putAutoExtendSheets(sheetName, 0, exportList);
      // 将Excel写入到指定的流中
      excelExporter.write();
    } catch (FileNotFoundException e) {
      log.error("Export error:" + e.getMessage());
      return ERROR;
    } catch (Exception e) {
      log.error("Export error:" + e.getMessage());
      return ERROR;
    } finally {
      // 关闭流
      if (null != outputStream) {
        try {
          outputStream.close();
        } catch (IOException e) {;
        }
      }
    }
    // 设置下载文件属性
    FileInputStream fileInputStream = null;
    OutputStream out = null;
    try {
      // 设置下载文件属性
      String fileName = URLEncoder.encode(title, "UTF8");
      HttpServletResponse response = ServletActionContext.getResponse();
      response.setHeader(
          "Content-disposition",
          "attachment;filename="
              + fileName
              + "-"
              + DateUtil.formatDateToString(new Date(), "yyyyMMddHHmmss")
              + ".xls");
      response.setContentType("application/msexcel; charset=\"utf-8\"");

      // 下载刚生成的文件
      fileInputStream = new FileInputStream(filePath);
      out = response.getOutputStream();
      int i = 0;
      while ((i = fileInputStream.read()) != -1) {
        out.write(i);
      }
    } catch (FileNotFoundException e) {
      log.error("Export error:" + e.getMessage());
      return ERROR;
    } catch (Exception e) {
      log.error("Export error:" + e.getMessage());
      return ERROR;
    } finally {
      // 关闭流
      if (null != fileInputStream) {
        try {
          fileInputStream.close();
        } catch (IOException e) {;
        }
      }
      if (null != out) {
        try {
          out.close();
        } catch (IOException e) {;
        }
      }
    }
    return null;
  }
Example #3
0
 /**
  * 按记录导出
  *
  * @return
  */
 public String exportRecord() {
   String exportTitle = "驾驶员刷卡记录";
   List<DriverStatInfo> list = new ArrayList<DriverStatInfo>();
   try {
     if ("1".equals(exportObj.getSearchTimeType())) { // 按时段查询
       String start_time = exportObj.getBegTime();
       String end_time = exportObj.getEndTime();
       exportObj.setBegTime(start_time + " 00:00:00");
       exportObj.setEndTime(end_time + " 23:59:59");
     } else {
       String month = exportObj.getMonth();
       String first = month + "-01";
       Calendar cal = Calendar.getInstance();
       cal.set(Calendar.YEAR, Integer.parseInt(month.substring(0, 4)));
       cal.set(Calendar.MONTH, Integer.parseInt(month.substring(5, 7)));
       cal.set(Calendar.DAY_OF_MONTH, 1);
       cal.add(Calendar.DAY_OF_MONTH, -1);
       exportObj.setBegTime(first + " 00:00:00");
       System.out.println(cal.get(Calendar.DAY_OF_MONTH));
       exportObj.setEndTime(month + "-" + cal.get(Calendar.DAY_OF_MONTH) + " 23:59:59");
     }
     String driverIds = exportObj.getDriverId();
     String searchIds = "";
     if (driverIds.length() > 0) {
       String[] Ids = driverIds.split(","); // 字符串转字符数组
       for (String id : Ids) {
         searchIds = searchIds + "'" + id + "',";
       }
       exportObj.setDriverId(searchIds.substring(0, searchIds.length() - 1));
     }
     UserInfo user =
         (UserInfo) ActionContext.getContext().getSession().get(Constants.USER_SESSION_KEY);
     exportObj.setEnterpriseId(user.getOrganizationID());
     if ("1".equals(exportObj.getState())) exportObj.setState("UP");
     else if ("2".equals(exportObj.getState())) exportObj.setState("DOWN");
     list =
         (List<DriverStatInfo>) service.getObjects("Drivershuaka.getDriverRecordList", exportObj);
   } catch (BusinessException e) {
     setMessage("info.db.error");
     log.error(exportTitle + "Export Data error:" + e.getMessage());
     return ERROR;
   } catch (Exception e) {
     e.printStackTrace();
     setMessage("info.db.error");
     log.error(exportTitle + "Export Data error:" + e.getMessage());
     return ERROR;
   }
   String filePath = "";
   OutputStream outputStream = null;
   try {
     filePath = "/tmp/" + UUIDGenerator.getUUID() + "DriverShuaka.xls";
     File file = new File(filePath);
     if (!file.getParentFile().exists()) {
       file.getParentFile().mkdirs();
     }
     outputStream = new FileOutputStream(filePath);
     IEExcelExporter excelExporter = new IEExcelExporter(outputStream);
     if ("1".equals(exportObj.getSearchTimeType())) // 按时段查询
     excelExporter.setTitle(
           exportTitle
               + "("
               + exportObj.getBegTime().substring(0, 10)
               + "——"
               + exportObj.getEndTime().substring(0, 10)
               + ")");
     else excelExporter.setTitle(exportTitle + "(" + exportObj.getMonth() + ")");
     if (null == list || list.size() < 1) {
       list.add(new DriverStatInfo());
     }
     excelExporter.putAutoExtendSheets("exportDriverShuaka", 0, list);
     // 将Excel写入到指定的流中
     excelExporter.write();
   } catch (FileNotFoundException e) {
     setMessage("file.export.error");
     log.error(exportTitle + "Export Data error:" + e.getMessage());
     return ERROR;
   } catch (Exception e) {
     setMessage("file.export.error");
     log.error(exportTitle + "Export Data error:" + e.getMessage());
     return ERROR;
   } finally {
     // 关闭流
     if (null != outputStream) {
       try {
         outputStream.close();
       } catch (IOException e) {;
       }
     }
   }
   // 设置下载文件属性
   HttpServletResponse response = ServletActionContext.getResponse();
   response.setHeader(
       "Content-disposition",
       "attachment;filename=driver_shuaka_info-" + DateUtil.getCurrentDayTime() + ".xls");
   response.setContentType("application/msexcel; charset=\"utf-8\"");
   FileInputStream fileInputStream = null;
   OutputStream out = null;
   try {
     // 下载刚生成的文件
     fileInputStream = new FileInputStream(filePath);
     out = response.getOutputStream();
     int i = 0;
     while ((i = fileInputStream.read()) != -1) {
       out.write(i);
     }
   } catch (FileNotFoundException e) {
     setMessage("file.export.error");
     log.error("Export student error:" + e.getMessage());
     return ERROR;
   } catch (Exception e) {
     setMessage("file.export.error");
     log.error("Export student error:" + e.getMessage());
     return null;
   } finally {
     // 关闭流
     if (null != fileInputStream) {
       try {
         fileInputStream.close();
       } catch (IOException e) {;
       }
     }
     if (null != out) {
       try {
         out.close();
       } catch (IOException e) {;
       }
     }
   }
   // 导出文件成功
   return null;
 }