| | |
| | | package com.yeshi.fanli.service.impl.goods;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.ibatis.annotations.Param;
|
| | | 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.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.exception.ShareGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | 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.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) {
|
| | | 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 void deleteByPrimaryKey(Long id) {
|
| | | taoBaoGoodsBriefMapper.deleteByPrimaryKey(id);
|
| | | }
|
| | | |
| | | @Override
|
| | | public void deleteBatchByGoodsId(List<Long> list) {
|
| | | taoBaoGoodsBriefMapper.deleteBatchByGoodsId(list);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> queryByAuctionId(Long auctionId) {
|
| | | return taoBaoGoodsBriefMapper.queryByAuctionId(auctionId);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<Long> listExistById(List<Long> list) {
|
| | | if (list != null && list.size() > 0)
|
| | | return taoBaoGoodsBriefMapper.listExistById(list);
|
| | | else
|
| | | return null;
|
| | | }
|
| | |
|
| | | @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 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 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);
|
| | | }
|
| | | |
| | | }
|
| | | 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; |
| | | } |
| | | |
| | | } |