"""组织隔离的实测准备:再插一个「另一个组织」的数据(energy=7777), 用于验证 role_level=1 的组织管理员**看不到**它的数据。 落点故意与 2026-09-19 那批数据同一时刻(= 服务 UTC 会话下的"今天"), 这样超管"今日"= 6000+7777 = 13777,而组织 1 管理员必须仍是 6000。 """ import json import os import pymysql HERE = os.path.dirname(os.path.abspath(__file__)) conn = pymysql.connect(host="10.8.0.252", user="root", password="Hbhyg731024@", database="pms_dev") cur = conn.cursor() created = {"org_id": None, "project_id": None, "cabinet_id": None, "board_id": None, "compartment_id": None, "record_id": None} cur.execute("INSERT INTO organizations (name) VALUES ('能耗验证临时组织B')") created["org_id"] = cur.lastrowid org_b = created["org_id"] cur.execute("INSERT INTO projects (organization_id, name) VALUES (%s, %s)", (org_b, "能耗验证临时项目B")) created["project_id"] = cur.lastrowid cur.execute( "INSERT INTO cabinets (project_id, abstract_id, imei, name, status) " "VALUES (%s, %s, %s, %s, %s)", (created["project_id"], "99-00000009", "999000000000009", "能耗验证临时柜-组织B", 1), ) created["cabinet_id"] = cur.lastrowid cur.execute("INSERT INTO cabin_boards (cabinet_id, board_id, status) VALUES (%s, 1, 1)", (created["cabinet_id"],)) created["board_id"] = cur.lastrowid cur.execute("INSERT INTO compartments (cabin_board_id, channel_id, status) VALUES (%s, 1, 0)", (created["board_id"],)) created["compartment_id"] = cur.lastrowid # 与 2026-09-19 那批(服务"今天")同一时刻 cur.execute( "INSERT INTO charge_records " "(compartment_id, cabinet_id, start_time, end_time, energy, max_temperature, status) " "VALUES (%s, %s, DATE_SUB(CURDATE(), INTERVAL 1 DAY) + INTERVAL 10 HOUR, " "DATE_SUB(CURDATE(), INTERVAL 1 DAY) + INTERVAL 12 HOUR, 7777, 29815, 0)", (created["compartment_id"], created["cabinet_id"]), ) created["record_id"] = cur.lastrowid conn.commit() path = os.path.join(HERE, "temp_ids_orgB.json") with open(path, "w", encoding="utf-8") as fh: json.dump(created, fh, ensure_ascii=False, indent=2) print(json.dumps(created, ensure_ascii=False)) cur.close() conn.close()