From 24a8d17e007545f7426c48352109aa1a9c6587ee Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 06 五月 2020 12:02:09 +0800
Subject: [PATCH] IOS上线隐藏我的界面的banner与超级会员升级信息

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java |  808 +++++++++++++++++++++++---------------------------------
 1 files changed, 335 insertions(+), 473 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..8cc434f 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
@@ -1,396 +1,96 @@
 package com.yeshi.fanli.service.impl.goods;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.Serializable;
-import java.net.URLEncoder;
-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;
 import java.util.UUID;
 
 import javax.annotation.Resource;
-import javax.transaction.Transactional;
 
-import org.apache.commons.beanutils.PropertyUtils;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
 import org.springframework.cache.annotation.Cacheable;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
-
-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.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.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;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.yeshi.fanli.dao.mybatis.GoodsClassMapper;
+import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
+import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
+import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
+import com.yeshi.fanli.exception.goods.GoodsClassException;
+import com.yeshi.fanli.service.inter.goods.GoodsClassService;
+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
 public class GoodsClassServiceImpl implements GoodsClassService {
 
 	@Resource
-	private GoodsClassDao goodsClassDao;
-
-	@Resource
-	private SystemService systemService;
-
-	@Resource
-	private SuperGoodsClassService superGoodsClassService;
-
-	@Resource
-	private ClassRecommendGoodsService classRecommendGoodsService;
-
-	@Resource
-	private GoodsSecondClassService goodsSecondClassService;
-
-	@Resource
 	private GoodsClassMapper goodsClassMapper;
-	
+
 	@Resource
-	private LabelClassMapper labelClassMapper;
-	
+	private GoodsSubClassService goodsSubClassService;
 
-	public GoodsClass getGoodsClass(long gcid) {
-		return goodsClassDao.find(GoodsClass.class, gcid);
+	@Resource
+	private LabelClassService labelClassService;
+
+	@Resource
+	private TaoBaoClassService taoBaoClassService;
+
+	public GoodsClass getGoodsClass(long id) {
+		return goodsClassMapper.selectByPrimaryKey(id);
 	}
 
 	@Override
-	public void deleteGoodsClass(final long id) {
-		goodsClassDao.excute(new HibernateCallback() {
-				public Object doInHibernate(Session session)
-						throws HibernateException {
-					Query query = session.createQuery("delete from GoodsClass  where  id = ? ");
-					query.setParameter(0, id);
-					query.executeUpdate();
-					return null;
-				}
-			});
+	public int updateByPrimaryKey(GoodsClass record) {
+		return goodsClassMapper.updateByPrimaryKey(record);
 	}
-	
+
 	@Override
-	@SuppressWarnings("unchecked")
-	public List<GoodsClass> getByorderby(int orderby) {
-		
-		List<GoodsClass> goodsClassList = (List<GoodsClass>) goodsClassDao.excute(new HibernateCallback<List<GoodsClass>>() {
-			public List<GoodsClass> doInHibernate(Session session) throws HibernateException {
-				Query query = session.createQuery(" from GoodsClass rs where rs.orderby = ? ");
-				query.setParameter(0, orderby);
-				return query.list();
-			}
-		});
-		
-		return goodsClassList;
-	}
-	
-	
-	@SuppressWarnings("unchecked")
-	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);
-		List<GoodsClass> GoodsClassList = null;
-		List<SuperGoodsClass> superGoodsClassList = null;
-		Map<Long, GoodsClassAdmin> goodsClassAdminMap = new HashMap<Long, GoodsClassAdmin>();
-		List<GoodsClassAdmin> goodsClassAdmin = new ArrayList<GoodsClassAdmin>();
-		if (system == null) {
-			final String likekey = "%" + key + "%";
-			GoodsClassList = (List<GoodsClass>) goodsClassDao.excute(new HibernateCallback<List<GoodsClass>>() {
-				public List<GoodsClass> doInHibernate(Session session) throws HibernateException {
-					Query query = session.createQuery(" from GoodsClass rs where rs.name like ? ");
-					query.setFirstResult(strat);
-					query.setMaxResults(Constant.PAGE_SIZE);
-					query.setParameter(0, likekey);
-					return query.list();
-				}
-			});
-			List<Long> gcIdList = new ArrayList<Long>();
-			for (GoodsClass rs : GoodsClassList) {
-				gcIdList.add(rs.getId());
-			}
-			superGoodsClassList = superGoodsClassService.getSuperGoodsClasss(gcIdList);
-			Map<Long, List<System>> superMap = new HashMap<Long, List<System>>();
-			Long rsId = null;
-			List<System> systemList = null;
-			for (SuperGoodsClass srs : superGoodsClassList) {
-				rsId = srs.getGoodsClass().getId();
-				systemList = superMap.get(rsId);
-				if (systemList == null) {
-					systemList = new ArrayList<System>();
-				}
-				systemList.add(srs.getSystem());
-				superMap.put(rsId, systemList);
-			}
-			GoodsClassAdmin rsa = null;
-			for (GoodsClass GoodsClass : GoodsClassList) {
-				long id = GoodsClass.getId();
-				rsa = goodsClassAdminMap.get(id);
-				if (rsa == null) {
-					rsa = new GoodsClassAdmin();
-				}
-				List<System> list = superMap.get(id);
-				if (list != null) {
-					rsa.getSystemList().addAll(superMap.get(id));
-				}
-				rsa.setGoodsClass(GoodsClass);
-				goodsClassAdminMap.put(id, rsa);
-			}
-		} else if (system != null) {
-			String likekey = "%" + key + "%";
-			superGoodsClassList = superGoodsClassService.getSuperGoodsClassList(system.getId(), strat,
-					Constant.PAGE_SIZE, likekey);
-			List<Long> gcIdList = new ArrayList<Long>();
-			for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
-				GoodsClass GoodsClass = superGoodsClass.getGoodsClass();
-				gcIdList.add(GoodsClass.getId());
-			}
-			superGoodsClassList = superGoodsClassService.getSuperGoodsClasss(gcIdList);
-			GoodsClassAdmin rsa = null;
-			for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
-				GoodsClass goodsClass = superGoodsClass.getGoodsClass();
-				rsa = goodsClassAdminMap.get(goodsClass.getId());
-				if (rsa == null) {
-					rsa = new GoodsClassAdmin(goodsClass);
-				}
-				rsa.getSystemList().add(superGoodsClass.getSystem());
-				goodsClassAdminMap.put(goodsClass.getId(), rsa);
-			}
-		}
-		Map map = Utils.orderBy(goodsClassAdminMap);
-		Collection<GoodsClassAdmin> values = map.values();
-		goodsClassAdmin.addAll(values);
-		return goodsClassAdmin;
-
+	public String getKeysById(Long id) {
+		return goodsClassMapper.getKeysById(id);
 	}
 
-	public int getCount(String platform, String packages, final String key) {
-		platform = Utils.getMap().get(platform);
-		final System system = systemService.getSystem(platform, packages);
-		return (Integer) goodsClassDao.excute(new HibernateCallback<Integer>() {
-
-			public Integer doInHibernate(Session session) throws HibernateException {
-				String k = "%" + key + "%";
-				if (system == null) {
-					// Query query = session.createSQLQuery("select
-					// count(a.name) from (select `name` from yeshi_ec_class
-					// where `name` like ?) a");
-					Query query = session.createQuery("select count(gc.id) from GoodsClass gc where gc.name like ?");
-					query.setParameter(0, k);
-					Long result = (Long) query.uniqueResult();
-					int intValue = result.intValue();
-					return intValue;
-				} else {
-					// Query query =session.createSQLQuery("select count(a.name)
-					// from (select hs.name from yeshi_ec_super_goodsclass shs
-					// left join yeshi_ec_class hs on shs.goodsclass_id=hs.id
-					// where shs.system_id=? and hs.name like ?) a");
-					Query query = session.createQuery(
-							"select count(sgc.id) from SuperGoodsClass sgc where sgc.goodsClass.name like ? and sgc.system.id=?");
-					query.setParameter(0, k);
-					query.setParameter(1, system.getId());
-					Long result = (Long) query.uniqueResult();
-					int intValue = result.intValue();
-					return intValue;
-				}
-			}
-		});
-	}
-
-	// @Transactional
-	// public void addGoodsClass(GoodsClass goodsClass) {
-	// goodsClass.setCreatetime(java.lang.System.currentTimeMillis());
-	// Serializable id = goodsClassDao.save(goodsClass);
-	// Properties properties = new Properties();
-	// InputStream in = null;
-	// try {
-	// in = new BufferedInputStream (new FileInputStream("url.properties"));
-	// properties.load(in);
-	// String url = (String) properties.get("url");
-	// goodsClass.setUrl(url+id);
-	// goodsClassDao.update(goodsClass);
-	// } catch (FileNotFoundException e) {
-	// e.printStackTrace();
-	// } catch (IOException e) {
-	// e.printStackTrace();
-	// }finally{
-	// if(in !=null){
-	// try {
-	// in.close();
-	// } catch (IOException e) {
-	// e.printStackTrace();
-	// }
-	// }
-	// }
-	// }
-
-	public Integer addGoodsClass(final GoodsClass goodsClass) {
-
-		return (Integer) goodsClassDao.excute(new HibernateCallback() {
-
-			public Object doInHibernate(Session session) throws HibernateException {
-				session.getTransaction().begin();
-				goodsClass.setCreatetime(java.lang.System.currentTimeMillis());
-				Serializable id = session.save(goodsClass);
-				Properties properties = new Properties();
-				InputStream in = null;
-				try {
-					in = this.getClass().getClassLoader().getResourceAsStream("url.properties");
-					properties.load(in);
-					String url = (String) properties.get("url");
-					url = MessageFormat.format(url, id, goodsClass.getKey(), goodsClass.getName());
-					goodsClass.setUrl(url);
-					session.update(goodsClass);
-					session.flush();
-					session.getTransaction().commit();
-				} catch (FileNotFoundException e) {
-					session.getTransaction().rollback();
-					e.printStackTrace();
-					return 1;
-				} catch (IOException e) {
-					session.getTransaction().rollback();
-					e.printStackTrace();
-					return 2;
-				} finally {
-					if (in != null) {
-						try {
-							in.close();
-						} catch (IOException e) {
-							e.printStackTrace();
-						}
-					}
-				}
-				return null;
-			}
-		});
-	}
-
-	
-	@Transactional
-	public void deleteGoodsClasss(long[] gcids) {
-		for (long id : gcids) {
-			superGoodsClassService.deleteSuperGoodsClass(id);
-			classRecommendGoodsService.deleteClassGoodsByGC(id);
-			goodsSecondClassService.deleteSecondClassByGC(id);
-			goodsClassDao.delete(new GoodsClass(id));
-		}
-	}
-	
-	public Integer updateGoodsClass(final GoodsClass goodsClass) {
-
-		return (Integer) goodsClassDao.excute(new HibernateCallback() {
-
-			public Object doInHibernate(Session session) throws HibernateException {
-				session.getTransaction().begin();
-				goodsClass.setCreatetime(java.lang.System.currentTimeMillis());
-				session.update(goodsClass);
-				Properties properties = new Properties();
-				InputStream in = null;
-				try {
-					in = this.getClass().getClassLoader().getResourceAsStream("url.properties");
-					properties.load(in);
-					String url = (String) properties.get("url");
-					
-					java.lang.System.out.println(goodsClass.getKey());
-					java.lang.System.out.println(goodsClass.getName());
-					
-					String encodeKey = URLEncoder.encode(goodsClass.getKey(), "utf-8");
-					String encodeName = URLEncoder.encode(goodsClass.getName(), "utf-8");
-					url = MessageFormat.format(url, goodsClass.getId(), encodeKey, encodeName);
-					goodsClass.setUrl(url);
-					session.update(goodsClass);
-					session.flush();
-					session.getTransaction().commit();
-				} catch (FileNotFoundException e) {
-					session.getTransaction().rollback();
-					e.printStackTrace();
-					return 1;
-				} catch (IOException e) {
-					session.getTransaction().rollback();
-					e.printStackTrace();
-					return 2;
-				} finally {
-					if (in != null) {
-						try {
-							in.close();
-						} catch (IOException e) {
-							e.printStackTrace();
-						}
-					}
-				}
-				return null;
-			}
-		});
-	}
-
-	@SuppressWarnings("unchecked")
 	@Override
-	public List<GoodsClass> queryAll(String platform, String packages) throws Exception{
+	public GoodsClass selectByPrimaryKey(Long gcid) {
+		return goodsClassMapper.selectByPrimaryKey(gcid);
+	}
 
-		List<System> defultList = systemService.getSystems();
+	@Override
+	public int updateByPrimaryKeySelective(GoodsClass record) {
+		return goodsClassMapper.updateByPrimaryKeySelective(record);
+	}
 
-		platform = Utils.getMap().get(platform);
-		com.yeshi.fanli.entity.system.System system = systemService.getSystem(platform, packages);
-		
-		List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
-		List<SuperGoodsClass> superGoodsClassList = null;
-		List<Long> gcIdList = new ArrayList<Long>();
-		
-		if (system == null) {
-			
-			goodsClassList = (List<GoodsClass>) goodsClassDao.excute(new HibernateCallback<List<GoodsClass>>() {
-				public List<GoodsClass> doInHibernate(Session session) throws HibernateException {
-					Query query = session.createQuery(" from GoodsClass order by orderby");
-					return query.list();
-				}
-			});
-			
-			if (goodsClassList == null || goodsClassList.size() == 0) {
-				return null;
-			}
-			
-			/* 瀛樻斁绫诲埆id闆嗗悎 */
-			for (GoodsClass rs : goodsClassList) {
-				gcIdList.add(rs.getId());
-			}
+	@Cacheable(value = "classCache", key = "'getGoodsClass-'+#gcid")
+	@Override
+	public GoodsClass getGoodsClassCache(long gcid) {
+		return getGoodsClass(gcid);
+	}
 
-		} else if (system != null) {
-			superGoodsClassList = superGoodsClassService.getSuperGoodsClassAll(system.getId());
-			
-			if (goodsClassList == null || goodsClassList.size() == 0) {
-				return null;
-			}
-			
-			for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
-				GoodsClass goodsClass = superGoodsClass.getGoodsClass();
-				goodsClassList.add(goodsClass);
-				gcIdList.add(goodsClass.getId());
-			}
-			
+	@Override
+	public void deleteGoodsClass(long id) {
+		goodsClassMapper.deleteByPrimaryKey(id);
+	}
+
+	@Override
+	public List<GoodsClass> listquery(Integer sex) throws Exception {
+
+		List<GoodsClass> list = goodsClassMapper.getGoodsClassAll(sex);
+
+		if (list != null && list.size() == 0) {
+			return list;
 		}
-		
-		/* 鏍规嵁绫诲埆 id 鏌ヨ鍏宠仈绯荤粺鏁版嵁 */
-		superGoodsClassList = superGoodsClassService.getSuperGoodsClasss(gcIdList);
 
-		for (GoodsClass gclass : goodsClassList) {
-			
+		for (GoodsClass gclass : list) {
 			Long iosClick = gclass.getIosClick();
 			Long androidClick = gclass.getAndroidClick();
 
@@ -404,142 +104,192 @@
 				gclass.setCountClick(0l);
 			}
 
-			int countlabel = labelClassMapper.getCountQueryByClassId(gclass.getId());
+			// 鍙傛暟澶勭悊
+			String searchParam = gclass.getSearchParam();
+			if (searchParam == null) {
+				gclass.setSearchParam("");
+			} else {
+				gclass.setSearchParam(searchParam);
+			}
+
+			// 鏍囩
+			int countlabel = labelClassService.getCountQueryByClassId(gclass.getId());
 			gclass.setCountlabel(countlabel);
 
-			List<Long> gList = new ArrayList<Long>();
-			if (superGoodsClassList != null && superGoodsClassList.size() > 0) {
-				for (SuperGoodsClass srs : superGoodsClassList) {
-					
-					long rsId = srs.getGoodsClass().getId();
-					
-					if (gclass.getId() == rsId) {
-						System gsystem = srs.getSystem();
-						gList.add(gsystem.getId());
-					}
+			List<TaoBaoClass> listTB = taoBaoClassService.listBySystemCid(0, Integer.MAX_VALUE, gclass.getId());
+			if (listTB == null || listTB.size() == 0) {
+				gclass.setTaobaoCids("");
+			} else {
+				String taobaoCids = "";
+				for (TaoBaoClass taoBaoClass : listTB) {
+					taobaoCids = taobaoCids + taoBaoClass.getCategoryName() + "-" + taoBaoClass.getCategoryId() + ",";
 				}
-			}
-			
-			List<System> newList = new ArrayList<System>();
-			// 鏄惁鏈夊叧鑱旂郴缁熼�夐」
-			for (System dsystem : defultList) {
-				
-				System newsystem = new System();
-				
-				PropertyUtils.copyProperties(newsystem, dsystem);
-				newsystem.setCheck(0);
-				
-				if (gList != null && gList.size() > 0) {
-					Long did = newsystem.getId();
-					for (Long gid : gList) {
-						if (gid == did) {
-							newsystem.setCheck(1);
-						}
-					}
-				}
-				
-				newList.add(newsystem);
-			}
-			 
-			gclass.setSystemList(newList);
-			 
-		}
-		
-		return goodsClassList;
 
+				if (!StringUtil.isNullOrEmpty(taobaoCids)) {
+					taobaoCids = taobaoCids.substring(0, taobaoCids.length() - 1);
+				}
+				gclass.setTaobaoCids(taobaoCids);
+			}
+
+		}
+		return list;
 	}
-	
+
 	public List<GoodsClass> getGoodsClassAll() {
-		return goodsClassDao.list("from GoodsClass order by orderby");
+		return goodsClassMapper.getGoodsClassAll(null);
 	}
 
 	@Override
-	public String getKwById(Long id) {
-		return goodsClassMapper.getKwById(id);
-	}
-	
-	@Override
-	public GoodsClass selectByPrimaryKey(Long gcid) {
-		return goodsClassMapper.selectByPrimaryKey(gcid);
-	}
-	
-	@Override
-	public int updateByPrimaryKeySelective(GoodsClass record) {
-		return goodsClassMapper.updateByPrimaryKeySelective(record);
-	}
-	
-	
-	
-	@Override
-	public List<GoodsClass> queryAll() {
-		return goodsClassMapper.queryAll();
-	}
-	
-	@Cacheable(value="classCache",key="'getGoodsClass-'+#gcid")
-	@Override
-	public GoodsClass getGoodsClassCache(long gcid) {
-		return getGoodsClass(gcid);
-	}
+	@Transactional(rollbackFor=Exception.class)
+	public void saveObject(MultipartFile file, GoodsClass record) throws GoodsClassException, Exception {
 
-	@Override
-	@SuppressWarnings("unchecked")
-	public long saveAdd(GoodsClass record, MultipartFile file) throws Exception{
-		
-		long result = 0;		
-		record.setCreatetime(java.lang.System.currentTimeMillis());
-		
-		/*  涓婁紶鏂板浘鐗�  */
-		if (file != null) {
-			InputStream inputStream = file.getInputStream();
-			String contentType = file.getContentType();
-			String type = contentType.substring(contentType.indexOf("/") + 1);
-			// 涓婁紶鏂囦欢鐩稿浣嶇疆
-			String fileUrl="ClassImg/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
-			String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
-			
-			record.setPicture(uploadFilePath);
+		String name = record.getName();
+		if (name == null || name.trim().length() == 0) {
+			throw new GoodsClassException(1, "鍒嗙被鍚嶇О涓嶈兘涓虹┖");
 		}
 		
-		addGoodsClass(record);
+		Integer sex = record.getSex();
+		if (sex == null) {
+			throw new GoodsClassException(1, "鎬у埆璁剧疆涓嶈兘涓虹┖");
+		}
 		
-		record.setOrderby((int)record.getId());
-		updateGoodsClass(record);
-		
-		long id = record.getId();
-		if (id > 0) 
-			return id;
-		
-		return result;
+		// 鍥剧墖涓婁紶
+		String picture = null;
+		if (file != null) {
+			picture = uploadPicture(file);
+		}
+
+		String params = record.getSearchParam();
+		if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
+			record.setSearchParam(null);
+		} else if (!StringUtil.isJson(params)) {
+			throw new GoodsClassException(1, "绛涢�夋潯浠堕潪JSON鏍煎紡");
+		}
+
+		Long id = record.getId();
+		if (id == null) {
+			record.setPicture(picture);
+			record.setIosClick(0L);
+			record.setAndroidClick(0L);
+			record.setCreatetime(java.lang.System.currentTimeMillis());
+
+			Integer state = record.getState();
+			if (state == null) {
+				record.setState(0);
+			}
+
+			if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
+				// 鎼滅储鏉′欢:鏈夊埜銆佸湪鍞环20-200銆佺墰鐨櫍杞诲井
+				record.setSearchParam(
+						"{\"quan\":1,\"endPrice\":220,\"includeGoodRate\":true,\"baoYou\":true,\"ip\":\"218.72.111.105\"}");
+			}
+
+			// 鎺掑簭
+			int maxOrder = goodsClassMapper.getMaxOrder();
+			record.setOrderby(maxOrder + 1);
+
+			goodsClassMapper.insert(record);
+
+		} else {
+			// 淇敼
+			GoodsClass resultObj = goodsClassMapper.selectByPrimaryKey(id);
+			if (resultObj == null) {
+				throw new GoodsClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪");
+			}
+
+			if (picture != null && picture.trim().length() > 0) {
+				// 鍒犻櫎鑰佸浘
+				removePicture(resultObj.getPicture());
+				// 瀛樺偍鏂板浘
+				record.setPicture(picture);
+			} else {
+				record.setPicture(resultObj.getPicture());
+			}
+
+			record.setIosClick(resultObj.getIosClick());
+			record.setOrderby(resultObj.getOrderby());
+			record.setAndroidClick(resultObj.getAndroidClick());
+			record.setCreatetime(resultObj.getCreatetime());
+			goodsClassMapper.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].trim();
+				tbCidList.add(Long.parseLong(cid));
+			}
+		}
+		taoBaoClassService.save(record.getId(), tbCidList);
 	}
-	
+
+	/**
+	 * 涓婁紶鍥剧墖
+	 * 
+	 * @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 = FilePathEnum.goodsClass.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
+		// 鎵ц涓婁紶
+		String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
+
+		return fileLink;
+	}
+
+	/**
+	 * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱
+	 * 
+	 * @param record
+	 * @throws Exception
+	 */
+	public void removePicture(String picture) throws Exception {
+		if (!Constant.IS_TEST)
+			if (picture != null && picture.trim().length() > 0) {
+				COSManager.getInstance().deleteFile(picture);
+			}
+	}
+
 	@Override
 	public void uploadPicture(GoodsClass record, MultipartFile file) throws Exception {
-		
+
 		InputStream inputStream = file.getInputStream();
 		String contentType = file.getContentType();
 		String type = contentType.substring(contentType.indexOf("/") + 1);
 		// 涓婁紶鏂囦欢鐩稿浣嶇疆
-		String fileUrl="ClassImg/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
-		
-		boolean deleteFile =true;
-		
-		/*  淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖  */
+		String fileUrl = FilePathEnum.goodsClassOld.getPath()+ UUID.randomUUID().toString().replace("-", "") + "." + type;
+
+		boolean deleteFile = true;
+
+		/* 淇敼鍥剧墖鏃讹紝鍏堝垹闄ゅ凡瀛樺湪鍥剧墖 */
 		String picture = record.getPicture();
-		if (!StringUtil.isNullOrEmpty(picture)) 
+		if (!StringUtil.isNullOrEmpty(picture))
 			deleteFile = COSManager.getInstance().deleteFile(picture);
-		
+
 		String uploadFilePath = null;
-		/*  涓婁紶鏂板浘鐗�  */
+		/* 涓婁紶鏂板浘鐗� */
 		if (deleteFile) {
 			uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
 		}
-		
-		/*  鏇存柊鏁版嵁搴撲俊鎭�  */
+
+		/* 鏇存柊鏁版嵁搴撲俊鎭� */
 		if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
 			record.setPicture(uploadFilePath);
-			updateGoodsClass(record);
+			goodsClassMapper.updateByPrimaryKey(record);
 		}
-		
+
 	}
 
 	/**
@@ -547,25 +297,137 @@
 	 */
 	@Override
 	public void removePicture(GoodsClass record) throws Exception {
-		
+
 		String fileUrl = record.getPicture();
-		
 		boolean deleteFile = true;
-		
+
 		if (StringUtil.isNullOrEmpty(fileUrl)) {
 			return;
 		}
-		
+
 		deleteFile = COSManager.getInstance().deleteFile(fileUrl);
-		
 		if (deleteFile) {
 			record.setPicture(null);
 			// 鏇存柊鏁版嵁搴�
-			 updateGoodsClass(record);
-		} 
-		
-		return;
+			goodsClassMapper.updateByPrimaryKey(record);
+		}
 	}
 
+	@Override
+	public void switchState(Long id) throws GoodsClassException {
+		if (id == null) {
+			throw new GoodsClassException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		GoodsClass resultObj = goodsClassMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new GoodsClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		GoodsClass updateObj = new GoodsClass();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		goodsClassMapper.updateByPrimaryKeySelective(updateObj);
+	}
 	
+	
+	@Override
+	@Cacheable(value = "classCache", key = "'getEffectiveClassCache'")
+	public List<GoodsClass> getEffectiveClassCache() {
+		return goodsClassMapper.getEffectiveClass();
+	}
+
+	@Override
+	@Cacheable(value = "classCache", key = "'getClassListAllCache'+#changePicture")
+	public List<Map<String, Object>> getClassListAllCache(boolean changePicture) throws Exception {
+
+		List<GoodsClass> goodsClassList = goodsClassMapper.getEffectiveClass();
+		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()) {
+
+						// 1.5.3鏂扮増鍥剧墖鏇挎崲
+						if (changePicture) {
+							String pictureSecond = goodsSubClass.getPictureSecond();
+							if (pictureSecond != null && pictureSecond.trim().length() > 0) {
+								goodsSubClass.setPicture(pictureSecond);
+							}
+						}
+
+						// 瀵瑰簲涓嬪瓙鍒嗙被
+						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;
+	}
+
+	@Override
+	@Transactional(rollbackFor=Exception.class)
+	public void updateOrder(Long id, Integer moveType) throws GoodsClassException {
+
+		if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
+			throw new GoodsClassException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+
+		GoodsClass resultObj = goodsClassMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new GoodsClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+
+		Integer order = resultObj.getOrderby();
+		// 鑾峰彇浜ゆ崲瀵硅薄
+		GoodsClass exchangeObject = goodsClassMapper.getByAdjoinOrder(order, moveType);
+		if (exchangeObject == null) {
+			if (moveType == 1) {
+				throw new GoodsClassException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡");
+			} else {
+				throw new GoodsClassException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡");
+			}
+		}
+
+		resultObj.setOrderby(exchangeObject.getOrderby());
+		exchangeObject.setOrderby(order);
+
+		goodsClassMapper.updateByPrimaryKey(resultObj);
+		goodsClassMapper.updateByPrimaryKey(exchangeObject);
+	}
+
 }

--
Gitblit v1.8.0