var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
    constructor() {
        super();
        this.iborderbaseSve = system.getObject("service.order.iborderbaseSve");
        this.ibdeliverbaseSve = system.getObject("service.order.ibdeliverbaseSve");

        this.iborderSve = system.getObject("service.order.iborderSve");
        this.iborderdeliverSve = system.getObject("service.order.iborderdeliverSve");

        this.businessmenSve = system.getObject("service.business.businessmenSve");
        this.businessmencontractSve = system.getObject("service.business.businessmencontractSve");

        //-----------------------------------------------------------------------------------------

        this.oorderSve = system.getObject("service.order.oorderSve");
        this.oorderdeliverSve = system.getObject("service.order.oorderdeliverSve");
        this.oorderstatusSve = system.getObject("service.order.oorderstatusSve");
        this.oprocessSve = system.getObject("service.product.oprocessSve");
        this.oproductSve = system.getObject("service.product.oproductSve");
        this.obusinessmenSve = system.getObject("service.order.obusinessmenSve");

        this.saasorderSve = system.getObject("service.saas.saasorderSve");
        this.saasorderbusinessmenSve = system.getObject("service.saas.saasorderbusinessmenSve");

    }
    /**
     * 接口跳转
     * action_process  执行的流程
     * action_type     执行的类型
     * action_body     执行的参数
     */
    async springboard(pobj, qobj, req) {
        var result;
        if (!pobj.action_process) {
            return system.getResult(null, "action_process参数不能为空");
        }
        if (!pobj.action_type) {
            return system.getResult(null, "action_type参数不能为空");
        }
        console.log(pobj.action_process, pobj.action_type, pobj.action_body, "---------------- this is order micro sve --------------------");
        try {
            result = await this.handleRequest(pobj.action_process, pobj.action_type, pobj.action_body);
        } catch (error) {
            console.log(error);
        }
        return result;
    }

    async handleRequest(action_process, action_type, action_body) {
        var opResult = null;
        try{
            switch (action_type) {
                case "orderInfo":   // 查订单信息
                    opResult = await this.oorderSve.info(action_body);
                    break;
                case "orderInfoAll":   // 查订单信息
                    opResult = await this.oorderSve.infoAll(action_body);
                    break;
                case "orderAndDeliver":   // 查订单信息
                    opResult = await this.oorderSve.orderAndDeliver(action_body);
                    break;
                case "orders":           //订单管理（平台）
                    opResult = await this.oorderSve.orders(action_body);
                    break;

                case "orderDelivers":    //订单管理（交付商）
                    opResult = await this.oorderdeliverSve.orderDelivers(action_body);
                    break;

                case "handleStatus":     //进度处理
                    opResult = await this.oorderstatusSve.handleStatus(action_body);
                    break;

                case "addSourceOrder":    // 创建来源订单
                    opResult = await this.oorderSve.addSourceOrder(action_body);
                    break;

                case "resetOrderProcess":    // 重置订单流程
                    opResult = await this.oorderSve.resetOrderProcess(action_body);
                    break;
                case "aliOrderPageAll":    // 阿里全部订单
                    opResult = await this.oorderSve.aliOrderPageAll(action_body);
                    break;
                case "aliOrderPage":    // 阿里我的业务订单
                    opResult = await this.oorderSve.aliOrderPage(action_body);
                    break;
                case "productDics":    // 阿里查询产品字典
                    opResult = await this.oproductSve.productDics(action_body);
                    break;

                case "allProcess":    // 查询业务进度
                    opResult = await this.oprocessSve.allNames(action_body);
                    break;
                // 个体户
                case "queryObusinessmen":  //查询个体工商户信息
                    opResult = await this.obusinessmenSve.queryObusinessmen(action_body);
                    break;
                case "businessmenByOrderId":  //查询个体工商户信息
                    opResult = await this.obusinessmenSve.businessmenByOrderId(action_body);
                    break;
                case "queryObusinessmenInfo":  //查询个体工商户信息
                    opResult = await this.obusinessmenSve.queryObusinessmenInfo(action_body);
                    break;
                case "queryObusinessmenByCreditCode":  //查询个体工商户信息
                    opResult = await this.obusinessmenSve.queryObusinessmenByCreditCode(action_body);
                    break;
                case "updateOBusinessmenProinvce":  //跟新个体工商户信息
                    opResult = await this.obusinessmenSve.updateOBusinessmenProinvce(action_body);
                    break;
                case "businessmenPage":
                    opResult = await this.obusinessmenSve.businessmenPage(action_body);
                    break;
                case "createAccount":
                    opResult = await this.obusinessmenSve.createAccount(action_body);
                    break;
                case "signing":
                    opResult = await this.obusinessmenSve.signing(action_body);
                    break;
                case "signNames":
                    opResult = await this.obusinessmenSve.signNames(action_body);
                    break;
                case "businessmenMapByCreditCodes":
                    opResult = await this.obusinessmenSve.mapByCreditCodes(action_body);
                    break;
                // 统计数据（平台）
                case "statTransData":     //数据简报  （本月交易数据）
                    opResult = await this.oorderSve.statTransData(action_body);
                    break;
                case "needToBeDealtWith":  //待办事项
                    opResult = await this.oorderSve.needToBeDealtWith(action_body);
                    break;
                case "statDeliverData":    //交付商统计
                    opResult = await this.oorderdeliverSve.statDeliverData(action_body);
                    break;
                    
                // 统计数据（交付商）
                case "deliverStatTransData":    //交付商统计
                    opResult = await this.oorderdeliverSve.deliverStatTransData(action_body);
                    break;
                case "businessManagement":       //业务办理
                    opResult = await this.oorderdeliverSve.businessManagement(action_body);
                    break;

                //*****************************个体宝saas*************************************** */

                case "saasOrderMicroAdd":       // 小程序下单
                    opResult = await this.saasorderSve.microAdd(action_body);
                    break;
                case "saasOrderUpdate":       // 订单信息
                    opResult = await this.saasorderSve.updateOrder(action_body);
                    break;
                case "saasOrderSveDeliver":       // 订单信息
                    opResult = await this.saasorderSve.sveDeliver(action_body);
                    break;
                case "saasOrderBusinessmen":       // 提送交付信息(建账和个体户完成后推送接口)
                    opResult = await this.saasorderSve.saveSaasOrderBusinessmen(action_body);
                    break;
                case "saasOrderInfo":       // 订单信息
                    opResult = await this.saasorderSve.info(action_body);
                    break;
                case "saasOrderPlatformOrderInfo":       // 订单信息
                    opResult = await this.saasorderSve.platformOrderInfo(action_body);
                    break;
                case "saasOrderMerchantOrderInfo":       // 订单信息
                    opResult = await this.saasorderSve.merchantOrderInfo(action_body);
                    break;
                case "saasOrderPage":       // 订单信息
                    opResult = await this.saasorderSve.pageByCondition(action_body);
                    break;
                case "saasOrderMapByIds":       // 订单信息
                    opResult = await this.saasorderSve.mapByIds(action_body);
                    break;
                case "saasOrderBulkAudit":       // 订单信息
                    opResult = await this.saasorderSve.bulkAudit(action_body);
                    break;
                case "saasOrderBulkDeliver":       // 订单信息
                    opResult = await this.saasorderSve.bulkDeliver(action_body);
                    break;
                case "saasOrderBulkOfflinePay":       // 订单信息
                    opResult = await this.saasorderSve.bulkOfflinePay(action_body);
                    break;
                case "saasOrderDeliverBusinessmenPage":       // 订单交付的个体户信息
                    opResult = await this.saasorderSve.businessmenPage(action_body);
                    break;
                case "saasBusinessmenMapByCreditCodes":       // 订单信息
                    opResult = await this.saasorderSve.mapByCreditCodes(action_body);
                    break;
                case "itemByIds":       // 订单信息
                    opResult = await this.saasorderSve.itemByIds(action_body);
                    break;
                case "updateItemInvoice":
                    opResult = await this.saasorderSve.updateInvoice(action_body);
                    break;
                case "saasorderbusinessmenPage":       // 订单信息
                    opResult = await this.saasorderbusinessmenSve.saasorderbusinessmenPage(action_body);
                    break;
                // case "queryBusinessmenByMerchantId":   //根据商户ID，SAAS_ID查询所有的个体户
                //     opResult = await this.saasorderbusinessmenSve.queryBusinessmenByMerchantId(action_body);
                //     break;
                case "assorderBusinessmenInfo":       // 订单信息
                    opResult = await this.saasorderbusinessmenSve.assorderBusinessmenInfo(action_body);
                    break;
                case "cancelInvoiceByDataIds":       // 订单信息
                    opResult = await this.saasorderSve.cancelInvoiceByDataIds(action_body);
                    break;
                default:
                    opResult = system.getResult(null, "action_type参数错误");
                    break;
            }
            return opResult;
        } catch (e) {
            console.log(e);
            return system.getResult(null, "order服务异常");
        }
    }
    exam() {
        return `<pre><pre/>`;
    }
    classDesc() {
        return {
            groupName: "op",
            groupDesc: "元数据服务包",
            name: "ActionAPI",
            desc: "此类是对外提供接口服务",
            exam: "",
        };
    }
    methodDescs() {
        return [{
            methodDesc: `<pre><pre/>`,
            methodName: "springboard",
            paramdescs: [{
                    paramDesc: "请求的行为，传递如：sjb",
                    paramName: "action_process",
                    paramType: "string",
                    defaultValue: null,
                },
                {
                    paramDesc: "业务操作类型，详情见方法中的描述",
                    paramName: "action_type",
                    paramType: "string",
                    defaultValue: null,
                },
                {
                    paramDesc: "业务操作类型的参数，action_body必须传递的参数有，times_tamp（时间戳，类型int）、sign(签名,类型string)，其余的为业务需要的参数",
                    paramName: "action_body",
                    paramType: "json",
                    defaultValue: null,
                }
            ],
            rtnTypeDesc: `<pre><pre/>`,
            rtnType: `<pre><pre/>`
        }];
    }
}
module.exports = ActionAPI;