From d60ad4170571c88d0aa6b0f37c8f623c3b13e661 Mon Sep 17 00:00:00 2001 From: rogersun Date: Thu, 16 Jul 2026 13:51:44 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=99=BA=E8=83=BD=E6=8E=92=E7=89=87?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=AA=E5=B1=95=E7=A4=BA=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1+=E6=89=8B=E5=8A=A8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=202=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=BD=B1=E9=99=A2=E7=AE=A1=E7=90=86=E4=B8=AD=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/migrations/0026_aishow_create_datetime.py | 18 +++++++++++ ai/models.py | 1 + ai/utils/show_database.py | 33 ++++++++++---------- ai/utils/show_func.py | 7 +++-- ai/utils/show_process.py | 28 ++++++++++------- ai/utils/sql.py | 14 +++++---- ai/views.py | 18 ++++++----- env.py | 2 +- update/utils/get_version.py | 2 +- 9 files changed, 76 insertions(+), 47 deletions(-) create mode 100644 ai/migrations/0026_aishow_create_datetime.py diff --git a/ai/migrations/0026_aishow_create_datetime.py b/ai/migrations/0026_aishow_create_datetime.py new file mode 100644 index 0000000..87b77df --- /dev/null +++ b/ai/migrations/0026_aishow_create_datetime.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2026-07-16 04:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ai', '0025_movieguidance_type'), + ] + + operations = [ + migrations.AddField( + model_name='aishow', + name='create_datetime', + field=models.CharField(default='', max_length=50), + ), + ] diff --git a/ai/models.py b/ai/models.py index da49cb1..4e05bd9 100644 --- a/ai/models.py +++ b/ai/models.py @@ -68,6 +68,7 @@ class AiShow(models.Model): prompt = models.TextField() # 生成的用户提示词部分 result = models.TextField() # ai返回结果中最终输出部分 message = models.TextField() # ai返回结果的完整信息 + create_datetime = models.CharField(max_length=50, default='') # 生成的时间 created_at = models.DateTimeField(auto_now_add=True) # ai返回结果的时间 updated_at = models.DateTimeField(auto_now=True) take_times = models.IntegerField(default=0) # 从提示词发给ai到取得返回结果的时间,单位秒 diff --git a/ai/utils/show_database.py b/ai/utils/show_database.py index 04fb473..7314fc8 100644 --- a/ai/utils/show_database.py +++ b/ai/utils/show_database.py @@ -59,31 +59,30 @@ class GetData: # 获取指定日期的可用于排片的影片 def get_handle_movie(self, date): if get_runtime_val('real_target') == '0': - start_datetime = datetime.datetime.today().replace(hour=6, minute=0,second=0,microsecond=0) - end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, - seconds=59) + movie_date_start = datetime.datetime.today().replace(hour=6, minute=0, second=0, microsecond=0) + movie_date_end = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, + seconds=59) + show_date_limit = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6, minutes=0, + seconds=0) + bl_bool, bl_str, bl_list = get_black_list(self.zz_code) + if bl_bool: + sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' + self.cur.execute(sql, (movie_date_start, movie_date_end, show_date_limit, *bl_list)) + print(self.cur.mogrify(sql, (movie_date_start, movie_date_end, show_date_limit, *bl_list))) + else: + sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' + self.cur.execute(sql, (movie_date_start, movie_date_end, show_date_limit)) + print(self.cur.mogrify(sql, (movie_date_start, movie_date_end, show_date_limit))) else: start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, seconds=59) end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6) - print('get_handle_movie-start_datetime', datetime.datetime.strftime(start_datetime, '%Y-%m-%d %H:%M:%S')) - print('get_handle_movie-end_datetime', datetime.datetime.strftime(end_datetime, '%Y-%m-%d %H:%M:%S')) - bl_bool, bl_str, bl_list = get_black_list(self.zz_code) - if bl_bool: - if get_runtime_val('real_target') == '0': - sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' - self.cur.execute(sql, (start_datetime, end_datetime, *bl_list)) - print(self.cur.mogrify(sql, (start_datetime, end_datetime, *bl_list))) - else: + bl_bool, bl_str, bl_list = get_black_list(self.zz_code) + if bl_bool: sql = GET_HANDLE_MOVIE + bl_str + ');' self.cur.execute(sql, (start_datetime, end_datetime, *bl_list)) print(self.cur.mogrify(sql, (start_datetime, end_datetime, *bl_list))) - else: - if get_runtime_val('real_target') == '0': - sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' - self.cur.execute(sql, (start_datetime, end_datetime)) - print(self.cur.mogrify(sql, (start_datetime, end_datetime))) else: sql = GET_HANDLE_MOVIE + bl_str + ');' self.cur.execute(sql, (start_datetime, end_datetime)) diff --git a/ai/utils/show_func.py b/ai/utils/show_func.py index 725f53f..23a39fe 100644 --- a/ai/utils/show_func.py +++ b/ai/utils/show_func.py @@ -47,7 +47,8 @@ def get_cinema_show_result_func(_zz_code, _show_date): result='', message='', take_times=0, - take_tokens='0' + take_tokens='0', + create_datetime=datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), ) except Exception as e: print(e) @@ -213,5 +214,5 @@ def get_movie_guidance(cinema, show_date): def get_test_date_from_db(cinema_code: str, show_date: str) -> list: test_data = AiShow.objects.filter( - Q(zz_code=cinema_code) & Q(show_date>=show_date) & Q(is_ai_show=True) & Q(is_manual_test=True)).all() - return [test.prompt_version for test in test_data] + Q(zz_code=cinema_code) & Q(show_date=show_date) & Q(is_ai_show=True)).order_by('-create_datetime').all() + return [(test.create_datetime, test.is_manual_test) for test in test_data] diff --git a/ai/utils/show_process.py b/ai/utils/show_process.py index 351936d..26dfdd2 100644 --- a/ai/utils/show_process.py +++ b/ai/utils/show_process.py @@ -86,6 +86,7 @@ def show_main_process(zz_code=None, day_delta=None): take_times=int((end - start).seconds), take_tokens=tokens, prompt_version=prompt_ver, + create_datetime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), ) except Exception as e: print(e) @@ -96,17 +97,26 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): cinema = TestCinema.objects.filter(zz_code=zz_code).first() ai = ShowAI(cinema, show_date) + # 处理模板日期的排片数据 + template_show, template_date = get_template_show_tomorrow(cinema) + + # 处理目标日期的排片数据 + if str(get_runtime_val('real_target')) == '1': + target_show = get_target_show(cinema, show_date) + else: + target_show = '影厅别名,影厅id,影片别名,本地影片id,语言,放映日期,开始时间,结束时间,片长,场间' + + # 开始请求AI start = datetime.datetime.now() # 开始计时 result, message, tokens = ai.get_show_result_ai(prompt) end = datetime.datetime.now() # 结束计时 + # 打印返回结果 print('prompt:', prompt) print('result:', result) print('message:', message) print('tokens:', tokens) - # 获取排片数据 - print('result:', result) - # 获取当前模型 + # 获取当前模型根据模型处理返回结果 model = AiModel.objects.filter(current_used=True).first() if model.config_name in ['lmstudio_qwen3.6_35b', 'company_qwen3.5_35b']: result_obj = json.loads(result.replace('```json', '').replace('}\n```', '}').strip()) @@ -119,11 +129,6 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): # 预测销售数据 _sales = str(result_obj['income']).strip() - ai_data = AiShow.objects.filter(Q(is_ai_show=True) & - Q(is_manual_test=False) & - Q(zz_code=zz_code) & - Q(show_date=show_date)).order_by('-id').first() - print(ai_data) # 处理返回结果 try: AiShow.objects.create( @@ -133,9 +138,9 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): is_ai_show=True, is_manual_test=True, ai_model=model.config_name, - template=ai_data.template if ai_data is not None else '', - temp_date=ai_data.temp_date if ai_data is not None else '', - target=ai_data.target if ai_data is not None else '', + template=template_show, + temp_date=template_date, + target=target_show, show=data_cleansing(_show), sales=_sales, prompt=prompt, @@ -144,6 +149,7 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str): take_times=int((end - start).seconds), take_tokens=tokens, prompt_version=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + create_datetime=datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), ) except Exception as e: print(e) diff --git a/ai/utils/sql.py b/ai/utils/sql.py index d1bce72..f864b83 100644 --- a/ai/utils/sql.py +++ b/ai/utils/sql.py @@ -202,7 +202,7 @@ SELECT cmi.cinema_movie_alias, cmi.cinema_movie_id, cmi.cinema_movie_time, cmlt.cinema_movie_lang_type_desc as language, - scvm.system_const_val_desc as media_type, + scvm.system_const_val_desc as media_type, cmi.cinema_movie_start_datetime, cmi.cinema_movie_end_datetime FROM cinema_movie_info cmi @@ -210,11 +210,13 @@ FROM cinema_movie_info cmi JOIN system_const_val_map scvm ON cmi.cinema_movie_media_type = scvm.system_const_val_value WHERE scvm.system_const_sub_module = 'new_media_type' AND cmi.cinema_movie_id IN (SELECT ms.cinema_movie_id -FROM cinema_movie_show ms -WHERE ms.cinema_del_flag = 1 - AND ms.cinema_movie_show_start_time >= %s - AND ms.cinema_movie_show_start_time <= %s -GROUP BY ms.cinema_movie_num) AND cmi.cinema_movie_num NOT IN ( + FROM cinema_movie_show ms + WHERE ms.cinema_del_flag = 1 + AND ms.cinema_movie_show_start_time >= %s + AND ms.cinema_movie_show_start_time <= %s + GROUP BY ms.cinema_movie_num) + AND cmi.cinema_movie_end_datetime > %s + AND cmi.cinema_movie_num NOT IN (' """ # 获取新上映的影片 diff --git a/ai/views.py b/ai/views.py index 28a05e6..ba9a727 100644 --- a/ai/views.py +++ b/ai/views.py @@ -1,5 +1,6 @@ from anyio import sleep from django.http import JsonResponse +from django.utils.timezone import make_aware, utc from django.db.models import Q from django.views.decorators.csrf import csrf_exempt import json @@ -70,15 +71,14 @@ def report(request): if test is None or test == '': last_ai_data = AiShow.objects.filter(Q(is_ai_show=True) & - Q(is_manual_test=False) & Q(zz_code=zz_code) & Q(show_date=show_date)).order_by('-id').first() else: + print('test', test) last_ai_data = AiShow.objects.filter(Q(is_ai_show=True) & - Q(is_manual_test=True) & Q(zz_code=zz_code) & Q(show_date=show_date) & - Q(prompt_version=test)).order_by('-id').first() + Q(create_datetime=test)).first() if not last_ai_data: result_dict = { 'status': 'Failure', @@ -102,9 +102,7 @@ def report(request): real_count, real_total = count_show(real_dict) target_count, target_total = count_show(target_dict) template_count, template_total = count_show(temp_dict) - # 生成时间 - create_time = datetime.datetime.strftime((last_ai_data.created_at + datetime.timedelta(hours=8)), - '%Y-%m-%d %H:%M:%S') + if last_ai_data.ai_model in ['lmstudio_qwen3.6_35b', 'company_qwen3.5_35b']: think = json.loads(last_ai_data.message)['choices'][0]['message']['reasoning'] else: @@ -136,15 +134,18 @@ def report(request): 'target_total': target_total, 'template_total': template_total, 'result': last_ai_data.result, + 'is_manual_test': last_ai_data.is_manual_test, + 'prompt_version': last_ai_data.prompt_version, 'think': think, 'ai_model': last_ai_data.ai_model, - 'create_time': create_time + 'create_time': last_ai_data.create_datetime } } print(result_dict) return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) +# 获取已经生成排片的日期范围 @csrf_exempt def get_report_date_api(request): start, end = get_report_date() @@ -208,6 +209,7 @@ def get_test_date(request): return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) +# 获取指定日和和影院的提示词用于手动验证 @csrf_exempt def get_prompt(request): cinema_code = request.GET.get('cinema_code') @@ -218,4 +220,4 @@ def get_prompt(request): 'data': get_prompt_process(cinema_code, show_date) } print(result_dict) - return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) \ No newline at end of file + return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) diff --git a/env.py b/env.py index 2e11221..2cd8a73 100644 --- a/env.py +++ b/env.py @@ -1 +1 @@ -ENV = 'local' +ENV = ('dev') diff --git a/update/utils/get_version.py b/update/utils/get_version.py index 3f1ef17..4cfca0a 100644 --- a/update/utils/get_version.py +++ b/update/utils/get_version.py @@ -79,7 +79,7 @@ class GetVersion(object): if cinema_config.get('url').endswith('cinema.yhz.com'): is_cloud = 'SAAS版' else: - is_cloud = '云版本' if res.get('dx_sys_version', '--') == 'CLOUD' else '--', + is_cloud = '云版本' if res.get('dx_sys_version', '--') == 'CLOUD' else '--' update_data = { 'name': res['cinema_name'], 'zz_num': res['cinema_num'],