yujian
2019-02-14 5eadf208bc38b0002f127217e479aa5353228ec8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.yeshi.fanli.goods.service.impl.recommend;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.fanli.facade.goods.entity.recommend.RecommendUserGoods;
import org.fanli.facade.goods.entity.recommend.RecommendUserGoodsMap;
import org.fanli.facade.goods.exception.recommend.RecommendUserGoodsException;
import org.fanli.facade.goods.exception.taobao.CommonGoodsException;
import org.fanli.facade.goods.service.recommend.RecommendUserGoodsService;
import org.fanli.facade.goods.service.taobao.CommonGoodsService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.base.entity.goods.CommonGoods;
import com.yeshi.fanli.base.entity.user.UserInfo;
import com.yeshi.fanli.goods.dao.recommend.RecommendUserGoodsMapMapper;
import com.yeshi.fanli.goods.dao.recommend.RecommendUserGoodsMapper;
 
@Service(version = "1.0.0")
public class RecommendUserGoodsServiceImpl implements RecommendUserGoodsService {
 
    @Resource
    private RecommendUserGoodsMapper recommendUserGoodsMapper;
    @Resource
    private RecommendUserGoodsMapMapper recommendUserGoodsMapMapper;
    @Resource
    private CommonGoodsService commonGoodsService;
 
    @Transactional
    @Override
    public void addRecommend(Long uid, String recommendDesc, List<CommonGoods> goodsList)
            throws RecommendUserGoodsException {
        if (goodsList == null || goodsList.size() == 0)
            throw new RecommendUserGoodsException(1, "无推荐商品");
 
        RecommendUserGoods goods = new RecommendUserGoods();
        goods.setCreateTime(new Date());
        goods.setRecommendDesc(recommendDesc);
        goods.setUser(new UserInfo(uid));
        recommendUserGoodsMapper.insertSelective(goods);
        for (CommonGoods commonGoods : goodsList)
            try {
                commonGoods = commonGoodsService.addCommonGoods(commonGoods);
                recommendUserGoodsMapMapper.insertSelective(new RecommendUserGoodsMap(commonGoods, goods, new Date()));
            } catch (CommonGoodsException e) {
                throw new RecommendUserGoodsException(2, "商品添加出错");
            }
    }
 
    @Override
    public List<RecommendUserGoods> listRecommend(Long uid, int page, int pageSize) {
        return recommendUserGoodsMapper.listRecommendGoods(uid, (page - 1) * pageSize, pageSize);
    }
 
    @Override
    public long countRecommend(Long uid) {
        return recommendUserGoodsMapper.countRecommendGoods(uid);
    }
 
    @Override
    public List<RecommendUserGoodsMap> listByUidAndCommonGoodsId(Long uid, Long commonGoodsId) {
        return null;
    }
 
    @Override
    public Long countByUidAndCommonGoodsId(Long uid, Long commonGoodsId) {
        return null;
    }
 
    @Override
    public RecommendUserGoods getLatestRecommendUserGoods(Long uid) {
        return recommendUserGoodsMapper.getLatestRecommendUserGoods(uid);
    }
 
}