merge wangcong dev
Showing
7 changed files
with
155 additions
and
3 deletions
| ... | @@ -51,7 +51,7 @@ from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult | ... | @@ -51,7 +51,7 @@ from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult |
| 51 | from .mixins import DocHandler, MPOSHandler | 51 | from .mixins import DocHandler, MPOSHandler |
| 52 | from . import consts | 52 | from . import consts |
| 53 | from apps.account.authentication import OAuth2AuthenticationWithUser | 53 | from apps.account.authentication import OAuth2AuthenticationWithUser |
| 54 | from celery_compare.tasks import compare | 54 | from celery_compare.tasks import compare, pos_compare |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | class CustomDate(fields.Date): | 57 | class CustomDate(fields.Date): |
| ... | @@ -781,7 +781,9 @@ class SECompareView(GenericView): | ... | @@ -781,7 +781,9 @@ class SECompareView(GenericView): |
| 781 | bank_obj.on_off = False | 781 | bank_obj.on_off = False |
| 782 | bank_obj.save() | 782 | bank_obj.save() |
| 783 | 783 | ||
| 784 | return response.ok() | 784 | compare_result = pos_compare(content) |
| 785 | |||
| 786 | return response.ok(data=compare_result) | ||
| 785 | 787 | ||
| 786 | post.openapi_doc = ''' | 788 | post.openapi_doc = ''' |
| 787 | tags: [info] | 789 | tags: [info] | ... | ... |
| ... | @@ -39,6 +39,7 @@ from apps.doc.exceptions import GCAPException | ... | @@ -39,6 +39,7 @@ from apps.doc.exceptions import GCAPException |
| 39 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType | 39 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType |
| 40 | from common.tools.comparison import cp | 40 | from common.tools.comparison import cp |
| 41 | from common.tools.des import decode_des | 41 | from common.tools.des import decode_des |
| 42 | from pos import pos | ||
| 42 | 43 | ||
| 43 | compare_log = logging.getLogger('compare') | 44 | compare_log = logging.getLogger('compare') |
| 44 | log_base = '[Compare]' | 45 | log_base = '[Compare]' |
| ... | @@ -3198,3 +3199,136 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True | ... | @@ -3198,3 +3199,136 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True |
| 3198 | compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' | 3199 | compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' |
| 3199 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, | 3200 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, |
| 3200 | traceback.format_exc())) | 3201 | traceback.format_exc())) |
| 3202 | |||
| 3203 | |||
| 3204 | # pos接口 | ||
| 3205 | def pos_compare(pos_content, application_id, application_entity, uniq_seq, ocr_res_id=None, is_ca=True, is_cms=False): | ||
| 3206 | # POS: application_id, application_entity, uniq_seq, None | ||
| 3207 | # OCR: application_id, business_type(application_entity), None, ocr_res_id | ||
| 3208 | compare_log.info('{0} [pos_compare] [entity={1}] [id={2}] [uniq_seq={3}] [is_ca={4}] ' | ||
| 3209 | '[is_cms={5}]'.format(log_base, application_entity, application_id, uniq_seq, | ||
| 3210 | is_ca, is_cms)) | ||
| 3211 | |||
| 3212 | # 根据application_id查找最新的比对信息,如果没有,结束 | ||
| 3213 | # if is_ca: | ||
| 3214 | # comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo | ||
| 3215 | # else: | ||
| 3216 | # if application_entity == consts.HIL_PREFIX: | ||
| 3217 | # comparison_class = HILSECMSInfo if is_cms else HILSEComparisonInfo | ||
| 3218 | # else: | ||
| 3219 | # comparison_class = AFCSECMSInfo if is_cms else AFCSEComparisonInfo | ||
| 3220 | # last_obj = comparison_class.objects.filter(application_id=application_id).last() | ||
| 3221 | # if last_obj is None: | ||
| 3222 | # compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] ' | ||
| 3223 | # '[is_ca={4}] [is_cms]={5}'.format(log_base, application_entity, application_id, uniq_seq, | ||
| 3224 | # is_ca, is_cms)) | ||
| 3225 | # return | ||
| 3226 | |||
| 3227 | # 根据application_id查找OCR累计结果指定license字段,如果没有,结束 | ||
| 3228 | if is_ca: | ||
| 3229 | result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult | ||
| 3230 | ca_ocr_res_dict = dict() | ||
| 3231 | else: | ||
| 3232 | result_class = HILSEOCRResult if application_entity == consts.HIL_PREFIX else AFCSEOCRResult | ||
| 3233 | ca_result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult | ||
| 3234 | # if ocr_res_id is None: | ||
| 3235 | ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values( | ||
| 3236 | *consts.CA_ADD_COMPARE_FIELDS).first() | ||
| 3237 | # else: | ||
| 3238 | # ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values( | ||
| 3239 | # *consts.CA_ADD_COMPARE_FIELDS).first() | ||
| 3240 | ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first() | ||
| 3241 | if ocr_res_dict is None: | ||
| 3242 | compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' | ||
| 3243 | '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id, | ||
| 3244 | uniq_seq, ocr_res_id, is_ca, is_cms)) | ||
| 3245 | return | ||
| 3246 | |||
| 3247 | pos_content_obj = json.loads(pos_content) | ||
| 3248 | if is_ca: | ||
| 3249 | # 比对逻辑 | ||
| 3250 | # compare_info = get_ca_compare_info(pos_content_obj) | ||
| 3251 | # compare_result, total_fields, failed_count = ca_compare_process(compare_info, ocr_res_dict) | ||
| 3252 | # compare_log.info('{0} [CA] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [result={4}]'.format( | ||
| 3253 | # log_base, application_entity, application_id, ocr_res_id, compare_result)) | ||
| 3254 | # ca_compare(application_id, application_entity, ocr_res_id, pos_content_obj, ocr_res_dict) | ||
| 3255 | compare_result = pos.PosCompare.ca_compare(pos_content_obj, ocr_res_dict) | ||
| 3256 | else: | ||
| 3257 | id_res_list = [] | ||
| 3258 | for field_name in consts.CA_ADD_COMPARE_FIELDS: | ||
| 3259 | if field_name == consts.IC_OCR_FIELD: | ||
| 3260 | id_res_list.append(ocr_res_dict.get(field_name)) | ||
| 3261 | id_res_list.append(ca_ocr_res_dict.get(field_name) if isinstance(ca_ocr_res_dict, dict) else None) | ||
| 3262 | |||
| 3263 | if isinstance(ca_ocr_res_dict, dict) and isinstance(ca_ocr_res_dict.get(field_name), str): | ||
| 3264 | tmp_ca_result = json.loads(ca_ocr_res_dict.get(field_name)) | ||
| 3265 | if isinstance(ocr_res_dict.get(field_name), str): | ||
| 3266 | tmp_se_result = json.loads(ocr_res_dict.get(field_name)) | ||
| 3267 | tmp_ca_result.extend(tmp_se_result) | ||
| 3268 | ocr_res_dict[field_name] = json.dumps(tmp_ca_result) | ||
| 3269 | # auto settlement | ||
| 3270 | # auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement | ||
| 3271 | # auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first() | ||
| 3272 | # bank_class = HILbankVerification if application_entity == consts.HIL_PREFIX else AFCbankVerification | ||
| 3273 | # ignore_bank = bank_class.objects.filter(application_id=application_id, on_off=True).exists() | ||
| 3274 | # if auto_obj is not None: | ||
| 3275 | # auto_result = se_compare_auto(application_id, application_entity, ocr_res_id, pos_content_obj, ocr_res_dict, auto_obj, ignore_bank, id_res_list) | ||
| 3276 | # else: | ||
| 3277 | # auto_result = None | ||
| 3278 | # | ||
| 3279 | # full_result = se_compare(application_id, application_entity, ocr_res_id, pos_content_obj, ocr_res_dict, is_cms, auto_result, ignore_bank, id_res_list) | ||
| 3280 | # | ||
| 3281 | # if auto_obj is not None: | ||
| 3282 | # try: | ||
| 3283 | # auto_obj.ocr_whole_result_pass = full_result | ||
| 3284 | # auto_obj.save() | ||
| 3285 | # compare_log.info('{0} [Auto SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | ||
| 3286 | # log_base, application_entity, application_id, ocr_res_id)) | ||
| 3287 | # except Exception as e: | ||
| 3288 | # compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' | ||
| 3289 | # '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, | ||
| 3290 | # traceback.format_exc())) | ||
| 3291 | |||
| 3292 | # result_table = HILCACompareResult if application_entity == consts.HIL_PREFIX else AFCCACompareResult | ||
| 3293 | # res_obj = result_table.objects.filter(application_id=application_id).first() | ||
| 3294 | compare_result = pos.PosCompare.se_compare(pos_content_obj, ocr_res_dict, id_res_list=id_res_list) | ||
| 3295 | return pos_result_output(compare_result) | ||
| 3296 | |||
| 3297 | |||
| 3298 | # pos输出解析 | ||
| 3299 | def pos_result_output(compare_result): | ||
| 3300 | result_obj = json.loads(compare_result) | ||
| 3301 | license_map = dict() | ||
| 3302 | for item in result_obj: | ||
| 3303 | license_en = item.get("License") | ||
| 3304 | if license_map.get(license_en): | ||
| 3305 | license_map.get(license_en).append(item) | ||
| 3306 | else: | ||
| 3307 | info_items = [item] | ||
| 3308 | license_map[license_en] = info_items | ||
| 3309 | |||
| 3310 | is_pass = True | ||
| 3311 | particulars = [] | ||
| 3312 | for license, license_items in license_map.items(): | ||
| 3313 | particular = {"object_name": license} | ||
| 3314 | # license_comments = OCR_COMPARE_COMMENT.get(license) | ||
| 3315 | # if not license_comments: | ||
| 3316 | # continue | ||
| 3317 | fields = [] | ||
| 3318 | particular["fields"] = fields | ||
| 3319 | for license_item in license_items: | ||
| 3320 | field = dict() | ||
| 3321 | field["input"] = license_item.get("Input") | ||
| 3322 | field["ocr"] = license_item.get("OCR") | ||
| 3323 | field["field_is_pass"] = license_item.get("Result") == 'Y' | ||
| 3324 | if not field["field_is_pass"]: | ||
| 3325 | is_pass = False | ||
| 3326 | field["comments"] = license_item.get('comments', '') | ||
| 3327 | fields.append(field) | ||
| 3328 | particular["fields"] = fields | ||
| 3329 | particulars.append(particular) | ||
| 3330 | |||
| 3331 | return { | ||
| 3332 | "is_pass": is_pass, | ||
| 3333 | "particulars": particulars | ||
| 3334 | } | ... | ... |
| 1 | import re | 1 | import re |
| 2 | import time | 2 | import time |
| 3 | import numpy as np | 3 | import numpy as np |
| 4 | from datetime import datetime | 4 | from datetime import datetime, timedelta |
| 5 | from dateutil.relativedelta import relativedelta | 5 | from dateutil.relativedelta import relativedelta |
| 6 | from .rmb_lower import rmb_handler | 6 | from .rmb_lower import rmb_handler |
| 7 | # from .rmb_upper import to_rmb_upper | 7 | # from .rmb_upper import to_rmb_upper |
| ... | @@ -29,6 +29,8 @@ class Comparison: | ... | @@ -29,6 +29,8 @@ class Comparison: |
| 29 | 29 | ||
| 30 | self.RESULT_Y = 'Y' | 30 | self.RESULT_Y = 'Y' |
| 31 | self.RESULT_N = 'N' | 31 | self.RESULT_N = 'N' |
| 32 | self.RESULT_N1 = 'N1' | ||
| 33 | self.RESULT_N2 = 'N2' | ||
| 32 | self.RESULT_NA = 'NA' | 34 | self.RESULT_NA = 'NA' |
| 33 | 35 | ||
| 34 | self.TRANS_MAP = { | 36 | self.TRANS_MAP = { |
| ... | @@ -608,6 +610,20 @@ class Comparison: | ... | @@ -608,6 +610,20 @@ class Comparison: |
| 608 | return self.RESULT_N | 610 | return self.RESULT_N |
| 609 | return self.se_date_compare_2(input_str, ocr_date_set.pop(), three_month=True) | 611 | return self.se_date_compare_2(input_str, ocr_date_set.pop(), three_month=True) |
| 610 | 612 | ||
| 613 | def se_date_compare_pos(self, input_str, ocr_str, **kwargs): | ||
| 614 | try: | ||
| 615 | ocr_date = datetime.strptime(ocr_str, "%Y-%m-%d").date() | ||
| 616 | today = datetime.now().date() | ||
| 617 | if ocr_date < today: | ||
| 618 | return self.RESULT_N1 | ||
| 619 | elif today <= ocr_date <= (today + timedelta(days=8)): | ||
| 620 | return self.RESULT_N2 | ||
| 621 | elif ocr_date > (today + timedelta(days=8)): | ||
| 622 | return self.RESULT_Y | ||
| 623 | except Exception as e: | ||
| 624 | return self.RESULT_N | ||
| 625 | return self.RESULT_N | ||
| 626 | |||
| 611 | 627 | ||
| 612 | cp = Comparison() | 628 | cp = Comparison() |
| 613 | 629 | ... | ... |
src/pos/__init__.py
0 → 100644
File mode changed
src/pos/pos.py
0 → 100644
This diff is collapsed.
Click to expand it.
src/pos/pos_compare.py
0 → 100644
This diff is collapsed.
Click to expand it.
src/pos/pos_consts.py
0 → 100644
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment