From e19ce4be094d93f68bdb6ee1c28e9caa502bf2c4 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 10 十月 2019 11:17:12 +0800 Subject: [PATCH] utils包添加工具类,抖音广告修改 --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java | 78 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 74 insertions(+), 4 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 481652c..4c974af 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,14 +1,19 @@ 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; +import java.util.UUID; import javax.annotation.Resource; import org.springframework.cache.annotation.Cacheable; +import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.brand.BrandShopCaheDao; import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper; @@ -27,6 +32,7 @@ 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.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.vo.brand.BrandInfoVO; @@ -63,15 +69,33 @@ @Resource private BrandShopCaheService brandShopCaheService; + @Resource(name = "taskExecutor") + private TaskExecutor executor; + + @Override - public void saveObject(BrandInfo record) throws BrandInfoException { + public void saveObject(MultipartFile file, BrandInfo record) throws BrandInfoException { String name = record.getName(); - if (name == null || name.trim().length() == 0) + if (StringUtil.isNullOrEmpty(name)) throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖"); + String searchKey = record.getSearchKey(); + if (StringUtil.isNullOrEmpty(searchKey)) + record.setSearchKey(name); + Integer state = record.getState(); if (state == null) record.setState(0); + + // 鍥剧墖涓婁紶 + String picture = null; + if (file != null) { + try { + picture = uploadPicture(file); + } catch (Exception e) { + throw new BrandInfoException(1, "鍥剧墖涓婁紶澶辫触"); + } + } Long id = record.getId(); if (id == null) { @@ -83,12 +107,57 @@ if (resultObj == null) throw new BrandInfoException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); + if (picture != null && picture.trim().length() > 0) { + // 鍒犻櫎鑰佸浘 + if (picture != null && picture.trim().length() > 0 && !Constant.IS_TEST) { + COSManager.getInstance().deleteFile(picture); + }; + // 瀛樺偍鏂板浘 + record.setIcon(picture); + } else { + record.setIcon(resultObj.getIcon()); + } + + record.setGoodsTotal(resultObj.getGoodsTotal()); record.setCreateTime(resultObj.getCreateTime()); record.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKey(record); } + + if (state == 1) { + executor.execute(new Runnable() { + @Override + public void run() { + int goodsTotal = brandGoodsCaheService.addBrandGoods(record); + record.setGoodsTotal(goodsTotal); + brandInfoMapper.updateByPrimaryKeySelective(record); + } + }); + } } + + /** + * 涓婁紶鍥剧墖 + * @param file + * @return + * @throws Exception + */ + public String uploadPicture(MultipartFile file) throws Exception { + + // 鏂囦欢瑙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 fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + + return fileLink; + } + @Override public int deleteBatchByPrimaryKey(List<Long> list) { return brandInfoMapper.deleteBatchByPrimaryKey(list); @@ -163,8 +232,9 @@ return; for (BrandInfo brandInfo : list) { - String key = brandInfo.getName(); - if (StringUtil.isNullOrEmpty(key)) + String name = brandInfo.getName(); + String searchKey = brandInfo.getSearchKey(); + if (StringUtil.isNullOrEmpty(name) && StringUtil.isNullOrEmpty(searchKey)) continue; // 娣诲姞鍟嗗搧 -- Gitblit v1.8.0