补充存表

This commit is contained in:
2024-08-08 16:14:11 +08:00
parent 2b6ba7b71e
commit a8d40eba22
3 changed files with 22 additions and 7 deletions

View File

@@ -1,5 +1,10 @@
import socket
from paddleocr import PaddleOCR from paddleocr import PaddleOCR
# 主机名
HOSTNAME = socket.gethostname()
""" """
项目配置 项目配置
""" """

View File

@@ -8,7 +8,7 @@ from sqlalchemy import update, and_
from db import MysqlSession from db import MysqlSession
from db.mysql import ZxPhrec, ZxPhhd 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 ucloud import BUCKET, ufile
from util import image_util, util 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): def photo_mask(pk_phhd, name, id_card_num):
session = MysqlSession() 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.pk_phhd == pk_phhd,
ZxPhrec.cRectype.in_(["3", "4"]) ZxPhrec.cRectype.in_(["3", "4"])
)).all() )).all()
@@ -236,6 +236,13 @@ def photo_mask(pk_phhd, name, id_card_num):
cv2.imwrite(temp_file.name, image) cv2.imwrite(temp_file.name, image)
try: try:
ufile.upload_file(phrec.cfjaddress, temp_file.name) 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: except Exception as e:
logging.error("上传图片出错", exc_info=e) logging.error("上传图片出错", exc_info=e)
finally: finally:
@@ -266,6 +273,7 @@ def main():
session = MysqlSession() session = MysqlSession()
update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values( update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values(
paint_flag="8", paint_flag="8",
paint_user=HOSTNAME,
paint_date=util.get_default_datetime())) paint_date=util.get_default_datetime()))
session.execute(update_flag) session.execute(update_flag)
session.commit() session.commit()

View File

@@ -19,7 +19,6 @@ from ucloud import ufile
from util import image_util, util from util import image_util, util
from util.data_util import handle_date, handle_decimal, parse_department, handle_name, \ 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 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])) 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]}) 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: for ie_result in ie_results:
result_json = json.dumps(ie_result["result"], ensure_ascii=False) result_json = json.dumps(ie_result["result"], ensure_ascii=False)
if len(result_json) > 5000: if len(result_json) > 5000:
@@ -142,7 +141,7 @@ def save_or_update_ie(table, pk_phhd, data):
obj = table(**data) obj = table(**data)
session = MysqlSession() session = MysqlSession()
db_data = session.query(table).filter_by(pk_phhd=pk_phhd).one_or_none() 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: if db_data:
# 更新 # 更新
db_data.update_time = now db_data.update_time = now
@@ -282,7 +281,7 @@ def main():
.distinct().limit(PHHD_BATCH_SIZE).all()) .distinct().limit(PHHD_BATCH_SIZE).all())
# 将状态改为正在识别中 # 将状态改为正在识别中
pk_phhd_values = [phhd.pk_phhd for phhd in phhds] 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.execute(update_flag)
session.commit() session.commit()
session.close() session.close()
@@ -294,7 +293,10 @@ def main():
# 识别完成更新标识 # 识别完成更新标识
session = MysqlSession() 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.execute(update_flag)
session.commit() session.commit()
session.close() session.close()