Merge branch 'feature/CHINARPA-3529'
Showing
3 changed files
with
109 additions
and
20 deletions
... | @@ -1458,15 +1458,20 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1458,15 +1458,20 @@ class Command(BaseCommand, LoggerMixin): |
1458 | # pdf下载 处理 图片存储 识别 | 1458 | # pdf下载 处理 图片存储 识别 |
1459 | for times in range(consts.RETRY_TIMES): | 1459 | for times in range(consts.RETRY_TIMES): |
1460 | try: | 1460 | try: |
1461 | self.edms.download(pdf_path, doc.metadata_version_id, doc.document_scheme, business_type) | 1461 | if doc.application_id.startswith(consts.FIXED_APPLICATION_ID_PREFIX): |
1462 | self.online_log.info('{0} [edms download success] [task={1}] [times={2}] ' | 1462 | self.online_log.info('{0} [mo ni xia dan] [task={1}] [times={2}] ' |
1463 | '[pdf_path={3}]'.format(self.e_log_base, task_str, times, pdf_path)) | 1463 | '[pdf_path={3}]'.format(self.log_base, task_str, |
1464 | 1464 | times, pdf_path)) | |
1465 | self.online_log.info('{0} [pdf to img start] [task={1}] [times={2}]'.format( | 1465 | else: |
1466 | self.e_log_base, task_str, times)) | 1466 | self.edms.download(pdf_path, doc.metadata_version_id, doc.document_scheme, business_type) |
1467 | pdf_handler.e_contract_process() | 1467 | self.online_log.info('{0} [edms download success] [task={1}] [times={2}] ' |
1468 | self.online_log.info( | 1468 | '[pdf_path={3}]'.format(self.e_log_base, task_str, times, pdf_path)) |
1469 | '{0} [pdf to img end] [task={1}] [times={2}]'.format(self.e_log_base, task_str, times)) | 1469 | |
1470 | self.online_log.info('{0} [pdf to img start] [task={1}] [times={2}]'.format( | ||
1471 | self.e_log_base, task_str, times)) | ||
1472 | pdf_handler.e_contract_process() | ||
1473 | self.online_log.info( | ||
1474 | '{0} [pdf to img end] [task={1}] [times={2}]'.format(self.e_log_base, task_str, times)) | ||
1470 | except Exception as e: | 1475 | except Exception as e: |
1471 | self.online_log.warn('{0} [download or pdf to img failed] [task={1}] [times={2}] ' | 1476 | self.online_log.warn('{0} [download or pdf to img failed] [task={1}] [times={2}] ' |
1472 | '[error={3}]'.format(self.e_log_base, task_str, times, | 1477 | '[error={3}]'.format(self.e_log_base, task_str, times, |
... | @@ -1973,7 +1978,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1973,7 +1978,7 @@ class Command(BaseCommand, LoggerMixin): |
1973 | self.log_base, task_str, traceback.format_exc())) | 1978 | self.log_base, task_str, traceback.format_exc())) |
1974 | else: | 1979 | else: |
1975 | self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str)) | 1980 | self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str)) |
1976 | os.remove(excel_path) | 1981 | # os.remove(excel_path) |
1977 | 1982 | ||
1978 | # report新增流水真伪 | 1983 | # report新增流水真伪 |
1979 | try: | 1984 | try: | ... | ... |
... | @@ -17,7 +17,7 @@ from webargs import fields, validate | ... | @@ -17,7 +17,7 @@ from webargs import fields, validate |
17 | from webargs.djangoparser import use_args, parser | 17 | from webargs.djangoparser import use_args, parser |
18 | from settings import conf | 18 | from settings import conf |
19 | from common import response | 19 | from common import response |
20 | from common.mixins import GenericView | 20 | from common.mixins import GenericView,DocGenericView |
21 | from common.tools.file_tools import file_write | 21 | from common.tools.file_tools import file_write |
22 | from common.redis_cache import redis_handler as rh | 22 | from common.redis_cache import redis_handler as rh |
23 | from .models import ( | 23 | from .models import ( |
... | @@ -360,6 +360,10 @@ compare_result_args = { | ... | @@ -360,6 +360,10 @@ compare_result_args = { |
360 | 360 | ||
361 | upload_pdf_args = { | 361 | upload_pdf_args = { |
362 | 'pdf_file': fields.Raw(required=True), | 362 | 'pdf_file': fields.Raw(required=True), |
363 | 'business_type': fields.Str(required=True), | ||
364 | 'document_scheme': fields.Str(required=True), | ||
365 | 'data_source': fields.Str(required=True), | ||
366 | 'document_name': fields.Str(required=True), | ||
363 | } | 367 | } |
364 | 368 | ||
365 | application_information = { | 369 | application_information = { |
... | @@ -1035,7 +1039,7 @@ class CompareOfflineView(GenericView): | ... | @@ -1035,7 +1039,7 @@ class CompareOfflineView(GenericView): |
1035 | ''' | 1039 | ''' |
1036 | 1040 | ||
1037 | 1041 | ||
1038 | class DocView(GenericView, DocHandler): | 1042 | class DocView(DocGenericView, DocHandler): |
1039 | 1043 | ||
1040 | # 文件列表页 | 1044 | # 文件列表页 |
1041 | @use_args(doc_list_args, location='querystring') | 1045 | @use_args(doc_list_args, location='querystring') |
... | @@ -1079,6 +1083,8 @@ class DocView(GenericView, DocHandler): | ... | @@ -1079,6 +1083,8 @@ class DocView(GenericView, DocHandler): |
1079 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( | 1083 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( |
1080 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) | 1084 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) |
1081 | doc_dict['target_url'] = application_link | 1085 | doc_dict['target_url'] = application_link |
1086 | doc_id = doc_dict.get('id') | ||
1087 | doc_dict['excel_link'] = self.get_link(doc_id, business_type, file='excel') | ||
1082 | 1088 | ||
1083 | # total = len(doc_list) | 1089 | # total = len(doc_list) |
1084 | pagination = {'current': page, 'total': total, 'page_size': page_size} | 1090 | pagination = {'current': page, 'total': total, 'page_size': page_size} |
... | @@ -1092,18 +1098,23 @@ class DocView(GenericView, DocHandler): | ... | @@ -1092,18 +1098,23 @@ class DocView(GenericView, DocHandler): |
1092 | return response.ok(data=res) | 1098 | return response.ok(data=res) |
1093 | 1099 | ||
1094 | # 上传pdf,模拟下单 | 1100 | # 上传pdf,模拟下单 |
1095 | @use_args(upload_pdf_args, location='files') | 1101 | # @use_args(upload_pdf_args) |
1096 | def post(self, request, args): | 1102 | def post(self, request): |
1097 | random_int = random.randint(0, consts.TIME_NUM) | 1103 | random_int = random.randint(0, consts.TIME_NUM) |
1098 | metadata_version_id = str(int(time.time()) - random_int) | 1104 | metadata_version_id = str(int(time.time()) - random_int) |
1099 | 1105 | ||
1100 | pdf_file = args.get('pdf_file') | 1106 | pdf_file = request.FILES.get('pdf_file') |
1101 | if isinstance(pdf_file.name, str): | 1107 | if isinstance(pdf_file.name, str): |
1102 | if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): | 1108 | if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): |
1103 | self.invalid_params(msg='invalid params: not a PDF file') | 1109 | self.invalid_params(msg='invalid params: not a PDF file') |
1104 | 1110 | ||
1111 | business_type = request.POST.get('business_type', '') | ||
1112 | document_scheme = request.POST.get('document_scheme', '') | ||
1113 | data_source = request.POST.get('data_source', '') | ||
1114 | document_name = request.POST.get('document_name', '') | ||
1115 | args = {'business_type':business_type,'document_scheme':document_scheme,'data_source':data_source,'document_name':document_name,'pdf_file':pdf_file} | ||
1105 | # business_type = random.choice(consts.BUSINESS_TYPE_LIST) | 1116 | # business_type = random.choice(consts.BUSINESS_TYPE_LIST) |
1106 | business_type = consts.BUSINESS_TYPE_LIST[0] | 1117 | # business_type = consts.BUSINESS_TYPE_LIST[0] |
1107 | tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) | 1118 | tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) |
1108 | file_write(pdf_file, tmp_save_path) | 1119 | file_write(pdf_file, tmp_save_path) |
1109 | 1120 | ||
... | @@ -1126,8 +1137,8 @@ class DocView(GenericView, DocHandler): | ... | @@ -1126,8 +1137,8 @@ class DocView(GenericView, DocHandler): |
1126 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) | 1137 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) |
1127 | upload_finish_time = timezone.now() | 1138 | upload_finish_time = timezone.now() |
1128 | # document_scheme = random.choice(consts.DOC_SCHEME_LIST) | 1139 | # document_scheme = random.choice(consts.DOC_SCHEME_LIST) |
1129 | document_scheme = consts.DOC_SCHEME_LIST[1] | 1140 | # document_scheme = consts.DOC_SCHEME_LIST[1] |
1130 | data_source = random.choice(consts.DATA_SOURCE_LIST) | 1141 | # data_source = random.choice(consts.DATA_SOURCE_LIST) |
1131 | # UploadDocRecords.objects.create( | 1142 | # UploadDocRecords.objects.create( |
1132 | # metadata_version_id=metadata_version_id, | 1143 | # metadata_version_id=metadata_version_id, |
1133 | # application_id=application_id, | 1144 | # application_id=application_id, |
... | @@ -1166,8 +1177,25 @@ class DocView(GenericView, DocHandler): | ... | @@ -1166,8 +1177,25 @@ class DocView(GenericView, DocHandler): |
1166 | 1177 | ||
1167 | # 4. 选择队列进入 | 1178 | # 4. 选择队列进入 |
1168 | is_priority = False | 1179 | is_priority = False |
1169 | tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)] | 1180 | |
1170 | enqueue_res = rh.enqueue(tasks, is_priority) | 1181 | classify_1 = 0 |
1182 | # 电子合同 Econtract or OVP(FSM) | ||
1183 | if data_source == consts.DATA_SOURCE_LIST[2] or data_source == consts.DATA_SOURCE_LIST[3]: | ||
1184 | if document_scheme == consts.DOC_SCHEME_LIST[1]: | ||
1185 | for keyword, classify_1_tmp in consts.ECONTRACT_KEYWORDS_MAP.get(prefix): | ||
1186 | if keyword in document_name: | ||
1187 | classify_1 = classify_1_tmp | ||
1188 | break | ||
1189 | # FSM合同:WEP/MSI/SC | ||
1190 | elif data_source == consts.DATA_SOURCE_LIST[0] and document_scheme == consts.DOC_SCHEME_LIST[0]: | ||
1191 | for keyword, classify_1_tmp in consts.FSM_ECONTRACT_KEYWORDS_MAP.get(prefix): | ||
1192 | if keyword in document_name: | ||
1193 | classify_1 = classify_1_tmp | ||
1194 | break | ||
1195 | |||
1196 | # tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)] | ||
1197 | task = consts.SPLIT_STR.join([prefix, str(doc.id), str(classify_1)]) | ||
1198 | enqueue_res = rh.enqueue([task], is_priority) | ||
1171 | 1199 | ||
1172 | self.running_log.info('[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' | 1200 | self.running_log.info('[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' |
1173 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, | 1201 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, | ... | ... |
... | @@ -104,6 +104,62 @@ class GenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView): | ... | @@ -104,6 +104,62 @@ class GenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView): |
104 | def get_object(self): | 104 | def get_object(self): |
105 | return None | 105 | return None |
106 | 106 | ||
107 | class DocGenericView(LoggerMixin, GenericExceptionMixin, GenericAPIView): | ||
108 | need_print_logger = True | ||
109 | |||
110 | def print_logger(self, request): | ||
111 | # parameters = getattr(request, request.method, {}) | ||
112 | parameters = None | ||
113 | if not parameters: | ||
114 | parameters = getattr(request, 'data', {}) | ||
115 | if not parameters: | ||
116 | parameters = {} | ||
117 | parameters_string = '' | ||
118 | for key, value in parameters.items(): | ||
119 | parameters_string += '[%s=%s] ' % (key, value) | ||
120 | for key, value in self.kwargs.items(): | ||
121 | parameters_string += '[%s=%s] ' % (key, value) | ||
122 | if request.user and not isinstance(request.user, AnonymousUser): | ||
123 | user_id = request.user.id | ||
124 | else: | ||
125 | user_id = 0 | ||
126 | self.running_log.info('[%s_%s_request] with parameters [user_id=%s] %s' | ||
127 | % (self.__class__.__name__, request.method, | ||
128 | user_id, parameters_string)) | ||
129 | |||
130 | def dispatch(self, request, *args, **kwargs): | ||
131 | """ | ||
132 | `.dispatch()` is pretty much the same as Django's regular dispatch, | ||
133 | but with extra hooks for startup, finalize, and exception handling. | ||
134 | """ | ||
135 | self.args = args | ||
136 | self.kwargs = kwargs | ||
137 | request = self.initialize_request(request, *args, **kwargs) | ||
138 | self.request = request | ||
139 | self.headers = self.default_response_headers # deprecate? | ||
140 | try: | ||
141 | self.initial(request, *args, **kwargs) | ||
142 | |||
143 | # Get the appropriate handler method | ||
144 | if request.method.lower() in self.http_method_names: | ||
145 | handler = getattr(self, request.method.lower(), | ||
146 | self.http_method_not_allowed) | ||
147 | else: | ||
148 | handler = self.http_method_not_allowed | ||
149 | |||
150 | if self.need_print_logger: | ||
151 | self.print_logger(request) | ||
152 | |||
153 | response = handler(request, *args, **kwargs) | ||
154 | except Exception as exc: | ||
155 | response = self.handle_exception(exc) | ||
156 | |||
157 | self.response = self.finalize_response( | ||
158 | request, response, *args, **kwargs) | ||
159 | return self.response | ||
160 | |||
161 | def get_object(self): | ||
162 | return None | ||
107 | 163 | ||
108 | class IWABaseView: | 164 | class IWABaseView: |
109 | 165 | ... | ... |
-
Please register or sign in to post a comment