import json, subprocess, tempfile, os
|
from urllib.parse import quote
|
|
def q(text):
|
return quote(text, encoding='utf-8')
|
|
def api(method, url, body=None):
|
cmd = ['sh', '.tmp_api.sh', method, url]
|
tmp = None
|
if body is not None:
|
fd, tmp = tempfile.mkstemp(suffix='.json')
|
with os.fdopen(fd, 'w', encoding='utf-8') as f:
|
json.dump(body, f, ensure_ascii=False)
|
cmd.append(tmp)
|
out = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8').stdout.strip()
|
if tmp:
|
os.remove(tmp)
|
try:
|
return json.loads(out)
|
except Exception:
|
return {'raw': out[:300]}
|
|
def res(tag, r):
|
print(f'{tag}: code={r.get("code")} msg={r.get("msg")}')
|
|
# 备份 33140006(所在城市「西宁」已禁用)的原始值,测完原样写回
|
orig = api('GET', '/account/user/company/33140006')['data']
|
print('原始 33140006:', orig['province'], '/', orig['cityName'], '| 城市id', orig['cityId'],
|
'|', orig['companyName'], '|', orig['contactName'], '|', orig['contactPhone'])
|
base = {
|
'id': 33140006,
|
'cityId': orig['cityId'],
|
'companyName': orig['companyName'],
|
'userId': orig['userId'],
|
'contactName': orig['contactName'],
|
'contactPhone': orig['contactPhone']
|
}
|
|
print()
|
print('=== I. 城市被禁用后,存量档案仍可修改(本次修复点) ===')
|
res('I1 城市不变 + 只改联系人', api('PUT', '/account/user/company', dict(base, contactName='改后联系人')))
|
d = api('GET', '/account/user/company/33140006')['data']
|
print('I2 落库结果: 联系人 =', d['contactName'], '| 城市 =', d['cityName'], '(期望 改后联系人 / 西宁)')
|
|
print()
|
print('=== J. 换成另一个禁用城市仍必须被拦 ===')
|
r = api('POST', '/account/user/city', {'province': '广东省', 'cityName': '临时测试市', 'sortNo': 999})
|
res('J1 建临时城市', r)
|
r = api('GET', '/account/user/city/list?' + q('临时测试市'))
|
tid = r['rows'][0]['id'] if r.get('rows') else None
|
print('J2 临时城市 id =', tid)
|
res('J3 禁用临时城市', api('PUT', '/account/user/city/changeStatus', {'id': tid, 'status': '1'}))
|
res('J4 把存量档案换到该禁用城市', api('PUT', '/account/user/company', dict(base, cityId=tid)))
|
res('J5 新增档案到该禁用城市', api('POST', '/account/user/company',
|
dict(base, id=None, cityId=tid, companyName='禁用城市测试')))
|
|
print()
|
print('=== K. 还原演示数据 ===')
|
res('K1 还原联系人', api('PUT', '/account/user/company', dict(base)))
|
d = api('GET', '/account/user/company/33140006')['data']
|
print('K2 还原后:', d['contactName'], '|', d['contactPhone'], '|', d['cityName'], '| status', d['status'])
|
res('K3 删除临时城市', api('DELETE', '/account/user/city/%s' % tid))
|
r = api('GET', '/account/user/city/list?pageNum=1&pageSize=50')
|
print('K4 城市(未删除)total =', r['total'], '(期望 28)')
|
r = api('GET', '/account/user/company/list?pageNum=1&pageSize=50')
|
print('K5 公司档案 total =', r['total'], '(期望 7)')
|
print('K6 最大档案号 =', max(x['id'] for x in r['rows']), '(期望 33140006)')
|