You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.7 KiB
39 lines
1.7 KiB
import pymysql |
|
from pymysql.cursors import DictCursor |
|
from group.models import * |
|
|
|
group_database_info = { |
|
'host': '10.10.1.52', |
|
'port': 3306, |
|
'user': 'dgp_read', |
|
'password': '1d8qB83F9s63kpS', |
|
} |
|
|
|
|
|
class GetGroupInfo: |
|
def __init__(self): |
|
self.db_conn = pymysql.connect(**group_database_info) |
|
self.db_cursor = self.db_conn.cursor(cursor=DictCursor) |
|
self.group_list = self.get_groups() |
|
|
|
# 如果集团数据不存在则返回False |
|
def is_group_exist(self, group_code): |
|
if Group.objects.filter(group_code=group_code).exists(): |
|
return Group.objects.get(group_code=group_code) |
|
else: |
|
for group in self.group_list: |
|
if group.get('group_code') == group_code: |
|
return Group.objects.create(group_code=group_code, |
|
group_name=group.get('group_name'), |
|
group_address=f"https://plus.yinghezhong.com/{group_code}", |
|
cinema_count=group.get('cinema_count')) |
|
return False |
|
|
|
# 查询集团数据库获取集团信息 |
|
def get_groups(self): |
|
group_info_sql = """SELECT bcg.group_code, bcg.group_name, COUNT(bc.group_code) as cinema_count FROM dgp_bd_db.bd_cinema_group as bcg LEFT JOIN dgp_bd_db.bd_cinema as bc ON bcg.group_code = bc.group_code WHERE bcg.status = 1 AND bc.status = 1 AND length(bcg.group_code) = 8 AND bcg.group_code != '87879012' GROUP BY bcg.group_code ORDER BY cinema_count DESC;""" |
|
self.db_cursor.execute(group_info_sql) |
|
group_list = self.db_cursor.fetchall() |
|
self.db_cursor.close() |
|
self.db_conn.close() |
|
return group_list
|
|
|