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.
80 lines
3.9 KiB
80 lines
3.9 KiB
|
1 day ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""第七轮诊断:①seed 联系人 jobTitleName ②pool+viewType 复现 ③edit CAS 复现"""
|
||
|
|
import io, sys, json, urllib.request, urllib.parse
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', line_buffering=True)
|
||
|
|
sys.path.insert(0, r"e:\code\crm-backend-matt\.scratch\customer-demo-ref\demo")
|
||
|
|
import pymysql
|
||
|
|
|
||
|
|
BASE = "http://localhost:8080"
|
||
|
|
ADMIN = "739564171091247104"
|
||
|
|
|
||
|
|
def get_json(url, token=None):
|
||
|
|
req = urllib.request.Request(url)
|
||
|
|
if token: req.add_header("Authorization", "Bearer " + token)
|
||
|
|
with urllib.request.urlopen(req, timeout=30) as r:
|
||
|
|
return json.loads(r.read().decode())
|
||
|
|
|
||
|
|
def post(url, data, token=None):
|
||
|
|
req = urllib.request.Request(url, data=urllib.parse.urlencode(data).encode(), method="POST")
|
||
|
|
req.add_header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
|
||
|
|
if token: req.add_header("Authorization", "Bearer " + token)
|
||
|
|
with urllib.request.urlopen(req, timeout=30) as r:
|
||
|
|
return json.loads(r.read().decode())
|
||
|
|
|
||
|
|
def db():
|
||
|
|
return pymysql.connect(host='8.129.84.155', port=3306, user='root', password='Itc@123456',
|
||
|
|
database='crm', charset='utf8mb4', autocommit=True, connect_timeout=10,
|
||
|
|
cursorclass=pymysql.cursors.DictCursor)
|
||
|
|
|
||
|
|
tok = get_json(f"{BASE}/api/auth/debug/token?userId={ADMIN}").get("data")
|
||
|
|
if isinstance(tok, dict): tok = tok.get("token")
|
||
|
|
|
||
|
|
print("== ① seed 联系人 jobTitleName ==")
|
||
|
|
with db() as conn, conn.cursor() as cur:
|
||
|
|
cur.execute("SELECT id, name, job_title_id, job_title_name, phone FROM customer_contact "
|
||
|
|
"WHERE customer_id=750844477165273088 AND deleted=0 ORDER BY id")
|
||
|
|
for r in cur.fetchall():
|
||
|
|
print(" ", r)
|
||
|
|
|
||
|
|
print("== ② pool+viewType 复现(对 e2c-dr-imp 客户) ==")
|
||
|
|
with db() as conn, conn.cursor() as cur:
|
||
|
|
cur.execute("SELECT id, customer_name, owner_user_id, archive_status, version FROM customer "
|
||
|
|
"WHERE customer_name LIKE 'e2c-dr%' AND deleted=0")
|
||
|
|
rows = cur.fetchall()
|
||
|
|
for r in rows: print(" ", r)
|
||
|
|
|
||
|
|
def wsp(view, kw="e2c-dr-imp"):
|
||
|
|
body = {"workspace": "pool", "current": "1", "size": "50", "viewType": view, "keyword": kw, "archiveStatus": "1"}
|
||
|
|
return post(f"{BASE}/api/customer/workspace/page", body, tok)
|
||
|
|
|
||
|
|
for v in ("ASSIGNED", "", "COLLABORATING"):
|
||
|
|
try:
|
||
|
|
d = wsp(v)
|
||
|
|
c = (d.get("data") or {})
|
||
|
|
rows2 = c.get("content") or []
|
||
|
|
print(" pool viewType=%r -> total=%s rows=%s" % (v, c.get("total"), [r.get("customerName") for r in rows2][:5]))
|
||
|
|
except Exception as e:
|
||
|
|
print(" pool viewType=%r -> ERR %s" % (v, e))
|
||
|
|
|
||
|
|
print("== ③ edit CAS 复现(对恒信达 seed) ==")
|
||
|
|
with db() as conn, conn.cursor() as cur:
|
||
|
|
cur.execute("SELECT id, customer_name, version FROM customer WHERE customer_name='e2c-dr-恒信达科技有限责任公司' AND deleted=0")
|
||
|
|
rows3 = cur.fetchall()
|
||
|
|
for r in rows3: print(" before:", r)
|
||
|
|
if rows3:
|
||
|
|
cid = str(rows3[0]["id"]); ver = str(rows3[0]["version"])
|
||
|
|
det = get_json(f"{BASE}/api/customer/detail?id={cid}", tok)
|
||
|
|
dv = ((det.get("data") or {}).get("detail") or {}).get("version")
|
||
|
|
print(" detail.version =", dv, "| db.version =", ver)
|
||
|
|
body = {"customerName": "e2c-dr-恒信达科技有限责任公司-改", "customerType": "customer_type_01",
|
||
|
|
"provinceCode": "440000", "cityCode": "440100", "districtCode": "440103",
|
||
|
|
"industryCode": "I", "version": ver}
|
||
|
|
ret = post(f"{BASE}/api/customer/edit?id={cid}", body, tok)
|
||
|
|
print(" edit ret:", json.dumps(ret, ensure_ascii=False)[:200])
|
||
|
|
with db() as conn, conn.cursor() as cur:
|
||
|
|
cur.execute("SELECT id, customer_name, version FROM customer WHERE id=%s", (int(cid),))
|
||
|
|
for r in cur.fetchall(): print(" after:", r)
|
||
|
|
# 还原
|
||
|
|
cur.execute("UPDATE customer SET customer_name='e2c-dr-恒信达科技有限责任公司' WHERE id=%s", (int(cid),))
|
||
|
|
print(" (已还原名字)")
|