Files
ppgo_job/CLAUDE.md
T
lmk 610b85e3a5 refactor: 从 Beego 迁移到 GoFrame v2
- 替换 Beego 框架为 GoFrame v2
- 重构项目结构: controller/service/dao/middleware 分层
- 替换自定义 crons 包为 gcron
- 模板从 views/ 迁移到 resource/template/
- 配置从 conf/app.conf 迁移到 config.yml
- 数据库从 MySQL 切换为 SQLite (modernc.org/sqlite)
- 移除 agent/ 远程执行器(待后续迁移)
- 移除 crons/ 自定义定时器包
- 静态资源整理到 resource/static/
2026-07-09 11:06:12 +08:00

101 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project
PPGo_Job — 定时任务管理系统,GoFrame v2 重构版。
**框架:** GoFrame v2(原版基于 Beego v1
**数据库:** SQLite(纯 Go 驱动 `modernc.org/sqlite`,无需 CGO
**定时任务:** GoFrame `gcron`(原版自定义 crons/ 包)
## Build & Run
```bash
# 编译(纯 Go,不需要 gcc/MinGW
CGO_ENABLED=0 go build -o ppgo_job.exe .
# 运行
./ppgo_job.exe
# 访问 http://localhost:8082
# 默认账号 admin / 123456
```
## Architecture
```
main.go # GoFrame 启动入口
config.yml # YAML 配置
boot/ # 启动初始化
db.go # 数据库初始化
router.go # 路由注册
tplfunc.go # 自定义模板函数(urlfor/date/substr 等)
init.go # 启动后初始化(加载任务到调度器)
controller/ # HTTP 层
base.go # display/ajaxMsg/ajaxList/parseFilters 辅助函数
login.go # 登录/登出
home.go # 首页/仪表盘/帮助
task.go # 任务 CRUD + 服务器/分组/日志/权限管理
service/ # 业务逻辑
scheduler/ # gcron 调度 + 任务执行引擎
dao/ # 数据访问层
model/entity/ # 数据库实体(含 Cols 字段常量)
middleware/ # 认证中间件(Cookie + RBAC 权限)
consts/ # 常量、表名定义
resource/
template/ # LayUI 模板(从原 views/ 迁移)
static/ # 静态资源(layui/css/js
sql/schema.sql # 建表 DDL + 初始数据
_old/ # 原 Beego 旧代码(参考用)
agent/ # 远程执行器(独立二进制,后续迁移)
```
## Layer Rules
- **controller**:参数解析 → 调用 Service/DAO → 渲染模板或返回 JSON。不含业务逻辑。
- **service**:业务逻辑。不含 HTTP 概念。
- **dao**:数据访问。纯 CRUD。
- **middleware**:认证、权限检查。
## Key Packages
| Package | Purpose |
|---|---|
| `controller` | All HTTP handlers (flat package, organized by file) |
| `dao` | Database CRUD operations, singleton pattern (`var Xxx = new(xxxDao)`) |
| `model/entity` | DB structs with `orm` tags and Cols constants |
| `service/scheduler` | Cron job scheduling + task execution engine |
| `middleware` | Cookie auth + RBAC permission checking |
| `consts` | Table names, status constants, message codes |
## Template Convention
LayUI 模板使用 `{{include "MainContent" .}}` 布局模式(layout.html 中定义)。
- `display(r, "page.html", data)` — 渲染带布局的页面
- `displayTpl(r, "page.html", data)` — 直接渲染模板
- `ajaxMsg(r, msg, code)` — JSON 消息响应
- `ajaxList(r, msg, code, count, data)` — LayUI table JSON 格式
## Database
SQLite 建表脚本:`sql/schema.sql`
首次启动自动创建 `./data/ppgo_job.db`
## Migration Status
| Phase | Status |
|-------|--------|
| 1 项目骨架 | ✅ |
| 2 数据访问层 | ✅ |
| 3 路由+控制器框架 | ✅ |
| 4 认证系统 | ✅ |
| 5 模板渲染 | ✅ |
| 6 任务调度器 | ✅ |
| 7 服务层 | ✅ |
| 8 清理 | ✅ |
待办:SSH/Telnet/Agent 远程执行器(参考 `_old/jobs/job.go`)、通知渠道(参考 `_old/notify/`