# -*- coding:utf-8 -*-
"""
Author: qiaoxinjiu
Email: qiaoxinjiu@sparkedu.com
Create Date: 2026/01/22 5:58 下午
"""
import logging
import os
import sys

# 添加项目根目录到 Python 路径，以便导入 base_framework 模块
current_file_path = os.path.abspath(__file__)
project_root = os.path.abspath(os.path.join(os.path.dirname(current_file_path), '../../../../'))
if project_root not in sys.path:
    sys.path.insert(0, project_root)

from base_framework.public_tools import log
from base_framework.public_tools.my_faker import MyFaker
from base_framework.public_tools.runner import Runner
from base_framework.public_tools.pgsqlhelper import PgSqlHelper
from base_framework.public_tools import read_config
from base_framework.public_tools import utils
from base_framework.public_tools import mg_keyword
from zhyy.library.ZZYY_interface import ZhyyInterface

obj_get_log = log.get_logger()
obj_my_faker = MyFaker()
obj_runner = Runner()
obj_pgsql_helper = PgSqlHelper()
obj_get_way = utils.Tools()
obj_mg_keyword = mg_keyword.ManageKeyWord()


class PurchaseOrder(ZhyyInterface):
    def __init__(self):
        '''
        这个是针对于读取配置文件的初始化函数，用于读取默认参数
        '''
        super().__init__()
        self.config_index_path = os.path.dirname(os.path.abspath(__file__))
        self.config_index_filePath = os.path.join(self.config_index_path, "purchase.ini")
        self.config_index_content = read_config.ReadConfig(filename=self.config_index_filePath)

    def kw_zhyy_get_purchase_page_post(self, note, user, **kwargs):
        """
            | 功能说明： |  返回采购工作台采购单列表数据 |
            | 输入参数： | note | 注释 |
                        |user | 用户信息，传入 'purchase' 默认读取配置文件里面  'purchase' 对应的默认账号信息|
                        |supplier_company_ids | 供应商id | 非必填 
                        |payment_status | 付款状态 | 非必填 
                        |status | 采购单状态 | 非必填 
                        |order_sn | 采购单号 | 非必填 
                        |page_no | 页码 | 必填 
                        |page_size | 每页条数 | 必填 
            | 返回参数： |  {"success":true,"message":"success","code":200,"data":
            {'todoTask':['PO260116003','PO260115010'],'inProcessTask':['PO260116003','PO260115010']}} |  |
            | 作者信息： |  谯新久     |  修改时间  | 2022-8-20 |
        """
        logging.info("==========={0}===========".format(note))
        # 获取所有参数
        supplier_company_ids = kwargs.get("supplier_company_ids")
        payment_status = kwargs.get("payment_status")
        status = kwargs.get("status")
        order_sn = kwargs.get("order_sn")
        page_no = kwargs.get("page_no")
        page_size = kwargs.get("page_size")
        
        # 检查必填参数
        if not page_no or not page_size:
            raise Exception("页码和每页条数不能为空")
        
        # 组装参数字典，只包含非空字段，参数名使用 pageNo 和 pageSize
        request_params = {
            "pageNo": page_no,
            "pageSize": page_size
        }
        
        # 如果字段不为空，才添加到参数字典中
        if supplier_company_ids is not None and supplier_company_ids != "":
            request_params["supplier_company_ids"] = supplier_company_ids
        if payment_status is not None and payment_status != "":
            request_params["payment_status"] = payment_status
        if status is not None and status != "":
            request_params["status"] = status
        if order_sn is not None and order_sn != "":
            request_params["order_sn"] = order_sn
        
        # 使用 ** 方式解包字典传递参数
        get_todo_info = self.kw_in_zhyy_purchase_order_page_post(user=user, **request_params)
        print(get_todo_info if get_todo_info else "查询失败")
        return get_todo_info


if __name__ == '__main__':
    test = PurchaseOrder()
    a = test.kw_zhyy_get_purchase_page_post(user='purchase', note="测试", page_no=1, page_size=10)
    print(a)    
