From ddf5db7d31af51fcf697eac0cee7dd46ff73bcc1 Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期二, 18 二月 2020 12:50:49 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java | 154 ++++++++++++++++++++++++++------------------------- 1 files changed, 79 insertions(+), 75 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 5689cdb..c4594b8 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,7 +1,6 @@ package com.yeshi.fanli.service.impl.brand; import java.io.InputStream; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -37,6 +36,7 @@ import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.FilePathEnum; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.vo.brand.BrandInfoVO; @@ -75,8 +75,7 @@ @Resource(name = "taskExecutor") private TaskExecutor executor; - - + @Override public void saveObject(MultipartFile file, BrandInfo record) throws BrandInfoException { String name = record.getName(); @@ -84,20 +83,19 @@ throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖"); BrandClass brandClass = record.getBrandClass(); - if (brandClass ==null || brandClass.getId() == null) + if (brandClass == null || brandClass.getId() == null) throw new BrandInfoException(1, "鍒嗙被涓嶈兘涓虹┖"); - + BrandInfo existBrand = brandInfoMapper.selectByUniqueName(name.trim(), brandClass.getId(), record.getId()); if (existBrand != null) throw new BrandInfoException(1, "璇ュ垎绫讳腑宸插瓨鍦細" + name.trim()); - + Integer state = record.getState(); if (state == null) { state = 0; record.setState(state); } - - + String picture = null; if (file != null) { try { // 鍥剧墖涓婁紶 @@ -106,27 +104,27 @@ throw new BrandInfoException(1, "鍥剧墖涓婁紶澶辫触"); } } - + String searchKey = record.getSearchKey(); if (!StringUtil.isNullOrEmpty(searchKey)) { if (StringUtil.isNullOrEmpty(record.getSearchKeyJD())) record.setSearchKeyJD(searchKey); - + if (StringUtil.isNullOrEmpty(record.getSearchKeyPDD())) record.setSearchKeyPDD(searchKey); } - + String shopKey = record.getShopKey(); if (!StringUtil.isNullOrEmpty(shopKey)) { if (StringUtil.isNullOrEmpty(record.getShopKeyJD())) record.setShopKeyJD(shopKey); - + if (StringUtil.isNullOrEmpty(record.getShopKeyPDD())) record.setShopKeyPDD(shopKey); } record.setName(name.trim()); record.setUpdateTime(new Date()); - + Long id = record.getId(); if (id == null) { record.setIcon(picture); @@ -135,7 +133,7 @@ record.setShopTotal(0); record.setCreateTime(new Date()); brandInfoMapper.insert(record); - + BrandInfo resultObj = new BrandInfo(); resultObj.setId(record.getId()); resultObj.setOrder(Integer.valueOf(record.getId().toString())); @@ -149,14 +147,15 @@ // 鍒犻櫎鑰佸浘 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()); } - - if (state == 0){ + + if (state == 0) { record.setGoodsTotal(0); record.setShopTotal(0); } else { @@ -167,8 +166,8 @@ record.setWeight(resultObj.getWeight()); record.setCreateTime(resultObj.getCreateTime()); brandInfoMapper.updateByPrimaryKey(record); - - if (state == 0){ + + if (state == 0) { executor.execute(new Runnable() { @Override public void run() { @@ -184,7 +183,7 @@ @Override public void run() { BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(record); - + BrandInfo update = new BrandInfo(); update.setId(record.getId()); update.setGoodsTotal(numInfo.getGoodsTotal()); @@ -195,76 +194,76 @@ } } - /** * 涓婁紶鍥剧墖 + * * @param file * @return * @throws Exception */ public String uploadPicture(MultipartFile file) throws Exception { - - // 鏂囦欢瑙f瀽 + + // 鏂囦欢瑙f瀽 InputStream inputStream = file.getInputStream(); String contentType = file.getContentType(); String type = contentType.substring(contentType.indexOf("/") + 1); - + // 鏂囦欢璺緞 - String filePath="/img/brand/"+UUID.randomUUID().toString().replace("-", "") + "." + type; + String filePath = FilePathEnum.brand.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; // 鎵ц涓婁紶 - String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); - + String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + return fileLink; } - + @Override public int deleteBatchByPrimaryKey(List<Long> list) { executor.execute(new Runnable() { @Override public void run() { - for (Long id: list) { + for (Long id : list) { brandGoodsCaheService.removeByBrandId(id); brandShopCaheService.removeByBrandId(id); } } }); - + return brandInfoMapper.deleteBatchByPrimaryKey(list); } - + @Override public void updateOrder(Long id, Integer moveType) throws BrandInfoException { if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) throw new BrandInfoException(1, "浼犻�掔殑绫诲瀷涓嶆纭�"); - + if (id == null) throw new BrandInfoException(1, "ID涓嶈兘涓虹┖"); - + BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id); - if (resultObj == null) + if (resultObj == null) throw new BrandInfoException(1, "鎿嶄綔鏁版嵁宸蹭笉瀛樺湪"); - + Integer oldOrder = resultObj.getOrder(); - BrandInfo changeObj = brandInfoMapper.getByAdjoinOrder(resultObj.getBrandClass().getId(),oldOrder, moveType); - if (changeObj == null ) + BrandInfo changeObj = brandInfoMapper.getByAdjoinOrder(resultObj.getBrandClass().getId(), oldOrder, moveType); + if (changeObj == null) throw new BrandInfoException(1, "宸茬粡鍦ㄦ渶杈圭紭锛屾棤鍙氦鎹㈢殑浣嶇疆"); - + BrandInfo changeObj1 = new BrandInfo(); changeObj1.setId(id); changeObj1.setOrder(changeObj.getOrder()); - + BrandInfo changeObj2 = new BrandInfo(); changeObj2.setId(changeObj.getId()); changeObj2.setOrder(oldOrder); - + brandInfoMapper.updateByPrimaryKeySelective(changeObj1); brandInfoMapper.updateByPrimaryKeySelective(changeObj2); } - @Override - public List<BrandInfo> listQuery(long start, int count, List<String> keys, Long cid, Integer state, Integer showState) { - return brandInfoMapper.listQuery(start, count, keys, cid, state,showState); + public List<BrandInfo> listQuery(long start, int count, List<String> keys, Long cid, Integer state, + Integer showState) { + return brandInfoMapper.listQuery(start, count, keys, cid, state, showState); } @Override @@ -291,11 +290,11 @@ } @Override - @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid") - public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid) { + @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid+'-'+#platform+'-'+#version") + public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid, String platform, String version) { List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>(); - List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid); + List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid, platform, version); if (listShop == null || listShop.size() == 0) return listInfo; @@ -324,15 +323,14 @@ return brandClassShopService.countBrandShopinfo(cid); } - @Override public void removeAgoByDate(Date date) { // 鍒犻櫎鍟嗗搧 brandGoodsCaheService.removeAgoByDate(date); - + // 鍒犻櫎搴楅摵 brandShopCaheService.removeAgoByDate(date); - + long count = brandInfoMapper.countValidByCid(null); if (count == 0) return; @@ -344,6 +342,7 @@ /** * 鏇存柊鍟嗗搧鏁伴噺 + * * @param start * @param count */ @@ -351,13 +350,13 @@ 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); + updateInfo.setGoodsTotal((int) goodsTotal); List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(brandInfo.getId()); if (listshop == null) { updateInfo.setShopTotal(0); @@ -368,14 +367,19 @@ brandInfoMapper.updateByPrimaryKeySelective(updateInfo); } } - - + @Override public void addShopAndGoods(long start, int count) { List<BrandInfo> list = brandInfoMapper.listValidAll(start, count); + addShopAndGoods(list); + } + + @Override + public void addShopAndGoods(List<BrandInfo> list) { if (list == null || list.size() == 0) return; + // long startTime = java.lang.System.currentTimeMillis(); for (BrandInfo brandInfo : list) { try { String name = brandInfo.getName(); @@ -384,8 +388,8 @@ continue; // 娣诲姞鍟嗗搧 BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo); - - BrandInfo updateInfo = new BrandInfo(); + + BrandInfo updateInfo = new BrandInfo(); updateInfo.setId(brandInfo.getId()); updateInfo.setWeight(Math.random() * 1000); updateInfo.setGoodsTotal(numInfo.getGoodsTotal()); @@ -395,8 +399,8 @@ } catch (Exception e) { LogHelper.errorDetailInfo(e); } - } + // long endTime = java.lang.System.currentTimeMillis(); } @Override @@ -419,20 +423,19 @@ @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#cid") @Override - public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) { + public List<BrandInfoVO> listValidToApp(long start, int count, Long cid, String platform, String version) { List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid); if (list == null || list.size() == 0) return null; - BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); - BigDecimal shareRate = hongBaoManageService.getShareRate(); - ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate()); + ConfigParamsDTO configParamsDTO = hongBaoManageService.getShowComputeRate(platform, version); + List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>(); for (int i = 0; i < list.size(); i++) { BrandInfoVO brand = list.get(i); if (brand == null) continue; - + List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId()); if (listGoods == null || listGoods.size() < 3) continue; @@ -465,24 +468,19 @@ } return listInfo; } - - - - + @Override - @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key") - public BrandInfoVO listByAlikeName(String key) { + @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key+'-'+#platform+'-'+#version") + public BrandInfoVO listByAlikeName(String key, String platform, String version) { if (StringUtil.isNullOrEmpty(key)) return null; - + List<BrandInfoVO> list = brandInfoMapper.listByAlikeName(key); if (list == null || list.size() == 0) return null; - BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); - BigDecimal shareRate = hongBaoManageService.getShareRate(); - ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate()); - + ConfigParamsDTO configParamsDTO = hongBaoManageService.getShowComputeRate(platform, version); + BrandInfoVO brand = list.get(0); List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId()); if (listGoods == null || listGoods.size() < 3) @@ -509,10 +507,16 @@ } } - if (listGoodsVO.size() < 3) + if (listGoodsVO.size() < 3) return null; - + brand.setListGoods(listGoodsVO); return brand; } + + @Override + public List<BrandInfo> listValidOrderByUpdateTime(int page, int pageSize) { + return brandInfoMapper.listValidAll((page - 1) * pageSize, pageSize); + } + } -- Gitblit v1.8.0