feat(plugin): XQ0036 0.1.1 配置收敛为工作目录、星级按工号实时查询
- 配置由 save_dir / standard_path / roster_path 收敛为 work_dir:线下标准表在 该目录内按文件名关键词(起调薪薪资标准/薪资标准)与日期自动取最新, 处理结果 xlsx 同目录输出 - 星级改为按待办工号实时查询,失败再回退全量花名册导出 - 处理窗口留空=全部待办(原先默认当前自然月);界面、规则说明、README 同步
This commit is contained in:
@@ -78,13 +78,49 @@ def _star_bonus(star: str, note: str = "") -> Optional[float]:
|
||||
return None
|
||||
|
||||
|
||||
_DATE_RE = re.compile(r"(20\d{6})")
|
||||
|
||||
|
||||
def find_latest_file(dir_path: str, log=None) -> str:
|
||||
"""在工作目录内按关键词挑最新标准表:文件名日期优先,无日期时按修改时间。"""
|
||||
try:
|
||||
names = os.listdir(dir_path)
|
||||
except OSError:
|
||||
return ""
|
||||
candidates = []
|
||||
for name in names:
|
||||
if name.startswith("~$") or not name.lower().endswith((".xlsx", ".xls")):
|
||||
continue
|
||||
if not any(keyword in name for keyword in config.STANDARD_FILE_KEYWORDS):
|
||||
continue
|
||||
full = os.path.join(dir_path, name)
|
||||
if not os.path.isfile(full):
|
||||
continue
|
||||
m = _DATE_RE.search(name)
|
||||
candidates.append((m.group(1) if m else "", os.path.getmtime(full), full))
|
||||
if not candidates:
|
||||
return ""
|
||||
dated = [c for c in candidates if c[0]]
|
||||
best = max(dated or candidates, key=lambda c: (c[0], c[1]))
|
||||
if log:
|
||||
log(f"[INFO] 标准表目录自动选取:{os.path.basename(best[2])}")
|
||||
return best[2]
|
||||
|
||||
|
||||
def load(path: str, log=None) -> List[dict]:
|
||||
"""读取标准表;返回带解析结果的行列表。
|
||||
"""读取标准表;path 为目录时按关键词+最新日期取一个文件。
|
||||
|
||||
表不存在、工作表被改名、列数不足或文件损坏时返回空列表(按「未载入标准表」处理,
|
||||
由调用方逐条记为待人工核对),不抛异常中断整批处理。
|
||||
"""
|
||||
path = config.text(path)
|
||||
if path and os.path.isdir(path):
|
||||
path = find_latest_file(path, log)
|
||||
if not path:
|
||||
if log:
|
||||
log(f"[WARN] 标准表目录内未找到含关键词「{config.STANDARD_FILE_KEYWORDS[0]}」的 xlsx;"
|
||||
f"服务/管理账套固定项总额按待人工核对处理", "WARNING")
|
||||
return []
|
||||
if not path or not os.path.exists(path):
|
||||
return []
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user