""" 设备模块服务层 """ 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), }