# xuchao: HHRS00406553(杨红)/HHRS00402305(钟慧林) 石化减免卷预约改回"预约成功" # 用法: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 docs/tools_reopen_petrol_two_20261116.py # 干跑 # ... --apply # 实际执行 # 背景: 上午批量迁移(tools_checkoff_petrol_closed_20261116.py, hhrs commit b8e7c64)把这两条置了已核销并补写自动核销记录; # 用户指令改为保留"预约成功"。回退= UPDATE status 4→1 + DELETE 对应 card_check(均为本日上午脚本插入,硬删)。 # 原值备查: status=4;card_check id 926120000000006(预约867991347166021,check_time 2026-11-10 23:45:00)、 # 926120000000007(预约869714399186053,check_time 2026-11-15 23:45:00)——回滚即按原值重插+改回4。 import sys os_env = __import__('os') os_env.environ['SETTLE_ENV'] = 'uat' path = '/Users/jacobxu/Documents/Project/12301-dscp/docs/tools/settle_recompute_check.py' src = open(path).read() marker = "cur = conn.cursor(pymysql.cursors.DictCursor)" ns = {'__name__': 'env'} exec(compile(src.split(marker, 1)[0] + marker, path, 'exec'), ns) conn, cur = ns['conn'], ns['cur'] APPTS = [867991347166021, 869714399186053] # 杨红 / 钟慧林 CHECKS = [926120000000006, 926120000000007] ids = ','.join(map(str, APPTS)) cids = ','.join(map(str, CHECKS)) APPLY = '--apply' in sys.argv conn.begin() cur.execute(f"""SELECT id, card_number, name, status, is_deleted FROM card_appointment WHERE id IN ({ids})""") rows = cur.fetchall() print('预约现状:', rows) assert len(rows) == 2 and all(r['status'] == 4 and r['is_deleted'] == b'\x00' for r in rows), '预约状态不符,中止' cur.execute(f"""SELECT id, appointment_id, checker_id, is_deleted FROM card_check WHERE id IN ({cids})""") checks = cur.fetchall() print('核销记录现状:', checks) assert len(checks) == 2 and sorted(c['appointment_id'] for c in checks) == APPTS and all(c['checker_id'] == -2 for c in checks), '核销记录不符,中止' if not APPLY: print('干跑结束(未写入)。确认后加 --apply') conn.rollback() sys.exit(0) cur.execute(f"UPDATE card_appointment SET status=1, updated_by=1 WHERE id IN ({ids}) AND status=4") print('预约改回预约成功:', cur.rowcount, '行') assert cur.rowcount == 2, 'UPDATE行数不符,回滚' cur.execute(f"DELETE FROM card_check WHERE id IN ({cids}) AND checker_id=-2") print('删除自动核销记录:', cur.rowcount, '行') assert cur.rowcount == 2, 'DELETE行数不符,回滚' cur.execute(f"SELECT COUNT(*) c FROM card_appointment WHERE id IN ({ids}) AND status=1") assert cur.fetchone()['c'] == 2, '自检失败' cur.execute(f"SELECT COUNT(*) c FROM card_check WHERE id IN ({cids})") assert cur.fetchone()['c'] == 0, '自检失败' conn.commit() print('COMMIT 完成')