fix: auto repair bugs #26, #25, #24
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m13s
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 3m13s
This commit is contained in:
parent
47be0781ac
commit
7a6a519fbe
26
apps/devices/services.py
Normal file
26
apps/devices/services.py
Normal 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),
|
||||||
|
}
|
||||||
@ -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.status = 'bound'
|
||||||
device.save()
|
device.save()
|
||||||
|
|
||||||
|
|||||||
@ -26,4 +26,6 @@ class Spirit(models.Model):
|
|||||||
ordering = ['-created_at']
|
ordering = ['-created_at']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if self.user_id is None:
|
||||||
|
return self.name
|
||||||
return f"{self.name} - {self.user.phone}"
|
return f"{self.name} - {self.user.phone}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user