| | |
| | | package com.yeshi.fanli.service.impl.taobao;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.taobao.ShareHotGoodsDao;
|
| | | import com.yeshi.fanli.entity.taobao.ShareHotGoods;
|
| | | import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class ShareHotGoodsServiceImpl implements ShareHotGoodsService {
|
| | | @Resource
|
| | | private ShareHotGoodsDao shareHotGoodsDao;
|
| | |
|
| | | @Override
|
| | | public void addShareHotGoods(ShareHotGoods goods) {
|
| | | if (goods == null || StringUtil.isNullOrEmpty(goods.getDay()) || goods.getGoods() == null)
|
| | | return;
|
| | | goods.setId(StringUtil.Md5(goods.getDay() + "#" + goods.getGoods().getAuctionId()));
|
| | | if (goods.getUpdateTime() == null)
|
| | | goods.setUpdateTime(new Date());
|
| | | shareHotGoodsDao.save(goods);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ShareHotGoods> listByDay(String day) {
|
| | | return shareHotGoodsDao.listByDayOrderByUpdateTime(day, 1, 10);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteById(String id) {
|
| | | shareHotGoodsDao.delete(id);
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.taobao; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.yeshi.fanli.dao.taobao.ShareHotGoodsDao; |
| | | import com.yeshi.fanli.entity.taobao.ShareHotGoods; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | | import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2; |
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException; |
| | | import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; |
| | | import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; |
| | | import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service; |
| | | import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | |
| | | @Service |
| | | public class ShareHotGoodsServiceImpl implements ShareHotGoodsService { |
| | | @Resource |
| | | private ShareHotGoodsDao shareHotGoodsDao; |
| | | |
| | | @Resource |
| | | private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; |
| | | |
| | | @Resource |
| | | private ConfigTaoLiJinService configTaoLiJinService; |
| | | |
| | | @Override |
| | | public void addShareHotGoods(ShareHotGoods goods) { |
| | | if (goods == null || StringUtil.isNullOrEmpty(goods.getDay()) || goods.getGoods() == null) |
| | | return; |
| | | goods.setId(StringUtil.Md5(goods.getDay() + "#" + goods.getGoods().getAuctionId())); |
| | | if (goods.getUpdateTime() == null) |
| | | goods.setUpdateTime(new Date()); |
| | | shareHotGoodsDao.save(goods); |
| | | } |
| | | |
| | | @Cacheable(value = "commonContentCache", key = "'listByDay'+#day") |
| | | @Override |
| | | public List<ShareHotGoods> listByDay(String day) { |
| | | return listByDay(day, 10); |
| | | } |
| | | |
| | | @Override |
| | | public List<ShareHotGoods> listByDay(String day, int count) { |
| | | List<ShareHotGoods> list = shareHotGoodsDao.listByDayOrderByUpdateTime(day, 1, count); |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (ShareHotGoods shg : list) |
| | | goodsList.add(shg.getGoods()); |
| | | } |
| | | |
| | | // 过滤基本商品信息 |
| | | goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList); |
| | | |
| | | // 过滤下线商品 |
| | | goodsList = taoBaoGoodsBriefService.filterOffLineGoods(goodsList); |
| | | // 添加大淘客信息 |
| | | goodsList = daTaoKeGoodsDetailV2Service.filterTaoBaoGoods(goodsList); |
| | | Map<String, TaoBaoGoodsBrief> goodsMap = new HashMap<>(); |
| | | if (goodsList != null) |
| | | for (TaoBaoGoodsBrief g : goodsList) |
| | | goodsMap.put(g.getAuctionId(), g); |
| | | |
| | | for (int j = 0; j < list.size(); j++) { |
| | | if (goodsMap.get(list.get(j).getGoods().getAuctionId()) == null) { |
| | | list.remove(j); |
| | | j--; |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(String id) { |
| | | shareHotGoodsDao.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> listPreGoods(int page) { |
| | | String warningValue = configTaoLiJinService.getValueByKey("warning_value", |
| | | new Date(TimeUtil.convertToTimeTemp( |
| | | TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), |
| | | "yyyy-MM-dd"))); |
| | | |
| | | BigDecimal minComminsion = new BigDecimal(1) |
| | | .divide(new BigDecimal(warningValue).multiply(new BigDecimal("0.01")), 2, RoundingMode.UP); |
| | | |
| | | List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Service.listPreShareHotGoods(page, minComminsion); |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (DaTaoKeDetailV2 v2 : list) |
| | | goodsList.add(TaoBaoUtil.convert(v2)); |
| | | } |
| | | return goodsList; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByGoodsId(String goodsId) { |
| | | shareHotGoodsDao.deleteByGoodsId(goodsId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean verifyCanCreateTLJ(String auctionId, TaoKeAppInfo info) { |
| | | try { |
| | | TaoKeApiUtil.createTaoLiJin(auctionId, "淘礼金验证", new BigDecimal("1.00"), 1, new Date(), |
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 6), new Date(), |
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 6), info); |
| | | } catch (TaoLiJinCreateException e1) { |
| | | if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 商品不允许创建淘礼金 |
| | | deleteByGoodsId(auctionId); |
| | | return false; |
| | | } |
| | | |
| | | } catch (TaoKeApiException e) { |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void updateShareGoods(TaoBaoGoodsBrief goods) { |
| | | List<ShareHotGoods> list = shareHotGoodsDao.listByAuctionId(goods.getAuctionId()); |
| | | if (list != null) |
| | | for (ShareHotGoods shareHotGoods : list) { |
| | | // 更新券信息 ,价格信息,销量信息 |
| | | shareHotGoods.getGoods().setZkPrice(goods.getZkPrice()); |
| | | shareHotGoods.getGoods().setCouponAmount(goods.getCouponAmount()); |
| | | shareHotGoods.getGoods().setCouponInfo(goods.getCouponInfo()); |
| | | shareHotGoods.getGoods().setCouponEffectiveEndTime(goods.getCouponEffectiveEndTime()); |
| | | shareHotGoods.getGoods().setCouponEffectiveStartTime(goods.getCouponEffectiveStartTime()); |
| | | shareHotGoods.getGoods().setCouponLeftCount(goods.getCouponLeftCount()); |
| | | shareHotGoods.getGoods().setCouponStartFee(goods.getCouponStartFee()); |
| | | shareHotGoods.getGoods().setCouponTotalCount(goods.getCouponTotalCount()); |
| | | shareHotGoods.getGoods().setBiz30day(goods.getBiz30day()); |
| | | shareHotGoods.getGoods().setTkRate(goods.getTkRate()); |
| | | shareHotGoodsDao.save(shareHotGoods); |
| | | } |
| | | } |
| | | } |