yujian
2019-12-03 2442c923fd35ef864be1cfe07e039eebfaf24ffc
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -19,8 +19,10 @@
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.brand.BrandGoodsCahe;
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;
@@ -80,18 +82,19 @@
      if (StringUtil.isNullOrEmpty(name))
         throw new BrandInfoException(1, "名称不能为空");
      String shopKey = record.getShopKey();
      if (StringUtil.isNullOrEmpty(shopKey))
         record.setShopKey(name);
      BrandClass brandClass = record.getBrandClass();
      if (brandClass ==null || brandClass.getId() == null)
         throw new BrandInfoException(1, "分类不能为空");
      
      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)
         record.setState(0);
      if (state == null) {
         state = 0;
         record.setState(state);
      }
      // 图片上传
      String picture = null;
      if (file != null) {
@@ -102,11 +105,20 @@
         }
      }
      record.setName(name.trim());
      Long id = record.getId();
      if (id == null) {
         record.setCreateTime(new Date());
         record.setGoodsTotal(0);
         record.setShopTotal(0);
         record.setUpdateTime(new Date());
         brandInfoMapper.insert(record);
         BrandInfo resultObj = new BrandInfo();
         resultObj.setId(record.getId());
         resultObj.setOrder(Integer.valueOf(record.getId().toString()));
         resultObj.setWeight(500.00);
         brandInfoMapper.updateByPrimaryKeySelective(resultObj);
      } else {
         BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
         if (resultObj == null)
@@ -122,15 +134,20 @@
         } else {
            record.setIcon(resultObj.getIcon());
         }
         if (state == 0){
            record.setGoodsTotal(0);
            record.setShopTotal(0);
         } else {
            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){
            executor.execute(new Runnable() {
@@ -147,9 +164,13 @@
         executor.execute(new Runnable() {
            @Override
            public void run() {
               int goodsTotal = brandGoodsCaheService.addBrandGoods(record);
               record.setGoodsTotal(goodsTotal);
               brandInfoMapper.updateByPrimaryKeySelective(record);
               BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(record);
               BrandInfo update = new BrandInfo();
               update.setId(record.getId());
               update.setGoodsTotal(numInfo.getGoodsTotal());
               update.setShopTotal(numInfo.getShopTotal());
               brandInfoMapper.updateByPrimaryKeySelective(update);
            }
         });
      }
@@ -191,15 +212,45 @@
      
      return brandInfoMapper.deleteBatchByPrimaryKey(list);
   }
   @Override
   public void updateOrder(Long id, Integer moveType) throws BrandInfoException {
      if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1)))
         throw new BrandInfoException(1, "传递的类型不正确");
      if (id == null)
         throw new BrandInfoException(1, "ID不能为空");
      BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
      if (resultObj == null)
         throw new BrandInfoException(1, "操作数据已不存在");
      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.setOrder(changeObj.getOrder());
      BrandInfo changeObj2 = new BrandInfo();
      changeObj2.setId(changeObj.getId());
      changeObj2.setOrder(oldOrder);
      brandInfoMapper.updateByPrimaryKeySelective(changeObj1);
      brandInfoMapper.updateByPrimaryKeySelective(changeObj2);
   }
   @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
@@ -288,6 +339,13 @@
         BrandInfo updateInfo = new BrandInfo();
         updateInfo.setId(brandInfo.getId());
         updateInfo.setGoodsTotal((int)goodsTotal);
         List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(brandInfo.getId());
         if (listshop == null) {
            updateInfo.setShopTotal(0);
         } else {
            updateInfo.setShopTotal(listshop.size());
         }
         brandInfoMapper.updateByPrimaryKeySelective(updateInfo);
      }
   }
@@ -306,10 +364,12 @@
            continue;
         // 添加商品
         int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo);
         BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo);
         brandInfo.setGoodsTotal(goodsTotal);
         brandInfo.setGoodsTotal(numInfo.getGoodsTotal());
         brandInfo.setShopTotal(numInfo.getShopTotal());
         brandInfo.setUpdateTime(new Date());
         brandInfo.setWeight(Math.random() * 1000);
         brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
      }
   }
@@ -332,7 +392,7 @@
      return brandInfoMapper.listValidByCidToApp(cid);
   }
//   @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#start +'-'+#cid")
   @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#cid")
   @Override
   public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) {
      List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid);