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

  /**
   * 条件查询
   * @param {} params 
   */
  async findUserByOrgId(params){
    let sql = [];
    sql.push(`SELECT c.ucid,c.ucname,c.uctype,c.saas_id,c.isEnabled,c.created_at,c.updated_at,c.deleted_at
      FROM uc_org a INNER JOIN uc_user_org b ON a.id = b.org_id INNER JOIN uc_user c ON b.user_id = c.id
      WHERE 1=1 and ( c.deleted_at is null or c.deleted_at > NOW() ) `);
    if(params.id){
      sql.push("AND a.id = :id");
    }
    return await this.customQuery(sql.join(" "), params);
  }

  async all() {
    return this.customQuery("SELECT * FROM uc_org WHERE deleted_at IS NULL");
  }
  

}
module.exports = OrgDao;