| | |
| | | package com.yeshi.fanli.service.impl.goods;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.goods.RecommendUserGoodsMapMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.goods.RecommendUserGoodsMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.goods.RecommendUserGoods;
|
| | | import com.yeshi.fanli.entity.goods.RecommendUserGoodsMap;
|
| | | import com.yeshi.fanli.exception.goods.CommonGoodsException;
|
| | | import com.yeshi.fanli.exception.goods.RecommendUserGoodsException;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService;
|
| | |
|
| | | @Service
|
| | | public class RecommendUserGoodsServiceImpl implements RecommendUserGoodsService {
|
| | |
|
| | | @Resource
|
| | | private RecommendUserGoodsMapper recommendUserGoodsMapper;
|
| | | @Resource
|
| | | private RecommendUserGoodsMapMapper recommendUserGoodsMapMapper;
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void addRecommend(Long uid, String recommendDesc, List<CommonGoods> goodsList)
|
| | | throws RecommendUserGoodsException {
|
| | | if (goodsList == null || goodsList.size() == 0)
|
| | | throw new RecommendUserGoodsException(1, "无推荐商品");
|
| | |
|
| | | RecommendUserGoods goods = new RecommendUserGoods();
|
| | | goods.setCreateTime(new Date());
|
| | | goods.setRecommendDesc(recommendDesc);
|
| | | goods.setUser(new UserInfo(uid));
|
| | | recommendUserGoodsMapper.insertSelective(goods);
|
| | | for (CommonGoods commonGoods : goodsList)
|
| | | try {
|
| | | commonGoods = commonGoodsService.addCommonGoods(commonGoods);
|
| | | recommendUserGoodsMapMapper.insertSelective(new RecommendUserGoodsMap(commonGoods, goods, new Date()));
|
| | | } catch (CommonGoodsException e) {
|
| | | throw new RecommendUserGoodsException(2, "商品添加出错");
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<RecommendUserGoods> listRecommend(Long uid, int page, int pageSize) {
|
| | | return recommendUserGoodsMapper.listRecommendGoods(uid, (page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countRecommend(Long uid) {
|
| | | return recommendUserGoodsMapper.countRecommendGoods(uid);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.goods; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.goods.RecommendUserGoodsMapMapper; |
| | | import com.yeshi.fanli.dao.mybatis.goods.RecommendUserGoodsMapper; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.goods.CommonGoods; |
| | | import com.yeshi.fanli.entity.goods.RecommendUserGoods; |
| | | import com.yeshi.fanli.entity.goods.RecommendUserGoodsMap; |
| | | import com.yeshi.fanli.exception.goods.CommonGoodsException; |
| | | import com.yeshi.fanli.exception.goods.RecommendUserGoodsException; |
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService; |
| | | import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Service |
| | | public class RecommendUserGoodsServiceImpl implements RecommendUserGoodsService { |
| | | |
| | | @Resource |
| | | private RecommendUserGoodsMapper recommendUserGoodsMapper; |
| | | @Resource |
| | | private RecommendUserGoodsMapMapper recommendUserGoodsMapMapper; |
| | | @Resource |
| | | private CommonGoodsService commonGoodsService; |
| | | |
| | | @Transactional(rollbackFor=Exception.class) |
| | | @Override |
| | | public void addRecommend(Long uid, String device, String recommendDesc, List<CommonGoods> goodsList) |
| | | throws RecommendUserGoodsException { |
| | | if (goodsList == null || goodsList.size() == 0) |
| | | throw new RecommendUserGoodsException(1, "无推荐商品"); |
| | | |
| | | RecommendUserGoods goods = new RecommendUserGoods(); |
| | | goods.setCreateTime(new Date()); |
| | | goods.setRecommendDesc(recommendDesc); |
| | | if (uid != null) |
| | | goods.setUser(new UserInfo(uid)); |
| | | goods.setDevice(device); |
| | | recommendUserGoodsMapper.insertSelective(goods); |
| | | for (CommonGoods commonGoods : goodsList) |
| | | try { |
| | | commonGoods = commonGoodsService.addCommonGoods(commonGoods); |
| | | recommendUserGoodsMapMapper.insertSelective(new RecommendUserGoodsMap(commonGoods, goods, new Date())); |
| | | } catch (CommonGoodsException e) { |
| | | throw new RecommendUserGoodsException(2, "商品添加出错"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<RecommendUserGoods> listRecommend(Long uid, int page, int pageSize) { |
| | | return recommendUserGoodsMapper.listRecommendGoods(uid, (page - 1) * pageSize, pageSize); |
| | | } |
| | | |
| | | @Override |
| | | public long countRecommend(Long uid) { |
| | | return recommendUserGoodsMapper.countRecommendGoods(uid); |
| | | } |
| | | |
| | | @Override |
| | | public List<RecommendUserGoodsMap> listByUidAndCommonGoodsId(Long uid, Long commonGoodsId) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Long countByUidAndCommonGoodsId(Long uid, Long commonGoodsId) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public RecommendUserGoods getLatestRecommendUserGoods(Long uid) { |
| | | return recommendUserGoodsMapper.getLatestRecommendUserGoods(uid); |
| | | } |
| | | |
| | | @Override |
| | | public RecommendUserGoods getLatestRecommendUserGoodsByDevice(String device) { |
| | | return recommendUserGoodsMapper.getLatestRecommendUserGoodsByDevice(device); |
| | | } |
| | | |
| | | @Override |
| | | public List<RecommendUserGoods> listRecommendGoodsByDevice(String device, int page, int pageSize) { |
| | | return recommendUserGoodsMapper.listRecommendGoodsByDevice(device, (page - 1) * pageSize, pageSize); |
| | | } |
| | | |
| | | @Override |
| | | public long countRecommendGoodsByDevice(String device) { |
| | | return recommendUserGoodsMapper.countRecommendGoodsByDevice(device); |
| | | } |
| | | |
| | | @Override |
| | | public void syncDeviceAndUid(Long uid, String targetDevice) { |
| | | |
| | | List<RecommendUserGoods> list = recommendUserGoodsMapper.listRecommendGoods(uid, 0, 20); |
| | | for (RecommendUserGoods ru : list) { |
| | | if (StringUtil.isNullOrEmpty(ru.getDevice())) { |
| | | RecommendUserGoods update = new RecommendUserGoods(); |
| | | update.setId(ru.getId()); |
| | | update.setDevice(targetDevice); |
| | | recommendUserGoodsMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |