|
@@ -1,9 +1,11 @@
|
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.txz.mall.core.AbstractService;
|
|
|
+import com.txz.mall.core.ServiceException;
|
|
|
import com.txz.mall.dao.CategoryMapper;
|
|
|
import com.txz.mall.model.Category;
|
|
|
import com.txz.mall.service.CategoryService;
|
|
@@ -33,12 +35,43 @@ public class CategoryServiceImpl extends AbstractService<Category> implements Ca
|
|
|
return getTree(type, status, name, null);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 带结构的无线级分类
|
|
|
- *
|
|
|
- * @author Mr.Zhang
|
|
|
- * @since 2020-04-16
|
|
|
- */
|
|
|
+ @Override
|
|
|
+ public boolean updateStatus(Long id) {
|
|
|
+ Category category = findById(id);
|
|
|
+ if (category == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (category.getStatus().equals(0)) {
|
|
|
+ category.setStatus(1);
|
|
|
+ }
|
|
|
+ if (category.getStatus().equals(1)) {
|
|
|
+ category.setStatus(0);
|
|
|
+ }
|
|
|
+ this.update(category);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ //查看是否有子类, 物理删除
|
|
|
+ if (getChildCountByPid(id) > 0) {
|
|
|
+ throw new ServiceException("当前分类下有子类,请先删除子类!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Category category = new Category();
|
|
|
+ category.setId(id);
|
|
|
+ category.setIsDelete(1);
|
|
|
+ this.update(category);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getChildCountByPid(Long pid) {
|
|
|
+ Condition condition = new Condition(Category.class);
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("pid", pid);
|
|
|
+ List<Category> list = this.findByCondition(condition);
|
|
|
+ return list.size();
|
|
|
+ }
|
|
|
+
|
|
|
private List<CategoryTreeVo> getTree(Integer type, Integer status, String name, List<Integer> categoryIdList) {
|
|
|
//循环数据,把数据对象变成带list结构的vo
|
|
|
List<CategoryTreeVo> treeList = new ArrayList<>();
|
|
@@ -90,9 +123,8 @@ public class CategoryServiceImpl extends AbstractService<Category> implements Ca
|
|
|
treeList.add(categoryTreeVo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//返回
|
|
|
- Map<Integer, CategoryTreeVo> map = new HashMap<>();
|
|
|
+ Map<Long, CategoryTreeVo> map = new HashMap<>();
|
|
|
//ID 为 key 存储到map 中
|
|
|
for (CategoryTreeVo categoryTreeVo1 : treeList) {
|
|
|
map.put(categoryTreeVo1.getId(), categoryTreeVo1);
|