/**
   * 申请审核额度调整
   *
   * @param userId
   * @return
   */
  public int applayApproveAmountAdjustment(String userId) {
    // 判断自己是否有审核任务
    int i = 0;
    if (amountAdjustmentComdao.getWaitProcessAmountAdjustmentCountByUserId(userId) != 0) {
      return 0;
    }
    // 是否有审核的进件
    List<AmountAdjustmentProcessForm> adjustmentProcessForms =
        amountAdjustmentDao.findWaitProcessAmountAdjustmentAll();
    for (AmountAdjustmentProcessForm adjustmentProcessForm : adjustmentProcessForms) {
      List<NodeAudit> listNode =
          nodeAuditService.findByNodeAuditByUserId(
              NodeAuditTypeEnum.ProductAmountAdjust.toString(),
              userId,
              adjustmentProcessForm.getProductId());
      boolean flag = false;
      for (NodeAudit nodeAudit : listNode) {
        if (adjustmentProcessForm.getProductId().equals(nodeAudit.getProductId())
            && adjustmentProcessForm.getNextNodeId().equals(nodeAudit.getId())) {
          adjustmentProcessForm.setDelayAuditUser(userId);
          i = amountAdjustmentDao.updateWaitProcessAmountAdjustment(adjustmentProcessForm);

          AmountAdjustment adjustment =
              commonDao.findObjectById(
                  AmountAdjustment.class, adjustmentProcessForm.getAmountAdjustmentId());
          adjustment.setModifiedBy(userId);
          adjustment.setModifiedTime(new Date());
          commonDao.updateObject(adjustment);
          flag = true;
          break;
        }
      }
      if (flag) {
        break;
      }
    }
    return i;
  }
  /**
   * 审核额度调整
   *
   * @param amountAdjustmentForm
   * @param request
   */
  public void approveAmountAdjustment(
      AmountAdjustmentForm amountAdjustmentForm, HttpServletRequest request) {
    User user = (User) Beans.get(LoginManager.class).getLoggedInUser(request);
    String approveStatus = amountAdjustmentForm.getApproveStatus();
    AmountAdjustment amountAdjustment =
        commonDao.findObjectById(AmountAdjustment.class, amountAdjustmentForm.getId());

    AmountAdjustmentProcess amountAdjustmentProcess =
        amountAdjustmentComdao.findAmountAdjustmentProcess(
            amountAdjustmentForm.getId(), amountAdjustmentForm.getSerialNumber());

    if (StringUtils.isNotEmpty(approveStatus)
        && approveStatus.equals(ApproveOperationTypeEnum.RETURNAPPROVE.toString())) {
      String fallbackReason = request.getParameter("reason");
      amountAdjustmentProcess.setFallbackReason(fallbackReason);
    } else if (StringUtils.isNotEmpty(approveStatus)
        && approveStatus.equals(ApproveOperationTypeEnum.REJECTAPPROVE.toString())) {
      amountAdjustmentProcess.setRefusalReason(amountAdjustmentForm.getReason());
    }
    String examineResutl =
        processService.examine(
            amountAdjustmentForm.getSerialNumber(),
            user.getId(),
            approveStatus,
            amountAdjustmentForm.getApprovalLimit());

    // 更新单据状态
    if (examineResutl.equals(ApproveOperationTypeEnum.REJECTAPPROVE.toString())
        || examineResutl.equals(ApproveOperationTypeEnum.RETURNAPPROVE.toString())
        || examineResutl.equals(ApproveOperationTypeEnum.NORMALEND.toString())) {
      if (examineResutl.equals(ApproveOperationTypeEnum.REJECTAPPROVE.toString())) {
        amountAdjustment.setApproval(AmountAdjustmentApproveStatusEnum.Refuse.toString());
      }
      if (examineResutl.equals(ApproveOperationTypeEnum.RETURNAPPROVE.toString())) {
        amountAdjustment.setApproval(AmountAdjustmentApproveStatusEnum.Back.toString());
      }
      if (examineResutl.equals(ApproveOperationTypeEnum.NORMALEND.toString())) {
        amountAdjustment.setApproval(AmountAdjustmentApproveStatusEnum.Success.toString());
      }
      amountAdjustment.setId(amountAdjustmentForm.getId());
      amountAdjustment.setModifiedBy(user.getId());
      amountAdjustment.setModifiedTime(new Date());
      commonDao.updateObject(amountAdjustment);

      amountAdjustmentProcess.setNextNodeId(null);
    } else {
      amountAdjustment.setApproval(AmountAdjustmentApproveStatusEnum.Audit.toString());
      amountAdjustment.setId(amountAdjustmentForm.getId());
      amountAdjustment.setModifiedBy(user.getId());
      amountAdjustment.setModifiedTime(new Date());
      commonDao.updateObject(amountAdjustment);

      amountAdjustmentProcess.setNextNodeId(examineResutl);
    }

    amountAdjustmentProcess.setProcessOpStatus(approveStatus);
    amountAdjustmentProcess.setExamineAmount(amountAdjustmentForm.getApprovalLimit());
    amountAdjustmentProcess.setAuditUser(user.getId());
    amountAdjustmentProcess.setAuditTime(new Date());

    amountAdjustmentDao.updateAmountAdjustmentProcess(amountAdjustmentProcess);
  }