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 Bill finishBill(Bill b, String[] billDetail) {
    Bill bill = baseDao.getEntityById(Bill.class, b.getId());
    bill.setFinishDate(b.getFinishDate());
    bill.setFinishAmount(b.getFinishAmount());
    bill.setFinishPrice(b.getFinishPrice());
    bill.setFinishRemark(b.getFinishRemark());
    bill.setStatus(WebConstants.BILL_STATUS_FINISH);

    // 保存农户财务明细
    for (String detail : billDetail) {
      String[] arr = detail.split(",");
      long areaId = Long.parseLong(arr[0]);
      long farmerId = Long.parseLong(arr[1]);
      double amount = Double.parseDouble(arr[2]);
      double totalPrice = Double.parseDouble(arr[3]);
      FarmerFinance ff = new FarmerFinance();
      ff.setAmount(amount);
      ff.setArea(this.getEntityById(Area.class, areaId));
      ff.setBill(bill);
      ff.setCreateDate(new Date());
      ff.setCreateName(
          ((User) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ))
              .getName());
      ff.setEnable(true);
      ff.setFactory(bill.getFactory());
      ff.setFarmer(this.getEntityById(Farmer.class, farmerId));
      ff.setModel(bill.getModel());
      ff.setMoney(totalPrice);
      ff.setProvider(bill.getProvider());
      ff.setRateFromDate(bill.getFinishDate());
      ff.setSize(bill.getSize());
      ff.setType(0);
      billDao.saveOrUpdate(ff);
      logger.info("农户分配财务信息保存成功【" + ff.getFarmer().getName() + "】");
    }

    // 保存供应厂财务明细
    ProviderFinance pf = new ProviderFinance();
    pf.setBill(bill);
    pf.setCreateDate(new Date());
    pf.setCreateName(
        ((User) ActionContext.getContext().getSession().get(WebConstants.SESS_USER_OBJ)).getName());
    pf.setEnable(true);
    pf.setProvider(bill.getProvider());
    pf.setAmount(bill.getFinishAmount());
    pf.setFarm(bill.getFarm());
    pf.setFarmer(bill.getFarmer());
    pf.setFactory(bill.getFactory());
    // pf.setMoney(bill.getFinishPrice());
    // 获取实付料款
    pf.setMoney(Util.multiplyMoney(bill.getAmount(), bill.getPriceOnOrder()));
    pf.setAgentMoney(Util.multiplyMoney(bill.getAmount(), bill.getAgentUnitPrice()));

    pf.setRateFromDate(bill.getFinishDate());
    pf.setType(0);
    billDao.saveOrUpdate(pf);
    logger.info("供应厂分配财务信息保存成功【" + pf.getProvider().getName() + "】");

    // 保存单据
    billDao.saveOrUpdate(bill);
    // 保存日志
    BillLog log = Util.getBaseLog(BillLog.class, "已发料 -> 已送达");
    log.setBill(bill);
    log.setRemark(bill.getFinishRemark());

    // 发邮件
    sendEmail(bill, "单据发料成功");

    this.saveOrUpdateEntity(log);
    return bill;
  }