123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- # -*- encoding: utf-8 -*-
- """
- @File : AgentDeviceController.py
- @Time : 2024/3/8 13:55
- @Author : stephen
- @Email : zhangdongming@asj6.wecom.work
- @Software: PyCharm
- """
- from datetime import datetime
- from dateutil.relativedelta import relativedelta
- from collections import defaultdict
- from decimal import Decimal
- import traceback
- from django.http import QueryDict
- from django.views import View
- from AgentModel.models import AgentCustomerInfo, AgentDeviceOrder, AgentDevice, AgentCloudServicePackage
- from Model.models import DeviceTypeModel
- from Object.ResponseObject import ResponseObject
- from Object.TokenObject import TokenObject
- class AgentDeviceView(View):
- def get(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.GET, request, operation)
- def post(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.POST, request, operation)
- def delete(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- delete = QueryDict(request.body)
- if not delete:
- delete = request.GET
- return self.validation(delete, request, operation)
- def put(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- put = QueryDict(request.body)
- return self.validation(put, request, operation)
- def validation(self, request_dict, request, operation):
- pass
- language = request_dict.get('language', 'en')
- response = ResponseObject(language, 'pc')
- # 订单结算界面
- if operation == 'XXXXX':
- pass
- else:
- tko = TokenObject(
- request.META.get('HTTP_AUTHORIZATION'),
- returntpye='pc')
- if tko.code != 0:
- return response.json(tko.code)
- response.lang = tko.lang
- userID = tko.userID
- if operation == 'getAgentDevice':
- return self.get_agent_device(userID, request_dict, response)
- else:
- return response.json(444, 'operation')
- def get_agent_device(self, userID, request_dict, response):
- """
- 查询设备明细
- @param userID: userID
- @param request_dict: 请求参数
- @param request_dict ac_id: 代理商id
- @param request_dict device_name: 设备名字
- @param request_dict status: 设备类型
- @param request_dict serial_number: 设备9位序列号
- @param response: 响应对象
- @return:
- """
- device_name = request_dict.get('device_name', None)
- status = request_dict.get('status', None)
- serial_number = request_dict.get('serial_number', None)
- agent_customer_info = AgentCustomerInfo.objects.filter(user_id=userID).first()
- if agent_customer_info is None:
- return response.json(104, 'Agent customer not found')
- ac_id = agent_customer_info.id
- try:
- agent_device_qs = AgentDevice.objects.filter(ac_id=ac_id)
- if device_name:
- # 根据device_name查询对应的type值
- device_types = DeviceTypeModel.objects.filter(name=device_name).values_list('type', flat=True)
- agent_device_qs = agent_device_qs.filter(type__in=device_types)
- if status:
- agent_device_qs = agent_device_qs.filter(status=status)
- if serial_number:
- agent_device_qs = agent_device_qs.filter(serial_number=serial_number)
- # 构造返回列表
- device_list = []
- for device in agent_device_qs:
- device_type = DeviceTypeModel.objects.filter(type=device.type).first()
- device_name = device_type.name if device_type else device.type
- device_list.append({
- 'id': device.id,
- 'ac_id': device.ac_id,
- 'status': device.status,
- 'serial_number': device.serial_number,
- 'device_name': device_name,
- 'at_time': device.at_time,
- })
- return response.json(0, {'list': device_list})
- except Exception as e:
- print(e)
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|