Эх сурвалжийг харах

修改问卷调查目录代码结构

zhangdongming 3 жил өмнө
parent
commit
51cdcf5386

+ 28 - 111
Controller/SurveysController.py → AdminController/SurveysManageController.py

@@ -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]):

+ 5 - 4
Ansjer/urls.py

@@ -19,10 +19,11 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     OrderTaskController, HistoryUIDController, UIDManageUserController, SerialNumberController, CompanyController, \
     RegionController, VPGController, LanguageController, TestController, DeviceConfirmRegion, S3GetStsController, \
     DetectControllerV2, ShadowController, TestDetectController, PcInfo, PctestController, DeviceDebug, PaymentCycle, \
-    DeviceLogController, CouponController, AiController, SurveysController
+    DeviceLogController, CouponController, AiController
+from Controller.Surveys import CloudStorageController
 from AdminController import UserManageController, RoleController, MenuController, TestServeController, \
     ServeManagementController, LogManagementController, DeviceManagementController, VersionManagementController, \
-    AiServeController
+    AiServeController, SurveysManageController
 
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -361,7 +362,7 @@ urlpatterns = [
     re_path('deviceDebug/(?P<operation>.*)', DeviceDebug.DeviceDebug.as_view()),
 
     # 问卷调查
-    url(r'^api/surveys/(?P<operation>.*)$', SurveysController.SurveysView.as_view()),
+    url(r'^api/surveys/(?P<operation>.*)$', CloudStorageController.CloudStorageView.as_view()),
 
     # 后台界面接口 -----------------------------------------------------
     # 用户登录信息等
@@ -388,7 +389,7 @@ urlpatterns = [
     # AI服务
     re_path('aiServe/(?P<operation>.*)', AiServeController.AiServeView.as_view()),
     # 问卷调查管理
-    url(r'surveys/(?P<operation>.*)', SurveysController.SurveysView.as_view()),
+    url(r'surveys/(?P<operation>.*)', SurveysManageController.SurveysView.as_view()),
     # 后台界面接口 -----------------------------------------------------
 
     re_path('(?P<path>.*)', LogManager.errorPath),

+ 135 - 0
Controller/Surveys/CloudStorageController.py

@@ -0,0 +1,135 @@
+#!/usr/bin/python3.6
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2022 #
+# @Time    : 2022/3/24 20:09
+# @Author  : ming
+# @Email   : zhangdongming@asj6.wecom.work
+# @File    : CloudStorageController.py
+# @Software: PyCharm
+import logging
+import time
+
+from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import csrf_exempt
+from django.views.generic.base import View
+
+from Model.models import Surveys, SurveysTitle, Order_Model, CloudVodSurveysAnswer, SurveysUserLog
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+from Service.CommonService import CommonService
+
+
+class CloudStorageView(View):
+    @method_decorator(csrf_exempt)
+    def dispatch(self, *args, **kwargs):
+        return super(CloudStorageView, self).dispatch(*args, **kwargs)
+
+    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 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, response)
+        if operation == 'cloud/answer/save':
+            ip = CommonService.get_ip_address(request)
+            return self.answer_save(userID, ip, request_dict, response)
+
+    def check_stock_user(self, user_id, 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))
+
+    @classmethod
+    def surveys_user_log_save(cls, 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()
+
+    @classmethod
+    def answer_save(cls, 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))

+ 9 - 0
Controller/Surveys/__init__.py

@@ -0,0 +1,9 @@
+#!/usr/bin/python3.6
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2022 #
+# @Time    : 2022/3/24 20:06
+# @Author  : ming
+# @Email   : zhangdongming@asj6.wecom.work
+# @File    : __init__.py.py
+# @Software: PyCharm