Fix GpsCheckin

This commit is contained in:
2025-08-29 20:05:34 +09:00
parent 23a9902885
commit 42f6471f73
2 changed files with 40 additions and 41 deletions

View File

@ -927,6 +927,9 @@ class GpsCheckin(models.Model):
event_id = models.BigIntegerField(null=True, blank=True)
team_id = models.BigIntegerField(null=True, blank=True)
checkpoint_id = models.BigIntegerField(null=True, blank=True)
# データベースの実際のフィールドと一致させる
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'rog_gpscheckin'
@ -935,14 +938,6 @@ class GpsCheckin(models.Model):
def __str__(self):
return f"GPS Checkin {self.id} - {self.zekken}"
def save(self, *args, **kwargs):
# 作成時・更新時のタイムスタンプを自動設定
from django.utils import timezone
if not self.create_at:
self.create_at = timezone.now()
self.update_at = timezone.now()
super().save(*args, **kwargs)
class RogUser(models.Model):
user=models.OneToOneField(CustomUser, on_delete=models.CASCADE)
phone=models.CharField(_('Phone Number'), max_length=55)

View File

@ -2659,30 +2659,34 @@ def get_checkins(request, *args, **kwargs):
logger.debug(f"=== event_code is required.")
return Response({"error": "event_code is required"}, status=400)
logger.debug(f"=== Searching for zekken={zekken_number}, event_code={event_code}")
# チェックインデータの取得とCP情報の結合
checkins = GpsCheckin.objects.filter(
zekken=zekken_number,
event_code=event_code
).order_by('serial_number')
logger.debug(f"=== Found {checkins.count()} checkins")
data = []
for c in checkins:
location = Location.objects.filter(cp=c.cp_number,group=event_code).first()
if location:
formatted_time = None
if c.create_at:
if c.checkin_time:
try:
# create_atが文字列の場合はdatetimeに変換
if isinstance(c.create_at, str):
c.create_at = datetime.strptime(c.create_at, '%Y-%m-%d %H:%M:%S')
# checkin_timeが文字列の場合はdatetimeに変換
if isinstance(c.checkin_time, str):
c.checkin_time = datetime.strptime(c.checkin_time, '%Y-%m-%d %H:%M:%S')
# JST(+9時間)に変換して時刻フォーマット
jst_time = c.create_at + timedelta(hours=9)
jst_time = c.checkin_time + timedelta(hours=9)
formatted_time = jst_time.strftime('%H:%M:%S')
except (ValueError, TypeError, AttributeError) as e:
logger.error(f"Error formatting create_at for checkin {c.id}: {str(e)}")
logger.error(f"Raw create_at value: {c.create_at}")
logger.error(f"Error formatting checkin_time for checkin {c.id}: {str(e)}")
logger.error(f"Raw checkin_time value: {c.checkin_time}")
formatted_time = None
data.append({
@ -2691,16 +2695,16 @@ def get_checkins(request, *args, **kwargs):
'cp_number': c.cp_number,
'sub_loc_id': location.sub_loc_id if location else f"#{c.cp_number}",
'location_name': location.location_name if location else None,
'create_at': formatted_time, #(c.create_at + timedelta(hours=9)).strftime('%H:%M:%S') if c.create_at else None,
'validate_location': c.validate_location,
'points': c.points or 0,
'buy_flag': c.buy_flag,
'create_at': formatted_time, #(c.checkin_time + timedelta(hours=9)).strftime('%H:%M:%S') if c.checkin_time else None,
'validate_location': True, # デフォルト値として設定
'points': location.checkin_point if location else 0, # locationから取得
'buy_flag': False, # デフォルト値として設定
'photos': location.photos if location else None,
'image_address': get_image_url(c.image_address),
'receipt_address': get_image_url(c.image_receipt),
'image_address': None, # 現在のモデルには存在しない
'receipt_address': None, # 現在のモデルには存在しない
'location_name': location.location_name if location else None,
'checkin_point': location.checkin_point if location else None,
'buy_point': location.buy_point
'buy_point': location.buy_point if location else 0
})
#logger.debug(f"data={data}")