防止每次都生成新的数据

main
rogersun 2 weeks ago
parent 05821f366b
commit ef5623ad27
  1. 27
      ai/migrations/0004_cinemahall.py
  2. 18
      ai/migrations/0005_alter_aishow_created_at.py
  3. 23
      ai/migrations/0006_aishow_updated_at_alter_aishow_created_at.py
  4. 10
      ai/views.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',
},
),
]

@ -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),
),
]

@ -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),
),
]

@ -57,6 +57,14 @@ 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)
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,
@ -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) &

Loading…
Cancel
Save