非标业绩提报、合伙人结算登记字段修改
续约回访 宜搭同步简道云辅助脚本 简道云同步宜搭辅助脚本
This commit is contained in:
@@ -32,7 +32,7 @@ class YDAPI:
|
||||
token = res.json().get('accessToken')
|
||||
return token
|
||||
|
||||
def update_from(self, token, formInstanceId, data_new,delay=2, max_retries=10):
|
||||
def update_from(self, token, formInstanceId, data_new):
|
||||
"""
|
||||
函数功能:更新表单内容
|
||||
|
||||
@@ -62,19 +62,9 @@ class YDAPI:
|
||||
"updateFormDataJson": json.dumps(data_new, cls=NpEncoder),
|
||||
|
||||
}
|
||||
attempt = 0
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法更新表单数据,跳过本次请求。")
|
||||
break
|
||||
try:
|
||||
res = requests.get(api, headers=headers,timeout=10)
|
||||
res.raise_for_status() # 如果响应状态码不是2xx,则抛出HTTPError
|
||||
return res.json()
|
||||
except (requests.exceptions.RequestException, Exception) as e:
|
||||
print(f"请求出现异常: {e}, 正在重试({attempt + 1}/{max_retries})...")
|
||||
time.sleep(delay) # 等待指定的延迟时间后再次尝试
|
||||
attempt += 1
|
||||
|
||||
res = requests.put(api, headers=headers, json=payload)
|
||||
return res
|
||||
|
||||
def processes_instancesInfos(self, token, id, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", delay=2, max_retries=10):
|
||||
@@ -115,7 +105,7 @@ class YDAPI:
|
||||
attempt += 1
|
||||
|
||||
def read_processes(self, token, formUuid, page, n, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", max_retries=10,delay=2):
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", max_retries=10, delay=2):
|
||||
"""
|
||||
函数功能:读取普通表单的所有数据
|
||||
|
||||
@@ -151,9 +141,9 @@ class YDAPI:
|
||||
|
||||
try:
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
logger.info(f"HTTP Status Code: {res.status_code}")
|
||||
logger.info(f"Response Headers: {dict(res.headers)}")
|
||||
logger.info(f"Raw Response Text: {res.text}") # 注意:不要在线上环境打印敏感数据!
|
||||
# logger.info(f"HTTP Status Code: {res.status_code}")
|
||||
# logger.info(f"Response Headers: {dict(res.headers)}")
|
||||
# logger.info(f"Raw Response Text: {res.text}") # 注意:不要在线上环境打印敏感数据!
|
||||
return res.json()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
@@ -163,7 +153,9 @@ class YDAPI:
|
||||
|
||||
def read_processes_instances(self, token, formUuid, page, n, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", instanceStatus="RUNNING",
|
||||
max_retries=10, delay=2, createFromTimeGMT=None, createToTimeGMT=None):
|
||||
max_retries=10, delay=2, createFromTimeGMT=None, createToTimeGMT=None,
|
||||
modifiedFromTimeGMT=None,
|
||||
modifiedToTimeGMT=None, searchFieldJson={}):
|
||||
"""
|
||||
函数功能:读取流程表单的所有数据,并加入重试机制。
|
||||
|
||||
@@ -200,7 +192,13 @@ class YDAPI:
|
||||
"instanceStatus": instanceStatus, # 运行中
|
||||
"createFromTimeGMT": createFromTimeGMT,
|
||||
"createToTimeGMT": createToTimeGMT,
|
||||
"modifiedFromTimeGMT": modifiedFromTimeGMT,
|
||||
"modifiedToTimeGMT": modifiedToTimeGMT,
|
||||
"searchFieldJson": json.dumps(
|
||||
searchFieldJson
|
||||
)
|
||||
}
|
||||
# print(formData)
|
||||
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
@@ -209,6 +207,62 @@ class YDAPI:
|
||||
|
||||
try:
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
# print(res.json())
|
||||
res.raise_for_status() # 如果返回状态码不是2xx,抛出异常
|
||||
return res.json()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.warning(f"请求异常: {e},正在尝试第 {attempt + 1} 次重试...")
|
||||
time.sleep(delay)
|
||||
attempt += 1
|
||||
|
||||
@staticmethod
|
||||
def get_ids_query(token, formUuid, appType, systemToken, formInstanceIdList=None, max_retries=10, delay=2):
|
||||
"""
|
||||
函数功能:读取表单的所有数据,并加入重试机制。
|
||||
|
||||
Args:
|
||||
token (str): 登录验证token,用于API调用的身份验证。
|
||||
formUuid (str): 表单唯一标识符,用于指定需要读取哪个表单的实例数据。
|
||||
page (int): 分页参数,指定请求的数据页码。
|
||||
n (int): 每页显示的数据条数。
|
||||
appType (str): 应用类型标识符,默认为 "APP_UYZ0KG6L0CCNV80GZ66O"
|
||||
systemToken (str): 系统token,默认为固定值
|
||||
instanceStatus (str): 流程实例状态,默认为"RUNNING"
|
||||
max_retries (int): 最大重试次数,默认为10次
|
||||
delay (int): 每次重试之间的延迟秒数,默认为2秒
|
||||
|
||||
Returns:
|
||||
dict: 返回从API获取的流程表单实例数据的JSON解析结果。
|
||||
|
||||
Raises:
|
||||
Exception: 如果达到最大重试次数仍未成功,则抛出异常。
|
||||
"""
|
||||
|
||||
attempt = 0
|
||||
api = f'https://api.dingtalk.com/v1.0/yida/forms/instances/ids/query'
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": token
|
||||
}
|
||||
formData = {
|
||||
"appType": appType,
|
||||
"systemToken": systemToken,
|
||||
"userId": "yida_pub_account", # 超级管理员账号
|
||||
"language": "zh_CN",
|
||||
"formUuid": formUuid,
|
||||
"formInstanceIdList": formInstanceIdList,
|
||||
}
|
||||
# print(formData)
|
||||
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法获取流程实例数据,跳过本次请求。")
|
||||
break
|
||||
|
||||
try:
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
# print(res.json())
|
||||
res.raise_for_status() # 如果返回状态码不是2xx,抛出异常
|
||||
return res.json()
|
||||
|
||||
@@ -277,7 +331,6 @@ class YDAPI:
|
||||
headers = {
|
||||
# "Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": token
|
||||
|
||||
}
|
||||
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user