|
|
@@ -10,11 +10,21 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.StoreCuisine;
|
|
|
+import shop.alien.entity.store.StoreCuisineCategory;
|
|
|
+import shop.alien.entity.store.StorePrice;
|
|
|
import shop.alien.entity.store.dto.StoreProductDiscountRuleSaveDto;
|
|
|
+import shop.alien.entity.store.vo.StoreProductSelectVo;
|
|
|
import shop.alien.entity.store.vo.StoreProductDiscountRuleDetailVo;
|
|
|
import shop.alien.entity.store.vo.StoreProductDiscountRuleListVo;
|
|
|
+import shop.alien.store.service.StoreCuisineCategoryService;
|
|
|
import shop.alien.store.service.StoreCuisineService;
|
|
|
import shop.alien.store.service.StoreProductDiscountService;
|
|
|
+import shop.alien.store.service.StorePriceService;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Api(tags = {"门店-菜品优惠"})
|
|
|
@@ -25,12 +35,15 @@ public class StoreProductDiscountController {
|
|
|
|
|
|
private final StoreProductDiscountService discountService;
|
|
|
private final StoreCuisineService storeCuisineService;
|
|
|
+ private final StorePriceService storePriceService;
|
|
|
+ private final StoreCuisineCategoryService storeCuisineCategoryService;
|
|
|
|
|
|
@ApiOperation("菜品列表(支持按名称模糊查询)")
|
|
|
@GetMapping("/productList")
|
|
|
- public R<IPage<StoreCuisine>> productList(
|
|
|
+ public R<IPage<StoreProductSelectVo>> productList(
|
|
|
@RequestParam Integer storeId,
|
|
|
@RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String type,
|
|
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
|
|
if (storeId == null) {
|
|
|
@@ -38,14 +51,39 @@ public class StoreProductDiscountController {
|
|
|
}
|
|
|
int pn = pageNum == null || pageNum < 1 ? 1 : pageNum;
|
|
|
int ps = pageSize == null || pageSize < 1 ? 10 : pageSize;
|
|
|
- Page<StoreCuisine> page = new Page<>(pn, ps);
|
|
|
- LambdaQueryWrapper<StoreCuisine> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StoreCuisine::getStoreId, storeId);
|
|
|
+ String typeValue = StringUtils.hasText(type) ? type.trim() : "1";
|
|
|
+ if (!"1".equals(typeValue) && !"2".equals(typeValue)) {
|
|
|
+ return R.fail("type参数不合法,仅支持1(美食)或2(其他)");
|
|
|
+ }
|
|
|
+ Map<Integer, String> categoryNameMap = storeCuisineCategoryService.getCategoryList(storeId)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(StoreCuisineCategory::getId, StoreCuisineCategory::getCategoryName, (a, b) -> a));
|
|
|
+
|
|
|
+ if ("1".equals(typeValue)) {
|
|
|
+ Page<StoreCuisine> page = new Page<>(pn, ps);
|
|
|
+ LambdaQueryWrapper<StoreCuisine> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreCuisine::getStoreId, storeId);
|
|
|
+ if (StringUtils.hasText(name)) {
|
|
|
+ wrapper.like(StoreCuisine::getName, name.trim());
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(StoreCuisine::getUpdatedTime);
|
|
|
+ IPage<StoreCuisine> cuisinePage = storeCuisineService.page(page, wrapper);
|
|
|
+ Page<StoreProductSelectVo> result = new Page<>(pn, ps, cuisinePage.getTotal());
|
|
|
+ result.setRecords(cuisinePage.getRecords().stream().map(item -> toProductSelectVo(item, categoryNameMap)).collect(Collectors.toList()));
|
|
|
+ return R.data(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<StorePrice> page = new Page<>(pn, ps);
|
|
|
+ LambdaQueryWrapper<StorePrice> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StorePrice::getStoreId, storeId);
|
|
|
if (StringUtils.hasText(name)) {
|
|
|
- wrapper.like(StoreCuisine::getName, name.trim());
|
|
|
+ wrapper.like(StorePrice::getName, name.trim());
|
|
|
}
|
|
|
- wrapper.orderByDesc(StoreCuisine::getUpdatedTime);
|
|
|
- return R.data(storeCuisineService.page(page, wrapper));
|
|
|
+ wrapper.orderByDesc(StorePrice::getUpdatedTime);
|
|
|
+ IPage<StorePrice> pricePage = storePriceService.page(page, wrapper);
|
|
|
+ Page<StoreProductSelectVo> result = new Page<>(pn, ps, pricePage.getTotal());
|
|
|
+ result.setRecords(pricePage.getRecords().stream().map(item -> toProductSelectVo(item, categoryNameMap)).collect(Collectors.toList()));
|
|
|
+ return R.data(result);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("优惠规则列表")
|
|
|
@@ -96,5 +134,58 @@ public class StoreProductDiscountController {
|
|
|
int count = discountService.autoCloseExpiredCustomRules();
|
|
|
return R.data(count);
|
|
|
}
|
|
|
+
|
|
|
+ private StoreProductSelectVo toProductSelectVo(StoreCuisine item, Map<Integer, String> categoryNameMap) {
|
|
|
+ StoreProductSelectVo vo = new StoreProductSelectVo();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setStoreId(item.getStoreId());
|
|
|
+ vo.setType(1);
|
|
|
+ vo.setName(item.getName());
|
|
|
+ vo.setTotalPrice(item.getTotalPrice());
|
|
|
+ vo.setImages(item.getImages());
|
|
|
+ vo.setCategoryIds(item.getCategoryIds());
|
|
|
+ List<Integer> categoryIdList = parseCategoryIds(item.getCategoryIds());
|
|
|
+ vo.setCategoryIdList(categoryIdList);
|
|
|
+ vo.setCategoryNames(categoryIdList.stream().map(categoryNameMap::get).filter(StringUtils::hasText).collect(Collectors.toList()));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private StoreProductSelectVo toProductSelectVo(StorePrice item, Map<Integer, String> categoryNameMap) {
|
|
|
+ StoreProductSelectVo vo = new StoreProductSelectVo();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setStoreId(item.getStoreId());
|
|
|
+ vo.setType(2);
|
|
|
+ vo.setName(item.getName());
|
|
|
+ vo.setTotalPrice(item.getTotalPrice());
|
|
|
+ vo.setImages(item.getImages());
|
|
|
+ vo.setCategoryIds(item.getCategoryIds());
|
|
|
+ List<Integer> categoryIdList = parseCategoryIds(item.getCategoryIds());
|
|
|
+ vo.setCategoryIdList(categoryIdList);
|
|
|
+ vo.setCategoryNames(categoryIdList.stream().map(categoryNameMap::get).filter(StringUtils::hasText).collect(Collectors.toList()));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> parseCategoryIds(String categoryIds) {
|
|
|
+ if (!StringUtils.hasText(categoryIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String cleaned = categoryIds.trim()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .replace("\"", "");
|
|
|
+ if (!StringUtils.hasText(cleaned)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return java.util.Arrays.stream(cleaned.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(StringUtils::hasText)
|
|
|
+ .map(Integer::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析分类ID失败: {}", categoryIds, e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|