Commit d7b6a7ab authored by shiyu's avatar shiyu

查询子类目

parent f6b07fc2
......@@ -21,6 +21,8 @@ public interface CategoryDao {
List<Category> queryByPids(List<Integer> pidList);
List<Category> queryByIds(List<Integer> idList);
Category findById(Integer id);
/**
......
......@@ -65,6 +65,14 @@ public class CategoryDaoImpl implements CategoryDao {
return categoryMapper.selectByExample(example);
}
@Override
public List<Category> queryByIds(List<Integer> idList) {
CategoryExample example = new CategoryExample();
CategoryExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(idList).andIsDeletedEqualTo(false);
return categoryMapper.selectByExample(example);
}
public Category findById(Integer id) {
return categoryMapper.selectByPrimaryKey(id);
}
......
......@@ -245,4 +245,22 @@ public class CategoryServiceImpl implements CategoryService {
}
@Override
public Result findChildCategory(CategoryRequestDto dto) {
try {
List<Category> categoryList = new ArrayList<>();
List<Category> selfList = categoryDao.queryByIds(dto.getPidList());
for (Category category : selfList) {
if (category.getIsLeaf()) {
categoryList.add(category);
}
}
List<Category> childList = categoryDao.queryByPids(dto.getPidList());
categoryList.addAll(childList);
return Result.success(categoryList);
} catch (Exception e) {
logger.error("查询子类目失败", e);
return Result.failed("查询子类目失败");
}
}
}
......@@ -59,5 +59,12 @@ public interface CategoryService {
*/
Result findCategoryByTransverse(CategoryRequestDto dto);
/**
* 查询子类目,没有就返回本身
* @param dto
* @return
*/
Result findChildCategory(CategoryRequestDto dto);
}
......@@ -60,6 +60,13 @@ public class QueryPriceController {
}
@ApiOperation(value = "查询子类目")
@PostMapping("/findChildCategory")
public Result findChildCategory(@RequestBody CategoryRequestDto dto) {
return categoryService.findChildCategory(dto);
}
@ApiOperation(value = "查询所有叶子类目")
@PostMapping("/findAllChildCategory")
public Result findAllChildCategory(@RequestBody CategoryRequestDto dto) {
......
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