Commit Graph

10 Commits

Author SHA1 Message Date
Pine b9b5e2e2ff feat(task): 任务中心扫码接单(多端) —— 服务端任务状态机/端口/迁移
- Task 加 task_code/tags/display_priority/claimed_by/claimed_at/doing_at;新增 TaskClaim 流水表。
- TaskService 加 claimed/doing/completed 状态机(claim/start_doing/complete),grab 并入 claim。
- TaskRepository 加 list_published/get_by_code/update/claim/set_doing + TaskClaimRepository;挂 Database。
- 端口:
  · opc  /tasks/grab-by-code、/tasks/{id}/doing、/tasks/{id}/complete
  · operator POST /tasks(auto task_code) + PATCH /tasks/:id
  · park  /park/api/tasks(大屏展示,含 scan_payload 二维码载荷)
  · training /api/tasks/claim-by-code、/api/tasks/my(小程序 C 端账号→OPC 身份 find-or-create 领单)
- 迁移 0008(tasks 加列 + task_claims)已应用+stamp;seed 补 task_code/tags/grab demo。
- tests/test_task_claim.py(自包含内存库, 状态机+流水+list_published), 直接 async 校验通过。

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-25 18:40:35 +08:00
Pine 879396b532 feat(user): 全局用户准确来源 + 丰富跨端字段(全端口兼容)
- users 增: wx_unionid/wx_mini_openid(微信绑定), source(来源枚举), auth_type, register_ip, last_login_ip/at, email, gender, birthday, compute_provisioned/username/quota/used_quota(算力镜像); alembic 0006
- 来源: register/phone-login/wx-login(读 X-Client 头,回退 body.source,再回退按 auth_type 推断)、admin 创建=admin、seed=seed
- auth: 登录(签发令牌)记 last_login; profile 返回 source/auth_type/compute; email/gender/birthday 可编辑
- 对账 sync-users 回写 compute_* 镜像到平台用户
- _user_to_dict 含全部新字段; 迁移已应用, 导入/零依赖校验通过(dict 含 source/算力)
2026-08-25 16:21:20 +08:00
Pine ad14f9ccce fix(compute): sync-users 移除 write_audit(根治会话 PendingRollback/UNIQUE 污染)
- write_audit 的 commit 与对账只读会话事务交互, 触发 PendingRollbackError + audit_logs.id UNIQUE 冲突, 并污染会话使后续 get_current_user 连带失败
- 对账幂等自明不写审计, 直接返回统计; 点击同步不再 500
2026-08-25 15:47:27 +08:00
Pine 77a71cc0e6 fix(compute): sync-users 审计改最佳努力,修复会话事务冲突 500
- 对账循环中 db.users.list() 开了未关事务, 末尾 write_audit 的 commit 报 IllegalStateChangeError(commit during prepare)
- 审计包裹 try/except 不阻断对账; 引擎用户同步不再 500
2026-08-25 15:45:30 +08:00
Pine 2675e3776a feat(compute): 引擎用户对账同步(用户=平台总用户)
- compute_client.ensure_user(幂等建号, 存在不抛)
- 新增 POST /admin/compute/sync-users: 遍历平台全部用户→建引擎账号(幂等)+缺令牌签PAT, 保证 engine用户=平台用户
- 解决已有平台用户未回填导致引擎≠平台(此前仅新用户同步)
2026-08-25 15:31:32 +08:00
Pine f067c02ec2 feat(compute): 新增 /admin/compute/proxy/{path} 透传 compute-engine 管理 API
- compute_client.proxy(): 转发到引擎 /api/<path>,保留原始状态码/响应体
- rbac_operator 新增 compute_proxy 端点(GET/POST/PUT/DELETE/PATCH),运营端鉴权
- 使 admin 端可 1:1 驱动 new-api 完整管理面(models/channels/groups/tokens/users/logs/redemption/ratio)
2026-08-25 01:52:35 +08:00
Pine 866f82dbc4 feat(admin): 运营端培训业务 P0 — 新增 /admin/courses|activities|bookings|tests
新增 courses 表(app/training/db.py SEED_COURSES),经 training_admin_bridge 桥接
app.training 的课程/活动(events)/报名(bookings)/测评(tests) 数据为统一运营视图;
schemas 增 Course/Activity/Booking/Test 请求模型;rbac_operator.py 增四件套端点
(含 create/status/patch),走 operator 角色 + action:* 权限码 + write_audit。
2026-08-24 16:57:13 +08:00
Pine b90539a013 feat(server): 统一登录+算力打通(port 阶段0-1)落地四层架构
- 登录:/auth/send-code·phone-login·wx-login·wx-phone(复用 RBAC 签发)
- 算力:services/compute_client(loopback :3000)+ /admin/compute/ping·provision
- /v1 relay 改走 compute-engine(前端不直连引擎)
- 模型:User 补 wx_openid/phone;仓储 async create+新方法
- 契约:api/schemas(auth/compute)Pydantic
2026-08-24 14:16:34 +08:00
Pine 01ef3c9637 refactor: schemas 抽取(DTO 从 models.py 与路由内联迁至 api/schemas/)
- 新建 api/schemas/:auth/agents/admin/ecosystem/investor/opc/operator/org/portals
- models.py 移除 15 个 Pydantic DTO(保留 ORM 数据模型层)
- 13 个路由内联 DTO 全部迁出,路由瘦身仅剩处理逻辑
- 全量 66 测试通过
2026-08-24 09:51:52 +08:00
Pine 980a2db6d9 refactor: 平台应用异步四层架构(接口/业务/领域/基础设施)
- 基础设施层 async:SQLAlchemy 异步引擎/会话、33 Repository async 化、models/security/seed 迁入 infrastructure、新增 cache.py(redis.asyncio) 与 oss.py(aioboto3)
- 接口层:routers 迁 api/routers 并全 async,dependencies 迁 api/dependencies(get_db/get_current_user async)
- 依赖:sqlalchemy[asyncio]/aiosqlite/asyncmy/redis/aioboto3;config 异步 URL + Redis/OSS 配置
- 删除废弃:旧同步 db/dependencies/repositories/storage
- 验证:平台 19 路由 + 培训 48 路由全注册;/health /auth/login /auth/me /admin/tasks /notifications 等接口 async 可用
2026-08-23 23:52:58 +08:00