# 标准库
import os
import time
import random
import json
import binascii
from datetime import date, timedelta, datetime
from urllib.parse import quote
from pathlib import Path

# 第三方库
import numpy as np
import pandas as pd
import requests
from pyDes import des, CBC, PAD_PKCS5
import mysql.connector
from mysql.connector import Error
import psycopg2

# 自定义模块
from config import Config
from api import API
from back_ground_module import CommonModule
from log_config import configure_task_logger, configure_error_task_logger

logger = configure_task_logger()
error_task_logger = configure_error_task_logger()
api_instance = API()
common_module = CommonModule()
output_dir = "output"  # 设置输出目录
os.makedirs(output_dir, exist_ok=True)

class RenewalToDo:
    def __init__(self):
        self.json_list = None
        self.data_NGV = None
        self.staff_id_list = None
        self.NGV_data_list = None


    def load_all_data(self):
        # 获取NGV数据
        payload = {"api_key": "675b900991ad2491c69389ca", "entry_id": "675bb02bd2d53c2034c665e4"}
        self.NGV_data_list = api_instance.entry_data_list(payload).get("data")

        # 获取简道云员工id
        payload = {"api_key": "6694d3c4fcb69ca9a111a6c4",
                   "entry_id": "6769204a1902c9341340a1bc",
                   }
        staff_id = api_instance.entry_data_list(payload)
        self.staff_id_list = staff_id.get("data")  # api请求格式，将数据封装在data字典里

        # 省市区人员关系表
        payload = {"api_key": "675b900991ad2491c69389ca", "entry_id": "676512ac3e54dc3159460c0a"}
        json_dict = api_instance.entry_data_list(payload)
        if json_dict and "data" in json_dict:
            self.json_list = json_dict.get("data")
        else:
            print("加载省市区人员关系表失败")
            self.json_list = []
            
        # 数据库获取续约回访数据
        self.data_NGV = common_module.get_renewal_details()

    def process_data(self):
        """

        :return:
        """


    def main(self):
        task_start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        try:
            logger.info("任务开始")
            # step1: 获取数据
            self.load_all_data()
            logger.info("加载数据完成")
            # step2:数据处理
            self.process_data()

            common_module.send_task_status(task_start_time, "续约回访待办")
        except Exception as e:
            error_task_logger.error(f"续约回访待办发生错误{e}")
            common_module.send_task_error(task_start_time, "续约回访待办", str(e))


if __name__ == '__main__':
    RenewalToDo().main()
