http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3918|回复: 3

[咨询站长] 关于取消收藏的功能

[复制链接]
发表于 2015-5-13 10:34:11 | 显示全部楼层 |阅读模式
10金钱
你好,我想做一个功能是这样的:
前台遍历显示的是所有产品列表,用户登录后可以收藏某个喜欢的产品,但是收藏后客户要求这个产品被收藏了就不能显示出来了,但是前台是遍历显示的产品。该怎么做??我用的是JAVA,贴上一些代码。
public static long collectBid(long userId, long bidId, ErrorInfo error) {
        error.clear();
         
        error.code = isCollect(userId, bidId);
        
        /* 表示已经收藏,或异常 */
        if (error.code == Constants.COLLECT) {
            error.code = -1;
            error.msg = "标已收藏!";
            
            return -1;
        }
        
        long bidUserId = 0l;
        
        try {
            bidUserId = t_bids.find("select user_id from t_bids where id = ?", bidId).first();
        } catch (Exception e) {
            Logger.error("标->收藏某个标:" + e.getMessage());
            error.code = -2;
            error.msg = "收藏失败!";
            
            return -1;
        }
        
        if(bidUserId == userId){
            error.code = -3;
            error.msg = "您不能收藏自己发布的借款标!";
            
            return -1;
        }
        
        t_user_attention_bids bid = new t_user_attention_bids();

        bid.time = new Date();
        bid.user_id = userId;
        bid.bid_id = bidId;

        try {
            bid.save();
        } catch (Exception e) {
            Logger.error("标->收藏某个标:" + e.getMessage());
            error.code = -4;
            error.msg = "收藏失败!";
            
            return -1;
        }
        
        if(bid.id < 1){
            error.code = -5;
            error.msg = "收藏失败!";
            
            return -1;
        }
        
        /* 添加事件 */
        DealDetail.userEvent(userId, UserEvent.COLLECT_BID, "收藏标", error);
        
        if(error.code < 0){
            error.msg = "收藏失败!";
            JPA.setRollbackOnly();
            
            return -1;
        }
        
        error.msg = "收藏成功!";
        
        return bid.id;
    }

    /**
     * 查询这个标是否已经被收藏
     * @param userId 用户ID
     * @param bidId 标ID
     * @param error 错误信息
     * @return 1:已收藏  0:未收藏
     */
    private static int isCollect(long userId, long bidId) {
        String hql = "select id from t_user_attention_bids where user_id=? and bid_id=?";
        Long id = null;
        
        try {
            id = t_user_attention_bids.find(hql, userId, bidId).first();
        } catch (Exception e) {
            Logger.error("标->查询这个标是否已经被收藏:"+ e.getMessage());

            return Constants.COLLECT; // 表示已收藏
        }
        
        if (id == null || id == 0) return Constants.NOT_COLLECT; // 表示未收藏

        return Constants.COLLECT; // 表示已收藏
    }
   
    /**
     * 判断标是否收藏,并返回收藏id
     * @param userId
     * @param bidId
     * @return
     */
    public static long isAttentionBid(long userId, long bidId) {
        String hql = "select id from t_user_attention_bids where user_id=? and bid_id=?";
        Long id = null;
        
        try {
            id = t_user_attention_bids.find(hql, userId, bidId).first();
        } catch (Exception e) {
            Logger.error("标->查询这个标是否已经被收藏:"+ e.getMessage());

            return Constants.COLLECT; // 表示已收藏
        }
        
        if (id == null || id == 0) return Constants.NOT_COLLECT; // 表示未收藏

        return id; // 表示已收藏
    }




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-5-13 10:58:55 | 显示全部楼层
思路就是把查询出来的列表中是收藏的部分删除掉就不会显示了 Sql 就是Not In
回复

使用道具 举报

 楼主| 发表于 2015-5-13 11:37:55 | 显示全部楼层
站长苏飞 发表于 2015-5-13 10:58
思路就是把查询出来的列表中是收藏的部分删除掉就不会显示了 Sql 就是Not In

这边的平台是这么处理的,加入收藏后保存这个产品的id到用户关注产品表。然后只看收藏的时候根据视图来查询,因为已经把产品id保存到了用户关注产品表,通过视图多表联查的。如果not in会造成未登录的用户看不了所有的产品吧
回复

使用道具 举报

发表于 2015-5-13 11:43:19 | 显示全部楼层
not in里产品ID应该是根据当前登录用户的ID查出来的,未登录的用户不存在,或者默认为0是查不到的,所以not in是不会影响查询全部的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-10 07:23

© 2014-2021

快速回复 返回顶部 返回列表