cc0dc16d by 周伟奇

add license field order

1 parent e570371a
...@@ -583,60 +583,73 @@ OTHER_CLASSIFY = 2 ...@@ -583,60 +583,73 @@ OTHER_CLASSIFY = 2
583 # 身份证 583 # 身份证
584 IC_CN_NAME = '身份证' 584 IC_CN_NAME = '身份证'
585 IC_CLASSIFY = 33 585 IC_CLASSIFY = 33
586 IC_FIELD_ORDER = ()
586 # 增值税发票 587 # 增值税发票
587 VAT_CN_NAME = '增值税发票' 588 VAT_CN_NAME = '增值税发票'
588 VAT_CLASSIFY = 0 589 VAT_CLASSIFY = 0
590 VAT_FIELD_ORDER = ()
589 # 机动车登记证书 591 # 机动车登记证书
590 MVC_CN_NAME = '机动车登记证书' 592 MVC_CN_NAME = '机动车登记证书'
591 MVC_CLASSIFY = 28 593 MVC_CLASSIFY = 28
594 MVC_FIELD_ORDER = ()
595 MVC_SE_FIELD_ORDER = ()
592 # 机动车销售统一发票 596 # 机动车销售统一发票
593 MVI_CN_NAME = '机动车销售统一发票' 597 MVI_CN_NAME = '机动车销售统一发票'
594 MVI_CLASSIFY = 29 598 MVI_CLASSIFY = 29
599 MVI_FIELD_ORDER = ()
595 IC_PID = VAT_PID = MVC_PID = MVI_PID = None 600 IC_PID = VAT_PID = MVC_PID = MVI_PID = None
596 601
597 # 营业执照 602 # 营业执照
598 BL_CN_NAME = '营业执照' 603 BL_CN_NAME = '营业执照'
599 BL_CLASSIFY = 31 604 BL_CLASSIFY = 31
600 BL_PID = 41 605 BL_PID = 41
606 BL_FIELD_ORDER = ()
601 # 二手车发票 607 # 二手车发票
602 UCI_CN_NAME = '二手车发票' 608 UCI_CN_NAME = '二手车发票'
603 UCI_CLASSIFY = 1 609 UCI_CLASSIFY = 1
604 UCI_PID = 60 610 UCI_PID = 60
611 UCI_FIELD_ORDER = ()
605 # 港澳台通行证 612 # 港澳台通行证
606 EEP_CN_NAME = '港澳台通行证' 613 EEP_CN_NAME = '港澳台通行证'
607 EEP_CLASSIFY = 30 614 EEP_CLASSIFY = 30
608 EEP_PID = 1018 615 EEP_PID = 1018
616 EEP_FIELD_ORDER = ()
609 # 行驶证 617 # 行驶证
610 DL_CN_NAME = '行驶证' 618 DL_CN_NAME = '行驶证'
611 DL_CLASSIFY = 32 619 DL_CLASSIFY = 32
612 DL_PID = 5 620 DL_PID = 5
621 DL_FIELD_ORDER = ()
613 # 护照 622 # 护照
614 PP_CN_NAME = '护照' 623 PP_CN_NAME = '护照'
615 PP_CLASSIFY = 3 624 PP_CLASSIFY = 3
616 PP_PID = 8 625 PP_PID = 8
626 PP_FIELD_ORDER = ()
617 # 银行卡 627 # 银行卡
618 BC_CN_NAME = '银行卡' 628 BC_CN_NAME = '银行卡'
619 BC_CLASSIFY = 37 629 BC_CLASSIFY = 37
620 BC_PID = 4 630 BC_PID = 4
621 BC_FIELD = (('CardNum', '银行卡号'), 631 # BC_FIELD = (('CardNum', '银行卡号'),
622 ('BankName', '发卡行名称'), 632 # ('BankName', '发卡行名称'),
623 ('CardName', '银行卡名称'), 633 # ('CardName', '银行卡名称'),
624 ('BankCode', '发卡行代号'), 634 # ('BankCode', '发卡行代号'),
625 ('CardType', '银行卡类型'), 635 # ('CardType', '银行卡类型'),
626 ('Date', '日期')) 636 # ('Date', '日期'))
637 BC_FIELD_ORDER = (('BankName', '发卡行名称'),
638 ('CardNum', '银行卡号'),
639 ('CardType', '银行卡类型'),)
627 640
628 SUCCESS_CODE_SET = {'0', 0} 641 SUCCESS_CODE_SET = {'0', 0}
629 642
630 LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME)), 643 LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME, MVI_FIELD_ORDER)),
631 (IC_CLASSIFY, (IC_PID, IC_CN_NAME)), 644 (IC_CLASSIFY, (IC_PID, IC_CN_NAME, IC_FIELD_ORDER)),
632 (BC_CLASSIFY, (BC_PID, BC_CN_NAME)), 645 (BC_CLASSIFY, (BC_PID, BC_CN_NAME, BC_FIELD_ORDER)),
633 (BL_CLASSIFY, (BL_PID, BL_CN_NAME)), 646 (BL_CLASSIFY, (BL_PID, BL_CN_NAME, BL_FIELD_ORDER)),
634 (UCI_CLASSIFY, (UCI_PID, UCI_CN_NAME)), 647 (UCI_CLASSIFY, (UCI_PID, UCI_CN_NAME, UCI_FIELD_ORDER)),
635 (EEP_CLASSIFY, (EEP_PID, EEP_CN_NAME)), 648 (EEP_CLASSIFY, (EEP_PID, EEP_CN_NAME, EEP_FIELD_ORDER)),
636 (DL_CLASSIFY, (DL_PID, DL_CN_NAME)), 649 (DL_CLASSIFY, (DL_PID, DL_CN_NAME, DL_FIELD_ORDER)),
637 (PP_CLASSIFY, (PP_PID, PP_CN_NAME)), 650 (PP_CLASSIFY, (PP_PID, PP_CN_NAME, PP_FIELD_ORDER)),
638 (MVC_CLASSIFY, (MVC_PID, MVC_CN_NAME)), 651 (MVC_CLASSIFY, (MVC_PID, MVC_CN_NAME, MVC_FIELD_ORDER)),
639 (VAT_CLASSIFY, (VAT_PID, VAT_CN_NAME))) 652 (VAT_CLASSIFY, (VAT_PID, VAT_CN_NAME, VAT_FIELD_ORDER)))
640 653
641 LICENSE_CLASSIFY_MAPPING = dict(LICENSE_ORDER) 654 LICENSE_CLASSIFY_MAPPING = dict(LICENSE_ORDER)
642 655
......
...@@ -163,28 +163,23 @@ class Command(BaseCommand, LoggerMixin): ...@@ -163,28 +163,23 @@ class Command(BaseCommand, LoggerMixin):
163 if not license_data: 163 if not license_data:
164 skip_img.append(self.parse_img_path(img_path)) 164 skip_img.append(self.parse_img_path(img_path))
165 return 165 return
166 for license_dict in license_data: 166 license_summary.setdefault(classify, []).extend(license_data)
167 res_list = []
168 for field, value in license_dict.items():
169 res_list.append((field, value))
170 license_summary.setdefault(classify, []).append(res_list)
171 167
172 def license2_process(self, ocr_res_2, license_summary, pid, classify, skip_img, img_path): 168 def license2_process(self, ocr_res_2, license_summary, pid, classify, skip_img, img_path):
173 if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: 169 if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET:
174 if pid == consts.BC_PID: 170 if pid == consts.BC_PID:
175 # 银行卡 171 # 银行卡
176 res_list = [] 172 # res_dict = {}
177 for en_key, chn_key in consts.BC_FIELD: 173 # for en_key, chn_key in consts.BC_FIELD:
178 res_list.append((chn_key, ocr_res_2.get(en_key, ''))) 174 # res_dict[chn_key] = ocr_res_2.get(en_key, '')
179 license_summary.setdefault(classify, []).append(res_list) 175 license_summary.setdefault(classify, []).append(ocr_res_2)
180 else: 176 else:
181 # 营业执照、行驶证等 177 # 营业执照、行驶证等
182 for result_dict in ocr_res_2.get('ResultList', []): 178 for result_dict in ocr_res_2.get('ResultList', []):
183 res_list = [] 179 res_dict = {}
184 for field_dict in result_dict.get('FieldList', []): 180 for field_dict in result_dict.get('FieldList', []):
185 res_list.append( 181 res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '')
186 (field_dict.get('chn_key', ''), field_dict.get('value', ''))) 182 license_summary.setdefault(classify, []).append(res_dict)
187 license_summary.setdefault(classify, []).append(res_list)
188 else: 183 else:
189 skip_img.append(self.parse_img_path(img_path)) 184 skip_img.append(self.parse_img_path(img_path))
190 185
...@@ -229,7 +224,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -229,7 +224,7 @@ class Command(BaseCommand, LoggerMixin):
229 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 224 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1
230 self.license1_process(ocr_data, license_summary, classify, skip_img, img_path) 225 self.license1_process(ocr_data, license_summary, classify, skip_img, img_path)
231 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 226 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2
232 pid, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) 227 pid, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify)
233 json_data_2 = { 228 json_data_2 = {
234 "pid": str(pid), 229 "pid": str(pid),
235 "key": conf.OCR_KEY, 230 "key": conf.OCR_KEY,
...@@ -566,9 +561,11 @@ class Command(BaseCommand, LoggerMixin): ...@@ -566,9 +561,11 @@ class Command(BaseCommand, LoggerMixin):
566 561
567 # 4.2 重构Excel文件 562 # 4.2 重构Excel文件
568 wb.save(src_excel_path) 563 wb.save(src_excel_path)
569 wb.rebuild(merged_bs_summary, license_summary, skip_img) 564 wb.rebuild(merged_bs_summary, license_summary, skip_img, doc.document_scheme)
570 wb.save(excel_path) 565 wb.save(excel_path)
571 except EDMSException as e: 566 except EDMSException as e:
567 doc.status = DocStatus.PROCESS_FAILED.value
568 doc.save()
572 self.cronjob_log.error('{0} [process failed (edms download)] [business_type={1}] [doc_id={2}] ' 569 self.cronjob_log.error('{0} [process failed (edms download)] [business_type={1}] [doc_id={2}] '
573 '[err={3}]'.format(self.log_base, business_type, doc.id, e)) 570 '[err={3}]'.format(self.log_base, business_type, doc.id, e))
574 except Exception as e: 571 except Exception as e:
......
...@@ -242,14 +242,15 @@ class BSWorkbook(Workbook): ...@@ -242,14 +242,15 @@ class BSWorkbook(Workbook):
242 elif summary_cell.value in self.loan_keyword: 242 elif summary_cell.value in self.loan_keyword:
243 summary_cell.fill = self.loan_fill 243 summary_cell.fill = self.loan_fill
244 244
245 amount_error = False
245 # 3.3.余额转数值 246 # 3.3.余额转数值
246 over_cell = rows[consts.OVER_IDX] 247 over_cell = rows[consts.OVER_IDX]
247 try: 248 try:
248 over_cell.value = locale.atof(self.amount_format(over_cell.value)) 249 over_cell.value = locale.atof(self.amount_format(over_cell.value))
249 except Exception as e: 250 except Exception as e:
250 continue 251 amount_error = True
251 else: 252 else:
252 over_cell.number_format = numbers.FORMAT_NUMBER_COMMA_SEPARATED1 253 over_cell.number_format = numbers.FORMAT_NUMBER_00
253 254
254 # 3.4.金额转数值 255 # 3.4.金额转数值
255 try: 256 try:
...@@ -267,11 +268,11 @@ class BSWorkbook(Workbook): ...@@ -267,11 +268,11 @@ class BSWorkbook(Workbook):
267 if amount_cell.value > 0: 268 if amount_cell.value > 0:
268 amount_cell.value = -amount_cell.value 269 amount_cell.value = -amount_cell.value
269 except Exception as e: 270 except Exception as e:
270 continue 271 amount_error = True
271 else: 272 else:
272 if rows[consts.BORROW_IDX].value in consts.BORROW_OUTLAY_SET: 273 if rows[consts.BORROW_IDX].value in consts.BORROW_OUTLAY_SET:
273 amount_cell.value = -amount_cell.value 274 amount_cell.value = -amount_cell.value
274 amount_cell.number_format = numbers.FORMAT_NUMBER_COMMA_SEPARATED1 275 amount_cell.number_format = numbers.FORMAT_NUMBER_00
275 same_amount_mapping = amount_mapping.get(date_cell.value, {}) 276 same_amount_mapping = amount_mapping.get(date_cell.value, {})
276 fill_rows = same_amount_mapping.get(-amount_cell.value) 277 fill_rows = same_amount_mapping.get(-amount_cell.value)
277 if fill_rows: 278 if fill_rows:
...@@ -281,12 +282,12 @@ class BSWorkbook(Workbook): ...@@ -281,12 +282,12 @@ class BSWorkbook(Workbook):
281 amount_cell.value, []).append(row) 282 amount_cell.value, []).append(row)
282 283
283 # 3.5.核对结果 284 # 3.5.核对结果
284 if row > 2: 285 if row > 2 and not amount_error:
285 if is_reverse: 286 if is_reverse:
286 rows[consts.RESULT_IDX].value = '=IF(D{0}=SUM(D{1},C{0}), "{2}", "{3}")'.format( 287 rows[consts.RESULT_IDX].value = '=IF(D{0}=ROUND(SUM(D{1},C{0}),2), "{2}", "{3}")'.format(
287 row - 1, row, *self.proof_res) 288 row - 1, row, *self.proof_res)
288 else: 289 else:
289 rows[consts.RESULT_IDX].value = '=IF(D{0}=SUM(D{1},C{0}), "{2}", "{3}")'.format( 290 rows[consts.RESULT_IDX].value = '=IF(D{0}=ROUND(SUM(D{1},C{0}),2), "{2}", "{3}")'.format(
290 row, row - 1, *self.proof_res) 291 row, row - 1, *self.proof_res)
291 292
292 # 删除金额辅助列 293 # 删除金额辅助列
...@@ -358,15 +359,18 @@ class BSWorkbook(Workbook): ...@@ -358,15 +359,18 @@ class BSWorkbook(Workbook):
358 for sheet in summary.get('sheet'): 359 for sheet in summary.get('sheet'):
359 self.remove(self.get_sheet_by_name(sheet)) 360 self.remove(self.get_sheet_by_name(sheet))
360 361
361 def license_rebuild(self, license_summary): 362 def license_rebuild(self, license_summary, document_scheme):
362 for classify, (_, name) in consts.LICENSE_ORDER: 363 for classify, (_, name, field_order) in consts.LICENSE_ORDER:
363 res = license_summary.get(classify) 364 # 机动车登记证:CA和SE不同顺序
364 if res is None: 365 if classify == consts.MVC_CLASSIFY and document_scheme == consts.DOC_SCHEME_LIST[1]:
366 field_order = consts.MVC_SE_FIELD_ORDER
367 license_list = license_summary.get(classify)
368 if license_list is None:
365 continue 369 continue
366 ws = self.create_sheet(name) 370 ws = self.create_sheet(name)
367 for bl in res: 371 for license_dict in license_list:
368 for bl_field in bl: 372 for search_field, write_field in field_order:
369 ws.append(bl_field) 373 ws.append((write_field, license_dict.get(search_field, '')))
370 ws.append((None, )) 374 ws.append((None, ))
371 375
372 def skip_img_sheet(self, skip_img): 376 def skip_img_sheet(self, skip_img):
...@@ -376,7 +380,7 @@ class BSWorkbook(Workbook): ...@@ -376,7 +380,7 @@ class BSWorkbook(Workbook):
376 for img_tuple in skip_img: 380 for img_tuple in skip_img:
377 ws.append(img_tuple) 381 ws.append(img_tuple)
378 382
379 def rebuild(self, bs_summary, license_summary, skip_img): 383 def rebuild(self, bs_summary, license_summary, skip_img, document_scheme):
380 self.bs_rebuild(bs_summary) 384 self.bs_rebuild(bs_summary)
381 self.license_rebuild(license_summary) 385 self.license_rebuild(license_summary, document_scheme)
382 self.skip_img_sheet(skip_img) 386 self.skip_img_sheet(skip_img)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!