|
@@ -5,20 +5,19 @@
|
|
|
# @Time : 2022/3/9 9:20
|
|
|
# @Author : ming
|
|
|
# @Email : zhangdongming@asj6.wecom.work
|
|
|
-# @File : SurveysController.py
|
|
|
+# @File : SurveysManageController.py
|
|
|
# @Software: PyCharm
|
|
|
-import time
|
|
|
import json
|
|
|
-from django.db.models import Count
|
|
|
+import time
|
|
|
+
|
|
|
+from django.db import connection
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic.base import View
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
+
|
|
|
+from Model.models import Surveys, SurveysTitle, CloudVodSurveysAnswer, Device_User, SurveysUserLog
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
-from Model.models import Surveys, SurveysTitle, Order_Model, CloudVodSurveysAnswer, Device_User, SurveysUserLog
|
|
|
-from Service.CommonService import CommonService
|
|
|
-import logging
|
|
|
-from django.db import connection
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
|
|
|
|
|
|
class SurveysView(View):
|
|
@@ -37,20 +36,10 @@ class SurveysView(View):
|
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
- logger = logging.getLogger('info')
|
|
|
token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
response = ResponseObject()
|
|
|
if token.code != 0:
|
|
|
return response.json(token.code)
|
|
|
- userID = token.userID
|
|
|
-
|
|
|
- ''' API '''
|
|
|
- logger.info('---- this user id:{},dict{}'.format(userID, request_dict))
|
|
|
- if operation == 'get/info':
|
|
|
- return self.check_stock_user(userID, request_dict, response)
|
|
|
- if operation == 'cloud/answer/save':
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
- return self.answer_save(userID, ip, request_dict, response)
|
|
|
|
|
|
''' 后台管理'''
|
|
|
response = ResponseObject(returntype='pc')
|
|
@@ -74,88 +63,8 @@ class SurveysView(View):
|
|
|
return self.cloud_storage_user_log_page(request_dict, response)
|
|
|
return response.json(0)
|
|
|
|
|
|
- def check_stock_user(self, user_id, request_dict, response):
|
|
|
- order = Order_Model.objects.filter(userID=user_id, status=1, order_type=0)
|
|
|
- if order.count() == 0:
|
|
|
- return response.json(10030)
|
|
|
- try:
|
|
|
- no = '01'
|
|
|
- surveys = Surveys.objects.filter(no=no, user_type=1)
|
|
|
- if not all(surveys):
|
|
|
- return response.json(173)
|
|
|
- result = surveys[0]
|
|
|
- surveys_title = SurveysTitle.objects.filter(surveys_id=result.id).order_by('-created_time')
|
|
|
-
|
|
|
- submit = 0
|
|
|
- if surveys_title.exists():
|
|
|
- surveys_title = surveys_title[0]
|
|
|
- cloud_vod = CloudVodSurveysAnswer.objects.filter(title_id=surveys_title.id, user_id=user_id)
|
|
|
- if cloud_vod.exists():
|
|
|
- submit = 1
|
|
|
- data = {
|
|
|
- 'no': result.no,
|
|
|
- 'title': 'Zosi Cloud Storage',
|
|
|
- 'imageUrl': 'https://d2cjxvw3tr9apc.cloudfront.net/app/images/ansjer-cloud-surveys.png',
|
|
|
- 'userType': result.user_type,
|
|
|
- 'startTime': result.start_time,
|
|
|
- 'endTime': result.end_time,
|
|
|
- 'isShow': result.is_show,
|
|
|
- 'isSubmit': submit,
|
|
|
- 'page': '/surveys?token=' if result.is_show == 1 else ''
|
|
|
- }
|
|
|
- status = True if submit == 1 else False
|
|
|
- self.surveys_user_log_save(status, user_id)
|
|
|
- return response.json(0, data)
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return response.json(500, repr(e))
|
|
|
-
|
|
|
- def surveys_user_log_save(self, status=False, userId='', survey_type=1):
|
|
|
- if userId:
|
|
|
- user_log = SurveysUserLog.objects.filter(user_id=userId, type=survey_type)
|
|
|
- if user_log.exists():
|
|
|
- if status and user_log[0].is_filled == 0:
|
|
|
- user_log.update(is_filled=1)
|
|
|
- else:
|
|
|
- createdTime = int(time.time())
|
|
|
- user_log = SurveysUserLog(user_id=userId, type=1, created_time=createdTime)
|
|
|
- user_log.save()
|
|
|
-
|
|
|
- def answer_save(self, userId, ip, request_dict, response):
|
|
|
- try:
|
|
|
- ipInfo = CommonService.getIpIpInfo(ip, "CN")
|
|
|
- country_name = ipInfo['country_name']
|
|
|
- no = request_dict.get('no', None)
|
|
|
- if not no:
|
|
|
- return response.json(10, 'no is null')
|
|
|
- survey = Surveys.objects.filter(no=no)
|
|
|
- if survey.exists():
|
|
|
- survey = survey[0]
|
|
|
- survey_title = SurveysTitle.objects.filter(surveys=survey.id)
|
|
|
- if survey_title.exists():
|
|
|
- survey_title = survey_title[0]
|
|
|
- cloud_vod = CloudVodSurveysAnswer.objects.filter(title_id=survey_title.id, user_id=userId)
|
|
|
- if cloud_vod.exists():
|
|
|
- return response.json(10, "Do not submit twice")
|
|
|
- score = request_dict.get('score', None)
|
|
|
- topicA = request_dict.get('topicA', None)
|
|
|
- topicB = request_dict.get('topicB', None)
|
|
|
- topicC = request_dict.get('topicC', None)
|
|
|
- topicD = request_dict.get('topicD', None)
|
|
|
- topicF = request_dict.get('topicF', None)
|
|
|
- createdTime = int(time.time())
|
|
|
- answer = CloudVodSurveysAnswer(title_id=survey_title.id, user_id=userId, ip=ip, answer1=int(score),
|
|
|
- answer2=topicA,
|
|
|
- answer3=topicB, answer4=topicC, answer5=topicD, answer6=topicF,
|
|
|
- created_time=createdTime, country_name=country_name)
|
|
|
- answer.save()
|
|
|
- SurveysUserLog.objects.filter(user_id=userId, type=1).update(is_filled=1)
|
|
|
- return response.json(0)
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return response.json(500, repr(e))
|
|
|
-
|
|
|
- def get_page(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def get_page(cls, request_dict, response):
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
if not all([pageNo, pageSize]):
|
|
@@ -186,7 +95,8 @@ class SurveysView(View):
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- def save(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def save(cls, request_dict, response):
|
|
|
no = request_dict.get('no', None)
|
|
|
if no:
|
|
|
if Surveys.objects.filter(no=no).exists():
|
|
@@ -208,7 +118,8 @@ class SurveysView(View):
|
|
|
return response.json(500, repr(e))
|
|
|
return response.json(0)
|
|
|
|
|
|
- def edit(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def edit(cls, request_dict, response):
|
|
|
sur_id = request_dict.get('id', None)
|
|
|
if not sur_id:
|
|
|
return response.json(10, 'id不存在')
|
|
@@ -224,14 +135,16 @@ class SurveysView(View):
|
|
|
is_show=int(isShow))
|
|
|
return response.json(0)
|
|
|
|
|
|
- def delete(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def delete(cls, request_dict, response):
|
|
|
sId = request_dict.get('id', None)
|
|
|
if not sId:
|
|
|
return response.json(10, 'id不存在')
|
|
|
Surveys.objects.filter(id=sId).delete()
|
|
|
response.json(0)
|
|
|
|
|
|
- def title_save(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def title_save(cls, request_dict, response):
|
|
|
surveyId = request_dict.get('surveyId', None)
|
|
|
if not surveyId:
|
|
|
return response(10, 'surveyId is null')
|
|
@@ -243,15 +156,15 @@ class SurveysView(View):
|
|
|
if title.exists():
|
|
|
title.update(title_content=content)
|
|
|
else:
|
|
|
- surveys_title = SurveysTitle(surveys_id=surveyId, title_content=content
|
|
|
- , created_time=createdTime)
|
|
|
+ surveys_title = SurveysTitle(surveys_id=surveyId, title_content=content, created_time=createdTime)
|
|
|
surveys_title.save()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- def get_title_list(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def get_title_list(cls, request_dict, response):
|
|
|
surveyId = request_dict.get('surveyId', None)
|
|
|
info = request_dict.get('info', None)
|
|
|
if not surveyId:
|
|
@@ -267,7 +180,8 @@ class SurveysView(View):
|
|
|
data = json.loads(content.title_content)
|
|
|
return response.json(0, {'answers': data})
|
|
|
|
|
|
- def title_edit(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def title_edit(cls, request_dict, response):
|
|
|
title_id = request_dict.get('id', None)
|
|
|
if not title_id:
|
|
|
return response.json(10, 'id不存在')
|
|
@@ -276,14 +190,16 @@ class SurveysView(View):
|
|
|
surveys_title.update(title_content=content)
|
|
|
return response.json(0)
|
|
|
|
|
|
- def title_del(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def title_del(cls, request_dict, response):
|
|
|
title_id = request_dict.get('id', None)
|
|
|
if not title_id:
|
|
|
return response.json(10, 'id不存在')
|
|
|
SurveysTitle.objects.filter(id=title_id).delete()
|
|
|
return response.json(0)
|
|
|
|
|
|
- def cloud_surveys_answer_page(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def cloud_surveys_answer_page(cls, request_dict, response):
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
userName = request_dict.get('userName', None)
|
|
@@ -354,7 +270,8 @@ class SurveysView(View):
|
|
|
|
|
|
''' 云存用户问卷调查统计 '''
|
|
|
|
|
|
- def cloud_storage_user_log_page(self, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def cloud_storage_user_log_page(cls, request_dict, response):
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
if not all([pageNo, pageSize]):
|