import datetime
starttime = datetime.datetime.now()

# -*- coding: utf-8 -*-
import psycopg2
import pandas as pd
from datetime import date, timedelta
# 获得连接
# conn = psycopg2.connect(database="f6_bi", user="BASIC$ro_caowei", password="!ro_caowei123", host="hgprecn-cn-nif1vnv0y002-cn-shanghai.hologres.aliyuncs.com", port="80")
conn = psycopg2.connect(database="f6_bi", user="LTAI5tMJsijFA9BS1R6uBpUT", password="PajEQMIRWNRcipd8mYvlud2KHWJr6N", host="hgpostcn-cn-m1e4gikbu00l-cn-shanghai.hologres.aliyuncs.com", port="80")

# 获得游标对象，一个游标对象可以对数据库进行执行操作
cursor = conn.cursor()

import datetime
now_time = datetime.datetime.now()
yes_time = now_time + datetime.timedelta(days=-2)
yes_time_nyr = int(yes_time.strftime('%Y%m%d'))# 获取前一天日期

today = date.today()
days_to_add = 120
future_date = str(today + timedelta(days=days_to_add))
# 输出结果
print("距离今天还有{}天的日期是：{}".format(days_to_add, future_date))
# sql语句 建表
sql =f"""SELECT * FROM "public"."holo_ads_report_saas_profile_ngv_detail_d" WHERE "date_id" = '{yes_time_nyr}' and "expiry_time" like '%{future_date}%';"""
# 执行语句
cursor.execute(sql)
# 获取结果集的每一行
rows = cursor.fetchall()
# 获取所有字段名
all_fields = cursor.description
#执行结果转化为dataframe
col = []
for i in all_fields:
    col.append(i[0])
data_NGV = pd.DataFrame(list(rows),columns=col)
# data_NGV.to_excel(r'C:\Users\admin\Desktop\NGV明细.xlsx')
# 关闭数据库连接
cursor.close()
conn.close()

# 基础函数配置
import pandas as pd
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()  # 当前工作目录
textField_lrzoowld = "正常" # 运行状态
textField_lrzoowlb = "" # 信息说明
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 read_instances(token, formUuid, page, n):
    """ 函数功能：读取普通表单的所有数据 """

    api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'

    headers = {
        "Content-Type": "application/json.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_delete(token, formInstanceId):
    """ 函数功能：调用本接口删除表单数据。 """

    api = f'https://api.dingtalk.com//v1.0/yida/forms/instances'

    headers = {
        "Content-Type": "application/json.json",
        "x-acs-dingtalk-access-token": token
    }

    formData = {
  "appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
  "systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
  "userId" : "yida_pub_account",
  "language" : "zh_CN",
  "formInstanceId" : formInstanceId
    }

    res = requests.delete(api, headers=headers, json=formData)
    return res.json()

def read_new(FORMID,formData):
    """ 通过实例id 获取表单内容   """
    api = f'https://api.dingtalk.com/v1.0/yida/forms/instances'

    headers = {
        "Content-Type": "application/json.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.post(api, headers=headers, json=payload)
    print(res.json())

    return res.json()

def component(FORMID,TOKEN):
    """ 获取组件信息   """
    api = f'https://api.dingtalk.com//v1.0/yida/forms/formFields'

    headers = {
        "Content-Type": "application/json.json",
        "x-acs-dingtalk-access-token": TOKEN
    }
    payload = {
        "formUuid" : FORMID,
        "appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
        # "formDataJson" : json.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 initiate_process(TOKEN,formData):
    """ 发起宜搭审批流程   """
    api = f'https://api.dingtalk.com//v1.0/yida/processes/instances/start'

    headers = {
        "Content-Type": "application/json.json",
        "x-acs-dingtalk-access-token": TOKEN
    }
    payload = {
        "appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
        "systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
        "userId" : "yida_pub_account",
        "language" : "zh_CN",
        "formUuid" : "FORM-PE866MD1MJMU0WGLYRFLYEN5YN9L1I55Z7ZUK22",
        "formDataJson" : json.dumps(formData, cls=NpEncoder),
        "processCode" : "TPROC--PE866MD1MJMU0WGLYRFLYEN5YN9L1885Z7ZUK32",
        }

    res = requests.post(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.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.json",
        "x-acs-dingtalk-access-token": TOKEN
    }
    res = requests.delete(api, headers=headers)
    return res.json()

def read_instances_ngv(token, formUuid, page, n,searchField):
    """ 函数功能：读取普通表单的所有数据 """

    api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'

    headers = {
        "Content-Type": "application/json.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),
        "currentPage" : page,
        "pageSize" : n
    }

    res = requests.post(api, headers=headers, json=formData)
    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)
        
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)


def des_descrypt(s):
    """
    DES 解密
    :param s: 加密后的字符串，16进制
    :return:  解密后的字符串
    """
    secret_key = 'HwdMBW8o'
    iv = secret_key
    k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
    de = k.decrypt(binascii.a2b_base64(s), padmode=PAD_PKCS5)
    return de

TOKEN = generateToken()     
'''读取省市小六技术专家区域客服区域客成 '''
FORMID = "FORM-8C7E8036770B495D99862638F87FA8BFOEEN"  #省市小六技术专家区域客服区域客成
try:
    # 读取流程表单数据
    form_data = read_instances(token=TOKEN, formUuid=FORMID, page=1, n=100)
    PAGES = form_data.get('totalCount')//100 + 1
    textField_gif29wy = {}
    textField_3athky8 = {}
    textField_3hgho1m = {}
    textField_nc7gskc = {}
    """  获取全量数据  """
    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'):
            textField_gif29wy[data['formData']['textField_m3hchxc']]=data['formData']['textField_gif29wy'] #区域客成id  # 根据市做判断
            textField_3athky8[data['formData']['textField_m3hchxc']]=data['formData']['textField_3athky8'] #区域客服id
            # textField_3hgho1m[data['formData']['textField_3hgho1m']]=data['formData']['textField_3hgho1m'] #小六id
            # textField_nc7gskc[data['formData']['textField_nc7gskc']]=data['formData']['textField_nc7gskc'] #技术专家id
    print(f'读取到省市小六技术专家区域客服区域客成表单中 {len(textField_gif29wy)} 条数据！')


    '''遍历数据进行新建'''
    data_NGV = data_NGV.astype('string')
    data_NGV = data_NGV.fillna('',inplace=False)
    group_grade = {
        "普通客户（VIP）":10,
        "重要客户（SVIP）":20,
        "区域KA（MVP）":30,
        "全国KA（FMVP）":50
    }
    # 过滤数据
    for i in range(0,len(data_NGV["date_fmt"])):
        try:
            t = time.time()
            ts = int(round(t * 1000))
            randint = random.randint(100000000, 999999999)
            req = data_NGV['id_own_org'][i] + "_" + 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/orgInfo"
            data = {
                'req':req_new,
                't':ts,
                'r':randint
            }

            res = requests.post(url,data=data)
            formData = res.json()['data']['yidaFormData']
            # 过期日期的时间戳
            expire_timestamp = int(formData['dateField_ksirro5l'])/1000

            # 获取距离过期日期前120天，前90天，前60天，前30天的日期
            expire_date = datetime.datetime.fromtimestamp(expire_timestamp)
            before_90_days = expire_date - datetime.timedelta(days=90)
            before_60_days = expire_date - datetime.timedelta(days=60)
            before_30_days = expire_date - datetime.timedelta(days=30)
            # print(formData)
            formData['dateField_ljzefdm4'] = str(int(before_90_days.timestamp()*1000)) # 90天限制日期
            formData['dateField_ljzefdm5'] = str(int(before_60_days.timestamp()*1000)) # 60天限制日期
            formData['dateField_ljzefdm6'] = str(int(before_30_days.timestamp()*1000)) # 30天限制日期


            employeeField_kykw5ege = str(formData['employeeField_kykw5ege'])
            employeeField_ksydghrd = str(formData['employeeField_ksydghrd'])
            formData['employeeField_ljz6gvwc'] = f"['{textField_gif29wy[formData['textField_kuj8nx01']]}', '{textField_3athky8[formData['textField_kuj8nx01']]}']" # 区域客成+区域客服
            # formData['employeeField_ljz6416i'] = f"[{textField_gif29wy[formData['textField_kuj8nx01']]}, {employeeField_kykw5ege}]" # 区域客成+小六
            formData['employeeField_ljz6416i'] = f"['{textField_gif29wy[formData['textField_kuj8nx01']]}', '{employeeField_kykw5ege}']" # 区域客成+小六
            formData['employeeField_ljz6416j'] = f"['{textField_gif29wy[formData['textField_kuj8nx01']]}', '{employeeField_ksydghrd}']" # 区域客成+技术专家
            formData['employeeField_ljz6gvwd'] = textField_3athky8[formData['textField_kuj8nx01']] # 区域客服
            formData['employeeField_ksydght0'] = textField_gif29wy[formData['textField_kuj8nx01']] # 区域客成

            if employeeField_kykw5ege =="1824534815658365" or employeeField_kykw5ege =="0627252740652855": 
                if employeeField_ksydghrd =="":
                    employeeField_kykw5ege = '0627252740652855'
                    formData['employeeField_ljz6gvwc'] = '0627252740652855' # 区域客成+区域客服
                    formData['employeeField_ljz6416i'] = '0627252740652855' # 区域客成+小六
                    formData['employeeField_ljz6416j'] = '0627252740652855' # 区域客成+技术专家
                    formData['employeeField_ljz6gvwd'] = '0627252740652855' # 区域客服
                    formData['employeeField_ksydght0'] = '0627252740652855' # 区域客成
                    formData['employeeField_kykw5ege'] = '0627252740652855' # 专属运营顾问
                    formData['employeeField_ksirro5o'] = '0627252740652855' # 续约绩效归属人
                else:
                    employeeField_kykw5ege = employeeField_ksydghrd
                    formData['employeeField_ljz6gvwc'] = employeeField_ksydghrd # 区域客成+区域客服
                    formData['employeeField_ljz6416i'] = employeeField_ksydghrd # 区域客成+小六
                    formData['employeeField_ljz6416j'] = employeeField_ksydghrd # 区域客成+技术专家
                    formData['employeeField_ljz6gvwd'] = employeeField_ksydghrd # 区域客服
                    formData['employeeField_ksydght0'] = employeeField_ksydghrd # 区域客成
                    formData['employeeField_kykw5ege'] = employeeField_ksydghrd # 专属运营顾问
                    formData['employeeField_ksirro5o'] = employeeField_ksydghrd # 续约绩效归属人
            if formData['textField_kycfic6o'] == "区域KA（MVP）" or formData['textField_kycfic6o'] == "全国KA（FMVP）":
                formData['employeeField_ljz6gvwc'] = f"['{employeeField_kykw5ege}', '{employeeField_ksydghrd}']" # 小六+技术专家
                formData['employeeField_ljz6416i'] = f"['{employeeField_kykw5ege}', '{employeeField_ksydghrd}']" # 小六+技术专家
                formData['employeeField_ljz6416j'] = f"['{employeeField_kykw5ege}', '{employeeField_ksydghrd}']" # 小六+技术专家
                formData['employeeField_ljz6gvwd'] = f"['{employeeField_kykw5ege}', '{employeeField_ksydghrd}']" # 小六+技术专家
            try:
                formData['textField_ksirro5g'] = group_grade[data_NGV['group_grade'][i]]
                formData['textField_kycfic6o'] = data_NGV['group_grade'][i]
            except:
                pass
            try:
                formData['textField_liwg9trm'] = res.json()['data']['franchiseGroupInfo']['groupName']
            except:
                pass
            # 富文本 超链接 NGV
            try:
                form_data_ngv = read_instances_ngv(token=TOKEN, formUuid="FORM-ZK866D91O9LA4NIHCARG2DPIPCXF3Z087PPHL91", page=1, n=100, searchField={'textField_l8nc9f2': data_NGV['id_own_org'][i]})
                formData['editorField_m3gn517y'] = ["root",{},["p",{},["span",{"data-type":"text"},["span",{"data-type":"leaf"},""]],["a",{"href":"https://f6car.aliwork.com/APP_UYZ0KG6L0CCNV80GZ66O/formDetail/FORM-ZK866D91O9LA4NIHCARG2DPIPCXF3Z087PPHL91?formInstId="+form_data_ngv['data'][0]['formInstanceId']+"&isAdmin=true"},["span",{"data-type":"text"},["span",{"unlink":{},"data-type":"leaf"},"点击查看门店NGV"]]],["span",{"data-type":"text"},["span",{"unlink":{},"data-type":"leaf"},""]]]] # 富文本 超链接 NGV
            except:
                pass
            res_new = initiate_process(TOKEN,formData)
            time.sleep(2)
            print(res_new)

            # 回传信息-------------------------------------------------------------------------------------------------------------
            default_new = True
            a_len = 1
            while default_new:
                t = time.time()
                ts = int(round(t * 1000))
                randint = random.randint(100000000, 999999999)
                req = res_new['result'] + "|" + formData['textField_kuntp6fk'] + "|" + formData['textField_kuntp6fl']+ "|" + formData['employeeField_kykw5ege'] + "_" + str(ts) + "_" + str(randint)
                str_en = des_encrypt(req)
                print(str_en.decode('utf-8'))
                req_new = str_en.decode('utf-8')
                url = f"http://manage.f6yc.com/hive-admin/py/yida/renewal/insertRenewalFormsData"
                data = {
                    'req':req_new,
                    't':ts,
                    'r':randint
                }
                res = requests.post(url,data=data)
                res.json()
                
                if res.json()['message'] == "SUCCESS":
                    default_new = False
                a_len = a_len + 1
                if a_len > 5:
                    default_new = False
                time.sleep(1)
            '''校验是否新建正常'''
            FORMID = "FORM-L8966281PTZA73CDBTGQBDLM628M2P4X1OYHL0" 

            if a_len < 5:
                print("数据新建成功！")
            else:
                def start_instance_process(token: str, name):

                    """发送宜搭表单 -- 发起流程表单

                    Args:
                        token 
                        data:需要发送的数据字典
                    """

                    yida_api = "https://api.dingtalk.com/v1.0/yida/processes/instances/start"

                    headers = {
                        "Content-Type": "application/json.json",
                        "x-acs-dingtalk-access-token": token
                    }

                    send_data = {
                        "textField_l9fe0uiw": name,
                        "textField_l9fe0uiv": name
                    }

                    payload = {
                        "appType": "APP_TNVBVZ3K8G56HG03Z45Q",
                        "systemToken": "CH7669818R0WN18TYTYJ42PE6GY22WZN0BYWKD1",
                        "userId": "yida_pub_account",# 超级管理员账号
                        "language": "zh_CN",
                        "formUuid": "FORM-UX866Q61GNLAZBCIEDF77BGVIIR83K82WYPHLH2",
                        "formDataJson": json.dumps(send_data),
                        "processCode":"TPROC--UX866Q61GNLAZBCIEDF77BGVIIR83M92WYPHLI2"
                    }

                    res = requests.post(yida_api, headers=headers, json=payload)
                    return res
                try:
                    name = f"[流程]续约服务流程 新建后接口回传失败，请检查！{data_NGV['id_own_org'][i]}"
                    res_yujing = start_instance_process(TOKEN,name)
                except:
                    textField_lrzoowld = "异常" # 运行状态
                    textField_lrzoowlb = "[流程]续约服务流程 新建后接口回传失败，请检查" # 信息说明
        except:
            '''校验是否新建正常'''
            FORMID = "FORM-L8966281PTZA73CDBTGQBDLM628M2P4X1OYHL0" 
            def start_instance_process(token: str, name):

                """发送宜搭表单 -- 发起流程表单

                Args:
                    token 
                    data:需要发送的数据字典
                """

                yida_api = "https://api.dingtalk.com/v1.0/yida/processes/instances/start"

                headers = {
                    "Content-Type": "application/json.json",
                    "x-acs-dingtalk-access-token": token
                }

                send_data = {
                    "textField_l9fe0uiw": name,
                    "textField_l9fe0uiv": name
                }

                payload = {
                    "appType": "APP_TNVBVZ3K8G56HG03Z45Q",
                    "systemToken": "CH7669818R0WN18TYTYJ42PE6GY22WZN0BYWKD1",
                    "userId": "yida_pub_account",# 超级管理员账号
                    "language": "zh_CN",
                    "formUuid": "FORM-UX866Q61GNLAZBCIEDF77BGVIIR83K82WYPHLH2",
                    "formDataJson": json.dumps(send_data),
                    "processCode":"TPROC--UX866Q61GNLAZBCIEDF77BGVIIR83M92WYPHLI2"
                }

                res = requests.post(yida_api, headers=headers, json=payload)
                return res
            try:
                name = f"[流程]续约服务流程 未成功新建，请检查！{data_NGV['id_own_org'][i]}"
                res_yujing = start_instance_process(TOKEN,name)
                textField_lrzoowld = "异常" # 运行状态
                textField_lrzoowlb = "[流程]续约服务流程 未成功新建，请检查" # 信息说明
            except:
                pass
except:
    '''校验是否新建正常'''
    FORMID = "FORM-L8966281PTZA73CDBTGQBDLM628M2P4X1OYHL0" 
    def start_instance_process(token: str, name):

        """发送宜搭表单 -- 发起流程表单

        Args:
            token 
            data:需要发送的数据字典
        """

        yida_api = "https://api.dingtalk.com/v1.0/yida/processes/instances/start"

        headers = {
            "Content-Type": "application/json.json",
            "x-acs-dingtalk-access-token": token
        }

        send_data = {
            "textField_l9fe0uiw": name,
            "textField_l9fe0uiv": name
        }

        payload = {
            "appType": "APP_TNVBVZ3K8G56HG03Z45Q",
            "systemToken": "CH7669818R0WN18TYTYJ42PE6GY22WZN0BYWKD1",
            "userId": "yida_pub_account",# 超级管理员账号
            "language": "zh_CN",
            "formUuid": "FORM-UX866Q61GNLAZBCIEDF77BGVIIR83K82WYPHLH2",
            "formDataJson": json.dumps(send_data),
            "processCode":"TPROC--UX866Q61GNLAZBCIEDF77BGVIIR83M92WYPHLI2"
        }

        res = requests.post(yida_api, headers=headers, json=payload)
        return res
    try:
        name = f"[流程]续约服务流程 表单数据读取失败，请检查！{data_NGV['id_own_org'][i]}"
        res_yujing = start_instance_process(TOKEN,name)
    except:
        textField_lrzoowld = "异常" # 运行状态
        textField_lrzoowlb = "[流程]续约服务流程 表单数据读取失败，请检查" # 信息说明

try:
    import requests
    import json
    import numpy as np
    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 start_instance_process(token: str, send_data):

        """发送宜搭表单 -- 发起流程表单

        Args:
            token 
            data:需要发送的数据字典
        """

        yida_api = "https://api.dingtalk.com/v1.0/yida/processes/instances/start"

        headers = {
            "Content-Type": "application/json.json",
            "x-acs-dingtalk-access-token": token
        }

        payload = {
            "appType": "APP_TNVBVZ3K8G56HG03Z45Q",
            "systemToken": "CH7669818R0WN18TYTYJ42PE6GY22WZN0BYWKD1",
            "userId": "yida_pub_account",# 超级管理员账号
            "language": "zh_CN",
            "formUuid": "FORM-96D58EF2219240C7B1F55F9CA463CD2D4MGC",
            "formDataJson": json.dumps(send_data),
            "processCode":"TPROC--5Q966D918T1I1AZM68NASC6TS13P3QOL3PZRLC"
        }

        res = requests.post(yida_api, headers=headers, json=payload)
        return res
    
    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)
    '''校验是否正常运行'''
    TOKEN = generateToken()    
    import datetime
    endtime = datetime.datetime.now()
    implement = (endtime - starttime).seconds    
    send_data = {
            "textField_ls01al4o": implement,  #运行耗时
            "textField_lrzoowl8": "yida_xuyuedaiban_paifa",  # 程序名称
            "textField_lrzoowl9": "每天早上9点重新派发续约跟进任务",  # 功能简述
            "textField_lrzoowld": textField_lrzoowld,  # 运行状态
            "textField_lrzoowlb": textField_lrzoowlb   # 信息说明
        }
    res_yujing = start_instance_process(TOKEN,send_data)
except:
    pass


