From 4114e871bcb3dce771b6aed64a1027d0bbb95ca6 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 16 五月 2019 15:28:37 +0800
Subject: [PATCH] 增加动态用户

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java |  162 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 99 insertions(+), 63 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java
index 30f95ce..0a3b2d2 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java
@@ -1,15 +1,16 @@
 package com.yeshi.fanli.service.impl.goods;
 
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 
 import javax.annotation.Resource;
-import javax.transaction.Transactional;
 
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 import org.yeshi.utils.tencentcloud.COSManager;
 
@@ -19,7 +20,9 @@
 import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
 import com.yeshi.fanli.exception.GoodsSubClassException;
 import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
+import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
 import com.yeshi.fanli.service.inter.lable.LabelClassService;
+import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
 
 @Service
@@ -31,7 +34,9 @@
 	private GoodsSubClassService goodsSubClassService;
 	@Resource
 	private LabelClassService labelClassService;
-	
+
+	@Resource
+	private TaoBaoClassService taoBaoClassService;
 
 	@Override
 	public int deleteByPrimaryKey(Long id) {
@@ -58,19 +63,18 @@
 		return goodsSubClassMapper.updateByPrimaryKeySelective(record);
 	}
 
-
 	@Override
 	@Transactional
 	public void deleteByRootId(Long id) throws Exception {
-		
+
 		List<GoodsSubClass> subClassList = goodsSubClassMapper.queryByRootId(id, null);
 		if (subClassList != null && subClassList.size() > 0) {
 			for (GoodsSubClass goodsSubClass : subClassList) {
-					deleteSub(goodsSubClass.getId());
+				deleteSub(goodsSubClass.getId());
 			}
 		}
 	}
-	
+
 	@Override
 	@Transactional
 	public void deleteByPrimaryKeyBatch(List<String> recordIds) throws Exception {
@@ -80,8 +84,7 @@
 			}
 		}
 	}
-	
-	
+
 	@Override
 	@Transactional
 	public void deleteSub(Long recordId) throws Exception {
@@ -96,6 +99,12 @@
 			COSManager.getInstance().deleteFile(picture);
 		}
 
+		/* 鍒犻櫎缃戠粶鍥剧墖 */
+		String pictureSecond = goodsSubClass.getPictureSecond();
+		if (!StringUtil.isNullOrEmpty(pictureSecond)) {
+			COSManager.getInstance().deleteFile(pictureSecond);
+		}
+
 		/* 鍒犻櫎鎵�鏈夊叧鑱斿瓙绫� */
 		List<GoodsSubClass> subList = goodsSubClassMapper.queryByPid(recordId, null);
 		if (subList != null && subList.size() > 0) {
@@ -105,52 +114,58 @@
 				deleteSub(id);
 			}
 		}
-		
+
 		/* 鍒犻櫎鍏宠仈鏍囩 */
 		labelClassService.deleteBySubClassId(recordId);
-		
+
 		/* 鍒犻櫎鏁版嵁 */
 		goodsSubClassMapper.deleteByPrimaryKey(recordId);
 	}
 
-	
-	
 	@Override
-	public void saveObject(MultipartFile file, GoodsSubClass record, Integer type, Long pid) throws GoodsSubClassException, Exception{
-		
+	public void saveObject(MultipartFile file, MultipartFile file2, GoodsSubClass record, Integer type, Long pid)
+			throws GoodsSubClassException, Exception {
+
 		String name = record.getName();
 		if (name == null || name.trim().length() == 0) {
 			throw new GoodsSubClassException(1, "鍒嗙被鍚嶇О涓嶈兘涓虹┖");
 		}
-		
+
 		// 鍥剧墖涓婁紶
 		String picture = null;
 		if (file != null) {
 			picture = uploadPicture(file);
 		}
-		
+
+		// 鍥剧墖涓婁紶
+		String pictureSecond = null;
+		if (file2 != null) {
+			pictureSecond = uploadPicture(file2);
+		}
+
 		String params = record.getSearchParam();
-		if (params== null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
+		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
 			record.setSearchJson(null);
+		} else if (!StringUtil.isJson(params)) {
+			throw new GoodsSubClassException(1, "绛涢�夋潯浠堕潪JSON鏍煎紡");
 		} else {
 			record.setSearchJson(params);
 		}
-		
+
 		Long id = record.getId();
 		if (id == null) {
 			if (type == null) {
 				throw new GoodsSubClassException(1, "绛夌骇涓嶈兘涓虹┖");
 			}
-			
+
 			if (type > 5) {
 				throw new GoodsSubClassException(1, "绛夌骇涓嶈兘瓒呰繃浜旂骇");
 			}
-			
+
 			if (pid == null) {
 				throw new GoodsSubClassException(1, "涓婄骇id涓虹┖");
 			}
-			
-			
+
 			if (type == 2) {
 				record.setRootClass(new GoodsClass(pid));
 				int weight = goodsSubClassMapper.getMaxWeightByRootId(pid);
@@ -160,43 +175,55 @@
 				int weight = goodsSubClassMapper.getMaxWeightByPid(pid);
 				record.setWeight(weight + 1);
 			}
-	
+
 			String key = record.getKey();
 			if (StringUtil.isNullOrEmpty(key)) {
 				record.setKey(name.trim());
 			}
-			
+
 			record.setLevel(type);
 			record.setPicture(picture);
+			record.setPictureSecond(pictureSecond);
 			record.setState(0);
 			record.setAndroidClick(0L);
 			record.setIosClick(0L);
 			record.setCreatetime(new Date());
 			record.setUpdatetime(new Date());
-			
-			if (params== null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
+
+			if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
 				// 鎼滅储鏉′欢:鏈夊埜銆佸湪鍞环20-200銆佺墰鐨櫍杞诲井
 				record.setSearchJson("{\"quan\":1,\"endPrice\":220,\"includeGoodRate\":true}");
 			}
-			
+
 			goodsSubClassMapper.insert(record);
-			
+
 		} else {
 			// 淇敼
 			GoodsSubClass resultObj = goodsSubClassMapper.selectByPrimaryKey(id);
 			if (resultObj == null) {
 				throw new GoodsSubClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
 			}
-			
+
 			if (picture != null && picture.trim().length() > 0) {
 				// 鍒犻櫎鑰佸浘
-				removePicture(resultObj.getPicture());
+				if (!Constant.IS_TEST)
+					removePicture(resultObj.getPicture());
 				// 瀛樺偍鏂板浘
 				record.setPicture(picture);
 			} else {
 				record.setPicture(resultObj.getPicture());
 			}
-			
+
+			if (pictureSecond != null && pictureSecond.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				if (!Constant.IS_TEST)
+					removePicture(resultObj.getPictureSecond());
+				// 瀛樺偍鏂板浘
+				record.setPictureSecond(pictureSecond);
+			} else {
+				record.setPictureSecond(resultObj.getPictureSecond());
+			}
+
 			record.setLevel(resultObj.getLevel());
 			record.setRootClass(resultObj.getRootClass());
 			record.setWeight(resultObj.getWeight());
@@ -206,31 +233,46 @@
 			record.setUpdatetime(new Date());
 			goodsSubClassMapper.updateByPrimaryKey(record);
 		}
+
+		// 淇濆瓨娣樺疂鍟嗗搧鍒嗙被id
+		String taobaoCids = record.getTaobaoCids();
+		List<Long> tbCidList = new ArrayList<>();
+		if (!StringUtil.isNullOrEmpty(taobaoCids) && !"null".equalsIgnoreCase(taobaoCids)) {
+
+			String[] sts = taobaoCids.split(",");
+			for (String st : sts) {
+				String cid = st.split("-")[st.split("-").length - 1];
+				tbCidList.add(Long.parseLong(cid));
+			}
+		}
+		taoBaoClassService.saveSub(record.getId(), tbCidList);
 	}
 
 	/**
 	 * 涓婁紶鍥剧墖
+	 * 
 	 * @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/GoodsSubClass/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
+		String filePath = "/img/GoodsSubClass/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
 		// 鎵ц涓婁紶
-		String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
-		
+		String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+
 		return fileLink;
 	}
 
 	/**
 	 * 鍒犻櫎鍥剧墖
+	 * 
 	 * @param record
 	 * @throws Exception
 	 */
@@ -239,9 +281,6 @@
 			COSManager.getInstance().deleteFile(picture);
 		}
 	}
-	
-	
-	
 
 	/**
 	 * 鍒犻櫎鍥剧墖
@@ -279,60 +318,57 @@
 		return goodsSubClassMapper.queryByPid(pid, state);
 	}
 
-	
 	@Override
-	public List<GoodsSubClass> queryByRootIdAndWeight(Long rootId,int type, int weight) throws Exception {
+	public List<GoodsSubClass> queryByRootIdAndWeight(Long rootId, int type, int weight) throws Exception {
 		return goodsSubClassMapper.queryByRootIdAndWeight(rootId, type, weight);
 	}
 
 	@Override
-	public List<GoodsSubClass> queryByPidAndWeight(Long pid,int type, int weight) throws Exception {
+	public List<GoodsSubClass> queryByPidAndWeight(Long pid, int type, int weight) throws Exception {
 		return goodsSubClassMapper.queryByPidAndWeight(pid, type, weight);
 	}
 
-	
 	@Override
 	public List<GoodsSubClass> getGoodsSecondClass(Long rootId, Integer state) throws Exception {
 		return goodsSubClassMapper.queryByRootId(rootId, state);
 	}
-	
-	
+
 	@Override
-	@Cacheable(value="classCache",key="'getSubClassCache-'+#rootId +'-'+#state")
+	@Cacheable(value = "classCache", key = "'getSubClassCache-'+#rootId +'-'+#state")
 	public List<GoodsSubClass> getSubClassCache(Long rootId, Integer state) throws Exception {
 		return getGoodsSecondClass(rootId, state);
 	}
-	
-	
+
 	@Override
-	@Cacheable(value="classCache",key="'getSubClassByPrimaryKeyCache-'+#id")
+	@Cacheable(value = "classCache", key = "'getSubClassByPrimaryKeyCache-'+#id")
 	public GoodsSubClass getSubClassByPrimaryKeyCache(Long id) throws Exception {
 		return selectByPrimaryKey(id);
 	}
-	
-	
-	
+
 	/**
-	 *  缁熻涓�绾т箣涓嬬殑鎵�鏈変簩绾у垎绫�
-	 * @param rootId  涓�绾d
+	 * 缁熻涓�绾т箣涓嬬殑鎵�鏈変簩绾у垎绫�
+	 * 
+	 * @param rootId
+	 *            涓�绾d
 	 * @returnL
 	 */
 	@Override
 	public int countByRootId(Long rootId) {
 		return goodsSubClassMapper.countByRootId(rootId);
 	}
-	
+
 	/**
-	 *  缁熻浜岀骇鍒嗙被涔嬩笅鍏朵粬鍒嗙被
-	 * @param rootId  涓�绾d
+	 * 缁熻浜岀骇鍒嗙被涔嬩笅鍏朵粬鍒嗙被
+	 * 
+	 * @param rootId
+	 *            涓�绾d
 	 * @return
 	 */
 	@Override
-	public int countByPid(Long pid){
+	public int countByPid(Long pid) {
 		return goodsSubClassMapper.countByPid(pid);
 	}
-	
-	
+
 	@Override
 	public void countClick(AcceptData acceptData, GoodsSubClass record) {
 		if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
@@ -352,9 +388,9 @@
 		}
 		goodsSubClassService.updateByPrimaryKeySelective(record);
 	}
-	
+
 	@Override
-	public List<GoodsSubClass> queryByListCid(List<Long> list){
+	public List<GoodsSubClass> queryByListCid(List<Long> list) {
 		return goodsSubClassMapper.queryByListCid(list);
 	}
 

--
Gitblit v1.8.0