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);
|
}
|
|
}
|