|
|
@@ -1,19 +1,14 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.entity.store.StoreImg;
|
|
|
import shop.alien.entity.store.StoreOfficialAlbum;
|
|
|
-import shop.alien.entity.store.vo.StoreAlbumDetailVo;
|
|
|
-import shop.alien.entity.store.vo.StoreAlbumNameVo;
|
|
|
-import shop.alien.entity.store.vo.StoreOfficialAlbumImgVo;
|
|
|
import shop.alien.entity.store.vo.StoreOfficialAlbumVo;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.mapper.StoreOfficialAlbumMapper;
|
|
|
@@ -21,10 +16,8 @@ import shop.alien.store.service.StoreOfficialAlbumService;
|
|
|
import shop.alien.store.util.CommonConstant;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-@Slf4j
|
|
|
@Transactional
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
@@ -104,178 +97,4 @@ public class StoreOfficialAlbumServiceImpl extends ServiceImpl<StoreOfficialAlbu
|
|
|
storeImgMapper.delete(wrapper);
|
|
|
return CommonConstant.ERROR_CODE_VALID_PARAMS;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取官方相册图片列表(客户端)
|
|
|
- * <p>
|
|
|
- * 根据门店ID和相册名称查询官方相册中的图片列表
|
|
|
- * 查询条件:imgType = 2(官方相册),通过 business_id 关联到 store_official_album 表,按 albumName 筛选
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @param storeId 门店ID,必填
|
|
|
- * @param albumName 相册名称,可选。例如:酒水、餐食、环境、全部等。当为null或空字符串时,查询全部
|
|
|
- * @return 图片列表和总数
|
|
|
- */
|
|
|
- @Override
|
|
|
- public StoreOfficialAlbumImgVo getOfficialAlbumImgList(Integer storeId, String albumName) {
|
|
|
- log.info("开始获取官方相册图片列表,门店ID:{},相册名称:{}", storeId, albumName);
|
|
|
-
|
|
|
- // 参数校验
|
|
|
- if (storeId == null || storeId <= 0) {
|
|
|
- log.warn("获取官方相册图片列表失败,门店ID无效:{}", storeId);
|
|
|
- throw new IllegalArgumentException("门店ID不能为空且必须大于0");
|
|
|
- }
|
|
|
-
|
|
|
- // 先查询符合条件的官方相册ID列表
|
|
|
- LambdaQueryWrapper<StoreOfficialAlbum> albumQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- albumQueryWrapper.eq(StoreOfficialAlbum::getStoreId, storeId)
|
|
|
- .eq(StoreOfficialAlbum::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE);
|
|
|
-
|
|
|
- // 如果指定了相册名称,添加筛选条件
|
|
|
- if (StringUtils.isNotBlank(albumName)) {
|
|
|
- albumQueryWrapper.eq(StoreOfficialAlbum::getAlbumName, albumName);
|
|
|
- }
|
|
|
-
|
|
|
- List<StoreOfficialAlbum> albumList = storeOfficialAlbumMapper.selectList(albumQueryWrapper);
|
|
|
-
|
|
|
- // 如果相册列表为空,直接返回空结果
|
|
|
- if (CollectionUtils.isEmpty(albumList)) {
|
|
|
- log.info("获取官方相册图片列表,门店ID:{},未查询到符合条件的相册", storeId);
|
|
|
- StoreOfficialAlbumImgVo result = new StoreOfficialAlbumImgVo();
|
|
|
- result.setImgList(Collections.emptyList());
|
|
|
- result.setTotalCount(0);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- // 提取相册ID列表
|
|
|
- List<Integer> albumIds = albumList.stream()
|
|
|
- .map(StoreOfficialAlbum::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- log.debug("查询到符合条件的相册数量:{},相册ID列表:{}", albumList.size(), albumIds);
|
|
|
-
|
|
|
- // 查询这些相册下的所有图片(imgType = 2 表示官方相册)
|
|
|
- LambdaQueryWrapper<StoreImg> imgQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- imgQueryWrapper.eq(StoreImg::getStoreId, storeId)
|
|
|
- .eq(StoreImg::getImgType, CommonConstant.STORE_IMG_ALBUM) // imgType = 2 表示官方相册
|
|
|
- .in(StoreImg::getBusinessId, albumIds) // business_id 关联到相册ID
|
|
|
- .eq(StoreImg::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE)
|
|
|
- .orderByAsc(StoreImg::getImgSort);
|
|
|
-
|
|
|
- List<StoreImg> imgList = storeImgMapper.selectList(imgQueryWrapper);
|
|
|
-
|
|
|
- // 构建返回结果
|
|
|
- StoreOfficialAlbumImgVo result = new StoreOfficialAlbumImgVo();
|
|
|
- result.setImgList(imgList);
|
|
|
- result.setTotalCount(imgList.size());
|
|
|
-
|
|
|
- log.info("获取官方相册图片列表完成,门店ID:{},相册名称:{},返回图片数量:{}",
|
|
|
- storeId, albumName, result.getTotalCount());
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取官方相册名称列表(客户端)
|
|
|
- * <p>
|
|
|
- * 根据门店ID查询所有可用的相册名称列表,用于前端展示筛选选项
|
|
|
- * 返回每个相册名称及其对应的图片数量
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @param storeId 门店ID,必填
|
|
|
- * @return 相册名称列表,包含相册名称和图片数量
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<StoreAlbumNameVo> getAlbumNameList(Integer storeId) {
|
|
|
- log.info("开始获取官方相册名称列表,门店ID:{}", storeId);
|
|
|
-
|
|
|
- // 参数校验
|
|
|
- if (storeId == null || storeId <= 0) {
|
|
|
- log.warn("获取官方相册名称列表失败,门店ID无效:{}", storeId);
|
|
|
- throw new IllegalArgumentException("门店ID不能为空且必须大于0");
|
|
|
- }
|
|
|
-
|
|
|
- // 查询该门店下所有未删除的官方相册
|
|
|
- LambdaQueryWrapper<StoreOfficialAlbum> albumQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- albumQueryWrapper.eq(StoreOfficialAlbum::getStoreId, storeId)
|
|
|
- .eq(StoreOfficialAlbum::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE)
|
|
|
- .isNotNull(StoreOfficialAlbum::getAlbumName)
|
|
|
- .ne(StoreOfficialAlbum::getAlbumName, "");
|
|
|
-
|
|
|
- List<StoreOfficialAlbum> albumList = storeOfficialAlbumMapper.selectList(albumQueryWrapper);
|
|
|
-
|
|
|
- // 如果相册列表为空,直接返回空列表
|
|
|
- if (CollectionUtils.isEmpty(albumList)) {
|
|
|
- log.info("获取官方相册名称列表,门店ID:{},未查询到相册", storeId);
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- // 提取相册ID列表
|
|
|
- List<Integer> albumIds = albumList.stream()
|
|
|
- .map(StoreOfficialAlbum::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 查询这些相册下的所有图片(imgType = 2 表示官方相册)
|
|
|
- LambdaQueryWrapper<StoreImg> imgQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- imgQueryWrapper.eq(StoreImg::getStoreId, storeId)
|
|
|
- .eq(StoreImg::getImgType, CommonConstant.STORE_IMG_ALBUM) // imgType = 2 表示官方相册
|
|
|
- .in(StoreImg::getBusinessId, albumIds) // business_id 关联到相册ID
|
|
|
- .eq(StoreImg::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE);
|
|
|
-
|
|
|
- List<StoreImg> imgList = storeImgMapper.selectList(imgQueryWrapper);
|
|
|
-
|
|
|
- // 构建相册ID到相册名称的映射
|
|
|
- Map<Integer, String> albumIdToNameMap = albumList.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- StoreOfficialAlbum::getId,
|
|
|
- StoreOfficialAlbum::getAlbumName,
|
|
|
- (existing, replacement) -> existing // 如果有重复的ID,保留第一个
|
|
|
- ));
|
|
|
-
|
|
|
- // 按相册名称分组统计图片数量
|
|
|
- Map<String, Long> albumNameCountMap = imgList.stream()
|
|
|
- .filter(img -> img.getBusinessId() != null && albumIdToNameMap.containsKey(img.getBusinessId()))
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- img -> albumIdToNameMap.get(img.getBusinessId()),
|
|
|
- Collectors.counting()
|
|
|
- ));
|
|
|
-
|
|
|
- // 转换为返回VO列表
|
|
|
- List<StoreAlbumNameVo> result = albumNameCountMap.entrySet().stream()
|
|
|
- .map(entry -> {
|
|
|
- StoreAlbumNameVo vo = new StoreAlbumNameVo();
|
|
|
- vo.setAlbumName(entry.getKey());
|
|
|
- vo.setImgCount(entry.getValue().intValue());
|
|
|
- return vo;
|
|
|
- })
|
|
|
- .sorted((a, b) -> {
|
|
|
- // 按图片数量降序排序,如果数量相同则按名称排序
|
|
|
- int countCompare = Integer.compare(b.getImgCount(), a.getImgCount());
|
|
|
- if (countCompare != 0) {
|
|
|
- return countCompare;
|
|
|
- }
|
|
|
- return a.getAlbumName().compareTo(b.getAlbumName());
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- log.info("获取官方相册名称列表完成,门店ID:{},返回相册数量:{}", storeId, result.size());
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将StoreImg转换为StoreImgInfo
|
|
|
- *
|
|
|
- * @param img 图片实体
|
|
|
- * @return 图片信息VO
|
|
|
- */
|
|
|
- private StoreAlbumDetailVo.StoreImgInfo convertToImgInfo(StoreImg img) {
|
|
|
- StoreAlbumDetailVo.StoreImgInfo info = new StoreAlbumDetailVo.StoreImgInfo();
|
|
|
- info.setId(img.getId());
|
|
|
- info.setImgUrl(img.getImgUrl());
|
|
|
- info.setImgDescription(img.getImgDescription());
|
|
|
- info.setImgSort(img.getImgSort());
|
|
|
- info.setImgType(img.getImgType());
|
|
|
- return info;
|
|
|
- }
|
|
|
}
|