se compare part 3
Showing
6 changed files
with
297 additions
and
6 deletions
... | @@ -6,4 +6,5 @@ urlpatterns = [ | ... | @@ -6,4 +6,5 @@ urlpatterns = [ |
6 | path(r'v1', views.CompareView.as_view()), | 6 | path(r'v1', views.CompareView.as_view()), |
7 | path(r'settlement/v1', views.SECompareView.as_view()), | 7 | path(r'settlement/v1', views.SECompareView.as_view()), |
8 | path(r'offline/v1', views.CompareOfflineView.as_view()), | 8 | path(r'offline/v1', views.CompareOfflineView.as_view()), |
9 | path(r'result', views.CompareResultView.as_view()), | ||
9 | ] | 10 | ] | ... | ... |
... | @@ -12,6 +12,7 @@ FIXED_APPLICATION_ID_PREFIX = 'CH-S' | ... | @@ -12,6 +12,7 @@ FIXED_APPLICATION_ID_PREFIX = 'CH-S' |
12 | 12 | ||
13 | DOC_SCHEME_LIST = ['ACCEPTANCE', 'SETTLEMENT', 'CONTRACTMANAGEMENT'] | 13 | DOC_SCHEME_LIST = ['ACCEPTANCE', 'SETTLEMENT', 'CONTRACTMANAGEMENT'] |
14 | DATA_SOURCE_LIST = ['POS', 'EAPP', 'ECONTRACT'] | 14 | DATA_SOURCE_LIST = ['POS', 'EAPP', 'ECONTRACT'] |
15 | COMPARE_DOC_SCHEME_LIST = ['CA', 'SE'] | ||
15 | 16 | ||
16 | HIL_PREFIX = 'HIL' | 17 | HIL_PREFIX = 'HIL' |
17 | AFC_PREFIX = 'AFC' | 18 | AFC_PREFIX = 'AFC' | ... | ... |
... | @@ -490,9 +490,22 @@ class IDBCRecords(models.Model): | ... | @@ -490,9 +490,22 @@ class IDBCRecords(models.Model): |
490 | 490 | ||
491 | class AFCSECompareResult(models.Model): | 491 | class AFCSECompareResult(models.Model): |
492 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 492 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 |
493 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | 493 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 |
494 | 494 | is_finish = models.BooleanField(default=False, verbose_name="是否完成") | |
495 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') | 495 | compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数") |
496 | failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目") | ||
497 | reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目") | ||
498 | reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目") | ||
499 | reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目") | ||
500 | reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目") | ||
501 | reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目") | ||
502 | reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目") | ||
503 | reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目") | ||
504 | reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目") | ||
505 | reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目") | ||
506 | reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目") | ||
507 | result = models.TextField(null=True, verbose_name="比对结果") | ||
508 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
496 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 509 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') |
497 | 510 | ||
498 | class Meta: | 511 | class Meta: |
... | @@ -501,3 +514,79 @@ class AFCSECompareResult(models.Model): | ... | @@ -501,3 +514,79 @@ class AFCSECompareResult(models.Model): |
501 | situ_db_label = 'afc' | 514 | situ_db_label = 'afc' |
502 | 515 | ||
503 | 516 | ||
517 | class AFCCACompareResult(models.Model): | ||
518 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
519 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
520 | is_finish = models.BooleanField(default=False, verbose_name="是否完成") | ||
521 | compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数") | ||
522 | failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目") | ||
523 | reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目") | ||
524 | reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目") | ||
525 | reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目") | ||
526 | reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目") | ||
527 | reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目") | ||
528 | reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目") | ||
529 | reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目") | ||
530 | reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目") | ||
531 | reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目") | ||
532 | reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目") | ||
533 | result = models.TextField(null=True, verbose_name="比对结果") | ||
534 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
535 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
536 | |||
537 | class Meta: | ||
538 | managed = False | ||
539 | db_table = 'afc_ca_compare_result' | ||
540 | situ_db_label = 'afc' | ||
541 | |||
542 | |||
543 | class HILSECompareResult(models.Model): | ||
544 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
545 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
546 | is_finish = models.BooleanField(default=False, verbose_name="是否完成") | ||
547 | compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数") | ||
548 | failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目") | ||
549 | reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目") | ||
550 | reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目") | ||
551 | reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目") | ||
552 | reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目") | ||
553 | reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目") | ||
554 | reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目") | ||
555 | reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目") | ||
556 | reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目") | ||
557 | reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目") | ||
558 | reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目") | ||
559 | result = models.TextField(null=True, verbose_name="比对结果") | ||
560 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
561 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
562 | |||
563 | class Meta: | ||
564 | managed = False | ||
565 | db_table = 'hil_se_compare_result' | ||
566 | |||
567 | |||
568 | class HILCACompareResult(models.Model): | ||
569 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
570 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
571 | is_finish = models.BooleanField(default=False, verbose_name="是否完成") | ||
572 | compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数") | ||
573 | failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目") | ||
574 | reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目") | ||
575 | reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目") | ||
576 | reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目") | ||
577 | reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目") | ||
578 | reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目") | ||
579 | reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目") | ||
580 | reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目") | ||
581 | reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目") | ||
582 | reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目") | ||
583 | reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目") | ||
584 | result = models.TextField(null=True, verbose_name="比对结果") | ||
585 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
586 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
587 | |||
588 | class Meta: | ||
589 | managed = False | ||
590 | db_table = 'hil_ca_compare_result' | ||
591 | |||
592 | ... | ... |
... | @@ -6,7 +6,7 @@ import datetime | ... | @@ -6,7 +6,7 @@ import datetime |
6 | import fitz | 6 | import fitz |
7 | import shutil | 7 | import shutil |
8 | from django.utils import timezone | 8 | from django.utils import timezone |
9 | from django.db.utils import IntegrityError | 9 | from django.http import HttpResponse |
10 | from django.db.models import Q | 10 | from django.db.models import Q |
11 | from rest_framework.permissions import IsAuthenticated | 11 | from rest_framework.permissions import IsAuthenticated |
12 | from webargs import fields, validate | 12 | from webargs import fields, validate |
... | @@ -16,7 +16,19 @@ from common import response | ... | @@ -16,7 +16,19 @@ from common import response |
16 | from common.mixins import GenericView | 16 | from common.mixins import GenericView |
17 | from common.tools.file_tools import file_write | 17 | from common.tools.file_tools import file_write |
18 | from common.redis_cache import redis_handler as rh | 18 | from common.redis_cache import redis_handler as rh |
19 | from .models import DocStatus, PriorityApplication, GCAPRecords, AFCComparisonInfo, HILComparisonInfo, AFCCompareOfflineReport, HILCompareOfflineReport | 19 | from .models import ( |
20 | DocStatus, | ||
21 | PriorityApplication, | ||
22 | GCAPRecords, | ||
23 | AFCComparisonInfo, | ||
24 | HILComparisonInfo, | ||
25 | AFCCompareOfflineReport, | ||
26 | HILCompareOfflineReport, | ||
27 | AFCCACompareResult, | ||
28 | AFCSECompareResult, | ||
29 | HILCACompareResult, | ||
30 | HILSECompareResult, | ||
31 | ) | ||
20 | from .mixins import DocHandler | 32 | from .mixins import DocHandler |
21 | from . import consts | 33 | from . import consts |
22 | from apps.account.authentication import OAuth2AuthenticationWithUser | 34 | from apps.account.authentication import OAuth2AuthenticationWithUser |
... | @@ -257,6 +269,13 @@ doc_list_args = { | ... | @@ -257,6 +269,13 @@ doc_list_args = { |
257 | 'create_time_end': fields.Date(required=False), | 269 | 'create_time_end': fields.Date(required=False), |
258 | } | 270 | } |
259 | 271 | ||
272 | compare_result_args = { | ||
273 | 'entity': fields.Str(required=True, validate=validate.OneOf(consts.BUSINESS_TYPE_LIST)), | ||
274 | 'scheme': fields.Str(required=True, validate=validate.OneOf(consts.COMPARE_DOC_SCHEME_LIST)), | ||
275 | 'id': fields.Int(required=False, validate=lambda val: val >= 1), | ||
276 | 'case_id': fields.Str(required=True, validate=validate.Length(max=64)), | ||
277 | } | ||
278 | |||
260 | upload_pdf_args = { | 279 | upload_pdf_args = { |
261 | 'pdf_file': fields.Raw(required=True), | 280 | 'pdf_file': fields.Raw(required=True), |
262 | } | 281 | } |
... | @@ -696,3 +715,60 @@ class DocView(GenericView, DocHandler): | ... | @@ -696,3 +715,60 @@ class DocView(GenericView, DocHandler): |
696 | is_priority, enqueue_res)) | 715 | is_priority, enqueue_res)) |
697 | data = {'excel_path': os.path.join(save_dir_path, '{0}.xlsx'.format(doc.id))} | 716 | data = {'excel_path': os.path.join(save_dir_path, '{0}.xlsx'.format(doc.id))} |
698 | return response.ok(data=data) | 717 | return response.ok(data=data) |
718 | |||
719 | |||
720 | class CompareResultView(GenericView): | ||
721 | |||
722 | # 获取比对结果 | ||
723 | @use_args(compare_result_args, location='querystring') | ||
724 | def get(self, request, args): | ||
725 | result_id = args.get('id', None) | ||
726 | entity = args.get('entity') | ||
727 | scheme = args.get('scheme') | ||
728 | case_id = args.get('case_id') | ||
729 | |||
730 | if entity == consts.HIL_PREFIX: | ||
731 | result_table = HILCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else HILSECompareResult | ||
732 | else: | ||
733 | result_table = AFCCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else AFCSECompareResult | ||
734 | |||
735 | if result_id is None: | ||
736 | result_str_list = result_table.objects.filter(id=result_id).values_list('result', flat=True) | ||
737 | else: | ||
738 | result_str_list = result_table.objects.filter(application_id=case_id).values_list('result', flat=True) | ||
739 | |||
740 | if len(result_str_list) == 0: | ||
741 | compare_result_list = [] | ||
742 | else: | ||
743 | compare_result_list = json.loads(result_str_list[0]) | ||
744 | |||
745 | if len(compare_result_list) == 0: | ||
746 | body_html = "<h1>没有比对结果</h1>" | ||
747 | else: | ||
748 | head_list = ['Info', 'Index', 'License', 'Field', 'Result', 'Input', 'OCR', 'Position', 'Image', 'errorType'] | ||
749 | head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in head_list]) | ||
750 | head_html = '<tr>{0}</tr>'.format(head_content) | ||
751 | row_html_list = [] | ||
752 | for row_dict in compare_result_list: | ||
753 | row_list = [row_dict.get(head, '') for head in head_list] | ||
754 | row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list]) | ||
755 | row_html = '<tr>{0}</tr>'.format(row_content) | ||
756 | row_html_list.append(row_html) | ||
757 | content_html = ''.join(row_html_list) | ||
758 | body_html = '<table border="1">{0}{1}</table>'.format(head_html, content_html) | ||
759 | |||
760 | html = """ | ||
761 | <!DOCTYPE html> | ||
762 | <html> | ||
763 | <head> | ||
764 | <meta charset="utf-8"> | ||
765 | <title>比对结果</title> | ||
766 | </head> | ||
767 | <body> | ||
768 | {0} | ||
769 | </body> | ||
770 | </html> | ||
771 | """.format(body_html) | ||
772 | return HttpResponse(html) | ||
773 | |||
774 | # return response.ok(data=compare_result) | ... | ... |
... | @@ -5,7 +5,17 @@ import traceback | ... | @@ -5,7 +5,17 @@ import traceback |
5 | from datetime import datetime, timedelta | 5 | from datetime import datetime, timedelta |
6 | from collections import OrderedDict | 6 | from collections import OrderedDict |
7 | from . import app | 7 | from . import app |
8 | from apps.doc.models import AFCOCRResult, HILOCRResult, AFCComparisonInfo, HILComparisonInfo, Configs, HILCompareReport, AFCCompareReport | 8 | from apps.doc.models import ( |
9 | AFCOCRResult, | ||
10 | HILOCRResult, | ||
11 | AFCComparisonInfo, | ||
12 | HILComparisonInfo, | ||
13 | Configs, | ||
14 | HILCompareReport, | ||
15 | AFCCompareReport, | ||
16 | AFCSECompareResult, | ||
17 | HILSECompareResult, | ||
18 | ) | ||
9 | from apps.doc import consts | 19 | from apps.doc import consts |
10 | from apps.doc.ocr.gcap import gcap | 20 | from apps.doc.ocr.gcap import gcap |
11 | from apps.doc.exceptions import GCAPException | 21 | from apps.doc.exceptions import GCAPException | ... | ... |
... | @@ -21,8 +21,65 @@ hil_sql = """ | ... | @@ -21,8 +21,65 @@ hil_sql = """ |
21 | update_time datetime not null, | 21 | update_time datetime not null, |
22 | create_time datetime not null | 22 | create_time datetime not null |
23 | ); | 23 | ); |
24 | |||
24 | create unique index hil_se_ocr_result_application_id_uindex | 25 | create unique index hil_se_ocr_result_application_id_uindex |
25 | on hil_se_ocr_result (application_id); | 26 | on hil_se_ocr_result (application_id); |
27 | |||
28 | create table hil_ca_compare_result | ||
29 | ( | ||
30 | id int identity primary key, | ||
31 | application_id nvarchar(64) not null, | ||
32 | is_finish bit default 0 not null, | ||
33 | compare_count smallint default 0 not null, | ||
34 | failed_count smallint default 0 not null, | ||
35 | reason1_count smallint default 0 not null, | ||
36 | reason2_count smallint default 0 not null, | ||
37 | reason3_count smallint default 0 not null, | ||
38 | reason4_count smallint default 0 not null, | ||
39 | reason5_count smallint default 0 not null, | ||
40 | reason6_count smallint default 0 not null, | ||
41 | reason7_count smallint default 0 not null, | ||
42 | reason8_count smallint default 0 not null, | ||
43 | reason9_count smallint default 0 not null, | ||
44 | reason10_count smallint default 0 not null, | ||
45 | result nvarchar(max), | ||
46 | update_time datetime not null, | ||
47 | create_time datetime not null | ||
48 | ); | ||
49 | |||
50 | create unique index hil_ca_compare_result_application_id_uindex | ||
51 | on hil_ca_compare_result (application_id); | ||
52 | |||
53 | create index hil_ca_compare_result_update_time_index | ||
54 | on hil_ca_compare_result (update_time); | ||
55 | |||
56 | create table hil_se_compare_result | ||
57 | ( | ||
58 | id int identity primary key, | ||
59 | application_id nvarchar(64) not null, | ||
60 | is_finish bit default 0 not null, | ||
61 | compare_count smallint default 0 not null, | ||
62 | failed_count smallint default 0 not null, | ||
63 | reason1_count smallint default 0 not null, | ||
64 | reason2_count smallint default 0 not null, | ||
65 | reason3_count smallint default 0 not null, | ||
66 | reason4_count smallint default 0 not null, | ||
67 | reason5_count smallint default 0 not null, | ||
68 | reason6_count smallint default 0 not null, | ||
69 | reason7_count smallint default 0 not null, | ||
70 | reason8_count smallint default 0 not null, | ||
71 | reason9_count smallint default 0 not null, | ||
72 | reason10_count smallint default 0 not null, | ||
73 | result nvarchar(max), | ||
74 | update_time datetime not null, | ||
75 | create_time datetime not null | ||
76 | ); | ||
77 | |||
78 | create unique index hil_se_compare_result_application_id_uindex | ||
79 | on hil_se_compare_result (application_id); | ||
80 | |||
81 | create index hil_se_compare_result_update_time_index | ||
82 | on hil_se_compare_result (update_time); | ||
26 | """ | 83 | """ |
27 | 84 | ||
28 | afc_sql = """ | 85 | afc_sql = """ |
... | @@ -45,8 +102,65 @@ afc_sql = """ | ... | @@ -45,8 +102,65 @@ afc_sql = """ |
45 | update_time datetime not null, | 102 | update_time datetime not null, |
46 | create_time datetime not null | 103 | create_time datetime not null |
47 | ); | 104 | ); |
105 | |||
48 | create unique index afc_se_ocr_result_application_id_uindex | 106 | create unique index afc_se_ocr_result_application_id_uindex |
49 | on afc_se_ocr_result (application_id); | 107 | on afc_se_ocr_result (application_id); |
108 | |||
109 | create table afc_ca_compare_result | ||
110 | ( | ||
111 | id int identity primary key, | ||
112 | application_id nvarchar(64) not null, | ||
113 | is_finish bit default 0 not null, | ||
114 | compare_count smallint default 0 not null, | ||
115 | failed_count smallint default 0 not null, | ||
116 | reason1_count smallint default 0 not null, | ||
117 | reason2_count smallint default 0 not null, | ||
118 | reason3_count smallint default 0 not null, | ||
119 | reason4_count smallint default 0 not null, | ||
120 | reason5_count smallint default 0 not null, | ||
121 | reason6_count smallint default 0 not null, | ||
122 | reason7_count smallint default 0 not null, | ||
123 | reason8_count smallint default 0 not null, | ||
124 | reason9_count smallint default 0 not null, | ||
125 | reason10_count smallint default 0 not null, | ||
126 | result nvarchar(max), | ||
127 | update_time datetime not null, | ||
128 | create_time datetime not null | ||
129 | ); | ||
130 | |||
131 | create unique index afc_ca_compare_result_application_id_uindex | ||
132 | on afc_ca_compare_result (application_id); | ||
133 | |||
134 | create index afc_ca_compare_result_update_time_index | ||
135 | on afc_ca_compare_result (update_time); | ||
136 | |||
137 | create table afc_se_compare_result | ||
138 | ( | ||
139 | id int identity primary key, | ||
140 | application_id nvarchar(64) not null, | ||
141 | is_finish bit default 0 not null, | ||
142 | compare_count smallint default 0 not null, | ||
143 | failed_count smallint default 0 not null, | ||
144 | reason1_count smallint default 0 not null, | ||
145 | reason2_count smallint default 0 not null, | ||
146 | reason3_count smallint default 0 not null, | ||
147 | reason4_count smallint default 0 not null, | ||
148 | reason5_count smallint default 0 not null, | ||
149 | reason6_count smallint default 0 not null, | ||
150 | reason7_count smallint default 0 not null, | ||
151 | reason8_count smallint default 0 not null, | ||
152 | reason9_count smallint default 0 not null, | ||
153 | reason10_count smallint default 0 not null, | ||
154 | result nvarchar(max), | ||
155 | update_time datetime not null, | ||
156 | create_time datetime not null | ||
157 | ); | ||
158 | |||
159 | create unique index afc_se_compare_result_application_id_uindex | ||
160 | on afc_se_compare_result (application_id); | ||
161 | |||
162 | create index afc_se_compare_result_update_time_index | ||
163 | on afc_se_compare_result (update_time); | ||
50 | """ | 164 | """ |
51 | 165 | ||
52 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | 166 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ... | ... |
-
Please register or sign in to post a comment