diff --git a/requirements.txt b/requirements.txt index df03e9f..5d7dd8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,25 +1,10 @@ -# Python Flask 日报系统依赖 - -# Web框架 Flask==3.0.0 Flask-CORS==4.0.0 - -# 数据库连接 PyMySQL==1.1.0 cryptography==41.0.7 - -# Excel处理 openpyxl==3.1.2 - -# 定时任务 APScheduler==3.10.4 - -# 工具库 python-dateutil==2.8.2 pytz==2023.3 - -# 生产服务器(Windows推荐) waitress==3.0.0 - -# 开发工具(可选) -python-dotenv==1.0.0 \ No newline at end of file +python-dotenv==1.0.0 diff --git a/启动.bat b/启动.bat index 8bf96a5..f24a288 100644 --- a/启动.bat +++ b/启动.bat @@ -4,6 +4,10 @@ title 订单日报系统 - 生产模式 cd /d "%~dp0" +REM 设置 Python 使用 UTF-8 编码,避免中文环境下读取文件乱码 +set PYTHONUTF8=1 +set PIP_DEFAULT_ENCODING=utf-8 + echo ======================================== echo 订单日报系统 - 生产模式启动 echo ======================================== diff --git a/部署文档.md b/部署文档.md new file mode 100644 index 0000000..2c0852c --- /dev/null +++ b/部署文档.md @@ -0,0 +1,239 @@ +# 订单日报系统 - 部署文档 + +## 项目简介 + +订单日报系统是一个基于 Flask 的 Web 应用,用于自动生成充电订单的日报报表。 + +## 技术栈 + +- **后端**: Python 3.10+ + Flask 3.0 + Waitress +- **数据库**: Apache Doris (MySQL 兼容) +- **前端**: 原生 HTML/CSS/JavaScript + +--- + +## 一、环境准备 + +### 1. 安装 Python + +- 下载地址:https://www.python.org/downloads/ +- 版本要求:Python 3.10 及以上 +- **重要:安装时勾选 "Add Python to PATH + +### 2. 拉取代码 + +```bash +# 从国内仓库拉取(推荐,速度快) +git clone http://www.yelite.cn:27825/huhao/ylt_diy.git + +# 或从 GitHub 拉取 +git clone https://github.com/huhaoslm-boop/ylt_diy.git + +cd ylt_diy +``` + +### 3. 配置正式环境 + +复制正式环境配置文件: + +```bash +copy .env.prod .env +``` + +根据实际情况修改 `.env` 文件中的配置: + +```env +# 服务监听地址 +DEPLOY_RUN_HOST=0.0.0.0 + +# 服务监听端口 +DEPLOY_RUN_PORT=5002 + +# 数据库配置 +DB_HOST=192.168.10.250 +DB_PORT=9030 +DB_USER=root +DB_PASSWORD=DsideaL147258369 +DB_NAME=yltcharge + +# 日志级别(DEBUG/INFO/WARNING/ERROR) +LOG_LEVEL=INFO +``` + +--- + +## 二、启动服务 + +### 方式一:直接启动(测试用) + +双击 `启动.bat`,或命令行执行: + +```bat +启动.bat +``` + +脚本会自动完成: +1. 读取 `.env` 配置 +2. 检查 Python 环境 +3. 创建虚拟环境(`.venv`) +4. 安装依赖 +5. 启动服务 + +启动成功后访问:http://localhost:5002 + +### 方式二:注册为 Windows 服务(推荐生产环境) + +使用 NSSM 工具将应用注册为 Windows 服务,实现开机自动启动。 + +#### 1. 下载 NSSM + +- 下载地址:https://nssm.cc/download +- 解压后把 `nssm.exe` 放到项目根目录 + +#### 2. 安装服务 + +双击 `服务管理.bat`,选择: + +``` +1 - 安装服务 +2 - 启动服务 +``` + +服务名称:`YltDailyReport` + +#### 3. 其他操作 + +``` +3 - 停止服务 +4 - 重启服务 +5 - 删除服务 +0 - 退出 +``` + +--- + +## 三、默认账号 + +``` +用户名:admin +密 码:123586 +``` + +登录后可在右上角点击"修改密码"修改默认密码。 + +--- + +## 四、代码更新 + +### 更新步骤 + +```bash +# 进入项目目录 +cd ylt_diy + +# 拉取最新代码 +git pull + +# 重启服务 +# (如果是服务模式:服务管理.bat → 4 重启服务 +# 如果是直接启动:关闭窗口重新打开启动.bat +``` + +--- + +## 五、双仓库配置说明 + +### 当前配置 + +| 操作 | 仓库地址 | +|------|--------| +| 拉取(fetch) | https://github.com/huhaoslm-boop/ylt_diy.git | +| 推送(push) | 同时推送到 GitHub 和 yelite.cn | + +### 查看当前配置 + +```bash +git remote -v +``` + +### 配置双仓库推送(已配置好的可跳过) + +```bash +# 设置两个 push 地址 +git remote set-url --push origin https://github.com/huhaoslm-boop/ylt_diy.git +git remote set-url --add --push origin http://www.yelite.cn:27825/huhao/ylt_diy.git +``` + +### 修改默认拉取源(可选:改为从国内仓库拉取 + +```bash +# 修改 fetch 地址为 yelite.cn +git remote set-url origin http://www.yelite.cn:27825/huhao/ylt_diy.git + +# 再加回两个 push 地址 +git remote set-url --add --push origin https://github.com/huhaoslm-boop/ylt_diy.git +git remote set-url --add --push origin http://www.yelite.cn:27825/huhao/ylt_diy.git +``` + +--- + +## 六、常见问题 + +### 1. 端口被占用 + +修改 `.env` 文件中的 `DEPLOY_RUN_PORT` 为其他端口。 + +### 2. 数据库连接失败 + +检查 `.env` 中的数据库配置是否正确。 + +### 3. 报表生成失败 + +查看日志文件:`logs/app.log` + +### 4. 忘记管理员密码 + +在数据库中执行: + +```sql +-- 重置密码为 123586 +UPDATE t_daily_report_admin +SET password = MD5('123586'), token = NULL, token_expire = NULL +WHERE username = 'admin'; +``` + +### 5. 服务无法启动 + +以命令行手动运行查看错误: + +```bash +.venv\Scripts\python.exe run_prod.py +``` + +--- + +## 七、项目结构 + +``` +ylt_diy/ +├── app.py # Flask 主应用 +├── run_prod.py # 生产环境启动入口 +├── 启动.bat # 一键启动脚本 +├── 服务管理.bat # Windows服务管理脚本 +├── .env.prod # 正式环境配置模板 +├── requirements.txt # Python依赖 +├── lib/ +│ ├── db.py # 数据库配置 +│ ├── db_init.py # 数据库初始化 +│ ├── logger.py # 日志模块 +│ ├── report_generator.py # 日报生成核心逻辑 +│ ├── sum_data_collector.py # 求和数据采集 +│ ├── field_mapping.py # 字段映射 +│ └── api/ # API 模块 +├── templates/ +│ └── index.html # 主页面 +├── public/ +│ ├── static/ # 静态资源 +│ └── reports/ # 生成的报表 +└── logs/ # 日志文件 +```