package com.engine.htsc.common.service.impl;

import com.engine.core.impl.Service;
import com.engine.htsc.common.service.CoWorkflowService;
import com.engine.htsc.payment.enums.Sequences;
import com.engine.htsc.payment.util.CoWfUtil;
import com.engine.htsc.payment.util.PayUtil;
import org.apache.commons.lang3.StringUtils;

public class CoWorkflowServiceImpl extends Service implements CoWorkflowService {

  @Override
  public String createRequestMark(String workflowId) throws Exception {
    if (StringUtils.isBlank(workflowId)) {
      throw new Exception("参数workflowId必填");
    }
    CoWfUtil coWfUtil = new CoWfUtil();
    return coWfUtil.createFundBusinessPayRequestMark(workflowId);
  }

  @Override
  public String createRequestMarkByType(String wfid, String type) throws Exception {
    String unNumber = PayUtil.getUnNumberByWorkFlowId(Integer.parseInt(wfid));
    if (StringUtils.isBlank(unNumber)) {
      throw new Exception("生成流程编号失败,错误unNumber");
    }
    if ("0".equals(type)) {
      return CoWfUtil.getRequestMarkByUnNumber(unNumber, Sequences.NET_REI_WORKFLOW_SEQ_ZB);
    } else if ("1".equals(type)) {
      return CoWfUtil.getRequestMarkByUnNumber(unNumber, Sequences.NET_REI_WORKFLOW_SEQ_FZ);
    } else if ("2".equals(type)) {
      return CoWfUtil.getRequestMarkByUnNumber(unNumber, Sequences.NET_REI_WORKFLOW_SEQ_ZGS);
    } else {
      throw new Exception("生成流程编号失败,错误type");
    }
  }
}
