From 15412a4d4abf9a822a3e4c2fbcbe68df429b062f Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期一, 11 三月 2019 17:03:36 +0800
Subject: [PATCH] Merge branch 'div'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java |   76 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java
index f8330ac..6932fa8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java
@@ -9,6 +9,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -27,17 +28,21 @@
 import org.springframework.web.multipart.MultipartFile;
 import org.yeshi.utils.tencentcloud.COSManager;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 import com.yeshi.fanli.dao.goods.GoodsClassDao;
 import com.yeshi.fanli.dao.mybatis.GoodsClassMapper;
 import com.yeshi.fanli.dao.mybatis.lable.LabelClassMapper;
 import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
 import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
+import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
 import com.yeshi.fanli.entity.bus.su.clazz.SuperGoodsClass;
 import com.yeshi.fanli.entity.system.System;
 import com.yeshi.fanli.service.inter.config.SystemService;
 import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
 import com.yeshi.fanli.service.inter.goods.GoodsClassService;
 import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
+import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
 import com.yeshi.fanli.service.inter.goods.SuperGoodsClassService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
@@ -66,6 +71,10 @@
 	
 	@Resource
 	private LabelClassMapper labelClassMapper;
+	
+	
+	@Resource
+	private GoodsSubClassService goodsSubClassService;
 	
 
 	public GoodsClass getGoodsClass(long gcid) {
@@ -555,15 +564,76 @@
 		}
 		
 		deleteFile = COSManager.getInstance().deleteFile(fileUrl);
-		
 		if (deleteFile) {
 			record.setPicture(null);
 			// 鏇存柊鏁版嵁搴�
 			 updateGoodsClass(record);
 		} 
-		
-		return;
 	}
 
+	@Override
+	@Cacheable(value="classCache",key="'getListClassCache-'+#systemId")
+	public List<GoodsClass> getListClassCache(Long systemId) throws Exception {
+		List<SuperGoodsClass> superGoodsClassList = superGoodsClassService.getSuperGoodsClassBySystemId(systemId);
+		
+		if (superGoodsClassList == null || superGoodsClassList.size() == 0) {
+			return null;
+		}
+		
+		List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
+		for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
+			GoodsClass goodsClass = superGoodsClass.getGoodsClass();
+			goodsClassList.add(goodsClass);
+		}
+		
+		return goodsClassList;
+	}
+	
+	
+	@Override
+	@Cacheable(value="classCache",key="'getClassListAllCache-'+#systemId")
+	public List<Map<String, Object>> getClassListAllCache(Long systemId) throws Exception {
+
+		List<GoodsClass> goodsClassList = goodsClassMapper.listGoodsClassBySystemId(systemId);
+		if (goodsClassList == null || goodsClassList.size() == 0) {
+			return null;
+		}
+
+		List<Long> listID = new ArrayList<Long>();
+		for (GoodsClass coodsClass : goodsClassList) {
+			listID.add(coodsClass.getId());
+		}
+	
+		List<GoodsSubClass> listSub = goodsSubClassService.queryByListCid(listID);
+		
+		Gson gson = new GsonBuilder().create();
+
+		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+		for (GoodsClass goodsClass : goodsClassList) {
+
+			List<GoodsSubClass> subClassList = new ArrayList<GoodsSubClass>();
+			
+			if (listSub != null && listSub.size() > 0) {
+				Iterator<GoodsSubClass> iterator = listSub.iterator();
+				while (iterator.hasNext()) {
+					GoodsSubClass goodsSubClass = iterator.next();
+					GoodsClass goodsClassInner = goodsSubClass.getRootClass();
+					if (goodsClass.getId() == goodsClassInner.getId()) {
+						// 瀵瑰簲涓嬪瓙鍒嗙被
+						subClassList.add(goodsSubClass);
+						iterator.remove();
+					}
+				}
+			}
+
+			Map<String, Object> map = new HashMap<String, Object>();
+			map.put("gclass", goodsClass);
+			map.put("subList", gson.toJson(subClassList));
+
+			list.add(map);
+		}
+
+		return list;
+	}
 	
 }

--
Gitblit v1.8.0