You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1.2 KiB
24 lines
1.2 KiB
|
7 days ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""票 05:给 ADMIN(罗伟健)补 dept_id(全库唯一缺部门用户,测试数据修复)。"""
|
||
|
|
import io, sys
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
|
import pymysql
|
||
|
|
conn = pymysql.connect(host='8.129.84.155', port=3306, user='root', password='Itc@123456',
|
||
|
|
database='crm', charset='utf8mb4', autocommit=True)
|
||
|
|
cur = conn.cursor()
|
||
|
|
# 顶级部门(e2e-rules a_dept_id 同款:parent_id=0 最新一条 = seed 造的部门)
|
||
|
|
cur.execute('SELECT id, dept_name FROM sys_dept WHERE deleted=0 AND parent_id=0 '
|
||
|
|
'ORDER BY create_time DESC LIMIT 3')
|
||
|
|
print('候选顶级部门:')
|
||
|
|
for r in cur.fetchall():
|
||
|
|
print(' ', r)
|
||
|
|
cur.execute('SELECT id, dept_name FROM sys_dept WHERE deleted=0 AND parent_id=0 '
|
||
|
|
'ORDER BY create_time DESC LIMIT 1')
|
||
|
|
dept_id, dept_name = cur.fetchone()
|
||
|
|
cur.execute("UPDATE crm_auth_user SET dept_id=%s WHERE id='739564171091247104' AND dept_id IS NULL",
|
||
|
|
(str(dept_id),))
|
||
|
|
print(f'ADMIN -> dept {dept_id} ({dept_name}), affected={cur.rowcount}')
|
||
|
|
cur.execute("SELECT id, username, dept_id FROM crm_auth_user WHERE id='739564171091247104'")
|
||
|
|
print('after:', cur.fetchone())
|
||
|
|
conn.close()
|