From 34728d5c2461144a99c418741a5e946c7c576f72 Mon Sep 17 00:00:00 2001 From: rogersun Date: Thu, 11 Jun 2026 11:36:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E6=8E=92=E7=89=87csv=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AD=A3=E5=88=99=E5=88=A4=E6=96=AD=202?= =?UTF-8?q?=E3=80=81=E6=89=8B=E5=8A=A8ai=E6=8E=92=E7=89=87=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8C=87=E5=AE=9A=E5=BD=B1=E9=99=A2=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/utils/show_process.py | 17 +++++++++++++++-- ai/views.py | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ai/utils/show_process.py b/ai/utils/show_process.py index e35428f..fd04e63 100644 --- a/ai/utils/show_process.py +++ b/ai/utils/show_process.py @@ -2,10 +2,11 @@ from ai.models import * from ai.utils.show_prompt import * import datetime from django_redis import get_redis_connection +from django.db.models import Q import re # ai排片主流程 -def show_main_process(): +def show_main_process(zz_code=None): # 查看状态 redis_conn = get_redis_connection() redis_key = f'ai_show{datetime.date.today().strftime("%Y%m%d")}' @@ -13,7 +14,10 @@ def show_main_process(): return False # 获取影院列表 redis_conn.set(redis_key, 1, ex=60*60*20) - test_cinema_list = TestCinema.objects.filter(is_active=True).all() + if not zz_code: + test_cinema_list = TestCinema.objects.filter(is_active=True).all() + else: + test_cinema_list = TestCinema.objects.filter(Q(zz_code=zz_code) & Q(is_active=True)).all() # 获取提示词版本 prompt_ver = PromptTemplate.objects.filter( Q(del_flag=False) & Q(prompt_type='version') & Q(prompt_key='ShowPromptVersion')).first().prompt_val @@ -32,11 +36,20 @@ def show_main_process(): print('message:', message) print('tokens:', tokens) # 获取排片数据 + # 方式一 _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '') _show = _show.strip() + # 方式二 if _show == '': _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '') _show = _show.replace('```', '').replace('csv', '').strip() + # 方式三 + if _show == '': + # 正则提取中间内容 + csv_pattern = r"```csv\s*([\s\S]*?)```" + match = re.search(csv_pattern, result) + if match: + _show = match.group(1) print('_show:', _show) # 获取销售额 _sales = next((s for s in result.split('\n') if re.search('预估销售数据', s)), '') diff --git a/ai/views.py b/ai/views.py index bade07e..08fb044 100644 --- a/ai/views.py +++ b/ai/views.py @@ -10,7 +10,8 @@ from ai.utils.basic_func import * # 手动触发ai排片 @csrf_exempt def manual_general_show(request): - result = show_main_process() + zz_code = request.GET.dict().get('cinema_code') + result = show_main_process(zz_code) result_dict = { 'status': 'success' if result else 'fail', 'message': '生成成功' if result else '生成失败', @@ -60,7 +61,7 @@ def report(request): Q(updated_at__gt=check_point)).order_by('-id').first() if not last_real_data: get_cinema_show_result_func(zz_code, show_date) - + last_ai_data = AiShow.objects.filter(Q(is_ai_show=True) & Q(zz_code=zz_code) & Q(show_date=show_date)).order_by('-id').first()