Files
ylt_diy/README.md
user9994793890 4750698f43 chore: 清理旧版本文件,只保留Python Flask版本
删除的文件:
- Node.js相关文件:.babelrc, .coze, .next, .npmrc, node_modules, src/, scripts/, components.json, eslint.config.mjs, next-env.d.ts, next.config.ts, package.json, pnpm-lock.yaml, postcss.config.mjs, tsconfig.json, tsconfig.tsbuildinfo
- 旧文档:AGENTS.md, WINDOWS_GUIDE.md
- 测试文件:check_*.py, fix_database.py, force_rebuild.py, test_*.py
- 诊断文档:修复下载问题.md, 如何找到生成的日报.md, 最终诊断指南.md, 查看调试日志.md, 诊断指南.md, 问题已定位.md
- 截图文件:assets/image*.png

保留的文件:
- app.py - Flask主应用
- lib/ - Python业务逻辑模块
- templates/ - HTML模板
- public/reports/ - Excel文件存储
- requirements.txt - Python依赖
- README.md - 更新为Python版本说明
- assets/t_equipment_charge_order.sql - 数据库表结构

现在项目结构清晰,只包含Python Flask版本的核心文件。

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
2026-07-09 14:53:19 +08:00

197 lines
4.9 KiB
Markdown
Raw Permalink 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.

# 订单日报系统 - Python Flask版本
一个基于Python Flask的订单日报自动生成系统用于公交等企业的订单报表自动生成。
## 功能特性
-**定时生成**每天早上8:01自动生成前一天的日报
-**配置管理**:支持创建、编辑、删除、启用/禁用、排序
-**日报生成**:按配置+时间范围生成
-**自定义字段**100+字段可选,中文显示
-**求和功能**:支持多字段求和
-**按企业/用户拆分**:灵活选择拆分方式
-**预设时间**昨天、最近3天、最近7天
-**自定义时间**:任意时间范围
-**Excel导出**格式化Excel文件
-**历史记录**:查看、下载、批量下载
## 技术栈
- **后端**Python 3.8+ / Flask 3.0
- **数据库**MySQL / Apache DorisPyMySQL驱动
- **Excel**openpyxl
- **定时任务**APScheduler
- **前端**原生HTML + CSS + JavaScript
## 项目结构
```
.
├── app.py # Flask主应用
├── requirements.txt # Python依赖
├── lib/ # 业务逻辑
│ ├── __init__.py
│ ├── db.py # 数据库连接
│ ├── field_mapping.py # 字段映射
│ └── report_generator.py # 日报生成
├── templates/ # HTML模板
│ └── index.html # 主页面
├── public/reports/ # Excel文件存储
└── README.md # 本文件
```
## 快速开始
### 1. 安装Python依赖
```bash
pip install -r requirements.txt
```
### 2. 配置数据库
编辑 `lib/db.py`,修改数据库连接信息:
```python
DB_CONFIG = {
'host': 'haoslm2.xicp.net',
'port': 10216,
'user': 'root',
'password': 'DsideaL147258369',
'database': 'yltcharge',
'charset': 'utf8mb4',
'cursorclass': pymysql.cursors.DictCursor
}
```
### 3. 启动服务
```bash
python app.py
```
服务将在 `http://localhost:5000` 启动。
### 4. 初始化数据库
首次运行需要初始化数据库表:
访问http://localhost:5000/api/init-tables
或运行:
```bash
curl -X POST http://localhost:5000/api/init-tables
```
### 5. 使用系统
1. 打开浏览器访问http://localhost:5000
2. 切换到"配置管理"标签,创建配置
3. 切换到"日报生成"标签,生成日报
4. 切换到"历史记录"标签,查看和下载日报
## API接口
### 配置管理
- `GET /api/config` - 获取所有配置
- `POST /api/config` - 创建配置
- `PUT /api/config/<id>` - 更新配置
- `DELETE /api/config/<id>` - 删除配置
- `POST /api/config/<id>/toggle` - 启用/禁用配置
- `POST /api/config/reorder` - 重新排序
### 日报生成
- `POST /api/report/generate` - 生成日报
- `GET /api/report/history` - 获取历史记录
- `GET /api/download` - 下载Excel文件
### 数据库
- `POST /api/init-tables` - 初始化数据库表
## 数据库表结构
### t_daily_report_config配置表
- `id` - 配置ID
- `config_name` - 配置名称
- `split_type` - 拆分方式company_id/user_id
- `split_value` - 拆分值
- `split_name` - 拆分显示名称
- `selected_fields` - 选择的字段JSON
- `sum_fields` - 求和字段JSON
- `is_active` - 是否启用
- `sort_order` - 排序顺序
- `create_time` - 创建时间
- `update_time` - 更新时间
### t_daily_report_history历史表
- `id` - 记录ID
- `report_date` - 报表日期
- `start_time` - 开始时间
- `end_time` - 结束时间
- `split_type` - 拆分方式
- `split_value` - 拆分值
- `split_name` - 拆分显示名称
- `config_id` - 配置ID
- `config_name` - 配置名称
- `total_orders` - 订单总数
- `total_amount` - 总金额
- `sum_results` - 求和结果JSON
- `file_path` - 文件路径
- `status` - 状态0=失败1=成功)
- `error_msg` - 错误信息
- `create_time` - 创建时间
## 定时任务
系统内置定时任务每天8:01北京时间自动生成日报
- 为所有启用的配置生成日报
- 时间范围前一天8:00到当天8:00
- 生成的Excel文件保存在 `public/reports/` 目录
## Windows运行
### 启动服务
```cmd
python app.py
```
### 常见问题
#### 端口被占用
```cmd
# 查看占用5000端口的进程
netstat -ano | findstr :5000
# 结束进程
taskkill /PID <进程ID> /F
```
#### 依赖安装失败
```cmd
# 使用国内镜像
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
```
## Linux/Mac运行
### 启动服务
```bash
python3 app.py
```
### 后台运行
```bash
nohup python3 app.py > app.log 2>&1 &
```
## 注意事项
1. **数据库连接**:确保数据库地址、端口、用户名、密码正确
2. **字段映射**:使用实际数据库中的字段名,参考 `lib/field_mapping.py`
3. **文件权限**:确保 `public/reports/` 目录有写入权限
4. **定时任务**:保持服务持续运行,定时任务才会执行
## 许可证
MIT License