|
@@ -18,6 +18,8 @@ import shop.alien.entity.store.StoreProductDelicacies;
|
|
|
import shop.alien.entity.store.StoreProductGym;
|
|
import shop.alien.entity.store.StoreProductGym;
|
|
|
import shop.alien.entity.store.StoreProductItem;
|
|
import shop.alien.entity.store.StoreProductItem;
|
|
|
import shop.alien.entity.store.vo.StoreProductItemGymVo;
|
|
import shop.alien.entity.store.vo.StoreProductItemGymVo;
|
|
|
|
|
+import shop.alien.entity.store.vo.StoreProductItemDelicaciesVo;
|
|
|
|
|
+import shop.alien.entity.store.vo.StoreProductDelicaciesVo;
|
|
|
import shop.alien.entity.store.dto.StoreProductItemDto;
|
|
import shop.alien.entity.store.dto.StoreProductItemDto;
|
|
|
import shop.alien.mapper.StoreProductItemMapper;
|
|
import shop.alien.mapper.StoreProductItemMapper;
|
|
|
import shop.alien.store.service.StoreProductBarService;
|
|
import shop.alien.store.service.StoreProductBarService;
|
|
@@ -26,7 +28,9 @@ import shop.alien.store.service.StoreProductGymService;
|
|
|
import shop.alien.store.service.StoreProductItemService;
|
|
import shop.alien.store.service.StoreProductItemService;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -238,5 +242,220 @@ public class StoreProductItemServiceImpl extends ServiceImpl<StoreProductItemMap
|
|
|
return R.fail("查询失败,数据不存在");
|
|
return R.fail("查询失败,数据不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<StoreProductItemDelicaciesVo> getPageWithDelicacies(int pageNum, int pageSize,
|
|
|
|
|
+ Integer storeId, String name,
|
|
|
|
|
+ String category, String extGroup,
|
|
|
|
|
+ Integer status, Integer packageType) {
|
|
|
|
|
+ log.info("StoreProductItemServiceImpl.getPageWithDelicacies?pageNum={}, pageSize={}, storeId={}, name={}, category={}, extGroup={}, status={}, packageType={}",
|
|
|
|
|
+ pageNum, pageSize, storeId, name, category, extGroup, status, packageType);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询主表store_product_item中关于美食的数据(prodType = 4)
|
|
|
|
|
+ LambdaQueryWrapper<StoreProductItem> itemWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ itemWrapper.eq(StoreProductItem::getProdType, 4)
|
|
|
|
|
+ .eq(StoreProductItem::getDeleteFlag, 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (storeId != null) {
|
|
|
|
|
+ itemWrapper.eq(StoreProductItem::getStoreId, storeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(name)) {
|
|
|
|
|
+ itemWrapper.like(StoreProductItem::getProdName, name);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status != null) {
|
|
|
|
|
+ itemWrapper.eq(StoreProductItem::getStatus, status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询所有主表数据(不分页,用于后续合并)
|
|
|
|
|
+ List<StoreProductItem> allItemList = this.list(itemWrapper);
|
|
|
|
|
+ List<Integer> allItemIds = allItemList != null ? allItemList.stream()
|
|
|
|
|
+ .map(StoreProductItem::getId)
|
|
|
|
|
+ .collect(Collectors.toList()) : new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询所有关联的子表数据
|
|
|
|
|
+ LambdaQueryWrapper<StoreProductDelicacies> relatedDelicaciesWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ if (!allItemIds.isEmpty()) {
|
|
|
|
|
+ relatedDelicaciesWrapper.in(StoreProductDelicacies::getExtId, allItemIds)
|
|
|
|
|
+ .eq(StoreProductDelicacies::getDeleteFlag, 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有主表数据,设置一个不可能的条件
|
|
|
|
|
+ relatedDelicaciesWrapper.eq(StoreProductDelicacies::getExtId, -1)
|
|
|
|
|
+ .eq(StoreProductDelicacies::getDeleteFlag, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 子表筛选条件
|
|
|
|
|
+ if (StringUtils.hasText(name)) {
|
|
|
|
|
+ relatedDelicaciesWrapper.like(StoreProductDelicacies::getName, name);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(category)) {
|
|
|
|
|
+ relatedDelicaciesWrapper.eq(StoreProductDelicacies::getCategory, category);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(extGroup)) {
|
|
|
|
|
+ relatedDelicaciesWrapper.eq(StoreProductDelicacies::getExtGroup, extGroup);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status != null) {
|
|
|
|
|
+ relatedDelicaciesWrapper.eq(StoreProductDelicacies::getStatus, status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<StoreProductDelicacies> relatedDelicaciesList = storeProductDelicaciesService.list(relatedDelicaciesWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 查询独立的子表数据(extId为null或不在主表ID列表中的)
|
|
|
|
|
+ LambdaQueryWrapper<StoreProductDelicacies> independentDelicaciesWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ independentDelicaciesWrapper.eq(StoreProductDelicacies::getDeleteFlag, 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 独立的子表:extId为null,或者extId不在主表ID列表中
|
|
|
|
|
+ if (allItemIds.isEmpty()) {
|
|
|
|
|
+ // 如果没有主表数据,查询所有extId为null的子表数据
|
|
|
|
|
+ independentDelicaciesWrapper.isNull(StoreProductDelicacies::getExtId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // extId为null,或者extId不在主表ID列表中
|
|
|
|
|
+ independentDelicaciesWrapper.and(wrapper -> wrapper.isNull(StoreProductDelicacies::getExtId)
|
|
|
|
|
+ .or().notIn(StoreProductDelicacies::getExtId, allItemIds));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 子表筛选条件
|
|
|
|
|
+ if (StringUtils.hasText(name)) {
|
|
|
|
|
+ independentDelicaciesWrapper.like(StoreProductDelicacies::getName, name);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(category)) {
|
|
|
|
|
+ independentDelicaciesWrapper.eq(StoreProductDelicacies::getCategory, category);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.hasText(extGroup)) {
|
|
|
|
|
+ independentDelicaciesWrapper.eq(StoreProductDelicacies::getExtGroup, extGroup);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status != null) {
|
|
|
|
|
+ independentDelicaciesWrapper.eq(StoreProductDelicacies::getStatus, status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<StoreProductDelicacies> independentDelicaciesList = storeProductDelicaciesService.list(independentDelicaciesWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 按extId分组,构建关联子表数据映射
|
|
|
|
|
+ Map<Integer, List<StoreProductDelicaciesVo>> delicaciesMap = relatedDelicaciesList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
|
+ StoreProductDelicacies::getExtId,
|
|
|
|
|
+ Collectors.mapping(delicacies -> convertToDelicaciesVo(delicacies), Collectors.toList())
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 组装结果列表
|
|
|
|
|
+ List<StoreProductItemDelicaciesVo> resultList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 5.1 添加主表数据及其关联的子表数据
|
|
|
|
|
+ if (allItemList != null) {
|
|
|
|
|
+ for (StoreProductItem item : allItemList) {
|
|
|
|
|
+ StoreProductItemDelicaciesVo vo = convertItemToVo(item);
|
|
|
|
|
+ // 设置子表列表(一对多关系)
|
|
|
|
|
+ List<StoreProductDelicaciesVo> subList = delicaciesMap.getOrDefault(item.getId(), new ArrayList<>());
|
|
|
|
|
+ vo.setDelicaciesList(subList);
|
|
|
|
|
+ resultList.add(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5.2 添加独立的子表数据(作为独立的记录,主表字段为空)
|
|
|
|
|
+ for (StoreProductDelicacies delicacies : independentDelicaciesList) {
|
|
|
|
|
+ StoreProductItemDelicaciesVo vo = new StoreProductItemDelicaciesVo();
|
|
|
|
|
+ // 主表字段为空或null
|
|
|
|
|
+ vo.setId(null);
|
|
|
|
|
+ vo.setStoreId(null);
|
|
|
|
|
+ // 子表字段
|
|
|
|
|
+ vo.setDelicaciesId(delicacies.getId());
|
|
|
|
|
+ vo.setExtId(delicacies.getExtId());
|
|
|
|
|
+ vo.setName(delicacies.getName());
|
|
|
|
|
+ vo.setPrice(delicacies.getPrice());
|
|
|
|
|
+ vo.setCostPrice(delicacies.getCostPrice());
|
|
|
|
|
+ vo.setUnit(delicacies.getUnit());
|
|
|
|
|
+ vo.setQuantity(delicacies.getQuantity());
|
|
|
|
|
+ vo.setCategory(delicacies.getCategory());
|
|
|
|
|
+ vo.setExtGroup(delicacies.getExtGroup());
|
|
|
|
|
+ vo.setDelicaciesStatus(delicacies.getStatus());
|
|
|
|
|
+ vo.setDelicaciesDeleteFlag(delicacies.getDeleteFlag());
|
|
|
|
|
+ vo.setDelicaciesCreatedUserId(delicacies.getCreatedUserId());
|
|
|
|
|
+ vo.setDelicaciesUpdatedUserId(delicacies.getUpdatedUserId());
|
|
|
|
|
+ vo.setDelicaciesCreatedTime(delicacies.getCreatedTime());
|
|
|
|
|
+ vo.setDelicaciesUpdatedTime(delicacies.getUpdatedTime());
|
|
|
|
|
+ // 子表列表只包含自己
|
|
|
|
|
+ List<StoreProductDelicaciesVo> subList = new ArrayList<>();
|
|
|
|
|
+ subList.add(convertToDelicaciesVo(delicacies));
|
|
|
|
|
+ vo.setDelicaciesList(subList);
|
|
|
|
|
+ resultList.add(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 按创建时间倒序排序(主表或子表的创建时间)
|
|
|
|
|
+ resultList.sort((a, b) -> {
|
|
|
|
|
+ Date dateA = a.getDelicaciesCreatedTime() != null ? a.getDelicaciesCreatedTime() : a.getCreatedTime();
|
|
|
|
|
+ Date dateB = b.getDelicaciesCreatedTime() != null ? b.getDelicaciesCreatedTime() : b.getCreatedTime();
|
|
|
|
|
+ if (dateA == null && dateB == null) return 0;
|
|
|
|
|
+ if (dateA == null) return 1;
|
|
|
|
|
+ if (dateB == null) return -1;
|
|
|
|
|
+ return dateB.compareTo(dateA); // 倒序
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 手动分页
|
|
|
|
|
+ int total = resultList.size();
|
|
|
|
|
+ int start = (pageNum - 1) * pageSize;
|
|
|
|
|
+ int end = Math.min(start + pageSize, total);
|
|
|
|
|
+
|
|
|
|
|
+ List<StoreProductItemDelicaciesVo> pageList = start < total ? resultList.subList(start, end) : new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 8. 构建分页结果
|
|
|
|
|
+ Page<StoreProductItemDelicaciesVo> resultPage = new Page<>(pageNum, pageSize);
|
|
|
|
|
+ resultPage.setRecords(pageList);
|
|
|
|
|
+ resultPage.setTotal(total);
|
|
|
|
|
+ resultPage.setPages((int) Math.ceil((double) total / pageSize));
|
|
|
|
|
+ resultPage.setCurrent(pageNum);
|
|
|
|
|
+ resultPage.setSize(pageSize);
|
|
|
|
|
+
|
|
|
|
|
+ return resultPage;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将StoreProductItem转换为VO
|
|
|
|
|
+ */
|
|
|
|
|
+ private StoreProductItemDelicaciesVo convertItemToVo(StoreProductItem item) {
|
|
|
|
|
+ StoreProductItemDelicaciesVo vo = new StoreProductItemDelicaciesVo();
|
|
|
|
|
+ vo.setId(item.getId());
|
|
|
|
|
+ vo.setStoreId(item.getStoreId());
|
|
|
|
|
+ vo.setProdName(item.getProdName());
|
|
|
|
|
+ vo.setTotalPrice(item.getTotalPrice());
|
|
|
|
|
+ vo.setProdType(item.getProdType());
|
|
|
|
|
+ vo.setImages(item.getImages());
|
|
|
|
|
+ vo.setImageContent(item.getImageContent());
|
|
|
|
|
+ vo.setDetailContent(item.getDetailContent());
|
|
|
|
|
+ vo.setExtraNote(item.getExtraNote());
|
|
|
|
|
+ vo.setNeedReserve(item.getNeedReserve());
|
|
|
|
|
+ vo.setReserveRule(item.getReserveRule());
|
|
|
|
|
+ vo.setPeopleLimit(item.getPeopleLimit());
|
|
|
|
|
+ vo.setUsageRule(item.getUsageRule());
|
|
|
|
|
+ vo.setStatus(item.getStatus());
|
|
|
|
|
+ vo.setRejectionReason(item.getRejectionReason());
|
|
|
|
|
+ vo.setDeleteFlag(item.getDeleteFlag());
|
|
|
|
|
+ vo.setCreatedUserId(item.getCreatedUserId());
|
|
|
|
|
+ vo.setUpdatedUserId(item.getUpdatedUserId());
|
|
|
|
|
+ vo.setCreatedTime(item.getCreatedTime());
|
|
|
|
|
+ vo.setUpdatedTime(item.getUpdatedTime());
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将StoreProductDelicacies转换为VO
|
|
|
|
|
+ */
|
|
|
|
|
+ private StoreProductDelicaciesVo convertToDelicaciesVo(StoreProductDelicacies delicacies) {
|
|
|
|
|
+ StoreProductDelicaciesVo vo = new StoreProductDelicaciesVo();
|
|
|
|
|
+ vo.setId(delicacies.getId());
|
|
|
|
|
+ vo.setExtId(delicacies.getExtId());
|
|
|
|
|
+ vo.setName(delicacies.getName());
|
|
|
|
|
+ vo.setPrice(delicacies.getPrice());
|
|
|
|
|
+ vo.setCostPrice(delicacies.getCostPrice());
|
|
|
|
|
+ vo.setUnit(delicacies.getUnit());
|
|
|
|
|
+ vo.setQuantity(delicacies.getQuantity());
|
|
|
|
|
+ vo.setCategory(delicacies.getCategory());
|
|
|
|
|
+ vo.setExtGroup(delicacies.getExtGroup());
|
|
|
|
|
+ vo.setStatus(delicacies.getStatus());
|
|
|
|
|
+ vo.setDeleteFlag(delicacies.getDeleteFlag());
|
|
|
|
|
+ vo.setCreatedUserId(delicacies.getCreatedUserId());
|
|
|
|
|
+ vo.setUpdatedUserId(delicacies.getUpdatedUserId());
|
|
|
|
|
+ vo.setCreatedTime(delicacies.getCreatedTime());
|
|
|
|
|
+ vo.setUpdatedTime(delicacies.getUpdatedTime());
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|