|
@@ -46,18 +46,18 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
Integer count = this.lambdaQuery().eq(Category::getName, param.getName()).count();
|
|
Integer count = this.lambdaQuery().eq(Category::getName, param.getName()).count();
|
|
AssertUtils.available(count <= 0, "分类名称已存在");
|
|
AssertUtils.available(count <= 0, "分类名称已存在");
|
|
Category category = CategoryCopier.INSTANCE.copying(param);
|
|
Category category = CategoryCopier.INSTANCE.copying(param);
|
|
-// Long userId = SessionContextHolder.getId();
|
|
|
|
-// Scope scope = StringUtils.ifEmpty(SessionContextHolder.getScope(), Scope::parse);
|
|
|
|
-// if (scope == Scope.ADMIN) {
|
|
|
|
-// category.setType("0");
|
|
|
|
-// }else {
|
|
|
|
-// List<Long> merchants = this.merchantService.getMerchantIdsByUserId(userId);
|
|
|
|
-// if (ObjectUtils.isEmpty(merchants)) {
|
|
|
|
-// return null;
|
|
|
|
-// }
|
|
|
|
-// category.setMerchantId(merchants.get(0));
|
|
|
|
-// category.setType("1");
|
|
|
|
-// }
|
|
|
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
|
+ Scope scope = StringUtils.ifEmpty(SessionContextHolder.getScope(), Scope::parse);
|
|
|
|
+ if (scope == Scope.ADMIN) {
|
|
|
|
+ category.setType("0");
|
|
|
|
+ }else {
|
|
|
|
+ List<Long> merchants = this.merchantService.getMerchantIdsByUserId(userId);
|
|
|
|
+ if (ObjectUtils.isEmpty(merchants)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ category.setMerchantId(merchants.get(0));
|
|
|
|
+ category.setType("1");
|
|
|
|
+ }
|
|
if (StringUtils.isEmpty(category.getParentId())){
|
|
if (StringUtils.isEmpty(category.getParentId())){
|
|
category.setParentId(0l);
|
|
category.setParentId(0l);
|
|
}
|
|
}
|
|
@@ -86,9 +86,9 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
}
|
|
}
|
|
Page<Category> page = this.lambdaQuery()
|
|
Page<Category> page = this.lambdaQuery()
|
|
.like(StringUtils.notEmpty(param.getName()), Category::getName, param.getName())
|
|
.like(StringUtils.notEmpty(param.getName()), Category::getName, param.getName())
|
|
-// .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
.eq(Objects.nonNull(param.getEnabled()), Category::getEnabled, param.getEnabled())
|
|
.eq(Objects.nonNull(param.getEnabled()), Category::getEnabled, param.getEnabled())
|
|
-// .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
.orderByAsc(Category::getSort).page(DatabaseContextHolder.page(param.getPaging()));
|
|
.orderByAsc(Category::getSort).page(DatabaseContextHolder.page(param.getPaging()));
|
|
return DatabaseContextHolder.pagination(page, CategoryCopier.INSTANCE::copying);
|
|
return DatabaseContextHolder.pagination(page, CategoryCopier.INSTANCE::copying);
|
|
}
|
|
}
|
|
@@ -105,11 +105,13 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
param.setMerchantId(merchants.get(0));
|
|
param.setMerchantId(merchants.get(0));
|
|
- param.setType("1");
|
|
|
|
|
|
+ if (StringUtils.isEmpty(param.getType())){
|
|
|
|
+ param.setType("1");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
List<Category> categories = this.lambdaQuery().eq(Category::getEnabled, true)
|
|
List<Category> categories = this.lambdaQuery().eq(Category::getEnabled, true)
|
|
-// .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
-// .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
.orderByAsc(Category::getSort).list();
|
|
.orderByAsc(Category::getSort).list();
|
|
categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
|
|
categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
|
|
List<CategoryDTO> categoryDTOS = CategoryCopier.INSTANCE.copying(categories);
|
|
List<CategoryDTO> categoryDTOS = CategoryCopier.INSTANCE.copying(categories);
|
|
@@ -131,6 +133,31 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
return categoryList;
|
|
return categoryList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<CategoryDTO> listCategory(CategoryListParam param) {
|
|
|
|
+ List<Category> categories = this.lambdaQuery().eq(Category::getEnabled, true)
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
+ .orderByAsc(Category::getSort).list();
|
|
|
|
+ categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
|
|
|
|
+ List<CategoryDTO> categoryDTOS = CategoryCopier.INSTANCE.copying(categories);
|
|
|
|
+ List<CategoryDTO> categoryList = new ArrayList<>();
|
|
|
|
+ for (CategoryDTO categoryDTO:categoryDTOS){
|
|
|
|
+ if (categoryDTO.getParentId() == 0){
|
|
|
|
+ categoryList.add(categoryDTO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (CategoryDTO categoryDTO:categoryList){
|
|
|
|
+ List<CategoryDTO> categorys = new ArrayList<>();
|
|
|
|
+ for (CategoryDTO categorydto:categoryDTOS){
|
|
|
|
+ if (categorydto.getParentId().equals(categoryDTO.getId()) ){
|
|
|
|
+ categorys.add(categorydto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ categoryDTO.setChildren(categorys);
|
|
|
|
+ }
|
|
|
|
+ return categoryList;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<CategoryDTO> listRecommendCategories(int size) {
|
|
public List<CategoryDTO> listRecommendCategories(int size) {
|
|
List<Category> categories = this.baseMapper.listRecommendCategories(size);
|
|
List<Category> categories = this.baseMapper.listRecommendCategories(size);
|
|
@@ -157,8 +184,8 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|
}
|
|
}
|
|
List<Category> categories = this.lambdaQuery()
|
|
List<Category> categories = this.lambdaQuery()
|
|
.eq(Category::getEnabled, true)
|
|
.eq(Category::getEnabled, true)
|
|
-// .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
-// .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getType()),Category::getType,param.getType())
|
|
|
|
+ .eq(StringUtils.notEmpty(param.getMerchantId()),Category::getMerchantId,param.getMerchantId())
|
|
.orderByAsc(Category::getSort).list();
|
|
.orderByAsc(Category::getSort).list();
|
|
categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
|
|
categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
|
|
return CategoryCopier.INSTANCE.copying(categories);
|
|
return CategoryCopier.INSTANCE.copying(categories);
|