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

  async findSignedContractId(params) {
    // idno, begin, end
    let sql = [];
    sql.push("SELECT t1.id FROM c_dkcontract t1");
    sql.push("INNER JOIN `p_user_eaccount` t2 ON t1.`usereaccount_id` = t2.`id`");
    sql.push("WHERE t2.`personsSign` = :idno AND t1.eflowstatus = '2'");
    if (params.ecid) {
      sql.push("AND t1.`dktemplate_id` = :ecid");
    }
    if (params.today) {
      sql.push("AND t1.`end_at` >= :today");
    }

    let list = await this.customQuery(sql.join(" "), params);
    if (!list || list.length == 0) {
      return 0;
    }
    return list[0].id || 0;
  }
}
module.exports=DKcontractDao;
