admin
2019-07-09 531d93708df8017e59830f15b41f3cc42d6126e6
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.yeshi.fanli.service.impl.taobao;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.taobao.ShareHotGoodsDao;
import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
import com.yeshi.fanli.entity.taobao.ShareHotGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
@Service
public class ShareHotGoodsServiceImpl implements ShareHotGoodsService {
    @Resource
    private ShareHotGoodsDao shareHotGoodsDao;
 
    @Resource
    private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
 
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
 
    @Resource
    private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
 
    @Override
    public void addShareHotGoods(ShareHotGoods goods) {
        if (goods == null || StringUtil.isNullOrEmpty(goods.getDay()) || goods.getGoods() == null)
            return;
        goods.setId(StringUtil.Md5(goods.getDay() + "#" + goods.getGoods().getAuctionId()));
        if (goods.getUpdateTime() == null)
            goods.setUpdateTime(new Date());
        shareHotGoodsDao.save(goods);
    }
 
    @Cacheable(value = "commonContentCache", key = "'listByDay'+#day")
    @Override
    public List<ShareHotGoods> listByDay(String day) {
        return listByDay(day, 10);
    }
 
    @Override
    public List<ShareHotGoods> listByDay(String day, int count) {
        List<ShareHotGoods> list = shareHotGoodsDao.listByDayOrderByUpdateTime(day, 1, count);
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        if (list != null) {
            for (ShareHotGoods shg : list)
                goodsList.add(shg.getGoods());
        }
        // 过滤下线商品
        goodsList = taoBaoGoodsBriefService.filterOffLineGoods(goodsList);
        // 添加大淘客信息
        goodsList = daTaoKeGoodsDetailService.filterTaoBaoGoods(goodsList);
        Map<Long, TaoBaoGoodsBrief> goodsMap = new HashMap<>();
        if (goodsList != null)
            for (TaoBaoGoodsBrief g : goodsList)
                goodsMap.put(g.getAuctionId(), g);
 
        for (int j = 0; j < list.size(); j++) {
            if (goodsMap.get(list.get(j).getGoods().getAuctionId()) == null) {
                list.remove(j);
                j--;
            }
        }
        return list;
    }
 
    @Override
    public void deleteById(String id) {
        shareHotGoodsDao.delete(id);
    }
 
    @Override
    public List<TaoBaoGoodsBrief> listPreGoods(int page) {
        List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Service.listPreShareHotGoods(page);
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        if (list != null) {
            for (DaTaoKeDetailV2 v2 : list)
                goodsList.add(TaoBaoUtil.convert(v2));
        }
        return goodsList;
    }
 
    @Override
    public void deleteByGoodsId(Long goodsId) {
        shareHotGoodsDao.deleteByGoodsId(goodsId);
    }
 
    @Override
    public boolean verifyCanCreateTLJ(Long auctionId,TaoKeAppInfo info) {
        TaoLiJinDTO taoLiJinDTO = null;
        try {
            taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "淘礼金验证", new BigDecimal("1.00"), 1, new Date(),
                    new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 6), new Date(),
                    new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 6),
                    info);
        } catch (TaoKeApiException e) {
            if (e.getCode() == TaoKeApiException.CODE_TLJ_FORBIDDEN) {
                // 该商品不支持创建淘礼金红包
                deleteByGoodsId(auctionId);
                return false;
            } else if (e.getCode() == TaoKeApiException.CODE_TLJ_NO_MONEY) {
                // 官方玩法钱包余额不足 TODO
            }
        }
        return true;
    }
 
    @Override
    public void updateShareGoods(TaoBaoGoodsBrief goods) {
        List<ShareHotGoods> list = shareHotGoodsDao.listByAuctionId(goods.getAuctionId());
        if (list != null)
            for (ShareHotGoods shareHotGoods : list) {
                // 更新券信息 ,价格信息,销量信息
                shareHotGoods.getGoods().setZkPrice(goods.getZkPrice());
                shareHotGoods.getGoods().setCouponAmount(goods.getCouponAmount());
                shareHotGoods.getGoods().setCouponInfo(goods.getCouponInfo());
                shareHotGoods.getGoods().setCouponEffectiveEndTime(goods.getCouponEffectiveEndTime());
                shareHotGoods.getGoods().setCouponEffectiveStartTime(goods.getCouponEffectiveStartTime());
                shareHotGoods.getGoods().setCouponLeftCount(goods.getCouponLeftCount());
                shareHotGoods.getGoods().setCouponStartFee(goods.getCouponStartFee());
                shareHotGoods.getGoods().setCouponTotalCount(goods.getCouponTotalCount());
                shareHotGoods.getGoods().setBiz30day(goods.getBiz30day());
                shareHotGoodsDao.save(shareHotGoods);
            }
    }
}