예제 #1
0
 def update_deal_doctor_flag(cls, section_id, status=-1):
     sql = "update {db}.{tbl}  set deal_doctor_flag={status} where `id`={section_id}".format(
         db=cls.db_name,
         tbl=cls.table_name,
         status=status,
         section_id=section_id)
     doctor_conn.execute_sql(sql)
예제 #2
0
 def insert(cls, map_item):
     sql = "insert into {db}.{tbl}(`hospital_index`, `section_p`, section_c, doctor_cnt, link, like_cnt) " \
           "values  ({hospital_index}, '{section_p}', '{section_c}', {doctor_cnt}, '{link}', {like_cnt}) ".format(
             db=cls.db_name,
             tbl=cls.table_name,
             hospital_index=map_item["hospital_index"] if "hospital_index" in map_item else 0,
             section_p=map_item["section_p"] if "section_p" in map_item else 0,
             section_c=map_item["section_c"] if "section_c" in map_item else 0,
             link=map_item["link"] if "link" in map_item else 0,
             like_cnt=map_item["like_cnt"] if "like_cnt" in map_item else 0,
             doctor_cnt=map_item["doctor_cnt"] if "doctor_cnt" in map_item else 0,
     )
     doctor_conn.execute_sql(sql)
예제 #3
0
    def insert(cls, cuid, device_type, device_os, device_model, app_version, channel, open_push, push_token):
        """
        根据id获取用户

        :return:
        """

        sql = "insert into {db}.{tbl}(cuid, device_type, device_os, device_model, app_version, channel, " \
              "open_push, push_token) values ('{cuid}', '{device_type}', '{device_os}', '{device_model}', " \
              "'{app_version}', '{channel}', {open_push}, '{push_token}') " \
              "on duplicate key update device_type='{device_type}', device_os='{device_os}', " \
              "device_model='{device_model}', app_version='{app_version}', push_token='{push_token}', " \
              "channel='{channel}' ".format(db=cls.db_name,
                                            tbl=cls.table_name,
                                            cuid=cuid,
                                            device_type=device_type,
                                            device_os=device_os,
                                            device_model=device_model,
                                            app_version=app_version,
                                            channel=channel,
                                            open_push=open_push,
                                            push_token=push_token,
                                            )

        item = doctor_conn.execute_sql(sql)
        return item
예제 #4
0
 def insert(cls, map_item):
     sql = "insert into {db}.{tbl}(`hospital_index`, `section_p`, section_c, `name`, link, img_url, title, good_at, province, city, area) " \
           "values  ({hospital_index}, '{section_p}', '{section_c}', '{name}', '{link}', '{img_url}', '{title}', '{good_at}', {province}, {city}, {area}) ".format(
             db=cls.db_name,
             tbl=cls.table_name,
             hospital_index=map_item["hospital_index"] if "hospital_index" in map_item else 0,
             section_p=map_item["section_p"] if "section_p" in map_item else 0,
             section_c=map_item["section_c"] if "section_c" in map_item else 0,
             link=map_item["link"] if "link" in map_item else 0,
             name=map_item["name"] if "name" in map_item else 0,
             img_url=map_item["img_url"] if "img_url" in map_item else 0,
             title=map_item["title"] if "title" in map_item else 0,
             good_at=map_item["good_at"] if "good_at" in map_item else 0,
             province=map_item["province"] if "province" in map_item else 0,
             city=map_item["city"] if "city" in map_item else 0,
             area=map_item["area"] if "area" in map_item else 0,
     )
     doctor_conn.execute_sql(sql)
예제 #5
0
 def insert(cls, hospital_item):
     try:
         sql = "insert into {db}.{tbl}(`name`, `index`, img_url, section_cnt, doctor_cnt, comment_cnt, province, city) " \
               "values  ('{name}', {index}, '{img_url}', {section_cnt}, {doctor_cnt}, {comment_cnt}, {province}, " \
               "{city}) ".format(
                 db=cls.db_name,
                 tbl=cls.table_name, name=hospital_item["name"].encode("utf-8"),
                 index=hospital_item["index"] if "index" in hospital_item else 0,
                 section_cnt=hospital_item["section_cnt"] if "section_cnt" in hospital_item else 0,
                 doctor_cnt=hospital_item["doctor_cnt"] if "doctor_cnt" in hospital_item else 0,
                 comment_cnt=hospital_item["comment_cnt"] if "comment_cnt" in hospital_item else 0,
                 province=hospital_item["province"] if "province" in hospital_item else 0,
                 city=hospital_item["city"] if "city" in hospital_item else 0,
                 img_url=hospital_item["img_url"].encode("utf-8")
         )
         doctor_conn.execute_sql(sql)
     except Exception, ex:
         logging.error(ex, exc_info=1)
         return None
예제 #6
0
class HospitalDao(BaseDao):
    db_name = "doctor"
    table_name = "hospital"

    @classmethod
    def insert(cls, hospital_list):
        """
        获取全部分类列表
        :return:
        """

        if len(hospital_list) == 0:
            logging.error("######## nothing to be inserted...")
            logging.error("######## nothing to be inserted...")
            logging.error("######## nothing to be inserted...")
            return

        sql = "insert into {db}.{tbl}(`name`, `number`, grade, category, is_public, is_appoint, address, " \
              "img_url, section_cnt, doctor_cnt, comment_cnt, like_cnt, good_at, csr) values ".format(db=cls.db_name,
                                                                                                      tbl=cls.table_name)

        item = {}
        try:
            for index, item in enumerate(hospital_list):
                sql += " ('{name}', {number}, {grade}, {category}, {is_public}, {is_appoint}, '{address}', " \
                       "'{img_url}', {section_cnt}, {doctor_cnt}, {comment_cnt}, {like_cnt}, '{good_at}', {csr}),". \
                    format(name=item["name"].encode("utf-8"),
                           number=item["number"] if "number" in item else 0,
                           grade=item["grade"] if "grade" in item else 0,
                           category=item["category"] if "category" in item else 0,
                           is_public=item["is_public"] if "is_public" in item else 0,
                           is_appoint=item["is_appoint"] if "is_appoint" in item else 0,
                           address=item["address"].encode("utf-8"),
                           img_url=item["img_url"].encode("utf-8"),
                           section_cnt=item["section_cnt"] if "section_cnt" in item else 0,
                           doctor_cnt=item["doctor_cnt"] if "doctor_cnt" in item else 0,
                           comment_cnt=item["comment_cnt"] if "comment_cnt" in item else 0,
                           like_cnt=item["like_cnt"] if "like_cnt" in item else 0,
                           good_at=(' '.join(item["good_at"])).encode("utf-8"),
                           csr=item["csr"] if "csr" in item else 0
                           )
        except Exception, ex:
            logging.error(ex, exc_info=1)
            # print item
            raise ex

        sql = sql[:-1]  # 去掉最后的,

        sql += " on duplicate key update del_flag=0"
        doctor_conn.execute_sql(sql)
예제 #7
0
    def insert(cls, phone, msg, sms_type):
        """
        分页获取...

        :return:
        """
        sql = "insert into {db}.{tbl}(phone,msg,sms_type) values ('{phone}', '{msg}', {sms_type}) ". \
            format(db=cls.db_name,
                   tbl=cls.table_name,
                   phone=phone,
                   msg=msg,
                   sms_type=sms_type,
                   )

        item = doctor_conn.execute_sql(sql)
        return item
예제 #8
0
 def update_deal_section_flag(cls, index, status=-1):
     sql = "update {db}.{tbl}  set deal_section_flag={status} where `index`={index}".format(
         db=cls.db_name, tbl=cls.table_name, status=status, index=index)
     doctor_conn.execute_sql(sql)
예제 #9
0
    @classmethod
    def insert_list(cls, hospital_list):
        if len(hospital_list) == 0:
            logging.error("######## nothing to be inserted...")
            return

        sql = "insert into {db}.{tbl}(`name`, `index`, img_url, section_cnt, doctor_cnt, comment_cnt, province, city) " \
              "values ".format(db=cls.db_name,
                               tbl=cls.table_name)

        try:
            for index, item in enumerate(hospital_list):
                sql += " ('{name}', {index}, '{img_url}', {section_cnt}, {doctor_cnt}, {comment_cnt}, '{province}', " \
                       "'{city}'),". \
                    format(name=item["name"].encode("utf-8"),
                           index=item["index"] if "index" in item else 0,
                           section_cnt=item["section_cnt"] if "section_cnt" in item else 0,
                           doctor_cnt=item["doctor_cnt"] if "doctor_cnt" in item else 0,
                           comment_cnt=item["comment_cnt"] if "comment_cnt" in item else 0,
                           province=item["province"] if "province" in item else 0,
                           city=item["city"] if "city" in item else 0,
                           img_url=item["img_url"].encode("utf-8")
                           )
        except Exception, ex:
            logging.error(ex, exc_info=1)
            raise ex

        sql = sql[:-1]  # 去掉最后的,
        doctor_conn.execute_sql(sql)
예제 #10
0
class HospitalSectionDao(BaseDao):
    db_name = "doctor"
    table_name = "hospital_section_map"

    @classmethod
    def update_deal_doctor_flag(cls, section_id, status=-1):
        sql = "update {db}.{tbl}  set deal_doctor_flag={status} where `id`={section_id}".format(
            db=cls.db_name,
            tbl=cls.table_name,
            status=status,
            section_id=section_id)
        doctor_conn.execute_sql(sql)

    @classmethod
    def get_all_sections_which_need_to_deal_doctor(cls):
        sql = "select * from {db}.{tbl} where deal_doctor_flag=0 limit 60000, 30000".format(
            db=cls.db_name, tbl=cls.table_name)
        print sql
        items = doctor_conn.fetchall(sql)
        return items

    @classmethod
    def get_by_hospital_index(cls, hospital_index):
        sql = "select * from {db}.{tbl} where `hospital_index`={hospital_index}". \
            format(db=cls.db_name,
                   tbl=cls.table_name,
                   hospital_index=hospital_index)
        item = doctor_conn.fetchone(sql)
        return item

    @classmethod
    def get_by_hospital_index_sectionP_sectionC(cls, hospital_index, section_p,
                                                section_c):
        sql = "select * from {db}.{tbl} where `hospital_index`={hospital_index} " \
              "and section_p='{section_p}' and section_c='{section_c}'". \
            format(db=cls.db_name,
                   tbl=cls.table_name,
                   hospital_index=hospital_index,
                   section_p=section_p,
                   section_c=section_c)
        item = doctor_conn.fetchone(sql)
        return item

    @classmethod
    def get_all_indexs(cls):
        sql = "select `index` from {db}.{tbl} ".format(db=cls.db_name,
                                                       tbl=cls.table_name)
        items = doctor_conn.fetchall(sql)
        return items

    @classmethod
    def insert(cls, map_item):
        sql = "insert into {db}.{tbl}(`hospital_index`, `section_p`, section_c, doctor_cnt, link, like_cnt) " \
              "values  ({hospital_index}, '{section_p}', '{section_c}', {doctor_cnt}, '{link}', {like_cnt}) ".format(
                db=cls.db_name,
                tbl=cls.table_name,
                hospital_index=map_item["hospital_index"] if "hospital_index" in map_item else 0,
                section_p=map_item["section_p"] if "section_p" in map_item else 0,
                section_c=map_item["section_c"] if "section_c" in map_item else 0,
                link=map_item["link"] if "link" in map_item else 0,
                like_cnt=map_item["like_cnt"] if "like_cnt" in map_item else 0,
                doctor_cnt=map_item["doctor_cnt"] if "doctor_cnt" in map_item else 0,
        )
        doctor_conn.execute_sql(sql)

    @classmethod
    def insert_list(cls, hospital_list):
        if len(hospital_list) == 0:
            logging.error("######## nothing to be inserted...")
            return

        sql = "insert into {db}.{tbl}(`name`, `index`, img_url, section_cnt, doctor_cnt, comment_cnt, province, city) " \
              "values ".format(db=cls.db_name,
                               tbl=cls.table_name)

        try:
            for index, item in enumerate(hospital_list):
                sql += " ('{name}', {index}, '{img_url}', {section_cnt}, {doctor_cnt}, {comment_cnt}, '{province}', " \
                       "'{city}'),". \
                    format(name=item["name"].encode("utf-8"),
                           index=item["index"] if "index" in item else 0,
                           section_cnt=item["section_cnt"] if "section_cnt" in item else 0,
                           doctor_cnt=item["doctor_cnt"] if "doctor_cnt" in item else 0,
                           comment_cnt=item["comment_cnt"] if "comment_cnt" in item else 0,
                           province=item["province"] if "province" in item else 0,
                           city=item["city"] if "city" in item else 0,
                           img_url=item["img_url"].encode("utf-8")
                           )
        except Exception, ex:
            logging.error(ex, exc_info=1)
            raise ex

        sql = sql[:-1]  # 去掉最后的,
        doctor_conn.execute_sql(sql)