yujian
2019-05-14 ad9fbd2c18f280ef9bba47f28353d367cf2d94e8
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoShopServiceImpl.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.service.impl.taobao;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
@@ -18,13 +19,15 @@
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.db.MongoDBManager;
import com.yeshi.fanli.util.taobao.TaoBaoShopUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
@Service
public class TaoBaoShopServiceImpl implements TaoBaoShopService {
   @Resource
   private MongoDBManager mongoDBManager;
   @Resource
   private TaoBaoShopMapper taoBaoShopMapper;
@@ -53,32 +56,29 @@
      LogHelper.test("获取店铺信息耗时:" + (System.currentTimeMillis() - startTime));
      return shopInfo;
   }
   @Override
   public TaoBaoShop selectByPrimaryKey(Long id) {
      return taoBaoShopMapper.selectByPrimaryKey(id);
   }
   @Override
   public int insertSelective(TaoBaoShop record) {
      return taoBaoShopMapper.insertSelective(record);
   }
   @Override
   public int updateByPrimaryKeySelective(TaoBaoShop record) {
      return taoBaoShopMapper.updateByPrimaryKeySelective(record);
   }
   @Override
   public void changeInfo(MultipartFile file, Long id, String shopName) {
      TaoBaoShop taoBaoShop = taoBaoShopMapper.selectByPrimaryKey(id);
      if (taoBaoShop == null) {
         return;
      }
      String fileLink = null;
      if (file != null) {
         try {
@@ -87,44 +87,67 @@
            e.printStackTrace();
         }
      }
      TaoBaoShop updateShop = new TaoBaoShop();
      if (!StringUtil.isNullOrEmpty(fileLink)) {
         updateShop.setShopIconCustom(fileLink);
         // 删除图片
         String shopIconCustom = taoBaoShop.getShopIconCustom();
         if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
            COSManager.getInstance().deleteFile(shopIconCustom);
         }
      }
      if (StringUtil.isNullOrEmpty(shopName) || "null".equalsIgnoreCase(shopName)) {
         shopName = null;
      }
      updateShop.setId(id);
      updateShop.setShopName(shopName);
      updateShop.setShopNameCustom(shopName);
      taoBaoShopMapper.updateByPrimaryKeySelective(updateShop);
   }
   /**
    * 上传图片
    *
    * @param file
    * @return
    * @throws Exception
    */
   public String uploadPicture(MultipartFile file) throws Exception {
      // 文件解析
      // 文件解析
      InputStream inputStream = file.getInputStream();
      String contentType = file.getContentType();
      String type = contentType.substring(contentType.indexOf("/") + 1);
      // 文件路径
      String filePath="/img/TaoBaoShop/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
      String filePath = "/img/TaoBaoShop/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
      // 执行上传
      String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
      String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
      return fileLink;
   }
   @Override
   public List<TaoBaoShopVO> listBrandShopinfo(long start, int count, Long cid) {
      return taoBaoShopMapper.listBrandShopinfo(start, count, cid);
   }
   @Override
   public long countBrandShopinfo(Long cid) {
      return taoBaoShopMapper.countBrandShopinfo(cid);
   }
   @Override
   public TaoBaoShop getTaoBaoShop(Long auctionId, Long sellerId) {
      TaoBaoShop shop = taoBaoShopMapper.selectByPrimaryKey(sellerId);
      if (shop != null)
         return shop;
      shop = TaoBaoUtil.getTaoBaoShopDetailByAuctionId(auctionId);
      if (shop != null)
         taoBaoShopMapper.insert(shop);
      return shop;
   }
}