/**
   * 申请审核额度调整
   *
   * @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 appId
   * @param adjustmentAccount
   * @param adjustmentType
   * @param user
   * @throws SQLException
   */
  public void insertAmountAdjustment(
      String appId, String adjustmentAccount, String adjustmentType, User user) {
    // 进件信息
    CustomerApplicationInfo applicationInfo =
        commonDao.findObjectById(CustomerApplicationInfo.class, appId);

    AmountAdjustment amountAdjustment = new AmountAdjustment();
    amountAdjustment.setCustomerId(applicationInfo.getCustomerId());
    amountAdjustment.setProductId(applicationInfo.getProductId());
    amountAdjustment.setApproval(AmountAdjustmentApproveStatusEnum.Audit.name());
    amountAdjustment.setActualAmount(applicationInfo.getActualQuote());
    amountAdjustment.setApprovalLimit(adjustmentAccount);
    amountAdjustment.setOriginalAmount(applicationInfo.getApplyQuota());
    amountAdjustment.setAdjustAmountTime(new Date());
    amountAdjustment.setCreatedBy(user.getId());
    amountAdjustment.setCreatedTime(new Date());
    amountAdjustment.setModifiedBy(user.getId());
    amountAdjustment.setModifiedTime(new Date());
    amountAdjustment.setAdjustmentType(adjustmentType);
    commonDao.insertObject(amountAdjustment);

    // 添加额度调整申请流程
    WfProcessInfo wf = new WfProcessInfo();
    wf.setProcessType(WfProcessInfoType.amount_adjustment_type); // TODO
    wf.setVersion("1");
    commonDao.insertObject(wf);
    List<NodeAudit> list =
        nodeAuditService.findByNodeTypeAndProductId(
            NodeAuditTypeEnum.ProductAmountAdjust.name(), applicationInfo.getProductId());
    boolean startBool = false;
    boolean endBool = false;
    // 节点id和WfStatusInfo id的映射
    Map<String, String> nodeWfStatusMap = new HashMap<String, String>();
    for (NodeAudit nodeAudit : list) {
      if (nodeAudit.getIsstart().equals(YesNoEnum.YES.name())) {
        startBool = true;
      }

      if (startBool && !endBool) {
        WfStatusInfo wfStatusInfo = new WfStatusInfo();
        wfStatusInfo.setIsStart(nodeAudit.getIsstart().equals(YesNoEnum.YES.name()) ? "1" : "0");
        wfStatusInfo.setIsClosed(nodeAudit.getIsend().equals(YesNoEnum.YES.name()) ? "1" : "0");
        wfStatusInfo.setRelationedProcess(wf.getId());
        wfStatusInfo.setStatusName(nodeAudit.getNodeName());
        wfStatusInfo.setStatusCode(nodeAudit.getId());
        commonDao.insertObject(wfStatusInfo);

        nodeWfStatusMap.put(nodeAudit.getId(), wfStatusInfo.getId());

        if (nodeAudit.getIsstart().equals(YesNoEnum.YES.name())) {
          // 添加初始审核
          AmountAdjustmentProcess amountAdjustmentProcess = new AmountAdjustmentProcess();
          String serialNumber = processService.start(wf.getId());
          amountAdjustmentProcess.setSerialNumber(serialNumber);
          amountAdjustmentProcess.setNextNodeId(nodeAudit.getId());
          amountAdjustmentProcess.setAmountAdjustmentId(amountAdjustment.getId());
          commonDao.insertObject(amountAdjustmentProcess);

          AmountAdjustment adjustment =
              commonDao.findObjectById(AmountAdjustment.class, amountAdjustment.getId());
          adjustment.setSerialNumber(serialNumber);
          commonDao.updateObject(adjustment);
        }
      }

      if (nodeAudit.getIsend().equals(YesNoEnum.YES.name())) {
        endBool = true;
      }
    }

    // 节点关系
    List<NodeControl> nodeControls =
        nodeAuditService.findNodeControlByNodeTypeAndProductId(
            NodeAuditTypeEnum.ProductAmountAdjust.name(), applicationInfo.getProductId());
    for (NodeControl control : nodeControls) {
      WfStatusResult wfStatusResult = new WfStatusResult();
      wfStatusResult.setCurrentStatus(nodeWfStatusMap.get(control.getCurrentNode()));
      wfStatusResult.setNextStatus(nodeWfStatusMap.get(control.getNextNode()));
      wfStatusResult.setExamineResult(control.getCurrentStatus());
      commonDao.insertObject(wfStatusResult);
    }
  }