From 2ec42a5aacea35d2918f0e17f07685cf5b4d25c8 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 12 五月 2020 20:20:41 +0800 Subject: [PATCH] 包名引用路径更改 --- fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java | 367 ++++++++++++++++++++++------------------------------ 1 files changed, 156 insertions(+), 211 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 0e39efe..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 @@ -9,11 +9,10 @@ import java.util.UUID; import javax.annotation.Resource; -import javax.transaction.Transactional; -import org.apache.commons.beanutils.PropertyUtils; 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; @@ -22,35 +21,30 @@ 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.su.clazz.SuperGoodsClass; -import com.yeshi.fanli.entity.system.BusinessSystem; -import com.yeshi.fanli.exception.GoodsClassException; -import com.yeshi.fanli.service.inter.config.BusinessSystemService; +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.SuperGoodsClassService; +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; -import com.yeshi.fanli.util.Utils; @Service public class GoodsClassServiceImpl implements GoodsClassService { @Resource - private BusinessSystemService businessSystemService; - - @Resource - private SuperGoodsClassService superGoodsClassService; - - @Resource private GoodsClassMapper goodsClassMapper; - + @Resource private GoodsSubClassService goodsSubClassService; - + @Resource private LabelClassService labelClassService; - + + @Resource + private TaoBaoClassService taoBaoClassService; public GoodsClass getGoodsClass(long id) { return goodsClassMapper.selectByPrimaryKey(id); @@ -60,97 +54,43 @@ public int updateByPrimaryKey(GoodsClass record) { return goodsClassMapper.updateByPrimaryKey(record); } - + @Override public String getKeysById(Long id) { return goodsClassMapper.getKeysById(id); } - + @Override public GoodsClass selectByPrimaryKey(Long gcid) { return goodsClassMapper.selectByPrimaryKey(gcid); } - + @Override public int updateByPrimaryKeySelective(GoodsClass record) { return goodsClassMapper.updateByPrimaryKeySelective(record); } - - - @Cacheable(value="classCache",key="'getGoodsClass-'+#gcid") + + @Cacheable(value = "classCache", key = "'getGoodsClass-'+#gcid") @Override public GoodsClass getGoodsClassCache(long gcid) { return getGoodsClass(gcid); } - @Override public void deleteGoodsClass(long id) { goodsClassMapper.deleteByPrimaryKey(id); } - @Override - public int getCount(String platform, String packages, final String key) { - - Long systemId = null; - - platform = Utils.getMap().get(platform); - - BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages); - if (system != null) { - systemId = system.getId(); + public List<GoodsClass> listquery(Integer sex) throws Exception { + + List<GoodsClass> list = goodsClassMapper.getGoodsClassAll(sex); + + if (list != null && list.size() == 0) { + return list; } - ; - return goodsClassMapper.countByName(key, systemId); - } - - @Override - public List<GoodsClass> queryAll(String platform, String packages) throws Exception{ - - List<BusinessSystem> defultList = businessSystemService.getBusinessSystems(); - - platform = Utils.getMap().get(platform); - BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages); - - List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>(); - List<SuperGoodsClass> superGoodsClassList = null; - List<Long> gcIdList = new ArrayList<Long>(); - - if (system == null) { - - goodsClassList = goodsClassMapper.getGoodsClassAll(); - - if (goodsClassList == null || goodsClassList.size() == 0) { - return null; - } - - /* 瀛樻斁绫诲埆id闆嗗悎 */ - for (GoodsClass rs : goodsClassList) { - gcIdList.add(rs.getId()); - } - - } else if (system != null) { - superGoodsClassList = superGoodsClassService.getSuperGoodsClassBySystemId(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()); - } - - } - - /* 鏍规嵁绫诲埆 id 鏌ヨ鍏宠仈绯荤粺鏁版嵁 */ - superGoodsClassList = superGoodsClassService.getSuperGoodsClasss(gcIdList); - - for (GoodsClass gclass : goodsClassList) { - + for (GoodsClass gclass : list) { Long iosClick = gclass.getIosClick(); Long androidClick = gclass.getAndroidClick(); @@ -163,126 +103,100 @@ } else { gclass.setCountClick(0l); } - + + // 鍙傛暟澶勭悊 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) { - BusinessSystem 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<BusinessSystem> newList = new ArrayList<BusinessSystem>(); - // 鏄惁鏈夊叧鑱旂郴缁熼�夐」 - for (BusinessSystem dsystem : defultList) { - - BusinessSystem newsystem = new BusinessSystem(); - - 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); - } - } + + if (!StringUtil.isNullOrEmpty(taobaoCids)) { + taobaoCids = taobaoCids.substring(0, taobaoCids.length() - 1); } - - newList.add(newsystem); + gclass.setTaobaoCids(taobaoCids); } - - gclass.setSystemList(newList); - + } - - return goodsClassList; - + return list; } - + public List<GoodsClass> getGoodsClassAll() { - return goodsClassMapper.getGoodsClassAll(); + return goodsClassMapper.getGoodsClassAll(null); } - @Override - public void saveObject(MultipartFile file, GoodsClass record) throws GoodsClassException, Exception{ - + @Transactional(rollbackFor=Exception.class) + public void saveObject(MultipartFile file, GoodsClass record) throws GoodsClassException, Exception { + String name = record.getName(); if (name == null || name.trim().length() == 0) { throw new GoodsClassException(1, "鍒嗙被鍚嶇О涓嶈兘涓虹┖"); } + Integer sex = record.getSex(); + if (sex == null) { + throw new GoodsClassException(1, "鎬у埆璁剧疆涓嶈兘涓虹┖"); + } // 鍥剧墖涓婁紶 String picture = null; if (file != null) { picture = uploadPicture(file); } - + 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.setSearchParam(null); - } else { - record.setSearchParam(params); + } 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()); - - 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\"}"); + + 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); - - // 榛樿鎵�鏈夌郴缁熶娇鐢� - List<BusinessSystem> listSystems = businessSystemService.getBusinessSystems(); - if (listSystems != null && listSystems.size() > 0) { - for(BusinessSystem businessSystem: listSystems) { - SuperGoodsClass superGoodsClass = new SuperGoodsClass(); - superGoodsClass.setGoodsClass(record);; - superGoodsClass.setSystem(businessSystem); - superGoodsClassService.insertSelective(superGoodsClass); - } - } - + } else { // 淇敼 GoodsClass resultObj = goodsClassMapper.selectByPrimaryKey(id); if (resultObj == null) { throw new GoodsClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); } - + if (picture != null && picture.trim().length() > 0) { // 鍒犻櫎鑰佸浘 removePicture(resultObj.getPicture()); @@ -291,80 +205,91 @@ } 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瀽 + + // 鏂囦欢瑙f瀽 InputStream inputStream = file.getInputStream(); String contentType = file.getContentType(); String type = contentType.substring(contentType.indexOf("/") + 1); - + // 鏂囦欢璺緞 - String filePath="/img/GoodsClass/"+UUID.randomUUID().toString().replace("-", "") + "." + type; + String filePath = FilePathEnum.goodsClass.getPath() + 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 */ public void removePicture(String picture) throws Exception { - if (picture != null && picture.trim().length() > 0) { - COSManager.getInstance().deleteFile(picture); - } + 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); goodsClassMapper.updateByPrimaryKey(record); } - + } /** @@ -372,46 +297,57 @@ */ @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); // 鏇存柊鏁版嵁搴� goodsClassMapper.updateByPrimaryKey(record); - } + } } @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; + 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, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); } - List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>(); - for (SuperGoodsClass superGoodsClass : superGoodsClassList) { - GoodsClass goodsClass = superGoodsClass.getGoodsClass(); - goodsClassList.add(goodsClass); + Integer state = resultObj.getState(); + if (state == null || state == 0) { + state = 1; + } else { + state = 0; } - return goodsClassList; + GoodsClass updateObj = new GoodsClass(); + updateObj.setId(id); + updateObj.setState(state); + goodsClassMapper.updateByPrimaryKeySelective(updateObj); } @Override - @Cacheable(value="classCache",key="'getClassListAllCache-'+#systemId") - public List<Map<String, Object>> getClassListAllCache(Long systemId) throws Exception { + @Cacheable(value = "classCache", key = "'getEffectiveClassCache'") + public List<GoodsClass> getEffectiveClassCache() { + return goodsClassMapper.getEffectiveClass(); + } - List<GoodsClass> goodsClassList = goodsClassMapper.listGoodsClassBySystemId(systemId); + @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; } @@ -420,26 +356,36 @@ 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(); } + } } @@ -453,23 +399,22 @@ return list; } - @Override - @Transactional + @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); + GoodsClass exchangeObject = goodsClassMapper.getByAdjoinOrder(order, moveType); if (exchangeObject == null) { if (moveType == 1) { throw new GoodsClassException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡"); @@ -477,12 +422,12 @@ throw new GoodsClassException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡"); } } - + resultObj.setOrderby(exchangeObject.getOrderby()); exchangeObject.setOrderby(order); - + goodsClassMapper.updateByPrimaryKey(resultObj); goodsClassMapper.updateByPrimaryKey(exchangeObject); } - + } -- Gitblit v1.8.0