From a8d40eba22b238509375f3180354c214359b15ed Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 8 Aug 2024 16:14:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=AD=98=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask/__init__.py | 5 +++++ photo_mask/photo_mask.py | 12 ++++++++++-- photo_review/photo_review.py | 12 +++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/photo_mask/__init__.py b/photo_mask/__init__.py index 94172c3..8036e5d 100644 --- a/photo_mask/__init__.py +++ b/photo_mask/__init__.py @@ -1,5 +1,10 @@ +import socket + from paddleocr import PaddleOCR +# 主机名 +HOSTNAME = socket.gethostname() + """ 项目配置 """ diff --git a/photo_mask/photo_mask.py b/photo_mask/photo_mask.py index c9b84b7..1d781ff 100644 --- a/photo_mask/photo_mask.py +++ b/photo_mask/photo_mask.py @@ -8,7 +8,7 @@ from sqlalchemy import update, and_ from db import MysqlSession from db.mysql import ZxPhrec, ZxPhhd -from photo_mask import OCR, PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS, SIMILAR_CHAR +from photo_mask import OCR, PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS, SIMILAR_CHAR, HOSTNAME from ucloud import BUCKET, ufile from util import image_util, util @@ -216,7 +216,7 @@ def mask_photo(img_url, name, id_card_num, color=(255, 255, 255)): def photo_mask(pk_phhd, name, id_card_num): session = MysqlSession() - phrecs = session.query(ZxPhrec.cfjaddress).filter(and_( + phrecs = session.query(ZxPhrec.pk_phrec, ZxPhrec.cfjaddress).filter(and_( ZxPhrec.pk_phhd == pk_phhd, ZxPhrec.cRectype.in_(["3", "4"]) )).all() @@ -236,6 +236,13 @@ def photo_mask(pk_phhd, name, id_card_num): cv2.imwrite(temp_file.name, image) try: ufile.upload_file(phrec.cfjaddress, temp_file.name) + session = MysqlSession() + update_flag = (update(ZxPhrec).where(ZxPhrec.pk_phrec == phrec.pk_phrec).values( + paint_user=HOSTNAME, + paint_date=util.get_default_datetime())) + session.execute(update_flag) + session.commit() + session.close() except Exception as e: logging.error("上传图片出错", exc_info=e) finally: @@ -266,6 +273,7 @@ def main(): session = MysqlSession() update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values( paint_flag="8", + paint_user=HOSTNAME, paint_date=util.get_default_datetime())) session.execute(update_flag) session.commit() diff --git a/photo_review/photo_review.py b/photo_review/photo_review.py index 3edf36d..dcbf5eb 100644 --- a/photo_review/photo_review.py +++ b/photo_review/photo_review.py @@ -19,7 +19,6 @@ from ucloud import ufile from util import image_util, util from util.data_util import handle_date, handle_decimal, parse_department, handle_name, \ handle_insurance_type, handle_original_data, handle_hospital, handle_department, handle_id, handle_age, parse_money -from util.util import get_default_datetime # 合并信息抽取结果 @@ -86,7 +85,7 @@ def information_extraction(ie, phrecs): rotated_img = image_util.rotate(split_result["img"], int(angles[1])) ie_results.append({"result": ie_temp_image(ie, OCR, rotated_img), "angle": angles[1]}) - now = get_default_datetime() + now = util.get_default_datetime() for ie_result in ie_results: result_json = json.dumps(ie_result["result"], ensure_ascii=False) if len(result_json) > 5000: @@ -142,7 +141,7 @@ def save_or_update_ie(table, pk_phhd, data): obj = table(**data) session = MysqlSession() db_data = session.query(table).filter_by(pk_phhd=pk_phhd).one_or_none() - now = get_default_datetime() + now = util.get_default_datetime() if db_data: # 更新 db_data.update_time = now @@ -282,7 +281,7 @@ def main(): .distinct().limit(PHHD_BATCH_SIZE).all()) # 将状态改为正在识别中 pk_phhd_values = [phhd.pk_phhd for phhd in phhds] - update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd.in_(pk_phhd_values)).values(exsuccess_flag=2)) + update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd.in_(pk_phhd_values)).values(exsuccess_flag="2")) session.execute(update_flag) session.commit() session.close() @@ -294,7 +293,10 @@ def main(): # 识别完成更新标识 session = MysqlSession() - update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values(exsuccess_flag=8)) + update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values( + exsuccess_flag="8", + ref_id1=HOSTNAME, + check_time=util.get_default_datetime())) session.execute(update_flag) session.commit() session.close()