|
@@ -9,10 +9,12 @@ from django.utils.timezone import utc
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
|
-from Ansjer.config import SERVER_DOMAIN, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
+from Ansjer.config import SERVER_DOMAIN, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, \
|
|
|
+ AWS_SECRET_ACCESS_KEY, AWS_SES_ACCESS_REGION
|
|
|
from Controller.CheckUserData import DataValid, RandomStr
|
|
|
from Model.models import Device_User, Role, UserExModel, CountryModel, MenuModel, FeedBackModel, StatResModel, \
|
|
|
SysMassModel, App_Info, SysMsgModel, DeviceSuperPassword, CustomizedPush, DeviceTypeModel
|
|
|
+from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -312,6 +314,8 @@ class UserManagement(View):
|
|
|
# 定制推送
|
|
|
elif operation == 'getCustomizedPushList': # 查询定制推送列表
|
|
|
return self.getCustomizedPushList(request_dict, response)
|
|
|
+ elif operation == 'addOrEditCustomizedPush': # 新增/编辑推送内容
|
|
|
+ return self.addOrEditCustomizedPush(request, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -927,6 +931,65 @@ class UserManagement(View):
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def addOrEditCustomizedPush(request, request_dict, response):
|
|
|
+ title = request_dict.get('title', None)
|
|
|
+ msg = request_dict.get('msg', None)
|
|
|
+ link = request_dict.get('link', None)
|
|
|
+ icon = request.FILES.get('icon', None)
|
|
|
+ country = request_dict.get('country', None)
|
|
|
+ device_type = request_dict.get('deviceType', None)
|
|
|
+ register_period = request_dict.get('registerPeriod', None)
|
|
|
+ time_zone = request_dict.get('timeZone', None)
|
|
|
+ push_time = request_dict.get('pushTime', None)
|
|
|
+ push_app = request_dict.get('pushApp', None)
|
|
|
+ is_edit = request_dict.get('isEdit', None)
|
|
|
+
|
|
|
+ if not all([title, msg, link, country, device_type, register_period, time_zone, push_time, push_app]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ customized_push_data = {
|
|
|
+ 'title': title,
|
|
|
+ 'msg': msg,
|
|
|
+ 'link': link,
|
|
|
+ 'country': country,
|
|
|
+ 'device_type': device_type,
|
|
|
+ 'register_period': register_period,
|
|
|
+ 'time_zone': time_zone,
|
|
|
+ 'push_time': push_time,
|
|
|
+ 'push_app': push_app
|
|
|
+ }
|
|
|
+ icon_link = ''
|
|
|
+ if icon is not None:
|
|
|
+ icon_name = icon.name
|
|
|
+ icon_link = 'https://ansjerfilemanager.s3.amazonaws.com/customized-push/' + icon_name
|
|
|
+ customized_push_data['icon_link'] = icon_link
|
|
|
+
|
|
|
+ if icon_link:
|
|
|
+ # 上传没有上传过的图片到S3
|
|
|
+ customized_push_qs = CustomizedPush.objects.filter(icon_link=icon_link)
|
|
|
+ if not customized_push_qs.exists():
|
|
|
+ bucket = 'ansjerfilemanager'
|
|
|
+ file_key = 'customized-push/' + icon_name
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ s3.upload_file_obj(
|
|
|
+ bucket,
|
|
|
+ file_key,
|
|
|
+ icon,
|
|
|
+ {'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
+
|
|
|
+ if is_edit: # 编辑
|
|
|
+ customized_push_id = request_dict.get('customizedPushId', None)
|
|
|
+ if not customized_push_id:
|
|
|
+ return response.json(444)
|
|
|
+ CustomizedPush.objects.filter(id=customized_push_id).update(**customized_push_data)
|
|
|
+ else: # 新增
|
|
|
+ CustomizedPush.objects.create(**customized_push_data)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
@staticmethod
|
|
|
def getCountryList(response):
|
|
|
try:
|