package weaver.interfaces.htsc.payment;

import com.engine.htsc.payment.enums.BudgetNodeType;
import com.engine.htsc.payment.service.impl.HeadPaymentBudgetCommand;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.general.GCONST;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;

public class PaymentWorkflowInvoke implements Action {
  
  private final Log log = LogFactory.getLog(PaymentWorkflowInvoke.class);
  
  //预算状态
  private String billStatus;
  
  @Override
  public String execute(RequestInfo requestInfo) {
    RequestManager requestManager = requestInfo.getRequestManager();
    try {
      // 主表
      String requestId = requestInfo.getRequestid();
      String src = requestManager.getSrc(); //提交方式
      if ("2".equals(billStatus) && !"reject".equals(src)) {
        log.info("识别当前流程为[" + requestId + "]自动创建,流程状态@" + src);
        return SUCCESS;
      }
      HeadPaymentBudgetCommand headPaymentBudgetCommand = new HeadPaymentBudgetCommand();
      if ("3".equals(billStatus)) {
        //拟稿后提交
        headPaymentBudgetCommand.submit(requestId, BudgetNodeType.SUBMIT.getValue());
      }
      if ("2,3".equals(billStatus)) {
        //会计节点提交
        headPaymentBudgetCommand.reSubmit(requestId);
      }
      if ("2".equals(billStatus)) {
        headPaymentBudgetCommand.reject(requestId);
      }
      return SUCCESS;
    } catch (Exception e) {
      requestManager.setMessagecontent("流程流转异常!请联系管理员" + e);
      requestManager.setMessageid("5000");
      return FAILURE_AND_CONTINUE;
    }
    
  }
  
  public String getBillStatus() {
    return billStatus;
  }
  
  public void setBillStatus(String billStatus) {
    this.billStatus = billStatus;
  }
  
}
