var system = require("../../system")
var settings = require("../../../config/settings");
const CtlBase = require("../ctl.base");
const uuidv4 = require('uuid/v4');
const moment = require("moment");
class EcompanybusiCtl extends CtlBase {
    constructor() {
        super(CtlBase.getServiceName(EcompanybusiCtl));

        this.regionareaSve = system.getObject("service.regionareaSve");
        this.userSve = system.getObject("service.userSve");
        this.epartnerSve = system.getObject("service.epartnerSve");
        this.ejobSve = system.getObject("service.ejobSve")

        this.ecompanyeventSve = system.getObject("service.ecompanyeventSve");
        this.eintentionSve = system.getObject("service.eintentionSve");
        this.etemplateSve = system.getObject("service.etemplateSve");

        this.ecompanybpoSve = system.getObject("service.ecompanybpoSve");

        this.esettleSve = system.getObject("service.esettleSve");

    }

    async mysave(queryobj, qobj, req) {
        try {
            var old = null;
            if (qobj.id) {
                old = await this.service.findById(qobj.id);
            }
            var rtn = null;
            if (old) { //修改
                rtn = await this.service.update(qobj);
            } else { //新增
                rtn = await this.service.create(qobj);
            }

            // 调用e签宝接口生成accountid
            return system.getResult2(rtn, null);
        } catch (e) {
            console.log(e);
            return {
                code: -1
            }
        }
    }

    async allList(queryobj, qobj, req) {
        var params = qobj.search;
        try {
            var page = await this.service.allList(params);
            return system.getResult2(page);
        } catch (e) {
            console.log(e);
            return system.getErrResult2("您的网络不稳, 请稍后重试");
        }
    }

    async info(queryobj, qobj, req) {
        var id = qobj.id;
        try {
            var info = await this.service.findById(id);
            return system.getResult2(info);
        } catch (e) {
            console.log(e);
            return system.getErrResult2("您的网络不稳, 请稍后重试");
        }
    }


}
module.exports = EcompanybusiCtl;
