From a6f34b99ee20e528b766c8ed5a61bd9c5aa0e7ae Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 16 十一月 2019 18:10:33 +0800 Subject: [PATCH] 淘宝相似商品推荐接口优化,根据商品ID搜索商品基本信息优化 --- fanli/src/main/java/com/yeshi/fanli/service/impl/clazz/GoodsSubClassLabelServiceImpl.java | 37 +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/clazz/GoodsSubClassLabelServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/clazz/GoodsSubClassLabelServiceImpl.java index 6360f72..7e0dd85 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/clazz/GoodsSubClassLabelServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/clazz/GoodsSubClassLabelServiceImpl.java @@ -1,20 +1,24 @@ package com.yeshi.fanli.service.impl.clazz; +import java.util.Calendar; import java.util.Date; import java.util.List; import javax.annotation.Resource; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.yeshi.fanli.dao.mybatis.clazz.GoodsSubClassLabelMapMapper; import com.yeshi.fanli.dao.mybatis.clazz.GoodsSubClassLabelMapper; +import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass; import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabel; import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabelMap; -import com.yeshi.fanli.exception.GoodsClassException; +import com.yeshi.fanli.exception.goods.GoodsClassException; import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService; import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.vo.goods.GoodsSubClassLabelVO; @Service public class GoodsSubClassLabelServiceImpl implements GoodsSubClassLabelService { @@ -87,8 +91,37 @@ @Override public GoodsSubClassLabelMap selectBySubClassId(Long subClassId) { - return goodsSubClassLabelMapMapper.selectBySubClassId(subClassId); } + @Override + @Cacheable(value = "classCache", key = "'listSubMapCache-'+#classId") + public List<GoodsSubClassLabelVO> listSubMapCache(Long classId) { + List<GoodsSubClassLabelVO> list = goodsSubClassLabelMapper.listSubMapByClassId(classId, + Calendar.getInstance().get(Calendar.MONTH) + 1); + if (list == null || list.size() == 0) { + return list; + } + + for (int i = 0; i < list.size(); i++) { + GoodsSubClassLabelVO labelVO = list.get(i); + List<GoodsSubClass> listSub = labelVO.getListSub(); + if (listSub == null || listSub.size() == 0) { + list.remove(labelVO); + i--; + continue; + } + + for (GoodsSubClass goodsSubClass : listSub) { + String pictureSecond = goodsSubClass.getPictureSecond(); + if (!StringUtil.isNullOrEmpty(pictureSecond)) { + goodsSubClass.setPicture(pictureSecond); + } + } + + labelVO.setListSub(listSub); + } + return list; + } + } -- Gitblit v1.8.0