add result to db
Showing
2 changed files
with
60 additions
and
6 deletions
... | @@ -1018,3 +1018,16 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?> | ... | @@ -1018,3 +1018,16 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?> |
1018 | 1018 | ||
1019 | CDATA_TEXT = """<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm><Request><Framework><UserName>SFCHINA\qqcout0</UserName><GUID>70d0efcb-3bc2-4018-ac4e-681c8f3131b6</GUID><DetailedTracingEnabled>False</DetailedTracingEnabled><ServiceName>AMSWebService</ServiceName><SupportsRedirection>true</SupportsRedirection><ServiceType>Service</ServiceType></Framework><Parms><InputXML type="string">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;InputXML&gt; &lt;Result&gt; {0} &lt;/Result&gt;&lt;AuthorizationData&gt;&lt;ServiceComponent&gt;OCR&lt;/ServiceComponent&gt;&lt;RoleId/&gt;&lt;CompanyId/&gt;&lt;/AuthorizationData&gt;&lt;/InputXML&gt;</InputXML></Parms></Request></strXMLParm></Exec>]]>""" | 1019 | CDATA_TEXT = """<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm><Request><Framework><UserName>SFCHINA\qqcout0</UserName><GUID>70d0efcb-3bc2-4018-ac4e-681c8f3131b6</GUID><DetailedTracingEnabled>False</DetailedTracingEnabled><ServiceName>AMSWebService</ServiceName><SupportsRedirection>true</SupportsRedirection><ServiceType>Service</ServiceType></Framework><Parms><InputXML type="string">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;InputXML&gt; &lt;Result&gt; {0} &lt;/Result&gt;&lt;AuthorizationData&gt;&lt;ServiceComponent&gt;OCR&lt;/ServiceComponent&gt;&lt;RoleId/&gt;&lt;CompanyId/&gt;&lt;/AuthorizationData&gt;&lt;/InputXML&gt;</InputXML></Parms></Request></strXMLParm></Exec>]]>""" |
1020 | 1020 | ||
1021 | RESULT_MAPPING = { | ||
1022 | MVI_CLASSIFY: 'mvi_ocr', | ||
1023 | IC_CLASSIFY: 'ic_ocr', | ||
1024 | RP_CLASSIFY: 'rp_ocr', | ||
1025 | BC_CLASSIFY: 'bc_ocr', | ||
1026 | BL_CLASSIFY: 'bl_ocr', | ||
1027 | UCI_CLASSIFY: 'uci_ocr', | ||
1028 | EEP_CLASSIFY: 'eep_ocr', | ||
1029 | DL_CLASSIFY: 'dl_ocr', | ||
1030 | PP_CLASSIFY: 'pp_ocr', | ||
1031 | MVC_CLASSIFY: 'mvc_ocr', | ||
1032 | VAT_CLASSIFY: 'vat_ocr', | ||
1033 | } | ... | ... |
... | @@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh | ... | @@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh |
23 | from apps.doc.named_enum import KeywordsType | 23 | from apps.doc.named_enum import KeywordsType |
24 | from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception | 24 | from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception |
25 | from apps.doc.ocr.wb import BSWorkbook | 25 | from apps.doc.ocr.wb import BSWorkbook |
26 | from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords | 26 | from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult |
27 | from celery_compare.tasks import compare | 27 | from celery_compare.tasks import compare |
28 | 28 | ||
29 | 29 | ||
... | @@ -300,6 +300,9 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -300,6 +300,9 @@ class Command(BaseCommand, LoggerMixin): |
300 | 300 | ||
301 | @staticmethod | 301 | @staticmethod |
302 | def license_rebuild(license_summary): | 302 | def license_rebuild(license_summary): |
303 | ic_merge = False | ||
304 | rp_merge = False | ||
305 | |||
303 | for classify in (consts.IC_CLASSIFY, consts.MVI_CLASSIFY): | 306 | for classify in (consts.IC_CLASSIFY, consts.MVI_CLASSIFY): |
304 | 307 | ||
305 | license_list = license_summary.get(classify) | 308 | license_list = license_summary.get(classify) |
... | @@ -314,19 +317,29 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -314,19 +317,29 @@ class Command(BaseCommand, LoggerMixin): |
314 | rp_side1_list = [] | 317 | rp_side1_list = [] |
315 | rp_side2_list = [] | 318 | rp_side2_list = [] |
316 | for license_dict in license_list: | 319 | for license_dict in license_list: |
320 | is_rp = license_dict.pop('类别', '0') | ||
317 | if key in license_dict: | 321 | if key in license_dict: |
318 | if license_dict.get('类别') == '1': | 322 | if is_rp == '1': |
319 | rp_side2_list.append(license_dict) | 323 | rp_side2_list.append(license_dict) |
320 | ic_side2_list.append(license_dict) | 324 | ic_side2_list.append(license_dict) |
321 | elif license_dict.get('类别') == '1': | 325 | elif is_rp == '1': |
322 | rp_side1_list.append(license_dict) | 326 | rp_side1_list.append(license_dict) |
323 | else: | 327 | else: |
324 | ic_side1_list.append(license_dict) | 328 | ic_side1_list.append(license_dict) |
325 | 329 | ||
330 | ic_merge = len(ic_side1_list) == len(ic_side2_list) == 1 | ||
331 | rp_merge = len(rp_side1_list) == len(rp_side2_list) == 1 | ||
332 | |||
326 | ic_side1_list.extend(ic_side2_list) | 333 | ic_side1_list.extend(ic_side2_list) |
327 | rp_side1_list.extend(rp_side2_list) | 334 | rp_side1_list.extend(rp_side2_list) |
328 | license_summary[consts.RP_CLASSIFY] = rp_side1_list | 335 | |
336 | if ic_side1_list: | ||
329 | license_list = ic_side1_list | 337 | license_list = ic_side1_list |
338 | else: | ||
339 | license_summary.pop(classify, None) | ||
340 | |||
341 | if rp_side1_list: | ||
342 | license_summary[consts.RP_CLASSIFY] = rp_side1_list | ||
330 | 343 | ||
331 | ic_side1_list = ic_side2_list = rp_side1_list = rp_side2_list = None | 344 | ic_side1_list = ic_side2_list = rp_side1_list = rp_side2_list = None |
332 | 345 | ||
... | @@ -345,6 +358,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -345,6 +358,8 @@ class Command(BaseCommand, LoggerMixin): |
345 | price = round(price_total * 100 / (rate + 100), 2) | 358 | price = round(price_total * 100 / (rate + 100), 2) |
346 | license_dict['不含税价(逻辑计算)'] = price | 359 | license_dict['不含税价(逻辑计算)'] = price |
347 | 360 | ||
361 | return ic_merge, rp_merge | ||
362 | |||
348 | 363 | ||
349 | def parse_img_path(self, img_path): | 364 | def parse_img_path(self, img_path): |
350 | img_name, _ = os.path.splitext(os.path.basename(img_path)) | 365 | img_name, _ = os.path.splitext(os.path.basename(img_path)) |
... | @@ -794,7 +809,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -794,7 +809,7 @@ class Command(BaseCommand, LoggerMixin): |
794 | merged_bs_summary = self.rebuild_bs_summary(bs_summary, unknown_summary) | 809 | merged_bs_summary = self.rebuild_bs_summary(bs_summary, unknown_summary) |
795 | del unknown_summary | 810 | del unknown_summary |
796 | 811 | ||
797 | self.license_rebuild(license_summary) | 812 | ic_merge, rp_merge = self.license_rebuild(license_summary) |
798 | 813 | ||
799 | # self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary)) | 814 | # self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary)) |
800 | 815 | ||
... | @@ -872,9 +887,35 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -872,9 +887,35 @@ class Command(BaseCommand, LoggerMixin): |
872 | self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str)) | 887 | self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str)) |
873 | os.remove(excel_path) | 888 | os.remove(excel_path) |
874 | finally: | 889 | finally: |
875 | pass | ||
876 | # TODO 识别结果存一张表,方便跑报表 | 890 | # TODO 识别结果存一张表,方便跑报表 |
877 | # 更新OCR累计识别结果表 | 891 | # 更新OCR累计识别结果表 |
892 | result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult | ||
893 | res_obj = result_class.objects.filter(application_id=doc.application_id).first() | ||
894 | if res_obj is None: | ||
895 | res_obj = result_class() | ||
896 | for classify, field in consts.RESULT_MAPPING.items(): | ||
897 | license_list = license_summary.get(classify) | ||
898 | if not license_list: | ||
899 | continue | ||
900 | if classify == consts.IC_CLASSIFY and ic_merge: | ||
901 | new_res_list = list() | ||
902 | new_res_list.append(license_list[0].update(license_list[1])) | ||
903 | license_list = new_res_list | ||
904 | new_res_list = None | ||
905 | elif classify == consts.RP_CLASSIFY and rp_merge: | ||
906 | new_res_list = list() | ||
907 | new_res_list.append(license_list[0].update(license_list[1])) | ||
908 | license_list = new_res_list | ||
909 | new_res_list = None | ||
910 | old_res_str = getattr(res_obj, field) | ||
911 | if old_res_str is None: | ||
912 | last_res_str = json.dumps(license_list) | ||
913 | else | ||
914 | old_res_list = json.loads(old_res_str) | ||
915 | old_res_list.extend(license_list) | ||
916 | last_res_str = json.dumps(old_res_list) | ||
917 | setattr(res_obj, field, last_res_str) | ||
918 | res_obj.save() | ||
878 | 919 | ||
879 | # 触发比对 | 920 | # 触发比对 |
880 | # compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare') | 921 | # compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare') | ... | ... |
-
Please register or sign in to post a comment