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

  async findListByPid(pid) {
    let sql = "SELECT * FROM o_product WHERE pid = :pid ORDER BY sort ASC";
    return await this.customQuery(sql, {pid: pid});
  }

  async findMapByPid(pid) {
    let result = {};
    let list = await this.findListByPid(pid);
    if (!list || list.length == 0) {
      return result;
    }

    for (var item of list) {
      result[item.id] = item;
    }
    return item.id;
  }

    /**
   * 条件查询所有符合条件的产品
   * @param {*} params 
   */
  async listByIds(ids){
    if(!ids || ids.length == 0) {
      return [];
    }
    let sql = [];
    sql.push(`SELECT * FROM o_product WHERE id in (:productIdList)`);
    
    return await this.customQuery(sql.join(" "), {productIdList: ids});
  }

  async mapByIds(params) {
    let list = await this.listByIds(params);
    var result = {};
    for(let item of list) {
      result[item.id] = item;
    }
    return result;
  }

}
module.exports = OproductDao;