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.

65 lines
2.9 KiB

17 hours ago
# -*- coding: utf-8 -*-
"""票 04 数据态修复:collab owner 还原曾偲青 + followFuture 补未来回访"""
import sys, io, json
from datetime import datetime, timedelta
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import requests
import pymysql
BASE = 'http://localhost:8080'
ADMIN = '739564171091247104'
BUDDY, BUDDY_NAME, BUDDY_DEPT, BUDDY_DEPT_NAME = ('744842318024015872', '曾偲青',
'744841292483133440', '职员')
COLLAB_ID = '750844482391375872'
FOLLOW_FUTURE_ID = '750844480352944128'
conn = pymysql.connect(host='8.129.84.155', user='root', password='Itc@123456',
database='crm', charset='utf8mb4', autocommit=True,
cursorclass=pymysql.cursors.DictCursor)
cur = conn.cursor()
# 1. collab owner 四字段还原(seed-customer.py L209-211 同款语义)
cur.execute("UPDATE customer SET owner_user_id=%s, owner_user_name_snapshot=%s, "
"owner_dept_id=%s, owner_dept_name_snapshot=%s WHERE id=%s",
(BUDDY, BUDDY_NAME, BUDDY_DEPT, BUDDY_DEPT_NAME, COLLAB_ID))
cur.execute("SELECT owner_user_id, owner_user_name_snapshot FROM customer WHERE id=%s",
(COLLAB_ID,))
row = cur.fetchone()
print('1. collab owner 还原 ->', row['owner_user_id'], row['owner_user_name_snapshot'])
assert str(row['owner_user_id']) == BUDDY
# 2. followFuture 补未来回访(API 走真实路径,返工后契约:params id + 表单)
tok = None # debug/token 偶发瞬时故障(Redis reset)→ 重试(core get_token 同款)
for _ in range(5):
try:
d = requests.get(f'{BASE}/api/auth/debug/token', params={'userId': ADMIN},
timeout=15).json().get('data')
if d:
tok = d if isinstance(d, str) else d.get('token')
if tok:
break
except Exception as e:
print(' token retry:', e)
import time
time.sleep(2)
assert tok, 'debug/token 重试 5 次仍失败'
nxt = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%S')
r = requests.post(f'{BASE}/api/customer/follow/add', params={'id': FOLLOW_FUTURE_ID},
headers={'Authorization': f'Bearer {tok}'},
data={'followWay': 'follow_way_01',
'followContent': 'e2c 数据态修复:补未来回访(票04)',
'nextFollowTime': nxt}, timeout=30)
body = r.json()
print('2. followFuture 补跟进 ->', r.status_code, body.get('code'), body.get('message'))
assert body.get('code') == 0
# 3. 复核 detail-head nextFollowTime
r = requests.get(f'{BASE}/api/customer/detail-head', params={'id': FOLLOW_FUTURE_ID},
headers={'Authorization': f'Bearer {tok}'}, timeout=30)
d = (r.json() or {}).get('data') or {}
print('3. detail-head nextFollowTime ->', d.get('nextFollowTime'))
assert d.get('nextFollowTime')
conn.close()
print('FIX DONE')