V1.0版本基本完成

main
RogerWork 11 months ago
parent 8a442be939
commit e327669ade
  1. 18
      mock/migrations/0004_zzmockmodel_errorcode.py
  2. 30
      mock/mock_templates/valid_error_tmp.py
  3. 2
      mock/models.py
  4. 1
      mock/urls.py
  5. 5
      mock/utils/mock_service.py
  6. 15
      mock/views.py
  7. 5
      update/utils/get_version.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='清洗错误接口返回的错误状态'),
),
]

@ -1,3 +1,31 @@
def get():
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

@ -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

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

@ -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})

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

@ -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')

Loading…
Cancel
Save