脚本
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2716\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<ipython-input-2-52524a399767>:162: UserWarning: Pandas requires version '1.4.3' or newer of 'xlsxwriter' (version '1.3.8' currently installed).\n",
|
||||
" df_data.to_excel(r\"C:\\Users\\admin\\Desktop\\新签节点化待办审批明细0803.xlsx\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 基础信息\n",
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import requests\n",
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
"import re\n",
|
||||
"import sys\n",
|
||||
"from datetime import datetime\n",
|
||||
"from dateutil.relativedelta import relativedelta\n",
|
||||
"from pathlib import Path\n",
|
||||
"from urllib.parse import quote\n",
|
||||
"from datetime import date, timedelta\n",
|
||||
"import datetime\n",
|
||||
"from io import BytesIO\n",
|
||||
"\n",
|
||||
"ROOT = Path('.').absolute() # 当前工作目录\n",
|
||||
"\n",
|
||||
"def generateToken() -> str:\n",
|
||||
" \"\"\" 生成 token \"\"\"\n",
|
||||
"\n",
|
||||
" token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'\n",
|
||||
"\n",
|
||||
" # 该信息在钉钉开放应用中\n",
|
||||
" data = {\n",
|
||||
" \"appKey\": \"ding5kqocon5s9oph5uq\",\n",
|
||||
" \"appSecret\": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" res = requests.post(token_api, json=data)\n",
|
||||
" token = res.json()['accessToken']\n",
|
||||
"\n",
|
||||
" return token\n",
|
||||
"\n",
|
||||
"def read_processes_instances(token, formUuid, page, n):\n",
|
||||
" \"\"\" 函数功能:读取流程表单的所有数据 \"\"\"\n",
|
||||
"\n",
|
||||
" api = f'https://api.dingtalk.com/v1.0/yida/processes/instances?pageNumber={page}&pageSize={n}'\n",
|
||||
"\n",
|
||||
" headers = {\n",
|
||||
" \"Content-Type\": \"application/json\",\n",
|
||||
" \"x-acs-dingtalk-access-token\": token\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" formData = {\n",
|
||||
" \"appType\": \"APP_UYZ0KG6L0CCNV80GZ66O\",\n",
|
||||
" \"systemToken\": \"XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2\",\n",
|
||||
" \"userId\": \"yida_pub_account\", # 超级管理员账号\n",
|
||||
" \"language\": \"zh_CN\",\n",
|
||||
" \"formUuid\": formUuid,\n",
|
||||
" # \"searchFieldJson\": json.dumps(searchField), # 如果增加上这一项会要求升级宜搭存储\n",
|
||||
" # \"instanceStatus\": \"RUNNING\" # 运行中\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" res = requests.post(api, headers=headers, json=formData)\n",
|
||||
" return res.json()\n",
|
||||
"\n",
|
||||
"def read_processes(token, formUuid, page, n):\n",
|
||||
" \"\"\" 函数功能:读取普通表单的所有数据 \"\"\"\n",
|
||||
"\n",
|
||||
" api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'\n",
|
||||
"\n",
|
||||
" headers = {\n",
|
||||
" \"Content-Type\": \"application/json\",\n",
|
||||
" \"x-acs-dingtalk-access-token\": token\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" formData = {\n",
|
||||
" \"appType\": \"APP_UYZ0KG6L0CCNV80GZ66O\",\n",
|
||||
" \"systemToken\": \"XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2\",\n",
|
||||
" \"userId\": \"yida_pub_account\", # 超级管理员账号\n",
|
||||
" \"language\": \"zh_CN\",\n",
|
||||
" \"formUuid\": formUuid,\n",
|
||||
" 'currentPage':page,\n",
|
||||
" 'pageSize':n\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" res = requests.post(api, headers=headers, json=formData)\n",
|
||||
" return res.json()\n",
|
||||
"\n",
|
||||
"def get_approval_records(token: str, processInstanceId: str):\n",
|
||||
" \"\"\" 函数功能:获取流程表单的审批记录 --F6客户服务 应用 \"\"\"\n",
|
||||
" appType = \"APP_UYZ0KG6L0CCNV80GZ66O\"\n",
|
||||
" systemToken = \"XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2\"\n",
|
||||
" userId = \"yida_pub_account\"\n",
|
||||
"\n",
|
||||
" api = f'https://api.dingtalk.com/v1.0/yida/processes/operationRecords?appType={appType}&systemToken={systemToken}&userId={userId}&language=zh_CN&processInstanceId={processInstanceId}'\n",
|
||||
"\n",
|
||||
" headers = {\n",
|
||||
" \"Content-Type\": \"application/json\",\n",
|
||||
" \"x-acs-dingtalk-access-token\": token\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" res = requests.get(api, headers=headers)\n",
|
||||
" # print('获取流程表单的审批记录')\n",
|
||||
" return res.json()\n",
|
||||
"def get_staffID(TOKEN: str,ALL_DATA_staff,staff_name):\n",
|
||||
" res_new = [v['formData']['textField_lfrw3u59'] for v in ALL_DATA_staff if v['formData']['textField_lfrw3u58']== staff_name]\n",
|
||||
" # print('通过员工名称获取员工id')\n",
|
||||
" return res_new\n",
|
||||
"\n",
|
||||
"def aggree_approval(token: str, taskId: str, processInstanceId: str, formData: dict,res_new):\n",
|
||||
" \"\"\" 函数功能:同意审批节点 --F6客户服务 应用 \"\"\"\n",
|
||||
" api = f'https://api.dingtalk.com/v1.0/yida/tasks/execute'\n",
|
||||
"\n",
|
||||
" headers = {\n",
|
||||
" \"Content-Type\": \"application/json\",\n",
|
||||
" \"x-acs-dingtalk-access-token\": token\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" payload = {\n",
|
||||
" \"outResult\": \"AGREE\",\n",
|
||||
" \"appType\": \"APP_UYZ0KG6L0CCNV80GZ66O\",\n",
|
||||
" \"systemToken\": \"XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2\",\n",
|
||||
" \"remark\": \"同意(接口自动)\",\n",
|
||||
" \"formDataJson\": json.dumps(formData, cls=NpEncoder),\n",
|
||||
" \"processInstanceId\": processInstanceId,\n",
|
||||
" # \"userId\": \"yida_pub_account\",\n",
|
||||
" \"userId\": res_new, \n",
|
||||
" \"language\": \"zh_CN\",\n",
|
||||
" \"taskId\": int(taskId)\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" res = requests.post(api, headers=headers, json=payload)\n",
|
||||
" # print('同意审批节点')\n",
|
||||
" return res\n",
|
||||
"\n",
|
||||
"class NpEncoder(json.JSONEncoder):\n",
|
||||
" def default(self, obj):\n",
|
||||
" if isinstance(obj, np.integer):\n",
|
||||
" return int(obj)\n",
|
||||
" elif isinstance(obj, np.floating):\n",
|
||||
" return float(obj)\n",
|
||||
" elif isinstance(obj, np.ndarray):\n",
|
||||
" return obj.tolist()\n",
|
||||
" else:\n",
|
||||
" return super(NpEncoder, self).default(obj)\n",
|
||||
"\n",
|
||||
"\"\"\" 处理流程开始 \"\"\"\n",
|
||||
"TOKEN = generateToken()\n",
|
||||
"FORMID = \"FORM-L89662816B04LXH893M4K50Q7MIZ1SVQI08ALU2\" # 读取新签节点化服务待办\n",
|
||||
"# 读取新签节点化服务待办\n",
|
||||
"form_data = read_processes_instances(token=TOKEN, formUuid=FORMID, page=1, n=100)\n",
|
||||
"print(form_data.get('totalCount'))\n",
|
||||
"PAGES = form_data.get('totalCount')//100 + 1\n",
|
||||
"df_data = pd.DataFrame(columns=['showName', 'operatorName','action', 'operateTimeGMT','remark'])\n",
|
||||
"\"\"\" 获取全量数据 \"\"\"\n",
|
||||
"for i in range(1, PAGES+1): # PAGES+1\n",
|
||||
" form_data = read_processes_instances(token=TOKEN, formUuid=FORMID, page=i, n=100)\n",
|
||||
" for v in range(0,len(form_data.get('data'))):\n",
|
||||
" # 获取当前所处节点\n",
|
||||
" res_new = get_approval_records(token=TOKEN, processInstanceId=form_data['data'][v]['processInstanceId'])\n",
|
||||
" records_new = res_new.get('result')\n",
|
||||
" for a in range(0,len(records_new)):\n",
|
||||
" try:\n",
|
||||
" try:\n",
|
||||
" df_data = df_data._append({'showName': records_new[a]['showName'], 'operatorName': records_new[a]['operatorName'], 'action': records_new[a]['action'], 'operateTimeGMT': records_new[a]['operateTimeGMT'], 'processInstanceId': records_new[a]['processInstanceId'],'remark': records_new[a]['remark']}, ignore_index=True)\n",
|
||||
" except:\n",
|
||||
" df_data = df_data._append({'showName': records_new[a]['showName'], 'operatorName': records_new[a]['operatorName'], 'action': records_new[a]['action'], 'operateTimeGMT': records_new[a]['operateTimeGMT'], 'processInstanceId': records_new[a]['processInstanceId']}, ignore_index=True)\n",
|
||||
" except:\n",
|
||||
" pass\n",
|
||||
"df_data.to_excel(r\"C:\\Users\\admin\\Desktop\\新签节点化待办审批明细0803.xlsx\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "F6processing",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.4"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user