|
@@ -0,0 +1,77 @@
|
|
|
+/**
|
|
|
+* @版权信息 (@copyright Copyright 2017-XXXX JDJR.COM All Right Reserved);
|
|
|
+* @see
|
|
|
+* @author 于海涛 京东金融【技术研发部-证券及营销平台研发部-营销平台研发部】
|
|
|
+* @version 1.0
|
|
|
+* @date 2018年6月9日
|
|
|
+*/
|
|
|
+
|
|
|
+package com.zskk.shop.service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.zskk.shop.controller.bean.GoodBean;
|
|
|
+import com.zskk.shop.dao.RecommendGoodMapper;
|
|
|
+import com.zskk.shop.dao.entry.GoodBase;
|
|
|
+import com.zskk.shop.dao.entry.GoodPrice;
|
|
|
+import com.zskk.shop.dao.entry.RecommendGood;
|
|
|
+import com.zskk.shop.utils.ToolsUtil;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RecommendGoodService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RecommendGoodMapper recommendGoodMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodService goodService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void add(Integer gid){
|
|
|
+ recommendGoodMapper.del(gid);
|
|
|
+ RecommendGood good = new RecommendGood();
|
|
|
+ good.setCtime(ToolsUtil.getNow());
|
|
|
+ good.setFloor(1);
|
|
|
+ good.setGid(gid);
|
|
|
+ recommendGoodMapper.add(good);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void del(Integer gid){
|
|
|
+ recommendGoodMapper.del(gid);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 是否是推荐商品
|
|
|
+ * @param gid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isRecommend(Integer gid){
|
|
|
+ return recommendGoodMapper.queryByGid(gid) != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询推荐商品ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Integer> queryRecommendGids(){
|
|
|
+ return recommendGoodMapper.query();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<GoodBean> getRecommendGoods(){
|
|
|
+ List<Integer> gids = this.queryRecommendGids();
|
|
|
+ if (gids.isEmpty()){
|
|
|
+ return new ArrayList<>(0);
|
|
|
+ }
|
|
|
+ List<GoodBase> goodList = goodService.queryGoodBases(gids, null);
|
|
|
+ List<GoodBean> beans = new ArrayList<>();
|
|
|
+ for (GoodBase base: goodList){
|
|
|
+ GoodPrice price = goodService.queryGoodPrice(base.getGid());
|
|
|
+ beans.add(goodService.toSimpleGoodBean(base, price));
|
|
|
+ }
|
|
|
+ return beans;
|
|
|
+ }
|
|
|
+}
|