From e327669adedc0af4bdf37555b47cbed8f26e0ab7 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Tue, 2 Jan 2024 10:24:52 +0800 Subject: [PATCH] =?UTF-8?q?V1.0=E7=89=88=E6=9C=AC=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/migrations/0004_zzmockmodel_errorcode.py | 18 +++++++++++ mock/mock_templates/valid_error_tmp.py | 32 +++++++++++++++++-- mock/models.py | 2 ++ mock/urls.py | 1 + mock/utils/mock_service.py | 5 ++- mock/views.py | 19 +++++++++-- update/utils/get_version.py | 5 ++- 7 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 mock/migrations/0004_zzmockmodel_errorcode.py diff --git a/mock/migrations/0004_zzmockmodel_errorcode.py b/mock/migrations/0004_zzmockmodel_errorcode.py new file mode 100644 index 0000000..61ea4fa --- /dev/null +++ b/mock/migrations/0004_zzmockmodel_errorcode.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-01-02 01:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mock', '0003_rename_auditsessioncode_zzmockmodel_auditshowid'), + ] + + operations = [ + migrations.AddField( + model_name='zzmockmodel', + name='errorCode', + field=models.CharField(help_text='清洗错误接口返回的错误状态', max_length=5, null=True, verbose_name='清洗错误接口返回的错误状态'), + ), + ] diff --git a/mock/mock_templates/valid_error_tmp.py b/mock/mock_templates/valid_error_tmp.py index 4653798..18eac11 100644 --- a/mock/mock_templates/valid_error_tmp.py +++ b/mock/mock_templates/valid_error_tmp.py @@ -1,3 +1,31 @@ -def get(): - mock_data = {'message': '操作成功', 'data': [], 'code': '200', 'status': 'success'} +import json +import datetime +from mock.models import ZZMockModel + + +def get_json(): + return {'message': '操作成功', 'data': [], 'code': '200', 'status': 'success'} + + +def get(cinema_data, request): + error_code_config = ZZMockModel.objects.filter(ip=cinema_data.ip).first() + error_code = error_code_config.errorCode + print(request.POST) + data = json.loads(request.POST['queries']) + if error_code == '0': + mock_data = {'message': '操作成功', 'data': [], 'code': '200', 'status': 'success'} + else: + data_list = [] + for ticket in data: + date_time = datetime.datetime.strptime(ticket['sessionDatetime'], '%Y-%m-%d %H:%M:%S') + date = datetime.datetime.strftime(date_time, '%Y-%m-%d') + data_list.append( + { + 'businessDate': date, + 'sendChannelCode': '96201703', + 'ticketNo': ticket['ticketNo'], + 'errorType': error_code + } + ) + mock_data = {'message': '操作成功', 'data': data_list, 'code': '200', 'status': 'success'} return mock_data diff --git a/mock/models.py b/mock/models.py index 57d126e..9a375f2 100644 --- a/mock/models.py +++ b/mock/models.py @@ -19,6 +19,8 @@ class ZZMockModel(models.Model): help_text='需要审核的过场场次编码') auditStatus = models.CharField(verbose_name='需要审核的过场场次状态', null=True, max_length=3, help_text='需要审核的过场场次状态') + errorCode = models.CharField(verbose_name='清洗错误接口返回的错误状态', null=True, max_length=5, + help_text='清洗错误接口返回的错误状态') def __str__(self): return self.ip diff --git a/mock/urls.py b/mock/urls.py index 5e66655..1e73a2d 100644 --- a/mock/urls.py +++ b/mock/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ path('api/get_overtime_show', get_overtime_show), path('api/get_response_json', get_response), path('api/set_overtime_config', set_overtime_config), + path('api/set_error_code_config', set_error_code_config), path('api/start_mock', enable_mock), path('api/end_mock', disable_mock) ] diff --git a/mock/utils/mock_service.py b/mock/utils/mock_service.py index 420ce73..e181902 100644 --- a/mock/utils/mock_service.py +++ b/mock/utils/mock_service.py @@ -37,7 +37,10 @@ def mock(_ip, _api, **kwargs): else: return bypass(kwargs.get('request')) if _api == 'validError': - mock_data = valid_error_tmp.get() + if kwargs.get('type') == 'getJson': + mock_data = valid_error_tmp.get_json() + else: + mock_data = valid_error_tmp.get(cinema_obj, kwargs.get('request')) return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) diff --git a/mock/views.py b/mock/views.py index 7da3f48..26c9f90 100644 --- a/mock/views.py +++ b/mock/views.py @@ -126,13 +126,15 @@ def get_overtime_ticket_status(request): # 数据查询 # 2、数据清洗错误查询接口 POST /query/validError +@csrf_exempt def valid_error(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.validError is True: - if customer_json := json_data.get('validError'): - return JsonResponse(customer_json, json_dumps_params={'ensure_ascii': False}) - return mock_service.mock(ip, 'validError') + if mock_service_switch.errorCode == '0': + if customer_json := json_data.get('validError'): + return JsonResponse(customer_json, json_dumps_params={'ensure_ascii': False}) + return mock_service.mock(ip, 'validError', request=request) else: return mock_service.bypass(request) @@ -201,6 +203,8 @@ def get_response(request): _api = api_dict[_api] if _api == 'getOvertimeTicketStatus': req = mock_service.mock(_ip, _api, request=request, type='getJson') + elif _api == 'validError': + req = mock_service.mock(_ip, _api, request=request, type='getJson') else: req = mock_service.mock(_ip, _api) return req @@ -237,6 +241,15 @@ def set_overtime_config(request): return JsonResponse({'success': True}) +# 设置验票接口的状态 +def set_error_code_config(request): + ip = request.GET.dict().get('ip') + cinema = ZZMockModel.objects.filter(ip=ip).first() + cinema.errorCode = request.GET.dict().get('error_code') + cinema.save() + return JsonResponse({'success': True}) + + # 启动mock @csrf_exempt def enable_mock(request): diff --git a/update/utils/get_version.py b/update/utils/get_version.py index 9867b1f..520c726 100644 --- a/update/utils/get_version.py +++ b/update/utils/get_version.py @@ -51,7 +51,7 @@ class GetVersion(object): return else: cinema_config = q.get() - sql_str = "SELECT * FROM cinema_version;" + sql_str = "SELECT cs.cinema_id, cs.cinema_name, cs.cinema_num, cv.server_version, cv.client_version FROM cinema_set cs LEFT JOIN cinema_version cv ON 1=1;;" ip = cinema_config.get('ip') db_config = { 'host': ip, @@ -65,6 +65,9 @@ class GetVersion(object): db_cursor.execute(sql_str) res = db_cursor.fetchone() update_data = { + 'name': res['cinema_name'], + 'zz_num': res['cinema_num'], + 'inner_id': res['cinema_id'], 'sys_ver': res['server_version'], 'client_ver': res['client_version'], # 'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')