admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java
@@ -51,65 +51,78 @@
   @Override
   public void saveObject(BrandClass record) throws BrandClassException, Exception{
      Long gcid = record.getGcid();
      if (gcid != null) {
         GoodsClass goodsClass = goodsClassService.selectByPrimaryKey(gcid);
         if (goodsClass != null) {
            record.setName(goodsClass.getName());
            record.setGoodsClass(goodsClass);
         }
      }
      if (gcid != null)
         record.setGoodsClass(new GoodsClass(gcid));
      
      String name = record.getName();
      if (name == null || name.trim().length() == 0) {
      if (name == null || name.trim().length() == 0)
         throw new BrandClassException(1, "名称和分类不能同时为空");
      }
      
      Integer state = record.getState();
      if (state == null) {
      if (state == null)
         record.setState(0);
      }
      record.setUpdateTime(new Date());
      
      Long id = record.getId();
      if (id == null) {
         record.setOrderBy(brandClassMapper.getMaxOrder() + 1);
         record.setCreateTime(new Date());
         record.setUpdateTime(new Date());
         brandClassMapper.insert(record);
      } else {
         BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id);
         if (resultObj == null) {
         if (resultObj == null)
            throw new BrandClassException(1, "修改内容已不存在");
         }
         record.setOrderBy(resultObj.getOrderBy());
         record.setCreateTime(resultObj.getCreateTime());
         record.setUpdateTime(new Date());
         brandClassMapper.updateByPrimaryKey(record);
      }
   }
   
   
   @Override
   public void updateOrder(Long id, Integer moveType) throws BrandClassException, Exception{
      if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
         throw new BrandClassException(1, "传递的类型不正确");
      }
   public void switchState(Long id) throws BrandClassException {
      if (id == null) {
         throw new BrandClassException(1, "ID不能为空");
         throw new BrandClassException(1, "请传递正确参数");
      }
      BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id);
      if (resultObj == null) {
         throw new BrandClassException(1, "操作数据已不存在");
         throw new BrandClassException(1, "此内容已不存在");
      }
      Integer state = resultObj.getState();
      if (state == null || state == 0) {
         state = 1;
      } else {
         state = 0;
      }
      BrandClass updateObj = new BrandClass();
      updateObj.setId(id);
      updateObj.setState(state);
      brandClassMapper.updateByPrimaryKeySelective(updateObj);
   }
   @Override
   public void updateOrder(Long id, Integer moveType) throws BrandClassException, Exception{
      if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1)))
         throw new BrandClassException(1, "传递的类型不正确");
      if (id == null)
         throw new BrandClassException(1, "ID不能为空");
      BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id);
      if (resultObj == null)
         throw new BrandClassException(1, "操作数据已不存在");
         
      Integer oldOrder = resultObj.getOrderBy();
      BrandClass changeObj = brandClassMapper.getByAdjoinOrder(oldOrder, moveType);
      
      if (changeObj == null ) {
      if (changeObj == null )
         throw new BrandClassException(1, "已经在最边缘,无可交换的位置");
      }
      // 交换排序序号
      resultObj.setOrderBy(changeObj.getOrderBy());
      changeObj.setOrderBy(oldOrder);
@@ -121,16 +134,12 @@
   
   @Override
   public int deleteBatchByPrimaryKey(List<Long> list) {
      // 删除已匹配的分类关系
      brandClassShopService.deleteBatchByClassId(list);
      return brandClassMapper.deleteBatchByPrimaryKey(list);
   }
   
   @Override
   public List<BrandClass> listQuery(long start, int count, String key, Integer state) {
      List<BrandClass> listQuery = brandClassMapper.listQuery(start, count, key, state);
      if (listQuery == null || listQuery.size() == 0) {
         return listQuery;
@@ -157,4 +166,6 @@
   
   
   
}