Commit d1143050 authored by shiyu's avatar shiyu

删除分类

parent 234d607f
......@@ -21,6 +21,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -150,20 +151,9 @@ public class CategoryController {
@PostMapping("/delete")
public Object delete(@RequestBody GoodsCategoryObsolete category) {
logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 商场管理->类目管理->删除,请求参数:{}", JSONObject.toJSONString(category));
Integer id = category.getId();
if (id == null) {
return ResponseUtil.badArgument();
}
categoryManager.deleteById(id);
Category pCat = new Category();
pCat.setId(category.getPid());
pCat.setIsLeaf(true);
categoryManager.updateById(pCat);
Object result = categoryService.delete(category);
logger.info("【请求结束】商场管理->类目管理->删除:响应结果:{}", "成功!");
return ResponseUtil.ok();
return result;
}
@RequiresPermissions("admin:category:list")
......
......@@ -3,8 +3,10 @@ package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.controller.CategoryController;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.admin.service.CategoryService;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.GoodsCategoryObsolete;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.manager.CategoryManager;
import com.wwdz.ch.db.manager.ItemManager;
......@@ -14,6 +16,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -101,6 +105,30 @@ public class CategoryServiceImpl implements CategoryService {
categoryManager.add(category);
}
@Override
public Object delete(GoodsCategoryObsolete category) {
Integer id = category.getId();
if (id == null) {
return ResponseUtil.badArgument();
}
//检验该分类下有没有商品,有商品的话不能删除
long count = itemManager.countByCid(id);
if (count > 0) {
return Result.failed("该分类下有归属商品,不能删除");
}
categoryManager.deleteById(id);
//查询该父节点下还有没有其它的节点,没有的话该父节点就是叶子节点
List<Category> categoryList = categoryManager.queryByPid(category.getPid());
if (CollectionUtils.isEmpty(categoryList)) {
Category pCat = new Category();
pCat.setId(category.getPid());
pCat.setIsLeaf(true);
categoryManager.updateById(pCat);
}
return Result.success();
}
@Override
public int updateById(Category category) {
return 0;
......
......@@ -2,6 +2,7 @@ package com.wwdz.ch.admin.service;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.GoodsCategoryObsolete;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
......@@ -14,6 +15,8 @@ public interface CategoryService {
void create(CategoryVo categoryVo);
Object delete(GoodsCategoryObsolete category);
List<Category> queryByLevel(Integer level, Integer offset, Integer limit);
List<Category> queryByPid(Integer pid);
......
......@@ -23,4 +23,6 @@ public interface ItemManager {
void cancelStandardItem(Long id);
Item findStandard(Integer cid);
long countByCid(Integer cid);
}
......@@ -106,4 +106,13 @@ public class ItemManagerImpl implements ItemManager {
criteria.andIsStdEqualTo(true);
return itemMapper.selectOneByExampleWithBLOBs(example);
}
@Override
public long countByCid(Integer cid) {
ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria();
criteria.andCidEqualTo(cid);
criteria.andIsDeletedEqualTo(false);
return itemMapper.countByExample(example);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment