91 lines
3.4 KiB
Python
91 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
票据理赔自动化主模块
|
||
功能清单
|
||
https://liubiren.feishu.cn/docx/WFjTdBpzroUjQvxxrNIcKvGnneh?from=from_copylink
|
||
"""
|
||
|
||
from datetime import datetime
|
||
from pathlib import Path
|
||
|
||
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": {
|
||
"case_number": case_path.stem, # 默认为赔案文件夹名称
|
||
"insurer_company": (
|
||
insurer_company := "中银保险有限公司苏州分公司"
|
||
), # 默认为中银保险有限公司苏州分公司
|
||
"report_time": datetime(
|
||
2025, 7, 25, 12, 0, 0
|
||
), # 指定报案时间,默认为 datetime对象
|
||
}, # 报案层
|
||
"images_layer": [], # 影像件层
|
||
"insured_person_layer": {}, # 出险人层
|
||
"liabilities_layer": [], # 理赔责任层
|
||
"receipts_layer": [], # 票据层
|
||
"adjustment_layer": {}, # 理算层
|
||
}
|
||
|
||
# 遍历赔案文件夹内所有影像件路径
|
||
for image_index, image_path in enumerate(
|
||
sorted(
|
||
[
|
||
i
|
||
for i in case_path.glob(pattern="*")
|
||
if i.is_file() and i.suffix.lower() in [".jpg", ".jpeg", ".png"]
|
||
],
|
||
key=lambda i: i.stat().st_birthtime, # 根据影像件创建时间顺序排序
|
||
),
|
||
1,
|
||
):
|
||
# 分类影像件、旋正并整合至赔案档案
|
||
image_classify(
|
||
image_index=image_index, image_path=image_path, dossier=dossier
|
||
)
|
||
|
||
# 就影像件层按照影像件类型指定排序
|
||
dossier["images_layer"].sort(
|
||
key=lambda i: [
|
||
"居民户口簿",
|
||
"居民身份证(国徽面)",
|
||
"居民身份证(头像面)",
|
||
"居民身份证(国徽、头像面)",
|
||
"中国港澳台地区及境外护照",
|
||
"理赔申请书",
|
||
"增值税发票",
|
||
"医疗门诊收费票据",
|
||
"医疗住院收费票据",
|
||
"医疗费用清单",
|
||
"银行卡",
|
||
"其它",
|
||
].index(i["image_type"])
|
||
)
|
||
|
||
# 遍历影像件层内影像件
|
||
for image in dossier["images_layer"]:
|
||
# 识别影像件并整合至赔案档案
|
||
image_recognize(
|
||
image=image,
|
||
insurer_company=insurer_company,
|
||
dossier=dossier,
|
||
)
|
||
|
||
# 就票据层按照开票日期和票据号顺序排序
|
||
dossier["receipts_layer"].sort(key=lambda x: (x["date"], x["number"]))
|
||
|
||
# 理算赔案并整合至赔案档案
|
||
case_adjust(dossier=dossier)
|