package com.seeyon.apps.src_flowIntegration.service;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.src_flowIntegration.config.FlowIntegrationConfigProvider;
import com.seeyon.apps.src_flowIntegration.constants.FlowIntegrationConstants;
import com.seeyon.utils.http.OaResp;
import com.seeyon.utils.http.OaRestClient;
import org.springframework.beans.factory.annotation.Autowired;

public class OaFlowCreateService {

    @Autowired
    private FlowIntegrationConfigProvider configProvider;

    public Object flowStart(String tirdFlowId,JSONObject flowParam,String token) throws Exception {
        OaRestClient client = new OaRestClient(configProvider.getBizConfigByKey(FlowIntegrationConstants.OA_HOST),
                configProvider.getBizConfigByKey(FlowIntegrationConstants.restName),
                configProvider.getBizConfigByKey(FlowIntegrationConstants.restPwd),false);
        String url = "/bpm/process/start";

        OaResp oaResp = client.sendPost(tirdFlowId, url, flowParam,token);
        if(oaResp.getCode() != 0) {
            throw new Exception(tirdFlowId + "流程发起失败:" + oaResp.getMessage());
    }
        return oaResp.getData();
    }

}
