95 lines
6.5 KiB
SQL
95 lines
6.5 KiB
SQL
-- UniSOA 生产库(unis_oa_prod)登录账号恢复:chenpeng -> chenpeng01
|
||
-- ⚠️【已被取代 2026-11-19 17:36】这一版把账号改回 chenpeng01 后只活了 5 分钟:
|
||
-- 17:30:54 又跑了一次手动 Hub 同步,账号被 Hub 改回 chenpeng,他从 chenpeng 进来
|
||
-- 什么都看不到。最终方向改成以 chenpeng 为准,见
|
||
-- sql/cleanup/20261119_chenpeng01_merge_to_chenpeng_prod.sql(把留在 chenpeng01 上的 84 行并过来)。
|
||
-- 本文件不要再执行,留着只是记录当时的判断与那 5 行的原值(备份同名在 sql/backup/ 下)。
|
||
-- 对象:users.id=1092 陈鹏(hub_user_id=313,企微 UserID=chenpeng01,部门 董事长)
|
||
--
|
||
-- 发生了什么(按库里的事实还原)
|
||
-- 2026-11-19 一天里手工同步了三次 Hub 目录,三次都在改这个人的登录账号:
|
||
-- 16:59:08 run 68be7ccf… chenpeng01 -> chenpeng(同时按 Hub 刷了企微 UserID)
|
||
-- 17:08:05 run 226313b2… chenpeng -> chenpeng01
|
||
-- 17:12:05 run 8e79be2f… chenpeng01 -> chenpeng ← 现在停在 chenpeng
|
||
-- 每次改名,hub_refs 只搬配置层引用(oa_role.list_auth 那 1 处),运行态历史行按口径不搬,
|
||
-- 于是同一个人在库里被劈成两半:改名前的 34 行还挂在 chenpeng01 上(oa_task 1 +
|
||
-- oa_task_completed 15 + oa_notification 18,与同步记录里报的那个 34 条对得上),
|
||
-- 改名之后新写的行挂在 chenpeng 上。他现在登录进去看得到账号是 chenpeng,
|
||
-- 发起过的单与已办全部查不到。
|
||
--
|
||
-- 改哪几行(都是"现在还在用"的那一层,历史留痕不动)
|
||
-- users 1 行 登录账号本身
|
||
-- oa_role 1 行 审批岗位「执行董事」成员名单——17:12 那趟同步搬走的,不搬回来
|
||
-- 下次走到这个环节就解析不出审批人
|
||
-- oa_task 1 行 在办的待办 YZSY20261118000003(17:07:45 落在 chenpeng 上)
|
||
-- oa_work 1 行 上面那张单的当前审批人游标,与 oa_task.identity 同一份口径
|
||
-- oa_notification 1 行 上面那条待办的未读站内信(read=0)
|
||
-- 共 5 行。
|
||
--
|
||
-- 故意不动
|
||
-- oa_operation_log(登录与操作留痕)、oa_notify_delivery(企微推送回执)、
|
||
-- oa_node_decision.response、oa_work_log.from_identity、oa_read*.source_identity、
|
||
-- oa_task_completed / oa_notification 上那 34 条 chenpeng01 的历史行——它们记的是当时那一刻,
|
||
-- 口径同 app/service/hub_refs.py 文件头:历史单据与待办不跟账号改名搬。
|
||
--
|
||
-- 备份:sql/backup/pre_chenpeng01_account_20261119_172341.sql(5 行原样 INSERT,可按主键回插)
|
||
--
|
||
-- ⚠️ 根因在 Hub 侧:本地 account 跟着 Hub 目录的账号走(hub_sync._plan_account_renames)。
|
||
-- Hub 里 313 这个人现在的账号是 chenpeng,不把它改回 chenpeng01,下次同步还会再改一次。
|
||
|
||
-- 执行前确认(左边是表名,右边应分别等于注释上的行数)
|
||
SELECT 'users' t, COUNT(*) n FROM `users` WHERE id = 1092 AND account = 'chenpeng' -- 1
|
||
UNION ALL SELECT 'oa_role', COUNT(*) FROM `oa_role` WHERE id = '1513972be8f544ca875c96fafb964319'
|
||
AND JSON_LENGTH(`list_auth`) = 1 AND JSON_SEARCH(`list_auth`, 'one', 'chenpeng') = '$[0]' -- 1
|
||
UNION ALL SELECT 'oa_task', COUNT(*) FROM `oa_task` WHERE id = 'd17e1ac12099498abbacb4e7b9cb4aff'
|
||
AND `identity` = 'chenpeng' AND `status` = 'pending' -- 1
|
||
UNION ALL SELECT 'oa_work', COUNT(*) FROM `oa_work` WHERE id = 'b25641ea12d845d1b750912a32f42c77'
|
||
AND JSON_LENGTH(`manual_identity_list`) = 1
|
||
AND JSON_SEARCH(`manual_identity_list`, 'one', 'chenpeng') = '$[0]' -- 1
|
||
UNION ALL SELECT 'oa_notification', COUNT(*) FROM `oa_notification` WHERE id = '4ac6599bfcc2416a88330094b9ab7ec9'
|
||
AND `identity` = 'chenpeng' -- 1
|
||
UNION ALL SELECT '撞车:已存在的 chenpeng01', COUNT(*) FROM `users` WHERE account = 'chenpeng01'; -- 0
|
||
|
||
START TRANSACTION;
|
||
|
||
-- users: 1 行,登录账号本体
|
||
UPDATE `users` SET `account` = 'chenpeng01' WHERE id = 1092 AND `account` = 'chenpeng';
|
||
|
||
-- oa_role: 1 行,审批岗位「执行董事」成员名单(备用金/印章等流程的该环节审批人来源)
|
||
-- list_auth / manual_identity_list 是 JSON 列,等号比不中,按数组元素原位替换(只有一格时)
|
||
UPDATE `oa_role` SET `list_auth` = JSON_REPLACE(`list_auth`, '$[0]', 'chenpeng01')
|
||
WHERE id = '1513972be8f544ca875c96fafb964319'
|
||
AND JSON_LENGTH(`list_auth`) = 1 AND JSON_SEARCH(`list_auth`, 'one', 'chenpeng') = '$[0]';
|
||
|
||
-- oa_task: 1 行,在办待办归回本人
|
||
UPDATE `oa_task` SET `identity` = 'chenpeng01'
|
||
WHERE id = 'd17e1ac12099498abbacb4e7b9cb4aff' AND `identity` = 'chenpeng' AND `status` = 'pending';
|
||
|
||
-- oa_work: 1 行,同一张单的当前审批人游标(与 oa_task.identity 保持一致)
|
||
UPDATE `oa_work` SET `manual_identity_list` = JSON_REPLACE(`manual_identity_list`, '$[0]', 'chenpeng01')
|
||
WHERE id = 'b25641ea12d845d1b750912a32f42c77'
|
||
AND JSON_LENGTH(`manual_identity_list`) = 1
|
||
AND JSON_SEARCH(`manual_identity_list`, 'one', 'chenpeng') = '$[0]';
|
||
|
||
-- oa_notification: 1 行,未读待办站内信归回本人收件箱
|
||
UPDATE `oa_notification` SET `identity` = 'chenpeng01'
|
||
WHERE id = '4ac6599bfcc2416a88330094b9ab7ec9' AND `identity` = 'chenpeng';
|
||
|
||
-- 五条 UPDATE 各影响 1 行才提交,否则 ROLLBACK
|
||
COMMIT;
|
||
|
||
-- 执行后确认
|
||
-- 1) 库里不该再有"当前还在用"的 chenpeng:这两条都应返回 0
|
||
SELECT '仍挂在 chenpeng 的在办待办' t, COUNT(*) n FROM `oa_task`
|
||
WHERE `identity` = 'chenpeng' AND `status` = 'pending'
|
||
UNION ALL SELECT '未读站内信挂在 chenpeng', COUNT(*) FROM `oa_notification`
|
||
WHERE `identity` = 'chenpeng' AND `read` = 0
|
||
UNION ALL SELECT '审批岗位仍指着 chenpeng', COUNT(*) FROM `oa_role`
|
||
WHERE JSON_SEARCH(`list_auth`, 'one', 'chenpeng') IS NOT NULL;
|
||
-- 2) 这个人的账号与历史行重新并回一串:应返回 1 / 34
|
||
SELECT 'users 上的 chenpeng01' t, COUNT(*) n FROM `users` WHERE account = 'chenpeng01' AND id = 1092
|
||
UNION ALL SELECT '运行态挂在 chenpeng01 的行',
|
||
(SELECT COUNT(*) FROM `oa_task` WHERE `identity` = 'chenpeng01')
|
||
+ (SELECT COUNT(*) FROM `oa_task_completed` WHERE `identity` = 'chenpeng01')
|
||
+ (SELECT COUNT(*) FROM `oa_notification` WHERE `identity` = 'chenpeng01');
|