admin
2019-09-24 f54093a69938aca18ca6ba005e17afe5ee5bbfe6
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -1,14 +1,18 @@
package com.yeshi.fanli.service.impl.brand;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
@@ -27,6 +31,7 @@
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
@@ -64,7 +69,7 @@
   private BrandShopCaheService brandShopCaheService;
   @Override
   public void saveObject(BrandInfo record) throws BrandInfoException {
   public void saveObject(MultipartFile file, BrandInfo record) throws BrandInfoException {
      String name = record.getName();
      if (name == null || name.trim().length() == 0)
         throw new BrandInfoException(1, "名称不能为空");
@@ -72,6 +77,16 @@
      Integer state = record.getState();
      if (state == null)
         record.setState(0);
      // 图片上传
      String picture = null;
      if (file != null) {
         try {
            picture = uploadPicture(file);
         } catch (Exception e) {
            throw new BrandInfoException(1, "图片上传失败");
         }
      }
      Long id = record.getId();
      if (id == null) {
@@ -83,12 +98,46 @@
         if (resultObj == null)
            throw new BrandInfoException(1, "修改内容已不存在");
         if (picture != null && picture.trim().length() > 0) {
            // 删除老图
            if (picture != null && picture.trim().length() > 0 && !Constant.IS_TEST) {
               COSManager.getInstance().deleteFile(picture);
            };
            // 存储新图
            record.setIcon(picture);
         } else {
            record.setIcon(resultObj.getIcon());
         }
         record.setGoodsTotal(resultObj.getGoodsTotal());
         record.setCreateTime(resultObj.getCreateTime());
         record.setUpdateTime(new Date());
         brandInfoMapper.updateByPrimaryKey(record);
      }
   }
   /**
    * 上传图片
    * @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/brand/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
      // 执行上传
      String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
      return fileLink;
   }
   @Override
   public int deleteBatchByPrimaryKey(List<Long> list) {
      return brandInfoMapper.deleteBatchByPrimaryKey(list);