admin
2021-05-14 ae2294be876ac4595d7b31b36c0057726d12354f
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
package com.yeshi.fanli.service.impl.taobao;
 
import java.math.BigDecimal;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.taobao.TLJFreeBuyGoodsDao;
import com.yeshi.fanli.entity.taobao.TLJFreeBuyGoods;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsUpdateService;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 
@Service
public class TLJFreeBuyGoodsUpdateServiceImpl implements TLJFreeBuyGoodsUpdateService {
    @Resource
    private TLJFreeBuyGoodsDao tljFreeBuyGoodsDao;
 
    @Resource
    private EhCacheCacheManager ehCacheCacheManager;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    
    @Override
    public void updateGoods(TaoBaoGoodsBrief goods) {
        if (goods == null)
            return;
 
        List<TLJFreeBuyGoods> list = tljFreeBuyGoodsDao.listByGoodsId(goods.getAuctionId());
        if (list != null) {
            
            // 验证是否有券
            if (goods.getCouponAmount() == null || goods.getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
                for (TLJFreeBuyGoods tljGoods : list) {
                    tljFreeBuyGoodsDao.delete(tljGoods.getId());
                }
                return;
            }
            
            // 计算券后价  1<= n <= 2
            BigDecimal couplePrice = TaoBaoUtil.getCouponPrice(goods);
            if (couplePrice.compareTo(new BigDecimal(1.0)) < 0 || couplePrice.compareTo(new BigDecimal(2.0)) > 0) {
                for (TLJFreeBuyGoods tljGoods : list) {
                    tljFreeBuyGoodsDao.delete(tljGoods.getId());
                }
                return;
            }
            
            for (TLJFreeBuyGoods TLJBuyGoods : list) {
                if (goods.getCouponInfo() == null)
                    goods.setCouponInfo("");
                if (goods.getCouponAmount() == null)
                    goods.setCouponAmount(new BigDecimal(0));
 
                // 判断 券信息 价格信息 返利比例信息是否改变
                boolean change = false;
                if (goods.getZkPrice().compareTo(TLJBuyGoods.getGoods().getZkPrice()) != 0)
                    change = true;
                if (goods.getCouponAmount().compareTo(TLJBuyGoods.getGoods().getCouponAmount()) != 0)
                    change = true;
                if (!goods.getCouponInfo().equalsIgnoreCase(TLJBuyGoods.getGoods().getCouponInfo()))
                    change = true;
                if (goods.getTkRate().compareTo(TLJBuyGoods.getGoods().getTkRate()) != 0)
                    change = true;
 
                if (change) {
                    // 清除列表缓存
                    ehCacheCacheManager.getCache("commonContentCache").evict(
                            "TLJFreeBuy-listByDay" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
                }
 
                // 更新券信息 ,价格信息,销量信息
                TLJBuyGoods.getGoods().setZkPrice(goods.getZkPrice());
                TLJBuyGoods.getGoods().setCouponAmount(goods.getCouponAmount());
                TLJBuyGoods.getGoods().setCouponInfo(goods.getCouponInfo());
                TLJBuyGoods.getGoods().setCouponEffectiveEndTime(goods.getCouponEffectiveEndTime());
                TLJBuyGoods.getGoods().setCouponEffectiveStartTime(goods.getCouponEffectiveStartTime());
                TLJBuyGoods.getGoods().setCouponLeftCount(goods.getCouponLeftCount());
                TLJBuyGoods.getGoods().setCouponStartFee(goods.getCouponStartFee());
                TLJBuyGoods.getGoods().setCouponTotalCount(goods.getCouponTotalCount());
                TLJBuyGoods.getGoods().setBiz30day(goods.getBiz30day());
                TLJBuyGoods.getGoods().setTkRate(goods.getTkRate());
                TLJBuyGoods.getGoods().setId(goods.getId());
                TLJBuyGoods.getGoods().setAuctionId(goods.getAuctionId());
                tljFreeBuyGoodsDao.save(TLJBuyGoods);
            }
        }
    }
}