ai:增加排片占比随动数据

升级:支持双网段升级
main
rogersun 1 week ago
parent 987d3b5cb1
commit 6b22f93426
  1. 4
      ai/views.py
  2. 18
      dingxin_toolbox_drf/settings.py
  3. 33
      update/utils/client_util_custom.py
  4. 9
      update/utils/db_compare.py
  5. 27
      update/utils/git_util.py

@ -89,6 +89,8 @@ def report(request):
# 计算排片占比 # 计算排片占比
ai_count = count_show(ai_dict) ai_count = count_show(ai_dict)
real_count = count_show(real_dict) real_count = count_show(real_dict)
target_count = count_show(target_dict)
template_count = count_show(temp_dict)
# 生成时间 # 生成时间
create_time = datetime.datetime.strftime((last_ai_data.created_at + datetime.timedelta(hours=8)), create_time = datetime.datetime.strftime((last_ai_data.created_at + datetime.timedelta(hours=8)),
'%Y-%m-%d %H:%M:%S') '%Y-%m-%d %H:%M:%S')
@ -116,6 +118,8 @@ def report(request):
'prompt': last_ai_data.prompt, 'prompt': last_ai_data.prompt,
'ai_count': ai_count, 'ai_count': ai_count,
'real_count': real_count, 'real_count': real_count,
'target_count': target_count,
'template_count': template_count,
'result': last_ai_data.result, 'result': last_ai_data.result,
'think': think, 'think': think,
'ai_model': last_ai_data.ai_model, 'ai_model': last_ai_data.ai_model,

@ -36,6 +36,12 @@ CONFIG = {
"PASSWORD": "cine123456", "PASSWORD": "cine123456",
"NAME": "dingxin_toolbox", "NAME": "dingxin_toolbox",
}, },
'DB_REMOTE': {
"HOST": '10.10.0.38',
"PORT": 3306,
"USER": "test",
"PASSWORD": "cine123456",
},
'REDIS_IP': '172.16.1.168', 'REDIS_IP': '172.16.1.168',
'ECARD_DB': { 'ECARD_DB': {
"HOST": '10.10.0.61', "HOST": '10.10.0.61',
@ -69,6 +75,12 @@ CONFIG = {
# "PASSWORD": "Cine123456", # "PASSWORD": "Cine123456",
# "NAME": "dingxin_toolbox", # "NAME": "dingxin_toolbox",
# }, # },
'DB_REMOTE': {
"HOST": '10.10.0.38',
"PORT": 3306,
"USER": "test",
"PASSWORD": "cine123456",
},
'REDIS_IP': '127.0.0.1', 'REDIS_IP': '127.0.0.1',
'ECARD_DB': { 'ECARD_DB': {
"HOST": '10.10.0.61', "HOST": '10.10.0.61',
@ -95,6 +107,12 @@ CONFIG = {
"PASSWORD": "Cine123456", "PASSWORD": "Cine123456",
"NAME": "dingxin_toolbox", "NAME": "dingxin_toolbox",
}, },
'DB_REMOTE': {
"HOST": '10.10.0.38',
"PORT": 3306,
"USER": "test",
"PASSWORD": "cine123456",
},
'REDIS_IP': '172.16.1.63', 'REDIS_IP': '172.16.1.63',
'ECARD_DB': { 'ECARD_DB': {
"HOST": '10.10.0.61', "HOST": '10.10.0.61',

@ -1,6 +1,7 @@
import os import os
import json import json
import paramiko import paramiko
import requests
from smb.SMBConnection import SMBConnection from smb.SMBConnection import SMBConnection
from update.models import ClientRelease, Cinema from update.models import ClientRelease, Cinema
import pymysql import pymysql
@ -23,6 +24,7 @@ class ClientUtilCustom:
self.local_path = os.path.join(BASE_DIR, 'dx', 'client') self.local_path = os.path.join(BASE_DIR, 'dx', 'client')
self.deploy_db_config = {'host': '10.10.0.80', 'port': 3306, 'user': 'cine_readonly', self.deploy_db_config = {'host': '10.10.0.80', 'port': 3306, 'user': 'cine_readonly',
'password': 'IyzCtV11', 'database': 'yhz_tool'} 'password': 'IyzCtV11', 'database': 'yhz_tool'}
self.client_mirror = {'url': 'http://10.10.0.38:8989/upload/'}
self.deploy_id = 0 self.deploy_id = 0
self.client_data = [] self.client_data = []
self.client_file_list = [] self.client_file_list = []
@ -135,7 +137,8 @@ class ClientUtilCustom:
print('找到本地文件:', file['name']) print('找到本地文件:', file['name'])
continue continue
# 下载文件到本地 # 下载文件到本地
with open(os.path.join(self.local_path, file['name']), 'wb') as local_file: file_path = os.path.join(self.local_path, file['name'])
with open(file_path, 'wb') as local_file:
# 接收文件并写入本地文件 # 接收文件并写入本地文件
print('从共享下载客户端文件到服务器 共享路径:', rf"{file['path']}{file['name']}", '服务器路径:', print('从共享下载客户端文件到服务器 共享路径:', rf"{file['path']}{file['name']}", '服务器路径:',
os.path.join(self.local_path, file['name'])) os.path.join(self.local_path, file['name']))
@ -145,17 +148,22 @@ class ClientUtilCustom:
client['file_name'] = file['name'] client['file_name'] = file['name']
# 关闭本地文件 # 关闭本地文件
local_file.close() local_file.close()
target_file = os.path.join('/home/client/', file['name'])
self.upload(self.client_mirror['host'], file_path, target_file, self.client_mirror['username'],
self.client_mirror['password'])
print(f'完成客户端同步: {target_file}')
print(self.client_data) print(self.client_data)
# 传输客户端的方法 # 传输客户端的方法
def upload(self, cine_ip, origin, target): def upload(self, cine_ip: str, origin: str, target: str, user: str = 'root', pwd: str = 'cine123456') -> bool:
print('upload', cine_ip, origin, target) print('upload', cine_ip, origin, target)
try:
# 创建Transport客户端 # 创建Transport客户端
trans = paramiko.Transport((cine_ip, 22)) trans = paramiko.Transport((cine_ip, 22))
# 使用密码连接服务器 # 使用密码连接服务器
trans.connect(username='root', password='cine123456') trans.connect(username=user, password=pwd)
# 创建SFTP客户端 # 创建SFTP客户端
sftp = paramiko.SFTPClient.from_transport(trans) sftp = paramiko.SFTPClient.from_transport(trans)
# 上传文件 参数(本地文件路径, 远程文件路径) # 上传文件 参数(本地文件路径, 远程文件路径)
@ -165,6 +173,17 @@ class ClientUtilCustom:
# 关闭客户端 # 关闭客户端
print(f'完成上传,路径/data0/cine/resource/upload/client/{target}') print(f'完成上传,路径/data0/cine/resource/upload/client/{target}')
trans.close() trans.close()
return True
except Exception as e:
print(e)
return False
def upload_server_to_server(self, cine_ip: str, origin: str, target: str) -> bool:
r = requests.get(self.client_mirror['url'], params={'cine_ip': cine_ip, 'origin': origin, 'target': target}).json()
print(r)
if r['result'] == 'success':
return True
return False
def upload_client(self, cinema_ip, client_ver, server_release): def upload_client(self, cinema_ip, client_ver, server_release):
print('upload_client', cinema_ip, client_ver, server_release) print('upload_client', cinema_ip, client_ver, server_release)
@ -183,8 +202,12 @@ class ClientUtilCustom:
print('最终上传版本:', client.file_name, client.upload_name) print('最终上传版本:', client.file_name, client.upload_name)
if not client: if not client:
return False return False
self.upload(cinema_ip, client.file_name, client.upload_name) if cinema_ip.startswith('10.'):
if not self.upload_server_to_server(cinema_ip, client.file_name, client.upload_name):
return False
else:
if not self.upload(cinema_ip, client.file_name, client.upload_name):
return False
# 更新数据库 # 更新数据库
cine = Cinema.objects.filter(ip=cinema_ip).first() cine = Cinema.objects.filter(ip=cinema_ip).first()
db_config = { db_config = {

@ -33,7 +33,12 @@ class DbCompare:
# serv_user = 'dingxin' # serv_user = 'dingxin'
# serv_pwd = 'cine123456' # serv_pwd = 'cine123456'
# serv_port = '3306' # serv_port = '3306'
if self.target_server.startswith('10.'):
serv_host = CONFIG[ENV]['DB_REMOTE']['HOST']
serv_user = CONFIG[ENV]['DB_REMOTE']['USER']
serv_pwd = CONFIG[ENV]['DB_REMOTE']['PASSWORD']
serv_port = 3306
else:
serv_host = CONFIG[ENV]['DB']['HOST'] serv_host = CONFIG[ENV]['DB']['HOST']
serv_user = CONFIG[ENV]['DB']['USER'] serv_user = CONFIG[ENV]['DB']['USER']
serv_pwd = CONFIG[ENV]['DB']['PASSWORD'] serv_pwd = CONFIG[ENV]['DB']['PASSWORD']
@ -42,7 +47,7 @@ class DbCompare:
server_1 = f'--server1={serv_user}:{serv_pwd}@{serv_host}:{serv_port}' server_1 = f'--server1={serv_user}:{serv_pwd}@{serv_host}:{serv_port}'
server_2 = f'--server2={self.target_user}:{self.target_pwd}@{self.target_server}:{self.target_port}' server_2 = f'--server2={self.target_user}:{self.target_pwd}@{self.target_server}:{self.target_port}'
git_util = GitUtil(self.target_release) git_util = GitUtil(self.target_release, self.target_server)
db_name = git_util.get_db_name() db_name = git_util.get_db_name()
cmd = f'mysqldiff {server_1} {server_2} --changes-for=server2 --difftype=sql --force --quiet --skip-table-options {db_name}:cine > {self.diff_sql_path}' cmd = f'mysqldiff {server_1} {server_2} --changes-for=server2 --difftype=sql --force --quiet --skip-table-options {db_name}:cine > {self.diff_sql_path}'

@ -19,18 +19,29 @@ from env import ENV
class GitUtil: class GitUtil:
def __init__(self, short_release): def __init__(self, short_release, target_ip):
self.short_release = short_release self.short_release = short_release
self.local_code_path = os.path.join(settings.BASE_DIR, 'dx', 'code','dingxin') self.target_ip = target_ip
self.local_code_path = os.path.join(settings.BASE_DIR, 'dx', 'code', 'dingxin')
self.cine_sql_path = os.path.join(settings.BASE_DIR, 'dx', 'sql') self.cine_sql_path = os.path.join(settings.BASE_DIR, 'dx', 'sql')
self.db_name = self.get_db_name(self.short_release) self.db_name = self.get_db_name(self.short_release)
self.db_config = { self.db_config = {
'172': {
'host': settings.CONFIG[ENV]['DB']['HOST'], 'host': settings.CONFIG[ENV]['DB']['HOST'],
'user': settings.CONFIG[ENV]['DB']['USER'], 'user': settings.CONFIG[ENV]['DB']['USER'],
'password': settings.CONFIG[ENV]['DB']['PASSWORD'], 'password': settings.CONFIG[ENV]['DB']['PASSWORD'],
'port': 3309, 'port': 3309,
'database': self.db_name, 'database': self.db_name,
'connect_timeout': 5, 'connect_timeout': 5,
},
'10': {
'host': settings.CONFIG[ENV]['DB_REMOTE']['HOST'],
'user': settings.CONFIG[ENV]['DB_REMOTE']['USER'],
'password': settings.CONFIG[ENV]['DB_REMOTE']['PASSWORD'],
'port': 3306,
'database': self.db_name,
'connect_timeout': 5,
}
} }
# 执行一次 clone代码到本地 # 执行一次 clone代码到本地
@ -106,7 +117,11 @@ class GitUtil:
def write_cine_sql_by_mysql(self): def write_cine_sql_by_mysql(self):
print('开始将cine.sql写入数据库') print('开始将cine.sql写入数据库')
if os.path.exists(sql_path := os.path.join(self.cine_sql_path, f'{self.db_name}.sql')): if os.path.exists(sql_path := os.path.join(self.cine_sql_path, f'{self.db_name}.sql')):
cmd = f'mysql -h{self.db_config["host"]} -P{self.db_config["port"]} -u{self.db_config["user"]} -p{self.db_config["password"]} < {sql_path}' if self.target_ip.startswith('10.'):
db = self.db_config['10']
else:
db = self.db_config['172']
cmd = f'mysql -h{db["host"]} -P{db["port"]} -u{db["user"]} -p{db["password"]} < {sql_path}'
print('执行命令', cmd) print('执行命令', cmd)
r = os.system(cmd) r = os.system(cmd)
print('cine.sql写入结果', r) print('cine.sql写入结果', r)
@ -125,7 +140,11 @@ class GitUtil:
f'DROP FUNCTION IF EXISTS `{self.db_name}`.`GetCostMobile`;', f'DROP FUNCTION IF EXISTS `{self.db_name}`.`GetCostMobile`;',
f'DROP VIEW IF EXISTS `{self.db_name}`.`retail_inventory_list`;' f'DROP VIEW IF EXISTS `{self.db_name}`.`retail_inventory_list`;'
] ]
_db_conn = pymysql.connect(**self.db_config) if self.target_ip.startswith('10.'):
db = self.db_config['10']
else:
db = self.db_config['172']
_db_conn = pymysql.connect(**db)
_db_cursor = _db_conn.cursor() _db_cursor = _db_conn.cursor()
for cmd in cmd_list: for cmd in cmd_list:
r = _db_cursor.execute(cmd) r = _db_cursor.execute(cmd)

Loading…
Cancel
Save