from recommend import *
from recommend.publicFunc import skuinfo,dapanBu

def preconditions(uuid):
    '''
    :param uuid:
    :return: 判断上批次是否为加购topic,是则不触发，不是才触发
    '''
    back_batch_redis=""
    return True

def recall_J1(skuno):
    '''
    :param skuno:
    :return: 将所有的数据都召回，然后进行去重并选取100
    '''
    # graph_change_sql=concatSql(graph_relation_sql,**{"sku1_id":skuno})
    # graph_df=execmysl('7438_27',graph_change_sql)
    # temp= graph_df.sort_values(by='rank')['sku2_id'].to_list()[:100]
    # if len(set(100))>100:
    #     return removeRepeat(temp)[:100]
    # als_change_sql1=concatSql(als_sql,**{"product_id1":skuno})
    # als_df1=execmysl('7438_27',als_change_sql1)
    # temp+=als_df1.sort_values(by='rank')['product_id2'].to_list()
    # als_change_sql2=concatSql(als_sql,**{"product_id2":skuno})
    # als_df2=execmysl('7438_27',als_change_sql1)
    # temp+=als_df2.sort_values(by='rank')['product_id1'].to_list()
    # return removeRepeat(temp)[:100]
    temp=[]
    graph_change_redis=graph_redis.format(sku_no=skuno)
    graph_date=getRedisValue(graph_change_redis).get(graph_change_redis)
    als_change_redis=als_redis.format(sku_no=skuno)
    als_date=getRedisValue(als_change_redis).get(als_change_redis)
    temp+=graph_date
    temp+=als_date
    temp+=supply_J1(skuno)
    return temp



def supply_J1(skuno):
    sku_info=skuinfo(skuno)
    dapan_change_sql=concatSql(dapan_sql,**{"cid3":sku_info.get('cid3')})
    dapan_df=execmysl('7438_27',dapan_change_sql)
    temp=dapan_df[dapan_df['brand_name']!=sku_info.get('brand_name')]['sku_no'].to_list()
    temp=removeRepeat(temp)[:50]
    dapan_change1_sql=concatSql(dapan_sql,**{"brand_name":sku_info.get('brand_name')})
    dapan1_df=execmysl('7438_27',dapan_change1_sql)
    temp+=dapan_df[dapan_df['cid3']!=sku_info.get('cid3')]['sku_no'].to_list()
    return removeRepeat(temp)[:100]

def recall_J2():
    pass

def recall_J3():
    return dapanBu()


if __name__ == '__main__':
    print(recall_J1('12312'))
