|
|
@@ -1,60 +1,45 @@
|
|
|
package com.izouma.dingdong.service.backstage;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
+
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.domain.backstage.Category;
|
|
|
-import com.izouma.dingdong.dto.CategoryDTO;
|
|
|
+import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
+import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
+import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
|
+import com.izouma.dingdong.dto.MerchantDTO;
|
|
|
+import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.backstage.CategoryRepo;
|
|
|
+import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
+import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class CategoryService {
|
|
|
|
|
|
private CategoryRepo categoryRepo;
|
|
|
+ private MerchantRepo merchantRepo;
|
|
|
+ private MerchantSettingsRepo merchantSettingsRepo;
|
|
|
|
|
|
/*
|
|
|
- 转DTO
|
|
|
+ 按类别显示商户列表
|
|
|
*/
|
|
|
- private CategoryDTO categoryDTO(Category category){
|
|
|
- CategoryDTO dto = new CategoryDTO();
|
|
|
- BeanUtil.copyProperties(category, dto);
|
|
|
- if (CollUtil.isNotEmpty(category.getChildren())){
|
|
|
- dto.setChildren(category.getChildren().stream().map(this::categoryDTO).collect(Collectors.toList()));
|
|
|
+ public List<MerchantDTO> categoryMer(Long categoryId) {
|
|
|
+ Category category = categoryRepo.findById(categoryId).orElseThrow(new BusinessException("无分类"));
|
|
|
+ List<MerchantSettings> settings = merchantSettingsRepo.findAllByCategoryContains(category);
|
|
|
+ if (ObjectUtil.isNull(settings)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- return dto;
|
|
|
+ List<MerchantDTO> dtos = CollUtil.newArrayList();
|
|
|
+ settings.forEach(s -> {
|
|
|
+ Merchant merchant = merchantRepo.findById(s.getMerchantId()).orElseThrow(new BusinessException("无商家"));
|
|
|
+ dtos.add(new MerchantDTO(merchant, s));
|
|
|
+ });
|
|
|
+ return dtos;
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- 树形显示菜单
|
|
|
- */
|
|
|
- public List<CategoryDTO> treeList(Long id) {
|
|
|
- List<Category> categories = categoryRepo.findAllByParent(id);
|
|
|
-
|
|
|
-// List<CategoryDTO> categoryDTOS = CollUtil.newArrayList();
|
|
|
-// List<CategoryDTO> children = CollUtil.newArrayList();
|
|
|
-/* categories.forEach(c -> {
|
|
|
- CategoryDTO categoryDTO = new CategoryDTO();
|
|
|
- BeanUtil.copyProperties(c, categoryDTO);
|
|
|
- if (CollUtil.isNotEmpty(c.getChildren())) {
|
|
|
- c.getChildren().forEach(category -> {
|
|
|
- CategoryDTO dto = new CategoryDTO();
|
|
|
- BeanUtil.copyProperties(category, dto);
|
|
|
- children.add(dto);
|
|
|
- });
|
|
|
- categoryDTO.setChildren(children);
|
|
|
- }
|
|
|
- categoryDTOS.add(categoryDTO);
|
|
|
- }
|
|
|
- );*/
|
|
|
-
|
|
|
-
|
|
|
- return categories.stream().map(this::categoryDTO).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|