public List<BizMiddleManHoldLoan> queryByStatusSet(
      Integer origLoanId, EnumSet<MiddleManHoldLoanStatus> statusSet) {
    StringBuffer sql = new StringBuffer();
    sql.append(" SELECT                      ");
    sql.append(" 	id,                      ");
    sql.append(" 	middle_man_id,           ");
    sql.append(" 	original_loan_id,        ");
    sql.append(" 	init_hold_loan_rate,     ");
    sql.append(" 	hold_loan_rate,          ");
    sql.append(" 	create_datetime,         ");
    sql.append(" 	loan_transfer_apply_id,  ");
    sql.append(" 	last_update_datetime,    ");
    sql.append(" 	hold_status,             ");
    sql.append(" 	version                  ");
    sql.append(" FROM                        ");
    sql.append(" 	biz_middle_man_hold_loan ");
    sql.append(" WHERE                       ");
    sql.append(" 	original_loan_id = ?     ");

    List<String> statusNames = new ArrayList<String>();
    for (MiddleManHoldLoanStatus status : statusSet) {
      statusNames.add("hold_status = '" + status.name() + "'");
    }
    sql.append("and (");
    sql.append(StringUtils.join(statusNames, " or "));
    sql.append(")");

    return this.jdbcTemplate.query(
        sql.toString(), new Object[] {origLoanId}, new BizMiddleManHoldLoanRowMapper());
  }
  public List<BizMiddleManHoldLoan> queryByStatus(int origLoanId, MiddleManHoldLoanStatus status) {
    StringBuffer sql = new StringBuffer();
    sql.append(" SELECT                      ");
    sql.append(" 	id,                      ");
    sql.append(" 	middle_man_id,           ");
    sql.append(" 	original_loan_id,        ");
    sql.append(" 	init_hold_loan_rate,     ");
    sql.append(" 	hold_loan_rate,          ");
    sql.append(" 	create_datetime,         ");
    sql.append(" 	loan_transfer_apply_id,  ");
    sql.append(" 	last_update_datetime,    ");
    sql.append(" 	hold_status,             ");
    sql.append(" 	version                  ");
    sql.append(" FROM                        ");
    sql.append(" 	biz_middle_man_hold_loan ");
    sql.append(" WHERE                       ");
    sql.append(" 	original_loan_id = ?     ");
    sql.append(" 	AND hold_status = ?      ");

    List<Object> params = new ArrayList<Object>();
    params.add(origLoanId);
    params.add(status.name());

    return this.jdbcTemplate.query(
        sql.toString(), params.toArray(), new BizMiddleManHoldLoanRowMapper());
  }
  /**
   * 更新持有记录的剩余百分比和状态
   *
   * @param holdLoanId
   * @param version
   * @param middleManSurplusHoldRate
   * @param status
   */
  public void update(
      Integer holdLoanId,
      int version,
      BigDecimal middleManSurplusHoldRate,
      MiddleManHoldLoanStatus status) {
    StringBuffer sql = new StringBuffer();
    sql.append(" UPDATE biz_middle_man_hold_loan ");
    sql.append(" 	SET hold_loan_rate = ?,      ");
    sql.append(" 	    hold_status = ?,         ");
    sql.append(" 	    last_update_datetime = ?, ");
    sql.append(" 	    version = version + 1    ");
    sql.append(" WHERE                           ");
    sql.append(" 	id = ?                       ");
    sql.append(" and version = ?                 ");

    List<Object> params = new ArrayList<Object>();
    params.add(CalculateUtil.setScaleForBizRate(middleManSurplusHoldRate));
    params.add(status.name());
    params.add(new Timestamp(new Date().getTime()));
    params.add(holdLoanId);
    params.add(version);

    int count = this.jdbcTemplate.update(sql.toString(), params.toArray());
    Assert.isTrue(count == 1, "update middleman hold loan error.");
  }
  /**
   * 获取居间人某种持有状态的持有记录ID集合
   *
   * @param middleManId
   * @param status
   * @return
   */
  public List<Integer> queryHoldLoanIds(Integer middleManId, MiddleManHoldLoanStatus status) {
    StringBuffer sql = new StringBuffer();
    sql.append(" SELECT                      ");
    sql.append(" 	id                       ");
    sql.append(" FROM                        ");
    sql.append(" 	biz_middle_man_hold_loan ");
    sql.append(" WHERE                       ");
    sql.append(" 	middle_man_id = ?        ");
    sql.append(" AND hold_status = ?         ");

    List<Object> params = new ArrayList<Object>();
    params.add(middleManId);
    params.add(status.name());

    return this.jdbcTemplate.queryForList(sql.toString(), Integer.class, params.toArray());
  }