v1.1.0: 实现核心业务逻辑(扫描/任务书/派发/状态机)
新增(scripts/ 分层完整实现):
- scripts/util/{constants,date_util,runtime_paths,logging_setup}.py
- scripts/db/{connection,seed_data,repository}.py(SQLite + 5 张表 + 50 份样例合同)
- scripts/service/{scanner,task_generator,dispatcher,html_renderer}.py
- scripts/cli/app.py(argparse 子命令)
- scripts/templates/task.html.j2(Jinja2 渲染,无 jinja2 时降级到 str.replace)
- examples/{contracts_sample,performance_sample}.csv(本地样例数据)
修改:
- scripts/main.py:argparse + jiangchang_skill_core 降级
- SKILL.md:version 1.0.1 → 1.1.0
- CHANGELOG.md:加 v1.1.0 条目
- .env.example:加 DB_PATH / HTML_OUTPUT_DIR / JIANGCHANG_DATA_DIR
本地验证(9 个 CLI 命令全部 exit code = 0):
- health / version / config-path / init-db:基础 4 命令
- scan-expiring-contracts --thresholds 90,60,30:42 份可续聘 → 红 10 / 橙 10 / 黄 10,生成 30 任务
- render-html:写 output/<task_id>.html(4.9 KB)
- generate-renewal-task:单份合同任务书生成
- mark-contract-renewed:状态机更新 + 关闭 open alerts
- dispatch-task-notice:按单位/月份派发 payload(dry-run 模式)
业务规则(AI 续聘建议本地版,规则顺序判断):
1. 师德 < 60 → non_renew
2. 近 3 年考核有不合格(< 60)→ observe
3. 全部 >= 80 且逐年上升 → renew
4. 其他 → observe
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
112
scripts/main.py
112
scripts/main.py
@@ -1,91 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""合同到期智能预警与续聘辅助 - CLI 入口(占位骨架)"""
|
||||
# -*- coding: utf-8 -*-
|
||||
"""合同到期智能预警与续聘辅助 - CLI 入口。
|
||||
|
||||
v1.1.0 实现:
|
||||
- argparse 子命令分发
|
||||
- jiangchang_skill_core 降级(宿主环境用完整版,本地用自包含实现)
|
||||
- UTF-8 输出兼容(Windows cmd)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 占位:开发者后续接入 jiangchang_skill_core
|
||||
# from jiangchang_skill_core import ...
|
||||
# UTF-8 输出兼容(Windows)
|
||||
if sys.platform == "win32":
|
||||
if hasattr(sys.stdout, "buffer"):
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
|
||||
if hasattr(sys.stderr, "buffer"):
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# scripts/main.py → scripts/ → 加进 sys.path
|
||||
_scripts_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if _scripts_dir not in sys.path:
|
||||
sys.path.insert(0, _scripts_dir)
|
||||
|
||||
|
||||
def health():
|
||||
"""运行检查(占位)。"""
|
||||
print(f"alert-contract-expiring-hr health check (placeholder)")
|
||||
print(f"base_dir: {BASE_DIR}")
|
||||
return 0
|
||||
def _apply_host_runtime() -> None:
|
||||
"""宿主共享 runtime 集成(本地无 jiangchang_skill_core 时跳过)。"""
|
||||
try:
|
||||
from jiangchang_skill_core.runtime_env import apply_cli_local_defaults
|
||||
|
||||
apply_cli_local_defaults()
|
||||
except ImportError:
|
||||
pass # 本地环境没有宿主 runtime,跳过
|
||||
|
||||
|
||||
def version():
|
||||
"""查看版本(占位)。"""
|
||||
print("alert-contract-expiring-hr v1.0.1")
|
||||
return 0
|
||||
|
||||
|
||||
def config_path():
|
||||
"""查看配置位置(占位)。"""
|
||||
print(f"{BASE_DIR / '.env'}")
|
||||
return 0
|
||||
|
||||
|
||||
def init_db():
|
||||
"""初始化数据库(占位)。"""
|
||||
print("init-db: 后续由开发者按 references/SCHEMA.md 实现")
|
||||
return 0
|
||||
|
||||
|
||||
def scan_expiring_contracts(thresholds: str = "90,60,30"):
|
||||
"""扫描即将到期合同(async)。"""
|
||||
print(f"scan-expiring-contracts: thresholds={thresholds} (待开发者实现)")
|
||||
return 0
|
||||
|
||||
|
||||
def generate_renewal_task(contract_id: str):
|
||||
"""生成续聘任务书。"""
|
||||
print(f"generate-renewal-task: contract_id={contract_id} (待开发者实现)")
|
||||
return 0
|
||||
|
||||
|
||||
def dispatch_task_notice(unit_id: str = "", month: str = ""):
|
||||
"""下发续聘任务通知单。"""
|
||||
print(f"dispatch-task-notice: unit_id={unit_id} month={month} (待开发者实现)")
|
||||
return 0
|
||||
|
||||
|
||||
def mark_contract_renewed(contract_id: str, material_id: str):
|
||||
"""标记合同已续签。"""
|
||||
print(f"mark-contract-renewed: contract_id={contract_id} material_id={material_id} (待开发者实现)")
|
||||
return 0
|
||||
|
||||
|
||||
def render_html(task_id: str):
|
||||
"""在浏览器中打开续聘任务书。"""
|
||||
print(f"render-html: task_id={task_id} (待开发者实现)")
|
||||
return 0
|
||||
|
||||
|
||||
COMMANDS = {
|
||||
"health": health,
|
||||
"version": version,
|
||||
"config-path": config_path,
|
||||
"init-db": init_db,
|
||||
"scan-expiring-contracts": scan_expiring_contracts,
|
||||
"generate-renewal-task": generate_renewal_task,
|
||||
"dispatch-task-notice": dispatch_task_notice,
|
||||
"mark-contract-renewed": mark_contract_renewed,
|
||||
"render-html": render_html,
|
||||
}
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
argv = argv or sys.argv[1:]
|
||||
if not argv or argv[0] not in COMMANDS:
|
||||
print("Usage: python scripts/main.py <command>")
|
||||
print("Commands:", ", ".join(COMMANDS.keys()))
|
||||
return 1
|
||||
return COMMANDS[argv[0]](*argv[1:])
|
||||
_apply_host_runtime()
|
||||
|
||||
from cli.app import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
raise SystemExit(main())
|
||||
|
||||
Reference in New Issue
Block a user