Search-Goods/README.md

38 lines
1.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.

# 商品查询系统
## 功能
- 导入Excel为数据库以条码为主键Upsert
- 查询商品:条码精确查、名称模糊查
- 响应式前端,手机/电脑可用
## 运行
1. 安装依赖:`python -m pip install fastapi "uvicorn[standard]" pandas openpyxl python-multipart`
2. 启动服务:`python -m uvicorn app.main:app --host 0.0.0.0 --port 57777`(或设置环境变量 `PORT=57777`
3. 打开页面:`http://localhost:57777/`
## 导入
- 页面“导入Excel”选择文件并提交
- 后端解析`Sheet1`并映射列:`名称(必填)`、`进货价(必填)`、`销售价(必填)`、`条码`、可选`分类(必填)`
## 接口
- `POST /import` 表单上传`file`
- `GET /products/{barcode}` 返回名称、进价、卖价、条码
- `GET /products?q=关键词&limit=20` 名称模糊查询
- `GET /health` 健康检查
## 数据库
- SQLite 文件:`data/products.db`
- 表:`products(barcode primary key, name, purchase_price, sale_price, category, created_at, source_file)`
- 索引:`idx_products_name(name)`
## 注意
- Excel中文列名需一致
- 非数字价格会被跳过或置为空
- 条码为空的行跳过
## Docker推荐部署
- 构建并启动:`docker compose up --build -d`
- 端口:宿主机映射 `57777:57777`
- 数据与静态资源挂载:
- `./data:/app/data`SQLite 持久化)
- `./static:/app/static:ro`(前端文件,无需重建镜像即可更新)