dd512564 by 周伟奇

pdf file check

1 parent e80661aa
1 import copy 1 import copy
2 2
3 TIME_NUM = 600000000
4
3 PAGE_DEFAULT = 1 5 PAGE_DEFAULT = 1
4 PAGE_SIZE_DEFAULT = 10 6 PAGE_SIZE_DEFAULT = 10
5 7
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
2 import time 2 import time
3 import random 3 import random
4 import datetime 4 import datetime
5 import fitz
5 from django.utils import timezone 6 from django.utils import timezone
6 from django.db.utils import IntegrityError 7 from django.db.utils import IntegrityError
7 from django.db.models import Q 8 from django.db.models import Q
...@@ -273,8 +274,17 @@ class DocView(GenericView, DocHandler): ...@@ -273,8 +274,17 @@ class DocView(GenericView, DocHandler):
273 # 上传pdf,模拟下单 274 # 上传pdf,模拟下单
274 @use_args(upload_pdf_args, location='files') 275 @use_args(upload_pdf_args, location='files')
275 def post(self, request, args): 276 def post(self, request, args):
277 random_int = random.randint(0, consts.TIME_NUM)
278 metadata_version_id = str(int(time.time()) - random_int)
279
280 # tmp_save_path = os.path.join(conf.DATA_DIR, '{0}.pdf'.format(metadata_version_id))
281 pdf_file = args.get('pdf_file')
282 # file_write(pdf_file, tmp_save_path)
283
284 if not fitz.open("pdf", pdf_file).isPDF:
285 raise self.invalid_params(msg='invalid params: not a PDF file')
286
276 # 1. 上传信息记录 287 # 1. 上传信息记录
277 metadata_version_id = str(int(time.time()))
278 application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) 288 application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id)
279 upload_finish_time = timezone.now() 289 upload_finish_time = timezone.now()
280 document_scheme = random.choice(consts.DOC_SCHEME_LIST) 290 document_scheme = random.choice(consts.DOC_SCHEME_LIST)
...@@ -308,17 +318,18 @@ class DocView(GenericView, DocHandler): ...@@ -308,17 +318,18 @@ class DocView(GenericView, DocHandler):
308 data_source=data_source, 318 data_source=data_source,
309 upload_finish_time=upload_finish_time, 319 upload_finish_time=upload_finish_time,
310 ) 320 )
311 # 3. 选择队列进入
312 is_priority = False
313 tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)]
314 enqueue_res = rh.enqueue(tasks, is_priority)
315 321
316 pdf_file = args.get('pdf_file') 322 # 3.pdf文件移动
317 save_dir_path = os.path.join(conf.DATA_DIR, business_type, str(doc.id)) 323 save_dir_path = os.path.join(conf.DATA_DIR, business_type, str(doc.id))
318 save_file_path = os.path.join(save_dir_path, '{0}.pdf'.format(doc.id)) 324 save_file_path = os.path.join(save_dir_path, '{0}.pdf'.format(doc.id))
319 os.makedirs(save_dir_path, exist_ok=True) 325 os.makedirs(save_dir_path, exist_ok=True)
320 file_write(pdf_file, save_file_path) 326 file_write(pdf_file, save_file_path)
321 327
328 # 4. 选择队列进入
329 is_priority = False
330 tasks = ['{0}{1}{2}'.format(prefix, consts.SPLIT_STR, doc.id)]
331 enqueue_res = rh.enqueue(tasks, is_priority)
332
322 self.running_log.info('[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' 333 self.running_log.info('[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] '
323 '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, 334 '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id,
324 is_priority, enqueue_res)) 335 is_priority, enqueue_res))
......
1 import pyodbc 1 import pyodbc
2 2
3 cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;UID=SA;PWD=pwd', autocommit=True) 3 cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
4 4
5 cursor = cnxn.cursor() 5 cursor = cnxn.cursor()
6 cursor.execute("create database afc") 6 cursor.execute("create database afc")
...@@ -455,7 +455,7 @@ afc_sql = """ ...@@ -455,7 +455,7 @@ afc_sql = """
455 on afc_doc (start_time, end_time); 455 on afc_doc (start_time, end_time);
456 """ 456 """
457 457
458 hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=hil;UID=SA;PWD=pwd', autocommit=True) 458 hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
459 459
460 hil_cursor = hil_cnxn.cursor() 460 hil_cursor = hil_cnxn.cursor()
461 hil_cursor.execute(hil_sql_1) 461 hil_cursor.execute(hil_sql_1)
...@@ -464,7 +464,7 @@ hil_cursor.execute(hil_sql_2) ...@@ -464,7 +464,7 @@ hil_cursor.execute(hil_sql_2)
464 hil_cursor.close() 464 hil_cursor.close()
465 hil_cnxn.close() 465 hil_cnxn.close()
466 466
467 afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=afc;UID=SA;PWD=pwd', autocommit=True) 467 afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
468 468
469 afc_cursor = afc_cnxn.cursor() 469 afc_cursor = afc_cnxn.cursor()
470 afc_cursor.execute(afc_sql) 470 afc_cursor.execute(afc_sql)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!