From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java |   90 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 69 insertions(+), 21 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 0a3b2d2..f47eea4 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
@@ -18,11 +18,15 @@
 import com.yeshi.fanli.entity.accept.AcceptData;
 import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
 import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
-import com.yeshi.fanli.exception.GoodsSubClassException;
+import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabel;
+import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabelMap;
+import com.yeshi.fanli.exception.goods.GoodsSubClassException;
+import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService;
 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.FilePathEnum;
 import com.yeshi.fanli.util.StringUtil;
 
 @Service
@@ -37,6 +41,9 @@
 
 	@Resource
 	private TaoBaoClassService taoBaoClassService;
+
+	@Resource
+	private GoodsSubClassLabelService goodsSubClassLabelService;
 
 	@Override
 	public int deleteByPrimaryKey(Long id) {
@@ -64,10 +71,10 @@
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	public void deleteByRootId(Long id) throws Exception {
 
-		List<GoodsSubClass> subClassList = goodsSubClassMapper.queryByRootId(id, null);
+		List<GoodsSubClass> subClassList = goodsSubClassMapper.queryByRootId(id, null, null);
 		if (subClassList != null && subClassList.size() > 0) {
 			for (GoodsSubClass goodsSubClass : subClassList) {
 				deleteSub(goodsSubClass.getId());
@@ -76,7 +83,7 @@
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	public void deleteByPrimaryKeyBatch(List<String> recordIds) throws Exception {
 		if (recordIds != null && recordIds.size() > 0) {
 			for (String recordId : recordIds) {
@@ -86,7 +93,7 @@
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	public void deleteSub(Long recordId) throws Exception {
 		GoodsSubClass goodsSubClass = goodsSubClassMapper.selectByPrimaryKey(recordId);
 
@@ -123,13 +130,16 @@
 	}
 
 	@Override
-	public void saveObject(MultipartFile file, MultipartFile file2, GoodsSubClass record, Integer type, Long pid)
-			throws GoodsSubClassException, Exception {
+	public void saveObject(MultipartFile file, MultipartFile file2, GoodsSubClass record, Integer type, Long pid,
+			Long labelId) throws GoodsSubClassException, Exception {
 
 		String name = record.getName();
 		if (name == null || name.trim().length() == 0) {
 			throw new GoodsSubClassException(1, "鍒嗙被鍚嶇О涓嶈兘涓虹┖");
 		}
+
+		if (StringUtil.isNullOrEmpty(record.getMonth()))
+			record.setMonth(null);
 
 		// 鍥剧墖涓婁紶
 		String picture = null;
@@ -189,6 +199,8 @@
 			record.setIosClick(0L);
 			record.setCreatetime(new Date());
 			record.setUpdatetime(new Date());
+			if (labelId != null)
+				record.setClassLabel(new GoodsSubClassLabel(labelId));
 
 			if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
 				// 鎼滅储鏉′欢:鏈夊埜銆佸湪鍞环20-200銆佺墰鐨櫍杞诲井
@@ -196,6 +208,13 @@
 			}
 
 			goodsSubClassMapper.insert(record);
+
+			if (labelId != null) {
+				GoodsSubClassLabelMap map = new GoodsSubClassLabelMap();
+				map.setGoodsSubClass(record);
+				map.setLabel(new GoodsSubClassLabel(labelId));
+				goodsSubClassLabelService.addSubClassLabelMap(map);
+			}
 
 		} else {
 			// 淇敼
@@ -231,6 +250,16 @@
 			record.setAndroidClick(resultObj.getAndroidClick());
 			record.setCreatetime(resultObj.getCreatetime());
 			record.setUpdatetime(new Date());
+			if (labelId != null) {
+				GoodsSubClassLabelMap map = new GoodsSubClassLabelMap();
+				map.setGoodsSubClass(record);
+				map.setLabel(new GoodsSubClassLabel(labelId));
+				try {
+					goodsSubClassLabelService.addSubClassLabelMap(map);
+				} catch (Exception e) {
+				}
+			}
+
 			goodsSubClassMapper.updateByPrimaryKey(record);
 		}
 
@@ -263,7 +292,7 @@
 		String type = contentType.substring(contentType.indexOf("/") + 1);
 
 		// 鏂囦欢璺緞
-		String filePath = "/img/GoodsSubClass/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
+		String filePath =FilePathEnum.goodsSubClass.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
 		// 鎵ц涓婁紶
 		String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
 
@@ -287,30 +316,49 @@
 	 */
 	@Override
 	public int removePicture(GoodsSubClass record) throws Exception {
-
-		String fileUrl = record.getPicture();
-
 		int result = -2;
-		boolean deleteFile = true;
-
+		String fileUrl = record.getPicture();
 		if (StringUtil.isNullOrEmpty(fileUrl)) {
 			return result;
 		}
 
-		deleteFile = COSManager.getInstance().deleteFile(fileUrl);
-
+		boolean deleteFile = COSManager.getInstance().deleteFile(fileUrl);;
 		if (deleteFile) {
 			record.setPicture(null);
 			// 鏇存柊鏁版嵁搴�
 			result = goodsSubClassMapper.updateByPrimaryKey(record);
 		}
-
 		return result;
 	}
 
+	
+	@Override
+	public void switchState(Long id) throws GoodsSubClassException {
+		if (id == null) {
+			throw new GoodsSubClassException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		GoodsSubClass resultObj = goodsSubClassMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new GoodsSubClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		GoodsSubClass updateObj = new GoodsSubClass();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		goodsSubClassMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
+	
 	@Override
 	public List<GoodsSubClass> queryByRootId(Long rootId, Integer state) throws Exception {
-		return goodsSubClassMapper.queryByRootId(rootId, state);
+		return goodsSubClassMapper.queryByRootId(rootId, state, null);
 	}
 
 	@Override
@@ -329,14 +377,14 @@
 	}
 
 	@Override
-	public List<GoodsSubClass> getGoodsSecondClass(Long rootId, Integer state) throws Exception {
-		return goodsSubClassMapper.queryByRootId(rootId, state);
+	public List<GoodsSubClass> getGoodsSecondClass(Long rootId, Integer state, Integer month) throws Exception {
+		return goodsSubClassMapper.queryByRootId(rootId, state, month);
 	}
 
 	@Override
 	@Cacheable(value = "classCache", key = "'getSubClassCache-'+#rootId +'-'+#state")
-	public List<GoodsSubClass> getSubClassCache(Long rootId, Integer state) throws Exception {
-		return getGoodsSecondClass(rootId, state);
+	public List<GoodsSubClass> getSubClassCache(Long rootId, Integer state, Integer month) throws Exception {
+		return getGoodsSecondClass(rootId, state, month);
 	}
 
 	@Override

--
Gitblit v1.8.0