- user_scopes 由"假开关"做成生效:粒度到项目级(组织隔离 ∧ 项目∈范围,取交集);未配置=不限制(逐字向后兼容);
总管理员豁免;脏数据保守忽略不锁死;配置期校验存在性+归属;逐接口叠加(列表/详情/写操作/Excel 导出落 scope_project_ids);
前端新增"数据范围"弹窗入口。顺带修 GET /api/charge-orders 此前完全没有组织隔离(跨租户泄露)、
GET /api/projects/{id}/cabinets 的 500
- 数据库列类型系统性对齐:扫描并修复 pms_dev 32 项 / pms 18 项漂移(时间列统一 DATETIME,sqlx NaiveDateTime 只兼容 DATETIME);
DECIMAL→BIGINT 与列注释口径拉平;修复生产 GET /api/charge-orders、GET /api/device-logs 必然 500 的根因;
恢复 7 张表丢失的 updated_at ON UPDATE(行为变化,已记入 AGENTS.md);修正 SCHEMA_SQL 前向引用(空库建表必崩);
新增 tools/db_schema_diff.py(漂移检查,退出码可接部署前置)与 test/schema_alignment_e2e.py
- 安全加固四项:上传去 .svg + 魔数嗅探(堵存储型 XSS);登录失败锁定(5次/15分)+challenge 限流+并发闸门+验证码容差收紧;
服务降权 root→pms;nginx 安全头 + limit_req + CORS 白名单收敛
- TCP 连接登录门控(上行+下行同一规则):login 前只放行 auth_str/login(PRE_LOGIN_ALLOWED_ACTS)
- 状态位按归属层级展示:柜级 status1/status2 显示在柜子(含柜门 + 开门按钮,独立动作不联动业务)、
仓体级 batt_status/pow_status 显示在仓体;两端解析函数同源同名
- 能耗报表改实时聚合 charge_records(原 energy_stats 全表只读不写导致报表恒 0)+ 补复合索引
- 组织可见性:新增 GET /api/my-organizations(工厂全量、客户仅本组织)
- 仓体 status 仅表占用,充满/故障由 Redis 通道状态派生
- 订单/占用/队列运维缺口:h5 建单漏单、214 仓体自愈、device:reports 上限、死信 TTL、LimitNOFILE、
每日 mysqldump + 回滚点保留 5 次
- 文档:AGENTS.md 补层级可见性/数据范围/状态位约定/数据库工具/行为变化;docs/API.md 删除废弃 TCP 章节、接口总表对齐 mod.rs
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
"""对**当前线上测试环境**(test.anzhizhichong.com → :3000,另一 agent 于 01:50 重新部署的
|
||
合并版二进制)做一次端到端验证:
|
||
|
||
插入 2 条临时 charge_records → 调 4 个接口(经 nginx + HTTPS)→ 删除临时数据。
|
||
|
||
服务端 sqlx 会话时区为 +00:00,所以"今天(UTC)"= 2026-09-19。
|
||
"""
|
||
import json
|
||
import time
|
||
import pymysql
|
||
import jwt
|
||
import requests
|
||
|
||
DB = dict(host="10.8.0.252", user="root", password="Hbhyg731024@", database="pms_dev")
|
||
SECRET = "32e8708743c42fe764aff1d40737a63803a46815a9501f4bcb50c41fe3d27108"
|
||
BASE = "https://test.anzhizhichong.com/api/pms"
|
||
|
||
conn = pymysql.connect(**DB)
|
||
cur = conn.cursor()
|
||
|
||
# ---- 临时总管理员
|
||
cur.execute(
|
||
"INSERT INTO users (phone, name, password, role, organization_id, status) "
|
||
"VALUES ('19900000002','能耗复验临时管理员','x',2,NULL,1)"
|
||
)
|
||
user_id = cur.lastrowid
|
||
|
||
# ---- 2 条临时充电记录(挂在已有柜子 1 / 仓体 1 上):昨天 222Wh + 今天(UTC) 333Wh
|
||
records = []
|
||
for energy, day_expr in ((333, "CURDATE()"), (222, "DATE_SUB(CURDATE(), INTERVAL 1 DAY)")):
|
||
cur.execute(
|
||
"INSERT INTO charge_records "
|
||
"(compartment_id, cabinet_id, start_time, end_time, energy, max_temperature, status) "
|
||
f"VALUES (1, 1, {day_expr} + INTERVAL 10 HOUR, {day_expr} + INTERVAL 12 HOUR, %s, 29815, 0)",
|
||
(energy,),
|
||
)
|
||
records.append(cur.lastrowid)
|
||
conn.commit()
|
||
print(f"插入临时数据: user_id={user_id} charge_records={records} (333Wh + 222Wh)")
|
||
|
||
now = int(time.time())
|
||
token = jwt.encode({"sub": user_id, "phone": "19900000002",
|
||
"exp": now + 3600, "iat": now}, SECRET, algorithm="HS256")
|
||
headers = {"Authorization": f"Bearer {token}"}
|
||
|
||
paths = [
|
||
"/energy-stats/summary",
|
||
"/energy-stats/cabinets",
|
||
"/energy-stats/projects",
|
||
"/energy-stats/trend?granularity=day&range=30",
|
||
]
|
||
try:
|
||
for p in paths:
|
||
r = requests.get(BASE + p, headers=headers, timeout=20)
|
||
print(f"\n--- GET /api/pms{p} [HTTP {r.status_code}]")
|
||
try:
|
||
print(json.dumps(r.json(), ensure_ascii=False))
|
||
except ValueError:
|
||
print(r.text[:400])
|
||
finally:
|
||
# ---- 清理
|
||
cur.execute("DELETE FROM charge_records WHERE id IN (%s,%s)", records)
|
||
cur.execute("DELETE FROM users WHERE id = %s", (user_id,))
|
||
conn.commit()
|
||
print(f"\n已清理: charge_records {records} 与 user_id={user_id}")
|
||
cur.execute("SELECT COUNT(*) FROM charge_records")
|
||
print("charge_records 剩余行数 =", cur.fetchone()[0])
|
||
cur.close()
|
||
conn.close()
|