from recommend import *

def online_intent_cid3(uuid='-999999',gid='-999999'):
    '''
    :param uuid:
    :param gid:
    :return: 用户实时cid3
    '''
    recommend_user_intent_change_sql=recommend_user_intent_sql.format(uuid,gid)
    df=execmysl('89',recommend_user_intent_change_sql)
    if df.empty:
        return []
    return df['intent_cid3'].astype(str).to_list()

def offine_intent_cid3(uuid='-999999',gid='-999999'):
    cold_start_user_history_cid3_intentions_change_sql=cold_start_user_history_cid3_intentions_sql.format(uuid,gid)
    df=execmysl('89',cold_start_user_history_cid3_intentions_change_sql)
    if df.empty:
        return []
    return df['cid3'].to_list()[:3]


def dapan():
    ##大盘补足
    timestamp=getRedisValue('89',cold_start_cid3_heat_intentions_timestamp_redis)
    if not timestamp:
        return []
    dapan_redis=cold_start_cid3_heat_intentions_redis.format(timestamp.get(cold_start_cid3_heat_intentions_timestamp_redis))
    dapan_cid3=getRedisValue('89',dapan_redis)
    return dapan_cid3.get(dapan_redis)[:3]

def main(uuid='-999999',gid='-999999'):
    online_cid3=online_intent_cid3(uuid,gid)
    print("实时意图召回80011:",online_cid3)
    offline_cid3=offine_intent_cid3(uuid,gid)
    print("离线意图召回80012:",offline_cid3)
    dapan_cid3=dapan()
    print("大盘意图召回80013:",dapan_cid3)
    cid3s=removeRepeat(online_cid3+offline_cid3+dapan_cid3)[:3]
    skus_change_sql=concatSql(skuinfo_sql,**{"cid3":cid3s})
    skus_df=execmysl('89',skus_change_sql)
    #print('最终的商品数据如下:',skus_df)
    return skus_df['sku_no'].to_list()


if __name__ == '__main__':
    uuid='1bb5268b-8cdb-4d98-8e24-37a39fc25235'
    gid=''
    #print(online_intent_cid3(uuid))
    print(main(uuid=uuid))

