完成接口与接口文档
This commit is contained in:
parent
a6fa6ebf9a
commit
d71251be06
|
@ -197,6 +197,17 @@ async def generate_report(base_info, baogao_info):
|
||||||
print(f"报告基本信息获取失败:{e}")
|
print(f"报告基本信息获取失败:{e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#检查参数合法性
|
||||||
|
if not if_fanglei or not if_neibu or not if_waibu:
|
||||||
|
print("请至少选择一种检查项目")
|
||||||
|
return
|
||||||
|
if not os.path.exists(muban_dir):
|
||||||
|
print(f"模板路径{muban_dir}不存在")
|
||||||
|
return
|
||||||
|
if not os.path.exists(shengcheng_dir):
|
||||||
|
print(f"生成路径{shengcheng_dir}不存在")
|
||||||
|
return
|
||||||
|
|
||||||
output_doc = None
|
output_doc = None
|
||||||
head_num = 1
|
head_num = 1
|
||||||
###封面创建###
|
###封面创建###
|
||||||
|
@ -215,6 +226,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
|
|
||||||
mianzhe_shengming = f"本报告仅涵盖{'、'.join(baogao_label)}检测内容"
|
mianzhe_shengming = f"本报告仅涵盖{'、'.join(baogao_label)}检测内容"
|
||||||
|
|
||||||
|
if baogao_info["if_docx_fengmian"] :
|
||||||
#创建文档、添加封面
|
#创建文档、添加封面
|
||||||
print(await create_document(output_dir))
|
print(await create_document(output_dir))
|
||||||
print(add_documents(output_dir, cover_dirs[0]))
|
print(add_documents(output_dir, cover_dirs[0]))
|
||||||
|
@ -240,6 +252,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
print(await search_and_replace(output_dir, 'mianzhe_shengming', mianzhe_shengming))
|
print(await search_and_replace(output_dir, 'mianzhe_shengming', mianzhe_shengming))
|
||||||
|
|
||||||
total_table_num = 0
|
total_table_num = 0
|
||||||
|
if baogao_info["if_docx_project_overview"]:
|
||||||
#项目概况表
|
#项目概况表
|
||||||
print("开始添加项目概况表")
|
print("开始添加项目概况表")
|
||||||
XIANG_MU_GAI_KUANG = os.path.join(muban_dir,"xiangmugaikuo.docx")
|
XIANG_MU_GAI_KUANG = os.path.join(muban_dir,"xiangmugaikuo.docx")
|
||||||
|
@ -272,6 +285,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||||||
head_num += 1
|
head_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_inspection_method']:
|
||||||
#检查方案描述
|
#检查方案描述
|
||||||
FANGAN_JIANCHA_DIR = os.path.join(muban_dir,"checkmethod.docx")
|
FANGAN_JIANCHA_DIR = os.path.join(muban_dir,"checkmethod.docx")
|
||||||
list_to_replace = {
|
list_to_replace = {
|
||||||
|
@ -287,7 +301,8 @@ async def generate_report(base_info, baogao_info):
|
||||||
total_table_num += 1
|
total_table_num += 1
|
||||||
head_num += 1
|
head_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_inspection_info']:
|
||||||
|
#检查信息
|
||||||
JIANCHA_XINGXI_DIR = os.path.join(muban_dir,"checkinfo.docx")
|
JIANCHA_XINGXI_DIR = os.path.join(muban_dir,"checkinfo.docx")
|
||||||
JIANCHA_XINGXI = list(list("" for i in range(4)) for j in range(9))
|
JIANCHA_XINGXI = list(list("" for i in range(4)) for j in range(9))
|
||||||
JIANCHA_XINGXI[0][1] = jiancha_renyuan
|
JIANCHA_XINGXI[0][1] = jiancha_renyuan
|
||||||
|
@ -311,6 +326,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
head_num += 1
|
head_num += 1
|
||||||
total_table_num += 1
|
total_table_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_chengguo_sub']:
|
||||||
# 添加成果递交表
|
# 添加成果递交表
|
||||||
CHENGGUO_DIJIAO_DIR = os.path.join(muban_dir,"chengguo_sub.docx")
|
CHENGGUO_DIJIAO_DIR = os.path.join(muban_dir,"chengguo_sub.docx")
|
||||||
CHENGGUO_DIJIAO = list(list("" for i in range(4)) for j in range(6))
|
CHENGGUO_DIJIAO = list(list("" for i in range(4)) for j in range(6))
|
||||||
|
@ -337,6 +353,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
head_num += 1
|
head_num += 1
|
||||||
total_table_num += 1
|
total_table_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_inspection_text'] and if_waibu:
|
||||||
#检查情况汇总表(文字信息)
|
#检查情况汇总表(文字信息)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -387,9 +404,9 @@ async def generate_report(base_info, baogao_info):
|
||||||
total_table_num += 1
|
total_table_num += 1
|
||||||
head_num += 1
|
head_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_inspection_picture']:
|
||||||
#主要部位图片展示表/检查内容表
|
#主要部位图片展示表/检查内容表
|
||||||
#获取典型图信息
|
#获取典型图信息
|
||||||
search_file_list = ["外汇总","内汇总","防汇总"]
|
|
||||||
try:
|
try:
|
||||||
Y1_list = safe_get(filtered_picture_data, "叶片1", dianxing_type, default=[])
|
Y1_list = safe_get(filtered_picture_data, "叶片1", dianxing_type, default=[])
|
||||||
Y2_list = safe_get(filtered_picture_data, "叶片2", dianxing_type, default=[])
|
Y2_list = safe_get(filtered_picture_data, "叶片2", dianxing_type, default=[])
|
||||||
|
@ -443,6 +460,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||||||
head_num += 1
|
head_num += 1
|
||||||
|
|
||||||
|
if baogao_info['if_docx_defect_picture'] and if_waibu:
|
||||||
# #缺陷详情
|
# #缺陷详情
|
||||||
QUEXIAN_XIANGQING_DIR = os.path.join(muban_dir,"check_check.docx")
|
QUEXIAN_XIANGQING_DIR = os.path.join(muban_dir,"check_check.docx")
|
||||||
QUEXIAN_XIANGQING_TITLE_DIR = os.path.join(muban_dir,"check_check_title.docx")
|
QUEXIAN_XIANGQING_TITLE_DIR = os.path.join(muban_dir,"check_check_title.docx")
|
||||||
|
@ -539,7 +557,7 @@ async def generate_report(base_info, baogao_info):
|
||||||
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y2_TABLES,QUEXIAN_XIANGQING_DIR,Y2_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
|
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y2_TABLES,QUEXIAN_XIANGQING_DIR,Y2_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
|
||||||
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y3_TABLES,QUEXIAN_XIANGQING_DIR,Y3_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
|
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y3_TABLES,QUEXIAN_XIANGQING_DIR,Y3_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
|
||||||
|
|
||||||
|
if baogao_info['if_docx_conclusion']:
|
||||||
#总结
|
#总结
|
||||||
ZONG_JIE_DIR = os.path.join(muban_dir,"result.docx")
|
ZONG_JIE_DIR = os.path.join(muban_dir,"result.docx")
|
||||||
ZONG_JIE_BEFORE = "result"
|
ZONG_JIE_BEFORE = "result"
|
||||||
|
@ -550,115 +568,33 @@ async def generate_report(base_info, baogao_info):
|
||||||
print(await search_and_replace(output_dir, 'baogao_date', baogao_date.split(' ')[0]))
|
print(await search_and_replace(output_dir, 'baogao_date', baogao_date.split(' ')[0]))
|
||||||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||||||
|
|
||||||
import argparse
|
from tools.argtool import (load_config, parse_arguments, get_default_config,
|
||||||
|
merge_configs)
|
||||||
def parse_arguments():
|
|
||||||
parser = argparse.ArgumentParser(description='报告生成工具')
|
|
||||||
|
|
||||||
# 设置默认值
|
|
||||||
default_json1 = {
|
|
||||||
"turbine_id": "183463dbf40d9278549a76b82b175dd9",
|
|
||||||
}
|
|
||||||
default_json2 = {
|
|
||||||
'shengcheng_dir': r"",
|
|
||||||
'muban_dir': r"",
|
|
||||||
"dianxing_enum" : "TYPICAL", # 典型图的枚举值
|
|
||||||
"quexian_enum" : "DEFECT", # 缺陷图的枚举值
|
|
||||||
"other_enum" : "OTHER", # 其他图的枚举值
|
|
||||||
"waibu_enum" : "out-work",
|
|
||||||
"neibu_enum" : "in-work",
|
|
||||||
"fanglei_enum" : "lightning-protection-work",
|
|
||||||
"if_waibu" : True,
|
|
||||||
"if_neibu" : True,
|
|
||||||
"if_fanglei" : True,
|
|
||||||
"userName" : "admin",
|
|
||||||
"baogaoCheck" : "未审核",
|
|
||||||
'key_words': '缺,损,裂,脱,污', #关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化
|
|
||||||
|
|
||||||
"data_processor" : "未获取",
|
|
||||||
"shigong_fangan" : None,
|
|
||||||
'jiancha_renyuan': '未获取',
|
|
||||||
"check_date" : None,
|
|
||||||
"coverurl" : None,
|
|
||||||
"conclusion" : "未填写总结",
|
|
||||||
}
|
|
||||||
|
|
||||||
parser.add_argument('--turbine_id', '--id', dest='turbine_id', default=default_json1['turbine_id'],
|
|
||||||
help='''风机ID,默认为测试项目:"183463dbf40d9278549a76b82b175dd9"
|
|
||||||
用于获取机组关联的所有静态信息与图片''')
|
|
||||||
parser.add_argument('--output_dir', '--out', dest='output_dir', default=default_json2['shengcheng_dir'],
|
|
||||||
help='输出目录,必填项')
|
|
||||||
parser.add_argument('--template_dir', '--tpl', dest='template_dir', default=default_json2['muban_dir'],
|
|
||||||
help='模板目录,必填项,用于获取模板文件,模板文件在同目录下的muban文件夹')
|
|
||||||
parser.add_argument('--data_processor', '--dp', dest='data_processor', default=default_json2['data_processor'],
|
|
||||||
help='数据处理人')
|
|
||||||
parser.add_argument('--jiancha_renyuan', '--jc', dest='jiancha_renyuan', default=default_json2['jiancha_renyuan'],
|
|
||||||
help='检查人')
|
|
||||||
parser.add_argument('--check_date', '--cdate', dest='check_date', default=default_json2['check_date'],
|
|
||||||
help='检查日期,格式为YYYY-MM-DD HH:MM:SS')
|
|
||||||
parser.add_argument('--username', '--user', dest='username', default=default_json2['userName'],
|
|
||||||
help='报告生成人,默认为admin')
|
|
||||||
parser.add_argument('--if_waibu', '--waibu', dest='if_waibu', default=default_json2['if_waibu'],
|
|
||||||
help='报告是否包含外部检测,默认为True')
|
|
||||||
parser.add_argument('--if_neibu', '--neibu', dest='if_neibu', default=default_json2['if_neibu'],
|
|
||||||
help='报告是否包含内部检测,默认为True')
|
|
||||||
parser.add_argument('--if_fanglei', '--fanglei', dest='if_fanglei', default=default_json2['if_fanglei'],
|
|
||||||
help='报告是否包含防雷检测,默认为True')
|
|
||||||
parser.add_argument('--reportchecker', '--rc', dest='baogaoCheck', default=default_json2['baogaoCheck'],
|
|
||||||
help='报告审核状态,默认为未审核')
|
|
||||||
parser.add_argument('--conclusion', '--con', dest='conclusion', default=default_json2['conclusion'],
|
|
||||||
help='总结,默认为未填写总结')
|
|
||||||
parser.add_argument('--keywords', '--kw', dest='keywords', default=default_json2['key_words'],
|
|
||||||
help='关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化')
|
|
||||||
parser.add_argument('--coverurl', default=default_json2['coverurl'], help='封面图片url,指定coverurl则不使用模板中的封面图片')
|
|
||||||
parser.add_argument('--dianxing_enum', '--dx', dest='dianxing_enum', default=default_json2['dianxing_enum'],
|
|
||||||
help='典型图的枚举值,默认为TYPICAL')
|
|
||||||
parser.add_argument('--quexian_enum', '--qx', dest='quexian_enum', default=default_json2['quexian_enum'],
|
|
||||||
help='缺陷图的枚举值,默认为DEFECT')
|
|
||||||
parser.add_argument('--other_enum', '--other', dest='other_enum', default=default_json2['other_enum'],
|
|
||||||
help='其他图的枚举值,默认为OTHER')
|
|
||||||
parser.add_argument('--waibu_enum', '--wb', dest='waibu_enum', default=default_json2['waibu_enum'],
|
|
||||||
help='外部检测的枚举值,默认为out_work')
|
|
||||||
parser.add_argument('--neibu_enum', '--nb', dest='neibu_enum', default=default_json2['neibu_enum'],
|
|
||||||
help='内部检测的枚举值,默认为in_work')
|
|
||||||
parser.add_argument('--fanglei_enum', '--fb', dest='fanglei_enum', default=default_json2['fanglei_enum'],
|
|
||||||
help='防雷检测的枚举值,默认为lightning-protection-work')
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_arguments()
|
args = parse_arguments()
|
||||||
|
|
||||||
json_data1 = {
|
default_cfg = get_default_config()
|
||||||
"turbine_id": args.turbine_id,
|
|
||||||
}
|
|
||||||
|
|
||||||
json_data2 = {
|
# 读取配置文件(若存在)
|
||||||
'shengcheng_dir': args.output_dir,
|
file_cfg = {}
|
||||||
'muban_dir': args.template_dir,
|
if Path(args.config_file).exists():
|
||||||
"dianxing_enum" : args.dianxing_enum, # 典型图的枚举值
|
try:
|
||||||
"quexian_enum" : args.quexian_enum, # 缺陷图的枚举值
|
file_cfg = load_config(args.config_file)
|
||||||
"other_enum" : args.other_enum, # 其他图的枚举值
|
except Exception as e:
|
||||||
"waibu_enum" : args.waibu_enum,
|
print(f'警告:加载配置文件失败 {e},使用默认配置')
|
||||||
"neibu_enum" : args.neibu_enum,
|
|
||||||
"fanglei_enum" : args.fanglei_enum,
|
|
||||||
"if_waibu" : args.if_waibu,
|
|
||||||
"if_neibu" : args.if_neibu,
|
|
||||||
"if_fanglei" : args.if_fanglei,
|
|
||||||
"userName" : args.username,
|
|
||||||
"baogaoCheck" : args.baogaoCheck,
|
|
||||||
'key_words': args.keywords, #关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化
|
|
||||||
"shigong_fangan" : None,
|
|
||||||
'jiancha_renyuan': args.jiancha_renyuan,
|
|
||||||
"check_date" : args.check_date,
|
|
||||||
"data_processor" : args.data_processor,
|
|
||||||
"coverurl" : args.coverurl,
|
|
||||||
"baogao_zongjie" : args.conclusion,
|
|
||||||
}
|
|
||||||
|
|
||||||
json_data2['shengcheng_dir'] = r"/home/dtyx/桌面/yhh/Report_Generate_Server/output"
|
merged = merge_configs(default_cfg, file_cfg, args)
|
||||||
json_data2['muban_dir'] = r"/home/dtyx/桌面/yhh/Report_Generate_Server/muban"
|
|
||||||
|
|
||||||
asyncio.run(generate_report(json_data1, json_data2))
|
# 补全必要目录
|
||||||
|
if not merged['json2']['shengcheng_dir']:
|
||||||
|
merged['json2']['shengcheng_dir'] = str(Path.cwd() / 'output')
|
||||||
|
if not merged['json2']['muban_dir']:
|
||||||
|
merged['json2']['muban_dir'] = str(Path.cwd() / 'muban')
|
||||||
|
|
||||||
|
Path(merged['json2']['shengcheng_dir']).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
asyncio.run(generate_report(merged['json1'], merged['json2']))
|
||||||
print('文档生成完毕')
|
print('文档生成完毕')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
报告生成接入服务器的测试开发(调用服务器的api测试)
|
#### 报告生成接入服务器的测试开发(调用服务器的api测试)
|
||||||
|
|
||||||
|
### 在dist目录查看编译好的文件,和使用文档
|
|
@ -0,0 +1,82 @@
|
||||||
|
# 报告生成工具使用文档
|
||||||
|
|
||||||
|
## 1. 功能简介
|
||||||
|
本工具用于根据风机巡检数据自动生成 Word 报告。
|
||||||
|
支持 **配置文件** 与 **命令行参数** 两种输入方式,命令行可覆盖配置文件中的同名字段。
|
||||||
|
|
||||||
|
## 2. 安装与准备
|
||||||
|
1. 克隆或下载代码。
|
||||||
|
2. 安装依赖(仅需标准库,无需额外包)。
|
||||||
|
3. 准备模板目录(默认 `./muban`)与输出目录(默认 `./output`)。
|
||||||
|
|
||||||
|
## 3. 配置文件(推荐)
|
||||||
|
在项目根目录新建 `config.json`(或任意文件名),格式如下:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"json1": {
|
||||||
|
"turbine_id": "183463dbf40d9278549a76b82b175dd9"
|
||||||
|
},
|
||||||
|
"json2": {
|
||||||
|
"shengcheng_dir": "./reports",
|
||||||
|
"muban_dir": "./templates",
|
||||||
|
"if_waibu": true,
|
||||||
|
"if_neibu": true,
|
||||||
|
"if_fanglei": true,
|
||||||
|
"userName": "张三",
|
||||||
|
"baogaoCheck": "已审核",
|
||||||
|
"key_words": "缺,损,裂",
|
||||||
|
"data_processor": "李四",
|
||||||
|
"jiancha_renyuan": "王五",
|
||||||
|
"check_date": "2024-06-01",
|
||||||
|
"coverurl": "https://example.com/cover.jpg",
|
||||||
|
"conclusion": "整体良好,详见报告"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 命令行参数
|
||||||
|
|
||||||
|
| 参数 | 说明 | 示例 |
|
||||||
|
|------|------|------|
|
||||||
|
| `--config` / `-c` | 指定配置文件 | `--config prod.json` |
|
||||||
|
| `--turbine_id` / `--id` | 风机 ID | `--turbine_id 123456` |
|
||||||
|
| `--output_dir` / `--out` | 报告输出目录 | `--output_dir ./result` |
|
||||||
|
| `--template_dir` / `--tpl` | 模板目录 | `--template_dir ./tpl` |
|
||||||
|
| `--if_waibu` | 是否包含外部作业章节 | `true` / `false` |
|
||||||
|
| `--if_neibu` | 是否包含内部作业章节 | `true` / `false` |
|
||||||
|
| `--if_fanglei` | 是否包含防雷作业章节 | `true` / `false` |
|
||||||
|
| `--userName` | 报告编制人 | `--userName 张三` |
|
||||||
|
| `--baogaoCheck` | 审核状态 | `--baogaoCheck 已审核` |
|
||||||
|
| `--key_words` | 关键词(英文逗号分隔) | `--key_words 缺,损,裂` |
|
||||||
|
| `--data_processor` | 数据处理人 | `--data_processor 李四` |
|
||||||
|
| `--jiancha_renyuan` | 检查人员 | `--jiancha_renyuan 王五` |
|
||||||
|
| `--check_date` | 检查日期(YYYY-MM-DD) | `--check_date 2024-06-01` |
|
||||||
|
| `--coverurl` | 封面图片 URL | `--coverurl /stastic/path/to/pic` |
|
||||||
|
| `--conclusion` | 报告总结 | `--conclusion 整体良好` |
|
||||||
|
|
||||||
|
5. 使用示例
|
||||||
|
|
||||||
|
### 5.1 仅使用配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python report.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 完全命令行
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python report.py \
|
||||||
|
--turbine_id 123456 \
|
||||||
|
--output_dir ./my_out \
|
||||||
|
--if_waibu false \
|
||||||
|
--userName Alice \
|
||||||
|
--check_date 2024-06-01 \
|
||||||
|
--conclusion "检查完毕,无异常"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.3 混合方式
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python report.py --config prod.json --userName Bob --if_fanglei false
|
||||||
|
```
|
|
@ -0,0 +1,111 @@
|
||||||
|
from typing import Dict, Any
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
|
def load_config(config_path: str) -> Dict[str, Any]:
|
||||||
|
"""从JSON配置文件加载配置"""
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def parse_arguments():
|
||||||
|
parser = argparse.ArgumentParser(description='报告生成工具')
|
||||||
|
|
||||||
|
# 添加配置文件参数
|
||||||
|
parser.add_argument('--config', '-c', dest='config_file',
|
||||||
|
default='config.json',
|
||||||
|
help='配置文件路径,默认为当前目录下的config.json')
|
||||||
|
|
||||||
|
# 保留一些关键参数作为命令行可覆盖选项
|
||||||
|
parser.add_argument('--turbine_id', '--id', dest='turbine_id',
|
||||||
|
help='覆盖配置文件中的风机ID')
|
||||||
|
parser.add_argument('--output_dir', '--out', dest='output_dir',
|
||||||
|
help='覆盖配置文件中的输出目录')
|
||||||
|
parser.add_argument('--template_dir', '--tpl', dest='template_dir',
|
||||||
|
help='覆盖配置文件中的模板目录')
|
||||||
|
parser.add_argument('--if_waibu', type=lambda x: x.lower() in ('true', '1', 'yes'),
|
||||||
|
help='是否包含外部作业章节')
|
||||||
|
parser.add_argument('--if_neibu', type=lambda x: x.lower() in ('true', '1', 'yes'),
|
||||||
|
help='是否包含内部作业章节')
|
||||||
|
parser.add_argument('--if_fanglei', type=lambda x: x.lower() in ('true', '1', 'yes'),
|
||||||
|
help='是否包含防雷作业章节')
|
||||||
|
parser.add_argument('--userName', dest='userName',
|
||||||
|
help='报告编制人')
|
||||||
|
parser.add_argument('--baogaoCheck', dest='baogaoCheck',
|
||||||
|
help='报告审核状态')
|
||||||
|
parser.add_argument('--key_words', dest='key_words',
|
||||||
|
help='关键词,英文逗号分隔')
|
||||||
|
parser.add_argument('--data_processor', dest='data_processor',
|
||||||
|
help='数据处理人')
|
||||||
|
parser.add_argument('--jiancha_renyuan', dest='jiancha_renyuan',
|
||||||
|
help='检查人员')
|
||||||
|
parser.add_argument('--check_date', dest='check_date',
|
||||||
|
help='检查日期,格式 YYYY-MM-DD')
|
||||||
|
parser.add_argument('--coverurl', dest='coverurl',
|
||||||
|
help='封面图片 URL')
|
||||||
|
parser.add_argument('--conclusion', dest='conclusion',
|
||||||
|
help='报告总结')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def merge_configs(default_cfg: Dict[str, Any],
|
||||||
|
file_cfg: Dict[str, Any],
|
||||||
|
cli: argparse.Namespace) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""合并默认配置、文件配置和命令行参数"""
|
||||||
|
|
||||||
|
merged = {
|
||||||
|
'json1': {**default_cfg['json1'], **file_cfg.get('json1', {})},
|
||||||
|
'json2': {**default_cfg['json2'], **file_cfg.get('json2', {})}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 高频覆盖项
|
||||||
|
if cli.turbine_id:
|
||||||
|
merged['json1']['turbine_id'] = cli.turbine_id
|
||||||
|
if cli.output_dir:
|
||||||
|
merged['json2']['shengcheng_dir'] = cli.output_dir
|
||||||
|
if cli.template_dir:
|
||||||
|
merged['json2']['muban_dir'] = cli.template_dir
|
||||||
|
for key in ('if_waibu', 'if_neibu', 'if_fanglei', 'userName',
|
||||||
|
'baogaoCheck', 'key_words', 'data_processor',
|
||||||
|
'jiancha_renyuan', 'check_date', 'coverurl', 'conclusion'):
|
||||||
|
val = getattr(cli, key, None)
|
||||||
|
if val is not None:
|
||||||
|
merged['json2'][key] = val
|
||||||
|
|
||||||
|
return merged
|
||||||
|
def get_default_config() -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""获取默认配置"""
|
||||||
|
return {
|
||||||
|
'json1': {
|
||||||
|
"turbine_id": "183463dbf40d9278549a76b82b175dd9",
|
||||||
|
},
|
||||||
|
'json2': {
|
||||||
|
'shengcheng_dir': "",
|
||||||
|
'muban_dir': "",
|
||||||
|
"dianxing_enum": "TYPICAL",
|
||||||
|
"quexian_enum": "DEFECT",
|
||||||
|
"other_enum": "OTHER",
|
||||||
|
"waibu_enum": "out-work",
|
||||||
|
"neibu_enum": "in-work",
|
||||||
|
"fanglei_enum": "lightning-protection-work",
|
||||||
|
"if_waibu": True,
|
||||||
|
"if_neibu": True,
|
||||||
|
"if_fanglei": True,
|
||||||
|
"userName": "admin",
|
||||||
|
"baogaoCheck": "未审核",
|
||||||
|
'key_words': '缺,损,裂,脱,污',
|
||||||
|
"data_processor": "未获取",
|
||||||
|
"shigong_fangan": None,
|
||||||
|
'jiancha_renyuan': '未获取',
|
||||||
|
"check_date": None,
|
||||||
|
"coverurl": None,
|
||||||
|
"conclusion": "未填写总结",
|
||||||
|
"if_docx_fengmian": True,
|
||||||
|
"if_docx_project_overview": True,
|
||||||
|
"if_docx_inspection_method": True,
|
||||||
|
"if_docx_inspection_info": True,
|
||||||
|
"if_docx_chengguo_sub": True,
|
||||||
|
"if_docx_inspection_text": True,
|
||||||
|
"if_docx_inspection_picture": True,
|
||||||
|
"if_docx_defect_picture": True,
|
||||||
|
"if_docx_conclusion": True,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue