Files
Orbitin/AGENTS.md

134 lines
4.2 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.

# AI助手开发文档
本项目 OrbitIn 是一个码头作业日志管理工具,用于从 Confluence API 获取交接班日志、提取作业数据并生成统计报表。
## 项目概述
- **主要功能**: 从 Confluence API 获取 HTML 并提取保留布局的文本
- **输出**: 文本文件、数据库记录、日报表
- **语言**: Python 3.7+
- **依赖**: requests, beautifulsoup4, python-dotenv
## 项目结构
```
OrbitIn/
├── main.py # CLI 入口
├── .env # 环境配置(敏感信息)
├── .env.example # 环境配置示例
├── README.md # 项目说明
├── AGENTS.md # AI助手文档
├── layout_output.txt # 缓存的布局文本
├── debug/ # 调试输出目录
│ └── layout_output_*.txt # 带时间戳的调试文件
├── data/ # 数据目录
│ └── daily_logs.db # SQLite3 数据库
└── src/ # 代码模块
├── __init__.py
├── confluence.py # Confluence API 客户端
├── extractor.py # HTML 文本提取器
├── parser.py # 日志解析器
├── database.py # SQLite3 数据库操作
├── report.py # 日报生成器
└── gui.py # GUI 图形界面
```
## 核心模块
### ConfluenceClient (src/confluence.py:9)
- `fetch_content(content_id, expand)` - 获取页面内容
- `get_html(content_id)` - 获取 HTML 字符串
### HTMLTextExtractor (src/extractor.py:12)
- `extract(html)` - 从 HTML 提取保留布局的文本
- 使用 `html.parser`(非 lxml
- 移除带 `ac:name` 属性的 Confluence 宏元素
- 表格格式化使用 `ljust()` 列对齐
### HandoverLogParser (src/parser.py:18)
- `parse(text)` - 解析日志文本,返回 `ShipLog` 列表
- 自动合并同日期同班次同船名的记录(二次靠泊)
- `ShipLog` 数据类date, shift, ship_name, teu, efficiency, vehicles
### DailyLogsDatabase (src/database.py:13)
- `insert(log)` - 插入单条记录(存在则跳过)
- `insert_many(logs)` - 批量插入
- `query_by_date(date)` - 按日期查询
- `query_by_ship(ship_name)` - 按船名查询
- `query_all(limit)` - 查询所有
- `get_stats()` - 获取统计信息
- `get_ships_with_monthly_teu(year_month)` - 获取当月每艘船的作业量
- `insert_unaccounted(year_month, teu, note)` - 添加未统计数据
- `get_unaccounted(year_month)` - 获取未统计数据
### DailyReportGenerator (src/report.py:15)
- `generate_report(date)` - 生成日报
- `print_report(date)` - 打印日报
### OrbitInGUI (src/gui.py:22)
- tkinter 图形界面
- 支持获取数据、生成日报、添加未统计数据
- 日报内容可复制
## 文本格式约定
- 列表前缀:`•` 用于 `ul`,数字+点用于 `ol`
- 粗体使用 `**text**`,斜体使用 `*text*`
- 水平线使用 `─` (U+2500) 字符
- 链接渲染为 `text (url)`
## 命令
```bash
# 默认:获取、提取、解析并保存到数据库
python3 main.py
# 仅获取HTML并提取文本保存到debug目录
python3 main.py fetch
# 获取并保存带时间戳的debug文件
python3 main.py fetch-debug
# 生成日报
python3 main.py report 2025-12-28
# 生成昨日日报
python3 main.py report-today
# 解析测试
python3 main.py parse-test
# 添加未统计数据
python3 main.py --unaccounted 118 --month 2025-12
# GUI界面
python3 src/gui.py
```
## 配置
`.env` 文件中配置 Confluence 连接信息:
```bash
CONFLUENCE_BASE_URL=https://confluence.westwell-lab.com/rest/api
CONFLUENCE_TOKEN=your-api-token
CONFLUENCE_CONTENT_ID=155764524
```
## 测试模式
如果设置了环境变量 `DEBUG_MODE=true`,系统会使用本地 `layout_output.txt` 文件而不是从 Confluence API 获取数据,方便离线测试。
## 注意事项
1. 二次靠泊记录会在解析时自动合并
2. 重复获取数据不会累加TEU会跳过已存在的记录
3. 未统计数据在报表中不显示,但会计算到当月实际作业量
4. 昨日日报按钮默认获取前一天的数据(因为通常在第二天汇报)