e-contract part2
Showing
6 changed files
with
118 additions
and
98 deletions
| ... | @@ -18,7 +18,7 @@ HIL_PREFIX = 'HIL' | ... | @@ -18,7 +18,7 @@ HIL_PREFIX = 'HIL' | 
| 18 | AFC_PREFIX = 'AFC' | 18 | AFC_PREFIX = 'AFC' | 
| 19 | SPLIT_STR = '_' | 19 | SPLIT_STR = '_' | 
| 20 | BUSINESS_TYPE_LIST = [HIL_PREFIX, AFC_PREFIX] | 20 | BUSINESS_TYPE_LIST = [HIL_PREFIX, AFC_PREFIX] | 
| 21 | HIL_SET = {'HIL', 'HIl', 'HiL', 'Hil', 'hIL', 'hIl', 'hiL', 'hil', 'CO00002'} | 21 | HIL_SET = {'HIL', 'HIl', 'HiL', 'Hil', 'hIL', 'hIl', 'hiL', 'hil', 'CO00002', 'SF5_CL'} | 
| 22 | 22 | ||
| 23 | PRIORITY_WORDS = {'muw', 'MUW', '42', 42} | 23 | PRIORITY_WORDS = {'muw', 'MUW', '42', 42} | 
| 24 | TMP_DIR_NAME = 'OCR_Files' | 24 | TMP_DIR_NAME = 'OCR_Files' | 
| ... | @@ -1786,6 +1786,18 @@ FILE_NAME_PREFIX_MAP = { | ... | @@ -1786,6 +1786,18 @@ FILE_NAME_PREFIX_MAP = { | 
| 1786 | ] | 1786 | ] | 
| 1787 | } | 1787 | } | 
| 1788 | 1788 | ||
| 1789 | ECONTRACT_KEYWORDS_MAP = { | ||
| 1790 | AFC_PREFIX: [ | ||
| 1791 | ('电子签署-汽车抵押贷款合同', CONTRACT_CLASSIFY, 0), | ||
| 1792 | ('电子签署-抵押登记豁免函', HMH_CLASSIFY, 0), | ||
| 1793 | ], | ||
| 1794 | HIL_PREFIX: [ | ||
| 1795 | ('电子签署-售后回租合同', HIL_CONTRACT_1_CLASSIFY, HIL_CONTRACT_3_CLASSIFY), | ||
| 1796 | ('电子签署-汽车租赁抵押合同', HIL_CONTRACT_2_CLASSIFY, 0), | ||
| 1797 | ('电子签署-抵押登记豁免函', HMH_CLASSIFY, 0), | ||
| 1798 | ] | ||
| 1799 | } | ||
| 1800 | |||
| 1789 | HIL_CONTRACT_TYPE_MAP = { | 1801 | HIL_CONTRACT_TYPE_MAP = { | 
| 1790 | str(HIL_CONTRACT_1_CLASSIFY): 0, | 1802 | str(HIL_CONTRACT_1_CLASSIFY): 0, | 
| 1791 | str(HIL_CONTRACT_2_CLASSIFY): 2, | 1803 | str(HIL_CONTRACT_2_CLASSIFY): 2, | ... | ... | 
| ... | @@ -947,7 +947,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -947,7 +947,7 @@ class Command(BaseCommand, LoggerMixin): | 
| 947 | 947 | ||
| 948 | pdf_handler = PDFHandler(pdf_path, img_save_path, doc.document_name) | 948 | pdf_handler = PDFHandler(pdf_path, img_save_path, doc.document_name) | 
| 949 | 949 | ||
| 950 | if classify_1_str == '0' or classify_1_str == str(consts.HMH_CLASSIFY): | 950 | if classify_1_str == '0': | 
| 951 | try: | 951 | try: | 
| 952 | # 2. 从EDMS获取PDF文件 | 952 | # 2. 从EDMS获取PDF文件 | 
| 953 | max_count_obj = Configs.objects.filter(id=2).first() | 953 | max_count_obj = Configs.objects.filter(id=2).first() | ... | ... | 
| ... | @@ -789,24 +789,24 @@ class HILCACompareResultRecord(models.Model): | ... | @@ -789,24 +789,24 @@ class HILCACompareResultRecord(models.Model): | 
| 789 | db_table = 'hil_ca_compare_result_record' | 789 | db_table = 'hil_ca_compare_result_record' | 
| 790 | 790 | ||
| 791 | 791 | ||
| 792 | class HILContract(models.Model): | 792 | # class HILContract(models.Model): | 
| 793 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 793 | # id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 
| 794 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | 794 | # application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | 
| 795 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 795 | # create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 
| 796 | 796 | ||
| 797 | class Meta: | 797 | # class Meta: | 
| 798 | managed = False | 798 | # managed = False | 
| 799 | db_table = 'hil_contract' | 799 | # db_table = 'hil_contract' | 
| 800 | 800 | ||
| 801 | 801 | ||
| 802 | class AFCContract(models.Model): | 802 | # class AFCContract(models.Model): | 
| 803 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 803 | # id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 
| 804 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | 804 | # application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | 
| 805 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 805 | # create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 
| 806 | 806 | ||
| 807 | class Meta: | 807 | # class Meta: | 
| 808 | managed = False | 808 | # managed = False | 
| 809 | db_table = 'afc_contract' | 809 | # db_table = 'afc_contract' | 
| 810 | situ_db_label = 'afc' | 810 | # situ_db_label = 'afc' | 
| 811 | 811 | ||
| 812 | 812 | ... | ... | 
| ... | @@ -36,14 +36,12 @@ from .models import ( | ... | @@ -36,14 +36,12 @@ from .models import ( | 
| 36 | AFCSECompareResultRecord, | 36 | AFCSECompareResultRecord, | 
| 37 | HILCACompareResultRecord, | 37 | HILCACompareResultRecord, | 
| 38 | HILSECompareResultRecord, | 38 | HILSECompareResultRecord, | 
| 39 | HILContract, | ||
| 40 | AFCContract, | ||
| 41 | ) | 39 | ) | 
| 42 | from .named_enum import ErrorType | 40 | from .named_enum import ErrorType | 
| 43 | from .mixins import DocHandler | 41 | from .mixins import DocHandler | 
| 44 | from . import consts | 42 | from . import consts | 
| 45 | from apps.account.authentication import OAuth2AuthenticationWithUser | 43 | from apps.account.authentication import OAuth2AuthenticationWithUser | 
| 46 | from celery_compare.tasks import compare, forwarding_station | 44 | from celery_compare.tasks import compare | 
| 47 | 45 | ||
| 48 | 46 | ||
| 49 | class CustomDate(fields.Date): | 47 | class CustomDate(fields.Date): | 
| ... | @@ -497,7 +495,7 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -497,7 +495,7 @@ class UploadDocView(GenericView, DocHandler): | 
| 497 | application_id = application_data.get('applicationId') | 495 | application_id = application_data.get('applicationId') | 
| 498 | document_scheme = document.get('documentScheme') | 496 | document_scheme = document.get('documentScheme') | 
| 499 | data_source = document.get('dataSource') | 497 | data_source = document.get('dataSource') | 
| 500 | document_name = document.get('documentName') | 498 | document_name = document.get('documentName', '') | 
| 501 | # main_name = self.get_name(applicant_data, 'mainApplicantName', 16) | 499 | # main_name = self.get_name(applicant_data, 'mainApplicantName', 16) | 
| 502 | # co_name = self.get_name(applicant_data, 'coApplicantName', 16) | 500 | # co_name = self.get_name(applicant_data, 'coApplicantName', 16) | 
| 503 | # g1_name = self.get_name(applicant_data, 'guarantor1Name', 16) | 501 | # g1_name = self.get_name(applicant_data, 'guarantor1Name', 16) | 
| ... | @@ -522,6 +520,12 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -522,6 +520,12 @@ class UploadDocView(GenericView, DocHandler): | 
| 522 | # self.invalid_params(msg='metadataVersionId repeat') | 520 | # self.invalid_params(msg='metadataVersionId repeat') | 
| 523 | # else: | 521 | # else: | 
| 524 | data_source = self.fix_data_source(data_source) | 522 | data_source = self.fix_data_source(data_source) | 
| 523 | document_scheme=self.fix_scheme(document_scheme) | ||
| 524 | |||
| 525 | if document_name.endswith('.zip'): | ||
| 526 | self.running_log.info('[doc upload success] [zip file skip] [args={0}]'.format(args)) | ||
| 527 | return response.ok() | ||
| 528 | |||
| 525 | if data_source == consts.DATA_SOURCE_LIST[1]: | 529 | if data_source == consts.DATA_SOURCE_LIST[1]: | 
| 526 | if isinstance(document_name, str): | 530 | if isinstance(document_name, str): | 
| 527 | if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'): | 531 | if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'): | 
| ... | @@ -536,15 +540,23 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -536,15 +540,23 @@ class UploadDocView(GenericView, DocHandler): | 
| 536 | # co_applicant=applicant_data.get('coApplicantName'), | 540 | # co_applicant=applicant_data.get('coApplicantName'), | 
| 537 | # guarantor_1=applicant_data.get('guarantor1Name'), | 541 | # guarantor_1=applicant_data.get('guarantor1Name'), | 
| 538 | # guarantor_2=applicant_data.get('guarantor2Name'), | 542 | # guarantor_2=applicant_data.get('guarantor2Name'), | 
| 539 | document_name=document.get('documentName'), | 543 | document_name=document_name, | 
| 540 | document_scheme=self.fix_scheme(document_scheme), | 544 | document_scheme=document_scheme, | 
| 541 | data_source=self.fix_data_source(data_source), | 545 | data_source=data_source, | 
| 542 | upload_finish_time=document.get('uploadFinishTime'), | 546 | upload_finish_time=document.get('uploadFinishTime'), | 
| 543 | ) | 547 | ) | 
| 544 | # 3. 选择队列进入 | 548 | # 3. 选择队列进入 | 
| 545 | is_priority = PriorityApplication.objects.filter(application_id=application_id, on_off=True).exists() | 549 | is_priority = PriorityApplication.objects.filter(application_id=application_id, on_off=True).exists() | 
| 546 | tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)] | 550 | |
| 547 | enqueue_res = rh.enqueue(tasks, is_priority) | 551 | classify_1 = classify_2 = 0 | 
| 552 | if data_source == consts.DATA_SOURCE_LIST[-1] and document_scheme == consts.DOC_SCHEME_LIST[1]: | ||
| 553 | for keyword, classify_1_tmp, classify_2_tmp in consts.FILE_NAME_PREFIX_MAP.get(prefix): | ||
| 554 | if keyword in document_name: | ||
| 555 | classify_1 = classify_1_tmp | ||
| 556 | classify_2 = classify_2_tmp | ||
| 557 | break | ||
| 558 | task = consts.SPLIT_STR.join([prefix, str(doc.id), str(classify_1), str(classify_2)]) | ||
| 559 | enqueue_res = rh.enqueue([task], is_priority) | ||
| 548 | self.running_log.info('[doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' | 560 | self.running_log.info('[doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' | 
| 549 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, | 561 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, | 
| 550 | is_priority, enqueue_res)) | 562 | is_priority, enqueue_res)) | 
| ... | @@ -1166,11 +1178,11 @@ class SEContractView(GenericView): | ... | @@ -1166,11 +1178,11 @@ class SEContractView(GenericView): | 
| 1166 | # pos上传e-contract信息接口 SE | 1178 | # pos上传e-contract信息接口 SE | 
| 1167 | @use_args(se_contract_args, location='data') | 1179 | @use_args(se_contract_args, location='data') | 
| 1168 | def post(self, request, args): | 1180 | def post(self, request, args): | 
| 1169 | contract_info = args.get('content', {}) | 1181 | # contract_info = args.get('content', {}) | 
| 1170 | application_id = contract_info.get('applicationId', '') | 1182 | # application_id = contract_info.get('applicationId', '') | 
| 1171 | entity = contract_info.get('applicationEntity', '') | 1183 | # entity = contract_info.get('applicationEntity', '') | 
| 1172 | table_class = HILContract if entity == consts.HIL_PREFIX else AFCContract | 1184 | # table_class = HILContract if entity == consts.HIL_PREFIX else AFCContract | 
| 1173 | table_class.objects.create(application_id=application_id) | 1185 | # table_class.objects.create(application_id=application_id) | 
| 1174 | forwarding_station.apply_async((application_id, entity), queue='queue_compare', countdown=conf.DELAY_SECONDS) | 1186 | # forwarding_station.apply_async((application_id, entity), queue='queue_compare', countdown=conf.DELAY_SECONDS) | 
| 1175 | self.running_log.info('[e-contract] [application_id={0}] [entity={1}]'.format(application_id, entity)) | 1187 | self.running_log.info('[e-contract pos in] [args={0}]'.format(args)) | 
| 1176 | return response.ok() | 1188 | return response.ok() | ... | ... | 
| ... | @@ -27,13 +27,10 @@ from apps.doc.models import ( | ... | @@ -27,13 +27,10 @@ from apps.doc.models import ( | 
| 27 | AFCCACompareResult, | 27 | AFCCACompareResult, | 
| 28 | HILSECompareResult, | 28 | HILSECompareResult, | 
| 29 | HILCACompareResult, | 29 | HILCACompareResult, | 
| 30 | AFCDoc, | ||
| 31 | HILDoc | ||
| 32 | ) | 30 | ) | 
| 33 | from apps.doc import consts | 31 | from apps.doc import consts | 
| 34 | from apps.doc.ocr.gcap import gcap | 32 | from apps.doc.ocr.gcap import gcap | 
| 35 | from apps.doc.ocr.cms import cms | 33 | from apps.doc.ocr.cms import cms | 
| 36 | from apps.doc.ocr.ecm import ECM, rh | ||
| 37 | from apps.doc.exceptions import GCAPException | 34 | from apps.doc.exceptions import GCAPException | 
| 38 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType | 35 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType | 
| 39 | from common.tools.comparison import cp | 36 | from common.tools.comparison import cp | 
| ... | @@ -41,11 +38,10 @@ from common.tools.des import decode_des | ... | @@ -41,11 +38,10 @@ from common.tools.des import decode_des | 
| 41 | 38 | ||
| 42 | compare_log = logging.getLogger('compare') | 39 | compare_log = logging.getLogger('compare') | 
| 43 | log_base = '[Compare]' | 40 | log_base = '[Compare]' | 
| 44 | e_log_base = '[e-contract]' | 41 | # e_log_base = '[e-contract]' | 
| 45 | empty_str = '' | 42 | empty_str = '' | 
| 46 | empty_error_type = 1000 | 43 | empty_error_type = 1000 | 
| 47 | des_key = conf.CMS_DES_KEY | 44 | des_key = conf.CMS_DES_KEY | 
| 48 | ecm = ECM() | ||
| 49 | 45 | ||
| 50 | 46 | ||
| 51 | def rotate_bound(image, angle): | 47 | def rotate_bound(image, angle): | 
| ... | @@ -1872,32 +1868,32 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True | ... | @@ -1872,32 +1868,32 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True | 
| 1872 | se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms) | 1868 | se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms) | 
| 1873 | 1869 | ||
| 1874 | 1870 | ||
| 1875 | @app.task | 1871 | # @app.task | 
| 1876 | def forwarding_station(application_id, entity): | 1872 | # def forwarding_station(application_id, entity): | 
| 1877 | compare_log.info('{0} [forward start] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity)) | 1873 | # compare_log.info('{0} [forward start] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity)) | 
| 1878 | doc_class = HILDoc if entity in consts.HIL_SET else AFCDoc | 1874 | # doc_class = HILDoc if entity in consts.HIL_SET else AFCDoc | 
| 1879 | entity_prefix = consts.HIL_PREFIX if entity in consts.HIL_SET else consts.AFC_PREFIX | 1875 | # entity_prefix = consts.HIL_PREFIX if entity in consts.HIL_SET else consts.AFC_PREFIX | 
| 1880 | for (classify_1, classify_2), prefix in consts.FILE_NAME_PREFIX_MAP.get(entity): | 1876 | # for (classify_1, classify_2), prefix in consts.FILE_NAME_PREFIX_MAP.get(entity): | 
| 1881 | try: | 1877 | # try: | 
| 1882 | file_list = ecm.search(application_id, entity, prefix.format(application_id)) # TODO 获取最新文件 | 1878 | # file_list = ecm.search(application_id, entity, prefix.format(application_id)) # TODO 获取最新文件 | 
| 1883 | except Exception as e: | 1879 | # except Exception as e: | 
| 1884 | compare_log.error('{0} [search failed] [application_id={1}] [entity={2}] [error={3}]'.format( | 1880 | # compare_log.error('{0} [search failed] [application_id={1}] [entity={2}] [error={3}]'.format( | 
| 1885 | e_log_base, application_id, entity, traceback.format_exc())) | 1881 | # e_log_base, application_id, entity, traceback.format_exc())) | 
| 1886 | else: | 1882 | # else: | 
| 1887 | compare_log.info('{0} [search end] [application_id={1}] [entity={2}] [file_list={3}]'.format( | 1883 | # compare_log.info('{0} [search end] [application_id={1}] [entity={2}] [file_list={3}]'.format( | 
| 1888 | e_log_base, application_id, entity, file_list)) | 1884 | # e_log_base, application_id, entity, file_list)) | 
| 1889 | for object_name, object_id in file_list: | 1885 | # for object_name, object_id in file_list: | 
| 1890 | doc = doc_class.objects.create( | 1886 | # doc = doc_class.objects.create( | 
| 1891 | metadata_version_id=object_id, | 1887 | # metadata_version_id=object_id, | 
| 1892 | application_id=application_id, | 1888 | # application_id=application_id, | 
| 1893 | document_name=object_name, | 1889 | # document_name=object_name, | 
| 1894 | document_scheme='SETTLEMENT', | 1890 | # document_scheme='SETTLEMENT', | 
| 1895 | data_source='POS', | 1891 | # data_source='POS', | 
| 1896 | upload_finish_time=datetime.now(), | 1892 | # upload_finish_time=datetime.now(), | 
| 1897 | ) | 1893 | # ) | 
| 1898 | task = consts.SPLIT_STR.join([entity_prefix, str(doc.id), str(classify_1), str(classify_2)]) | 1894 | # task = consts.SPLIT_STR.join([entity_prefix, str(doc.id), str(classify_1), str(classify_2)]) | 
| 1899 | enqueue_res = rh.enqueue([task], False) | 1895 | # enqueue_res = rh.enqueue([task], False) | 
| 1900 | compare_log.info('{0} [upload success] [res={1}] [application_id={2}] [entity={3}] [object_name={4}] ' | 1896 | # compare_log.info('{0} [upload success] [res={1}] [application_id={2}] [entity={3}] [object_name={4}] ' | 
| 1901 | '[object_id={5}] [doc_id={6}]'.format(e_log_base, enqueue_res, application_id, entity, | 1897 | # '[object_id={5}] [doc_id={6}]'.format(e_log_base, enqueue_res, application_id, entity, | 
| 1902 | object_name, object_id, doc.id)) | 1898 | # object_name, object_id, doc.id)) | 
| 1903 | compare_log.info('{0} [forward end] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity)) | 1899 | # compare_log.info('{0} [forward end] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity)) | ... | ... | 
| 1 | import pyodbc | 1 | # import pyodbc | 
| 2 | 2 | ||
| 3 | afc_sql = """ | 3 | # afc_sql = """ | 
| 4 | create table afc_contract | 4 | # create table afc_contract | 
| 5 | ( | 5 | # ( | 
| 6 | id bigint identity primary key, | 6 | # id bigint identity primary key, | 
| 7 | application_id nvarchar(64) not null, | 7 | # application_id nvarchar(64) not null, | 
| 8 | create_time datetime not null | 8 | # create_time datetime not null | 
| 9 | ); | 9 | # ); | 
| 10 | 10 | ||
| 11 | create index afc_contract_application_id_index | 11 | # create index afc_contract_application_id_index | 
| 12 | on afc_contract (application_id); | 12 | # on afc_contract (application_id); | 
| 13 | """ | 13 | # """ | 
| 14 | 14 | ||
| 15 | hil_sql = """ | 15 | # hil_sql = """ | 
| 16 | create table hil_contract | 16 | # create table hil_contract | 
| 17 | ( | 17 | # ( | 
| 18 | id bigint identity primary key, | 18 | # id bigint identity primary key, | 
| 19 | application_id nvarchar(64) not null, | 19 | # application_id nvarchar(64) not null, | 
| 20 | create_time datetime not null | 20 | # create_time datetime not null | 
| 21 | ); | 21 | # ); | 
| 22 | 22 | ||
| 23 | create index hil_contract_application_id_index | 23 | # create index hil_contract_application_id_index | 
| 24 | on hil_contract (application_id); | 24 | # on hil_contract (application_id); | 
| 25 | """ | 25 | # """ | 
| 26 | 26 | ||
| 27 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | 27 | # hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | 
| 28 | 28 | ||
| 29 | hil_cursor = hil_cnxn.cursor() | 29 | # hil_cursor = hil_cnxn.cursor() | 
| 30 | hil_cursor.execute(hil_sql) | 30 | # hil_cursor.execute(hil_sql) | 
| 31 | 31 | ||
| 32 | hil_cursor.close() | 32 | # hil_cursor.close() | 
| 33 | hil_cnxn.close() | 33 | # hil_cnxn.close() | 
| 34 | 34 | ||
| 35 | afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | 35 | # afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | 
| 36 | 36 | ||
| 37 | afc_cursor = afc_cnxn.cursor() | 37 | # afc_cursor = afc_cnxn.cursor() | 
| 38 | afc_cursor.execute(afc_sql) | 38 | # afc_cursor.execute(afc_sql) | 
| 39 | 39 | ||
| 40 | afc_cursor.close() | 40 | # afc_cursor.close() | 
| 41 | afc_cnxn.close() | 41 | # afc_cnxn.close() | ... | ... | 
- 
Please register or sign in to post a comment