feat(scripts): 投标产线自持 init 导入脚本(码表幂等+废弃码清理+产线描述)

This commit is contained in:
yumoqing 2026-08-31 13:45:57 +08:00
parent 44f8c18ac3
commit 45cdb2e61e

View File

@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""投标产线 init 数据导入(码表 + 产线描述),幂等可重复执行。
独立于宿主 scripts/import_init.py(其 INIT_MODULES 漏了本模块),
由模块自己维护,部署时在宿主应用根目录执行:
cd <APP_ROOT> && py3/bin/python pkgs/pipeline-bidding/scripts/import_init_bidding.py
"""
import os
import subprocess
import sys
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "..", "..", ".."))
sys.path.insert(0, ROOT_DIR)
from appPublic.jsonConfig import getConfig
from appPublic.aes import aes_decode_b64
def mysql_exec(kw, pwd, sql):
r = subprocess.run(
["mysql", "-h", str(kw.host), "-P", str(kw.port),
"-u", str(kw.user), "-p%s" % pwd, str(kw.db), "-e", sql],
capture_output=True, text=True)
if r.returncode != 0:
raise RuntimeError(r.stderr[:300])
return r.stdout.strip()
def main():
cfg = getConfig(ROOT_DIR, {"workdir": ROOT_DIR})
kw = cfg.databases["pipeline"].kwargs
pwd = aes_decode_b64(cfg.password_key, kw.password)
# ── 1. bid_qc_type:QC 审核对象码表(幂等:按组合键)──
qc_items = [
("scoring_items", "评分项+得分规则"),
("qualifications", "所需资质"),
("doc_requirements", "投标文件要求"),
("chapter_outline", "章节骨架"),
]
mysql_exec(kw, pwd,
"INSERT IGNORE INTO appcodes (id, name, hierarchy_flg) "
"VALUES ('bid_qc_type', 'QC审核对象', '0')")
for k, v in qc_items:
mysql_exec(kw, pwd,
"INSERT IGNORE INTO appcodes_kv (id, parentid, k, v) "
"VALUES ('bid_qc_type_%s', 'bid_qc_type', '%s', '%s')" % (k, k, v))
print("bid_qc_type: %d items ensured" % len(qc_items))
# ── 2. bid_tender_source:旧值 mail(邮件采集) 已废弃 → 替换为 tender_doc ──
mysql_exec(kw, pwd,
"DELETE FROM appcodes_kv WHERE id='bid_tender_source_mail'")
mysql_exec(kw, pwd,
"INSERT IGNORE INTO appcodes_kv (id, parentid, k, v) "
"VALUES ('bid_tender_source_tender_doc', 'bid_tender_source', "
"'tender_doc', '招标文件解析')")
print("bid_tender_source: mail removed, tender_doc ensured")
# ── 3. 已废弃的招标审批状态码表清理(前三步归商机产线)──
mysql_exec(kw, pwd, "DELETE FROM appcodes_kv WHERE parentid='bid_tender_status'")
mysql_exec(kw, pwd, "DELETE FROM appcodes WHERE id='bid_tender_status'")
print("bid_tender_status: deprecated codes cleaned")
# ── 4. 产线描述更新 ──
desc = ("上传招标文件→解析(评分项/得分规则/资质/投标文件要求/章节骨架)"
"→QC契合度审核→资质准备→分章节编写→章节评审→合成标书→整书评分→交付。"
"招标信息的采集/摘要/审批归商机产线。")
mysql_exec(kw, pwd,
"UPDATE pipelines SET description='%s' WHERE id='bidding_general'" % desc)
print("pipelines.bidding_general: description updated")
if __name__ == "__main__":
main()