|
@@ -11,62 +11,37 @@
|
|
@file: cloudstorage.py
|
|
@file: cloudstorage.py
|
|
@Contact: chanjunkai@163.com
|
|
@Contact: chanjunkai@163.com
|
|
"""
|
|
"""
|
|
-import base64
|
|
|
|
-import json
|
|
|
|
|
|
+import logging
|
|
import os
|
|
import os
|
|
import time
|
|
import time
|
|
-import glob
|
|
|
|
-import urllib
|
|
|
|
from urllib.parse import quote, parse_qs, unquote
|
|
from urllib.parse import quote, parse_qs, unquote
|
|
|
|
|
|
import apns2
|
|
import apns2
|
|
import boto3
|
|
import boto3
|
|
|
|
+import botocore
|
|
import jpush
|
|
import jpush
|
|
-import oss2
|
|
|
|
import paypalrestsdk
|
|
import paypalrestsdk
|
|
-import threading
|
|
|
|
-import calendar
|
|
|
|
-import datetime
|
|
|
|
-import logging
|
|
|
|
-import sys
|
|
|
|
-import requests
|
|
|
|
-from aliyunsdkcore import client
|
|
|
|
-from aliyunsdksts.request.v20150401 import AssumeRoleRequest
|
|
|
|
from boto3.session import Session
|
|
from boto3.session import Session
|
|
-from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
|
|
|
|
|
|
+from botocore import client
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
|
|
+from django.db.models import Q, F, Sum
|
|
|
|
+from django.http import HttpResponseRedirect, HttpResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
-import jwt
|
|
|
|
-from Object.ETkObject import ETkObject
|
|
|
|
from pyfcm import FCMNotification
|
|
from pyfcm import FCMNotification
|
|
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \
|
|
|
|
- SERVER_DOMAIN_SSL, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ARN, APNS_MODE, APNS_CONFIG, BASE_DIR, \
|
|
|
|
- JPUSH_CONFIG, FCM_CONFIG, OAUTH_ACCESS_TOKEN_SECRET, DETECT_PUSH_DOMAINS
|
|
|
|
-from Controller.CheckUserData import DataValid
|
|
|
|
-from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
|
|
|
|
- ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
|
|
|
|
- Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel, CouponModel, \
|
|
|
|
- AiStoreMeal, AiService, UidSetModel, Ai_Push_Info, iotdeviceInfoModel, AiProcessTime, Equipment_Info
|
|
|
|
-from Object.AWS.S3Email import S3Email
|
|
|
|
|
|
+
|
|
|
|
+from Ansjer.config import PAYPAL_CRD, \
|
|
|
|
+ SERVER_DOMAIN_SSL, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APNS_MODE, APNS_CONFIG, BASE_DIR, \
|
|
|
|
+ JPUSH_CONFIG, FCM_CONFIG, DETECT_PUSH_DOMAINS
|
|
|
|
+from Model.models import Device_Info, Order_Model, ExperienceAiModel, Pay_Type, CDKcontextModel, UidPushModel, \
|
|
|
|
+ AiStoreMeal, AiService, UidSetModel, Ai_Push_Info
|
|
from Object.AliPayObject import AliPayObject
|
|
from Object.AliPayObject import AliPayObject
|
|
-from Object.AliSmsObject import AliSmsObject
|
|
|
|
|
|
+from Object.ETkObject import ETkObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
-from Object.UidTokenObject import UidTokenObject
|
|
|
|
-from Service.CommonService import CommonService
|
|
|
|
-from Object.m3u8generate import PlaylistGenerator
|
|
|
|
from Object.WechatPayObject import WechatPayObject
|
|
from Object.WechatPayObject import WechatPayObject
|
|
-from django.db.models import Q, F, Count, Sum
|
|
|
|
-from Controller.PaymentCycle import Paypal
|
|
|
|
-from decimal import Decimal
|
|
|
|
-from Ansjer.config import SERVER_TYPE
|
|
|
|
|
|
+from Service.CommonService import CommonService
|
|
from Service.ModelService import ModelService
|
|
from Service.ModelService import ModelService
|
|
-from Object import MergePic
|
|
|
|
-import boto3
|
|
|
|
-import botocore
|
|
|
|
-from botocore import client
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
# AI服务
|
|
# AI服务
|
|
@@ -117,6 +92,8 @@ class AiView(View):
|
|
return self.do_querylist(userID, request_dict, response)
|
|
return self.do_querylist(userID, request_dict, response)
|
|
elif operation == 'getUsingPackage': # 获取当前使用的ai套餐
|
|
elif operation == 'getUsingPackage': # 获取当前使用的ai套餐
|
|
return self.getUsingPackage(request_dict, userID, response)
|
|
return self.getUsingPackage(request_dict, userID, response)
|
|
|
|
+ elif operation == 'experienceOrder': # 体验AI套餐
|
|
|
|
+ return self.experience_order(request_dict, userID, response)
|
|
else:
|
|
else:
|
|
return response.json(414)
|
|
return response.json(414)
|
|
|
|
|
|
@@ -193,17 +170,17 @@ class AiView(View):
|
|
uid_set_qs = UidSetModel.objects.create(**qs_data)
|
|
uid_set_qs = UidSetModel.objects.create(**qs_data)
|
|
uid_set_id = uid_set_qs.id
|
|
uid_set_id = uid_set_qs.id
|
|
|
|
|
|
- qs_data['detect_status'] = status # ai开关状态
|
|
|
|
|
|
+ qs_data['detect_status'] = status # ai开关状态
|
|
ai_service_qs.update(**qs_data)
|
|
ai_service_qs.update(**qs_data)
|
|
topic_name = 'ansjer/generic/{}'.format(uid)
|
|
topic_name = 'ansjer/generic/{}'.format(uid)
|
|
- if status == 0: # 关闭
|
|
|
|
|
|
+ if status == 0: # 关闭
|
|
# mqtt通知设备关闭AI识别功能
|
|
# mqtt通知设备关闭AI识别功能
|
|
msg = {'commandType': 'AIDisable'}
|
|
msg = {'commandType': 'AIDisable'}
|
|
req_success = CommonService.req_publish_mqtt_msg(uid, topic_name, msg)
|
|
req_success = CommonService.req_publish_mqtt_msg(uid, topic_name, msg)
|
|
if not req_success:
|
|
if not req_success:
|
|
return response.json(10044)
|
|
return response.json(10044)
|
|
return response.json(0)
|
|
return response.json(0)
|
|
- elif status == 1: # 开启
|
|
|
|
|
|
+ elif status == 1: # 开启
|
|
uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
|
|
uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
|
|
|
|
|
|
if uid_push_qs.exists():
|
|
if uid_push_qs.exists():
|
|
@@ -237,7 +214,8 @@ class AiView(View):
|
|
etkObj = ETkObject(etk='')
|
|
etkObj = ETkObject(etk='')
|
|
etk = etkObj.encrypt(uid)
|
|
etk = etkObj.encrypt(uid)
|
|
|
|
|
|
- aiIdentificationUrl = "{DETECT_PUSH_DOMAIN}AiService/identification".format(DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAINS)
|
|
|
|
|
|
+ aiIdentificationUrl = "{DETECT_PUSH_DOMAIN}AiService/identification".format(
|
|
|
|
+ DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAINS)
|
|
|
|
|
|
# mqtt通知设备开启AI识别功能
|
|
# mqtt通知设备开启AI识别功能
|
|
msg = {
|
|
msg = {
|
|
@@ -284,9 +262,10 @@ class AiView(View):
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
# 查询套餐数据
|
|
# 查询套餐数据
|
|
- ai_meal_qs = AiStoreMeal.objects.filter(is_show=1, lang__lang=lang).\
|
|
|
|
- annotate(ai_meal_id=F('id'), title=F('lang__title'), content=F('lang__content')).\
|
|
|
|
- values("ai_meal_id", "title", "content", "price", "effective_day", "currency", "virtual_price", "symbol")
|
|
|
|
|
|
+ ai_meal_qs = AiStoreMeal.objects.filter(is_show=1, lang__lang=lang). \
|
|
|
|
+ annotate(ai_meal_id=F('id'), title=F('lang__title'), content=F('lang__content')). \
|
|
|
|
+ values("ai_meal_id", "title", "content", "price", "effective_day", "currency", "virtual_price",
|
|
|
|
+ "symbol")
|
|
if not ai_meal_qs.exists():
|
|
if not ai_meal_qs.exists():
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
@@ -323,8 +302,10 @@ class AiView(View):
|
|
count = omqs.count()
|
|
count = omqs.count()
|
|
omqs = omqs.annotate(rank__title=F('ai_rank__lang__title'), rank__content=F('ai_rank__lang__content'),
|
|
omqs = omqs.annotate(rank__title=F('ai_rank__lang__title'), rank__content=F('ai_rank__lang__content'),
|
|
rank__day=F('ai_rank__effective_day'), rank__price=F('ai_rank__price'),
|
|
rank__day=F('ai_rank__effective_day'), rank__price=F('ai_rank__price'),
|
|
- rank__expire=F('ai_rank__effective_day'), rank__id=F('ai_rank_id'), rank__currency=F('ai_rank__currency'))
|
|
|
|
- order_ql = omqs[(page - 1) * line:page * line].values("orderID", "UID", "channel", "desc", "price", "currency",
|
|
|
|
|
|
+ rank__expire=F('ai_rank__effective_day'), rank__id=F('ai_rank_id'),
|
|
|
|
+ rank__currency=F('ai_rank__currency'))
|
|
|
|
+ order_ql = omqs[(page - 1) * line:page * line].values("orderID", "UID", "channel", "desc", "price",
|
|
|
|
+ "currency",
|
|
"addTime",
|
|
"addTime",
|
|
"updTime", "paypal", "rank__day", "payType",
|
|
"updTime", "paypal", "rank__day", "payType",
|
|
"rank__price", "status",
|
|
"rank__price", "status",
|
|
@@ -366,8 +347,10 @@ class AiView(View):
|
|
return response.json(0, [])
|
|
return response.json(0, [])
|
|
|
|
|
|
# 计算套餐过期时间
|
|
# 计算套餐过期时间
|
|
- sum_end_time = AiService.objects.filter(Q(uid=uid), ~Q(use_status=2)).aggregate(Sum('endTime'))['endTime__sum']
|
|
|
|
- ai_service_qs = ai_service_qs.order_by('addTime').annotate(bucket__content=F('orders__ai_rank__lang__title')).\
|
|
|
|
|
|
+ sum_end_time = AiService.objects.filter(Q(uid=uid), ~Q(use_status=2)).aggregate(Sum('endTime'))[
|
|
|
|
+ 'endTime__sum']
|
|
|
|
+ ai_service_qs = ai_service_qs.order_by('addTime').annotate(
|
|
|
|
+ bucket__content=F('orders__ai_rank__lang__title')). \
|
|
values('uid', 'use_status', 'bucket__content')
|
|
values('uid', 'use_status', 'bucket__content')
|
|
ai_service_data = ai_service_qs[0]
|
|
ai_service_data = ai_service_qs[0]
|
|
ai_service_data['endTime'] = sum_end_time
|
|
ai_service_data['endTime'] = sum_end_time
|
|
@@ -376,6 +359,96 @@ class AiView(View):
|
|
print(e)
|
|
print(e)
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
|
|
+ # 体验AI套餐
|
|
|
|
+ @staticmethod
|
|
|
|
+ def experience_order(request_dict, userID, response):
|
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
|
+ commodity_code = request_dict.get('commodity_code', None)
|
|
|
|
+ pay_type = int(request_dict.get('pay_type', None))
|
|
|
|
+ rank = request_dict.get('rank', None)
|
|
|
|
+ cdk = request_dict.get('cdk', None)
|
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
|
+
|
|
|
|
+ # 使用redis设置唯一key加锁
|
|
|
|
+ redisObj = RedisObject()
|
|
|
|
+ redis_key = uid + 'do_experience_ai_order'
|
|
|
|
+ isLock = redisObj.CONN.setnx(redis_key, 1)
|
|
|
|
+ redisObj.CONN.expire(redis_key, 60)
|
|
|
|
+ if not isLock:
|
|
|
|
+ return response.json(5)
|
|
|
|
+
|
|
|
|
+ if pay_type == 10: # 判断是否已体验过套餐
|
|
|
|
+ exc_ai_qs = ExperienceAiModel.objects.filter(uid=uid, experience_type=0)
|
|
|
|
+ if exc_ai_qs.exists():
|
|
|
|
+ return response.json(5)
|
|
|
|
+
|
|
|
|
+ if cdk is not None and pay_type == 11:
|
|
|
|
+ cdk_qs = CDKcontextModel.objects.filter(cdk=cdk).values('is_activate', 'rank__id', 'rank__commodity_code')
|
|
|
|
+ if not cdk_qs.exists():
|
|
|
|
+ return response.json(10040)
|
|
|
|
+ if cdk_qs[0]['is_activate'] == 1:
|
|
|
|
+ return response.json(10039)
|
|
|
|
+ rank = cdk_qs[0]['rank__id']
|
|
|
|
+ commodity_code = cdk_qs[0]['rank__commodity_code']
|
|
|
|
+
|
|
|
|
+ if uid is None or channel is None or commodity_code is None or pay_type is None or rank is None:
|
|
|
|
+ redisObj.del_data(key=redis_key)
|
|
|
|
+ return response.json(13, '参数有误.')
|
|
|
|
+
|
|
|
|
+ # 判断是否为主用户操作
|
|
|
|
+ device_info_qs = Device_Info.objects.filter(Q(UID=uid) & ~Q(vodPrimaryUserID='')).values('vodPrimaryUserID')
|
|
|
|
+ if device_info_qs.exists():
|
|
|
|
+ if device_info_qs[0]['vodPrimaryUserID'] != userID:
|
|
|
|
+ if pay_type == 10:
|
|
|
|
+ return response.json(10035)
|
|
|
|
+ if pay_type == 11:
|
|
|
|
+ return response.json(10036)
|
|
|
|
+
|
|
|
|
+ dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1)
|
|
|
|
+ if not dv_qs.exists():
|
|
|
|
+ return response.json(12)
|
|
|
|
+
|
|
|
|
+ orderID = CommonService.createOrderID()
|
|
|
|
+ nowTime = int(time.time())
|
|
|
|
+ ai_store_meal_qs = AiStoreMeal.objects.filter(id=rank, lang__lang=lang, is_show=1). \
|
|
|
|
+ values('expire', 'lang__content', 'price', 'currency', 'effective_day')
|
|
|
|
+ if not ai_store_meal_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+
|
|
|
|
+ effective_day = ai_store_meal_qs[0]['effective_day']
|
|
|
|
+ endTime = nowTime + effective_day * 24 * 60 * 60 # 套餐结束时间
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ # 订单表创建数据
|
|
|
|
+ Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
|
+ desc=ai_store_meal_qs[0]['lang__content'], payType=pay_type, payTime=nowTime,
|
|
|
|
+ price=ai_store_meal_qs[0]['price'], currency=ai_store_meal_qs[0]['currency'],
|
|
|
|
+ addTime=nowTime, updTime=nowTime, pay_url='AI体验',
|
|
|
|
+ commodity_code=commodity_code,
|
|
|
|
+ commodity_type=ai_store_meal_qs[0]['commodity_type'],
|
|
|
|
+ rank_id=1, ai_rank_id=rank, status=1)
|
|
|
|
+ # ai服务表创建数据
|
|
|
|
+ AiService.objects.create(uid=uid, channel=channel, orders_id=orderID, detect_status=1, endTime=endTime,
|
|
|
|
+ addTime=nowTime, updTime=nowTime, use_status=1)
|
|
|
|
+
|
|
|
|
+ if pay_type == 10:
|
|
|
|
+ ExperienceAiModel.objects.create(
|
|
|
|
+ experience_type=0,
|
|
|
|
+ uid=uid,
|
|
|
|
+ do_time=nowTime
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ elif pay_type == 11:
|
|
|
|
+ CDKcontextModel.objects.filter(cdk=cdk).update(is_activate=1, order=orderID)
|
|
|
|
+
|
|
|
|
+ redisObj.del_data(key=redis_key)
|
|
|
|
+ pay_ok_url = "{}cloudstorage/payOK?paytype={}&lang={}".format(SERVER_DOMAIN_SSL, pay_type, lang)
|
|
|
|
+ return response.json(0, pay_ok_url)
|
|
|
|
+ except Exception:
|
|
|
|
+ redisObj.del_data(key=redis_key)
|
|
|
|
+ return response.json(474)
|
|
|
|
+
|
|
def do_create_pay_order(self, request_dict, request, userID, response):
|
|
def do_create_pay_order(self, request_dict, request, userID, response):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
channel = request_dict.get('channel', None)
|
|
channel = request_dict.get('channel', None)
|
|
@@ -430,15 +503,17 @@ class AiView(View):
|
|
'order_type': 1,
|
|
'order_type': 1,
|
|
}
|
|
}
|
|
|
|
|
|
- if pay_type == 1: # PayPal支付
|
|
|
|
- order_dict['paymentID'], order_dict['pay_url'] = self.create_paypal_payment(lang, orderID, price, currency, content, response)
|
|
|
|
|
|
+ if pay_type == 1: # PayPal支付
|
|
|
|
+ order_dict['paymentID'], order_dict['pay_url'] = self.create_paypal_payment(lang, orderID, price,
|
|
|
|
+ currency, content, response)
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID}
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID}
|
|
- elif pay_type == 2: # 支付宝
|
|
|
|
|
|
+ elif pay_type == 2: # 支付宝
|
|
order_dict['pay_url'] = self.create_alipay_payment(lang, orderID, price, title, content, response)
|
|
order_dict['pay_url'] = self.create_alipay_payment(lang, orderID, price, title, content, response)
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID}
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID}
|
|
- elif pay_type == 3: # 微信支付
|
|
|
|
|
|
+ elif pay_type == 3: # 微信支付
|
|
ip = CommonService.get_ip_address(request)
|
|
ip = CommonService.get_ip_address(request)
|
|
- order_dict['pay_url'], sign_params = self.create_wechat_payment(lang, orderID, price, ip, content, response)
|
|
|
|
|
|
+ order_dict['pay_url'], sign_params = self.create_wechat_payment(lang, orderID, price, ip, content,
|
|
|
|
+ response)
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID, 'result': sign_params}
|
|
res_data = {'redirectUrl': order_dict['pay_url'], 'orderID': orderID, 'result': sign_params}
|
|
else:
|
|
else:
|
|
return response.json(444, {'param': 'pay_type'})
|
|
return response.json(444, {'param': 'pay_type'})
|
|
@@ -591,8 +666,8 @@ class AiView(View):
|
|
attach = data["attach"]
|
|
attach = data["attach"]
|
|
parmap = dict([(k, v[0]) for k, v in parse_qs(unquote(attach)).items()])
|
|
parmap = dict([(k, v[0]) for k, v in parse_qs(unquote(attach)).items()])
|
|
lang = parmap['lang']
|
|
lang = parmap['lang']
|
|
- trade_status = data['result_code'] # 业务结果 SUCCESS/FAIL
|
|
|
|
- orderID = data['out_trade_no'] # 商户订单号
|
|
|
|
|
|
+ trade_status = data['result_code'] # 业务结果 SUCCESS/FAIL
|
|
|
|
+ orderID = data['out_trade_no'] # 商户订单号
|
|
order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
if not order_qs.exists():
|
|
if not order_qs.exists():
|
|
return response.json(173)
|
|
return response.json(173)
|
|
@@ -634,7 +709,6 @@ class AiView(View):
|
|
'detect_status': 1,
|
|
'detect_status': 1,
|
|
'addTime': nowTime,
|
|
'addTime': nowTime,
|
|
'updTime': nowTime,
|
|
'updTime': nowTime,
|
|
- 'detect_group': '1'
|
|
|
|
}
|
|
}
|
|
if ai_service_qs.exists(): # 有正在使用的套餐,套餐结束时间保存为套餐有效期
|
|
if ai_service_qs.exists(): # 有正在使用的套餐,套餐结束时间保存为套餐有效期
|
|
ai_service_dict['endTime'] = effective_day * 24 * 60 * 60
|
|
ai_service_dict['endTime'] = effective_day * 24 * 60 * 60
|
|
@@ -672,13 +746,13 @@ class AiView(View):
|
|
'2': ['Dog', 'Pet', 'Canine', 'Animal', 'Puppy'], # 动物
|
|
'2': ['Dog', 'Pet', 'Canine', 'Animal', 'Puppy'], # 动物
|
|
'3': ['Car', 'Vehicle', 'Transportation', 'Automobile'] # 车
|
|
'3': ['Car', 'Vehicle', 'Transportation', 'Automobile'] # 车
|
|
}
|
|
}
|
|
- #找出识别的所有标签
|
|
|
|
|
|
+ # 找出识别的所有标签
|
|
for label in labels:
|
|
for label in labels:
|
|
label_name.append(label['Name'])
|
|
label_name.append(label['Name'])
|
|
for Parents in label['Parents']:
|
|
for Parents in label['Parents']:
|
|
label_name.append(Parents['Name'])
|
|
label_name.append(Parents['Name'])
|
|
|
|
|
|
- #删除用户没有选择的ai识别类型, 并且得出最终识别结果
|
|
|
|
|
|
+ # 删除用户没有选择的ai识别类型, 并且得出最终识别结果
|
|
user_detect_list = user_detect_group.split(',')
|
|
user_detect_list = user_detect_group.split(',')
|
|
user_detect_list = [i.strip() for i in user_detect_list]
|
|
user_detect_list = [i.strip() for i in user_detect_list]
|
|
label_result_list = []
|
|
label_result_list = []
|
|
@@ -690,56 +764,56 @@ class AiView(View):
|
|
if label in label_name:
|
|
if label in label_name:
|
|
label_result_list.append(label)
|
|
label_result_list.append(label)
|
|
|
|
|
|
- #找出标签边框线位置信息
|
|
|
|
|
|
+ # 找出标签边框线位置信息
|
|
boundingBoxList = []
|
|
boundingBoxList = []
|
|
for label in labels:
|
|
for label in labels:
|
|
if label['Name'] in label_result_list:
|
|
if label['Name'] in label_result_list:
|
|
for boundingBox in label['Instances']:
|
|
for boundingBox in label['Instances']:
|
|
boundingBoxList.append(boundingBox['BoundingBox'])
|
|
boundingBoxList.append(boundingBox['BoundingBox'])
|
|
|
|
|
|
- #找出边框位置信息对应的单图位置并重新计算位置比
|
|
|
|
|
|
+ # 找出边框位置信息对应的单图位置并重新计算位置比
|
|
merge_image_height = image_size['height']
|
|
merge_image_height = image_size['height']
|
|
merge_image_width = image_size['width']
|
|
merge_image_width = image_size['width']
|
|
- single_height = merge_image_height//image_size['num']
|
|
|
|
|
|
+ single_height = merge_image_height // image_size['num']
|
|
new_bounding_box_dict = {}
|
|
new_bounding_box_dict = {}
|
|
- new_bounding_box_dict[n_time+'_0'] = []
|
|
|
|
- new_bounding_box_dict[n_time+'_1'] = []
|
|
|
|
- new_bounding_box_dict[n_time+'_2'] = []
|
|
|
|
- new_bounding_box_dict[n_time+'_3'] = []
|
|
|
|
|
|
+ new_bounding_box_dict[n_time + '_0'] = []
|
|
|
|
+ new_bounding_box_dict[n_time + '_1'] = []
|
|
|
|
+ new_bounding_box_dict[n_time + '_2'] = []
|
|
|
|
+ new_bounding_box_dict[n_time + '_3'] = []
|
|
for k, val in enumerate(boundingBoxList):
|
|
for k, val in enumerate(boundingBoxList):
|
|
boundingBoxTop = merge_image_height * val['Top']
|
|
boundingBoxTop = merge_image_height * val['Top']
|
|
- #找出当前边框属于哪张图片范围
|
|
|
|
|
|
+ # 找出当前边框属于哪张图片范围
|
|
boxDict = {}
|
|
boxDict = {}
|
|
for i in range(image_size['num']):
|
|
for i in range(image_size['num']):
|
|
- min = i*single_height #第n张图
|
|
|
|
- max = (i+1)*single_height
|
|
|
|
|
|
+ min = i * single_height # 第n张图
|
|
|
|
+ max = (i + 1) * single_height
|
|
if boundingBoxTop >= min and boundingBoxTop <= max:
|
|
if boundingBoxTop >= min and boundingBoxTop <= max:
|
|
# print("属于第{i}张图".format(i=i+1))
|
|
# print("属于第{i}张图".format(i=i+1))
|
|
boxDict['Width'] = val['Width']
|
|
boxDict['Width'] = val['Width']
|
|
- boxDict['Height'] = merge_image_height*val['Height']/single_height
|
|
|
|
- boxDict['Top'] = ((merge_image_height*val['Top'])-(i*single_height))/single_height #减去前i张图片的高度
|
|
|
|
|
|
+ boxDict['Height'] = merge_image_height * val['Height'] / single_height
|
|
|
|
+ boxDict['Top'] = ((merge_image_height * val['Top']) - (
|
|
|
|
+ i * single_height)) / single_height # 减去前i张图片的高度
|
|
boxDict['Left'] = val['Left']
|
|
boxDict['Left'] = val['Left']
|
|
- boxDict['picName'] = "{n_time}_{i}".format(n_time=n_time,i=i)
|
|
|
|
|
|
+ boxDict['picName'] = "{n_time}_{i}".format(n_time=n_time, i=i)
|
|
# new_bounding_box_list.append(boxDict)
|
|
# new_bounding_box_list.append(boxDict)
|
|
# new_bounding_box_list.append(boxDict)
|
|
# new_bounding_box_list.append(boxDict)
|
|
- new_bounding_box_dict["{n_time}_{i}".format(n_time=n_time,i=i)].append(boxDict)
|
|
|
|
|
|
+ new_bounding_box_dict["{n_time}_{i}".format(n_time=n_time, i=i)].append(boxDict)
|
|
# exit(new_bounding_box_list)
|
|
# exit(new_bounding_box_list)
|
|
user_labels_list = list(new_labels_type.keys())
|
|
user_labels_list = list(new_labels_type.keys())
|
|
user_labels_list.sort()
|
|
user_labels_list.sort()
|
|
return {'label_type': user_labels_list, 'label_list': label_result_list,
|
|
return {'label_type': user_labels_list, 'label_list': label_result_list,
|
|
- 'new_bounding_box_dict':new_bounding_box_dict}
|
|
|
|
-
|
|
|
|
|
|
+ 'new_bounding_box_dict': new_bounding_box_dict}
|
|
|
|
|
|
def upload_s3(self, file_path, upload_path):
|
|
def upload_s3(self, file_path, upload_path):
|
|
try:
|
|
try:
|
|
- aws_key = "AKIA2E67UIMD45Y3HL53" #【你的 aws_access_key】
|
|
|
|
- aws_secret = "ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw" # 【你的 aws_secret_key】
|
|
|
|
|
|
+ aws_key = "AKIA2E67UIMD45Y3HL53" # 【你的 aws_access_key】
|
|
|
|
+ aws_secret = "ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw" # 【你的 aws_secret_key】
|
|
session = Session(aws_access_key_id=aws_key,
|
|
session = Session(aws_access_key_id=aws_key,
|
|
aws_secret_access_key=aws_secret,
|
|
aws_secret_access_key=aws_secret,
|
|
region_name="us-east-1")
|
|
region_name="us-east-1")
|
|
s3 = session.resource("s3")
|
|
s3 = session.resource("s3")
|
|
# client = session.client("s3")
|
|
# client = session.client("s3")
|
|
- bucket = "foreignpush" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
|
|
|
|
|
|
+ bucket = "foreignpush" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
|
|
upload_data = open(file_path, "rb")
|
|
upload_data = open(file_path, "rb")
|
|
# upload_key = "test"
|
|
# upload_key = "test"
|
|
s3.Bucket(bucket).put_object(Key=upload_path, Body=upload_data)
|
|
s3.Bucket(bucket).put_object(Key=upload_path, Body=upload_data)
|
|
@@ -768,7 +842,7 @@ class AiView(View):
|
|
return nickname
|
|
return nickname
|
|
|
|
|
|
def get_msg_text(self, channel, n_time, lang, tz, label_list):
|
|
def get_msg_text(self, channel, n_time, lang, tz, label_list):
|
|
- n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
|
|
|
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
|
|
if lang == 'cn':
|
|
if lang == 'cn':
|
|
msg = '摄像头AI识别到了{}'.format(label_list)
|
|
msg = '摄像头AI识别到了{}'.format(label_list)
|
|
send_text = '{msg} 通道:{channel} 日期:{date}'.format(msg=msg, channel=channel, date=n_date)
|
|
send_text = '{msg} 通道:{channel} 日期:{date}'.format(msg=msg, channel=channel, date=n_date)
|
|
@@ -815,7 +889,6 @@ class AiView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return 'serverKey abnormal'
|
|
return 'serverKey abnormal'
|
|
|
|
|
|
-
|
|
|
|
def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
logger = logging.getLogger('info')
|
|
logger = logging.getLogger('info')
|
|
logger.info("进来do_apns函数了")
|
|
logger.info("进来do_apns函数了")
|
|
@@ -823,7 +896,8 @@ class AiView(View):
|
|
logger.info(APNS_MODE)
|
|
logger.info(APNS_MODE)
|
|
logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
try:
|
|
try:
|
|
- cli = apns2.APNSClient(mode=APNS_MODE, client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
|
|
|
|
+ cli = apns2.APNSClient(mode=APNS_MODE,
|
|
|
|
+ client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
"received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
|
|
"received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
|
|
alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
|
|
alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
|
|
@@ -854,7 +928,7 @@ class AiView(View):
|
|
eventType = request_dict.get('eventType', None)
|
|
eventType = request_dict.get('eventType', None)
|
|
|
|
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
- seven_days_ago = now_time - 7 * 24 * 3600 # 查询7天内的数据
|
|
|
|
|
|
+ seven_days_ago = now_time - 7 * 24 * 3600 # 查询7天内的数据
|
|
qs = Ai_Push_Info.objects.filter(userID_id=userID, eventTime__gt=seven_days_ago).order_by('-eventTime')
|
|
qs = Ai_Push_Info.objects.filter(userID_id=userID, eventTime__gt=seven_days_ago).order_by('-eventTime')
|
|
|
|
|
|
if startTime and endTime:
|
|
if startTime and endTime:
|
|
@@ -903,17 +977,17 @@ class AiView(View):
|
|
s3_img_cover = '{uid}/{channel}/cover{time}.jpg'.format(uid=devUid, channel=channel, time=eventTime)
|
|
s3_img_cover = '{uid}/{channel}/cover{time}.jpg'.format(uid=devUid, channel=channel, time=eventTime)
|
|
s3_img_desc = '{uid}/{channel}/desc{time}.jpg'.format(uid=devUid, channel=channel, time=eventTime)
|
|
s3_img_desc = '{uid}/{channel}/desc{time}.jpg'.format(uid=devUid, channel=channel, time=eventTime)
|
|
response_url_cover = aws_s3_client.generate_presigned_url('get_object',
|
|
response_url_cover = aws_s3_client.generate_presigned_url('get_object',
|
|
- ExpiresIn=300,
|
|
|
|
- Params={
|
|
|
|
- 'Bucket': 'aipush', 'Key': s3_img_cover
|
|
|
|
- },
|
|
|
|
- )
|
|
|
|
- response_url_desc = aws_s3_client.generate_presigned_url('get_object',
|
|
|
|
ExpiresIn=300,
|
|
ExpiresIn=300,
|
|
Params={
|
|
Params={
|
|
- 'Bucket': 'aipush', 'Key': s3_img_desc
|
|
|
|
|
|
+ 'Bucket': 'aipush', 'Key': s3_img_cover
|
|
},
|
|
},
|
|
)
|
|
)
|
|
|
|
+ response_url_desc = aws_s3_client.generate_presigned_url('get_object',
|
|
|
|
+ ExpiresIn=300,
|
|
|
|
+ Params={
|
|
|
|
+ 'Bucket': 'aipush', 'Key': s3_img_desc
|
|
|
|
+ },
|
|
|
|
+ )
|
|
p['img'] = response_url_cover
|
|
p['img'] = response_url_cover
|
|
p['img_list'] = [response_url_desc]
|
|
p['img_list'] = [response_url_desc]
|
|
|
|
|
|
@@ -923,13 +997,14 @@ class AiView(View):
|
|
# 列表装载回放时间戳标记
|
|
# 列表装载回放时间戳标记
|
|
p['img_list'] = []
|
|
p['img_list'] = []
|
|
for i in range(4):
|
|
for i in range(4):
|
|
- thumbspng = '{uid}/{channel}/{time}_{st}.jpg'.format(uid=devUid, channel=p['Channel'], time=eventTime, st=i)
|
|
|
|
|
|
+ thumbspng = '{uid}/{channel}/{time}_{st}.jpg'.format(uid=devUid, channel=p['Channel'],
|
|
|
|
+ time=eventTime, st=i)
|
|
response_url = aws_s3_client.generate_presigned_url('get_object',
|
|
response_url = aws_s3_client.generate_presigned_url('get_object',
|
|
- ExpiresIn=300,
|
|
|
|
- Params={
|
|
|
|
- 'Bucket': 'aipush', 'Key': thumbspng
|
|
|
|
- },
|
|
|
|
- )
|
|
|
|
|
|
+ ExpiresIn=300,
|
|
|
|
+ Params={
|
|
|
|
+ 'Bucket': 'aipush', 'Key': thumbspng
|
|
|
|
+ },
|
|
|
|
+ )
|
|
p['img_list'].append(response_url)
|
|
p['img_list'].append(response_url)
|
|
|
|
|
|
if devUid in uid_type_dict.keys():
|
|
if devUid in uid_type_dict.keys():
|
|
@@ -944,18 +1019,18 @@ class AiView(View):
|
|
is_update_all = request_dict.get('is_update_all', 0)
|
|
is_update_all = request_dict.get('is_update_all', 0)
|
|
|
|
|
|
try:
|
|
try:
|
|
- if int(is_update_all) == 1: # 全部已读
|
|
|
|
|
|
+ if int(is_update_all) == 1: # 全部已读
|
|
is_update = Ai_Push_Info.objects.filter(userID_id=userID).update(status=1)
|
|
is_update = Ai_Push_Info.objects.filter(userID_id=userID).update(status=1)
|
|
return response.json(0, {'update_count': is_update})
|
|
return response.json(0, {'update_count': is_update})
|
|
else:
|
|
else:
|
|
id_list = request_dict.get('id_list', None)
|
|
id_list = request_dict.get('id_list', None)
|
|
if not id_list:
|
|
if not id_list:
|
|
- request_dict.getlist('id_list[]', None) # 获取IOS数组传参
|
|
|
|
|
|
+ request_dict.getlist('id_list[]', None) # 获取IOS数组传参
|
|
logger = logging.getLogger('info')
|
|
logger = logging.getLogger('info')
|
|
logger.info('已读ai消息id_list:{}'.format(id_list))
|
|
logger.info('已读ai消息id_list:{}'.format(id_list))
|
|
if not id_list:
|
|
if not id_list:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
- id_list = eval(id_list) # 字符串转列表
|
|
|
|
|
|
+ id_list = eval(id_list) # 字符串转列表
|
|
param_flag = CommonService.get_param_flag(data=id_list)
|
|
param_flag = CommonService.get_param_flag(data=id_list)
|
|
if not param_flag:
|
|
if not param_flag:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
@@ -995,5 +1070,3 @@ class AiView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
-
|
|
|
|
-
|
|
|