yujian
2019-12-03 2442c923fd35ef864be1cfe07e039eebfaf24ffc
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -86,13 +86,9 @@
      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) {
@@ -109,6 +105,7 @@
         }
      }
      record.setName(name.trim());
      Long id = record.getId();
      if (id == null) {
         record.setCreateTime(new Date());
@@ -119,7 +116,8 @@
         
         BrandInfo resultObj = new BrandInfo();
         resultObj.setId(record.getId());
         resultObj.setWeight(Double.valueOf(record.getId()));
         resultObj.setOrder(Integer.valueOf(record.getId().toString()));
         resultObj.setWeight(500.00);
         brandInfoMapper.updateByPrimaryKeySelective(resultObj);
      } else {
         BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
@@ -145,6 +143,7 @@
            record.setShopTotal(resultObj.getShopTotal());
         }
         
         record.setOrder(resultObj.getOrder());
         record.setWeight(resultObj.getWeight());
         record.setCreateTime(resultObj.getCreateTime());
         record.setUpdateTime(new Date());
@@ -226,18 +225,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 +244,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
@@ -370,6 +369,7 @@
         brandInfo.setGoodsTotal(numInfo.getGoodsTotal());
         brandInfo.setShopTotal(numInfo.getShopTotal());
         brandInfo.setUpdateTime(new Date());
         brandInfo.setWeight(Math.random() * 1000);
         brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
      }
   }