fix: auto repair bugs #26, #25, #24
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m13s

This commit is contained in:
repair-agent 2026-02-24 16:19:40 +08:00
parent 47be0781ac
commit 7a6a519fbe
3 changed files with 33 additions and 2 deletions

26
apps/devices/services.py Normal file
View File

@ -0,0 +1,26 @@
"""
设备模块服务层
"""
from .models import Device, UserDevice
class DeviceStatsService:
"""设备统计服务"""
@staticmethod
def get_bindrate(user):
"""获取用户设备绑定率"""
total_count = Device.objects.count()
if total_count == 0:
return {
'total_count': 0,
'bound_count': 0,
'bind_rate': 0,
}
bound_count = Device.objects.filter(status='bound').count()
bind_rate = bound_count / total_count * 100
return {
'total_count': total_count,
'bound_count': bound_count,
'bind_rate': round(bind_rate, 2),
}

View File

@ -120,7 +120,10 @@ class DeviceViewSet(viewsets.ViewSet):
}
)
# 更新设备状态
# 更新设备状态和可选的设备名称
device_name = request.data.get('device_name')
if device_name:
device.name = device_name
device.status = 'bound'
device.save()

View File

@ -26,4 +26,6 @@ class Spirit(models.Model):
ordering = ['-created_at']
def __str__(self):
if self.user_id is None:
return self.name
return f"{self.name} - {self.user.phone}"