Files
Neo-ZQYY/packages/shared/README.md
Neo b25308c3f4 feat: P1-P3 全栈集成 — 数据库基础 + DWS 扩展 + 小程序鉴权 + 工程化体系
## P1 数据库基础
- zqyy_app: 创建 auth/biz schema、FDW 连接 etl_feiqiu
- etl_feiqiu: 创建 app schema RLS 视图、商品库存预警表
- 清理 assistant_abolish 残留数据

## P2 ETL/DWS 扩展
- 新增 DWS 助教订单贡献度表 (dws.assistant_order_contribution)
- 新增 assistant_order_contribution_task 任务及 RLS 视图
- member_consumption 增加充值字段、assistant_daily 增加处罚字段
- 更新 ODS/DWD/DWS 任务文档及业务规则文档
- 更新 consistency_checker、flow_runner、task_registry 等核心模块

## P3 小程序鉴权系统
- 新增 xcx_auth 路由/schema(微信登录 + JWT)
- 新增 wechat/role/matching/application 服务层
- zqyy_app 鉴权表迁移 + 角色权限种子数据
- auth/dependencies.py 支持小程序 JWT 鉴权

## 文档与审计
- 新增 DOCUMENTATION-MAP 文档导航
- 新增 7 份 BD_Manual 数据库变更文档
- 更新 DDL 基线快照(etl_feiqiu 6 schema + zqyy_app auth)
- 新增全栈集成审计记录、部署检查清单更新
- 新增 BACKLOG 路线图、FDW→Core 迁移计划

## Kiro 工程化
- 新增 5 个 Spec(P1/P2/P3/全栈集成/核心业务)
- 新增审计自动化脚本(agent_on_stop/build_audit_context/compliance_prescan)
- 新增 6 个 Hook(合规检查/会话日志/提交审计等)
- 新增 doc-map steering 文件

## 运维与测试
- 新增 ops 脚本:迁移验证/API 健康检查/ETL 监控/集成报告
- 新增属性测试:test_dws_contribution / test_auth_system
- 清理过期 export 报告文件
- 更新 .gitignore 排除规则
2026-02-26 08:03:53 +08:00

88 lines
2.5 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.
# packages/shared — 跨项目共享包
`neozqyy-shared`NeoZQYY Monorepo 的共享工具包,提供业务枚举、金额精度处理和时间工具。
## 安装
作为 uv workspace 成员,其他模块通过 `pyproject.toml` 引用:
```toml
[project]
dependencies = ["neozqyy-shared"]
[tool.uv.sources]
neozqyy-shared = { workspace = true }
```
## 模块说明
### `enums.py` — 业务枚举
所有枚举继承 `(str, Enum)`,值为小写英文标识符,可直接与数据库字段和 API 响应比较。
| 枚举类 | 说明 | 值 |
|--------|------|-----|
| `PaymentStatus` | 支付状态 | pending / paid / refunded / partially_refunded / cancelled |
| `OrderStatus` | 订单状态 | pending / confirmed / in_progress / completed / cancelled / refunded |
| `MemberStatus` | 会员状态 | active / inactive / suspended / expired |
| `AssistantStatus` | 助教状态 | active / on_leave / resigned |
| `DataSource` | 数据源模式 | online / offline / hybrid |
| `TaskCategory` | ETL 任务分类 | ODS / DWD / DWS / Schema / Quality / Other |
用法:
```python
from neozqyy_shared.enums import PaymentStatus, OrderStatus
if row["status"] == PaymentStatus.PAID:
...
```
### `money.py` — 金额精度工具
业务约定:所有金额字段保留 2 位小数(分),与数据库 `numeric(*, 2)` 对齐。使用 `Decimal` + `ROUND_HALF_UP`
| 函数 | 说明 |
|------|------|
| `round_cny(amount: Decimal) -> Decimal` | 人民币金额四舍五入到分 |
| `to_cny(value) -> Decimal` | 将任意数值int/float/str/Decimal转为 CNY 精度 |
用法:
```python
from neozqyy_shared.money import to_cny, round_cny
from decimal import Decimal
price = to_cny(99.999) # Decimal('100.00')
total = round_cny(Decimal("123.456")) # Decimal('123.46')
```
### `datetime_utils.py` — 时间工具
默认时区 `Asia/Shanghai`UTC+8与业务数据库 `timestamptz` 对齐。
| 函数 | 说明 |
|------|------|
| `now_shanghai() -> datetime` | 获取上海时区当前时间 |
| `date_range(start, end) -> list[date]` | 生成日期范围列表(含首尾) |
用法:
```python
from neozqyy_shared.datetime_utils import now_shanghai, date_range
from datetime import date
now = now_shanghai()
dates = date_range(date(2026, 1, 1), date(2026, 1, 7)) # 7 天
```
## 依赖
```
python-dateutil>=2.8.0
tzdata>=2023.0
```
## 使用方
- `apps/etl/connectors/feiqiu/` — ETL Connector
- `apps/backend/` — FastAPI 后端
- `apps/mcp-server/` — MCP Server