From aa552facf6d833acab0d3e3e29bda2a0fb826ffe Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 25 十一月 2019 16:14:13 +0800 Subject: [PATCH] 品牌缓存生效 --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java | 75 +++++++++++++++++++++++++++++++++---- 1 files changed, 66 insertions(+), 9 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 48c7fdb..6e2cf5f 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 @@ -17,9 +17,11 @@ import com.yeshi.fanli.dao.brand.BrandShopCaheDao; import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper; +import com.yeshi.fanli.dto.ConfigParamsDTO; 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.jd.JDGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoShop; @@ -79,6 +81,10 @@ if (StringUtil.isNullOrEmpty(name)) throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖"); + String shopKey = record.getShopKey(); + if (StringUtil.isNullOrEmpty(shopKey)) + record.setShopKey(name); + String searchKey = record.getSearchKey(); if (StringUtil.isNullOrEmpty(searchKey)) record.setSearchKey(name); @@ -109,16 +115,19 @@ if (picture != null && picture.trim().length() > 0) { // 鍒犻櫎鑰佸浘 - if (picture != null && picture.trim().length() > 0 && !Constant.IS_TEST) { - COSManager.getInstance().deleteFile(picture); + if (resultObj.getIcon() != null && resultObj.getIcon().trim().length() > 0 && !Constant.IS_TEST) { + COSManager.getInstance().deleteFile(resultObj.getIcon()); }; // 瀛樺偍鏂板浘 record.setIcon(picture); } else { record.setIcon(resultObj.getIcon()); } - - record.setGoodsTotal(resultObj.getGoodsTotal()); + if (state == 0){ + record.setGoodsTotal(0); + } else { + record.setGoodsTotal(resultObj.getGoodsTotal()); + } record.setCreateTime(resultObj.getCreateTime()); record.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKey(record); @@ -141,6 +150,13 @@ public void run() { int goodsTotal = brandGoodsCaheService.addBrandGoods(record); record.setGoodsTotal(goodsTotal); + + List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(record.getId()); + if (listshop == null) { + record.setShopTotal(0); + } else { + record.setShopTotal(listshop.size()); + } brandInfoMapper.updateByPrimaryKeySelective(record); } }); @@ -254,8 +270,42 @@ // 鍒犻櫎搴楅摵 brandShopCaheService.removeAgoByDate(date); + + long count = brandInfoMapper.countValidByCid(null); + if (count == 0) + return; + + for (int page = 0; page < (count / 100) + 1; page++) { + updateTotalGoods(page * 100, 100); + } } + /** + * 鏇存柊鍟嗗搧鏁伴噺 + * @param start + * @param count + */ + private void updateTotalGoods(long start, int count) { + List<BrandInfo> list = brandInfoMapper.listValidAll(start, count); + if (list == null || list.size() == 0) + return; + + for (BrandInfo brandInfo : list) { + long goodsTotal = brandGoodsCaheService.countByBrandId(brandInfo.getId()); + + BrandInfo updateInfo = new BrandInfo(); + updateInfo.setId(brandInfo.getId()); + updateInfo.setGoodsTotal((int)goodsTotal); + List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(brandInfo.getId()); + if (listshop == null) { + updateInfo.setShopTotal(0); + } else { + updateInfo.setShopTotal(listshop.size()); + } + + brandInfoMapper.updateByPrimaryKeySelective(updateInfo); + } + } @Override @@ -275,6 +325,13 @@ brandInfo.setGoodsTotal(goodsTotal); brandInfo.setUpdateTime(new Date()); + + List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(brandInfo.getId()); + if (listshop == null) { + brandInfo.setShopTotal(0); + } else { + brandInfo.setShopTotal(listshop.size()); + } brandInfoMapper.updateByPrimaryKeySelective(brandInfo); } } @@ -297,7 +354,7 @@ return brandInfoMapper.listValidByCidToApp(cid); } - @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#start +'-'+#cid") + @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#cid") @Override public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) { List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid); @@ -306,7 +363,7 @@ BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); BigDecimal shareRate = hongBaoManageService.getShareRate(); - + ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE); List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>(); for (int i = 0; i < list.size(); i++) { BrandInfoVO brand = list.get(i); @@ -321,19 +378,19 @@ for (BrandGoodsCahe brandGoods : listGoods) { JDGoods goodsJD = brandGoods.getGoodsJD(); if (goodsJD != null) { - listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, fanLiRate, shareRate)); + listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, configParamsDTO)); continue; } TaoBaoGoodsBrief goodsTB = brandGoods.getGoodsTB(); if (goodsTB != null) { - listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, null, fanLiRate, shareRate)); + listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, configParamsDTO)); continue; } PDDGoodsDetail goodsPDD = brandGoods.getGoodsPDD(); if (goodsPDD != null) { - listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, fanLiRate, shareRate)); + listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, configParamsDTO)); continue; } } -- Gitblit v1.8.0