106 lines
4.1 KiB
Python
106 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
票据理赔自动化主模块
|
||
功能清单
|
||
https://liubiren.feishu.cn/docx/WFjTdBpzroUjQvxxrNIcKvGnneh?from=from_copylink
|
||
"""
|
||
|
||
from datetime import datetime
|
||
from pathlib import Path
|
||
import re
|
||
|
||
from case import case_adjust
|
||
from image import image_classify, image_recognize
|
||
|
||
if __name__ == "__main__":
|
||
# 初始化文件路径
|
||
file_path = Path(__file__).parent
|
||
|
||
# 初始化所有赔案的文件夹路径(需要注意在TraeCN中,文件路径需显式声明)
|
||
folder_path = file_path / "directory"
|
||
folder_path.mkdir(parents=True, exist_ok=True) # 若文件夹路径不存在则创建
|
||
|
||
# 遍历文件夹中赔案文件夹并创建赔案档案
|
||
for case_path in [x for x in folder_path.iterdir() if x.is_dir()]:
|
||
# 初始化赔案档案(推送至TPA时,保险公司会提保险分公司名称、报案时间和影像件等,TPA签收后生成赔案号)
|
||
dossier = {
|
||
"report_layer": {
|
||
"insurer_company": (
|
||
insurer_company := "中银保险有限公司苏州分公司"
|
||
), # 保险分公司名称默认为中银保险有限公司苏州分公司
|
||
"report_time": datetime(
|
||
2025, 7, 25, 12, 0, 0
|
||
), # 报案时间默认为2025-07-25 12:00:00
|
||
"images_counts": 15, # 影像件数默认为15
|
||
"case_number": case_path.stem, # 赔案号默认为赔案文件夹名称
|
||
}, # 报案层
|
||
"images_layer": {}, # 影像件层
|
||
"insured_person_layer": {}, # 出险人层
|
||
"liabilities_layer": [], # 理赔责任层
|
||
"receipts_layer": [], # 票据层
|
||
"adjustment_layer": {}, # 理算层
|
||
}
|
||
|
||
# 遍历赔案文件夹内所有影像件路径
|
||
for image_index, image_path in enumerate(
|
||
sorted(
|
||
[
|
||
x
|
||
for x in case_path.glob(pattern="*")
|
||
if x.is_file() and x.suffix.lower() in [".jpg", ".jpeg", ".png"]
|
||
],
|
||
key=lambda x: x.stat().st_birthtime, # 根据影像件创建时间顺序排序
|
||
),
|
||
1,
|
||
):
|
||
# 分类影像件、旋正并整合至赔案档案
|
||
image_classify(
|
||
image_index=image_index, image_path=image_path, dossier=dossier
|
||
)
|
||
|
||
# 就影像件层按照影像件类型指定排序
|
||
dossier["images_layer"] = dict(
|
||
sorted(
|
||
dossier["images_layer"].items(),
|
||
key=lambda x: [
|
||
"居民户口簿",
|
||
"居民身份证(国徽面)",
|
||
"居民身份证(头像面)",
|
||
"居民身份证(国徽、头像面)",
|
||
"中国港澳台地区及境外护照",
|
||
"银行卡",
|
||
"理赔申请书",
|
||
"其它",
|
||
"增值税发票",
|
||
"医疗门诊收费票据",
|
||
"医疗住院收费票据",
|
||
"医疗费用清单",
|
||
].index(x[1]["image_type"]),
|
||
),
|
||
)
|
||
# 统计已分类影像件数
|
||
dossier["classified_images_counts"] = len(dossier["images_layer"])
|
||
|
||
# 遍历影像件层内所有影像件
|
||
for image_index, image in dossier["images_layer"].items():
|
||
if re.match(pattern=r"^\d{2}$", string=image_index):
|
||
# 识别影像件并整合至赔案档案
|
||
image_recognize(
|
||
image_index=image_index,
|
||
image=image,
|
||
insurer_company=insurer_company,
|
||
dossier=dossier,
|
||
)
|
||
|
||
# 统计已识别影像件数
|
||
dossier["recognized_images_counts"] = len(
|
||
[
|
||
image
|
||
for image in dossier["images_layer"].values()
|
||
if image["image_recognized"] == "是"
|
||
]
|
||
)
|
||
|
||
# 理算赔案并整合至赔案档案
|
||
case_adjust(dossier=dossier)
|