package com.yeshi.fanli.service.impl.brand;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
|
import com.yeshi.fanli.dto.jd.JDShopInfo;
|
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
|
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
|
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
|
import com.yeshi.fanli.entity.brand.BrandInfo;
|
import com.yeshi.fanli.entity.brand.BrandShopCahe;
|
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
|
import com.yeshi.fanli.service.inter.brand.BrandShopCaheService;
|
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory;
|
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
|
import com.yeshi.fanli.vo.goods.ShopInfoVO;
|
|
@Service
|
public class BrandShopCaheServiceImpl implements BrandShopCaheService {
|
|
@Resource
|
private BrandShopCaheDao brandShopCaheDao;
|
|
@Resource
|
private TaoBaoShopService taoBaoShopService;
|
|
|
/**
|
* 淘宝店铺
|
* @param brandInfo
|
* @return
|
*/
|
@Override
|
public boolean addBrandShopTB(BrandInfo brandInfo, Long auctionId, Long sellerId) {
|
TaoBaoShop taoBaoShop = taoBaoShopService.getTaoBaoShop(auctionId, sellerId);
|
if (taoBaoShop == null)
|
return true;
|
|
ShopInfoVO shopInfoVO = ShopInfoVOFactory.convertTaoBaoShop(taoBaoShop);
|
shopInfoVO.setShopIcon(brandInfo.getIcon());
|
|
BrandShopCahe brandShop = new BrandShopCahe();
|
brandShop.setBrandId(brandInfo.getId());
|
brandShop.setShop(shopInfoVO);
|
brandShop.setCreateTime(new Date());
|
brandShopCaheDao.insert(brandShop);
|
return false;
|
}
|
|
|
/**
|
* 京东
|
*
|
* @param brandInfo
|
* @return
|
*/
|
@Override
|
public void addBrandShopJD(BrandInfo brandInfo, JDShopInfo shopInfo) {
|
ShopInfoVO shopInfoVO = ShopInfoVOFactory.convertJDShop(shopInfo);
|
shopInfoVO.setShopIcon(brandInfo.getIcon());
|
|
BrandShopCahe brandShop = new BrandShopCahe();
|
brandShop.setBrandId(brandInfo.getId());
|
brandShop.setShop(shopInfoVO);
|
brandShop.setCreateTime(new Date());
|
brandShopCaheDao.insert(brandShop);
|
}
|
|
|
/**
|
* 拼多多
|
* @param brandInfo
|
* @return
|
*/
|
@Override
|
public int addBrandShopPDD(BrandInfo brandInfo) {
|
String shopKey = brandInfo.getShopKeyPDD();
|
if (StringUtil.isNullOrEmpty(shopKey))
|
return 0;
|
|
String searchKey = brandInfo.getSearchKeyPDD();
|
if (StringUtil.isNullOrEmpty(searchKey))
|
searchKey = brandInfo.getName();
|
|
ShopInfoVO shopInfoVO = null;
|
PDDSearchFilter pddfilter = new PDDSearchFilter();
|
pddfilter.setKw(searchKey);
|
pddfilter.setPage(1);
|
pddfilter.setPageSize(100);
|
pddfilter.setSortType(6);
|
pddfilter.setMerchantType(3);
|
|
PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
|
if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) {
|
boolean addShop = true;
|
List<PDDGoodsDetail> goodsList = result.getGoodsList();
|
for (PDDGoodsDetail goods : goodsList) {
|
// 包含店铺id 、包含品牌名称
|
String mallName = goods.getMallName();
|
if(addShop && !StringUtil.isNullOrEmpty(mallName) && mallName.toLowerCase().contains(shopKey.toLowerCase())
|
&& goods.getMallId() != null){
|
shopInfoVO = new ShopInfoVO();
|
shopInfoVO.setId(goods.getMallId().toString());
|
shopInfoVO.setShopName(mallName);
|
addShop = false;
|
break;
|
}
|
}
|
}
|
|
if (shopInfoVO != null) {
|
shopInfoVO.setShopIcon(brandInfo.getIcon());
|
shopInfoVO.setUserType(30);
|
shopInfoVO.setShopLink("https://mobile.yangkeduo.com/mall_page.html?mall_id=" + shopInfoVO.getId());
|
BrandShopCahe brandShop = new BrandShopCahe();
|
brandShop.setBrandId(brandInfo.getId());
|
brandShop.setShop(shopInfoVO);
|
brandShop.setCreateTime(new Date());
|
brandShopCaheDao.insert(brandShop);
|
return 1;
|
}
|
return 0;
|
}
|
|
|
|
@Override
|
public List<BrandShopCahe> getByBrandId(Long brandId){
|
return brandShopCaheDao.getByBrandId(brandId);
|
}
|
|
|
@Override
|
public void removeAgoByDate(Date createTime) {
|
brandShopCaheDao.removeAgoByDate(createTime);
|
}
|
|
@Override
|
public void removeByBrandId(Long brandId) {
|
brandShopCaheDao.removeByBrandId(brandId);
|
}
|
|
@Override
|
public void removeByDateAndType(Long brandId, int type, Date date) {
|
brandShopCaheDao.removeByDate(brandId, type, date);
|
}
|
|
|
}
|