admin
2019-06-13 22a5179fbf4aed13dae767aff93d9ca047cba369
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
package com.yeshi.fanli.service.impl.goods;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dto.common.CommonContentNav;
import com.yeshi.fanli.dto.common.CommonContentResult;
import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 
@Service
public class CommonTemplateContentServiceImpl implements CommonTemplateContentService {
 
    @Resource
    private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
 
    @Override
    public List<CommonContentNav> getNavList(CommonContentTypeEnum type) {
        List<CommonContentNav> navList = new ArrayList<>();
        if (type == CommonContentTypeEnum._9k9) {
            navList.add(new CommonContentNav("-1", "综合"));
            navList.add(new CommonContentNav("0", "最新"));
            for (GoodsClass gc : DaTaoKeUtil.goodsClasses) {
                navList.add(new CommonContentNav(gc.getId() + "", gc.getName()));
            }
        } else if (type == CommonContentTypeEnum.chaoSheng) {
            navList.add(new CommonContentNav("1", "5%~10%返利"));
            navList.add(new CommonContentNav("2", "10%~20%返利"));
            navList.add(new CommonContentNav("3", "20%~30%返利"));
            navList.add(new CommonContentNav("4", "30%~40%返利"));
            navList.add(new CommonContentNav("5", "40%以上返利"));
        } else if (type == CommonContentTypeEnum.haoQuan) {
            navList.add(new CommonContentNav("1", "5~10元券"));
            navList.add(new CommonContentNav("2", "10~30元券"));
            navList.add(new CommonContentNav("3", "30~50元券"));
            navList.add(new CommonContentNav("4", "50元以上券"));
        } else if (type == CommonContentTypeEnum.juJia) {
            navList.add(new CommonContentNav("1", "综合"));
            navList.add(new CommonContentNav("2", "最新"));
            navList.add(new CommonContentNav("3", "热卖"));
            navList.add(new CommonContentNav("4", "销量"));
            navList.add(new CommonContentNav("5", "返利比"));
        } else if (type == CommonContentTypeEnum.meiShi) {
            navList.add(new CommonContentNav("1", "综合"));
            navList.add(new CommonContentNav("2", "最新"));
            navList.add(new CommonContentNav("3", "热卖"));
            navList.add(new CommonContentNav("4", "销量"));
            navList.add(new CommonContentNav("5", "返利比"));
        } else if (type == CommonContentTypeEnum.muYin) {
            navList.add(new CommonContentNav("1", "精选"));
            navList.add(new CommonContentNav("2", "备孕"));
            navList.add(new CommonContentNav("3", "0~6月"));
            navList.add(new CommonContentNav("4", "7~12月"));
            navList.add(new CommonContentNav("5", "1~3岁"));
            navList.add(new CommonContentNav("6", "4~6岁"));
            navList.add(new CommonContentNav("7", "7~12岁"));
        } else if (type == CommonContentTypeEnum.reMai) {
            navList.add(new CommonContentNav("1", "综合"));
            navList.add(new CommonContentNav("2", "最新"));
            navList.add(new CommonContentNav("3", "热卖"));
            navList.add(new CommonContentNav("4", "销量"));
            navList.add(new CommonContentNav("5", "返利比"));
        }
        return navList;
    }
 
    
    
    @Cacheable(value = "commonContentCache", key = "#type+'-'+#cid+'-'+#page+'-'+#pageSize")
    @Override
    public CommonContentResult getContentList(CommonContentTypeEnum type, String cid, int page, int pageSize) {
        if (type == CommonContentTypeEnum._9k9)
            return get9K9Content(cid, page, pageSize);
 
        return null;
    }
 
    private CommonContentResult get9K9Content(String cid, int page, int pageSize) {
        DaTaoKeGoodsResult result = null;
        if ("-1".equalsIgnoreCase(cid)) {
            result = DaTaoKeApiUtil.search("", null, null, new BigDecimal("10"), page, pageSize,
                    DaTaoKeApiUtil.SORT_DEFAULT);
 
        } else if ("0".equalsIgnoreCase(cid)) {
            result = DaTaoKeApiUtil.search("", null, null, new BigDecimal("10"), page, pageSize,
                    DaTaoKeApiUtil.SORT_CREATETIME);
        } else {
            List<Integer> cidList = new ArrayList<>();
            cidList.add(Integer.parseInt(cid));
            result = DaTaoKeApiUtil.search("", cidList, null, new BigDecimal("10"), page, pageSize,
                    DaTaoKeApiUtil.SORT_DEFAULT);
        }
 
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        long count = 0;
        if (result != null) {
            count = result.getTotalCount();
            if (result.getGoodsList() != null)
                for (DaTaoKeDetailV2 detail : result.getGoodsList())
                    goodsList.add(TaoBaoUtil.convert(detail));
        }
        return new CommonContentResult(goodsList, count);
    }
 
}