From 50e074067ab1406a52023300239189165d9cdca7 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期三, 05 六月 2019 15:00:03 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java | 171 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 97 insertions(+), 74 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java index a3158d8..597b7df 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java @@ -17,8 +17,10 @@ import com.yeshi.fanli.entity.brand.BrandClass; import com.yeshi.fanli.entity.brand.BrandClassShop; import com.yeshi.fanli.entity.goods.CommonGoods; +import com.yeshi.fanli.entity.taobao.SearchFilter; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra; +import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; import com.yeshi.fanli.entity.taobao.TaoBaoShop; import com.yeshi.fanli.exception.brand.BrandClassShopException; import com.yeshi.fanli.service.inter.brand.BrandClassShopService; @@ -31,25 +33,26 @@ 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; import com.yeshi.fanli.vo.brand.TaoBaoShopVO; import net.sf.json.JSONObject; @Service public class BrandClassShopServiceImpl implements BrandClassShopService { - + @Resource private BrandClassShopMapper brandClassShopMapper; - + @Resource private CommonGoodsService commonGoodsService; - + @Resource private TaoBaoShopService taoBaoShopService; - + @Resource private TaoBaoShopHistoryService taoBaoShopHistoryService; - + @Resource private HongBaoManageService manageService; @@ -58,34 +61,31 @@ @Resource private TaoBaoGoodsBriefService taoBaoGoodsBriefService; - - @Override - public List<BrandClassShop> getExistByShopIds(List<Long> list){ + public List<BrandClassShop> getExistByShopIds(List<Long> list) { return brandClassShopMapper.getExistByShopIds(list); } - @Override @Transactional - public String saveShopInfo(Long cid, List<Long> list) throws BrandClassShopException{ + public String saveShopInfo(Long cid, List<Long> list) throws BrandClassShopException { if (list == null || list.size() == 0) { throw new BrandClassShopException(1, "璇烽�夋嫨搴楅摵"); } - + if (cid == null) { throw new BrandClassShopException(1, "璇烽�夋嫨搴楅摵绫诲瀷"); } - + String shopIds = ""; BrandClass brandClass = new BrandClass(cid); - - for (Long shopId: list) { - List<CommonGoods> listGoods= commonGoodsService.listBySellerId(shopId); - + + for (Long shopId : list) { + List<CommonGoods> listGoods = commonGoodsService.listBySellerId(shopId); + TaoBaoShop taoBaoShop = null; - for (CommonGoods commonGoods: listGoods) { + for (CommonGoods commonGoods : listGoods) { try { taoBaoShop = TaoBaoUtil.getTaoBaoShopDetailByAuctionId(commonGoods.getGoodsId()); if (taoBaoShop != null && taoBaoShop.getId() != null) { @@ -95,19 +95,19 @@ e.printStackTrace(); } } - + if (taoBaoShop == null) { shopIds = shopIds + "," + shopId; continue; } - + TaoBaoShop current = taoBaoShopService.selectByPrimaryKey(shopId); if (current == null) { taoBaoShopService.insertSelective(taoBaoShop); } else { taoBaoShopService.updateByPrimaryKeySelective(taoBaoShop); } - + BrandClassShop brandClassShop = brandClassShopMapper.getByShopIdAndCid(cid, shopId); if (brandClassShop == null) { brandClassShop = new BrandClassShop(); @@ -123,33 +123,33 @@ } return shopIds; } - - + @Override @Transactional - public void changeShopInfo(MultipartFile file, Long id, Long cid, String shopName, Integer state, Integer top) throws BrandClassShopException{ - + public void changeShopInfo(MultipartFile file, Long id, Long cid, String shopName, Integer state, Integer top) + throws BrandClassShopException { + if (id == null) { throw new BrandClassShopException(1, "鏁版嵁涓虹┖锛氳閫夋嫨搴楅摵"); } - + if (cid == null) { throw new BrandClassShopException(1, "璇烽�夋嫨搴楅摵绫诲瀷"); } - + BrandClassShop current = brandClassShopMapper.selectByPrimaryKey(id); if (current == null) { throw new BrandClassShopException(1, "璇ユ暟鎹凡涓嶅瓨鍦�"); } - + TaoBaoShop shop = current.getShop(); if (shop == null) { throw new BrandClassShopException(1, "搴楅摵淇℃伅宸蹭笉瀛樺湪"); } - + // 鑷畾涔夊浘鐗� taoBaoShopService.changeInfo(file, shop.getId(), shopName); - + BrandClassShop updateshop = new BrandClassShop(); updateshop.setState(state); updateshop.setTop(top); @@ -157,7 +157,6 @@ updateshop.setBrandClass(new BrandClass(cid)); brandClassShopMapper.updateByPrimaryKeySelective(updateshop); } - @Override public List<BrandClassShop> listQuery(long start, int count, String key, Long cid, Integer state) { @@ -165,23 +164,23 @@ if (listQuery == null || listQuery.size() == 0) { return listQuery; } - + for (BrandClassShop brandClassShop : listQuery) { TaoBaoShop shop = brandClassShop.getShop(); if (shop != null) { long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId()); brandClassShop.setCouponNum(couponNum); - + String shopLink = shop.getShopLink(); if (StringUtil.isNullOrEmpty(shopLink)) { shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId())); } - + String shopNameCustom = shop.getShopNameCustom(); if (!StringUtil.isNullOrEmpty(shopNameCustom)) { shop.setShopName(shopNameCustom); } - + String shopIconCustom = shop.getShopIconCustom(); if (!StringUtil.isNullOrEmpty(shopIconCustom)) { shop.setShopIcon(shopIconCustom); @@ -191,12 +190,10 @@ return listQuery; } - @Override public long countQuery(String key, Long cid, Integer state) { return brandClassShopMapper.countQuery(key, cid, state); } - @Override @Transactional @@ -204,11 +201,11 @@ if (list == null || list.size() == 0) { return; } - for (Long id: list) { + for (Long id : list) { brandClassShopMapper.deleteByPrimaryKey(id); } } - + @Override public void deleteBatchByClassId(List<Long> list) { if (list == null || list.size() == 0) { @@ -216,62 +213,61 @@ } brandClassShopMapper.deleteBatchByClassId(list); } - - + @Override - public void updateOrder(Long id, Integer moveType) throws BrandClassShopException, Exception{ + public void updateOrder(Long id, Integer moveType) throws BrandClassShopException, Exception { if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) { throw new BrandClassShopException(1, "浼犻�掔殑绫诲瀷涓嶆纭�"); } - + if (id == null) { throw new BrandClassShopException(1, "ID涓嶈兘涓虹┖"); } - + BrandClassShop resultObj = brandClassShopMapper.selectByPrimaryKey(id); if (resultObj == null) { throw new BrandClassShopException(1, "鎿嶄綔鏁版嵁宸蹭笉瀛樺湪"); } - + BrandClass brandClass = resultObj.getBrandClass(); if (brandClass == null) { throw new BrandClassShopException(1, "鍒嗙被鏁版嵁宸蹭笉瀛樺湪"); } - + Integer oldOrder = resultObj.getOrderby(); - BrandClassShop changeObj = brandClassShopMapper.getByAdjoinOrder(brandClass.getId(),oldOrder, moveType); - - if (changeObj == null ) { + BrandClassShop changeObj = brandClassShopMapper.getByAdjoinOrder(brandClass.getId(), oldOrder, moveType); + + if (changeObj == null) { throw new BrandClassShopException(1, "宸茬粡鍦ㄦ渶杈圭紭锛屾棤鍙氦鎹㈢殑浣嶇疆"); } // 浜ゆ崲鎺掑簭搴忓彿 resultObj.setOrderby(changeObj.getOrderby()); changeObj.setOrderby(oldOrder); - + brandClassShopMapper.updateByPrimaryKeySelective(changeObj); brandClassShopMapper.updateByPrimaryKeySelective(resultObj); } - + @Override @Cacheable(value = "brandCache", key = "'listEffectiveCache-'+#page+'-'+#cid") public JSONObject listEffectiveCache(int page, Long cid) { long countShop = 0; - + if (cid != null && cid <= 0) { cid = null; } - + List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>(); // 绗竴椤� 鏌ヨ鍏ㄩ儴鍒嗙被涓嬪簵閾� - if (page == 1 && cid != null) { + if (page == 1 && cid != null) { List<BrandClassShop> list = brandClassShopMapper.listEffective(cid); if (list == null) { list = new ArrayList<BrandClassShop>(); } else if (list.size() > 0) { countShop = brandClassShopMapper.countEffective(cid); } - + for (BrandClassShop brandClassShop : list) { TaoBaoShop shop = brandClassShop.getShop(); if (shop != null) { @@ -279,53 +275,53 @@ if (StringUtil.isNullOrEmpty(shopLink)) { shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId())); } - + String shopNameCustom = shop.getShopNameCustom(); if (!StringUtil.isNullOrEmpty(shopNameCustom)) { shop.setShopName(shopNameCustom); } - + String shopIconCustom = shop.getShopIconCustom(); if (!StringUtil.isNullOrEmpty(shopIconCustom)) { shop.setShopIcon(shopIconCustom); } - + listShop.add(shop); } } } - + JSONObject data = new JSONObject(); data.put("countShop", countShop); data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop)); - + long count = 0; - List<TaoBaoShopVO> listInfo = taoBaoShopService.listBrandShopinfo((page-1)*Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid); + List<TaoBaoShopVO> listInfo = taoBaoShopService.listBrandShopinfo((page - 1) * Constant.PAGE_SIZE, + Constant.PAGE_SIZE, cid); if (listInfo == null) { listInfo = new ArrayList<TaoBaoShopVO>(); } else if (listInfo.size() > 0) { count = taoBaoShopService.countBrandShopinfo(cid); } - + BigDecimal proportion = manageService.getFanLiRate(); for (TaoBaoShopVO taoBaoShopVO : listInfo) { - + String shopLink = taoBaoShopVO.getShopLink(); if (StringUtil.isNullOrEmpty(shopLink)) { taoBaoShopVO.setShopLink(TaoBaoUtil.getShopLink(taoBaoShopVO.getId())); } - + String shopNameCustom = taoBaoShopVO.getShopNameCustom(); if (!StringUtil.isNullOrEmpty(shopNameCustom)) { taoBaoShopVO.setShopName(shopNameCustom); } - + String shopIconCustom = taoBaoShopVO.getShopIconCustom(); if (!StringUtil.isNullOrEmpty(shopIconCustom)) { taoBaoShopVO.setShopIcon(shopIconCustom); } - - + List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>(); List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief(); for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) { @@ -335,12 +331,10 @@ } data.put("count", count); data.put("list", JsonUtil.getApiCommonGson().toJson(listInfo)); - + return data; } - - - + @Override public void addClick(Long shopId) { BrandClassShop brandClassShop = brandClassShopMapper.getByShopId(shopId); @@ -349,13 +343,42 @@ if (browseNum == null) { browseNum = 0L; } - + BrandClassShop classShop = new BrandClassShop(); classShop.setId(brandClassShop.getId()); - classShop.setBrowseNum(browseNum ++); + classShop.setBrowseNum(browseNum++); brandClassShopMapper.updateByPrimaryKeySelective(classShop); } } - - + + @Override + public void updateShopGoods() { + // 鏌ヨ搴楅摵 + List<BrandClassShop> shopList = listQuery(0, 1000, "", null, BrandClassShop.STATE_VALID); + if (shopList != null) + for (BrandClassShop shop : shopList) { + SearchFilter sf = new SearchFilter(); + sf.setKey(shop.getShop().getShopName().replace("瀹樻柟鏃楄埌搴�", "").replace("鏃楄埌搴�", "")); + sf.setPage(1); + sf.setPageSize(100); + TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(sf); + List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); + if (result != null && result.getTaoBaoGoodsBriefs() != null) + for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) { + if (goods.getSellerId().longValue() == shop.getShop().getId()) { + if (taoBaoGoodsBriefService.queryByAuctionId(goods.getAuctionId()).size() == 0) { + goods.setCreatetime(new Date()); + goods.setState(0); + goods.setUpdatetime(new Date()); + goodsList.add(goods); + } + } + } + + if (goodsList.size() > 0) + taoBaoGoodsBriefService.insertBatch(goodsList); + } + + } + } -- Gitblit v1.8.0