yujian
2019-12-19 626d711cb15896055c13fe344eb7fcc824589715
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -27,6 +27,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.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;
@@ -86,40 +87,58 @@
      if (brandClass ==null || brandClass.getId() == null)
         throw new BrandInfoException(1, "分类不能为空");
      
      String shopKey = record.getShopKey();
      if (StringUtil.isNullOrEmpty(shopKey))
         record.setShopKey(name);
      String searchKey = record.getSearchKey();
      if (StringUtil.isNullOrEmpty(searchKey))
         record.setSearchKey(name);
      BrandInfo existBrand = brandInfoMapper.selectByUniqueName(name.trim(), brandClass.getId(), record.getId());
      if (existBrand != null)
         throw new BrandInfoException(1, "该分类中已存在:" + name.trim());
      
      Integer state = record.getState();
      if (state == null) {
         state = 0;
         record.setState(state);
      }
      // 图片上传
      String picture = null;
      if (file != null) {
         try {
         try { // 图片上传
            picture = uploadPicture(file);
         } catch (Exception e) {
            throw new BrandInfoException(1, "图片上传失败");
         }
      }
      String searchKey = record.getSearchKey();
      if (!StringUtil.isNullOrEmpty(searchKey)) {
         if (StringUtil.isNullOrEmpty(record.getSearchKeyJD()))
            record.setSearchKeyJD(searchKey);
         if (StringUtil.isNullOrEmpty(record.getSearchKeyPDD()))
            record.setSearchKeyPDD(searchKey);
      }
      String shopKey = record.getShopKey();
      if (!StringUtil.isNullOrEmpty(shopKey)) {
         if (StringUtil.isNullOrEmpty(record.getShopKeyJD()))
            record.setShopKeyJD(shopKey);
         if (StringUtil.isNullOrEmpty(record.getShopKeyPDD()))
            record.setShopKeyPDD(shopKey);
      }
      record.setName(name.trim());
      record.setUpdateTime(new Date());
      Long id = record.getId();
      if (id == null) {
         record.setCreateTime(new Date());
         record.setIcon(picture);
         record.setWeight(500.00);
         record.setGoodsTotal(0);
         record.setShopTotal(0);
         record.setUpdateTime(new Date());
         record.setCreateTime(new Date());
         brandInfoMapper.insert(record);
         
         BrandInfo resultObj = new BrandInfo();
         resultObj.setId(record.getId());
         resultObj.setWeight(Double.valueOf(record.getId()));
         resultObj.setOrder(Integer.valueOf(record.getId().toString()));
         brandInfoMapper.updateByPrimaryKeySelective(resultObj);
      } else {
         BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
@@ -144,10 +163,9 @@
            record.setGoodsTotal(resultObj.getGoodsTotal());
            record.setShopTotal(resultObj.getShopTotal());
         }
         record.setOrder(resultObj.getOrder());
         record.setWeight(resultObj.getWeight());
         record.setCreateTime(resultObj.getCreateTime());
         record.setUpdateTime(new Date());
         brandInfoMapper.updateByPrimaryKey(record);
         
         if (state == 0){
@@ -226,18 +244,18 @@
      if (resultObj == null) 
         throw new BrandInfoException(1, "操作数据已不存在");
      
      Double oldOrder = resultObj.getWeight();
      Integer oldOrder = resultObj.getOrder();
      BrandInfo changeObj = brandInfoMapper.getByAdjoinOrder(resultObj.getBrandClass().getId(),oldOrder, moveType);
      if (changeObj == null )
         throw new BrandInfoException(1, "已经在最边缘,无可交换的位置");
      
      BrandInfo changeObj1 = new BrandInfo();
      changeObj1.setId(id);
      changeObj1.setWeight(changeObj.getWeight());
      changeObj1.setOrder(changeObj.getOrder());
      
      BrandInfo changeObj2 = new BrandInfo();
      changeObj2.setId(changeObj.getId());
      changeObj2.setWeight(oldOrder);
      changeObj2.setOrder(oldOrder);
      
      brandInfoMapper.updateByPrimaryKeySelective(changeObj1);
      brandInfoMapper.updateByPrimaryKeySelective(changeObj2);
@@ -245,13 +263,13 @@
   
   @Override
   public List<BrandInfo> listQuery(long start, int count, String key, Long cid, Integer state) {
      return brandInfoMapper.listQuery(start, count, key, cid, state);
   public List<BrandInfo> listQuery(long start, int count, List<String> keys, Long cid, Integer state, Integer showState) {
      return brandInfoMapper.listQuery(start, count, keys, cid, state,showState);
   }
   @Override
   public long countQuery(String key, Long cid, Integer state) {
      return brandInfoMapper.countQuery(key, cid, state);
   public long countQuery(List<String> keys, Long cid, Integer state, Integer showState) {
      return brandInfoMapper.countQuery(keys, cid, state, showState);
   }
   @Override
@@ -346,7 +364,7 @@
         } else {
            updateInfo.setShopTotal(listshop.size());
         }
         updateInfo.setWeight(Math.random() * 1000);
         brandInfoMapper.updateByPrimaryKeySelective(updateInfo);
      }
   }
@@ -359,18 +377,25 @@
         return;
      for (BrandInfo brandInfo : list) {
         String name = brandInfo.getName();
         String searchKey = brandInfo.getSearchKey();
         if (StringUtil.isNullOrEmpty(name) && StringUtil.isNullOrEmpty(searchKey))
            continue;
         // 添加商品
         BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo);
         brandInfo.setGoodsTotal(numInfo.getGoodsTotal());
         brandInfo.setShopTotal(numInfo.getShopTotal());
         brandInfo.setUpdateTime(new Date());
         brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
         try {
            String name = brandInfo.getName();
            String searchKey = brandInfo.getSearchKey();
            if (StringUtil.isNullOrEmpty(name) && StringUtil.isNullOrEmpty(searchKey))
               continue;
            // 添加商品
            BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo);
            BrandInfo updateInfo = new BrandInfo();
            updateInfo.setId(brandInfo.getId());
            updateInfo.setWeight(Math.random() * 1000);
            updateInfo.setGoodsTotal(numInfo.getGoodsTotal());
            updateInfo.setShopTotal(numInfo.getShopTotal());
            updateInfo.setUpdateTime(new Date());
            brandInfoMapper.updateByPrimaryKeySelective(updateInfo);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
         }
      }
   }
@@ -401,7 +426,7 @@
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE);
      ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate());
      List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
      for (int i = 0; i < list.size(); i++) {
         BrandInfoVO brand = list.get(i);
@@ -440,4 +465,54 @@
      }
      return listInfo;
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listByAlikeName-'+#key")
   public BrandInfoVO listByAlikeName(String key) {
      if (StringUtil.isNullOrEmpty(key))
         return null;
      List<BrandInfoVO> list = brandInfoMapper.listByAlikeName(key);
      if (list == null || list.size() == 0)
         return null;
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      ConfigParamsDTO configParamsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate());
      BrandInfoVO brand = list.get(0);
      List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId());
      if (listGoods == null || listGoods.size() < 3)
         return null;
      List<GoodsDetailVO> listGoodsVO = new ArrayList<GoodsDetailVO>();
      for (BrandGoodsCahe brandGoods : listGoods) {
         JDGoods goodsJD = brandGoods.getGoodsJD();
         if (goodsJD != null) {
            listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, configParamsDTO));
            continue;
         }
         TaoBaoGoodsBrief goodsTB = brandGoods.getGoodsTB();
         if (goodsTB != null) {
            listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, configParamsDTO));
            continue;
         }
         PDDGoodsDetail goodsPDD = brandGoods.getGoodsPDD();
         if (goodsPDD != null) {
            listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, configParamsDTO));
            continue;
         }
      }
      if (listGoodsVO.size() < 3)
         return null;
      brand.setListGoods(listGoodsVO);
      return brand;
   }
}