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

  async byImagepath(imagepath) {
    if(!imagepath) {
      return [];
    }
    let sql = "SELECT * FROM t_company_tax_item WHERE imagepath = :imagepath";
    return await this.customQuery(sql, {imagepath: imagepath});
  }

  async delByTaxOcrId(taxOcrId) {
    if(!taxOcrId) {
      return;
    }
    let sql = "DELETE FROM t_company_tax_item WHERE taxOcrId = :taxOcrId";
    await this.customUpdate(sql, {taxOcrId: taxOcrId});
  }

  async countByCondition(condition) {
    var sql = [];
    sql.push("SELECT COUNT(1) AS num FROM `t_company_tax_item` 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_item`");
    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");
    }

    if (params.idName) {
      params.idNameLike = "%" + params.idName + "%"
      sql.push("AND idName LIKE :idNameLike");
    }

    if (params.idNo) {
      sql.push("AND idNo = :idNo");
    }
  }
}
module.exports=TCompanytaxitemDao;
