菜品预定
This commit is contained in:
1 parent
9e09738b26
commit
77dedf29f2
11 files changed
+248
-62
No files matched your search
+8
@@ -99,4 +99,12 @@ public class BoxesBookingEntity extends Model<BoxesBookingEntity> {
|
|||||||
@Schema(description="用户名称")
|
@Schema(description="用户名称")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
|
@Schema(description="餐次名称")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String mealName;
|
||||||
|
|
||||||
|
@Schema(description="预约时间")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String reservationTime;
|
||||||
}
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.bsd.pjcloud.canteen.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "时间段配置VO")
|
||||||
|
public class TimeSlotConfigVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "餐次类型 1-早餐 2-中餐 3-晚餐")
|
||||||
|
private Integer mealType;
|
||||||
|
|
||||||
|
@Schema(description = "餐次名称")
|
||||||
|
private String mealName;
|
||||||
|
|
||||||
|
@Schema(description = "开始时间")
|
||||||
|
@JsonFormat(pattern = "HH:mm")
|
||||||
|
private LocalTime startTime;
|
||||||
|
|
||||||
|
@Schema(description = "结束时间")
|
||||||
|
@JsonFormat(pattern = "HH:mm")
|
||||||
|
private LocalTime endTime;
|
||||||
|
|
||||||
|
@Schema(description = "时间段名称")
|
||||||
|
private String timeSlotName;
|
||||||
|
|
||||||
|
@Schema(description = "是否启用 0-禁用 1-启用")
|
||||||
|
private Integer isEnabled;
|
||||||
|
|
||||||
|
@Schema(description = "排序")
|
||||||
|
private Integer sort;
|
||||||
|
}
|
||||||
+14
@@ -66,6 +66,20 @@ public class CanteenSpuController {
|
|||||||
return R.ok(canteenSpuService.pageScope(page, canteenSpu));
|
return R.ok(canteenSpuService.pageScope(page, canteenSpu));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线订餐选择每日菜品下拉
|
||||||
|
*
|
||||||
|
* @param page 分页对象
|
||||||
|
* @param canteenSpu 菜品spu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Operation(summary = "在线订餐选择每日菜品下拉", description = "在线订餐选择每日菜品下拉")
|
||||||
|
@GetMapping("/selectPage")
|
||||||
|
@PreAuthorize("@pms.hasPermission('canteen_canteenSpu_view')")
|
||||||
|
public R getSelectPage(@ParameterObject Page page, @ParameterObject CanteenSpuEntity canteenSpu) {
|
||||||
|
return R.ok(canteenSpuService.selectPage(page, canteenSpu));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "erp分页查询", description = "erp分页查询")
|
@Operation(summary = "erp分页查询", description = "erp分页查询")
|
||||||
@GetMapping("/erp/page")
|
@GetMapping("/erp/page")
|
||||||
|
|||||||
+2
-3
@@ -1,11 +1,10 @@
|
|||||||
package com.bsd.pjcloud.canteen.mapper;
|
package com.bsd.pjcloud.canteen.mapper;
|
||||||
|
|
||||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface TimeSlotConfigMapper extends PjcloudBaseMapper<TimeSlotConfigEntity> {
|
public interface TimeSlotConfigMapper extends BaseMapper<TimeSlotConfigEntity> {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+7
@@ -68,4 +68,11 @@ public interface CanteenSpuService extends IService<CanteenSpuEntity> {
|
|||||||
Page<CanteenSpuStockVO> erpPageScope(Page page, CanteenSpuEntity canteenSpu);
|
Page<CanteenSpuStockVO> erpPageScope(Page page, CanteenSpuEntity canteenSpu);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线订餐选择每日菜品下拉
|
||||||
|
* @param page
|
||||||
|
* @param canteenSpu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Object selectPage(Page page, CanteenSpuEntity canteenSpu);
|
||||||
}
|
}
|
||||||
+15
@@ -2,7 +2,22 @@ package com.bsd.pjcloud.canteen.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
||||||
|
import com.bsd.pjcloud.canteen.vo.TimeSlotConfigVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface TimeSlotConfigService extends IService<TimeSlotConfigEntity> {
|
public interface TimeSlotConfigService extends IService<TimeSlotConfigEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有启用的时间段配置
|
||||||
|
* @return 时间段配置列表
|
||||||
|
*/
|
||||||
|
List<TimeSlotConfigEntity> getEnabledTimeSlots();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取餐次类型到时间段的映射
|
||||||
|
* @return 餐次类型 -> 时间段的映射
|
||||||
|
*/
|
||||||
|
Map<Integer, String> getMealTypeTimeRangeMap();
|
||||||
}
|
}
|
||||||
+14
-11
@@ -6,10 +6,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.bsd.pjcloud.canteen.entity.BoxesAvailabilityEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesAvailabilityEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.BoxesInfoEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesInfoEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.BoxesBookingEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesBookingEntity;
|
||||||
|
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
||||||
import com.bsd.pjcloud.canteen.mapper.BoxesAvailabilityMapper;
|
import com.bsd.pjcloud.canteen.mapper.BoxesAvailabilityMapper;
|
||||||
import com.bsd.pjcloud.canteen.mapper.BoxesInfoMapper;
|
import com.bsd.pjcloud.canteen.mapper.BoxesInfoMapper;
|
||||||
import com.bsd.pjcloud.canteen.mapper.BoxesBookingMapper;
|
import com.bsd.pjcloud.canteen.mapper.BoxesBookingMapper;
|
||||||
import com.bsd.pjcloud.canteen.service.BoxesAvailabilityService;
|
import com.bsd.pjcloud.canteen.service.BoxesAvailabilityService;
|
||||||
|
import com.bsd.pjcloud.canteen.service.TimeSlotConfigService;
|
||||||
import com.bsd.pjcloud.canteen.vo.APPBXAvaliabilityRespVO;
|
import com.bsd.pjcloud.canteen.vo.APPBXAvaliabilityRespVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -34,6 +36,7 @@ public class BoxesAvailabilityServiceImpl extends ServiceImpl<BoxesAvailabilityM
|
|||||||
|
|
||||||
private final BoxesInfoMapper boxesInfoMapper;
|
private final BoxesInfoMapper boxesInfoMapper;
|
||||||
private final BoxesBookingMapper boxesBookingMapper;
|
private final BoxesBookingMapper boxesBookingMapper;
|
||||||
|
private final TimeSlotConfigService timeSlotConfigService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<APPBXAvaliabilityRespVO> getAvailableMeals(Long boxesId, LocalDate date) {
|
public List<APPBXAvaliabilityRespVO> getAvailableMeals(Long boxesId, LocalDate date) {
|
||||||
@@ -44,9 +47,12 @@ public class BoxesAvailabilityServiceImpl extends ServiceImpl<BoxesAvailabilityM
|
|||||||
return new ArrayList<>(); // 返回空列表,表示餐桌不存在
|
return new ArrayList<>(); // 返回空列表,表示餐桌不存在
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 定义三个餐次类型
|
// 2. 从配置表获取所有启用的餐次类型
|
||||||
List<Integer> mealTypes = List.of(1, 2, 3); // 1-早餐, 2-中餐, 3-晚餐
|
List<TimeSlotConfigEntity> enabledTimeSlots = timeSlotConfigService.getEnabledTimeSlots();
|
||||||
List<String> mealNames = List.of("早餐", "中餐", "晚餐");
|
if (enabledTimeSlots.isEmpty()) {
|
||||||
|
log.warn("没有找到启用的时间段配置");
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
// 3. 查询指定包厢在指定日期的所有预约记录
|
// 3. 查询指定包厢在指定日期的所有预约记录
|
||||||
LambdaQueryWrapper<BoxesBookingEntity> bookingWrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<BoxesBookingEntity> bookingWrapper = Wrappers.lambdaQuery();
|
||||||
@@ -61,22 +67,19 @@ public class BoxesAvailabilityServiceImpl extends ServiceImpl<BoxesAvailabilityM
|
|||||||
|
|
||||||
// 5. 构建可预约餐段列表
|
// 5. 构建可预约餐段列表
|
||||||
List<APPBXAvaliabilityRespVO> availableMeals = new ArrayList<>();
|
List<APPBXAvaliabilityRespVO> availableMeals = new ArrayList<>();
|
||||||
for (int i = 0; i < mealTypes.size(); i++) {
|
for (TimeSlotConfigEntity timeSlot : enabledTimeSlots) {
|
||||||
Integer mealType = mealTypes.get(i);
|
|
||||||
String mealName = mealNames.get(i);
|
|
||||||
|
|
||||||
APPBXAvaliabilityRespVO meal = new APPBXAvaliabilityRespVO();
|
APPBXAvaliabilityRespVO meal = new APPBXAvaliabilityRespVO();
|
||||||
meal.setBoxesId(boxesId);
|
meal.setBoxesId(boxesId);
|
||||||
meal.setBxDate(date);
|
meal.setBxDate(date);
|
||||||
meal.setMealType(mealType);
|
meal.setMealType(timeSlot.getMealType());
|
||||||
meal.setMealName(mealName);
|
meal.setMealName(timeSlot.getMealName());
|
||||||
|
|
||||||
// 如果该餐次已被预约,状态设为1(已预约),否则设为0(可预约)
|
// 如果该餐次已被预约,状态设为1(已预约),否则设为0(可预约)
|
||||||
if (bookedMealTypes.contains(mealType)) {
|
if (bookedMealTypes.contains(timeSlot.getMealType())) {
|
||||||
meal.setStatus(1); // 已预约
|
meal.setStatus(1); // 已预约
|
||||||
// 找到对应的预约记录,填充预约信息
|
// 找到对应的预约记录,填充预约信息
|
||||||
BoxesBookingEntity booking = existingBookings.stream()
|
BoxesBookingEntity booking = existingBookings.stream()
|
||||||
.filter(b -> b.getMealType().equals(mealType))
|
.filter(b -> b.getMealType().equals(timeSlot.getMealType()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (booking != null) {
|
if (booking != null) {
|
||||||
|
|||||||
+37
-22
@@ -15,10 +15,12 @@ import com.bsd.pjcloud.canteen.dto.boxes.admin.BokingPageDTO;
|
|||||||
import com.bsd.pjcloud.canteen.entity.BoxesInfoEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesInfoEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.BoxesBookingEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesBookingEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.BoxesAvailabilityEntity;
|
import com.bsd.pjcloud.canteen.entity.BoxesAvailabilityEntity;
|
||||||
|
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
||||||
import com.bsd.pjcloud.canteen.mapper.BoxesInfoMapper;
|
import com.bsd.pjcloud.canteen.mapper.BoxesInfoMapper;
|
||||||
import com.bsd.pjcloud.canteen.mapper.BoxesBookingMapper;
|
import com.bsd.pjcloud.canteen.mapper.BoxesBookingMapper;
|
||||||
import com.bsd.pjcloud.canteen.service.BoxesAvailabilityService;
|
import com.bsd.pjcloud.canteen.service.BoxesAvailabilityService;
|
||||||
import com.bsd.pjcloud.canteen.service.BoxesBookingService;
|
import com.bsd.pjcloud.canteen.service.BoxesBookingService;
|
||||||
|
import com.bsd.pjcloud.canteen.service.TimeSlotConfigService;
|
||||||
import com.bsd.pjcloud.canteen.vo.AppMakeSaveReqVO;
|
import com.bsd.pjcloud.canteen.vo.AppMakeSaveReqVO;
|
||||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||||
@@ -31,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -56,6 +59,8 @@ public class BoxesBookingServiceImpl extends ServiceImpl<BoxesBookingMapper, Box
|
|||||||
|
|
||||||
private final BoxesAvailabilityService boxesAvailabilityService;
|
private final BoxesAvailabilityService boxesAvailabilityService;
|
||||||
|
|
||||||
|
private final TimeSlotConfigService timeSlotConfigService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<BoxesBookingEntity> pageScope(Page page, BokingPageDTO bokingPageDTO) {
|
public IPage<BoxesBookingEntity> pageScope(Page page, BokingPageDTO bokingPageDTO) {
|
||||||
LambdaQueryWrapper<BoxesBookingEntity> wrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<BoxesBookingEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
@@ -85,9 +90,8 @@ public class BoxesBookingServiceImpl extends ServiceImpl<BoxesBookingMapper, Box
|
|||||||
if (CollectionUtils.isEmpty(records)){
|
if (CollectionUtils.isEmpty(records)){
|
||||||
return pageData;
|
return pageData;
|
||||||
}
|
}
|
||||||
Set<Long> boxesIds = records.stream().map(boxesBookingEntity -> boxesBookingEntity.getBoxesId()).collect(Collectors.toSet());
|
Set<Long> boxesIds = records.stream().map(BoxesBookingEntity::getBoxesId).collect(Collectors.toSet());
|
||||||
Set<Long> usersIds = records.stream().map(boxesBookingEntity -> boxesBookingEntity.getUserId()).collect(Collectors.toSet());
|
Set<Long> usersIds = records.stream().map(BoxesBookingEntity::getUserId).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
List<BoxesInfoEntity> boxesInfoEntities = boxesInfoMapper.selectByIds(boxesIds);
|
List<BoxesInfoEntity> boxesInfoEntities = boxesInfoMapper.selectByIds(boxesIds);
|
||||||
Map<Long, BoxesInfoEntity> boxMap = boxesInfoEntities.stream()
|
Map<Long, BoxesInfoEntity> boxMap = boxesInfoEntities.stream()
|
||||||
@@ -95,10 +99,26 @@ public class BoxesBookingServiceImpl extends ServiceImpl<BoxesBookingMapper, Box
|
|||||||
R<Map<Long, SysUser>> userMapData = remoteUserService.getUserMap(usersIds);
|
R<Map<Long, SysUser>> userMapData = remoteUserService.getUserMap(usersIds);
|
||||||
Map<Long, SysUser> userMap = userMapData.getData();
|
Map<Long, SysUser> userMap = userMapData.getData();
|
||||||
|
|
||||||
|
// 从配置表获取餐次名称和时间段映射
|
||||||
|
Map<Integer, String> mealTypeNameMap = new HashMap<>();
|
||||||
|
Map<Integer, String> mealTypeTimeRangeMap = timeSlotConfigService.getMealTypeTimeRangeMap();
|
||||||
|
|
||||||
|
// 获取所有启用的时间段配置
|
||||||
|
List<TimeSlotConfigEntity> enabledTimeSlots = timeSlotConfigService.getEnabledTimeSlots();
|
||||||
|
for (TimeSlotConfigEntity timeSlot : enabledTimeSlots) {
|
||||||
|
mealTypeNameMap.put(timeSlot.getMealType(), timeSlot.getMealName());
|
||||||
|
}
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(records)){
|
if (!CollectionUtils.isEmpty(records)){
|
||||||
records.stream().forEach(record -> {
|
records.forEach(record -> {
|
||||||
|
// 餐桌名称
|
||||||
record.setBoxesName(boxMap.get(record.getBoxesId()) == null ? "" : boxMap.get(record.getBoxesId()).getName());
|
record.setBoxesName(boxMap.get(record.getBoxesId()) == null ? "" : boxMap.get(record.getBoxesId()).getName());
|
||||||
|
// 用户名称
|
||||||
record.setUserName(userMap.get(record.getUserId()) == null ? "" : userMap.get(record.getUserId()).getUsername());
|
record.setUserName(userMap.get(record.getUserId()) == null ? "" : userMap.get(record.getUserId()).getUsername());
|
||||||
|
// 餐次名称(从配置表获取)
|
||||||
|
record.setMealName(mealTypeNameMap.getOrDefault(record.getMealType(), ""));
|
||||||
|
// 预约时间(从配置表获取)
|
||||||
|
record.setReservationTime(mealTypeTimeRangeMap.getOrDefault(record.getMealType(), ""));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return pageData;
|
return pageData;
|
||||||
@@ -161,31 +181,26 @@ public class BoxesBookingServiceImpl extends ServiceImpl<BoxesBookingMapper, Box
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建可用时间段
|
|
||||||
*/
|
|
||||||
private BoxesAvailabilityEntity createAvailabilityTimeSlot(Long boxesId, LocalDate date, Integer mealType) {
|
private BoxesAvailabilityEntity createAvailabilityTimeSlot(Long boxesId, LocalDate date, Integer mealType) {
|
||||||
BoxesAvailabilityEntity availability = new BoxesAvailabilityEntity();
|
BoxesAvailabilityEntity availability = new BoxesAvailabilityEntity();
|
||||||
availability.setBoxesId(boxesId);
|
availability.setBoxesId(boxesId);
|
||||||
availability.setBxDate(date);
|
availability.setBxDate(date);
|
||||||
availability.setMealType(mealType);
|
availability.setMealType(mealType);
|
||||||
availability.setStatus(0); // 空闲
|
availability.setStatus(0);
|
||||||
|
|
||||||
// 根据餐次类型设置餐次名称
|
// 从配置表获取餐次名称
|
||||||
switch (mealType) {
|
List<TimeSlotConfigEntity> enabledTimeSlots = timeSlotConfigService.getEnabledTimeSlots();
|
||||||
case 1:
|
for (TimeSlotConfigEntity timeSlot : enabledTimeSlots) {
|
||||||
availability.setMealName("早餐");
|
if (timeSlot.getMealType().equals(mealType)) {
|
||||||
|
availability.setMealName(timeSlot.getMealName());
|
||||||
break;
|
break;
|
||||||
case 2:
|
}
|
||||||
availability.setMealName("中餐");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
availability.setMealName("晚餐");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
availability.setMealName("未知餐次");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (availability.getMealName() == null) {
|
||||||
|
availability.setMealName("未知餐次");
|
||||||
|
}
|
||||||
|
|
||||||
boxesAvailabilityService.save(availability);
|
boxesAvailabilityService.save(availability);
|
||||||
return availability;
|
return availability;
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-15
@@ -23,11 +23,13 @@ import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在线点餐spu
|
* 在线点餐spu
|
||||||
@@ -44,6 +46,8 @@ public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMap
|
|||||||
private final CanteenOnlineCategoryMapper canteenOnlineCategoryMapper;
|
private final CanteenOnlineCategoryMapper canteenOnlineCategoryMapper;
|
||||||
|
|
||||||
private final CanteenDailyMenuMapper canteenDailyMenuMapper;
|
private final CanteenDailyMenuMapper canteenDailyMenuMapper;
|
||||||
|
|
||||||
|
private final CanteenOnlineSpuMapper baseMapper;
|
||||||
@Override
|
@Override
|
||||||
public R<List<APPOnlineSpuVO>> getCanteenOnlineSpuList(String categoryId, String merchantId,String time) {
|
public R<List<APPOnlineSpuVO>> getCanteenOnlineSpuList(String categoryId, String merchantId,String time) {
|
||||||
LambdaQueryWrapper<CanteenOnlineSpuEntity> canteenOnlineSpuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<CanteenOnlineSpuEntity> canteenOnlineSpuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
@@ -86,33 +90,72 @@ public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Object saveCanteenSpuBatch(CanteenOnlineSpuSaveDto canteenOnlineSpuSaveDto) {
|
public Object saveCanteenSpuBatch(CanteenOnlineSpuSaveDto canteenOnlineSpuSaveDto) {
|
||||||
Long merchantId = canteenOnlineSpuSaveDto.getMerchantId();
|
Long merchantId = canteenOnlineSpuSaveDto.getMerchantId();
|
||||||
List<CanteenOnlineSpuSaveItemDto> items = canteenOnlineSpuSaveDto.getItems();
|
List<CanteenOnlineSpuSaveItemDto> items = canteenOnlineSpuSaveDto.getItems();
|
||||||
List<CanteenOnlineSpuEntity> canteenSpuEntities = BeanUtils.toBean(items, CanteenOnlineSpuEntity.class);
|
List<CanteenOnlineSpuEntity> canteenSpuEntities = BeanUtils.toBean(items, CanteenOnlineSpuEntity.class);
|
||||||
//每日菜谱的分类,查询在线分类里面是否有
|
|
||||||
Set<Long> categoryIds = canteenSpuEntities.stream().map(c -> c.getCategoryId()).collect(Collectors.toSet());
|
// 1. 检查是否有重复的linkSpuId
|
||||||
List<CanteenCategoryEntity> canteenCategoryEntities = categoryMapper.selectList(new LambdaQueryWrapper<CanteenCategoryEntity>().select(CanteenCategoryEntity::getId).in(CanteenCategoryEntity::getId, categoryIds));
|
List<Long> linkSpuIds = canteenSpuEntities.stream()
|
||||||
//把canteenCategoryEntities转为key map
|
.map(CanteenOnlineSpuEntity::getLinkSpuId)
|
||||||
Map<Long, CanteenCategoryEntity> canteenCategoryEntityMap = canteenCategoryEntities.stream().collect(Collectors.toMap(CanteenCategoryEntity::getId, c -> c));
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!linkSpuIds.isEmpty()) {
|
||||||
|
// 查询数据库中是否已经存在这些linkSpuId
|
||||||
|
LambdaQueryWrapper<CanteenOnlineSpuEntity> existingWrapper = new LambdaQueryWrapper<>();
|
||||||
|
existingWrapper.eq(CanteenOnlineSpuEntity::getMerchantId, merchantId);
|
||||||
|
existingWrapper.in(CanteenOnlineSpuEntity::getLinkSpuId, linkSpuIds);
|
||||||
|
List<CanteenOnlineSpuEntity> existingSpus = baseMapper.selectList(existingWrapper);
|
||||||
|
|
||||||
|
if (!existingSpus.isEmpty()) {
|
||||||
|
// 找出重复的菜品名称
|
||||||
|
List<String> duplicateNames = existingSpus.stream()
|
||||||
|
.map(CanteenOnlineSpuEntity::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return R.failed("以下菜品已经导入过,不能重复导入:" + String.join("、", duplicateNames));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 每日菜谱的分类,查询在线分类里面是否有
|
||||||
|
Set<Long> categoryIds = canteenSpuEntities.stream().map(c -> c.getCategoryId()).collect(Collectors.toSet());
|
||||||
|
LambdaQueryWrapper<CanteenCategoryEntity> canteenCategoryEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
canteenCategoryEntityLambdaQueryWrapper.in(CanteenCategoryEntity::getId, categoryIds);
|
||||||
|
List<CanteenCategoryEntity> canteenCategoryEntities = categoryMapper.selectList(canteenCategoryEntityLambdaQueryWrapper);
|
||||||
|
|
||||||
|
// 3. 把canteenCategoryEntities转为key map
|
||||||
|
Map<Long, CanteenCategoryEntity> canteenCategoryEntityMap = canteenCategoryEntities.stream()
|
||||||
|
.collect(Collectors.toMap(CanteenCategoryEntity::getId, c -> c));
|
||||||
|
|
||||||
Long deptId = SecurityUtils.getUser().getDeptId();
|
Long deptId = SecurityUtils.getUser().getDeptId();
|
||||||
canteenSpuEntities.forEach(c -> {
|
canteenSpuEntities.forEach(c -> {
|
||||||
CanteenCategoryEntity canteenCategoryEntity = canteenCategoryEntityMap.get(c.getCategoryId());
|
CanteenCategoryEntity canteenCategoryEntity = canteenCategoryEntityMap.get(c.getCategoryId());
|
||||||
String name = canteenCategoryEntity.getName();
|
if (canteenCategoryEntity != null) {
|
||||||
//查询分类里面是否有
|
String name = canteenCategoryEntity.getName();
|
||||||
CanteenOnlineCategoryEntity canteenOnlineCategoryEntity = canteenOnlineCategoryMapper.selectOne(new LambdaQueryWrapper<CanteenOnlineCategoryEntity>().eq(CanteenOnlineCategoryEntity::getName, name));
|
//查询分类里面是否有
|
||||||
if (canteenOnlineCategoryEntity == null){
|
CanteenOnlineCategoryEntity canteenOnlineCategoryEntity = canteenOnlineCategoryMapper.selectOne(
|
||||||
CanteenOnlineCategoryEntity bean = BeanUtils.toBean(canteenCategoryEntity, CanteenOnlineCategoryEntity.class);
|
new LambdaQueryWrapper<CanteenOnlineCategoryEntity>().eq(CanteenOnlineCategoryEntity::getName, name)
|
||||||
canteenOnlineCategoryMapper.insert(bean);
|
);
|
||||||
c.setCategoryId(bean.getId());
|
if (null == canteenOnlineCategoryEntity) {
|
||||||
}else {
|
CanteenOnlineCategoryEntity bean = BeanUtils.toBean(canteenCategoryEntity, CanteenOnlineCategoryEntity.class);
|
||||||
c.setCategoryId(canteenOnlineCategoryEntity.getId());
|
canteenOnlineCategoryMapper.insert(bean);
|
||||||
|
c.setCategoryId(bean.getId());
|
||||||
|
} else {
|
||||||
|
c.setCategoryId(canteenOnlineCategoryEntity.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.setMerchantId(merchantId);
|
c.setMerchantId(merchantId);
|
||||||
c.setDeptId(deptId);
|
c.setDeptId(deptId);
|
||||||
});
|
});
|
||||||
return baseMapper.insert(canteenSpuEntities);
|
|
||||||
|
// 4. 使用批量插入方法
|
||||||
|
boolean result = this.saveBatch(canteenSpuEntities);
|
||||||
|
if (result) {
|
||||||
|
return R.ok("批量保存成功,共保存 " + canteenSpuEntities.size() + " 条记录");
|
||||||
|
} else {
|
||||||
|
return R.failed("批量保存失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+19
-8
@@ -12,10 +12,7 @@ import com.bsd.pjcloud.canteen.entity.CanteenDailyMenuEntity;
|
|||||||
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
|
import com.bsd.pjcloud.canteen.entity.CanteenOnlineSpuEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
|
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
|
||||||
import com.bsd.pjcloud.canteen.entity.CanteenStockEntity;
|
import com.bsd.pjcloud.canteen.entity.CanteenStockEntity;
|
||||||
import com.bsd.pjcloud.canteen.mapper.CanteenCategoryMapper;
|
import com.bsd.pjcloud.canteen.mapper.*;
|
||||||
import com.bsd.pjcloud.canteen.mapper.CanteenDailyMenuMapper;
|
|
||||||
import com.bsd.pjcloud.canteen.mapper.CanteenSpuMapper;
|
|
||||||
import com.bsd.pjcloud.canteen.mapper.CanteenStockMapper;
|
|
||||||
import com.bsd.pjcloud.canteen.service.CanteenDailyMenuService;
|
import com.bsd.pjcloud.canteen.service.CanteenDailyMenuService;
|
||||||
import com.bsd.pjcloud.canteen.service.CanteenSpuService;
|
import com.bsd.pjcloud.canteen.service.CanteenSpuService;
|
||||||
import com.bsd.pjcloud.canteen.service.CanteenStockService;
|
import com.bsd.pjcloud.canteen.service.CanteenStockService;
|
||||||
@@ -31,10 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +45,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
|
|||||||
private final CanteenDailyMenuMapper canteenDailyMenuMapper;
|
private final CanteenDailyMenuMapper canteenDailyMenuMapper;
|
||||||
private final CanteenCategoryMapper canteenCategoryMapper;
|
private final CanteenCategoryMapper canteenCategoryMapper;
|
||||||
private final CanteenStockMapper canteenStockMapper;
|
private final CanteenStockMapper canteenStockMapper;
|
||||||
|
private final CanteenOnlineSpuMapper canteenOnlineSpuMapper;
|
||||||
@Override
|
@Override
|
||||||
public Object selectFoodList(LambdaQueryWrapper<CanteenSpuEntity> wrapper) {
|
public Object selectFoodList(LambdaQueryWrapper<CanteenSpuEntity> wrapper) {
|
||||||
return baseMapper.selectListByScope(wrapper, DataScope.of());
|
return baseMapper.selectListByScope(wrapper, DataScope.of());
|
||||||
@@ -226,7 +221,23 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
|
|||||||
return resultPage;
|
return resultPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object selectPage(Page page, CanteenSpuEntity canteenSpu) {
|
||||||
|
LambdaQueryWrapper<CanteenSpuEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.like(StrUtil.isNotBlank(canteenSpu.getName()), CanteenSpuEntity::getName, canteenSpu.getName());
|
||||||
|
wrapper.eq(Objects.nonNull(canteenSpu.getCategoryId()), CanteenSpuEntity::getCategoryId, canteenSpu.getCategoryId());
|
||||||
|
wrapper.orderByAsc(CanteenSpuEntity::getSort).orderByDesc(CanteenSpuEntity::getId);
|
||||||
|
|
||||||
|
LambdaQueryWrapper<CanteenOnlineSpuEntity> canteenOnlineSpuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
canteenOnlineSpuEntityLambdaQueryWrapper.isNotNull(CanteenOnlineSpuEntity::getLinkSpuId);
|
||||||
|
List<CanteenOnlineSpuEntity> canteenOnlineSpuEntities = canteenOnlineSpuMapper.selectListByScope(canteenOnlineSpuEntityLambdaQueryWrapper, DataScope.of());
|
||||||
|
Set<Long> spuIds = canteenOnlineSpuEntities.stream().map(CanteenOnlineSpuEntity::getLinkSpuId).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
wrapper.notIn(spuIds.size() > 0, CanteenSpuEntity::getId, spuIds);
|
||||||
|
|
||||||
|
Page pageData = baseMapper.selectPageByScope(page, wrapper, DataScope.of());
|
||||||
|
return pageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+36
-3
@@ -1,16 +1,49 @@
|
|||||||
package com.bsd.pjcloud.canteen.service.impl;
|
package com.bsd.pjcloud.canteen.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
import com.bsd.pjcloud.canteen.entity.TimeSlotConfigEntity;
|
||||||
import com.bsd.pjcloud.canteen.mapper.TimeSlotConfigMapper;
|
import com.bsd.pjcloud.canteen.mapper.TimeSlotConfigMapper;
|
||||||
import com.bsd.pjcloud.canteen.service.TimeSlotConfigService;
|
import com.bsd.pjcloud.canteen.service.TimeSlotConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间段配置表
|
* 时间段配置服务实现
|
||||||
*
|
*
|
||||||
* @author pjcloud
|
* @author zjf
|
||||||
* @date 2025-08-13 12:17:22
|
* @date 2024-12-17
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class TimeSlotConfigServiceImpl extends ServiceImpl<TimeSlotConfigMapper, TimeSlotConfigEntity> implements TimeSlotConfigService {
|
public class TimeSlotConfigServiceImpl extends ServiceImpl<TimeSlotConfigMapper, TimeSlotConfigEntity> implements TimeSlotConfigService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TimeSlotConfigEntity> getEnabledTimeSlots() {
|
||||||
|
LambdaQueryWrapper<TimeSlotConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
|
wrapper.eq(TimeSlotConfigEntity::getIsEnabled, 1); // 只查询启用的
|
||||||
|
wrapper.orderByAsc(TimeSlotConfigEntity::getSort); // 按排序升序
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Integer, String> getMealTypeTimeRangeMap() {
|
||||||
|
List<TimeSlotConfigEntity> enabledTimeSlots = getEnabledTimeSlots();
|
||||||
|
|
||||||
|
Map<Integer, String> mealTypeTimeRangeMap = new HashMap<>();
|
||||||
|
for (TimeSlotConfigEntity timeSlot : enabledTimeSlots) {
|
||||||
|
String timeRange = timeSlot.getStartTime() + "-" + timeSlot.getEndTime();
|
||||||
|
mealTypeTimeRangeMap.put(timeSlot.getMealType(), timeRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mealTypeTimeRangeMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user