左侧树:删除分类
This commit is contained in:
parent
8bc44ffc64
commit
2a94318c9e
@ -49,4 +49,14 @@ public class CategoryController {
|
|||||||
categoryService.addCategory(params);
|
categoryService.addCategory(params);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除分类
|
||||||
|
*/
|
||||||
|
@Operation(summary = "删除分类")
|
||||||
|
@PostMapping("/delCategory")
|
||||||
|
public R<?> delCategory(@RequestBody JSONObject params) {
|
||||||
|
categoryService.delCategory(params);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,6 @@ public interface CategoryService extends IService<Category> {
|
|||||||
List<Category> showCategory(Category category);
|
List<Category> showCategory(Category category);
|
||||||
|
|
||||||
void addCategory(JSONObject params);
|
void addCategory(JSONObject params);
|
||||||
|
|
||||||
|
void delCategory(JSONObject params);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import iet.ustb.sf.domain.Category;
|
import iet.ustb.sf.domain.Category;
|
||||||
|
import iet.ustb.sf.domain.Target;
|
||||||
import iet.ustb.sf.exception.ErrorCode;
|
import iet.ustb.sf.exception.ErrorCode;
|
||||||
import iet.ustb.sf.exception.ThrowUtils;
|
import iet.ustb.sf.exception.ThrowUtils;
|
||||||
import iet.ustb.sf.mapper.TargetMapper;
|
import iet.ustb.sf.mapper.TargetMapper;
|
||||||
@ -85,6 +86,28 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
|
|||||||
category.setUpdateTime(now);
|
category.setUpdateTime(now);
|
||||||
categoryMapper.insert(category);
|
categoryMapper.insert(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delCategory(JSONObject params) {
|
||||||
|
String id = params.getString("id");
|
||||||
|
CheckUtils.checkEmpty(id, "分类ID");
|
||||||
|
Category category = categoryMapper.selectById(id);
|
||||||
|
ThrowUtils.throwIf(category==null,ErrorCode.PARAMS_ERROR,"分类不存在!");
|
||||||
|
|
||||||
|
Date now = new Date();
|
||||||
|
|
||||||
|
QueryWrapper<Target> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("category_id", category.getId());
|
||||||
|
List<Target> targetList = targetMapper.selectList(queryWrapper);
|
||||||
|
for (Target target : targetList) {
|
||||||
|
target.setLevel(0);
|
||||||
|
target.setCategoryId("");
|
||||||
|
target.setUpdateTime(now);
|
||||||
|
}
|
||||||
|
targetMapper.insertOrUpdate(targetList);
|
||||||
|
|
||||||
|
categoryMapper.deleteById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user