logo
0
1
WeChat Login

工作日志自动填报工具 (alog)

基于 Node.js/TypeScript 开发的自动化填报工作日志工具,扫描本地 Git 仓库获取提交记录,自动整理后提交到 OA 系统。

功能特性

  • 自动扫描指定目录下的所有 Git 仓库
  • 按时间段(上午/下午/晚间)自动分组提交记录
  • 单提交自动填充整天(上午3h + 下午5h)
  • 避开法定节假日,智能提示
  • 支持补填历史日期日志
  • 支持定时自动填报
  • Cookie 持久化,无需重复登录

安装

cd alog npm install npm run build

Windows 用户注意

在 Windows PowerShell 中执行脚本前,需要设置执行策略:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

此设置仅对当前用户生效,允许执行本地脚本和远程签名的脚本。

配置文件说明

config.json

{ "oa": { "baseUrl": "https://npms.newcapec.cn", }, "git": { "scanDir": "~/work", "excludeDirs": ["node_modules", ".git", "dist", "build", "vendor"], "excludeRepos": [], "repos": [], "includeScanDir": false }, "log": { "morningCutoff": "12:00", "afternoonCutoff": "18:30", "defaultMorningHours": 3, "defaultAfternoonHours": 5, "maxNightHours": 8 }, "task": { "defaultObjectType": "task_你的默认任务", "location": "company" }, "schedule": { "enabled": false, "cron": "0 20 * * 1-5" } }

git 配置说明

Git 扫描配置支持多种模式,可根据实际需求灵活配置:

字段类型说明
scanDirstring | string[]扫描目录,支持单个路径或路径数组,递归扫描这些目录下的所有 Git 仓库
excludeDirsstring[]递归扫描时要排除的目录名(如 node_modules)
excludeReposstring[]要排除的仓库,支持路径或仓库名称匹配
reposRepoConfig[]精确指定的仓库列表,不进行递归扫描
includeScanDirboolean当配置了 repos 时,是否同时扫描 scanDir(默认 false)

配置示例:

方式一:递归扫描单个目录

{ "git": { "scanDir": "~/work", "excludeDirs": ["node_modules", ".git", "dist", "build", "vendor"] } }

方式二:递归扫描多个目录

{ "git": { "scanDir": ["~/work", "~/projects", "~/opensource"], "excludeDirs": ["node_modules", ".git", "dist", "build"] } }

方式三:精确指定仓库(推荐)

适用于仓库分散在不同位置,或需要精确控制扫描哪些仓库:

{ "git": { "repos": [ { "path": "~/work/project-a" }, { "path": "~/projects/project-b", "name": "项目B" }, { "path": "/Users/xxx/opensource/lib-xyz" } ] } }

方式四:混合模式

精确指定仓库,同时扫描其他目录:

{ "git": { "scanDir": "~/work", "repos": [ { "path": "~/projects/important-project" } ], "includeScanDir": true } }

方式五:排除不需要的仓库

{ "git": { "scanDir": "~/work", "excludeRepos": ["test-repo", "archive", "/Users/xxx/work/old-project"] } }

credentials.json

{ "mobile": "", "zentaosid": "" }
  • zentaosid: 登录 OA 后从浏览器 Cookie 中获取

使用方法

1. 配置 Cookie

首次使用需要配置登录 Cookie:

  1. 在浏览器中登录 OA 系统 (https://npms.newcapec.cn)
  2. 打开开发者工具 (F12) -> Application/Storage -> Cookies
  3. 复制 zentaosid 的值
  4. 编辑 credentials.json,填入 Cookie 值
  5. 日志填报页面任务列表中找到默认任务的值,填入config.json中的task.defaultObjectType

2. 今日填报

扫描今日提交并自动填报:

# 方式一(推荐) alog today # 方式二 alog scan

预览模式(不提交):

alog today --preview

3. 补填历史日志

交互式选择日期补填:

alog fill

指定日期补填:

alog fill -d 2026-03-11

预览模式:

alog fill -d 2026-03-11 --preview

自动模式(处理所有有提交的日期):

alog fill --auto

指定日期范围补填:

alog fill --start-date 2026-03-01 --end-date 2026-03-10

日期范围参数说明:

参数说明示例
--start-date日期范围开始--start-date 2026-03-01
--end-date日期范围结束--end-date 2026-03-10

4. 定时任务

查看定时任务配置:

alog schedule --info

注意:内置定时任务需要保持进程运行。更推荐使用系统 crontab(见下文)。

5. 状态检查

alog status

定时任务配置(推荐)

推荐使用系统 crontab (Linux/macOS) 或 Task Scheduler (Windows) 配置定时任务,无需保持进程运行:

添加定时任务

# 编辑 crontab crontab -e # 添加以下行(每天晚上8点执行) # Linux/macOS 使用 nvm/node 路径,Windows 使用 Task Scheduler 0 20 * * 1-5 /path/to/your/alog/node_modules/.bin/node /path/to/your/alog/dist/index.js today >> /path/to/your/alog/alog.log 2>&1

Cron 表达式说明

表达式含义
0 20 * * 1-5每周一到周五晚上20:00
0 18 * * 1-5每周一到周五晚上18:00
0 9 * * 1-5每周一到周五早上9:00

查看定时任务

crontab -l

删除定时任务

crontab -r

日志整理规则

时间段划分

时段时间范围默认耗时
上午 (am)00:00 - 12:003 小时
下午 (pm)12:00 - 18:305 小时
晚间 (nt)18:30 - 24:00动态计算

单提交填充规则

如果当天只有 1 条提交记录,将自动填充整天:

  • 上午:3 小时
  • 下午:5 小时

多提交分组规则

  • 12:00 前的提交 → 上午
  • 12:00-18:30 的提交 → 下午
  • 18:30 后的提交 → 晚间

验证规则

  • 上午 + 下午 = 8 小时
  • 上午耗时:3-4 小时
  • 下午耗时:4-5 小时
  • 晚间耗时 ≤ 8 小时

节假日配置

节假日配置存储在 holidays.json 文件中,格式如下:

{ "2026": [ "2026-01-01", "2026-01-26", ... ] }

补填日志时:

  • 自动跳过法定节假日
  • 周末不显示在选项中
  • 无提交的工作日会提示是否用后续提交填充

常见问题

Q: Cookie 过期了怎么办?

A: 重新登录 OA 系统,获取新的 zentaosid 值,更新到 credentials.json

Q: 如何修改扫描的仓库目录?

A: 编辑 config.json 中的 git.scanDir 字段,支持以下方式:

  1. 递归扫描目录:设置 scanDir 为目录路径
  2. 精确指定仓库:在 repos 数组中添加仓库路径
  3. 排除不需要的仓库:在 excludeRepos 中添加要排除的仓库名称或路径

详见上方 git 配置说明 章节。

Q: 提交失败怎么办?

A: 1. 检查 Cookie 是否有效;2. 检查当天是否已填报;3. 使用 --preview 查看提交内容是否正确。

命令列表

命令说明
scan扫描并填报今日日志
fill补填历史日期日志
set-password设置登录密码
schedule定时任务管理
status查看登录状态

项目结构

alog/ ├── src/ │ ├── index.ts # CLI 入口 │ ├── git-scanner.ts # Git 提交扫描 │ ├── log-builder.ts # 日志整理 │ ├── oa-auth.ts # OA 登录 │ ├── oa-api.ts # OA API 交互 │ ├── config.ts # 配置管理 │ ├── holiday-checker.ts # 节假日检查 │ └── types.ts # 类型定义 ├── config.json # 配置文件 ├── credentials.json # 登录凭据 ├── holidays.json # 节假日配置 ├── package.json └── tsconfig.json

About

No description, topics, or website provided.
Language
TypeScript72.5%
JavaScript27.5%