const ServiceBase = require("../sve.base");

class EtemplatebusiService extends ServiceBase {
    constructor() {
        super(ServiceBase.getDaoName(EtemplatebusiService));
    }

    async getlist(id) {
        var sql = "SELECT * FROM c_etemplate_busi WHERE template_id = " + id;
        var page = await this.customQuery(sql);
        return page;
    }
    async busiIdsByTemplateId(template_id) {
        var sql = "SELECT busi_id FROM c_etemplate_busi WHERE template_id = :template_id";
        var list = await this.customQuery(sql, {template_id: template_id});
        let rs = [];
        if (!list || list.length == 0) {
            return rs;
        }
        for (let item of list) {
            rs.push(item.busi_id);
        }
        return rs;
    }

    async getinfo(qobj) {
        var sql = "SELECT * FROM c_etemplate_busi WHERE template_id = " + qobj.template_id + " AND busi_id = " + qobj.company_id;
        var page = await this.customQuery(sql);
        return page;
    }

    async deleteTetId(qobj) {
        let sql = "DELETE FROM c_etemplate_busi WHERE id = " + qobj.id;
        await this.customExecAddOrPutSql(sql);
        return 1;
    }

    async suggest(name, ownerIds) {
        return await this.dao.suggest(name, ownerIds);
    }

    async saveto(etebusi) {
        return await this.create(etebusi);

    }
}

module.exports = EtemplatebusiService;