| | |
| | | package com.yeshi.fanli.service.impl.goods;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | import org.hibernate.HibernateException;
|
| | | import org.hibernate.Query;
|
| | | import org.hibernate.Session;
|
| | | import org.springframework.orm.hibernate4.HibernateCallback;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.config.AddEveryDayTaskDao;
|
| | | import com.yeshi.fanli.dao.goods.RecommendSectionGoodsDao;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper;
|
| | | import com.yeshi.fanli.dao.taobao.TaoBaoGoodsBriefDao;
|
| | | import com.yeshi.fanli.entity.admin.EveryDayTask;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.entity.bus.recommend.RecommendSection;
|
| | | import com.yeshi.fanli.entity.bus.recommend.RecommendSectionGoods;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TBPid;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.exception.ExistObjectException;
|
| | | import com.yeshi.fanli.exception.NotExistObjectException;
|
| | | import com.yeshi.fanli.exception.ShareGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendSectionGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendSectionService;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.TBPidService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | @Service
|
| | | public class TaoBaoGoodsBriefServiceImpl implements TaoBaoGoodsBriefService {
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefDao taoBaoGoodsBriefDao;
|
| | |
|
| | | @Resource
|
| | | private RecommendSectionGoodsDao recommendSectionGoodsDao;
|
| | |
|
| | | @Resource
|
| | | private RecommendSectionGoodsService recommendSectionGoodsService;
|
| | |
|
| | | @Resource
|
| | | private RecommendSectionService recommendSectionService;
|
| | |
|
| | | @Resource
|
| | | private ClassRecommendGoodsService classRecommendGoodsService;
|
| | |
|
| | | @Resource
|
| | | private GoodsClassService goodsClassService;
|
| | |
|
| | | @Resource
|
| | | private AddEveryDayTaskDao addEveryDayTaskDao;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoCouponService taoBaoCouponService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper;
|
| | |
|
| | | @Resource
|
| | | private TBPidService tbPidService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | public void save(TaoBaoGoodsBrief taoBaoGoodsBrief) throws ExistObjectException {
|
| | |
|
| | | long auctionId = taoBaoGoodsBrief.getAuctionId();
|
| | | List<TaoBaoGoodsBrief> list = taoBaoGoodsBriefDao.list("from TaoBaoGoodsBrief tb where tb.auctionId = ?",
|
| | | new Serializable[] { auctionId });
|
| | | if (list.size() > 0) {
|
| | | throw new ExistObjectException("已存在该商品");
|
| | | }
|
| | |
|
| | | taoBaoGoodsBrief.setCreatetime(new Date());
|
| | | taoBaoGoodsBriefDao.create(taoBaoGoodsBrief);
|
| | | }
|
| | |
|
| | | public List<TaoBaoGoodsBrief> getTBList(int index, String key) {
|
| | |
|
| | | int start = index * Constant.PAGE_SIZE;
|
| | |
|
| | | boolean b = NumberUtil.isNumeric(key);
|
| | | if (b) {
|
| | | return taoBaoGoodsBriefDao.list(
|
| | | "from TaoBaoGoodsBrief tb where tb.title like ? or tb.auctionId = ? order by tb.id desc", start,
|
| | | Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%", Long.parseLong(key) });
|
| | | } else {
|
| | | return taoBaoGoodsBriefDao.list("from TaoBaoGoodsBrief tb where tb.title like ? order by tb.id desc", start,
|
| | | Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%" });
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public int getCount(String key) {
|
| | | boolean b = NumberUtil.isNumeric(key);
|
| | | Long lcount = 0L;
|
| | | if (b) {
|
| | | lcount = taoBaoGoodsBriefDao.getCount(
|
| | | "select count(*) from TaoBaoGoodsBrief tb where tb.title like ? or tb.auctionId = ? ",
|
| | | new Serializable[] { "%" + key + "%", Long.parseLong(key) });
|
| | | } else {
|
| | | lcount = taoBaoGoodsBriefDao.getCount("select count(*) from TaoBaoGoodsBrief tb where tb.title like ? ",
|
| | | new Serializable[] { "%" + key + "%" });
|
| | | }
|
| | |
|
| | | return lcount.intValue();
|
| | | }
|
| | |
|
| | | public TaoBaoGoodsBrief getTaoBao(long id) {
|
| | |
|
| | | return taoBaoGoodsBriefDao.find(TaoBaoGoodsBrief.class, id);
|
| | | }
|
| | |
|
| | | public TaoBaoGoodsBrief getTaoBaoByAuctionId(long id) {
|
| | | List<TaoBaoGoodsBrief> list = taoBaoGoodsBriefDao
|
| | | .list("from TaoBaoGoodsBrief goods where goods.auctionId=" + id);
|
| | | if (list == null || list.size() == 0)
|
| | | return null;
|
| | | else
|
| | | return list.get(0);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void deleteTaoBaoGoods(final long id) {
|
| | | taoBaoGoodsBriefDao.excute(new HibernateCallback() {
|
| | |
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | recommendSectionGoodsService.deleteRecommendSectionGoodsByTB(id);
|
| | | classRecommendGoodsService.deleteRecommendGoodsByTB(id);
|
| | | Query query = session.createQuery("delete from TaoBaoGoodsBrief tb where tb.id = ?");
|
| | | query.setParameter(0, id);
|
| | | return query.executeUpdate();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void addRecommendSectionGoods(long rsid, long tbid) throws NotExistObjectException, ExistObjectException {
|
| | | RecommendSection recommendSection = recommendSectionService.getRecommendSection(rsid);
|
| | | TaoBaoGoodsBrief taobao = taoBaoGoodsBriefDao.find(TaoBaoGoodsBrief.class, tbid);
|
| | | if (recommendSection == null || taobao == null) {
|
| | | throw new NotExistObjectException("不存在该板块或者淘宝商品");
|
| | | }
|
| | | recommendSectionGoodsService.addRecommendSectionGoods(recommendSection, taobao);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加商品到每日任务
|
| | | */
|
| | | @Override
|
| | | public void addEveryDayTask(long tbid) throws NotExistObjectException, ExistObjectException {
|
| | | TaoBaoGoodsBrief taobao = taoBaoGoodsBriefDao.find(TaoBaoGoodsBrief.class, tbid);
|
| | | if (taobao == null) {
|
| | | throw new NotExistObjectException("不存在该淘宝商品");
|
| | | }
|
| | | EveryDayTask everyDaoTask = new EveryDayTask();
|
| | | everyDaoTask.setEtGoods(taobao);
|
| | | everyDaoTask.setEtCreateTime(new Date());
|
| | | addEveryDayTaskDao.create(everyDaoTask);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void addClassRecommendGoods(long gcid, long tbid) throws NotExistObjectException, ExistObjectException {
|
| | | GoodsClass goodsClass = goodsClassService.getGoodsClass(gcid);
|
| | | TaoBaoGoodsBrief taobao = taoBaoGoodsBriefDao.find(TaoBaoGoodsBrief.class, tbid);
|
| | | if (goodsClass == null || taobao == null) {
|
| | | throw new NotExistObjectException("不存在该分类或者淘宝商品");
|
| | | }
|
| | | classRecommendGoodsService.addRecommendGoods(goodsClass, taobao);
|
| | | }
|
| | |
|
| | | public TaoBaoGoodsBrief getTaoBaoByAuctionId(String tbid) {
|
| | | List<TaoBaoGoodsBrief> list = taoBaoGoodsBriefDao.list("from TaoBaoGoodsBrief tb where tb.auctionId=?",
|
| | | new Serializable[] { Long.parseLong(tbid) });
|
| | | if (list.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | return list.get(0);
|
| | | }
|
| | |
|
| | | public void updateTBGoods(TaoBaoGoodsBrief tb) throws NotExistObjectException {
|
| | | TaoBaoGoodsBrief find = taoBaoGoodsBriefDao.find(TaoBaoGoodsBrief.class, tb.getId());
|
| | | if (find == null) {
|
| | | throw new NotExistObjectException("不存在该对象");
|
| | | }
|
| | | find.setPictUrl(tb.getPictUrl());
|
| | | find.setTitle(tb.getTitle());
|
| | | taoBaoGoodsBriefDao.update(find);
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | public List<TaoBaoGoodsBrief> getAllTaoBao() {
|
| | | return (List<TaoBaoGoodsBrief>) taoBaoGoodsBriefDao.excute(new HibernateCallback<List<TaoBaoGoodsBrief>>() {
|
| | |
|
| | | public List<TaoBaoGoodsBrief> doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createQuery("from TaoBaoGoodsBrief ");
|
| | | return query.list();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void getUpdateTaoBao() {
|
| | | List<TaoBaoGoodsBrief> list = getAllTaoBao();
|
| | | int len = list.size();
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : list) {
|
| | | try {
|
| | | Thread.sleep(2000);
|
| | | } catch (InterruptedException e) {
|
| | | continue;
|
| | | }
|
| | | try {
|
| | | updateTaoBaoGoods(taoBaoGoodsBrief);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | len--;
|
| | | System.out.println("还剩:" + len + "个商品未更新");
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | public void updateTaoBaoGoods(TaoBaoGoodsBrief taoBaoGoodsBrief) throws TaobaoGoodsDownException {
|
| | |
|
| | | SearchFilter filter = new SearchFilter();
|
| | | filter.setKey("https://item.taobao.com/item.htm?id=" + taoBaoGoodsBrief.getAuctionId());
|
| | | TaoBaoGoodsBrief tb = TaoKeApiUtil.searchGoodsDetail(taoBaoGoodsBrief.getAuctionId());
|
| | | if (tb == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | taoBaoGoodsBrief.setCouponLink(tb.getCouponLink());
|
| | | taoBaoGoodsBrief.setCouponActivityId(tb.getCouponActivityId());
|
| | | taoBaoGoodsBrief.setCouponAmount(tb.getCouponAmount());
|
| | | taoBaoGoodsBrief.setCouponEffectiveStartTime(tb.getCouponEffectiveStartTime());
|
| | | taoBaoGoodsBrief.setCouponEffectiveEndTime(tb.getCouponEffectiveEndTime());
|
| | | taoBaoGoodsBrief.setCouponInfo(tb.getCouponInfo());
|
| | | taoBaoGoodsBrief.setCouponLeftCount(tb.getCouponLeftCount());
|
| | | taoBaoGoodsBrief.setCouponLinkTaoToken(tb.getCouponLinkTaoToken());
|
| | | taoBaoGoodsBrief.setCouponOriLink(tb.getCouponOriLink());
|
| | | taoBaoGoodsBrief.setCouponShortLink(tb.getCouponShortLink());
|
| | | taoBaoGoodsBrief.setCouponStartFee(tb.getCouponStartFee());
|
| | | taoBaoGoodsBrief.setCouponTotalCount(tb.getCouponTotalCount());
|
| | | taoBaoGoodsBrief.setBiz30day(tb.getBiz30day());
|
| | | taoBaoGoodsBrief.setTkRate(tb.getTkRate());
|
| | | taoBaoGoodsBrief.setZkPrice(tb.getZkPrice());
|
| | | taoBaoGoodsBrief.setEventRate(tb.getEventRate());
|
| | | taoBaoGoodsBrief.setTkMktStatus(tb.getTkMktStatus());
|
| | | taoBaoGoodsBrief.setReservePrice(tb.getReservePrice());
|
| | |
|
| | | taoBaoGoodsBrief.setCreatetime(new Date());
|
| | | taoBaoGoodsBriefDao.update(taoBaoGoodsBrief);
|
| | |
|
| | | }
|
| | |
|
| | | public int getInvalidCount() {
|
| | | Long count = taoBaoGoodsBriefDao.getCount("select count(tb.id) from TaoBaoGoodsBrief tb where tb.tkRate = 0");
|
| | | return count.intValue();
|
| | | }
|
| | |
|
| | | public List<TaoBaoGoodsBrief> getInvalidTB(int pageIndex) {
|
| | | int start = (pageIndex - 1) * Constant.PAGE_SIZE;
|
| | | return taoBaoGoodsBriefDao.list("from TaoBaoGoodsBrief tb where tb.tkRate = 0 ", start, Constant.PAGE_SIZE,
|
| | | new Serializable[] {});
|
| | | }
|
| | |
|
| | | /**
|
| | | * 从yeshi_ec_recommend_section_goods表中查询数据
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public List<RecommendSectionGoods> listRecommendSectionGoods() {
|
| | | return recommendSectionGoodsDao.list("from RecommendSectionGoods");
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String getGoodsUserHongBao(TaoBaoGoodsBrief goods) {
|
| | | BigDecimal rate = hongBaoManageService.getFanLiRate();
|
| | | return TaoBaoUtil.getGoodsHongBaoInfo(goods, rate);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getShareGoodsUserHongBao(TaoBaoGoodsBrief goods) {
|
| | | BigDecimal rate = hongBaoManageService.getShareRate();
|
| | | return TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> queryByAuctionId(Long auctionId) {
|
| | | return taoBaoGoodsBriefMapper.queryByAuctionId(auctionId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> listQueryByAuctionId(List<Long> list) {
|
| | | return taoBaoGoodsBriefMapper.queryGoodsByAuctionId(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insertSelective(TaoBaoGoodsBrief taoBaoGoodsBrief) {
|
| | |
|
| | | return taoBaoGoodsBriefMapper.insertSelective(taoBaoGoodsBrief);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insertBatch(List<TaoBaoGoodsBrief> list) {
|
| | |
|
| | | return taoBaoGoodsBriefMapper.insertBatch(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoGoodsBrief selectByPrimaryKey(Long id) {
|
| | | return taoBaoGoodsBriefMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void updateTBGoodsWithNewInfo(TaoBaoGoodsBrief tb) throws NotExistObjectException {
|
| | | if (tb == null)
|
| | | return;
|
| | | List<TaoBaoGoodsBrief> findList = taoBaoGoodsBriefDao
|
| | | .list("from TaoBaoGoodsBrief tb where tb.auctionId=" + tb.getAuctionId());
|
| | | if (findList != null && findList.size() > 0) {
|
| | | for (TaoBaoGoodsBrief goods : findList) {
|
| | | tb.setId(goods.getId());
|
| | | if (!StringUtil.isNullOrEmpty(goods.getPictUrl()))
|
| | | tb.setPictUrl(goods.getPictUrl());
|
| | | taoBaoGoodsBriefDao.update(tb);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void setGoodsBriefDefault(TaoBaoGoodsBrief goodsBrief) {
|
| | |
|
| | | BigDecimal defaultZero = new BigDecimal("0");
|
| | |
|
| | | if (goodsBrief.getBiz30day() == null)
|
| | | goodsBrief.setBiz30day(0);
|
| | |
|
| | | if (goodsBrief.getCouponAmount() == null)
|
| | | goodsBrief.setCouponAmount(defaultZero);
|
| | |
|
| | | if (goodsBrief.getCouponLeftCount() == null)
|
| | | goodsBrief.setCouponLeftCount(0);
|
| | |
|
| | | if (goodsBrief.getCouponStartFee() == null)
|
| | | goodsBrief.setCouponStartFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getCouponTotalCount() == null)
|
| | | goodsBrief.setCouponTotalCount(0);
|
| | |
|
| | | if (goodsBrief.getDayLeft() == null)
|
| | | goodsBrief.setDayLeft(0);
|
| | |
|
| | | if (goodsBrief.getEventCreatorId() == null)
|
| | | goodsBrief.setEventCreatorId(0);
|
| | |
|
| | | if (goodsBrief.getHasRecommended() == null)
|
| | | goodsBrief.setHasRecommended(0);
|
| | |
|
| | | if (goodsBrief.getHasSame() == null)
|
| | | goodsBrief.setHasSame(0);
|
| | |
|
| | | if (goodsBrief.getIncludeDxjh() == null)
|
| | | goodsBrief.setIncludeDxjh(0);
|
| | |
|
| | | if (goodsBrief.getLeafCatId() == null)
|
| | | goodsBrief.setIncludeDxjh(0);
|
| | |
|
| | | if (goodsBrief.getReservePrice() == null)
|
| | | goodsBrief.setReservePrice(defaultZero);
|
| | |
|
| | | if (goodsBrief.getRfdRate() == null)
|
| | | goodsBrief.setRfdRate(0);
|
| | |
|
| | | if (goodsBrief.getRootCatId() == null)
|
| | | goodsBrief.setRootCatId(0);
|
| | |
|
| | | if (goodsBrief.getRootCatScore() == null)
|
| | | goodsBrief.setRootCatScore(0);
|
| | |
|
| | | if (goodsBrief.getSameItemPid() == null)
|
| | | goodsBrief.setSameItemPid(0L);
|
| | |
|
| | | if (goodsBrief.getSellerId() == null)
|
| | | goodsBrief.setSellerId(0L);
|
| | |
|
| | | if (goodsBrief.getTkCommFee() == null)
|
| | | goodsBrief.setTkCommFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTkRate() == null)
|
| | | goodsBrief.setTkRate(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTotalFee() == null)
|
| | | goodsBrief.setTotalFee(defaultZero);
|
| | |
|
| | | if (goodsBrief.getTotalNum() == null)
|
| | | goodsBrief.setTotalNum(0);
|
| | |
|
| | | if (goodsBrief.getUserType() == null)
|
| | | goodsBrief.setUserType(0);
|
| | |
|
| | | if (goodsBrief.getZkPrice() == null)
|
| | | goodsBrief.setZkPrice(defaultZero);
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoGoodsBrief getTaoBaoGoodsDetailForShare(Long auctionId, Long uid) throws ShareGoodsException {
|
| | | if (uid == null || uid == 0)
|
| | | throw new ShareGoodsException(201, "用户ID为空");
|
| | | if (auctionId == null || auctionId == 0)
|
| | | throw new ShareGoodsException(202, "商品ID为空");
|
| | | // 获取PID信息
|
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid == null)
|
| | | throw new ShareGoodsException(203, "未能获取到PID");
|
| | | String appId = tbPid.getPid().split("_")[2];
|
| | | // 获取淘客媒体信息
|
| | | TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId);
|
| | | if (config == null)
|
| | | throw new ShareGoodsException(204, "媒体数据为空");
|
| | |
|
| | | TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo();
|
| | | taoKeAppInfo.setAdzoneId(tbPid.getPid().split("_")[3]);
|
| | | taoKeAppInfo.setAppKey(config.getAppKey());
|
| | | taoKeAppInfo.setAppSecret(config.getAppSecret());
|
| | | taoKeAppInfo.setPid(tbPid.getPid());
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null;
|
| | | try {
|
| | | taoBaoGoodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId, taoKeAppInfo);
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | if (taoBaoGoodsBrief == null)
|
| | | throw new ShareGoodsException(204, "商品详情数据为空");
|
| | |
|
| | | return taoBaoGoodsBrief;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateBatchSelective(List<TaoBaoGoodsBrief> list) {
|
| | | taoBaoGoodsBriefMapper.updateBatchSelective(list);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.goods; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TBPid; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | | import com.yeshi.fanli.exception.share.ShareGoodsException; |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; |
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | import com.yeshi.fanli.service.inter.user.TBPidService; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | |
| | | @Service |
| | | public class TaoBaoGoodsBriefServiceImpl implements TaoBaoGoodsBriefService { |
| | | |
| | | @Resource |
| | | private HongBaoManageService hongBaoManageService; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper; |
| | | |
| | | @Resource |
| | | private TBPidService tbPidService; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Override |
| | | public String getGoodsUserHongBao(TaoBaoGoodsBrief goods, SystemEnum system) { |
| | | BigDecimal rate = hongBaoManageService.getFanLiRate(system); |
| | | return TaoBaoUtil.getGoodsHongBaoInfo(goods, rate,false); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getShareGoodsUserHongBao(TaoBaoGoodsBrief goods, SystemEnum system) { |
| | | BigDecimal rate = hongBaoManageService.getShareRate(system); |
| | | return TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByPrimaryKey(Long id) { |
| | | taoBaoGoodsBriefMapper.deleteByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteBatchByGoodsId(List<String> list) { |
| | | taoBaoGoodsBriefMapper.deleteBatchByGoodsId(list); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> queryByAuctionId(String auctionId) { |
| | | return taoBaoGoodsBriefMapper.queryByAuctionId(auctionId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> listExistById(List<String> list) { |
| | | if (list != null && list.size() > 0) |
| | | return taoBaoGoodsBriefMapper.listExistById(list); |
| | | else |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public int insertBatch(List<TaoBaoGoodsBrief> list) { |
| | | return taoBaoGoodsBriefMapper.insertBatch(list); |
| | | } |
| | | |
| | | @Override |
| | | public TaoBaoGoodsBrief selectByPrimaryKey(Long id) { |
| | | return taoBaoGoodsBriefMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public TaoBaoGoodsBrief selectByGoodsId(String goodsId) { |
| | | List<TaoBaoGoodsBrief> list = queryByAuctionId(goodsId); |
| | | if(list!=null&&list.size()>0){ |
| | | return list.get(list.size()-1); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void setGoodsBriefDefault(TaoBaoGoodsBrief goodsBrief) { |
| | | |
| | | BigDecimal defaultZero = new BigDecimal("0"); |
| | | |
| | | if (goodsBrief.getBiz30day() == null) |
| | | goodsBrief.setBiz30day(0); |
| | | |
| | | if (goodsBrief.getCouponAmount() == null) |
| | | goodsBrief.setCouponAmount(defaultZero); |
| | | |
| | | if (goodsBrief.getCouponLeftCount() == null) |
| | | goodsBrief.setCouponLeftCount(0); |
| | | |
| | | if (goodsBrief.getCouponStartFee() == null) |
| | | goodsBrief.setCouponStartFee(defaultZero); |
| | | |
| | | if (goodsBrief.getCouponTotalCount() == null) |
| | | goodsBrief.setCouponTotalCount(0); |
| | | |
| | | if (goodsBrief.getDayLeft() == null) |
| | | goodsBrief.setDayLeft(0); |
| | | |
| | | if (goodsBrief.getEventCreatorId() == null) |
| | | goodsBrief.setEventCreatorId(0); |
| | | |
| | | if (goodsBrief.getHasRecommended() == null) |
| | | goodsBrief.setHasRecommended(0); |
| | | |
| | | if (goodsBrief.getHasSame() == null) |
| | | goodsBrief.setHasSame(0); |
| | | |
| | | if (goodsBrief.getIncludeDxjh() == null) |
| | | goodsBrief.setIncludeDxjh(0); |
| | | |
| | | if (goodsBrief.getLeafCatId() == null) |
| | | goodsBrief.setIncludeDxjh(0); |
| | | |
| | | if (goodsBrief.getReservePrice() == null) |
| | | goodsBrief.setReservePrice(defaultZero); |
| | | |
| | | if (goodsBrief.getRfdRate() == null) |
| | | goodsBrief.setRfdRate(0); |
| | | |
| | | if (goodsBrief.getRootCatId() == null) |
| | | goodsBrief.setRootCatId(0); |
| | | |
| | | if (goodsBrief.getRootCatScore() == null) |
| | | goodsBrief.setRootCatScore(0); |
| | | |
| | | if (goodsBrief.getSameItemPid() == null) |
| | | goodsBrief.setSameItemPid(0L); |
| | | |
| | | if (goodsBrief.getSellerId() == null) |
| | | goodsBrief.setSellerId(0L); |
| | | |
| | | if (goodsBrief.getTkCommFee() == null) |
| | | goodsBrief.setTkCommFee(defaultZero); |
| | | |
| | | if (goodsBrief.getTkRate() == null) |
| | | goodsBrief.setTkRate(defaultZero); |
| | | |
| | | if (goodsBrief.getTotalFee() == null) |
| | | goodsBrief.setTotalFee(defaultZero); |
| | | |
| | | if (goodsBrief.getTotalNum() == null) |
| | | goodsBrief.setTotalNum(0); |
| | | |
| | | if (goodsBrief.getUserType() == null) |
| | | goodsBrief.setUserType(0); |
| | | |
| | | if (goodsBrief.getZkPrice() == null) |
| | | goodsBrief.setZkPrice(defaultZero); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public TaoBaoGoodsBrief getTaoBaoGoodsDetailForShare(String auctionId, Long uid) throws ShareGoodsException { |
| | | if (uid == null || uid == 0) |
| | | throw new ShareGoodsException(201, "用户ID为空"); |
| | | if (StringUtil.isNullOrEmpty(auctionId)) |
| | | throw new ShareGoodsException(202, "商品ID为空"); |
| | | // 获取PID信息 |
| | | TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); |
| | | if (tbPid == null) |
| | | throw new ShareGoodsException(203, "未能获取到PID"); |
| | | String appId = tbPid.getPid().split("_")[2]; |
| | | // 获取淘客媒体信息 |
| | | TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(appId); |
| | | if (config == null) |
| | | throw new ShareGoodsException(204, "媒体数据为空"); |
| | | |
| | | TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo(); |
| | | taoKeAppInfo.setAdzoneId(tbPid.getPid().split("_")[3]); |
| | | taoKeAppInfo.setAppKey(config.getAppKey()); |
| | | taoKeAppInfo.setAppSecret(config.getAppSecret()); |
| | | taoKeAppInfo.setPid(tbPid.getPid()); |
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = null; |
| | | try { |
| | | taoBaoGoodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId, taoKeAppInfo); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | if (taoBaoGoodsBrief == null) |
| | | throw new ShareGoodsException(204, "商品详情数据为空"); |
| | | |
| | | return taoBaoGoodsBrief; |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> listByShopId(long start, int count, Long shopId) { |
| | | return taoBaoGoodsBriefMapper.listByShopId(start, count, shopId); |
| | | } |
| | | |
| | | @Override |
| | | public long countByShopId(Long shopId) { |
| | | return taoBaoGoodsBriefMapper.countByShopId(shopId); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> filterOffLineGoods(List<TaoBaoGoodsBrief> goodsList) { |
| | | int page = goodsList.size() % 40 == 0 ? goodsList.size() / 40 -1 : goodsList.size() / 40; |
| | | List<TaoBaoGoodsBrief> flist = new ArrayList<>(); |
| | | for (int i = 0; i <= page; i++) { |
| | | List<TaoBaoGoodsBrief> list = goodsList.subList(i * 40, |
| | | i * 40 + 40 > goodsList.size() ?goodsList.size(): i * 40 + 40 ); |
| | | String ids = ""; |
| | | for (TaoBaoGoodsBrief goods : list) { |
| | | ids += goods.getAuctionId() + ","; |
| | | } |
| | | ids = ids.endsWith(",") ? ids.substring(0, ids.length() - 1) : ids; |
| | | Map<String, TaoBaoGoodsBrief> goodsMap = new HashMap<>(); |
| | | try { |
| | | List<TaoBaoGoodsBrief> finalList = TaoKeApiUtil.getBatchGoodsInfos(ids); |
| | | if (finalList != null) |
| | | for (TaoBaoGoodsBrief ggods : finalList) |
| | | goodsMap.put(ggods.getAuctionId(), ggods); |
| | | |
| | | for (int j = 0; j < list.size(); j++) { |
| | | if (goodsMap.get(list.get(j).getAuctionId()) == null) { |
| | | list.remove(j); |
| | | j--; |
| | | } |
| | | } |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | flist.addAll(list); |
| | | } |
| | | return flist; |
| | | } |
| | | |
| | | } |