diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index 7fde102..5a3bc25 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-hfujy!ih1uvio_p^cfdj^%8juf_wdb@szu$t=aaacd)^(zf@b% # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Application definition @@ -42,6 +42,7 @@ INSTALLED_APPS = [ 'rest_framework.authtoken', # Token验证应用 'django_filters', 'update', + 'mock', ] MIDDLEWARE = [ diff --git a/dingxin_toolbox_drf/urls.py b/dingxin_toolbox_drf/urls.py index 0699053..41b09a6 100644 --- a/dingxin_toolbox_drf/urls.py +++ b/dingxin_toolbox_drf/urls.py @@ -23,5 +23,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api-token-auth/', obtain_auth_token), path('update/', include('update.urls')), # cinema Update 备注 + path('', include('mock.urls')), path('docs/', include_docs_urls(title='接口文档')), ] diff --git a/mock/__init__.py b/mock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mock/admin.py b/mock/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/mock/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/mock/apps.py b/mock/apps.py new file mode 100644 index 0000000..04c95e2 --- /dev/null +++ b/mock/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MockConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'mock' diff --git a/mock/migrations/__init__.py b/mock/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mock/models.py b/mock/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/mock/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/mock/tests.py b/mock/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/mock/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/mock/urls.py b/mock/urls.py new file mode 100644 index 0000000..a7f36ae --- /dev/null +++ b/mock/urls.py @@ -0,0 +1,24 @@ +""" +URL configuration for dingxin_toolbox_drf project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include +from mock.views import * + +urlpatterns = [ + # path('report/reportTicket/', report_ticket), + path('data/getCinemaInfo', get_cinema_info), +] diff --git a/mock/views.py b/mock/views.py new file mode 100644 index 0000000..175c402 --- /dev/null +++ b/mock/views.py @@ -0,0 +1,27 @@ +from django.shortcuts import render +from django.http.response import JsonResponse + + +# Create your views here. + +# 1、票房数据上报接口 POST /report/reportTicket +def report_ticket(request): + if request.method == 'POST': + print(request.headers) + print(request.body) + return JsonResponse({'status': 'success'}) + + +# 数据下载 +# 1、影片信息下载接口 GET /data/downloadFilmInfo +# 2、影院信息下载接口 GET /data/getCinemaInfo +def get_cinema_info(request): + print(request.headers) + print(request.body) + if request.method == 'GET': + print('getCinemaInfo') + print(request.headers) + print(request.body) + return JsonResponse({'status': 'success'}) + +# 3、影厅信息下载接口 GET /data/getScreenInfo diff --git a/update/utils/get_version.py b/update/utils/get_version.py index 1feb34e..437d37e 100644 --- a/update/utils/get_version.py +++ b/update/utils/get_version.py @@ -4,6 +4,7 @@ from multiprocessing import cpu_count from update.models import Cinema import queue import threading +from django.utils import timezone import datetime @@ -30,19 +31,19 @@ class GetVersion(object): cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1 cinema_num = len(all_cinema_obj) self.th_num = cpu_num if cpu_num < cinema_num else cinema_num - print(self.queue) def main_process(self): print('main_process') self.get_all_cinema() - threads = [] - for i in range(self.th_num): - t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,)) - threads.append(t) - for i in range(self.th_num): - threads[i].start() - for i in range(self.th_num): - threads[i].join() + while self.queue.qsize() > 0: + threads = [] + for i in range(self.th_num): + t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,)) + threads.append(t) + for i in range(self.th_num): + threads[i].start() + for i in range(self.th_num): + threads[i].join() @staticmethod def get_cinema_ver(q): @@ -51,7 +52,6 @@ class GetVersion(object): return else: cinema_config = q.get() - print(cinema_config) sql_str = "SELECT * FROM cinema_version;" ip = cinema_config.get('ip') db_config = { @@ -61,18 +61,17 @@ class GetVersion(object): 'database': 'cine', 'connect_timeout': 5, } - print(db_config) db_conn = pymysql.Connect(**db_config) db_cursor = db_conn.cursor(cursor=DictCursor) db_cursor.execute(sql_str) res = db_cursor.fetchone() - print(res) update_data = { 'sys_ver': res['server_version'], 'client_ver': res['client_version'], - 'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') + # 'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') + 'update_time': timezone.now() } - print(update_data) + print(ip, update_data, db_config) cinema_obj = Cinema.objects.filter(ip=ip).update(**update_data) diff --git a/update/views.py b/update/views.py index 53d5e41..01bef95 100644 --- a/update/views.py +++ b/update/views.py @@ -1,6 +1,8 @@ from django.http import JsonResponse from django.db.models import Q from rest_framework import viewsets, permissions, status, filters +from rest_framework.filters import OrderingFilter + from update.models import Cinema from update.serializers import CinemaSerializer from rest_framework.views import APIView @@ -27,16 +29,18 @@ class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet): queryset = Cinema.objects.all() serializer_class = CinemaSerializer permission_classes = (permissions.IsAuthenticated,) - filter_backends = (filters.SearchFilter, DjangoFilterBackend) + filter_backends = (filters.SearchFilter, DjangoFilterBackend, OrderingFilter) + ordering_fields = ('ip', ) search_fields = ('sys_ver',) # filter_fields = ('ip',) filterset_fields = ('ip',) GetVersion().main_process() @action(methods=['get'], detail=False) + @method_decorator(cache_page(60 * 1)) def refresh(self, request, *args, **kwargs): GetVersion().main_process() - queryset = Cinema.objects.all() + queryset = Cinema.objects.all().order_by('ip') serializer = self.get_serializer(instance=queryset, many=True) return Response(serializer.data)