Exemple #1
0
def delete_product(product):
    """删除产品及产品相关信息"""
    product_id = product.get('_id')
    MongodbUtil.delete('shopping', 'product', product)
    logger.info('Delete a product: %s successfully!!!' % product.get('title'))
    #删除索引中product.id
    keyword_list = product.get('keywordList')
    for keyword in keyword_list:
        keyword = MongodbUtil.find_one('shopping', 'keywordIndex',
                                       {'keyword': keyword})
        if not keyword:
            continue
        if keyword['invertedIndex'].__contains__(product_id.__str__()):
            del keyword['invertedIndex'][product_id.__str__()]
            MongodbUtil.save('shopping', 'keywordIndex', keyword)
            logger.info('Update keyword index: %s successfully!!!' %
                        keyword.get('keyword'))
        #删除merchant中product.id
    merchant_id = product.get('merchantId')
    merchant = MongodbUtil.find_one('shopping', 'merchant',
                                    {'_id': merchant_id})
    index_id = merchant['productIdList'].index(product_id)
    if isinstance(index_id, int):
        del merchant['productIdList'][index_id]
    MongodbUtil.save('shopping', 'merchant', merchant)
    logger.info('Update merchant productIdList successfully!!!')
    #删除product的image及图片文件
    images = MongodbUtil.find('shopping', 'image', {'productId': product_id})
    for image in images:
        MongodbUtil.remove(filename=image.get('fileName'))
    MongodbUtil.delete('shopping', 'image', {'productId': product_id})
Exemple #2
0
def save_overdue_product(product_list):
    """保存过期产品到overdueProduct集合中"""
    update_count = 0
    insert_count = 0
    for product in product_list:
        product_id = product.get('_id')
        overdue_product_id = MongodbUtil.insert('shopping', 'overdueProduct',
                                                product)
        if overdue_product_id:
            insert_count += 1
            logger.info('Insert overdue product: %s successfully!!!' %
                        product.get('title'))
            #cpc统计数据转移至备份集合overdueCpc中后删除
        cpc_list = MongodbUtil.find('shopping', 'cpc',
                                    {'productId': product_id})
        save_overdue_cpc(overdue_product_id, product, cpc_list)
        MongodbUtil.delete('shopping', 'cpc', {'cpcProductId': product_id})
    logger.info('Update %s overdue product, Insert %s overdue product!!!' %
                (update_count, insert_count))