修改为空报错问题

This commit is contained in:
qjq
2024-04-24 09:37:26 +08:00
parent 81a95d7615
commit bec466faa2

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.service.dishestype;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -93,35 +94,37 @@ public class DishesTypeServiceImpl implements DishesTypeService {
List<DishesTypeListRespVO> list=new ArrayList<>();
//获取订单id
List<Long> collect = dishesTypeMapper.selectOrderIds(carteenId, startTime, endTime);
List<OrderDetail> orderDetailDOS = dishesTypeMapper.selectByIdAmdTypeName(collect);
orderDetailDOS.forEach(f-> f.setCreator(TimePeriodEnum.getTimePeriod(f.getCreateTime())));
// 根据时间进行分组
Map<String, List<OrderDetail>> map = orderDetailDOS.stream()
.collect(Collectors.groupingBy(OrderDetail::getCreator));
for (Map.Entry<String, List<OrderDetail>> en : map.entrySet()) {
DishesTypeListRespVO vo=new DishesTypeListRespVO();
vo.setTime(en.getKey());
//集合根据菜品名称去重
List<OrderDetail> collect1 = new ArrayList<>(en.getValue().stream().collect(Collectors.toMap(
OrderDetail::getDishesName,
m -> m,
(oldValue, newValue) -> newValue
)).values());
//根据类型进行分组
collect1.stream()
.collect(Collectors.groupingBy(OrderDetail::getDishUrl))
.forEach((v,k)-> {
Map<String, String> map1 = MapUtil.builder(new HashMap<String, String>())
.put("dishesName", StrUtil.join(",",k.stream()
.map(OrderDetail::getDishesName)
.collect(Collectors.toList())))
.put("typeName", v)
.map();
vo.getDishesTypeName().add(map1);
});
list.add(vo);
if(ObjUtil.isNotEmpty(collect)){
List<OrderDetail> orderDetailDOS = dishesTypeMapper.selectByIdAmdTypeName(collect);
orderDetailDOS.forEach(f-> f.setCreator(TimePeriodEnum.getTimePeriod(f.getCreateTime())));
// 根据时间进行分组
Map<String, List<OrderDetail>> map = orderDetailDOS.stream()
.collect(Collectors.groupingBy(OrderDetail::getCreator));
for (Map.Entry<String, List<OrderDetail>> en : map.entrySet()) {
DishesTypeListRespVO vo=new DishesTypeListRespVO();
vo.setTime(en.getKey());
//集合根据菜品名称去重
List<OrderDetail> collect1 = new ArrayList<>(en.getValue().stream().collect(Collectors.toMap(
OrderDetail::getDishesName,
m -> m,
(oldValue, newValue) -> newValue
)).values());
//根据类型进行分组
collect1.stream()
.collect(Collectors.groupingBy(OrderDetail::getDishUrl))
.forEach((v,k)-> {
Map<String, String> map1 = MapUtil.builder(new HashMap<String, String>())
.put("dishesName", StrUtil.join(",",k.stream()
.map(OrderDetail::getDishesName)
.collect(Collectors.toList())))
.put("typeName", v)
.map();
vo.getDishesTypeName().add(map1);
});
list.add(vo);
}
list.sort(Comparator.comparing(DishesTypeListRespVO::getTime));
}
list.sort(Comparator.comparing(DishesTypeListRespVO::getTime));
return list;
}
}