admin
2020-08-26 26f7accb815f55f18f8eedfca4324700a96884ec
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -8,13 +8,13 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.task.TaskExecutor;
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;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
@@ -23,19 +23,17 @@
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.brand.BrandShopCahe;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.common.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.exception.brand.BrandInfoException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.brand.BrandGoodsCaheService;
import com.yeshi.fanli.service.inter.brand.BrandInfoService;
import com.yeshi.fanli.service.inter.brand.BrandShopCaheService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
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.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
@@ -49,22 +47,10 @@
   private BrandInfoMapper brandInfoMapper;
   @Resource
   private HongBaoManageService hongBaoManageService;
   @Resource
   private QualityGoodsService qualityGoodsService;
   @Resource
   private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
   @Resource
   private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
   private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
   @Resource
   private BrandClassShopService brandClassShopService;
   @Resource
   private BrandShopCaheDao brandShopCaheDao;
   @Resource
   private BrandGoodsCaheService brandGoodsCaheService;
@@ -181,7 +167,7 @@
         executor.execute(new Runnable() {
            @Override
            public void run() {
               BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(record);
               BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(record, SystemEnum.blks);
               BrandInfo update = new BrandInfo();
               update.setId(record.getId());
@@ -201,20 +187,42 @@
    * @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 filePath = FilePathEnum.brand.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
      // 执行上传
      String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
      return fileLink;
      return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
   }
   @Override
   public void switchState(Long id) throws BrandInfoException {
      if (id == null) {
         throw new BrandInfoException(1, "请传递正确参数");
      }
      BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
      if (resultObj == null) {
         throw new BrandInfoException(1, "此内容已不存在");
      }
      Integer state = resultObj.getState();
      if (state == null || state == 0) {
         state = 1;
      } else {
         state = 0;
      }
      BrandInfo updateObj = new BrandInfo();
      updateObj.setId(id);
      updateObj.setState(state);
      brandInfoMapper.updateByPrimaryKeySelective(updateObj);
   }
   @Override
   public int deleteBatchByPrimaryKey(List<Long> list) {
      executor.execute(new Runnable() {
@@ -272,10 +280,10 @@
   @Override
   @Cacheable(value = "brandCache", key = "'listValidBrandInfoCache-'+#cid")
   public List<BrandInfo> listValidBrandInfoCache(Long cid) {
   public List<BrandInfo> listValidBrandInfoCache(Long cid,SystemEnum system) {
      List<BrandInfo> listInfo = new ArrayList<BrandInfo>();
      List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid);
      List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid,system);
      if (listShop == null || listShop.size() == 0)
         return listInfo;
      for (TaoBaoShop taoBaoShop : listShop) {
@@ -289,11 +297,11 @@
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid+'-'+#platform+'-'+#version")
   public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid, String platform, String version) {
   @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid+'-'+#platform+'-'+#version+'-'+#system")
   public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid, String platform, String version,SystemEnum system) {
      List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
      List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid, platform, version);
      List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid, platform, version,system);
      if (listShop == null || listShop.size() == 0)
         return listInfo;
@@ -370,12 +378,15 @@
   @Override
   public void addShopAndGoods(long start, int count) {
      List<BrandInfo> list = brandInfoMapper.listValidAll(start, count);
      addShopAndGoods(list);
   }
   @Override
   public void addShopAndGoods(List<BrandInfo> list) {
      if (list == null || list.size() == 0)
         return;
      long startTime = java.lang.System.currentTimeMillis();
      LogHelper.test(start + "品牌更新service---addShopAndGoods" + startTime);
      // long startTime = java.lang.System.currentTimeMillis();
      for (BrandInfo brandInfo : list) {
         try {
            String name = brandInfo.getName();
@@ -383,7 +394,7 @@
            if (StringUtil.isNullOrEmpty(name) && StringUtil.isNullOrEmpty(searchKey))
               continue;
            // 添加商品
            BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo);
            BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo, SystemEnum.blks);
            BrandInfo updateInfo = new BrandInfo();
            updateInfo.setId(brandInfo.getId());
@@ -396,9 +407,7 @@
            LogHelper.errorDetailInfo(e);
         }
      }
      long endTime = java.lang.System.currentTimeMillis();
      LogHelper.test(start + "品牌更新service---addShopAndGoods" + endTime + ",本次总耗时:" + (endTime - startTime) / 1000);
      // long endTime = java.lang.System.currentTimeMillis();
   }
   @Override
@@ -407,26 +416,26 @@
   }
   @Override
   public long countValidByCidToApp(Long cid) {
      return brandInfoMapper.countValidByCidToApp(cid);
   public long countValidByCidToApp(Long cid, SystemEnum system) {
      return brandInfoMapper.countValidByCidToApp(cid,system);
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listValidByCidToApp-'+#cid")
   public List<BrandInfo> listValidByCidToApp(Long cid) {
   @Cacheable(value = "brandCache", key = "'listValidByCidToApp-'+#cid+'-'+#system")
   public List<BrandInfo> listValidByCidToApp(Long cid, SystemEnum system) {
      if (cid == null)
         return null;
      return brandInfoMapper.listValidByCidToApp(cid);
      return brandInfoMapper.listValidByCidToApp(cid,system);
   }
   @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#cid")
   @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#cid+'-'+#system")
   @Override
   public List<BrandInfoVO> listValidToApp(long start, int count, Long cid, String platform, String version) {
      List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid);
   public List<BrandInfoVO> listValidToApp(long start, int count, Long cid, String platform, String version,SystemEnum system) {
      List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid,system);
      if (list == null || list.size() == 0)
         return null;
      ConfigParamsDTO configParamsDTO = hongBaoManageService.getShowComputeRate(platform, version);
      ConfigParamsDTO configParamsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version,system);
      List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
      for (int i = 0; i < list.size(); i++) {
@@ -468,8 +477,8 @@
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key+'-'+#platform+'-'+#version")
   public BrandInfoVO listByAlikeName(String key,String platform,String version) {
   @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key+'-'+#platform+'-'+#version+'-'+#system")
   public BrandInfoVO listByAlikeName(String key, String platform, String version,SystemEnum system) {
      if (StringUtil.isNullOrEmpty(key))
         return null;
@@ -477,8 +486,7 @@
      if (list == null || list.size() == 0)
         return null;
      ConfigParamsDTO configParamsDTO =  hongBaoManageService.getShowComputeRate(platform, version);
      ConfigParamsDTO configParamsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(platform, version, system);
      BrandInfoVO brand = list.get(0);
      List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId());
@@ -512,4 +520,10 @@
      brand.setListGoods(listGoodsVO);
      return brand;
   }
   @Override
   public List<BrandInfo> listValidOrderByUpdateTime(int page, int pageSize) {
      return brandInfoMapper.listValidAll((page - 1) * pageSize, pageSize);
   }
}