package com.nzwz.api;

import com.nzwz.utils.JsonUtil;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lnori
 */
public class KingDeeK3CloudApi extends KingDeeApiClient {

    public KingDeeK3CloudApi(String serverUrl) {
        super(serverUrl);
    }

    public String excuteOperation(String formid, String opNumber, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation", new Object[]{formid, opNumber, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String save(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String batchSave(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String audit(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String delete(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String unAudit(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String submit(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public String view(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }

    public List<List<Object>> executeBillQuery(String data) throws Exception {
        List execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", new Object[]{data}, ArrayList.class);
        if (CollectionUtils.isEmpty(execute)) {
            execute = new ArrayList<>();
        }
        return execute;
    }

    public String draft(String formid, String data) throws Exception {
        Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Draft", new Object[]{formid, data}, Object.class);
        return JsonUtil.toString(execute);
    }


}
