license result rebuild
Showing
4 changed files
with
61 additions
and
41 deletions
... | @@ -68,8 +68,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -68,8 +68,8 @@ class Command(BaseCommand, LoggerMixin): |
68 | nation = idcard_dict.get('民族') | 68 | nation = idcard_dict.get('民族') |
69 | if nation is None: | 69 | if nation is None: |
70 | continue | 70 | continue |
71 | if idcard_dict.get('类别') == '1': | 71 | # if idcard_dict.get('类别') == '1': |
72 | continue | 72 | # continue |
73 | content_list.append((idcard_dict.get('公民身份号码'), nation)) | 73 | content_list.append((idcard_dict.get('公民身份号码'), nation)) |
74 | if len(content_list) == 0: | 74 | if len(content_list) == 0: |
75 | continue | 75 | continue | ... | ... |
... | @@ -298,6 +298,54 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -298,6 +298,54 @@ class Command(BaseCommand, LoggerMixin): |
298 | else: | 298 | else: |
299 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 299 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) |
300 | 300 | ||
301 | @staticmethod | ||
302 | def license_rebuild(license_summary): | ||
303 | for classify in (consts.IC_CLASSIFY, consts.MVI_CLASSIFY): | ||
304 | |||
305 | license_list = license_summary.get(classify) | ||
306 | |||
307 | if not license_list: | ||
308 | continue | ||
309 | |||
310 | if classify == consts.IC_CLASSIFY: # 身份证、居住证分开,先正面,后反面 | ||
311 | key, _, _ = consts.FIELD_ORDER_MAP.get(classify) | ||
312 | ic_side1_list = [] | ||
313 | ic_side2_list = [] | ||
314 | rp_side1_list = [] | ||
315 | rp_side2_list = [] | ||
316 | for license_dict in license_list: | ||
317 | if key in license_dict: | ||
318 | if license_dict.get('类别') == '1': | ||
319 | rp_side2_list.append(license_dict) | ||
320 | ic_side2_list.append(license_dict) | ||
321 | elif license_dict.get('类别') == '1': | ||
322 | rp_side1_list.append(license_dict) | ||
323 | else: | ||
324 | ic_side1_list.append(license_dict) | ||
325 | |||
326 | ic_side1_list.extend(ic_side2_list) | ||
327 | rp_side1_list.extend(rp_side2_list) | ||
328 | license_summary[consts.RP_CLASSIFY] = rp_side1_list | ||
329 | license_list = ic_side1_list | ||
330 | |||
331 | ic_side1_list = ic_side2_list = rp_side1_list = rp_side2_list = None | ||
332 | |||
333 | if classify == consts.MVI_CLASSIFY: # 机动车销售统一发票, 增加不含税价(逻辑计算) | ||
334 | for license_dict in license_list: | ||
335 | price = '' | ||
336 | rate_str = license_dict.get('增值税税率') | ||
337 | price_total_str = license_dict.get('价税合计小写') | ||
338 | if rate_str is not None and price_total_str is not None: | ||
339 | try: | ||
340 | rate = int(rate_str.rstrip('%')) | ||
341 | price_total = float(price_total_str) | ||
342 | except Exception as e: | ||
343 | pass | ||
344 | else: | ||
345 | price = round(price_total * 100 / (rate + 100), 2) | ||
346 | license_dict['不含税价(逻辑计算)'] = price | ||
347 | |||
348 | |||
301 | def parse_img_path(self, img_path): | 349 | def parse_img_path(self, img_path): |
302 | img_name, _ = os.path.splitext(os.path.basename(img_path)) | 350 | img_name, _ = os.path.splitext(os.path.basename(img_path)) |
303 | part_list = img_name.split('_') | 351 | part_list = img_name.split('_') |
... | @@ -735,23 +783,24 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -735,23 +783,24 @@ class Command(BaseCommand, LoggerMixin): |
735 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_1)) | 783 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_1)) |
736 | self.online_log.info('{0} [ocr_1 res error] [img={1}]'.format(self.log_base, img_path)) | 784 | self.online_log.info('{0} [ocr_1 res error] [img={1}]'.format(self.log_base, img_path)) |
737 | 785 | ||
738 | self.online_log.info('{0} [task={1}] [bs_summary={2}] [unknown_summary={3}] ' | 786 | self.online_log.info('{0} [task={1}] [bs_summary={2}] [unknown_summary={3}]'.format( |
739 | '[license_summary={4}]'.format(self.log_base, task_str, bs_summary, | 787 | self.log_base, task_str, bs_summary, unknown_summary)) |
740 | unknown_summary, license_summary)) | ||
741 | 788 | ||
742 | self.license_log.info('[task={0}] [license_summary={1}]'.format(task_str, license_summary)) | 789 | # self.license_log.info('[task={0}] [license_summary={1}]'.format(task_str, license_summary)) |
743 | idcard_list = license_summary.get(consts.IC_CLASSIFY) | 790 | idcard_list = license_summary.get(consts.IC_CLASSIFY) |
744 | if idcard_list: | 791 | if idcard_list: |
745 | self.idcard_log.info('[task={0}] [idcard={1}]'.format(task_str, idcard_list)) | 792 | self.idcard_log.info('[task={0}] [idcard={1}]'.format(task_str, idcard_list)) |
746 | 793 | ||
747 | merged_bs_summary = self.rebuild_bs_summary(bs_summary, unknown_summary) | 794 | merged_bs_summary = self.rebuild_bs_summary(bs_summary, unknown_summary) |
795 | del unknown_summary | ||
796 | |||
797 | self.license_rebuild(license_summary) | ||
748 | 798 | ||
749 | self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary)) | 799 | # self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary)) |
750 | 800 | ||
751 | self.online_log.info('{0} [task={1}] [merged_bs_summary={2}] [unknown_summary={3}] ' | 801 | self.online_log.info('{0} [task={1}] [merged_bs_summary={2}] [license_summary={3}] ' |
752 | '[res_list={4}]'.format(self.log_base, task_str, merged_bs_summary, | 802 | '[res_list={4}]'.format(self.log_base, task_str, merged_bs_summary, |
753 | unknown_summary, res_list)) | 803 | license_summary, res_list)) |
754 | del unknown_summary | ||
755 | 804 | ||
756 | except Exception as e: | 805 | except Exception as e: |
757 | 806 | ... | ... |
... | @@ -638,43 +638,14 @@ class BSWorkbook(Workbook): | ... | @@ -638,43 +638,14 @@ class BSWorkbook(Workbook): |
638 | license_list = license_summary.get(classify) | 638 | license_list = license_summary.get(classify) |
639 | if not license_list: | 639 | if not license_list: |
640 | continue | 640 | continue |
641 | if classify == consts.IC_CLASSIFY: # 身份证、居住证先正面,后反面 | ||
642 | key, _, _ = consts.FIELD_ORDER_MAP.get(classify) | ||
643 | side1_list = [] | ||
644 | side2_list = [] | ||
645 | for license_dict in license_list: | ||
646 | if key in license_dict: | ||
647 | side2_list.append(license_dict) | ||
648 | else: | ||
649 | side1_list.append(license_dict) | ||
650 | side1_list.extend(side2_list) | ||
651 | license_list = side1_list | ||
652 | side2_list = None | ||
653 | side1_list = None | ||
654 | count = 0 | 641 | count = 0 |
655 | ws = self.create_sheet(name) | 642 | ws = self.create_sheet(name) |
656 | if scheme_diff and document_scheme == consts.DOC_SCHEME_LIST[1]: | 643 | if scheme_diff and document_scheme == consts.DOC_SCHEME_LIST[1]: |
657 | classify = consts.MVC_CLASSIFY_SE | 644 | classify = consts.MVC_CLASSIFY_SE |
658 | for license_dict in license_list: | 645 | for license_dict in license_list: |
659 | if classify == consts.IC_CLASSIFY and license_dict.get('类别') == '1': # 居住证处理 | ||
660 | license_summary.setdefault(consts.RP_CLASSIFY, []).append(license_dict) | ||
661 | continue | ||
662 | if side_diff: | 646 | if side_diff: |
663 | key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify) | 647 | key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify) |
664 | field_order = field_order_yes if key in license_dict else field_order_no | 648 | field_order = field_order_yes if key in license_dict else field_order_no |
665 | if classify == consts.MVI_CLASSIFY: # 机动车销售统一发票, 增加不含税价(逻辑计算) | ||
666 | price = '' | ||
667 | rate_str = license_dict.get('增值税税率') | ||
668 | price_total_str = license_dict.get('价税合计小写') | ||
669 | if rate_str is not None and price_total_str is not None: | ||
670 | try: | ||
671 | rate = int(rate_str.rstrip('%')) | ||
672 | price_total = float(price_total_str) | ||
673 | except Exception as e: | ||
674 | pass | ||
675 | else: | ||
676 | price = round(price_total*100/(rate+100), 2) | ||
677 | license_dict['不含税价(逻辑计算)'] = price | ||
678 | for search_field, write_field in field_order: | 649 | for search_field, write_field in field_order: |
679 | field_value = license_dict.get(search_field, '') | 650 | field_value = license_dict.get(search_field, '') |
680 | if isinstance(field_value, list): | 651 | if isinstance(field_value, list): | ... | ... |
... | @@ -40,8 +40,8 @@ class LoggerMixin: | ... | @@ -40,8 +40,8 @@ class LoggerMixin: |
40 | exception_log = logging.getLogger('exception') | 40 | exception_log = logging.getLogger('exception') |
41 | online_log = logging.getLogger('online') | 41 | online_log = logging.getLogger('online') |
42 | folder_log = logging.getLogger('folder') | 42 | folder_log = logging.getLogger('folder') |
43 | bs_log = logging.getLogger('bs') | 43 | # bs_log = logging.getLogger('bs') |
44 | license_log = logging.getLogger('license') | 44 | # license_log = logging.getLogger('license') |
45 | idcard_log = logging.getLogger('idcard') | 45 | idcard_log = logging.getLogger('idcard') |
46 | 46 | ||
47 | 47 | ... | ... |
-
Please register or sign in to post a comment