def get_by_location(cls, province_code, city_code, area_code, page_num, page_size): """ 分页获取... :return: """ location_str = "" if province_code != 0 and city_code == 0 and area_code == 0: location_str = " and province={province} ".format(province=province_code) elif province_code != 0 and city_code != 0 and area_code == 0: location_str = " and province={province} and city={city} ". \ format(province=province_code, city=city_code) elif province_code != 0 and city_code != 0 and area_code != 0: location_str = " and province={province} and city={city} and area={area} ". \ format(province=province_code, city=city_code, area=area_code) offset = (page_num - 1) * page_size sql = "select * from {db}.{table} where del_flag=0 " \ "{location_str} " \ "order by `number` ASC limit {offset},{limit}". \ format(db=cls.db_name, table=cls.table_name, offset=offset, limit=page_size, location_str=location_str) item_list = doctor_conn.fetchall(sql) return item_list
def get_all(cls, is_white_mode=False): """ 获取全部的homepage items 如果是白名单模式,则可以看到未上架未过期的item,否则只能看到已上架未过期的item。 :param is_white_mode: 是否为白名单模式 :return: """ now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") if is_white_mode: sql = "select id, ui_type, `title`, `desc`, obj_id, link, float_txt, img_url from {db}.{table} " \ "where del_flag=0 " \ "and end_time>='{now}' order by sort desc".format(db=cls.db_name, table=cls.table_name, now=now) else: sql = "select id, ui_type, `title`, `desc`, obj_id, link, float_txt, img_url from {db}.{table} " \ "where del_flag=0 " \ "and start_time<='{now}' and end_time>='{now}' " \ "order by sort desc".format(db=cls.db_name, table=cls.table_name, now=now) item_list = doctor_conn.fetchall(sql) return item_list
def get_all(cls): """ 获取全部分类列表 :return: """ sql = "select id,`name` from {db}.{tbl} where del_flag=0 order by sort desc".format( db=cls.db_name, tbl=cls.table_name) items = doctor_conn.fetchall(sql) return items
def get_all(cls): """ 分页获取... :return: """ sql = "select id as code, `name`, `level` from {db}.{table} where del_flag=0 ". \ format(db=cls.db_name, table=cls.table_name) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_answer(cls, answer_id): """ :param answer_id: :return: """ sql = "select img_url from {db}.{table} where del_flag=0 and answer_id={answer_id} order by sort desc ". \ format(db=cls.db_name, table=cls.table_name, answer_id=answer_id) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_news_id(cls, news_id): """ 根据分类获取news :param news_id: :return: """ sql = "select img_url, thumb_url from {db}.{tbl} where news_id={news_id}". \ format(db=cls.db_name, tbl=cls.table_name, news_id=news_id, ) items = doctor_conn.fetchall(sql) return items
def get_by_askid(cls, ask_id): """ 根据ask_id获取图片列表 :return: """ sql = "select img_url from {db}.{table} where del_flag=0 and ask_id={ask_id} order by sort desc ". \ format(db=cls.db_name, table=cls.table_name, ask_id=ask_id) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_location_and_section(cls, province_code, city_code, area_code, section_outer, section_inner, page_num, page_size): """ 分页获取... :return: """ # 省市区 location_str = "" if province_code != 0 and city_code == 0 and area_code == 0: location_str = " and province={province} ".format( province=province_code) elif province_code != 0 and city_code != 0 and area_code == 0: location_str = " and province={province} and city={city} ". \ format(province=province_code, city=city_code) elif province_code != 0 and city_code != 0 and area_code != 0: location_str = " and province={province} and city={city} and area={area} ". \ format(province=province_code, city=city_code, area=area_code) # 科室 section_str = "" if section_outer and section_inner: section_str = " and section_p='{section_outer}' and section_c='{section_inner}' ". \ format(section_outer=section_outer, section_inner=section_inner ) elif section_outer and not section_inner: section_str = " and section_p='{section_outer}' ". \ format(section_outer=section_outer, ) # 分页 offset = (page_num - 1) * page_size sql = "select * from {db}.{table} where del_flag=0 " \ "{location_str} {section_str} " \ "limit {offset},{limit}". \ format(db=cls.db_name, table=cls.table_name, offset=offset, limit=page_size, location_str=location_str, section_str=section_str, ) logger.error(sql) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_page(cls, page_num, page_size): """ 分页获取问题... :return: """ offset = (page_num - 1) * page_size sql = "select * from {db}.{table} where del_flag=0 order by sort desc limit {offset},{limit}". \ format(db=cls.db_name, table=cls.table_name, offset=offset, limit=page_size) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_section(cls, section_code, page_num, page_size): """ 分页获取... :return: """ offset = (page_num - 1) * page_size sql = "select * from {db}.{table} where del_flag=0 " \ "and section_code={section_code} " \ "order by `number` ASC limit {offset},{limit}". \ format(db=cls.db_name, table=cls.table_name, offset=offset, limit=page_size, section_code=section_code) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_page(cls, ask_id, answer_id, page_num, page_size): """ 分页获取问题... :return: """ offset = (page_num - 1) * page_size sql = "select * from {db}.{table} where ask_id={ask_id} and answer_id={answer_id} " \ "and del_flag=0 limit {offset},{limit}". \ format(db=cls.db_name, table=cls.table_name, ask_id=ask_id, answer_id=answer_id, offset=offset, limit=page_size) item_list = doctor_conn.fetchall(sql) return item_list
def get_by_category(cls, category_id, page_num, page_size): """ 根据分类获取news :param category_id: :param page_num: :param page_size: :return: """ sql = "select id, title, content, author_id, comment_num, follow_num, keep_num, like_num," \ "UNIX_TIMESTAMP(create_time) as create_time, UNIX_TIMESTAMP(update_time) as update_time from {db}.{tbl} " \ "where id in " \ "(select news_id from {db}.{category_map_tbl} where category_id={category_id} ) " \ "order by create_time desc limit {offset}, {page_size}" \ .format(db=cls.db_name, tbl=cls.table_name, category_map_tbl="news_category_map", category_id=category_id, offset=(int(page_num) - 1) * page_size, page_size=page_size ) items = doctor_conn.fetchall(sql) return items
def get_all_indexs_which_need_to_deal_section(cls): sql = "select `index` from {db}.{tbl} where deal_section_flag=-1".format( db=cls.db_name, tbl=cls.table_name) print sql items = doctor_conn.fetchall(sql) return items
def get_all_indexs(cls): sql = "select `index` from {db}.{tbl}".format(db=cls.db_name, tbl=cls.table_name) print sql items = doctor_conn.fetchall(sql) return items
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