import os

from flask_app.old_version.提取json工程标版_old import convert_clause_to_json
from flask_app.general.json_utils import extract_content_from_json
from flask_app.old_version.形式响应评审old import process_reviews
from flask_app.old_version.资格评审old_old import process_qualification
from flask_app.general.llm.通义千问long import upload_file, qianwen_long
from concurrent.futures import ThreadPoolExecutor


def combine_review_standards(truncate1,truncate3,knowledge_name,truncate0_jsonpath,clause_path,input_file,output_folder):   #评标办法前附表
    # 形式评审、响应评审:千问
    file_id=upload_file(truncate1)    #评标办法前附表
    user_query_1 = "根据该文档中的评标办法前附表，请你列出该文件中的形式评审标准和响应性评审标准和资格评审标准，请以json格式返回，外层键名为'形式评审标准'和'响应性评审标准'和'资格评审标准',嵌套键名为'评审因素'中的内容，相应的键值为对应'评审标准'中的内容。"
    results = qianwen_long(file_id, user_query_1)
    original_dict_data = extract_content_from_json(results)
    qualification_review = original_dict_data.pop('资格评审标准', '默认值或None')    #qianwen-long有关资格评审的内容
    with ThreadPoolExecutor() as executor:
        # 创建Future对象
        future_qualification = executor.submit(process_qualification, qualification_review, truncate3, knowledge_name)
        future_form_response = executor.submit(process_reviews, original_dict_data, knowledge_name, truncate0_jsonpath,
                                               clause_path,input_file,output_folder)

        # 等待执行结果
        final_qualify_json = future_qualification.result()
        form_response_dict = future_form_response.result()
    form_response_dict.update(final_qualify_json)
    # return nest_json_under_key(form_response_dict,"资格审查")
    return {"资格审查":form_response_dict}

if __name__ == "__main__":
    input_file="D:\\flask_project\\flask_app\\static\\output\\c02a12c2-6f7b-49dc-b97f-c3d740c96c21\\ztbfile.pdf"
    output_folder = "D:\\flask_project\\flask_app\\static\\output\\c02a12c2-6f7b-49dc-b97f-c3d740c96c21"
    # truncate0 = os.path.join(output_folder, "zbtest20_tobidders_notice_table.pdf")
    truncate2=os.path.join(output_folder,"ztbfile_tobidders_notice.pdf")
    knowledge_name="zbtest20"
    truncate1=os.path.join(output_folder,"ztbfile_evaluation_method.pdf")
    truncate3=os.path.join(output_folder,"ztbfile_qualification.pdf")
    clause_path = convert_clause_to_json(truncate2, output_folder)
    truncate0_jsonpath = os.path.join(output_folder, "truncate_output.json")
    res=combine_review_standards(truncate1,truncate3, knowledge_name,truncate0_jsonpath,clause_path,input_file,output_folder)
    print(res)