From a8e45a802600ca1cde28fe8522a26635328bbd99 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 15 三月 2019 17:45:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java |  110 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 89 insertions(+), 21 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 e62f65f..e069436 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
@@ -8,8 +8,8 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -26,23 +26,27 @@
 import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 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.entity.system.BusinessSystem;
+import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 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;
 import com.yeshi.fanli.util.Utils;
-import org.yeshi.utils.tencentcloud.COSManager;
 
 @Service
 public class GoodsClassServiceImpl implements GoodsClassService {
@@ -51,7 +55,7 @@
 	private GoodsClassDao goodsClassDao;
 
 	@Resource
-	private SystemService systemService;
+	private BusinessSystemService businessSystemService;
 
 	@Resource
 	private SuperGoodsClassService superGoodsClassService;
@@ -67,6 +71,10 @@
 	
 	@Resource
 	private LabelClassMapper labelClassMapper;
+	
+	
+	@Resource
+	private GoodsSubClassService goodsSubClassService;
 	
 
 	public GoodsClass getGoodsClass(long gcid) {
@@ -106,7 +114,7 @@
 	public List<GoodsClassAdmin> getGoodsClassAdmins(int index, String platform, String packages, String key) {
 		final int strat = index * Constant.PAGE_SIZE;
 		platform = Utils.getMap().get(platform);
-		com.yeshi.fanli.entity.system.System system = systemService.getSystem(platform, packages);
+		BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages);
 		List<GoodsClass> GoodsClassList = null;
 		List<SuperGoodsClass> superGoodsClassList = null;
 		Map<Long, GoodsClassAdmin> goodsClassAdminMap = new HashMap<Long, GoodsClassAdmin>();
@@ -127,14 +135,14 @@
 				gcIdList.add(rs.getId());
 			}
 			superGoodsClassList = superGoodsClassService.getSuperGoodsClasss(gcIdList);
-			Map<Long, List<System>> superMap = new HashMap<Long, List<System>>();
+			Map<Long, List<BusinessSystem>> superMap = new HashMap<Long, List<BusinessSystem>>();
 			Long rsId = null;
-			List<System> systemList = null;
+			List<BusinessSystem> systemList = null;
 			for (SuperGoodsClass srs : superGoodsClassList) {
 				rsId = srs.getGoodsClass().getId();
 				systemList = superMap.get(rsId);
 				if (systemList == null) {
-					systemList = new ArrayList<System>();
+					systemList = new ArrayList<BusinessSystem>();
 				}
 				systemList.add(srs.getSystem());
 				superMap.put(rsId, systemList);
@@ -146,7 +154,7 @@
 				if (rsa == null) {
 					rsa = new GoodsClassAdmin();
 				}
-				List<System> list = superMap.get(id);
+				List<BusinessSystem> list = superMap.get(id);
 				if (list != null) {
 					rsa.getSystemList().addAll(superMap.get(id));
 				}
@@ -183,7 +191,7 @@
 
 	public int getCount(String platform, String packages, final String key) {
 		platform = Utils.getMap().get(platform);
-		final System system = systemService.getSystem(platform, packages);
+		final BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages);
 		return (Integer) goodsClassDao.excute(new HibernateCallback<Integer>() {
 
 			public Integer doInHibernate(Session session) throws HibernateException {
@@ -344,10 +352,10 @@
 	@Override
 	public List<GoodsClass> queryAll(String platform, String packages) throws Exception{
 
-		List<System> defultList = systemService.getSystems();
+		List<BusinessSystem> defultList = businessSystemService.getBusinessSystems();
 
 		platform = Utils.getMap().get(platform);
-		com.yeshi.fanli.entity.system.System system = systemService.getSystem(platform, packages);
+		BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages);
 		
 		List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
 		List<SuperGoodsClass> superGoodsClassList = null;
@@ -414,17 +422,17 @@
 					long rsId = srs.getGoodsClass().getId();
 					
 					if (gclass.getId() == rsId) {
-						System gsystem = srs.getSystem();
+						BusinessSystem gsystem = srs.getSystem();
 						gList.add(gsystem.getId());
 					}
 				}
 			}
 			
-			List<System> newList = new ArrayList<System>();
+			List<BusinessSystem> newList = new ArrayList<BusinessSystem>();
 			// 鏄惁鏈夊叧鑱旂郴缁熼�夐」
-			for (System dsystem : defultList) {
+			for (BusinessSystem dsystem : defultList) {
 				
-				System newsystem = new System();
+				BusinessSystem newsystem = new BusinessSystem();
 				
 				PropertyUtils.copyProperties(newsystem, dsystem);
 				newsystem.setCheck(0);
@@ -549,7 +557,6 @@
 	public void removePicture(GoodsClass record) throws Exception {
 		
 		String fileUrl = record.getPicture();
-		
 		boolean deleteFile = true;
 		
 		if (StringUtil.isNullOrEmpty(fileUrl)) {
@@ -557,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