Commit 3bc2cdd4 authored by muhong's avatar muhong

修改 小程序分类名称搜索

parent 18ea215a
......@@ -35,6 +35,14 @@ public interface CategoryDao {
*/
List<Category> queryByName(String name);
/**
* 判断是否存在子类目
*
* @param id
* @return
*/
boolean isExistedChild(Integer id);
List<Category> querySelective(String id, String name, Integer page, Integer size, String sort, String order);
int updateById(Category category);
......
......@@ -64,6 +64,13 @@ public class CategoryDaoImpl implements CategoryDao {
return categoryMapper.selectByExample(example);
}
@Override
public boolean isExistedChild (Integer id) {
CategoryExample example = new CategoryExample();
example.or().andPidEqualTo(id).andIsDeletedEqualTo(false);
return categoryMapper.countByExample(example) > 0;
}
public List<Category> querySelective(String id, String name, Integer page, Integer size, String sort,
String order) {
CategoryExample example = new CategoryExample();
......
......@@ -82,7 +82,17 @@ public class CategoryServiceImpl implements CategoryService {
return Result.success(new ArrayList<>());
}
try {
return Result.success(categoryDao.queryByName(dto.getName()));
List<Category> result = new ArrayList<>();
List<Category> list = categoryDao.queryByName(dto.getName());
// 筛选叶子节点
if (CollectionUtils.isNotEmpty(list)) {
for (Category category : list) {
if (!categoryDao.isExistedChild(category.getId())) {
result.add(category);
}
}
}
return Result.success(result);
} catch (Exception e) {
logger.error("搜索分类失败", e);
return Result.failed("搜索分类失败");
......
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