private String buildEmailBody(Bill bill) {
   StringBuffer sb = new StringBuffer();
   sb.append(
       "您有一条新任务,请进入<a href=\""
           + WebConstants.URL
           + "\" target=\"_blank\">"
           + WebConstants.URL
           + "</a>来处理");
   sb.append("农场管区: ");
   sb.append(bill.getFarm() == null ? "" : bill.getFarm().getName());
   sb.append("-" + bill.getArea() == null ? "" : bill.getArea().getName());
   sb.append("\n");
   sb.append("饲料经理签名:" + (bill.getManager() == null ? "" : bill.getManager().getName()));
   sb.append("\n");
   sb.append("单据编号:" + bill.getOrderId());
   sb.append("\n");
   sb.append("管区:" + (bill.getArea() == null ? "" : bill.getArea().getName()));
   sb.append("\n");
   sb.append("单据:" + (bill.getOrderNo() == null ? "" : bill.getOrderNo()));
   sb.append("\n");
   sb.append("负责人:" + bill.getCurrUserName());
   sb.append("\n");
   sb.append("饲料规格:" + bill.getModel());
   sb.append("\n");
   sb.append("饲料型号:" + bill.getSize());
   sb.append("\n");
   sb.append("饲料吨数:" + bill.getAmount());
   sb.append("\n");
   sb.append("预计达到时间:" + Util.getDate(bill.getPlanDate()));
   sb.append("\n");
   return sb.toString();
 }
  public String getSentBillExcelDownloadFile(
      Bill condition, Date fromDate, Date toDate, String currMan, String accountName) {
    List<Bill> billList =
        billDao.getSentBillList(condition, fromDate, toDate, currMan, accountName);
    String path = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
    path = path.substring(0, path.indexOf("WEB-INF"));
    path += "excel";
    System.out.println("excel saved path : " + path);
    // String sourceFile = path + File.separator + "template.xls";
    String targetFile = path + File.separator + System.currentTimeMillis() + ".xls";
    Workbook rw = null;
    try {
      WritableWorkbook workbook = Workbook.createWorkbook(new File(targetFile));
      WritableSheet sheet = workbook.createSheet("单据列表", 0);

      // 加表头
      WritableFont font = new WritableFont(WritableFont.TIMES, 12, WritableFont.BOLD);
      WritableCellFormat format = new WritableCellFormat(font);
      sheet.addCell(new Label(0, 0, "编号", format));
      sheet.addCell(new Label(1, 0, "供货厂商", format));
      sheet.addCell(new Label(2, 0, "饲料厂商", format));
      sheet.addCell(new Label(3, 0, "计划到料日期", format));
      sheet.addCell(new Label(4, 0, "发料日期", format));
      sheet.addCell(new Label(5, 0, "到料日期", format));
      sheet.addCell(new Label(6, 0, "规格", format));
      sheet.addCell(new Label(7, 0, "用料量(吨)", format));
      sheet.addCell(new Label(8, 0, "合计金额", format));
      sheet.addCell(new Label(9, 0, "单据状态", format));
      sheet.addCell(new Label(10, 0, "当前处理人", format));
      sheet.addCell(new Label(11, 0, "所属区域", format));
      // 加内容
      int i = 1;
      for (Bill f : billList) {
        sheet.addCell(new Number(0, i, f.getId()));
        sheet.addCell(new Label(1, i, f.getProvider().getName()));
        sheet.addCell(new Label(2, i, f.getFactory().getName()));
        sheet.addCell(new Label(3, i, f.getPlanDate().toString()));
        sheet.addCell(new Label(4, i, Util.getDate(f.getSendDate()))); // 发料日期
        sheet.addCell(new Label(5, i, Util.getDate(f.getFinishDate()))); // 到料日期
        sheet.addCell(new Label(6, i++, f.getSize()));
        sheet.addCell(new Number(7, i++, f.getAmount()));
        sheet.addCell(new Label(8, i++, f.getBillPrice()));
        sheet.addCell(new Label(9, i++, f.getStatusTxt()));
        sheet.addCell(new Label(10, i++, f.getCurrUserName())); // 当前处理人
        sheet.addCell(new Label(11, i++, f.getFarm().getName()));
      }

      workbook.write();
      workbook.close();
      return targetFile;
    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      if (rw != null) rw.close();
    }
    return null;
  }
 private String getEmailAddr(Bill bill) {
   if (bill == null) return null;
   String currName = bill.getCurrUserName();
   if (!Util.isEmpty(currName)) {
     List<User> list = billDao.getEntitiesByColumn(User.class, "name", currName);
     if (list != null && list.size() > 0) return list.get(0).getEmail();
   }
   return null;
 }