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

  async countByCondition(condition) {
    var sql = [];
    sql.push("SELECT COUNT(1) AS num FROM `t_company_tax` WHERE 1 = 1");
    this.setCondition(sql, condition);

    let rs = await this.customQuery(sql.join(" "), condition);
    if (!rs || rs.length == 0) {
      return 0;
    }
    return rs[0].num || 0;
  }

  async pageByCondition(condition) {
    var sql = [];
    sql.push("SELECT");
    sql.push("* ");
    sql.push("FROM `t_company_tax`");
    sql.push("WHERE 1 = 1");
    this.setCondition(sql, condition);

    sql.push("GROUP BY id DESC");
    sql.push("LIMIT :startRow, :pageSize");
    return await this.customQuery(sql.join(" "), condition);
  }

  setCondition(sql, params) {
    if (params.month) {
      sql.push("AND month = :month");
    }
    if (params.companyId) {
      sql.push("AND companyId = :companyId");
    }
  }

  async findMapByIds(ids) {
    var result = {};
    var sql = "SELECT * FROM `t_company_tax` WHERE id IN (:ids)";
    var list = await this.customQuery(sql, {
      ids: ids
    });
    if (!list || list.length == 0) {
      return result;
    }
    for (var item of list) {
      result[item.id] = item;
    }
    return result;
  }

}
module.exports = TCompanytaxDao;
