From ef5623ad276f9d89f417d088e4a3f30265eec07a Mon Sep 17 00:00:00 2001 From: rogersun Date: Wed, 10 Jun 2026 16:04:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=AF=8F=E6=AC=A1=E9=83=BD?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=B0=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/migrations/0004_cinemahall.py | 27 ++++++++++++ ai/migrations/0005_alter_aishow_created_at.py | 18 ++++++++ ...show_updated_at_alter_aishow_created_at.py | 23 ++++++++++ ai/views.py | 44 +++++++++++-------- 4 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 ai/migrations/0004_cinemahall.py create mode 100644 ai/migrations/0005_alter_aishow_created_at.py create mode 100644 ai/migrations/0006_aishow_updated_at_alter_aishow_created_at.py diff --git a/ai/migrations/0004_cinemahall.py b/ai/migrations/0004_cinemahall.py new file mode 100644 index 0000000..d108466 --- /dev/null +++ b/ai/migrations/0004_cinemahall.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.7 on 2026-06-09 10:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ai', '0003_prompttemplate'), + ] + + operations = [ + migrations.CreateModel( + name='CinemaHall', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('cinema_code', models.CharField(max_length=50)), + ('hall_id', models.CharField(max_length=50)), + ('hall_name', models.CharField(max_length=50)), + ], + options={ + 'verbose_name': '影厅数据', + 'verbose_name_plural': '影厅数据', + 'db_table': 'ai_show_hall', + }, + ), + ] diff --git a/ai/migrations/0005_alter_aishow_created_at.py b/ai/migrations/0005_alter_aishow_created_at.py new file mode 100644 index 0000000..9c58894 --- /dev/null +++ b/ai/migrations/0005_alter_aishow_created_at.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2026-06-10 07:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ai', '0004_cinemahall'), + ] + + operations = [ + migrations.AlterField( + model_name='aishow', + name='created_at', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/ai/migrations/0006_aishow_updated_at_alter_aishow_created_at.py b/ai/migrations/0006_aishow_updated_at_alter_aishow_created_at.py new file mode 100644 index 0000000..318a0a4 --- /dev/null +++ b/ai/migrations/0006_aishow_updated_at_alter_aishow_created_at.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.7 on 2026-06-10 07:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ai', '0005_alter_aishow_created_at'), + ] + + operations = [ + migrations.AddField( + model_name='aishow', + name='updated_at', + field=models.DateTimeField(auto_now=True), + ), + migrations.AlterField( + model_name='aishow', + name='created_at', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/ai/views.py b/ai/views.py index e26688f..184b829 100644 --- a/ai/views.py +++ b/ai/views.py @@ -57,22 +57,30 @@ def get_cinema_show_result_func(_zz_code, _show_date): show = data.get_show_data(start, end) income = data.get_total_income(start, end) print(show, income) - try: - AiShow.objects.create( - cinema=cinema.name, - zz_code=cinema.zz_code, - show_date=_show_date, - is_ai_show=False, - show=show, - sales=income, - prompt='', - result='', - message='', - take_times=0, - take_tokens='0' - ) - except Exception as e: - print(e) + show_db = AiShow.objects.filter(Q(is_ai_show=False) & Q(zz_code=_zz_code) & Q(show_date=_show_date)).order_by( + '-id').first() + if show_db: + print('show_db', show_db) + show_db.show = show + show_db.income = income + show_db.save() + else: + try: + AiShow.objects.create( + cinema=cinema.name, + zz_code=cinema.zz_code, + show_date=_show_date, + is_ai_show=False, + show=show, + sales=income, + prompt='', + result='', + message='', + take_times=0, + take_tokens='0' + ) + except Exception as e: + print(e) return show, income @@ -102,7 +110,7 @@ def report(request): last_real_data = AiShow.objects.filter(Q(is_ai_show=False) & Q(zz_code=zz_code) & Q(show_date=show_date) & - Q(created_at__gt=check_point)).order_by('-id').first() + 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) & @@ -149,7 +157,7 @@ def report(request): output_list = [] output_csv = [ ['影厅别名', '影片别名', '语言', '开始时间', '结束时间', '片长', '场间', '', '影厅别名', '影片别名', '语言', - '开始时间', '结束时间', '片长', '场间']] + '开始时间', '结束时间', '片长', '场间']] for v in data.values(): if len(v['ai']) >= len(v['real']): for i in range(len(v['ai'])):