From aec36e0e136b55ffeb1d22dd3d7f5c2443b806aa Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 23 九月 2019 10:49:56 +0800
Subject: [PATCH] 品牌 后台管理

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 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..513f76e 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,18 @@
 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.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 +31,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;
@@ -64,7 +69,7 @@
 	private BrandShopCaheService brandShopCaheService;
 
 	@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)
 			throw new BrandInfoException(1, "鍚嶇О涓嶈兘涓虹┖");
@@ -72,6 +77,16 @@
 		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 +98,46 @@
 			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);
 		}
 	}
 
+	
+	/**
+	 * 涓婁紶鍥剧墖
+	 * @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);

--
Gitblit v1.8.0