From 7ad7905f32ef6b2d67bbd45260a0413be904fa8d Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期五, 20 九月 2019 14:33:08 +0800 Subject: [PATCH] 品牌 、金币任务bug --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java | 187 +++++++++++++++++++++++++--------------------- 1 files changed, 102 insertions(+), 85 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java index 6b048af..481652c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.yeshi.fanli.service.impl.brand; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -11,31 +12,33 @@ import com.yeshi.fanli.dao.brand.BrandShopCaheDao; import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper; +import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; +import com.yeshi.fanli.entity.brand.BrandGoodsCahe; import com.yeshi.fanli.entity.brand.BrandInfo; -import com.yeshi.fanli.entity.brand.BrandShopCahe; -import com.yeshi.fanli.entity.taobao.SearchShopFilter; +import com.yeshi.fanli.entity.jd.JDGoods; +import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoShop; -import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo; import com.yeshi.fanli.exception.brand.BrandInfoException; import com.yeshi.fanli.service.inter.brand.BrandClassShopService; import com.yeshi.fanli.service.inter.brand.BrandGoodsCaheService; import com.yeshi.fanli.service.inter.brand.BrandInfoService; +import com.yeshi.fanli.service.inter.brand.BrandShopCaheService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.lable.QualityGoodsService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory; -import com.yeshi.fanli.util.taobao.TaoKeApiUtil; +import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.vo.brand.BrandInfoVO; import com.yeshi.fanli.vo.brand.TaoBaoShopVO; +import com.yeshi.fanli.vo.goods.GoodsDetailVO; @Service public class BrandInfoServiceImpl implements BrandInfoService { - + @Resource private BrandInfoMapper brandInfoMapper; - + @Resource private HongBaoManageService hongBaoManageService; @@ -47,28 +50,29 @@ @Resource private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; - + @Resource private BrandClassShopService brandClassShopService; @Resource private BrandShopCaheDao brandShopCaheDao; - + @Resource private BrandGoodsCaheService brandGoodsCaheService; - - - + + @Resource + private BrandShopCaheService brandShopCaheService; + @Override - public void saveObject(BrandInfo record) throws BrandInfoException{ + public void saveObject(BrandInfo record) throws BrandInfoException { String name = record.getName(); if (name == null || name.trim().length() == 0) throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖"); - + Integer state = record.getState(); if (state == null) record.setState(0); - + Long id = record.getId(); if (id == null) { record.setCreateTime(new Date()); @@ -78,36 +82,33 @@ BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id); if (resultObj == null) throw new BrandInfoException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); - + record.setCreateTime(resultObj.getCreateTime()); record.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKey(record); } } - - + @Override public int deleteBatchByPrimaryKey(List<Long> list) { return brandInfoMapper.deleteBatchByPrimaryKey(list); } - @Override - public List<BrandInfo> listQuery(long start, int count, String key, Integer state) { - return null; + public List<BrandInfo> listQuery(long start, int count, String key, Long cid, Integer state) { + return brandInfoMapper.listQuery(start, count, key, cid, state); } - @Override - public long countQuery(String key, Integer state) { - return 0; + public long countQuery(String key, Long cid, Integer state) { + return brandInfoMapper.countQuery(key, cid, state); } - + @Override @Cacheable(value = "brandCache", key = "'listValidBrandInfoCache-'+#cid") public List<BrandInfo> listValidBrandInfoCache(Long cid) { List<BrandInfo> listInfo = new ArrayList<BrandInfo>(); - + List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid); if (listShop == null || listShop.size() == 0) return listInfo; @@ -120,17 +121,16 @@ } return listInfo; } - - + @Override @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid") public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid) { List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>(); - + List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid); if (listShop == null || listShop.size() == 0) return listInfo; - + for (TaoBaoShopVO taoBaoShopVO : listShop) { String shopNameCustom = taoBaoShopVO.getShopNameCustom(); if (!StringUtil.isNullOrEmpty(shopNameCustom)) { @@ -140,7 +140,7 @@ if (!StringUtil.isNullOrEmpty(shopIconCustom)) { taoBaoShopVO.setShopIcon(shopIconCustom); } - + BrandInfoVO brandInfoVO = new BrandInfoVO(); brandInfoVO.setId(taoBaoShopVO.getId()); brandInfoVO.setName(taoBaoShopVO.getShopName()); @@ -151,78 +151,95 @@ return listInfo; } - @Override - public long countBrandInfo(Long cid){ + public long countBrandInfo(Long cid) { return brandClassShopService.countBrandShopinfo(cid); } - - + + @Override public void addShopAndGoods(long start, int count) { List<BrandInfo> list = brandInfoMapper.listValidAll(start, count); - if(list == null || list.size() == 0) + if (list == null || list.size() == 0) return; - - for (BrandInfo brandInfo: list) { + + for (BrandInfo brandInfo : list) { String key = brandInfo.getName(); - if(StringUtil.isNullOrEmpty(key)) + if (StringUtil.isNullOrEmpty(key)) continue; - - // 娣诲姞搴楅摵 - addBrandShop(brandInfo); - - // 娣诲姞搴楅摵 + + // 娣诲姞鍟嗗搧 int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo); - + brandInfo.setGoodsTotal(goodsTotal); + brandInfo.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKeySelective(brandInfo); } } - - - /** - * 鍔犲叆鍝佺墝搴楅摵 - * @param brandInfo - */ - private void addBrandShop(BrandInfo brandInfo) { - SearchShopFilter filter = new SearchShopFilter(); - filter.setKey(brandInfo.getName()); - filter.setPageSize(100); - filter.setTmall(true); - filter.setSort("锛坱otal_auction_des"); - - - TaoBaoShopInfo taoBaoShop = null; - for(int page = 1; page < 3; page++) { - filter.setPage(page); - List<TaoBaoShopInfo> listShop = TaoKeApiUtil.searchShop(filter); - if(listShop == null || listShop.size() == 0) + + @Override + public long countValidByCid(Long cid) { + return brandInfoMapper.countValidByCid(cid); + } + + @Override + public long countValidByCidToApp(Long cid) { + return brandInfoMapper.countValidByCidToApp(cid); + } + + @Override + @Cacheable(value = "brandCache", key = "'listValidByCidToApp-'+#cid") + public List<BrandInfo> listValidByCidToApp(Long cid) { + if (cid == null) + return null; + return brandInfoMapper.listValidByCidToApp(cid); + } + + @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#start +'-'+#cid") + @Override + public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) { + List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid); + if (list == null || list.size() == 0) + return null; + + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); + BigDecimal shareRate = hongBaoManageService.getShareRate(); + + List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>(); + for (int i = 0; i < list.size(); i++) { + BrandInfoVO brand = list.get(i); + if (brand == null) continue; - for (TaoBaoShopInfo shop: listShop) { - String shopTitle = shop.getShopTitle(); - if(StringUtil.isNullOrEmpty(shopTitle)) + List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId()); + if (listGoods == null || listGoods.size() < 3) + continue; + + List<GoodsDetailVO> listGoodsVO = new ArrayList<GoodsDetailVO>(); + for (BrandGoodsCahe brandGoods : listGoods) { + JDGoods goodsJD = brandGoods.getGoodsJD(); + if (goodsJD != null) { + listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, fanLiRate, shareRate)); continue; - - if(!shopTitle.contains("鏃楄埌搴�")) + } + + TaoBaoGoodsBrief goodsTB = brandGoods.getGoodsTB(); + if (goodsTB != null) { + listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, null, fanLiRate, shareRate)); continue; - - taoBaoShop = shop; - break; + } + + PDDGoodsDetail goodsPDD = brandGoods.getGoodsPDD(); + if (goodsPDD != null) { + listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, fanLiRate, shareRate)); + continue; + } } - - if (taoBaoShop != null) - break; + + if (listGoodsVO.size() >= 3) { + brand.setListGoods(listGoodsVO); + listInfo.add(brand); + } } - - BrandShopCahe brandShop = new BrandShopCahe(); - brandShop.setBrandId(brandInfo.getId()); - brandShop.setShop(ShopInfoVOFactory.convertTaoBaoShop(taoBaoShop)); - brandShop.setCreateTime(new Date()); - brandShop.setUpdateTime(new Date()); - brandShopCaheDao.save(brandShop); + return listInfo; } - - - } -- Gitblit v1.8.0