|
@@ -12,6 +12,7 @@ import shutil
|
|
|
import hashlib
|
|
import hashlib
|
|
|
import zipfile
|
|
import zipfile
|
|
|
import base64
|
|
import base64
|
|
|
|
|
+import uuid
|
|
|
from decimal import Decimal
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
# 数据库配置 (从 application-dev.yml 获取)
|
|
# 数据库配置 (从 application-dev.yml 获取)
|
|
@@ -19,16 +20,18 @@ from decimal import Decimal
|
|
|
DB_CONFIG = {
|
|
DB_CONFIG = {
|
|
|
'user': 'root',
|
|
'user': 'root',
|
|
|
'password': '84853032',
|
|
'password': '84853032',
|
|
|
- 'host': '47.99.60.80',
|
|
|
|
|
- 'port': 3306,
|
|
|
|
|
- 'database': '2022hs060',
|
|
|
|
|
|
|
+ 'host': '172.16.10.152',
|
|
|
|
|
+ 'port': 15606,
|
|
|
|
|
+ 'database': 'dnn202500200jy',
|
|
|
'use_pure': True,
|
|
'use_pure': True,
|
|
|
- 'connect_timeout': 5
|
|
|
|
|
|
|
+ 'connect_timeout': 10
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# 目标API配置
|
|
# 目标API配置
|
|
|
API_URL = "http://218.94.73.106:8081/api/eps9/tyjk/api/data/asip/HWKJLZF"
|
|
API_URL = "http://218.94.73.106:8081/api/eps9/tyjk/api/data/asip/HWKJLZF"
|
|
|
-FILE_BASE_URL = "https://oss.dnnbuild.com" # 猜测的文件下载基地址
|
|
|
|
|
|
|
+FILE_BASE_URL = "https://oss.dnnbuild.com"
|
|
|
|
|
+ARCHIVE_UNIT = "无锡至宜兴高速公路雪堰枢纽至西坞枢纽段扩建工程"
|
|
|
|
|
+CATALOG_SIGNING_UNIT = "沪武高速公路太仓至常州段扩建工程苏州段"
|
|
|
|
|
|
|
|
# XML 模板
|
|
# XML 模板
|
|
|
XML_DESC_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
XML_DESC_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -47,7 +50,19 @@ XML_DESC_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<起始件号></起始件号>
|
|
<起始件号></起始件号>
|
|
|
<截至件号></截至件号>
|
|
<截至件号></截至件号>
|
|
|
<信息系统名称>档案综合利用平台</信息系统名称>
|
|
<信息系统名称>档案综合利用平台</信息系统名称>
|
|
|
-</文件说明>"""
|
|
|
|
|
|
|
+{process_xml}</文件说明>"""
|
|
|
|
|
+
|
|
|
|
|
+XML_PROCESS_NODE_TEMPLATE = """ <节点>
|
|
|
|
|
+ <节点标识>{node_id}</节点标识>
|
|
|
|
|
+ <节点名称>{name}</节点名称>
|
|
|
|
|
+ <类型>{type}</类型>
|
|
|
|
|
+ <机构名称>{org_name}</机构名称>
|
|
|
|
|
+ <办理人>{operator_name}</办理人>
|
|
|
|
|
+ <创建时间>{created_time}</创建时间>
|
|
|
|
|
+ <办理时间>{operate_time}</办理时间>
|
|
|
|
|
+ <审核意见>{opinion}</审核意见>
|
|
|
|
|
+ <审核结论>{conclusion}</审核结论>
|
|
|
|
|
+ </节点>"""
|
|
|
|
|
|
|
|
XML_CATALOG_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
XML_CATALOG_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<文件目录>
|
|
<文件目录>
|
|
@@ -64,7 +79,7 @@ XML_CATALOG_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<标题>{title}</标题>
|
|
<标题>{title}</标题>
|
|
|
<主送机关></主送机关>
|
|
<主送机关></主送机关>
|
|
|
<附件说明></附件说明>
|
|
<附件说明></附件说明>
|
|
|
- <发文机关或签发人署名>沪武高速公路太仓至常州段扩建工程苏州段</发文机关或签发人署名>
|
|
|
|
|
|
|
+ <发文机关或签发人署名>{signing_unit}</发文机关或签发人署名>
|
|
|
<成文日期>{date_compact}</成文日期>
|
|
<成文日期>{date_compact}</成文日期>
|
|
|
<附注></附注>
|
|
<附注></附注>
|
|
|
<抄送机关></抄送机关>
|
|
<抄送机关></抄送机关>
|
|
@@ -75,7 +90,16 @@ XML_CATALOG_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<年度>{year}</年度>
|
|
<年度>{year}</年度>
|
|
|
<保管期限></保管期限>
|
|
<保管期限></保管期限>
|
|
|
<机构或问题></机构或问题>
|
|
<机构或问题></机构或问题>
|
|
|
- <件号></件号>
|
|
|
|
|
|
|
+ <当前计量期>{current_period}</当前计量期>
|
|
|
|
|
+ <计量号>{measure_number}</计量号>
|
|
|
|
|
+ <起始日期>{period_start}</起始日期>
|
|
|
|
|
+ <终止日期>{period_end}</终止日期>
|
|
|
|
|
+ <制表人标识>{tabulator_id}</制表人标识>
|
|
|
|
|
+ <制表人名称>{tabulator_name}</制表人名称>
|
|
|
|
|
+ <制表日期>{tabulation_date}</制表日期>
|
|
|
|
|
+ <到上期末累计完成额>{completed_last_period}</到上期末累计完成额>
|
|
|
|
|
+ <本期完成额>{current_period_amount}</本期完成额>
|
|
|
|
|
+ <本期末累计额>{completed_cumulative}</本期末累计额>
|
|
|
<数字对象标识></数字对象标识>
|
|
<数字对象标识></数字对象标识>
|
|
|
<环境信息></环境信息>
|
|
<环境信息></环境信息>
|
|
|
<软件环境></软件环境>
|
|
<软件环境></软件环境>
|
|
@@ -107,7 +131,7 @@ XML_METADATA_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<封装包类型 name="M205" />
|
|
<封装包类型 name="M205" />
|
|
|
<封装包类型描述 name="M206" />
|
|
<封装包类型描述 name="M206" />
|
|
|
<封装包创建时间 name="M207">{date}</封装包创建时间>
|
|
<封装包创建时间 name="M207">{date}</封装包创建时间>
|
|
|
- <封装包创建单位 name="M208">沪武高速公路太仓至常州段扩建工程苏州段</封装包创建单位>
|
|
|
|
|
|
|
+ <封装包创建单位 name="M208">{archive_unit}</封装包创建单位>
|
|
|
<封装内容 name="M209">
|
|
<封装内容 name="M209">
|
|
|
<文件实体块 name="M210">
|
|
<文件实体块 name="M210">
|
|
|
<文件实体 name="M211">
|
|
<文件实体 name="M211">
|
|
@@ -115,8 +139,8 @@ XML_METADATA_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<来源 name="M2">
|
|
<来源 name="M2">
|
|
|
<档案馆名称 name="M3">xx</档案馆名称>
|
|
<档案馆名称 name="M3">xx</档案馆名称>
|
|
|
<档案馆代码 name="M4" />
|
|
<档案馆代码 name="M4" />
|
|
|
- <全宗名称 name="M5">沪武高速公路太仓至常州段扩建工程苏州段</全宗名称>
|
|
|
|
|
- <立档单位名称 name="M6">沪武高速公路太仓至常州段扩建工程苏州段</立档单位名称>
|
|
|
|
|
|
|
+ <全宗名称 name="M5">{archive_unit}</全宗名称>
|
|
|
|
|
+ <立档单位名称 name="M6">{archive_unit}</立档单位名称>
|
|
|
</来源>
|
|
</来源>
|
|
|
<电子文件号 name="M7" />
|
|
<电子文件号 name="M7" />
|
|
|
<档号 name="M8">
|
|
<档号 name="M8">
|
|
@@ -133,24 +157,24 @@ XML_METADATA_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<页号 name="M20" />
|
|
<页号 name="M20" />
|
|
|
</档号>
|
|
</档号>
|
|
|
<内容描述 name="M21">
|
|
<内容描述 name="M21">
|
|
|
- <题名 name="M22">{title}</题名>
|
|
|
|
|
- <并列题名 name="M23" />
|
|
|
|
|
- <副题名 name="M24" />
|
|
|
|
|
- <说明题名文字 name="M25" />
|
|
|
|
|
- <主题词 name="M26" />
|
|
|
|
|
- <关键词 name="M27" />
|
|
|
|
|
- <人名 name="M28" />
|
|
|
|
|
- <摘要 name="M29" />
|
|
|
|
|
- <分类号 name="M30" />
|
|
|
|
|
- <文件编号 name="M31" />
|
|
|
|
|
- <责任者 name="M32" />
|
|
|
|
|
- <日期 name="M33">{date}</日期>
|
|
|
|
|
- <文种 name="M34" />
|
|
|
|
|
- <紧急程度 name="M35" />
|
|
|
|
|
- <主送 name="M36" />
|
|
|
|
|
- <抄送 name="M37" />
|
|
|
|
|
- <密级 name="M38" />
|
|
|
|
|
- <保管期限 name="M39" />
|
|
|
|
|
|
|
+ <题名 name="M22">{title}</题名>
|
|
|
|
|
+ <并列题名 name="M23" />
|
|
|
|
|
+ <副题名 name="M24" />
|
|
|
|
|
+ <说明题名文字 name="M25" />
|
|
|
|
|
+ <主题词 name="M26" />
|
|
|
|
|
+ <关键词 name="M27" />
|
|
|
|
|
+ <人名 name="M28" />
|
|
|
|
|
+ <摘要 name="M29" />
|
|
|
|
|
+ <分类号 name="M30" />
|
|
|
|
|
+ <文件编号 name="M31" />
|
|
|
|
|
+ <责任者 name="M32" />
|
|
|
|
|
+ <日期 name="M33">{date_compact}</日期>
|
|
|
|
|
+ <文种 name="M34" />
|
|
|
|
|
+ <紧急程度 name="M35" />
|
|
|
|
|
+ <主送 name="M36" />
|
|
|
|
|
+ <抄送 name="M37" />
|
|
|
|
|
+ <密级 name="M38" />
|
|
|
|
|
+ <保管期限 name="M39" />
|
|
|
</内容描述>
|
|
</内容描述>
|
|
|
<形式特征 name="M41">
|
|
<形式特征 name="M41">
|
|
|
<文件组合类型 name="M42" />
|
|
<文件组合类型 name="M42" />
|
|
@@ -164,16 +188,51 @@ XML_METADATA_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
{docs}
|
|
{docs}
|
|
|
</文件数据>
|
|
</文件数据>
|
|
|
</文件实体>
|
|
</文件实体>
|
|
|
|
|
+ <文件实体关系 name="M222">
|
|
|
|
|
+ <文件标识符 name="M223">{file_id}</文件标识符>
|
|
|
|
|
+ <被关联文件标识符 name="M224" />
|
|
|
|
|
+ <关系类型 name="M87" />
|
|
|
|
|
+ <关系 name="M87" />
|
|
|
|
|
+ <关系描述 name="M88" />
|
|
|
|
|
+ </文件实体关系>
|
|
|
</文件实体块>
|
|
</文件实体块>
|
|
|
|
|
+ <业务实体块 name="M225">
|
|
|
|
|
+{business_entities_xml}
|
|
|
|
|
+ </业务实体块>
|
|
|
|
|
+ <机构人员实体块 name="M229">
|
|
|
|
|
+{person_entities_xml}
|
|
|
|
|
+ </机构人员实体块>
|
|
|
</封装内容>
|
|
</封装内容>
|
|
|
</被签名对象>
|
|
</被签名对象>
|
|
|
|
|
+ <电子签名块 name="M201">
|
|
|
|
|
+ <电子签名 name="M57">
|
|
|
|
|
+ <签名标识符 name="M234" />
|
|
|
|
|
+ <签名规则 name="M58" />
|
|
|
|
|
+ <签名时间 name="M59" />
|
|
|
|
|
+ <签名人 name="M60" />
|
|
|
|
|
+ <签名结果 name="M61" />
|
|
|
|
|
+ <签名算法标识 name="M64" />
|
|
|
|
|
+ </电子签名>
|
|
|
|
|
+ </电子签名块>
|
|
|
|
|
+ <锁定签名 name="M201">
|
|
|
|
|
+ <被锁定签名标识符 name="M237" />
|
|
|
|
|
+ <签名规则 name="M58" />
|
|
|
|
|
+ <签名时间 name="M59" />
|
|
|
|
|
+ <签名人 name="M60" />
|
|
|
|
|
+ <签名结果 name="M61" />
|
|
|
|
|
+ <证书块 name="M235">
|
|
|
|
|
+ <证书 name="M62" />
|
|
|
|
|
+ <证书引证 name="M63" />
|
|
|
|
|
+ </证书块>
|
|
|
|
|
+ <签名算法标识 name="M64" />
|
|
|
|
|
+ </锁定签名>
|
|
|
</电子文件封装包>"""
|
|
</电子文件封装包>"""
|
|
|
|
|
|
|
|
XML_DOC_TEMPLATE = """ <文档>
|
|
XML_DOC_TEMPLATE = """ <文档>
|
|
|
<文档标识符 name="M215">{md5}</文档标识符>
|
|
<文档标识符 name="M215">{md5}</文档标识符>
|
|
|
<文档序号 name="M19" />
|
|
<文档序号 name="M19" />
|
|
|
<文档主从声明 name="M216" />
|
|
<文档主从声明 name="M216" />
|
|
|
- <题名 name="M22"/>
|
|
|
|
|
|
|
+ <题名 name="M22">{doc_title}</题名>
|
|
|
<文档数据 name="M217">
|
|
<文档数据 name="M217">
|
|
|
<编码 name="M218">
|
|
<编码 name="M218">
|
|
|
<电子属性 name="M46">
|
|
<电子属性 name="M46">
|
|
@@ -182,7 +241,7 @@ XML_DOC_TEMPLATE = """ <文档>
|
|
|
<计算机文件大小 name="M49">{size}</计算机文件大小>
|
|
<计算机文件大小 name="M49">{size}</计算机文件大小>
|
|
|
<文档创建程序 name="M50" />
|
|
<文档创建程序 name="M50" />
|
|
|
<信息系统描述 name="M51" />
|
|
<信息系统描述 name="M51" />
|
|
|
- <计算机文件创建时间 name="M101">{date}</计算机文件创建时间>
|
|
|
|
|
|
|
+ <计算机文件创建时间 name="M101">{date_compact}</计算机文件创建时间>
|
|
|
</电子属性>
|
|
</电子属性>
|
|
|
<数字化属性 name="M52">
|
|
<数字化属性 name="M52">
|
|
|
<数字化对象形态 name="M53" />
|
|
<数字化对象形态 name="M53" />
|
|
@@ -202,17 +261,334 @@ XML_DOC_TEMPLATE = """ <文档>
|
|
|
<签名算法标识 name="M64" />
|
|
<签名算法标识 name="M64" />
|
|
|
</电子签名>
|
|
</电子签名>
|
|
|
<存储位置 name="M65">
|
|
<存储位置 name="M65">
|
|
|
- <当前位置 name="M66" />
|
|
|
|
|
|
|
+ <当前位置 name="M66">{path}</当前位置>
|
|
|
<脱机载体编号 name="M67" />
|
|
<脱机载体编号 name="M67" />
|
|
|
<脱机载体存址 name="M68" />
|
|
<脱机载体存址 name="M68" />
|
|
|
<缩微号 name="M69" />
|
|
<缩微号 name="M69" />
|
|
|
</存储位置>
|
|
</存储位置>
|
|
|
|
|
+ <权限管理 name="M70">
|
|
|
|
|
+ <知识产权说明 name="M71" />
|
|
|
|
|
+ <控制标识 name="M74" />
|
|
|
|
|
+ </权限管理>
|
|
|
</文档数据>
|
|
</文档数据>
|
|
|
|
|
+ <固化信息块 name="P16">
|
|
|
|
|
+ <固化信息 name="P17">
|
|
|
|
|
+ <类型 name="P18" />
|
|
|
|
|
+ <值 name="P19" />
|
|
|
|
|
+ </固化信息>
|
|
|
|
|
+ </固化信息块>
|
|
|
</文档>"""
|
|
</文档>"""
|
|
|
|
|
|
|
|
|
|
+XML_BUSINESS_ENTITY_TEMPLATE = """ <业务实体 name="M226">
|
|
|
|
|
+ <业务标识符 name="M227">{business_id}</业务标识符>
|
|
|
|
|
+ <机构人员标识符 name="M228">{operator_id}</机构人员标识符>
|
|
|
|
|
+ <文件标识符 name="M223">{file_id}</文件标识符>
|
|
|
|
|
+ <业务状态 name="M80">历史行为</业务状态>
|
|
|
|
|
+ <业务行为 name="M81">审批</业务行为>
|
|
|
|
|
+ <行为时间 name="M82">{action_time}</行为时间>
|
|
|
|
|
+ <行为依据 name="M83">{action_basis}</行为依据>
|
|
|
|
|
+ <行为描述 name="M84">{description}</行为描述>
|
|
|
|
|
+ <机构人员名称 name="M77">{operator_name}</机构人员名称>
|
|
|
|
|
+ <组织机构代码 name="M78">{org_name}</组织机构代码>
|
|
|
|
|
+ </业务实体>"""
|
|
|
|
|
+
|
|
|
|
|
+XML_PERSON_ENTITY_TEMPLATE = """ <机构人员实体 name="M230">
|
|
|
|
|
+ <机构人员标识符 name="M210">{operator_id}</机构人员标识符>
|
|
|
|
|
+ <机构人员类型 name="M76">经办人</机构人员类型>
|
|
|
|
|
+ <机构人员名称 name="M77">{operator_name}</机构人员名称>
|
|
|
|
|
+ <组织机构代码 name="M78">{org_name}</组织机构代码>
|
|
|
|
|
+ <个人职位 name="M79" />
|
|
|
|
|
+ </机构人员实体>"""
|
|
|
|
|
+
|
|
|
|
|
+XML_PERSON_RELATION_TEMPLATE = """ <机构人员实体关系 name="M231">
|
|
|
|
|
+ <机构人员标识符 name="M228">{operator_id}</机构人员标识符>
|
|
|
|
|
+ <被关联机构人员标识符 name="M76" />
|
|
|
|
|
+ <关系类型 name="M77" />
|
|
|
|
|
+ <关系 name="M78" />
|
|
|
|
|
+ <关系描述 name="M79" />
|
|
|
|
|
+ </机构人员实体关系>"""
|
|
|
|
|
+
|
|
|
# 本地缓存文件
|
|
# 本地缓存文件
|
|
|
SQLITE_DB = 'measure_data_cache.db'
|
|
SQLITE_DB = 'measure_data_cache.db'
|
|
|
|
|
|
|
|
|
|
+# 流程节点 operateType -> 审核结论 映射 (参考 FlowProcessServiceImpl.resolveHisActivityStatus)
|
|
|
|
|
+OPERATE_TYPE_CONCLUSION = {
|
|
|
|
|
+ 'pass': '通过',
|
|
|
|
|
+ 'agree': '通过',
|
|
|
|
|
+ 'start': '通过',
|
|
|
|
|
+ 'reject': '驳回',
|
|
|
|
|
+ 'deliver': '转办',
|
|
|
|
|
+ 'stop': '终止',
|
|
|
|
|
+ 'read': '已阅',
|
|
|
|
|
+ 'addAssignee': '后加签',
|
|
|
|
|
+ 'insertAssignee': '前加签',
|
|
|
|
|
+ 'assignReject': '指定回退',
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# 流程节点查询 SQL: 从 Flowable 历史表还原 /api/flow/process/flow/detail 的 historyFlows 数据
|
|
|
|
|
+QUERY_FLOW_NODES = """
|
|
|
|
|
+ SELECT ai.ID_ AS node_id,
|
|
|
|
|
+ ai.TASK_ID_ AS task_id,
|
|
|
|
|
+ ai.ACT_ID_ AS task_def_key,
|
|
|
|
|
+ ai.ACT_NAME_ AS task_name,
|
|
|
|
|
+ ai.START_TIME_ AS create_time,
|
|
|
|
|
+ ai.END_TIME_ AS end_time,
|
|
|
|
|
+ ai.ASSIGNEE_ AS assignee,
|
|
|
|
|
+ u.account AS assignee_account,
|
|
|
|
|
+ u.real_name AS assignee_name,
|
|
|
|
|
+ d.full_name AS org_name,
|
|
|
|
|
+ (SELECT v.TEXT_
|
|
|
|
|
+ FROM ACT_HI_VARINST v
|
|
|
|
|
+ WHERE v.TASK_ID_ = ai.TASK_ID_
|
|
|
|
|
+ AND v.NAME_ = 'operateType'
|
|
|
|
|
+ LIMIT 1) AS operate_type,
|
|
|
|
|
+ (SELECT CONVERT(cm.FULL_MSG_ USING utf8mb4)
|
|
|
|
|
+ FROM ACT_HI_COMMENT cm
|
|
|
|
|
+ WHERE cm.TASK_ID_ = ai.TASK_ID_
|
|
|
|
|
+ AND cm.TYPE_ = 'comment'
|
|
|
|
|
+ ORDER BY cm.TIME_
|
|
|
|
|
+ LIMIT 1) AS comment_msg
|
|
|
|
|
+ FROM ACT_HI_ACTINST ai
|
|
|
|
|
+ LEFT JOIN blade_user u ON u.id = ai.ASSIGNEE_ AND u.is_deleted = 0
|
|
|
|
|
+ LEFT JOIN blade_dept d ON FIND_IN_SET(d.id, u.dept_id) AND d.is_deleted = 0
|
|
|
|
|
+ WHERE ai.PROC_INST_ID_ = %s
|
|
|
|
|
+ AND ai.ACT_TYPE_ = 'userTask'
|
|
|
|
|
+ ORDER BY IFNULL(ai.END_TIME_, NOW()), ai.START_TIME_
|
|
|
|
|
+"""
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def fetch_flow_nodes(cursor, flow_process_inst_id):
|
|
|
|
|
+ """获取计量单审核过程节点列表 (等价于 /api/flow/process/flow/detail 的 flow 数据)。
|
|
|
|
|
+
|
|
|
|
|
+ 只保留已办结 (END_TIME_ 非空) 且带 operateType 的节点,与后端
|
|
|
|
|
+ FlowProcessServiceImpl.resolveHisActivityStatus 的过滤逻辑一致。
|
|
|
|
|
+ """
|
|
|
|
|
+ if not flow_process_inst_id:
|
|
|
|
|
+ return []
|
|
|
|
|
+
|
|
|
|
|
+ # flow_process_inst.id -> proc_inst_id
|
|
|
|
|
+ cursor.execute(
|
|
|
|
|
+ "SELECT proc_inst_id FROM flow_process_inst WHERE id = %s",
|
|
|
|
|
+ (flow_process_inst_id,)
|
|
|
|
|
+ )
|
|
|
|
|
+ inst_row = cursor.fetchone()
|
|
|
|
|
+ if not inst_row or not inst_row.get('proc_inst_id'):
|
|
|
|
|
+ return []
|
|
|
|
|
+
|
|
|
|
|
+ cursor.execute(QUERY_FLOW_NODES, (inst_row['proc_inst_id'],))
|
|
|
|
|
+ rows = cursor.fetchall()
|
|
|
|
|
+
|
|
|
|
|
+ def fmt_time(value):
|
|
|
|
|
+ if not value:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ if isinstance(value, (datetime.datetime, datetime.date)):
|
|
|
|
|
+ return value.isoformat(timespec='milliseconds') if isinstance(value, datetime.datetime) else value.isoformat()
|
|
|
|
|
+ return str(value)
|
|
|
|
|
+
|
|
|
|
|
+ nodes = []
|
|
|
|
|
+ for row in rows:
|
|
|
|
|
+ # 未办结节点无 operateType, 后端同样跳过
|
|
|
|
|
+ if not row.get('end_time') or not row.get('operate_type'):
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ operate_type = str(row['operate_type'])
|
|
|
|
|
+ comment = row.get('comment_msg') or ''
|
|
|
|
|
+ if isinstance(comment, (bytes, bytearray)):
|
|
|
|
|
+ try:
|
|
|
|
|
+ comment = comment.decode('utf-8')
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ comment = ''
|
|
|
|
|
+
|
|
|
|
|
+ nodes.append({
|
|
|
|
|
+ 'id': row.get('node_id') or '',
|
|
|
|
|
+ 'name': row.get('task_name') or '',
|
|
|
|
|
+ 'type': '计量支付',
|
|
|
|
|
+ 'orgName': row.get('org_name') or ARCHIVE_UNIT,
|
|
|
|
|
+ 'operatorId': str(row.get('assignee') or row.get('assignee_account') or ''),
|
|
|
|
|
+ 'operatorName': row.get('assignee_name') or '',
|
|
|
|
|
+ 'createdTime': fmt_time(row.get('create_time')),
|
|
|
|
|
+ 'operateTime': fmt_time(row.get('end_time')),
|
|
|
|
|
+ 'opinion': comment,
|
|
|
|
|
+ 'conclusion': OPERATE_TYPE_CONCLUSION.get(operate_type, operate_type),
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return nodes
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def build_process_xml(process_nodes):
|
|
|
|
|
+ """把审核过程节点渲染成 说明文件.xml 的 <审核过程> 片段。"""
|
|
|
|
|
+ if not process_nodes:
|
|
|
|
|
+ return " <审核过程></审核过程>"
|
|
|
|
|
+
|
|
|
|
|
+ node_xml = "\n".join(
|
|
|
|
|
+ XML_PROCESS_NODE_TEMPLATE.format(
|
|
|
|
|
+ node_id=xml_escape(node.get('id')),
|
|
|
|
|
+ name=xml_escape(node.get('name')),
|
|
|
|
|
+ type=xml_escape(node.get('type')),
|
|
|
|
|
+ org_name=xml_escape(node.get('orgName')),
|
|
|
|
|
+ operator_name=xml_escape(node.get('operatorName')),
|
|
|
|
|
+ created_time=xml_escape(node.get('createdTime')),
|
|
|
|
|
+ operate_time=xml_escape(node.get('operateTime')),
|
|
|
|
|
+ opinion=xml_escape(node.get('opinion')),
|
|
|
|
|
+ conclusion=xml_escape(node.get('conclusion')),
|
|
|
|
|
+ )
|
|
|
|
|
+ for node in process_nodes
|
|
|
|
|
+ )
|
|
|
|
|
+ return " <审核过程>\n" + node_xml + "\n </审核过程>"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def xml_escape(value):
|
|
|
|
|
+ if value is None:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ return (str(value)
|
|
|
|
|
+ .replace('&', '&')
|
|
|
|
|
+ .replace('<', '<')
|
|
|
|
|
+ .replace('>', '>'))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def safe_value(value, default=''):
|
|
|
|
|
+ return default if value is None else value
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def format_date(value, fmt='%Y-%m-%d'):
|
|
|
|
|
+ if not value:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ if isinstance(value, (datetime.datetime, datetime.date)):
|
|
|
|
|
+ return value.strftime(fmt)
|
|
|
|
|
+ text = str(value).strip()
|
|
|
|
|
+ if not text:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ if len(text) >= 10 and text[4] == '-' and text[7] == '-':
|
|
|
|
|
+ try:
|
|
|
|
|
+ return datetime.datetime.strptime(text[:10], '%Y-%m-%d').strftime(fmt)
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ if len(text) >= 8 and text.isdigit():
|
|
|
|
|
+ try:
|
|
|
|
|
+ return datetime.datetime.strptime(text[:8], '%Y%m%d').strftime(fmt)
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ return text[:10] if fmt == '%Y-%m-%d' else text
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def format_datetime(value):
|
|
|
|
|
+ if not value:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ if isinstance(value, datetime.datetime):
|
|
|
|
|
+ return value.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
+ text = str(value).strip().replace('T', ' ')
|
|
|
|
|
+ if not text:
|
|
|
|
|
+ return ''
|
|
|
|
|
+ if len(text) >= 19:
|
|
|
|
|
+ return text[:19]
|
|
|
|
|
+ if len(text) == 10:
|
|
|
|
|
+ return text + ' 00:00:00'
|
|
|
|
|
+ return text
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def format_amount(value):
|
|
|
|
|
+ if value is None or value == '':
|
|
|
|
|
+ return '0.00'
|
|
|
|
|
+ try:
|
|
|
|
|
+ return f"{Decimal(str(value)).quantize(Decimal('0.01')):.2f}"
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ return str(value)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def stable_guid(seed):
|
|
|
|
|
+ return uuid.uuid5(uuid.NAMESPACE_URL, str(seed)).hex.upper()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def build_metadata_entities(order_data, file_id):
|
|
|
|
|
+ header = order_data.get('header') or {}
|
|
|
|
|
+ process_nodes = order_data.get('process') or []
|
|
|
|
|
+ business_rows = []
|
|
|
|
|
+ person_rows = []
|
|
|
|
|
+ seen_operators = set()
|
|
|
|
|
+
|
|
|
|
|
+ def add_entity(operator_id, operator_name, org_name, action_time, action, description, basis='', business_id=None):
|
|
|
|
|
+ operator_id = str(operator_id or '').strip()
|
|
|
|
|
+ operator_name = str(operator_name or '').strip()
|
|
|
|
|
+ org_name = str(org_name or '').strip()
|
|
|
|
|
+ action_time = format_datetime(action_time)
|
|
|
|
|
+ if not operator_id or not operator_name or not org_name or not action_time:
|
|
|
|
|
+ return
|
|
|
|
|
+ person_key = (operator_id, org_name)
|
|
|
|
|
+ if person_key not in seen_operators:
|
|
|
|
|
+ person_rows.append({
|
|
|
|
|
+ 'operator_id': operator_id,
|
|
|
|
|
+ 'operator_name': operator_name,
|
|
|
|
|
+ 'org_name': org_name,
|
|
|
|
|
+ })
|
|
|
|
|
+ seen_operators.add(person_key)
|
|
|
|
|
+ business_rows.append({
|
|
|
|
|
+ 'business_id': business_id or stable_guid(f"{file_id}:{operator_id}:{action_time}:{description}"),
|
|
|
|
|
+ 'operator_id': operator_id,
|
|
|
|
|
+ 'file_id': file_id,
|
|
|
|
|
+ 'action_time': action_time,
|
|
|
|
|
+ 'action_basis': basis,
|
|
|
|
|
+ 'action': action or '审批',
|
|
|
|
|
+ 'description': description or '文件审核通过',
|
|
|
|
|
+ 'operator_name': operator_name,
|
|
|
|
|
+ 'org_name': org_name,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ tabulator_id = header.get('tabulator_id') or order_data.get('tabulator_id') or f"OP{str(order_data.get('id'))[-12:]}"
|
|
|
|
|
+ tabulator_name = header.get('tabulator') or order_data.get('tabulator_name')
|
|
|
|
|
+ tabulation_date = header.get('tabulation_date')
|
|
|
|
|
+ tabulator_org = header.get('tabulator_org') or header.get('contractor') or header.get('section') or ARCHIVE_UNIT
|
|
|
|
|
+ add_entity(
|
|
|
|
|
+ tabulator_id,
|
|
|
|
|
+ tabulator_name,
|
|
|
|
|
+ tabulator_org,
|
|
|
|
|
+ tabulation_date,
|
|
|
|
|
+ '制表',
|
|
|
|
|
+ f"{tabulator_name or ''}文件制表提交".strip(),
|
|
|
|
|
+ business_id=stable_guid(f"{file_id}:tabulator")
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ for node in process_nodes:
|
|
|
|
|
+ operator_id = node.get('operatorId') or node.get('assignee')
|
|
|
|
|
+ operator_name = node.get('operatorName')
|
|
|
|
|
+ org_name = node.get('orgName') or ARCHIVE_UNIT
|
|
|
|
|
+ conclusion = node.get('conclusion') or '通过'
|
|
|
|
|
+ action = '审批通过' if conclusion == '通过' else f"审批{conclusion}"
|
|
|
|
|
+ description = f"{node.get('name') or '审批节点'}-{operator_name or ''}{action}".strip('-')
|
|
|
|
|
+ add_entity(
|
|
|
|
|
+ operator_id,
|
|
|
|
|
+ operator_name,
|
|
|
|
|
+ org_name,
|
|
|
|
|
+ node.get('operateTime'),
|
|
|
|
|
+ '审批',
|
|
|
|
|
+ description,
|
|
|
|
|
+ node.get('id') or node.get('taskId') or '',
|
|
|
|
|
+ stable_guid(f"{file_id}:{node.get('id') or node.get('taskId') or node.get('operatorId')}")
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if not business_rows:
|
|
|
|
|
+ fallback_id = tabulator_id or f"OP{str(order_data.get('id'))[-12:]}"
|
|
|
|
|
+ fallback_name = tabulator_name or '系统管理员'
|
|
|
|
|
+ fallback_org = tabulator_org
|
|
|
|
|
+ fallback_time = tabulation_date or datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
+ add_entity(fallback_id, fallback_name, fallback_org, fallback_time, '审批', f"{fallback_name}文件审核通过", business_id=stable_guid(f"{file_id}:fallback"))
|
|
|
|
|
+
|
|
|
|
|
+ business_xml = "\n".join(
|
|
|
|
|
+ XML_BUSINESS_ENTITY_TEMPLATE.format(**{k: xml_escape(v) for k, v in row.items()})
|
|
|
|
|
+ for row in business_rows
|
|
|
|
|
+ )
|
|
|
|
|
+ person_xml = "\n".join(
|
|
|
|
|
+ XML_PERSON_ENTITY_TEMPLATE.format(**{k: xml_escape(v) for k, v in row.items()})
|
|
|
|
|
+ for row in person_rows
|
|
|
|
|
+ )
|
|
|
|
|
+ if person_rows:
|
|
|
|
|
+ relation_xml = "\n".join(
|
|
|
|
|
+ XML_PERSON_RELATION_TEMPLATE.format(operator_id=xml_escape(row['operator_id']))
|
|
|
|
|
+ for row in person_rows
|
|
|
|
|
+ )
|
|
|
|
|
+ person_xml = person_xml + "\n" + relation_xml
|
|
|
|
|
+ return business_xml, person_xml
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def init_sqlite():
|
|
def init_sqlite():
|
|
|
conn = sqlite3.connect(SQLITE_DB)
|
|
conn = sqlite3.connect(SQLITE_DB)
|
|
|
cursor = conn.cursor()
|
|
cursor = conn.cursor()
|
|
@@ -277,24 +653,37 @@ def fetch_from_mysql():
|
|
|
cursor.execute("SELECT * FROM mp_construction_measure_others WHERE mp_construction_measure_id = %s AND is_deleted = 0", (order_id,))
|
|
cursor.execute("SELECT * FROM mp_construction_measure_others WHERE mp_construction_measure_id = %s AND is_deleted = 0", (order_id,))
|
|
|
others = cursor.fetchall()
|
|
others = cursor.fetchall()
|
|
|
|
|
|
|
|
- # 4. 获取 Tabulator Name (blade_user)
|
|
|
|
|
tabulator_name = None
|
|
tabulator_name = None
|
|
|
|
|
+ tabulator_id = str(order.get('tabulator') or '')
|
|
|
|
|
+ tabulator_org = None
|
|
|
if order.get('tabulator'):
|
|
if order.get('tabulator'):
|
|
|
- cursor.execute("SELECT real_name FROM blade_user WHERE id = %s", (order['tabulator'],))
|
|
|
|
|
|
|
+ cursor.execute("""
|
|
|
|
|
+ SELECT u.id, u.account, u.real_name, d.full_name AS org_name
|
|
|
|
|
+ FROM blade_user u
|
|
|
|
|
+ LEFT JOIN blade_dept d ON FIND_IN_SET(d.id, u.dept_id) AND d.is_deleted = 0
|
|
|
|
|
+ WHERE u.id = %s AND u.is_deleted = 0
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ """, (order['tabulator'],))
|
|
|
user_row = cursor.fetchone()
|
|
user_row = cursor.fetchone()
|
|
|
if user_row:
|
|
if user_row:
|
|
|
tabulator_name = user_row['real_name']
|
|
tabulator_name = user_row['real_name']
|
|
|
|
|
+ tabulator_id = str(user_row.get('id') or order.get('tabulator') or '')
|
|
|
|
|
+ tabulator_org = user_row.get('org_name')
|
|
|
|
|
|
|
|
# 5. 获取附件
|
|
# 5. 获取附件
|
|
|
# 关联 mp_measure_attachments 和 tb_file (corrected from blade_attach)
|
|
# 关联 mp_measure_attachments 和 tb_file (corrected from blade_attach)
|
|
|
query_attachments = """
|
|
query_attachments = """
|
|
|
- SELECT a.id, a.mp_measure_id, f.file_title as name, f.path as link
|
|
|
|
|
|
|
+ SELECT a.id, a.mp_measure_id, a.sort, f.file_title as name, f.path as link, f.file_hash, f.create_time AS file_create_time
|
|
|
FROM mp_measure_attachments a
|
|
FROM mp_measure_attachments a
|
|
|
JOIN tb_file f ON a.file_id = f.id
|
|
JOIN tb_file f ON a.file_id = f.id
|
|
|
WHERE a.mp_measure_id = %s AND a.is_deleted = 0 AND f.is_deleted = 0
|
|
WHERE a.mp_measure_id = %s AND a.is_deleted = 0 AND f.is_deleted = 0
|
|
|
|
|
+ ORDER BY a.sort, a.id
|
|
|
"""
|
|
"""
|
|
|
cursor.execute(query_attachments, (order_id,))
|
|
cursor.execute(query_attachments, (order_id,))
|
|
|
attachments = cursor.fetchall()
|
|
attachments = cursor.fetchall()
|
|
|
|
|
+
|
|
|
|
|
+ # 6. 获取审核过程 (流程节点)
|
|
|
|
|
+ process_nodes = fetch_flow_nodes(cursor, order.get('flow_process_inst_id'))
|
|
|
|
|
|
|
|
# 格式化附件数据
|
|
# 格式化附件数据
|
|
|
attachment_list = []
|
|
attachment_list = []
|
|
@@ -305,7 +694,9 @@ def fetch_from_mysql():
|
|
|
attachment_list.append({
|
|
attachment_list.append({
|
|
|
'id': str(att['id']),
|
|
'id': str(att['id']),
|
|
|
'name': att['name'],
|
|
'name': att['name'],
|
|
|
- 'url': url
|
|
|
|
|
|
|
+ 'url': url,
|
|
|
|
|
+ 'hash': att.get('file_hash') or '',
|
|
|
|
|
+ 'fileCreateTime': att.get('file_create_time').isoformat() if isinstance(att.get('file_create_time'), (datetime.date, datetime.datetime)) else att.get('file_create_time')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
# Helper to serialize date/decimal
|
|
# Helper to serialize date/decimal
|
|
@@ -367,15 +758,18 @@ def fetch_from_mysql():
|
|
|
# Flattened Header Info
|
|
# Flattened Header Info
|
|
|
header_info = {
|
|
header_info = {
|
|
|
'measure_no': order.get('measure_no'),
|
|
'measure_no': order.get('measure_no'),
|
|
|
- 'section': contract.get('section_id') if contract else None, # Assuming section_id holds the name
|
|
|
|
|
- 'measure_method': '分解计量', # Hardcoded as per screenshot/context
|
|
|
|
|
|
|
+ 'measure_period': order.get('end_date').strftime('%Y%m') if order.get('end_date') else None,
|
|
|
|
|
+ 'section': contract.get('section_id') if contract else None,
|
|
|
|
|
+ 'measure_method': '分解计量',
|
|
|
'employer': contract.get('employer') if contract else None,
|
|
'employer': contract.get('employer') if contract else None,
|
|
|
'contractor': order.get('construct_dept') or (contract.get('contractor_dept') if contract else None),
|
|
'contractor': order.get('construct_dept') or (contract.get('contractor_dept') if contract else None),
|
|
|
'supervisor': contract.get('jl_section') if contract else None,
|
|
'supervisor': contract.get('jl_section') if contract else None,
|
|
|
'period_start': order.get('start_date').isoformat() if order.get('start_date') else None,
|
|
'period_start': order.get('start_date').isoformat() if order.get('start_date') else None,
|
|
|
'period_end': order.get('end_date').isoformat() if order.get('end_date') else None,
|
|
'period_end': order.get('end_date').isoformat() if order.get('end_date') else None,
|
|
|
'tabulation_date': order.get('tabulation_time').isoformat() if order.get('tabulation_time') else None,
|
|
'tabulation_date': order.get('tabulation_time').isoformat() if order.get('tabulation_time') else None,
|
|
|
- 'tabulator': tabulator_name
|
|
|
|
|
|
|
+ 'tabulator_id': tabulator_id,
|
|
|
|
|
+ 'tabulator': tabulator_name,
|
|
|
|
|
+ 'tabulator_org': tabulator_org
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Statistics Info
|
|
# Statistics Info
|
|
@@ -397,7 +791,8 @@ def fetch_from_mysql():
|
|
|
'status': order.get('status'), # Keep for internal use
|
|
'status': order.get('status'), # Keep for internal use
|
|
|
'header': header_info,
|
|
'header': header_info,
|
|
|
'statistics': statistics_info,
|
|
'statistics': statistics_info,
|
|
|
- 'attachments': attachment_list
|
|
|
|
|
|
|
+ 'attachments': attachment_list,
|
|
|
|
|
+ 'process': process_nodes
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
cursor.close()
|
|
cursor.close()
|
|
@@ -452,10 +847,11 @@ def cache_data(sqlite_conn, data_list):
|
|
|
count_new += 1
|
|
count_new += 1
|
|
|
else:
|
|
else:
|
|
|
# Update data and reset sync_status to 0 to ensure updated data is synced
|
|
# Update data and reset sync_status to 0 to ensure updated data is synced
|
|
|
- cursor.execute('''
|
|
|
|
|
- UPDATE measure_orders SET data_json = ?, sync_status = 0 WHERE id = ?
|
|
|
|
|
- ''', (json_str, order_id))
|
|
|
|
|
- count_updated += 1
|
|
|
|
|
|
|
+ # cursor.execute('''
|
|
|
|
|
+ # UPDATE measure_orders SET data_json = ?, sync_status = 0 WHERE id = ?
|
|
|
|
|
+ # ''', (json_str, order_id))
|
|
|
|
|
+ # count_updated += 1
|
|
|
|
|
+ continue
|
|
|
|
|
|
|
|
|
|
|
|
|
# 存储附件信息
|
|
# 存储附件信息
|
|
@@ -536,10 +932,22 @@ def download_file(url, dest_path):
|
|
|
def create_eep_package(order_data, output_dir='eep_packages'):
|
|
def create_eep_package(order_data, output_dir='eep_packages'):
|
|
|
order_id = str(order_data['id'])
|
|
order_id = str(order_data['id'])
|
|
|
archive_id = order_id
|
|
archive_id = order_id
|
|
|
- year = datetime.datetime.now().year
|
|
|
|
|
- date_str = datetime.datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
- date_compact = datetime.datetime.now().strftime('%Y%m%d')
|
|
|
|
|
-
|
|
|
|
|
|
|
+ header = order_data.get('header') or {}
|
|
|
|
|
+ statistics = order_data.get('statistics') or {}
|
|
|
|
|
+ measure_no = header.get('measure_no') or ''
|
|
|
|
|
+ title = f"计量单-{measure_no}"
|
|
|
|
|
+ tabulation_raw = header.get('tabulation_date')
|
|
|
|
|
+ period_end_raw = header.get('period_end')
|
|
|
|
|
+ current_period = header.get('measure_period') or format_date(period_end_raw, '%Y%m')
|
|
|
|
|
+ tabulator_id = header.get('tabulator_id') or f"OP{order_id[-12:]}"
|
|
|
|
|
+ if not current_period and measure_no and len(measure_no.split('-')) >= 2:
|
|
|
|
|
+ current_period = measure_no.split('-')[-2]
|
|
|
|
|
+ year_source = tabulation_raw or period_end_raw
|
|
|
|
|
+ year = int(format_date(year_source, '%Y') or datetime.datetime.now().year)
|
|
|
|
|
+ date_str = format_date(tabulation_raw) or datetime.datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
+ date_compact = format_date(tabulation_raw, '%Y%m%d') or datetime.datetime.now().strftime('%Y%m%d')
|
|
|
|
|
+ file_id = stable_guid(f"file:{archive_id}")
|
|
|
|
|
+
|
|
|
# Clean output dir for this order
|
|
# Clean output dir for this order
|
|
|
pkg_root = os.path.join(output_dir, archive_id)
|
|
pkg_root = os.path.join(output_dir, archive_id)
|
|
|
if os.path.exists(pkg_root):
|
|
if os.path.exists(pkg_root):
|
|
@@ -568,12 +976,13 @@ def create_eep_package(order_data, output_dir='eep_packages'):
|
|
|
fext = os.path.splitext(fname)[1].lstrip('.')
|
|
fext = os.path.splitext(fname)[1].lstrip('.')
|
|
|
files_info.append({
|
|
files_info.append({
|
|
|
'name': fname,
|
|
'name': fname,
|
|
|
- 'path': f'/电子档案/{year}/{archive_id}/{fname}',
|
|
|
|
|
|
|
+ 'path': f'电子档案/{year}/{archive_id}/{fname}',
|
|
|
'real_path': local_path,
|
|
'real_path': local_path,
|
|
|
'size': fsize,
|
|
'size': fsize,
|
|
|
- 'md5': fmd5,
|
|
|
|
|
|
|
+ 'md5': (att.get('hash') or fmd5).lower(),
|
|
|
'ext': fext,
|
|
'ext': fext,
|
|
|
- 'type': '附件'
|
|
|
|
|
|
|
+ 'type': '附件',
|
|
|
|
|
+ 'created': att.get('fileCreateTime') or tabulation_raw or date_str
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
# Calculate total size
|
|
# Calculate total size
|
|
@@ -586,7 +995,8 @@ def create_eep_package(order_data, output_dir='eep_packages'):
|
|
|
size=total_size,
|
|
size=total_size,
|
|
|
date=date_str,
|
|
date=date_str,
|
|
|
year=year,
|
|
year=year,
|
|
|
- file_count=len(files_info)
|
|
|
|
|
|
|
+ file_count=len(files_info),
|
|
|
|
|
+ process_xml=build_process_xml(order_data.get('process') or [])
|
|
|
)
|
|
)
|
|
|
with open(os.path.join(pkg_root, '说明文件.xml'), 'w', encoding='utf-8') as f:
|
|
with open(os.path.join(pkg_root, '说明文件.xml'), 'w', encoding='utf-8') as f:
|
|
|
f.write(desc_xml)
|
|
f.write(desc_xml)
|
|
@@ -602,37 +1012,58 @@ def create_eep_package(order_data, output_dir='eep_packages'):
|
|
|
type=f['type']
|
|
type=f['type']
|
|
|
) + "\n"
|
|
) + "\n"
|
|
|
|
|
|
|
|
- catalog_xml = XML_CATALOG_TEMPLATE.format(
|
|
|
|
|
- doc_num=order_data.get('header', {}).get('measure_no', ''),
|
|
|
|
|
- title=f"计量单-{order_data.get('header', {}).get('measure_no', '')}",
|
|
|
|
|
- date=date_str,
|
|
|
|
|
- date_compact=date_compact,
|
|
|
|
|
- archive_id=archive_id,
|
|
|
|
|
- year=year,
|
|
|
|
|
- file_details=file_details_xml
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ catalog_values = {
|
|
|
|
|
+ 'doc_num': measure_no,
|
|
|
|
|
+ 'title': title,
|
|
|
|
|
+ 'date': date_str,
|
|
|
|
|
+ 'date_compact': date_compact,
|
|
|
|
|
+ 'archive_id': archive_id,
|
|
|
|
|
+ 'year': year,
|
|
|
|
|
+ 'file_details': file_details_xml,
|
|
|
|
|
+ 'signing_unit': CATALOG_SIGNING_UNIT,
|
|
|
|
|
+ 'current_period': current_period,
|
|
|
|
|
+ 'measure_number': header.get('measure_no') or '',
|
|
|
|
|
+ 'period_start': format_date(header.get('period_start')),
|
|
|
|
|
+ 'period_end': format_date(header.get('period_end')),
|
|
|
|
|
+ 'tabulator_id': tabulator_id,
|
|
|
|
|
+ 'tabulator_name': header.get('tabulator') or '',
|
|
|
|
|
+ 'tabulation_date': format_date(tabulation_raw),
|
|
|
|
|
+ 'completed_last_period': format_amount(statistics.get('completed_last_period')),
|
|
|
|
|
+ 'current_period_amount': format_amount(statistics.get('subtotal')),
|
|
|
|
|
+ 'completed_cumulative': format_amount(statistics.get('completed_cumulative')),
|
|
|
|
|
+ }
|
|
|
|
|
+ catalog_xml = XML_CATALOG_TEMPLATE.format(**{key: xml_escape(value) if key != 'file_details' else value for key, value in catalog_values.items()})
|
|
|
with open(os.path.join(pkg_root, '文件目录.xml'), 'w', encoding='utf-8') as f:
|
|
with open(os.path.join(pkg_root, '文件目录.xml'), 'w', encoding='utf-8') as f:
|
|
|
f.write(catalog_xml)
|
|
f.write(catalog_xml)
|
|
|
|
|
|
|
|
# 3. 文件元数据.xml
|
|
# 3. 文件元数据.xml
|
|
|
docs_xml = ""
|
|
docs_xml = ""
|
|
|
- for f in files_info:
|
|
|
|
|
- docs_xml += XML_DOC_TEMPLATE.format(
|
|
|
|
|
- date=date_str,
|
|
|
|
|
- md5=f['md5'],
|
|
|
|
|
- ext=f['ext'],
|
|
|
|
|
- filename=f['name'],
|
|
|
|
|
- size=f['size'],
|
|
|
|
|
- date_compact=date_compact
|
|
|
|
|
- ) + "\n"
|
|
|
|
|
-
|
|
|
|
|
- metadata_xml = XML_METADATA_TEMPLATE.format(
|
|
|
|
|
- date=date_str,
|
|
|
|
|
- year=year,
|
|
|
|
|
- title=f"计量单-{order_data.get('header', {}).get('measure_no', '')}",
|
|
|
|
|
- date_compact=date_compact,
|
|
|
|
|
- docs=docs_xml
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ for file_info in files_info:
|
|
|
|
|
+ doc_values = {
|
|
|
|
|
+ 'date': date_str,
|
|
|
|
|
+ 'md5': file_info['md5'],
|
|
|
|
|
+ 'ext': file_info['ext'],
|
|
|
|
|
+ 'filename': file_info['name'],
|
|
|
|
|
+ 'size': file_info['size'],
|
|
|
|
|
+ 'date_compact': format_date(file_info.get('created'), '%Y%m%d') or date_compact,
|
|
|
|
|
+ 'doc_title': file_info['name'],
|
|
|
|
|
+ 'path': file_info['path'],
|
|
|
|
|
+ }
|
|
|
|
|
+ docs_xml += XML_DOC_TEMPLATE.format(**{key: xml_escape(value) for key, value in doc_values.items()}) + "\n"
|
|
|
|
|
+
|
|
|
|
|
+ business_entities_xml, person_entities_xml = build_metadata_entities(order_data, file_id)
|
|
|
|
|
+ metadata_values = {
|
|
|
|
|
+ 'date': date_str,
|
|
|
|
|
+ 'year': year,
|
|
|
|
|
+ 'title': title,
|
|
|
|
|
+ 'date_compact': date_compact,
|
|
|
|
|
+ 'docs': docs_xml,
|
|
|
|
|
+ 'file_id': file_id,
|
|
|
|
|
+ 'archive_unit': ARCHIVE_UNIT,
|
|
|
|
|
+ 'business_entities_xml': business_entities_xml,
|
|
|
|
|
+ 'person_entities_xml': person_entities_xml,
|
|
|
|
|
+ }
|
|
|
|
|
+ metadata_xml = XML_METADATA_TEMPLATE.format(**{key: value if key in {'docs', 'business_entities_xml', 'person_entities_xml'} else xml_escape(value) for key, value in metadata_values.items()})
|
|
|
with open(os.path.join(archive_dir, '文件元数据.xml'), 'w', encoding='utf-8') as f:
|
|
with open(os.path.join(archive_dir, '文件元数据.xml'), 'w', encoding='utf-8') as f:
|
|
|
f.write(metadata_xml)
|
|
f.write(metadata_xml)
|
|
|
|
|
|
|
@@ -739,10 +1170,10 @@ def sync_to_external_system(sqlite_conn):
|
|
|
for row in rows:
|
|
for row in rows:
|
|
|
order_id = row[0]
|
|
order_id = row[0]
|
|
|
data_json = row[1]
|
|
data_json = row[1]
|
|
|
- if order_id == '2005072020533338113':
|
|
|
|
|
- print(f"Debug: {order_id}")
|
|
|
|
|
- else:
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ # if order_id == '2005072020533338113':
|
|
|
|
|
+ # print(f"Debug: {order_id}")
|
|
|
|
|
+ # else:
|
|
|
|
|
+ # continue
|
|
|
data = json.loads(data_json)
|
|
data = json.loads(data_json)
|
|
|
try:
|
|
try:
|
|
|
print(f"Processing order {data.get('header', {}).get('measure_no', 'Unknown')} (ID: {order_id})...")
|
|
print(f"Processing order {data.get('header', {}).get('measure_no', 'Unknown')} (ID: {order_id})...")
|