const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasChannelDao extends Dao {
  constructor() {
    super(Dao.getModelName(SaasChannelDao));
  }

  async listByIds(ids, attrs) {
    if (!ids || ids.length == 0) {
      return [];
    }
    attrs = attrs || "*";
    let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE id IN (:ids) `;
    return await this.customQuery(sql, {
      ids: ids
    });
  }

  async mapByIds(ids, attrs) {
    let result = {};
    let list = await this.listByIds(ids, attrs);
    if (!list || list.length == 0) {
      return result;
    }
    for (var item of list) {
      result[item.id] = item;
    }
    return result;
  }

  async findDics(params){
    let sql = [];
    sql.push("select * from saas_channel where 1=1");
    if(params.name){
      params.nameLike = `%${params.name}%`;
      sql.push("and name like :nameLike");
    }
    return await this.customQuery(sql.join(" "), params);
  }
}
module.exports = SaasChannelDao;
