from Utils.sql_handler import test_env_conn from TestData.setting.notification_test_data import notifycationData team_id_select_sql = f'select id from `resource_item` where brand_id = {notifycationData.brandId} and resource_id = 1' team_id_select_result = test_env_conn.select_many_value(sql=team_id_select_sql) team_id = [team['id'] for team in team_id_select_result] team_cs_rel_select_sql = f'select * from `resource_item_cs_rel` where cs_id = {notifycationData.userId}' team_cs_rel_select_result = test_env_conn.select_many_value(sql=team_cs_rel_select_sql) if team_cs_rel_select_result: team_cs_rel_id = tuple([team['id'] for team in team_cs_rel_select_result]) 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 ({notifycationData.insert_team_name},'',0,{notifycationData.brandId},1,0,0,'2024-02-19 16:43:20','2024-02-19 16:43:20'); """ test_env_conn.execute_sql(sql=team_insert_sql) insert_team_id_select_sql = f'select id from `resource_item` where brand_id = {notifycationData.brandId} and resource_id = 1 and name = {notifycationData.insert_team_name}' insert_team_id_select_result = test_env_conn.select_one_value(sql=insert_team_id_select_sql) insert_team_id = insert_team_id_select_result['id'] team_cs_rel_insert_sql = f"""INSERT INTO `resource_item_cs_rel` (item_id,cs_id,sorts,is_hup,is_delete,update_at,create_at) VALUES ({insert_team_id},{notifycationData.userId},0,1,0,'2024-02-19 16:43:20','2024-02-19 16:43:20'); """ team_cs_rel_insert_result = test_env_conn.execute_sql(sql=team_cs_rel_insert_sql) team_cs_rel_id = (insert_team_id) room_select_sql = f""" select room_id from `im_room` where cate_id = {notifycationData.brandId} and site_id = {notifycationData.shopId} """ room_select_result = test_env_conn.select_many_value(sql=room_select_sql) if room_select_result: room_id = tuple([team['room_id'] for team in room_select_result]) else: room_insert_sql = f""" INSERT INTO `im_room` (room_id,title,room_type,cate_id,site_id,first_send_uid,first_send_uid_type,first_operation_uid,platform,allocation_uid,first_send_name,first_send_avatar,status,open_time,close_time,close_uid,is_mark,is_ignore,is_msg_reply,last_msg_time,last_msg_uid,last_msg_type,last_msg_uid_type,last_msg_context,allocation_name,allocation_avatar,room_platform,room_channel_type,from_id,channel_id,recipient_id,email_topic,ref_email_topic,session_id,create_at,update_at,read_status,third_create_time) VALUES ({notifycationData.insert_room_id},'',1,{notifycationData.brandId},{notifycationData.shopId},1,1,{notifycationData.userId},0,{notifycationData.userId},'Willdesk Team','',1,0,1714295061,{notifycationData.userId},0,0,1,1714295078362,{notifycationData.userId},11,2,'{"contentList":"0.24day关闭
","attachmentList":[]}','auto_test','https://img.willdesk.com/$','willdesk','wk','','','','','','',1708332200,1714295078,2,0); """ test_env_conn.execute_sql(sql=room_insert_sql) room_id = (notifycationData.insert_room_id) room_rel_select_sql = f'select * from `resource_room_rel` where room_id in {room_id} and item_id in {team_cs_rel_id}' room_rel_select_result = test_env_conn.select_one_value(sql=room_rel_select_sql) if room_rel_select_result: setattr(notifycationData, 'team_room_rel_id', room_rel_select_result['id']) else: setattr(notifycationData, 'no_team_room_rel_id', room_rel_select_result['id']) if hasattr(notifycationData, 'team_room_rel_id'): no_rel_room_select_sql = f'select * from '