414 lines
15 KiB
Python
414 lines
15 KiB
Python
# 基础函数配置
|
|
import pandas as pd
|
|
import requests
|
|
from pathlib import Path
|
|
from urllib.parse import quote
|
|
import json
|
|
import numpy as np
|
|
import time
|
|
from datetime import date, timedelta
|
|
|
|
ROOT = Path('.').absolute() # 当前工作目录
|
|
|
|
def generateToken() -> str:
|
|
""" 生成 token """
|
|
|
|
token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'
|
|
|
|
# 该信息在钉钉开放应用中
|
|
data = {
|
|
"appKey": "ding5kqocon5s9oph5uq",
|
|
"appSecret": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'
|
|
}
|
|
|
|
res = requests.post(token_api, json=data)
|
|
token = res.json()['accessToken']
|
|
|
|
return token
|
|
|
|
def transcation(token,FORMID,data_new):
|
|
""" 函数功能:更新表单内容 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
payload = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "2268275546837446", # 曹伟 id
|
|
"language" : "zh_CN",
|
|
"useLatestVersion" : "false",
|
|
"formInstanceId" : FORMID,
|
|
"updateFormDataJson" : json.dumps(data_new, cls=NpEncoder),
|
|
}
|
|
|
|
res = requests.put(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def aggree_approval(token: str, taskId: str, processInstanceId: str, formData: dict,res_new):
|
|
""" 函数功能:同意审批节点 --F6客户服务 应用 """
|
|
api = f'https://api.dingtalk.com/v1.0/yida/tasks/execute'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
payload = {
|
|
"outResult": "AGREE",
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"remark": "同意(接口自动)",
|
|
"formDataJson": json.dumps(formData, cls=NpEncoder),
|
|
"processInstanceId": processInstanceId,
|
|
# "userId": "yida_pub_account",
|
|
"userId": res_new,
|
|
"language": "zh_CN",
|
|
"taskId": int(taskId)
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
# print('同意审批节点')
|
|
return res
|
|
def read_instances_new(token, formUuid, page, n):
|
|
""" 函数功能:读取流程表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/processes/instances?pageNumber={page}&pageSize={n}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId": "yida_pub_account", # 超级管理员账号
|
|
"language": "zh_CN",
|
|
"formUuid": formUuid,
|
|
# "searchFieldJson": json.dumps(searchField), # 如果增加上这一项会要求升级宜搭存储
|
|
"instanceStatus": "RUNNING"
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def get_approval_records(token: str, processInstanceId: str):
|
|
""" 函数功能:获取流程表单的审批记录 --F6客户服务 应用 """
|
|
appType = "APP_UYZ0KG6L0CCNV80GZ66O"
|
|
systemToken = "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2"
|
|
userId = "yida_pub_account"
|
|
|
|
api = f'https://api.dingtalk.com/v1.0/yida/processes/operationRecords?appType={appType}&systemToken={systemToken}&userId={userId}&language=zh_CN&processInstanceId={processInstanceId}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
# print('获取流程表单的审批记录')
|
|
return res.json()
|
|
def read_instances(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "yida_pub_account",
|
|
"language" : "zh_CN",
|
|
"formUuid" : formUuid,
|
|
"currentPage" : page,
|
|
"pageSize" : n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def read_instances_pt(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "yida_pub_account",
|
|
"language" : "zh_CN",
|
|
"formUuid" : formUuid,
|
|
"currentPage" : page,
|
|
"pageSize" : n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def read_processes(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId": "yida_pub_account", # 超级管理员账号
|
|
"language": "zh_CN",
|
|
"formUuid": formUuid,
|
|
'currentPage':page,
|
|
'pageSize':n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def instances_id(TOKEN,id):
|
|
""" 函数功能:查询表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/{id}?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
|
|
return res.json()
|
|
def component(FORMID,TOKEN):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/formFields'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
# "language" : "zh_CN",
|
|
"userId" : "yida_pub_account"
|
|
}
|
|
|
|
res = requests.get(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def component_id(id,TOKEN):
|
|
api = f'https://api.dingtalk.com/v1.0/yida/processes/instancesInfos/{id}?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
|
|
return res.json()
|
|
def find_indexes(daichuli_mendian_name,i_two):
|
|
indexes = [i for i, x in enumerate(daichuli_mendian_name) if x == i_two]
|
|
return indexes
|
|
def get_staffID(TOKEN: str,ALL_DATA_staff,staff_name):
|
|
res_new = [v['formData']['textField_lfrw3u59'] for v in ALL_DATA_staff if v['formData']['textField_lfrw3u58']== staff_name]
|
|
# print('通过员工名称获取员工id')
|
|
return res_new
|
|
|
|
def component(FORMID,TOKEN):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/formFields'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
# "language" : "zh_CN",
|
|
"userId" : "yida_pub_account"
|
|
}
|
|
|
|
res = requests.get(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def delete_in_batches(FORMID,TOKEN,ALL_DATA_instance):
|
|
""" 批量删除表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/batchRemove'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"asynchronousExecution" : "true",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"formInstanceIdList" : json.dumps(ALL_DATA_instance, cls=NpEncoder),
|
|
"userId" : "yida_pub_account",
|
|
"executeExpression" : "false" # 不触发
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
return res.json()
|
|
def delete_in(TOKEN,formInstanceIdList):
|
|
""" 逐条删除表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN&formInstanceId={formInstanceIdList}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
res = requests.delete(api, headers=headers)
|
|
return res.json()
|
|
def Batch_creation(FORMID,TOKEN,ALL_formData):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/batchSave'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"noExecuteExpression" : "false",
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"asynchronousExecution" : "false",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"keepRunningAfterException" : "false",
|
|
"userId" : "2268275546837446",
|
|
"formDataJsonList" : json.dumps(ALL_formData, cls=NpEncoder),
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
return res.json()
|
|
class NpEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
if isinstance(obj, np.integer):
|
|
return int(obj)
|
|
elif isinstance(obj, np.floating):
|
|
return float(obj)
|
|
elif isinstance(obj, np.ndarray):
|
|
return obj.tolist()
|
|
else:
|
|
return super(NpEncoder, self).default(obj)
|
|
# -*- coding: utf-8 -*-
|
|
import psycopg2
|
|
import pandas as pd
|
|
|
|
TOKEN = generateToken()
|
|
'''读取员工对应关系:宜搭员工-ID对应表 '''
|
|
FORMID = "FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6" # 宜搭员工-ID对应表 FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6
|
|
# 读取流程表单数据
|
|
form_data = read_instances(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
|
PAGES = form_data.get('totalCount')//100 + 1
|
|
ALL_DATA_staff = {}
|
|
""" 获取全量数据 """
|
|
for i in range(1, PAGES+1):
|
|
# form_data = read_processes_instances(token=TOKEN, formUuid=FORMID, createFromTimeGMT=CREATE_FROM, createToTimeGMT=CREATE_TO, page=i, n=100, searchField={'textField_l7if5ff9': '否'})
|
|
form_data = read_instances(token=TOKEN, formUuid=FORMID, page=i, n=100)
|
|
for data in form_data.get('data'):
|
|
ALL_DATA_staff[data['formData']['textField_lfrw3u58']]=data['formData']['textField_lfrw3u59']
|
|
import datetime
|
|
now_time = datetime.datetime.now()
|
|
yes_time = now_time + datetime.timedelta(days=-2)
|
|
yes_time_nyr = yes_time.strftime('%Y-%m-%d')# 获取日期
|
|
import binascii
|
|
import time
|
|
import random
|
|
from pyDes import des, CBC, PAD_PKCS5
|
|
import requests
|
|
def des_encrypt(s):
|
|
"""
|
|
DES 加密
|
|
:param s: 原始字符串
|
|
:return: 加密后字符串,16进制
|
|
"""
|
|
secret_key = 'HwdMBW8o'
|
|
iv = secret_key
|
|
k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
|
|
en = k.encrypt(s, padmode=PAD_PKCS5)
|
|
return binascii.b2a_base64(en, newline=False)
|
|
t = time.time()
|
|
ts = int(round(t * 1000))
|
|
randint = random.randint(100000000, 999999999)
|
|
# req = "1|2000|"+ "2020-01-01" + "|" + yes_time_nyr + "_" + str(ts) + "_" + str(randint)
|
|
req = f"1|20|{yes_time_nyr}|{yes_time_nyr}" + "_" + str(ts) + "_" + str(randint)
|
|
str_en = des_encrypt(req)
|
|
req_new = str_en.decode('utf-8')
|
|
|
|
url = f"http://manage.f6yc.com/hive-admin/py/yida/renewal/coupons/fetch"
|
|
data = {
|
|
'req':req_new,
|
|
't':ts,
|
|
'r':randint
|
|
}
|
|
res = requests.post(url,data=data)
|
|
merged_df = res.json()
|
|
pang = int(merged_df["data"]['total']/20) + 1
|
|
for a in range(1,pang):
|
|
t = time.time()
|
|
ts = int(round(t * 1000))
|
|
randint = random.randint(100000000, 999999999)
|
|
req = f"{a}|20|{yes_time_nyr}|{yes_time_nyr}" + "_" + str(ts) + "_" + str(randint)
|
|
str_en = des_encrypt(req)
|
|
req_new = str_en.decode('utf-8')
|
|
|
|
url = f"http://manage.f6yc.com/hive-admin/py/yida/renewal/coupons/fetch"
|
|
data = {
|
|
'req':req_new,
|
|
't':ts,
|
|
'r':randint
|
|
}
|
|
res = requests.post(url,data=data)
|
|
merged_df = res.json()
|
|
# 遍历数据进行新建
|
|
for i in range(0,len(merged_df["data"]['list'])):
|
|
if merged_df["data"]['list'][i]["takeSourceCode"] == "yidaApproveAutoGrantCoupon":
|
|
ALL_formData = []
|
|
formData = {
|
|
'textField_llungzvc':merged_df["data"]['list'][i]['couponName'],#"券名称"
|
|
'numberField_llungzvf':merged_df["data"]['list'][i]['couponValue'],#"券金额"
|
|
'dateField_llxgj2t0':merged_df["data"]['list'][i]['validityBegin'],#"券有效期"
|
|
'dateField_llxgj2t1':merged_df["data"]['list'][i]['validityEnd'],#"券有效期"
|
|
'dateField_llungzvi':merged_df["data"]['list'][i]['takeTime'],#"发券时间"
|
|
'textField_llym1q8j':merged_df["data"]['list'][i]['createBy'],#"发券人id"
|
|
'textField_llym1q8k':merged_df["data"]['list'][i]['createName'],#"发券人姓名"
|
|
'textField_llungzvj':merged_df["data"]['list'][i]['customerGroupName'],#"领券人公司"
|
|
'textField_llungzvk':merged_df["data"]['list'][i]['cellPhone'],#"领券人手机号"
|
|
'textField_llungzvl':merged_df["data"]['list'][i]['conditionValue'],#"使用门槛"
|
|
'textField_llungzvm':str(merged_df["data"]['list'][i]['spuList']),#"适用商品"
|
|
'textField_llungzvn':"宜搭审批自动发劵",#"券来源"
|
|
}
|
|
try:
|
|
formData['employeeField_llungzvp'] = ALL_DATA_staff[merged_df["data"]['list'][i]['couponValue']]#"技术专家"
|
|
except:
|
|
formData['employeeField_llungzvp'] = ""
|
|
try:
|
|
formData['employeeField_llungzvh'] = ALL_DATA_staff[merged_df["data"]['list'][i]['createName']]#"发券人"
|
|
except:
|
|
formData['employeeField_llungzvh'] = "0627252740652855"
|
|
ALL_formData.append(json.dumps(formData, cls=NpEncoder))
|
|
FORMID = "FORM-A8666NA1BDNDLTRV6ASGDD4J2YMW3FHOGNULLE"
|
|
res_new = Batch_creation(FORMID,TOKEN,ALL_formData)
|
|
print(res_new)
|
|
time.sleep(1) |