views.py
3.96 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
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.models import HILSEOCRResult, HILOCRResult, AFCSEOCRResult, AFCOCRResult
from prese import consts
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)
}
# pos 接口接收NSC 发票信息
class NSCInvoiceView(GenericView):
@use_args(input_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
content = args.get('content', {})
invoice_code = content['invoiceCode']
invoice_number = content['invoiceNumber']
issue_date = content['issueDate']
buyer_name = content['buyerName']
buyer_id = content['buyerId']
vin = content['vin']
dealer = content['dealer']
price_with_vat = content['priceWithVat']
price_no_vat = content['priceNoVat']
price_in_capitals = content['priceInCapitals']
vat = content['vat']
vat_rate = content['vatRate']
return response.ok(data=content)
de_mortgage_params = {
}
de_mortgage_args = {
'content': fields.Nested(de_mortgage_params, required=True)
}
# 解除抵押识别处理
class DeMortgageView(GenericView):
@use_args(de_mortgage_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
content = args.get('content', {})
application_id = content['applicationId']
customer_name = content['customerName']
application_entity = content['applicationEntity']
de_mortgage_date = content['deMortgageDate']
# ocr 检测
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
result_class = HILSEOCRResult if application_entity in consts.HIL_SET else AFCSEOCRResult
ca_result_class = HILOCRResult if application_entity in consts.HIL_SET else AFCOCRResult
ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values(
*consts.CA_ADD_COMPARE_FIELDS_PRE).first()
ocr_res_dict = result_class.objects.filter(application_id=application_id).values(
*consts.PRE_COMPARE_FIELDS).first()
# if ocr_res_dict is None:
# return get_empty_result()
ic_res_list = []
ic_res_list.append(ca_ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None)
ic_res_list.append(ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None)
field_name, compare_logic, args, comment = consts.ID_COMPARE_LOGIC.get(consts.ID_FIELDS[0])
for ic_res in ic_res_list:
if ic_res:
value = ic_res.get(field_name, '')
compare_logic
result = {
"is_pass": True,
"fields": [{
"name": "",
"input": "张三",
"ocr": "张三",
"field_is_pass": True,
"comments": "身份证姓名与系统不一致"
}]
# "customer_name": True,
# "application_entity": True,
# "de_mortgage_date": True
}
return response.ok(data=result)