yujian
2019-04-29 9a24f2802a3d6fe3e82c05e52f2880d65ad04dcf
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java
@@ -9,10 +9,10 @@
import java.util.UUID;
import javax.annotation.Resource;
import javax.transaction.Transactional;
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;
@@ -21,9 +21,11 @@
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.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.StringUtil;
@@ -39,6 +41,9 @@
   @Resource
   private LabelClassService labelClassService;
   
   @Resource
   private TaoBaoClassService taoBaoClassService;
   public GoodsClass getGoodsClass(long id) {
      return goodsClassMapper.selectByPrimaryKey(id);
@@ -112,6 +117,23 @@
         // 标签
         int countlabel = labelClassService.getCountQueryByClassId(gclass.getId());
         gclass.setCountlabel(countlabel);
         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() + ",";
            }
            if (!StringUtil.isNullOrEmpty(taobaoCids)){
               taobaoCids = taobaoCids.substring(0, taobaoCids.length()-1);
            }
            gclass.setTaobaoCids(taobaoCids);
         }
      }
      return list;
   }
@@ -122,6 +144,7 @@
   
   @Override
   @Transactional
   public void saveObject(MultipartFile file, GoodsClass record) throws GoodsClassException, Exception{
      
      String name = record.getName();
@@ -141,6 +164,7 @@
      } else if (!StringUtil.isJson(params)) {
         throw new GoodsClassException(1, "筛选条件非JSON格式");
      }
      
      
      Long id = record.getId();
@@ -188,6 +212,12 @@
         record.setAndroidClick(resultObj.getAndroidClick());
         record.setCreatetime(resultObj.getCreatetime());
         goodsClassMapper.updateByPrimaryKey(record);
      }
      // 保存淘宝商品分类id
      String taobaoCids = record.getTaobaoCids();
      if (!StringUtil.isNullOrEmpty(taobaoCids) && !"null".equalsIgnoreCase(taobaoCids)) {
         taoBaoClassService.save(record.getId(), taobaoCids);
      }
   }
   
@@ -284,8 +314,8 @@
   
   
   @Override
   @Cacheable(value="classCache",key="'getClassListAllCache'")
   public List<Map<String, Object>> getClassListAllCache() throws Exception {
   @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) {
@@ -312,10 +342,21 @@
               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();
               }
            }
         }