from db.mod_db import DataBase
from common import sql_utils
class NameDao:
    def __init__(self, db=None):
        if db is None:
            self.dataBase = DataBase(dbname="igirl")
        else:
            self.dataBase = db


    def select_null_dao(self,size):
        return self.dataBase.fetch_all(
            'select * from check_name_treasure_name  where name_type is null and state = 1 order by rand() limit %s' % (size))

    def select_name_dao(self, ncl_one_list, name_size, include_word, word_type,):
        if word_type == "首位":
            include_word_type = include_word + "%"
        if word_type == "末位":
            include_word_type = "%" + include_word
        if word_type == "中位" or  word_type == "随机" or word_type == "" :
            include_word_type = "%" + include_word + "%"

        print('select * from tm_treasure_name  where name_size = %s  and ncl_one in (%s) and whether_register = 1 and tm_name like "%s" order by rand() limit 120 ' % (
             name_size,sql_utils.to_sql_in(ncl_one_list), include_word_type))
        return self.dataBase.fetch_all(
            'select * from tm_treasure_name  where name_size = %s  and ncl_one in (%s) and whether_register = 1 and tm_name like "%s" order by rand() limit 120 ' % (
             name_size,sql_utils.to_sql_in(ncl_one_list), include_word_type))
