const system = require("../../../system");
const Dao = require("../../dao.base");

class CfollowlogDao extends Dao {
  constructor() {
    super(Dao.getModelName(CfollowlogDao));
  }

  /**
   * fn:根据线索ID查询记录
   * @param params
   * @returns {Promise<void>}
   */
  async followlogsByClueIds(params){
    var sql = [];
    sql.push("SELECT * FROM `c_follow_log` WHERE 1=1");
    this.setcfollowlogCount(sql,params);
    sql.push("ORDER BY created_at DESC");
    let list = await this.customQuery(sql.join(" "), params);
    let map = {};
    for (let item of list) {
      if(!map[item.clue_id]){
        map[item.clue_id] = [];
      }
      map[item.clue_id].push(item);
    }
    return map;
  }

  setcfollowlogCount(sql,params){
    if(params.clueIds && params.clueIds.length>0){
      sql.push(`and clue_id in (:clueIds)`);
    }
    if(params.clue_id){
      sql.push(`and clue_id =:clue_id`);
    }
  }

  /**
   * fn:根据线索ID查询所有的跟踪日志
   * @param clue_id
   * @returns {Promise<{}>}
   */
  async followlogsByClueId(clue_id){
    var sql = [];
    sql.push("SELECT * FROM `c_follow_log` WHERE 1=1");
    this.setcfollowlogCount(sql,params);
    sql.push("ORDER BY created_at DESC");
    return await this.customQuery(sql.join(" "), params);
  }

}

module.exports = CfollowlogDao;
