|
@@ -1,3 +1,17 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""
|
|
|
+@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
+@AUTHOR: ASJRD019
|
|
|
+@NAME: AnsjerFormal
|
|
|
+@software: PyCharm
|
|
|
+@DATE: 2019/5/9 11:50
|
|
|
+@Version: python3.6
|
|
|
+@MODIFY DECORD:ansjer dev
|
|
|
+@file: AliPayObject.py
|
|
|
+@Contact: pzb3076@163.com
|
|
|
+"""
|
|
|
+
|
|
|
from django.views.generic.base import View
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
@@ -8,6 +22,7 @@ import traceback,time
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
+from collections import Counter
|
|
|
'''
|
|
|
|
|
|
http://192.168.136.45:8077/userbrandinfo?operation=query&token=test&page=1&line=10
|
|
@@ -48,6 +63,8 @@ class UserBrandInfo(View):
|
|
|
return self.add_info(request_dict, userID,response)
|
|
|
elif operation == 'queryAll':
|
|
|
return self.query_all_info(request_dict, userID,response)
|
|
|
+ elif operation == 'queryDeviceSupplier':
|
|
|
+ return self.query_deviceSupplier_info(request_dict, userID,response)
|
|
|
else:
|
|
|
return response.json(444,'444')
|
|
|
else:
|
|
@@ -109,42 +126,59 @@ class UserBrandInfo(View):
|
|
|
def query_all_info(self, request_dict, userID,response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
- order = request_dict.get('order','-id')
|
|
|
- if order == '':
|
|
|
- order ='-id'
|
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
|
if param_flag is True:
|
|
|
check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
if check_perm is True:
|
|
|
+ # 按照用户去重复查询
|
|
|
user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
|
|
|
-
|
|
|
print (user_brand_queryset)
|
|
|
- addtime=[]
|
|
|
send_jsons=[]
|
|
|
counts=0
|
|
|
for i in user_brand_queryset:
|
|
|
counts=counts+1
|
|
|
- user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by(order)[:1]
|
|
|
+ user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
- addtime.append(user_brand_querysetlast["datas"][0]['fields']['addTime'])
|
|
|
username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
+ # 按照加入的日期排序
|
|
|
+ send_jsons = sorted(send_jsons, key=lambda x:x['fields']['addTime'], reverse=True)
|
|
|
+ # 分页
|
|
|
+ send_jsons = send_jsons[(page - 1) * line:page * line]
|
|
|
+ return response.json(0, {'datas': send_jsons, 'count': counts})
|
|
|
|
|
|
- print(addtime)
|
|
|
- print(1111111111)
|
|
|
- user_brand_queryset = User_Brand.objects.filter(userID__in = user_brand_queryset, addTime__in=addtime).order_by(order)
|
|
|
- if user_brand_queryset.exists():
|
|
|
- count = user_brand_queryset.count()
|
|
|
- res = user_brand_queryset[(page - 1) * line:page * line]
|
|
|
- send_json = CommonService.qs_to_dict(res)
|
|
|
- for k, v in enumerate(send_json["datas"]):
|
|
|
- username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
|
|
|
- send_json["datas"][k]['fields']['username']=username
|
|
|
- send_json['count'] = count
|
|
|
- return response.json(0, {'datas': send_jsons, 'count': counts})
|
|
|
- return response.json(0, {'datas': [], 'count': 0})
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
+
|
|
|
+
|
|
|
+ def query_deviceSupplier_info(self, request_dict, userID,response):
|
|
|
+ check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ if check_perm is True:
|
|
|
+ # 按照用户去重复查询
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
|
|
|
+ print (user_brand_queryset)
|
|
|
+ send_jsons=[]
|
|
|
+ counts=0
|
|
|
+ for i in user_brand_queryset:
|
|
|
+ counts=counts+1
|
|
|
+ user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
+ user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
+ username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
+ user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
+ send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
+ deviceSupplier=[]
|
|
|
+ for k, v in enumerate(send_jsons):
|
|
|
+ deviceSupplier.append(v['fields']['deviceSupplier'])
|
|
|
+ deviceSupplier = Counter(deviceSupplier)
|
|
|
+ return response.json(0, {'datas': deviceSupplier})
|
|
|
+
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|