refactor: 完成项目目录重构与代码迁移
本次提交完成了整体项目的目录梳理与代码迁移: 1. 将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构 2. 移动并整理了插件目录结构,将插件统一放入根级plugins/ 3. 调整了前端项目的路径与配置,统一前后端开发构建流程 4. 清理了废弃的旧版app/目录与冗余的构建中间文件 5. 更新了.gitignore与README.md,适配新的项目结构
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""考勤月报封存检查 - webhost 场景插件(XQ0011)
|
||||
|
||||
流程:填写检查月份与正休规则 → 一键执行(拉取数据 + 运行五项检查 + 自动导出多 Sheet Excel)。
|
||||
复用 desktop/shared 数据真源(由宿主共享登录态注入 session/user_id),不内置登录逻辑。
|
||||
"""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, RunContext, ScenePlugin
|
||||
|
||||
from webhost.backend.plugins.seal_check import config
|
||||
from webhost.backend.plugins.seal_check.data import (
|
||||
fetch_compare_diffs, fetch_org_name_map, fetch_roster_data,
|
||||
fetch_seal_rows, fetch_shift_batch,
|
||||
)
|
||||
from webhost.backend.plugins.seal_check.logic import LeaveRuleEngine, run_all_checks
|
||||
from webhost.backend.plugins.seal_check.report import CHECK_TAB_TITLES, export_report
|
||||
|
||||
|
||||
def _default_month() -> str:
|
||||
last_end = datetime.now().replace(day=1) - timedelta(days=1)
|
||||
return f"{last_end.year:04d}-{last_end.month:02d}"
|
||||
|
||||
|
||||
class SealCheckPlugin(ScenePlugin):
|
||||
id = "seal_check"
|
||||
name = "考勤月报封存检查"
|
||||
version = "1.0.0"
|
||||
description = "填写每月正休规则,一键执行五项检查并导出多 Sheet Excel 报告"
|
||||
platform = "hr"
|
||||
uses_month = True # 月份由底座页眉统一提供(注入 ref_month),插件自身不再单列
|
||||
fields = [
|
||||
{"key": "fixed_rest_days", "label": "固休应休天数", "type": "int",
|
||||
"default": config.DEFAULT_RULES["fixed_rest_days"]},
|
||||
{"key": "size_rest_days", "label": "大小休应休天数", "type": "int",
|
||||
"default": config.DEFAULT_RULES["size_rest_days"]},
|
||||
{"key": "quota_rest_days", "label": "限额排休上限", "type": "int",
|
||||
"default": config.DEFAULT_RULES["quota_rest_days"]},
|
||||
]
|
||||
|
||||
def run(self, fields: dict, ctx: RunContext) -> dict:
|
||||
month_str = str(fields.get("ref_month") or _default_month()).strip()
|
||||
year, month = int(month_str[:4]), int(month_str[5:7].strip())
|
||||
yearmonth = f"{year:04d}{month:02d}"
|
||||
month_display = f"{year:04d}-{month:02d}"
|
||||
|
||||
engine = LeaveRuleEngine(
|
||||
size_rest_days=int(fields.get("size_rest_days") or config.DEFAULT_RULES["size_rest_days"]),
|
||||
fixed_rest_days=int(fields.get("fixed_rest_days") or config.DEFAULT_RULES["fixed_rest_days"]),
|
||||
quota_rest_days=int(fields.get("quota_rest_days") or config.DEFAULT_RULES["quota_rest_days"]),
|
||||
)
|
||||
|
||||
session = ctx.get_session("hr")
|
||||
user_id = ctx.get_user_id("hr")
|
||||
|
||||
ctx.log(f"开始考勤月报封存检查:{month_display}")
|
||||
ctx.progress(5)
|
||||
|
||||
ctx.log("拉取考勤封存数据……")
|
||||
seal_rows = fetch_seal_rows(session, user_id, yearmonth)
|
||||
ctx.progress(30)
|
||||
ctx.log(f"封存数据 {len(seal_rows)} 人")
|
||||
|
||||
ctx.log("拉取组织表……")
|
||||
org_name_map = fetch_org_name_map(session)
|
||||
ctx.progress(45)
|
||||
ctx.log(f"组织 {len(org_name_map)} 条")
|
||||
|
||||
ctx.log("导出花名册(获取职位序列)……")
|
||||
seq_map, in_service_records = fetch_roster_data(session)
|
||||
ctx.progress(60)
|
||||
ctx.log(f"花名册职位序列 {len(seq_map)} 人,在职 {len(in_service_records)} 人")
|
||||
|
||||
ctx.log("批量拉取排班(计算应出勤天数)……")
|
||||
shift_map = fetch_shift_batch(session, user_id, yearmonth)
|
||||
ctx.progress(80)
|
||||
ctx.log(f"排班应出勤 {len(shift_map)} 人")
|
||||
|
||||
diff_rows, diff_note = fetch_compare_diffs(session, user_id, yearmonth)
|
||||
ctx.progress(90)
|
||||
|
||||
notes = [diff_note] if diff_note else []
|
||||
ctx.log("运行全部检查……")
|
||||
result = run_all_checks(
|
||||
seal_rows=seal_rows,
|
||||
org_name_map=org_name_map,
|
||||
seq_map=seq_map,
|
||||
in_service_records=in_service_records,
|
||||
shift_map=shift_map,
|
||||
engine=engine,
|
||||
year=year, month=month,
|
||||
diff_rows=diff_rows, diff_fields=None, notes=notes,
|
||||
)
|
||||
ctx.progress(95)
|
||||
|
||||
path = export_report(result["rows"], month_display, result["notes"])
|
||||
ctx.progress(100)
|
||||
|
||||
for note in result["notes"]:
|
||||
ctx.log(f"[提示] {note}")
|
||||
summary = ";".join(
|
||||
f"{CHECK_TAB_TITLES[i]} {len(result['rows'].get(i, []))} 条"
|
||||
for i in range(1, 6))
|
||||
ctx.log(f"结果汇总:{summary}")
|
||||
ctx.log(f"===== 检查完成,报告已导出:{path} =====")
|
||||
|
||||
return {
|
||||
"summary": summary,
|
||||
"path": path,
|
||||
"rows": {str(k): v for k, v in result["rows"].items()},
|
||||
"notes": result["notes"],
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(SealCheckPlugin())
|
||||
Reference in New Issue
Block a user