h5每日菜谱接口重写

This commit is contained in:
zjf committed 2025-04-18 11:52:46 +08:00
1 parent cc34513a56
commit 8f66cc9505
3 files changed
+94 -54

No files matched your search

@@ -1,7 +1,10 @@
package com.bsd.pjcloud.canteen.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.canteen.dto.app.DailyMenuDTO;
import com.bsd.pjcloud.canteen.vo.ADCanteenDailyMenuListVO;
import com.bsd.pjcloud.canteen.vo.DailyMenuVO;
import com.bsd.pjcloud.canteen.vo.app.DailyMenuAppVO;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.canteen.entity.CanteenDailyMenuEntity;
@@ -27,4 +30,8 @@ public interface CanteenDailyMenuMapper extends PjcloudBaseMapper<CanteenDailyMe
*/
List<ADCanteenDailyMenuListVO> getCanteenMenuList(@Param("day") String day, @Param("hourType") Integer hourType,
@Param("categoryId") Long categoryId, @Param("merchantId") Long merchantId,DataScope dataScope);
Page<DailyMenuAppVO> selectTimeFoodPage(@Param("page")Page page, DailyMenuDTO dailyMenuDTO);
}
@@ -143,63 +143,65 @@ public class CanteenDailyMenuServiceImpl extends ServiceImpl<CanteenDailyMenuMap
@Override
public Page selectTimeFoodPage(Page page, DailyMenuDTO dailyMenuDTO) {
LambdaQueryWrapper<CanteenDailyMenuEntity> canteenDailyMenuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
canteenDailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getMerchantId, dailyMenuDTO.getMerchantId());
canteenDailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getStartTime, dailyMenuDTO.getStartTime());
canteenDailyMenuEntityLambdaQueryWrapper.eq(dailyMenuDTO.getHourType() != null,
CanteenDailyMenuEntity::getHourType, dailyMenuDTO.getHourType());
// LambdaQueryWrapper<CanteenDailyMenuEntity> canteenDailyMenuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
// canteenDailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getMerchantId, dailyMenuDTO.getMerchantId());
// canteenDailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getStartTime, dailyMenuDTO.getStartTime());
// canteenDailyMenuEntityLambdaQueryWrapper.eq(dailyMenuDTO.getHourType() != null,
// CanteenDailyMenuEntity::getHourType, dailyMenuDTO.getHourType());
//
// //查询
// LambdaQueryWrapper<CanteenSpuEntity> onlineFoodSpuDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
// onlineFoodSpuDOLambdaQueryWrapper.eq(null != dailyMenuDTO.getCategoryId(), CanteenSpuEntity::getCategoryId, dailyMenuDTO.getCategoryId());
// onlineFoodSpuDOLambdaQueryWrapper.eq(CanteenSpuEntity::getIsShow, "1");
// List<CanteenSpuEntity> spuEntities = canteenSpuService.list(onlineFoodSpuDOLambdaQueryWrapper);
//
// if (CollectionUtils.isNotEmpty(spuEntities)){
// List<Long> spuIds = spuEntities.stream().map(CanteenSpuEntity::getId).collect(Collectors.toList());
// canteenDailyMenuEntityLambdaQueryWrapper.notIn(CanteenDailyMenuEntity::getSpuId, spuIds);
// }
//
// Page pageData = baseMapper.selectPage(page, canteenDailyMenuEntityLambdaQueryWrapper);
// List<CanteenDailyMenuEntity> canteenDailyMenuEntities = pageData.getRecords();
// if (CollectionUtils.isNotEmpty(canteenDailyMenuEntities)) {
// List<Long> spuIds = canteenDailyMenuEntities.stream().map(CanteenDailyMenuEntity::getSpuId).distinct().collect(Collectors.toList());
// LambdaQueryWrapper<CanteenSpuEntity> spuDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
// onlineFoodSpuDOLambdaQueryWrapper.in(CanteenSpuEntity::getId, spuIds);
// List<CanteenSpuEntity> list = canteenSpuService.list(spuDOLambdaQueryWrapper);
// // 按 id 分组成 Map
// Map<Long, CanteenSpuEntity> spuEntityMap = list.stream()
// .collect(Collectors.toMap(CanteenSpuEntity::getId, spu -> spu));
// // 构造新的 VO 列表
// List<DailyMenuAppVO> dailyMenuVOList = canteenDailyMenuEntities.stream()
// .map(menu -> {
// DailyMenuAppVO vo = new DailyMenuAppVO();
// BeanUtils.copyProperties(menu, vo); // 拷贝通用属性
// CanteenSpuEntity spuEntity = spuEntityMap.get(menu.getSpuId());
// if (spuEntity != null) {
// vo.setSpuId(spuEntity.getId());
// vo.setStock(spuEntity.getStock());
// vo.setPrice(spuEntity.getPrice());
// vo.setPicUrl(spuEntity.getPicUrl());
// vo.setName(spuEntity.getName());
// vo.setSort(spuEntity.getSort());
// vo.setIsShow(spuEntity.getIsShow());
// // 其他需要的字段
// }
// return vo;
// })
// .collect(Collectors.toList());
//// dailyMenuVOList.sort(Comparator.comparing(DailyMenuAppVO::getSort));
// // 修改排序逻辑,处理null值情况
// dailyMenuVOList.sort(Comparator.comparing(
// DailyMenuAppVO::getSort,
// Comparator.nullsFirst(Comparator.naturalOrder())
// ));
// pageData.setRecords(dailyMenuVOList);
//查询
LambdaQueryWrapper<CanteenSpuEntity> onlineFoodSpuDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
onlineFoodSpuDOLambdaQueryWrapper.eq(null != dailyMenuDTO.getCategoryId(), CanteenSpuEntity::getCategoryId, dailyMenuDTO.getCategoryId());
onlineFoodSpuDOLambdaQueryWrapper.eq(CanteenSpuEntity::getIsShow, "1");
List<CanteenSpuEntity> spuEntities = canteenSpuService.list(onlineFoodSpuDOLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(spuEntities)){
List<Long> spuIds = spuEntities.stream().map(CanteenSpuEntity::getId).collect(Collectors.toList());
canteenDailyMenuEntityLambdaQueryWrapper.notIn(CanteenDailyMenuEntity::getSpuId, spuIds);
}
Page pageData = baseMapper.selectPage(page, canteenDailyMenuEntityLambdaQueryWrapper);
List<CanteenDailyMenuEntity> canteenDailyMenuEntities = pageData.getRecords();
if (CollectionUtils.isNotEmpty(canteenDailyMenuEntities)) {
List<Long> spuIds = canteenDailyMenuEntities.stream().map(CanteenDailyMenuEntity::getSpuId).distinct().collect(Collectors.toList());
LambdaQueryWrapper<CanteenSpuEntity> spuDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
onlineFoodSpuDOLambdaQueryWrapper.in(CanteenSpuEntity::getId, spuIds);
List<CanteenSpuEntity> list = canteenSpuService.list(spuDOLambdaQueryWrapper);
// 按 id 分组成 Map
Map<Long, CanteenSpuEntity> spuEntityMap = list.stream()
.collect(Collectors.toMap(CanteenSpuEntity::getId, spu -> spu));
// 构造新的 VO 列表
List<DailyMenuAppVO> dailyMenuVOList = canteenDailyMenuEntities.stream()
.map(menu -> {
DailyMenuAppVO vo = new DailyMenuAppVO();
BeanUtils.copyProperties(menu, vo); // 拷贝通用属性
CanteenSpuEntity spuEntity = spuEntityMap.get(menu.getSpuId());
if (spuEntity != null) {
vo.setSpuId(spuEntity.getId());
vo.setStock(spuEntity.getStock());
vo.setPrice(spuEntity.getPrice());
vo.setPicUrl(spuEntity.getPicUrl());
vo.setName(spuEntity.getName());
vo.setSort(spuEntity.getSort());
vo.setIsShow(spuEntity.getIsShow());
// 其他需要的字段
}
return vo;
})
.collect(Collectors.toList());
// dailyMenuVOList.sort(Comparator.comparing(DailyMenuAppVO::getSort));
// 修改排序逻辑,处理null值情况
dailyMenuVOList.sort(Comparator.comparing(
DailyMenuAppVO::getSort,
Comparator.nullsFirst(Comparator.naturalOrder())
));
pageData.setRecords(dailyMenuVOList);
Page<DailyMenuAppVO> pageData=baseMapper.selectTimeFoodPage(page,dailyMenuDTO);
return pageData;
}
// }
return null;
// return null;
}
// 发送mq消息
@@ -82,4 +82,35 @@
</if>
</where>
</select>
<select id="selectTimeFoodPage" resultType="com.bsd.pjcloud.canteen.vo.app.DailyMenuAppVO" parameterType="com.bsd.pjcloud.canteen.dto.app.DailyMenuDTO">
SELECT m.id,
m.hour_type,
s.id as spu_id,
s.`name`,
s.price,
s.stock,
s.pic_url,
s.sort,
s.is_show,
c.id as category_id
FROM `canteen_daily_menu` m
left JOIN canteen_spu s
on m.spu_id = s.id
LEFT JOIN canteen_category c
on s.category_id = c.id
<where>
m.del_flag = 0 and s.del_flag = 0 and m.merchant_id = #{dailyMenuDTO.merchantId} and s.is_show = 0
<if test="dailyMenuDTO.startTime != null">
AND m.start_time = #{dailyMenuDTO.startTime}
</if>
<if test="dailyMenuDTO.categoryId != null">
AND s.category_id = #{dailyMenuDTO.categoryId}
</if>
<if test="dailyMenuDTO.hourType != null">
AND m.hour_type = #{dailyMenuDTO.hourType}
</if>
</where>
order by s.sort asc
</select>
</mapper>