# -*- coding: utf-8 -*-
# @Time    : 2024/6/7
# @Author  : 魏志亮

from service.common_connect import plt


def get_wind_info(field_code, need_rated_param=True):
    query_sql = """
    SELECT t.engine_code,t.engine_name,t.rated_capacity,a.rated_cut_out_windspeed 
    from wind_engine_group t LEFT JOIN wind_engine_mill a on t.mill_type_code  = a.mill_type_code 
    where t.field_code = %s and t.del_state = 0
    """
    dict_datas = plt.execute(query_sql, (field_code,))
    wind_result = dict()
    power_result = dict()
    for data in dict_datas:
        wind_result[str(data['engine_name'])] = str(data['engine_code'])
        if need_rated_param:
            power_result[str(data['engine_code'])] = (
                float(data['rated_capacity']), float(data['rated_cut_out_windspeed']))
    return wind_result, power_result


def get_all_wind():
    query_sql = """
    SELECT t.code_number,t.code_name from wind_relation t where t.type = 'field' 
    """
    return plt.execute(query_sql)


def get_all_wind_by_company_code(company_code):
    query_sql = f"""
    SELECT t.code_number,t.code_name from wind_relation t where t.parent_code = '{company_code}' and t.type = 'field' 
    """
    datas = plt.execute(query_sql)
    result = dict()
    for data in datas:
        result[data['code_number']] = str(data['code_name'])

    return result


if __name__ == '__main__':
    print(get_all_wind_by_company_code('COM00002'))
