views.py
4.33 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
from common.mixins import GenericView
from webargs.djangoparser import use_args, parser
from webargs import fields, validate
from apps.doc.views import CustomDecimal, CustomDate
from common import response
from apps.doc.mixins import PosHandler
from common.tools.comparison import cp
from rest_framework.permissions import IsAuthenticated
from apps.account.authentication import OAuth2AuthenticationWithUser
params = {
'invoiceCode': fields.Str(required=True, validate=validate.Length(max=128)),
'invoiceNumber': fields.Str(required=True, validate=validate.Length(max=64)),
'issueDate': CustomDate(required=True),
'buyerName': fields.Str(required=True, validate=validate.Length(max=64)),
"buyerId": fields.Int(required=True),
'vin': fields.Str(required=True, validate=validate.Length(max=128)),
'dealer': fields.Str(required=False, validate=validate.Length(max=64)),
'priceWithVat': CustomDecimal(required=True),
'priceNoVat': CustomDecimal(required=True),
'priceInCapitals': fields.Str(required=False),
'vat': CustomDecimal(required=True),
'vatRate': CustomDecimal(required=False),
}
input_args = {
'content': fields.Nested(params, required=True)
}
# poss 接口接收NSC 发票信息
class NSCInvoiceView(GenericView):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(input_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
content = args.get('content', {})
invoice_code = content.get('invoiceCode', '')
invoice_number = content.get('invoiceNumber', '')
issue_date = content.get('issueDate', None)
buyer_name = content.get('buyerName', '')
buyer_id = content.get('buyerId', 0)
vin = content.get('vin', '')
dealer = content.get('dealer', '')
price_with_vat = content.get('priceWithVat', 0.0)
price_no_vat = content.get('priceNoVat', 0.0)
price_in_capitals = content.get('priceInCapitals', '')
vat = content.get('vat', 0.0)
vat_rate = content.get('vatRate', 0.0)
return response.ok()
de_mortgage_args = {
'customerName': fields.Str(required=True, validate=validate.Length(max=64)),
'application': fields.Str(required=True, validate=validate.Length(max=64)),
'deMortgageDate': fields.Date(required=True),
'file_base64': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)),
}
de_mortgage_comments = {
'customerName': ('机动车所有人识别不一致', ),
'application': ('抵押权人姓名/名称识别不一致', ),
'deMortgageDate': ('解除抵押日期不一致', )
}
# 解除抵押识别处理
class DeMortgageView(GenericView):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(de_mortgage_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
img_files = args.get('file_base64', [])
customer_name = args.get('customerName', '')
application = args.get('application', '')
de_mortgage_date = args.get('deMortgageDate')
fields_input = {
'customerName': customer_name,
'application': application,
'deMortgageDate': de_mortgage_date
}
de_mortgage_info = {}
# 绿本必须分开ocr
for img_file in img_files:
info = PosHandler.de_mortgage_ocr_process1(img_file)
de_mortgage_info.update(info)
request_pass = True
fields_result = []
for field_name, input_val in fields_input.items():
field_result = {
"name": field_name,
"input": input_val,
"ocr": de_mortgage_info.get(field_name, ''),
"field_is_pass": False,
"comments": ''
}
result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
if result == cp.RESULT_Y:
fields_result['field_is_pass'] = result
else:
request_pass = False
fields_result['comments'] = de_mortgage_comments.get(field_name, '')
fields_result.append(field_result)
result = {
"is_pass": request_pass,
"fields": fields_result
}
return response.ok(data=result)