1bd26cf0 by 周伟奇

add result to db

1 parent 0347cfa5
......@@ -1018,3 +1018,16 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?>
CDATA_TEXT = """<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm>&lt;Request&gt;&lt;Framework&gt;&lt;UserName&gt;SFCHINA\qqcout0&lt;/UserName&gt;&lt;GUID&gt;70d0efcb-3bc2-4018-ac4e-681c8f3131b6&lt;/GUID&gt;&lt;DetailedTracingEnabled&gt;False&lt;/DetailedTracingEnabled&gt;&lt;ServiceName&gt;AMSWebService&lt;/ServiceName&gt;&lt;SupportsRedirection&gt;true&lt;/SupportsRedirection&gt;&lt;ServiceType&gt;Service&lt;/ServiceType&gt;&lt;/Framework&gt;&lt;Parms&gt;&lt;InputXML type="string"&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt;&amp;lt;InputXML&amp;gt; &amp;lt;Result&amp;gt; {0} &amp;lt;/Result&amp;gt;&amp;lt;AuthorizationData&amp;gt;&amp;lt;ServiceComponent&amp;gt;OCR&amp;lt;/ServiceComponent&amp;gt;&amp;lt;RoleId/&amp;gt;&amp;lt;CompanyId/&amp;gt;&amp;lt;/AuthorizationData&amp;gt;&amp;lt;/InputXML&amp;gt;&lt;/InputXML&gt;&lt;/Parms&gt;&lt;/Request&gt;</strXMLParm></Exec>]]>"""
RESULT_MAPPING = {
MVI_CLASSIFY: 'mvi_ocr',
IC_CLASSIFY: 'ic_ocr',
RP_CLASSIFY: 'rp_ocr',
BC_CLASSIFY: 'bc_ocr',
BL_CLASSIFY: 'bl_ocr',
UCI_CLASSIFY: 'uci_ocr',
EEP_CLASSIFY: 'eep_ocr',
DL_CLASSIFY: 'dl_ocr',
PP_CLASSIFY: 'pp_ocr',
MVC_CLASSIFY: 'mvc_ocr',
VAT_CLASSIFY: 'vat_ocr',
}
......
......@@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh
from apps.doc.named_enum import KeywordsType
from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception
from apps.doc.ocr.wb import BSWorkbook
from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords
from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult
from celery_compare.tasks import compare
......@@ -300,6 +300,9 @@ class Command(BaseCommand, LoggerMixin):
@staticmethod
def license_rebuild(license_summary):
ic_merge = False
rp_merge = False
for classify in (consts.IC_CLASSIFY, consts.MVI_CLASSIFY):
license_list = license_summary.get(classify)
......@@ -314,19 +317,29 @@ class Command(BaseCommand, LoggerMixin):
rp_side1_list = []
rp_side2_list = []
for license_dict in license_list:
is_rp = license_dict.pop('类别', '0')
if key in license_dict:
if license_dict.get('类别') == '1':
if is_rp == '1':
rp_side2_list.append(license_dict)
ic_side2_list.append(license_dict)
elif license_dict.get('类别') == '1':
elif is_rp == '1':
rp_side1_list.append(license_dict)
else:
ic_side1_list.append(license_dict)
ic_merge = len(ic_side1_list) == len(ic_side2_list) == 1
rp_merge = len(rp_side1_list) == len(rp_side2_list) == 1
ic_side1_list.extend(ic_side2_list)
rp_side1_list.extend(rp_side2_list)
license_summary[consts.RP_CLASSIFY] = rp_side1_list
license_list = ic_side1_list
if ic_side1_list:
license_list = ic_side1_list
else:
license_summary.pop(classify, None)
if rp_side1_list:
license_summary[consts.RP_CLASSIFY] = rp_side1_list
ic_side1_list = ic_side2_list = rp_side1_list = rp_side2_list = None
......@@ -345,6 +358,8 @@ class Command(BaseCommand, LoggerMixin):
price = round(price_total * 100 / (rate + 100), 2)
license_dict['不含税价(逻辑计算)'] = price
return ic_merge, rp_merge
def parse_img_path(self, img_path):
img_name, _ = os.path.splitext(os.path.basename(img_path))
......@@ -794,7 +809,7 @@ class Command(BaseCommand, LoggerMixin):
merged_bs_summary = self.rebuild_bs_summary(bs_summary, unknown_summary)
del unknown_summary
self.license_rebuild(license_summary)
ic_merge, rp_merge = self.license_rebuild(license_summary)
# self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary))
......@@ -872,9 +887,35 @@ class Command(BaseCommand, LoggerMixin):
self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str))
os.remove(excel_path)
finally:
pass
# TODO 识别结果存一张表,方便跑报表
# 更新OCR累计识别结果表
result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult
res_obj = result_class.objects.filter(application_id=doc.application_id).first()
if res_obj is None:
res_obj = result_class()
for classify, field in consts.RESULT_MAPPING.items():
license_list = license_summary.get(classify)
if not license_list:
continue
if classify == consts.IC_CLASSIFY and ic_merge:
new_res_list = list()
new_res_list.append(license_list[0].update(license_list[1]))
license_list = new_res_list
new_res_list = None
elif classify == consts.RP_CLASSIFY and rp_merge:
new_res_list = list()
new_res_list.append(license_list[0].update(license_list[1]))
license_list = new_res_list
new_res_list = None
old_res_str = getattr(res_obj, field)
if old_res_str is None:
last_res_str = json.dumps(license_list)
else
old_res_list = json.loads(old_res_str)
old_res_list.extend(license_list)
last_res_str = json.dumps(old_res_list)
setattr(res_obj, field, last_res_str)
res_obj.save()
# 触发比对
# compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare')
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!