views.py
5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from django.shortcuts import render
from webargs import fields, validate
from webargs.djangoparser import use_args, parser
from common.mixins import GenericView
from common import response
from .models import UploadDocRecords
# Create your views here.
# restframework将request.body封装至request.data, webargs从request.data中获取参数
@parser.location_loader("data")
def load_data(request, schema):
return request.data
application_data_args = {'applicationId': fields.Str(required=True, validate=validate.Length(max=64))}
applicant_data_args = {
'mainApplicantName': fields.Str(required=True, validate=validate.Length(max=16)),
'coApplicantName': fields.Str(required=True, validate=validate.Length(max=16)),
'guarantor1Name': fields.Str(required=True, validate=validate.Length(max=16)),
'guarantor2Name': fields.Str(required=True, validate=validate.Length(max=16)),
}
document_args = {
'documentName': fields.Str(required=True, validate=validate.Length(max=255)),
'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)),
'businessType': fields.Str(required=True, validate=validate.Length(max=64)),
'uploadFinishTime': fields.DateTime(required=True),
'dataSource': fields.Str(required=True, validate=validate.Length(max=64)),
'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)),
}
doc_upload_args = {
'applicationData': fields.Nested(application_data_args, required=True),
'applicantData': fields.Nested(applicant_data_args, required=True),
'document': fields.Nested(document_args, required=True),
}
class DocView(GenericView):
permission_classes = []
# 创建模型
@use_args(doc_upload_args, location='data')
def post(self, request, args):
application_data = args.get('applicationData')
applicant_data = args.get('applicantData')
document = args.get('document')
UploadDocRecords.objects.create(
application_id=application_data.get('applicationId'),
main_applicant=applicant_data.get('mainApplicantName'),
co_applicant=applicant_data.get('coApplicantName'),
guarantor_1=applicant_data.get('guarantor1Name'),
guarantor_2=applicant_data.get('guarantor2Name'),
document_name=document.get('documentName'),
document_scheme=document.get('documentScheme'),
business_type=document.get('businessType'),
data_source=document.get('dataSource'),
metadata_version_id=document.get('metadataVersionId'),
upload_finish_time=document.get('uploadFinishTime'),
)
self.running_log.info('[doc upload success] [args={0}]'.format(args))
return response.ok()
post.openapi_doc = '''
summary: POS系统上传文件信息
tags: [POS]
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
applicationData:
description: 申请信息
type: object
properties:
applicationId:
description: 申请id
type: string
example: CH-B0011010101
applicantData:
description: 申请人信息
type: object
properties:
mainApplicantName:
description: 主申请人
type: string
example: 王明阳
coApplicantName:
description: 共同申请人
type: string
example: 王明月
guarantor1Name:
description: 担保人1
type: string
example: 王明日
guarantor2Name:
description: 担保人2
type: string
example: 王明雨
document:
description: 文件信息
type: object
properties:
documentName:
description: 文件名
type: string
example: CH-B0011010101王明阳申请表
documentScheme:
description: 文件格式?
type: string
example: CO00001
businessType:
description: 业务类型
type: string
example: HIL
uploadFinishTime:
description: 上传完成时间
type: string
example: '2020-09-01 12:21:11'
dataSource:
description: 数据源
type: string
example: POS
metadataVersionId:
description: 元数据版本ID
type: string
example: '8410480'
responses:
200:
description: ok
content:
application/json:
schema:
type: object
$ref: '#/components/schemas/ApiResponse'
'''