from Utils.sql_handler import test_env_conn from TestData.setting.team_test_data import teamData team_select_sql = f'select * from `resource_item` where brand_id = {teamData.brandId} and resource_id = 1 and is_delete = 0' team_select_result = test_env_conn.select_many_value(sql=team_select_sql) if team_select_result: team_num = len(team_select_result) team_id_select_sql = f'select * from `resource_item` where brand_id = {teamData.brandId} and name = "{teamData.team_name}"' team_id_result = test_env_conn.select_one_value(sql=team_id_select_sql) if not team_id_result: team_insert_sql = f"""INSERT INTO resource_item (name,picture,rel_id,brand_id,resource_id,sorts,is_delete,update_at,create_at) VALUES ('{teamData.team_name}','',0,{teamData.brandId},1,0,0,'2024-05-11 15:47:45','2024-05-11 15:47:45'); """ test_env_conn.execute_sql(sql=team_insert_sql) team_id_select_sql = f'select * from `resource_item` where brand_id = {teamData.brandId} and name = "{teamData.team_name}"' team_id_result = test_env_conn.select_one_value(sql=team_id_select_sql) team_id = team_id_result['id'] else: team_id = team_id_result['id'] setattr(teamData, 'team_id', team_id) setattr(teamData, 'team_num', team_num) else: team_insert_sql = f"""INSERT INTO resource_item (name,picture,rel_id,brand_id,resource_id,sorts,is_delete,update_at,create_at) VALUES ('{teamData.team_name}','',0,{teamData.brandId},1,0,0,'2024-05-11 15:47:45','2024-05-11 15:47:45'); """ test_env_conn.execute_sql(sql=team_insert_sql) team_id_select_sql = f'select * from `resource_item` where brand_id = {teamData.brandId} and name = "{teamData.team_name}"' team_id_result = test_env_conn.select_one_value(sql=team_id_select_sql) team_id = team_id_result['id'] team_num = 1 setattr(teamData, 'team_id', team_id) setattr(teamData, 'team_num', team_num)