更新了写真预约模块

This commit is contained in:
chen-xin-zhi 2025-02-15 20:15:42 +08:00
parent 930505100c
commit 34c887e363
26 changed files with 596 additions and 313 deletions

View File

@ -1,31 +1,26 @@
package com.cultural.heritage.controller.book;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.constant.BookConstant;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonStringRequest;
import com.cultural.heritage.model.dto.book.BookingDateAddRequest;
import com.cultural.heritage.model.dto.timeinterval.TimeIntervalAddRequest;
import com.cultural.heritage.model.entity.BookingDate;
import com.cultural.heritage.model.entity.TimeInterval;
import com.cultural.heritage.model.vo.book.BookingDateVO;
import com.cultural.heritage.model.vo.timeinterval.TimeIntervalVO;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.bookingDate.single.BookingDateSingleAddRequest;
import com.cultural.heritage.model.dto.bookingTime.BookingTimeAddRequest;
import com.cultural.heritage.model.dto.bookingTime.single.BookingTimeSingleAddRequest;
import com.cultural.heritage.model.entity.*;
import com.cultural.heritage.service.book.BookingDateService;
import com.cultural.heritage.service.book.TimeIntervalService;
import com.cultural.heritage.service.book.BookingTimeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
@ -33,10 +28,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/book")
@ -50,129 +42,152 @@ public class BookingDateController {
@Resource
private TimeIntervalService timeIntervalService;
private BookingTimeService bookingTimeService;
/**
* Web端管理员添加写真预约日期和时间段
* @param bookingDateAddRequestList 预约日期列表
* @return 是否添加成功
* Web端管理员根据id删除预约日期
* @param commonRequest 预约日期id
* @return 是否删除成功
*/
@PostMapping("/add")
@Operation(summary = "Web端管理员添加写真预约日期和时间段", description = "参数:预约日期列表,权限:管理员(admin, boss)方法名addBookingDate")
@PostMapping("/del/id")
@Operation(summary = "Web端管理员根据id删除预约日期", description = "参数:预约日期id权限管理员(admin, boss)方法名delAppointmentDateById")
@Transactional(rollbackFor = Exception.class)
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> addBookingDate(@RequestBody List<BookingDateAddRequest> bookingDateAddRequestList) {
if (bookingDateAddRequestList == null) {
public BaseResponse<Boolean> delBookingDateById(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 添加写真预约日期
List<BookingDate> bookingDateList = bookingDateAddRequestList.stream().map(bookingDateAddRequest -> {
BookingDate bookingDate = new BookingDate();
BeanUtils.copyProperties(bookingDateAddRequest, bookingDate);
bookingDateService.validBookingDate(bookingDate, false);
return bookingDate;
}).toList();
boolean result = bookingDateService.saveBatch(bookingDateList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
Long id = commonRequest.getId();
// 删除这个预约日期关联的所有时间点
QueryWrapper<BookingTime> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bookingDateId", id);
boolean remove = bookingTimeService.remove(queryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间点删除失败");
// 删除这个预约日期
boolean success = bookingDateService.removeById(id);
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "预约日期删除失败");
// 添加写真预约时间段
List<TimeInterval> timeIntervals = new ArrayList<>();
for (int i = 0; i < bookingDateAddRequestList.size(); i++) {
BookingDate bookingDate = bookingDateList.get(i);
Long dateId = bookingDate.getId();
BookingDateAddRequest bookingDateAddRequest = bookingDateAddRequestList.get(i);
List<TimeIntervalAddRequest> timeIntervalAddRequestList = bookingDateAddRequest.getTimeIntervalAddRequestList();
List<TimeInterval> timeIntervalList = timeIntervalAddRequestList.stream().map(timeIntervalAddRequest -> {
TimeInterval timeInterval = new TimeInterval();
BeanUtils.copyProperties(timeIntervalAddRequest, timeInterval);
timeInterval.setBookingDateId(dateId);
timeIntervalService.validTimeInterval(timeInterval, false);
return timeInterval;
}).toList();
timeIntervals.addAll(timeIntervalList);
}
boolean success = timeIntervalService.saveBatch(timeIntervals);
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* Web端管理员根据预约类型查询预约时间表
* @param commonStringRequest 预约类型
* @return 预约时间表
* Web端管理员根据id删除预约时间
* @param commonRequest 预约时间id
* @return 是否删除成功
*/
@PostMapping("/list/type")
@Operation(summary = "Web端管理员根据预约类型查询预约时间表", description = "参数:预约类型,权限:管理员(admin, boss)方法名listBookingDateByType")
@Transactional(rollbackFor = Exception.class)
@PostMapping("/del/time/id")
@Operation(summary = "Web端管理员根据id删除预约时间", description = "参数预约时间id权限管理员(admin, boss)方法名delBookingTimeById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<List<BookingDateVO>> listBookingDateByType(@RequestBody CommonStringRequest commonStringRequest) {
if (commonStringRequest == null || StringUtils.isBlank(commonStringRequest.getType())) {
public BaseResponse<Boolean> delBookingTimeById(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
String type = commonStringRequest.getType();
if (!type.equals(BookConstant.RENT_CLOTHES) && !type.equals(BookConstant.OWN_CLOTHES)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "类型参数错误");
}
QueryWrapper<BookingDate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", type);
List<BookingDate> bookingDateList = bookingDateService.list(queryWrapper);
List<TimeInterval> timeIntervalList = timeIntervalService.list();
// 存储写真预约时间段的map集合(:预约日期id, :预约时间段列表)
Map<Long, List<TimeIntervalVO>> timeMap = new HashMap<>();
// 处理预约时间段将预约时间段存入map集合
for (TimeInterval timeInterval : timeIntervalList) {
TimeIntervalVO timeIntervalVO = new TimeIntervalVO();
BeanUtils.copyProperties(timeInterval, timeIntervalVO);
Long bookingDateId = timeInterval.getBookingDateId();
List<TimeIntervalVO> timeIntervalVOS = timeMap.get(bookingDateId);
if (timeIntervalVOS == null) {
timeIntervalVOS = new ArrayList<>();
}
timeIntervalVOS.add(timeIntervalVO);
timeMap.put(bookingDateId, timeIntervalVOS);
}
// 处理预约日期填充当前预约日期对应的预约时间段
List<BookingDateVO> bookingDateVOList = new ArrayList<>();
for (BookingDate bookingDate : bookingDateList) {
BookingDateVO bookingDateVO = new BookingDateVO();
BeanUtils.copyProperties(bookingDate, bookingDateVO);
Long dateId = bookingDate.getId();
List<TimeIntervalVO> timeIntervalVOS = timeMap.get(dateId);
bookingDateVO.setTimeIntervalVOList(timeIntervalVOS);
bookingDateVOList.add(bookingDateVO);
}
Long id = commonRequest.getId();
boolean remove = bookingTimeService.removeById(id);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间删除失败");
// 将预约日期从小到大排序
bookingDateVOList.sort((book1, book2) -> {
DateTime date1 = DateUtil.parse(book1.getSpecificDate(), "yyyy-MM-dd");
DateTime date2 = DateUtil.parse(book2.getSpecificDate(), "yyyy-MM-dd");
return date1.compareTo(date2);
});
return ResultUtils.success(bookingDateVOList);
return ResultUtils.success(true);
}
/**
* Web端管理员根据id修改预约日期的状态
* @param commonRequest 预约日期id
* @return 是否更新成功
*/
@PostMapping("/update/status")
@Operation(summary = "Web端管理员根据id修改预约日期的状态", description = "参数预约日期id权限管理员(admin, boss)方法名updateBookingTimeStatusById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateBookingTimeStatusById(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = commonRequest.getId();
BookingDate bookingDate = bookingDateService.getById(id);
ThrowUtils.throwIf(bookingDate == null, ErrorCode.OPERATION_ERROR, "预约日期不存在");
Integer status = bookingDate.getIsAvailable() == 0 ? 1 : 0;
UpdateWrapper<BookingDate> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", id);
updateWrapper.set("isAvailable", status);
boolean update = bookingDateService.update(updateWrapper);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "预约日期状态修改失败");
return ResultUtils.success(true);
}
/**
* Web端管理员添加预约时间
* @param bookingTimeSingleAddRequest 预约时间段添加请求体
* @return 是否添加成功
*/
@PostMapping("/add/time")
@Operation(summary = "Web端管理员添加预约时间段", description = "参数:预约时间段添加请求体,权限:管理员(admin, boss)方法名addAppointmentDate")
@Transactional(rollbackFor = Exception.class)
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Long> addTimePeriod(@RequestBody BookingTimeSingleAddRequest bookingTimeSingleAddRequest) {
if (bookingTimeSingleAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
BookingTime bookingTime = new BookingTime();
BeanUtils.copyProperties(bookingTimeSingleAddRequest, bookingTime);
boolean save = bookingTimeService.save(bookingTime);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "预约时间段添加失败");
return ResultUtils.success(bookingTime.getId());
}
/**
* Web端管理员添加预约日期
* @param bookingDateSingleAddRequest 预约日期添加请求体
* @return 是否添加成功
*/
@PostMapping("/add")
@Operation(summary = "Web端管理员添加预约日期", description = "参数:预约日期添加请求体,权限:管理员(admin, boss)方法名addBookingDate")
@Transactional(rollbackFor = Exception.class)
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> addBookingDate(@RequestBody BookingDateSingleAddRequest bookingDateSingleAddRequest) {
if (bookingDateSingleAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 添加当前商品的预约日期
BookingDate bookingDate = new BookingDate();
BeanUtils.copyProperties(bookingDateSingleAddRequest, bookingDate);
boolean save = bookingDateService.save(bookingDate);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "预约日期添加失败");
// 添加当前预约日期的预约时间段
Long bookingDateId = bookingDate.getId();
List<BookingTimeAddRequest> bookingTimeAddRequestList = bookingDateSingleAddRequest.getBookingTimeAddRequestList();
List<BookingTime> bookingTimes = bookingTimeAddRequestList.stream().map(bookingTimeAddRequest -> {
BookingTime bookingTime = new BookingTime();
BeanUtils.copyProperties(bookingTimeAddRequest, bookingTime);
bookingTime.setBookingDateId(bookingDateId);
return bookingTime;
}).toList();
boolean result = bookingTimeService.saveBatch(bookingTimes);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "批量添加预约时间失败");
return ResultUtils.success(true);
}
// @PostMapping("/update")
// @Operation(summary = "Web端管理员根据预约类型更新预约时间表", description = "参数:预约类型,权限:管理员(admin, boss)方法名updateBookingDate")
// @Transactional(rollbackFor = Exception.class)
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
// public BaseResponse<Boolean> updateBookingDate(@RequestBody CommonStringRequest commonStringRequest) {
// if (commonStringRequest == null || StringUtils.isBlank(commonStringRequest.getType())) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
// }
// String type = commonStringRequest.getType();
// if (!type.equals(BookConstant.RENT_CLOTHES) && !type.equals(BookConstant.OWN_CLOTHES)) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR, "类型参数错误");
// }
// QueryWrapper<BookingDate> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("type", type);
// return null;
// }
}

View File

@ -1,6 +1,8 @@
package com.cultural.heritage.controller.book;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -13,13 +15,22 @@ import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonBatchRequest;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.bookingDate.BookingDateAddRequest;
import com.cultural.heritage.model.dto.bookingTime.BookingTimeAddRequest;
import com.cultural.heritage.model.dto.photoProducts.PhotoProductsAddRequest;
import com.cultural.heritage.model.dto.photoProducts.PhotoProductsQueryRequest;
import com.cultural.heritage.model.dto.photoProducts.PhotoProductsUpdateRequest;
import com.cultural.heritage.model.entity.BookingDate;
import com.cultural.heritage.model.entity.BookingTime;
import com.cultural.heritage.model.entity.PhotoProducts;
import com.cultural.heritage.model.vo.bookingDate.BookingDateVO;
import com.cultural.heritage.model.vo.bookingTime.BookingTimeVO;
import com.cultural.heritage.model.vo.clothesinfo.PhotoProductsVO;
import com.cultural.heritage.service.book.BookingDateService;
import com.cultural.heritage.service.book.BookingTimeService;
import com.cultural.heritage.service.book.PhotoCategoryService;
import com.cultural.heritage.service.book.PhotoProductsService;
import com.cultural.heritage.service.common.CommonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@ -31,7 +42,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/photoProducts")
@ -48,6 +62,18 @@ public class PhotoProductsController {
private PhotoCategoryService photoCategoryService;
@Resource
private BookingDateService bookingDateService;
@Resource
private BookingTimeService bookingTimeService;
@Resource
private CommonService commonService;
/**
* Web端管理员添加写真产品
* @param photoProductsAddRequest 写真产品添加请求体
@ -66,6 +92,42 @@ public class PhotoProductsController {
photoProductsService.validPhotoProducts(photoProducts, false);
boolean result = photoProductsService.save(photoProducts);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "写真产品添加失败");
// 封装map集合预约日期id, 预约时间列表
Map<Long, List<BookingTimeAddRequest>> map = new HashMap<>();
// 添加预约日期
List<BookingDateAddRequest> bookingDateAddRequestList = photoProductsAddRequest.getBookingDateAddRequestList();
List<BookingDate> bookingDateList = bookingDateAddRequestList.stream().map(bookingDateAddRequest -> {
BookingDate bookingDate = new BookingDate();
BeanUtils.copyProperties(bookingDateAddRequest, bookingDate);
bookingDate.setPhotoProductId(photoProducts.getId());
// 校验
bookingDateService.validBookingDate(bookingDate, false);
return bookingDate;
}).toList();
boolean saveBatch = bookingDateService.saveBatch(bookingDateList);
ThrowUtils.throwIf(!saveBatch, ErrorCode.OPERATION_ERROR, "写真产品预约日期添加失败");
// 添加预约时间段
List<BookingTime> bookingTimes = new ArrayList<>();
for (int i = 0; i < bookingDateList.size(); i++) {
BookingDate bookingDate = bookingDateList.get(i);
Long bookingDateId = bookingDate.getId();
BookingDateAddRequest bookingDateAddRequest = bookingDateAddRequestList.get(i);
List<BookingTimeAddRequest> bookingTimeAddRequestList = bookingDateAddRequest.getBookingTimeAddRequestList();
List<BookingTime> bookingTimeList = bookingTimeAddRequestList.stream().map(bookingTimeAddRequest -> {
BookingTime bookingTime = new BookingTime();
BeanUtils.copyProperties(bookingTimeAddRequest, bookingTime);
bookingTime.setBookingDateId(bookingDateId);
return bookingTime;
}).toList();
bookingTimes.addAll(bookingTimeList);
}
boolean save = bookingTimeService.saveBatch(bookingTimes);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "写真产品预约时间添加失败");
return ResultUtils.success(photoProducts.getId());
}
@ -109,6 +171,19 @@ public class PhotoProductsController {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = commonRequest.getId();
// 删除写真产品下的预约时间
QueryWrapper<BookingDate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("photoProductId", id);
List<BookingDate> bookingDateList = bookingDateService.list(queryWrapper);
List<Long> bookingDateIds = bookingDateList.stream().map(BookingDate::getId).toList();
QueryWrapper<BookingTime> bookingTimeQueryWrapper = new QueryWrapper<>();
bookingTimeQueryWrapper.in("bookingDateId", bookingDateIds);
boolean remove = bookingTimeService.remove(bookingTimeQueryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间批量删除失败");
// 删除写真产品下的预约时间
boolean success = bookingDateService.remove(queryWrapper);
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "预约日期批量删除失败");
// 删除写真产品
boolean result = photoProductsService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "写真产品删除失败");
return ResultUtils.success(true);
@ -130,6 +205,20 @@ public class PhotoProductsController {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
List<Long> idList = commonBatchRequest.getIdList();
// 删除写真产品下的预约时间
QueryWrapper<BookingDate> queryWrapper = new QueryWrapper<>();
queryWrapper.in("photoProductId", idList);
List<BookingDate> bookingDateList = bookingDateService.list(queryWrapper);
List<Long> bookingDateIds = bookingDateList.stream().map(BookingDate::getId).toList();
QueryWrapper<BookingTime> bookingTimeQueryWrapper = new QueryWrapper<>();
bookingTimeQueryWrapper.in("bookingDateId", bookingDateIds);
boolean remove = bookingTimeService.remove(bookingTimeQueryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间批量删除失败");
// 删除写真产品下的预约时间
boolean success = bookingDateService.remove(queryWrapper);
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "预约日期批量删除失败");
// 批量删除写真产品
boolean result = photoProductsService.removeBatchByIds(idList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "写真产品批量删除失败");
return ResultUtils.success(true);
@ -154,15 +243,60 @@ public class PhotoProductsController {
long pageSize = photoProductsQueryRequest.getPageSize();
QueryWrapper<PhotoProducts> queryWrapper = photoProductsService.getQueryWrapper(photoProductsQueryRequest);
Page<PhotoProducts> page = photoProductsService.page(new Page<>(current, pageSize), queryWrapper);
// 封装服装类VO
// 获取写真产品列表
List<PhotoProducts> records = page.getRecords();
List<PhotoProductsVO> photoProductsVOS = records.stream().map(photoProducts -> {
// 获取预约日期表
List<BookingDate> bookingDateList = commonService.getItemsByIds(records, bookingDateService, PhotoProducts::getId);
// 获取预约时间表
List<BookingTime> bookingTimeList = commonService.getItemsByIds(bookingDateList, bookingTimeService, BookingDate::getId);
// 封装成BookingTimeVO列表
List<BookingTimeVO> bookingTimeVOList = bookingTimeList.stream().map(bookingTime -> {
BookingTimeVO bookingTimeVO = new BookingTimeVO();
BeanUtils.copyProperties(bookingTime, bookingTimeVO);
return bookingTimeVO;
}).toList();
// 将预约时间从小到大排序
bookingTimeVOList.sort((b1, b2) -> {
DateTime time1 = DateUtil.parse(b1.getTimePoint(), "HH:mm");
DateTime time2 = DateUtil.parse(b2.getTimePoint(), "HH:mm");
return time1.compareTo(time2); // 按照时间升序排序
});
// 封装成BookingDateVO列表
List<BookingDateVO> bookingDateVOS = new ArrayList<>();
for (BookingDate bookingDate : bookingDateList) {
Long bookingDateId = bookingDate.getId();
List<BookingTimeVO> bookingTimeVOS = bookingTimeVOList.stream().filter(bookingTimeVO ->
bookingTimeVO.getBookingDateId().equals(bookingDateId)).toList();
BookingDateVO bookingDateVO = new BookingDateVO();
BeanUtils.copyProperties(bookingDate, bookingDateVO);
bookingDateVO.setBookingTimeVOList(bookingTimeVOS);
bookingDateVOS.add(bookingDateVO);
}
// 将预约日期从小到大排序
bookingDateVOS.sort((app1, app2) -> {
DateTime date1 = DateUtil.parse(app1.getSpecificDate(), "yyyy-MM-dd");
DateTime date2 = DateUtil.parse(app2.getSpecificDate(), "yyyy-MM-dd");
return date1.compareTo(date2);
});
// 封装成BookingPhotoProductsVO列表
List<PhotoProductsVO> photoProductsVOList = new ArrayList<>();
for (PhotoProducts photoProducts : records) {
Long photoProductsId = photoProducts.getId();
List<BookingDateVO> bookingDateVOList = bookingDateVOS.stream().filter(bookingDateVO ->
bookingDateVO.getPhotoProductId().equals(photoProductsId)).toList();
PhotoProductsVO photoProductsVO = new PhotoProductsVO();
BeanUtils.copyProperties(photoProducts, photoProductsVO);
return photoProductsVO;
}).toList();
photoProductsVO.setBookingDateVOList(bookingDateVOList);
photoProductsVOList.add(photoProductsVO);
}
Page<PhotoProductsVO> voPage = new Page<>();
voPage.setRecords(photoProductsVOS);
voPage.setRecords(photoProductsVOList);
voPage.setTotal(page.getTotal());
voPage.setCurrent(page.getCurrent());
voPage.setSize(page.getSize());
@ -187,8 +321,77 @@ public class PhotoProductsController {
Long id = commonRequest.getId();
PhotoProducts photoProducts = photoProductsService.getById(id);
ThrowUtils.throwIf(photoProducts == null || photoProducts.getIsShelves() == 0, ErrorCode.OPERATION_ERROR, "该商品已被删除或者已下架");
// 获取预约日期表
QueryWrapper<BookingDate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("photoProductId", id);
List<BookingDate> bookingDateList = bookingDateService.list(queryWrapper);
// 获取预约时间表
List<BookingTime> bookingTimeList = commonService.getItemsByIds(bookingDateList, bookingTimeService, BookingDate::getId);
// 封装成BookingTimeVO列表
List<BookingTimeVO> bookingTimeVOList = bookingTimeList.stream().map(bookingTime -> {
BookingTimeVO bookingTimeVO = new BookingTimeVO();
BeanUtils.copyProperties(bookingTime, bookingTimeVO);
return bookingTimeVO;
}).toList();
// 将预约时间从小到大排序
bookingTimeVOList.sort((b1, b2) -> {
DateTime time1 = DateUtil.parse(b1.getTimePoint(), "HH:mm");
DateTime time2 = DateUtil.parse(b2.getTimePoint(), "HH:mm");
return time1.compareTo(time2); // 按照时间升序排序
});
// 封装成BookingDateVO列表
List<BookingDateVO> bookingDateVOS = new ArrayList<>();
for (BookingDate bookingDate : bookingDateList) {
Long bookingDateId = bookingDate.getId();
List<BookingTimeVO> bookingTimeVOS = bookingTimeVOList.stream().filter(bookingTimeVO ->
bookingTimeVO.getBookingDateId().equals(bookingDateId)).toList();
BookingDateVO bookingDateVO = new BookingDateVO();
BeanUtils.copyProperties(bookingDate, bookingDateVO);
bookingDateVO.setBookingTimeVOList(bookingTimeVOS);
bookingDateVOS.add(bookingDateVO);
}
// 将预约日期从小到大排序
bookingDateVOS.sort((b1, b2) -> {
DateTime date1 = DateUtil.parse(b1.getSpecificDate(), "yyyy-MM-dd");
DateTime date2 = DateUtil.parse(b2.getSpecificDate(), "yyyy-MM-dd");
return date1.compareTo(date2);
});
List<BookingDateVO> bookingDateVOList = new ArrayList<>();
// 过滤掉不合理的预约时间
for (BookingDateVO bookingDateVO : bookingDateVOS) {
// 过滤掉没有空闲的预约时间
if (bookingDateVO.getIsAvailable() == 0) continue;
// 过滤掉已过期的预约时间
String specificDate = bookingDateVO.getSpecificDate();
String today = DateUtil.today();
int result = DateUtil.compare(DateUtil.parse(specificDate), DateUtil.parse(today));
if (result < 0) continue;
// 如果预约日期相同过滤掉预约时间
if (result == 0) {
List<BookingTimeVO> bookingTimeVOS = bookingDateVO.getBookingTimeVOList();
bookingTimeVOS = bookingTimeVOS.stream().filter(bookingTimeVO -> {
String timePoint = bookingTimeVO.getTimePoint() + ":00";
DateTime targetTime = DateUtil.parse(timePoint, "HH:mm:ss");
DateTime now = DateUtil.date();
DateTime currentTime = DateUtil.parse(now.toString("HH:mm:ss"), "HH:mm:ss");
return currentTime.compareTo(targetTime) < 0;
}).toList();
if (bookingTimeVOS.isEmpty()) continue;
}
bookingDateVOList.add(bookingDateVO);
}
// 封装成BookingPhotoProductsVO列表
PhotoProductsVO photoProductsVO = new PhotoProductsVO();
BeanUtils.copyProperties(photoProductsVO, photoProductsVO);
photoProductsVO.setBookingDateVOList(bookingDateVOList);
return ResultUtils.success(photoProductsVO);
}

View File

@ -463,6 +463,18 @@ public class GoodController {
timeMap.put(id, timePeriodVOList);
}
// 将预约时间段从小到大排序
Set<Long> timeIds = timeMap.keySet();
for (Long timeId : timeIds) {
List<TimePeriodVO> timePeriodVOList = timeMap.get(timeId);
timePeriodVOList.sort((t1, t2) -> {
DateTime time1 = DateUtil.parse(t1.getTimeSlot().split("-")[0], "HH:mm");
DateTime time2 = DateUtil.parse(t2.getTimeSlot().split("-")[0], "HH:mm");
return time1.compareTo(time2); // 按照时间升序排序
});
}
// 封装预约日期集合
Set<Long> dateIds = dateMap.keySet();
for (Long dateId : dateIds) {
@ -545,6 +557,17 @@ public class GoodController {
timeMap.put(appId, timePeriodVOList);
}
// 将预约时间段从小到大排序
Set<Long> timeIds = timeMap.keySet();
for (Long timeId : timeIds) {
List<TimePeriodVO> timePeriodVOList = timeMap.get(timeId);
timePeriodVOList.sort((t1, t2) -> {
DateTime time1 = DateUtil.parse(t1.getTimeSlot().split("-")[0], "HH:mm");
DateTime time2 = DateUtil.parse(t2.getTimeSlot().split("-")[0], "HH:mm");
return time1.compareTo(time2); // 按照时间升序排序
});
}
Set<Long> dateIds = dateMap.keySet();
for (Long dateId : dateIds) {
AppointmentDateVO appointmentDateVO = dateMap.get(dateId);

View File

@ -0,0 +1,7 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.BookingTime;
public interface BookingTimeMapper extends BaseMapper<BookingTime> {
}

View File

@ -1,7 +0,0 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.TimeInterval;
public interface TimeIntervalMapper extends BaseMapper<TimeInterval> {
}

View File

@ -11,7 +11,7 @@ import java.util.List;
@Data
@Schema(description = "预约日期请求体", requiredProperties = {
"specificDate", "isAvailable", "timePeriodAddRequestList"
"goodId", "specificDate", "isAvailable", "timePeriodAddRequestList"
})
public class AppointmentDateSingleAddRequest implements Serializable {

View File

@ -1,6 +1,6 @@
package com.cultural.heritage.model.dto.book;
package com.cultural.heritage.model.dto.bookingDate;
import com.cultural.heritage.model.dto.timeinterval.TimeIntervalAddRequest;
import com.cultural.heritage.model.dto.bookingTime.BookingTimeAddRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -9,7 +9,7 @@ import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "预约日期添加请求体", requiredProperties = {"specificDate", "isAvailable", "type"})
@Schema(description = "预约日期添加请求体", requiredProperties = {"specificDate", "isAvailable", "bookingTimeAddRequestList"})
public class BookingDateAddRequest implements Serializable {
/**
@ -26,18 +26,11 @@ public class BookingDateAddRequest implements Serializable {
private Integer isAvailable;
/**
* 预约类别
*/
@Schema(description = "预约类别", example = "整套约拍")
private String type;
/**
* 预约时间段列表
*/
@Schema(description = "预约时间段列表")
private List<TimeIntervalAddRequest> timeIntervalAddRequestList;
private List<BookingTimeAddRequest> bookingTimeAddRequestList;
@Serial

View File

@ -1,4 +1,4 @@
package com.cultural.heritage.model.dto.book;
package com.cultural.heritage.model.dto.bookingDate;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -0,0 +1,44 @@
package com.cultural.heritage.model.dto.bookingDate.single;
import com.cultural.heritage.model.dto.bookingTime.BookingTimeAddRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "预约日期请求体", requiredProperties = {
"photoProductId", "specificDate", "isAvailable", "bookingTimeAddRequestList"
})
public class BookingDateSingleAddRequest implements Serializable {
/**
* 写真预约产品id
*/
@Schema(description = "写真预约产品id", example = "2")
private Long photoProductId;
/**
* 具体预约时间
*/
@Schema(description = "具体预约时间", example = "2024-12-04")
private String specificDate;
/**
* 是否可预约
*/
@Schema(description = "是否可预约", example = "1")
private Integer isAvailable;
/**
* 预约时间段列表
*/
private List<BookingTimeAddRequest> bookingTimeAddRequestList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,26 @@
package com.cultural.heritage.model.dto.bookingTime;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
@Schema(description = "写真预约时间添加请求体", requiredProperties = {
"timePoint"})
public class BookingTimeAddRequest implements Serializable {
/**
* 时间段
*/
@Schema(description = "时间点", example = "08:00")
private String timePoint;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,32 @@
package com.cultural.heritage.model.dto.bookingTime.single;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
@Schema(description = "写真预约时间添加请求体", requiredProperties = {
"timePoint", "bookingDateId"})
public class BookingTimeSingleAddRequest implements Serializable {
/**
* 时间段
*/
@Schema(description = "时间点", example = "08:00")
private String timePoint;
/**
* 预约日期id
*/
@Schema(description = "预约日期id", example = "10")
private Long bookingDateId;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -58,9 +58,9 @@ public class ServiceGoodAddRequest implements Serializable {
/**
* 未来几天的预约详情
* 未来的预约详情
*/
@Schema(description = "未来的预约时间表")
@Schema(description = "未来的预约详情")
private List<AppointmentDateAddRequest> appointmentDateAddRequestList;

View File

@ -1,11 +1,13 @@
package com.cultural.heritage.model.dto.photoProducts;
import com.cultural.heritage.model.dto.bookingDate.BookingDateAddRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
@ -80,6 +82,13 @@ public class PhotoProductsAddRequest implements Serializable {
/**
* 未来的预约详情
*/
@Schema(description = "未来的预约详情")
private List<BookingDateAddRequest> bookingDateAddRequestList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,40 +0,0 @@
package com.cultural.heritage.model.dto.timeinterval;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
@Schema(description = "写真预约时间段添加请求体", requiredProperties = {
"timeSlot", "minNumber", "maxNumber"})
public class TimeIntervalAddRequest implements Serializable {
/**
* 时间段
*/
@Schema(description = "时间段", example = "08:00-10:00")
private String timeSlot;
/**
* 最小预约人数
*/
@Schema(description = "最小预约人数", example = "3")
private Integer minNumber;
/**
* 最大预约人数
*/
@Schema(description = "最大预约人数", example = "10")
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -19,7 +19,7 @@ import java.util.Date;
public class BookingDate implements Serializable {
/**
* 预约日期
* 预约日期id
*/
@TableId(type = IdType.AUTO)
private Long id;
@ -38,9 +38,9 @@ public class BookingDate implements Serializable {
/**
* 预约类别
* 写真产品id
*/
private String type;
private Long photoProductId;
/**
@ -53,11 +53,6 @@ public class BookingDate implements Serializable {
*/
private Date updateTime;
/**
* 是否删除
*/
private Integer isDelete;
@Serial

View File

@ -12,34 +12,22 @@ import java.util.Date;
/**
* 写真预约时间段表
* @TableName time_interval
* @TableName booking_time
*/
@Data
@TableName("time_interval")
public class TimeInterval implements Serializable {
@TableName("booking_time")
public class BookingTime implements Serializable {
/**
* 预约时间id
* 预约时间id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 时间
* 预约时间
*/
private String timeSlot;
/**
* 最小预约人数
*/
private Integer minNumber;
/**
* 最大预约人数
*/
private Integer maxNumber;
private String timePoint;
/**
@ -57,10 +45,6 @@ public class TimeInterval implements Serializable {
*/
private Date updateTime;
/**
* 是否删除
*/
private Integer isDelete;
@Serial
private static final long serialVersionUID = 1L;

View File

@ -1,6 +1,6 @@
package com.cultural.heritage.model.vo.book;
package com.cultural.heritage.model.vo.bookingDate;
import com.cultural.heritage.model.vo.timeinterval.TimeIntervalVO;
import com.cultural.heritage.model.vo.bookingTime.BookingTimeVO;
import lombok.Data;
import java.io.Serial;
@ -30,15 +30,15 @@ public class BookingDateVO implements Serializable {
/**
* 预约类别
* 写真产品id
*/
private String type;
private Long photoProductId;
/**
* 预约时间
* 预约时间列表
*/
private List<TimeIntervalVO> timeIntervalVOList;
private List<BookingTimeVO> bookingTimeVOList;

View File

@ -0,0 +1,29 @@
package com.cultural.heritage.model.vo.bookingTime;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class BookingTimeVO implements Serializable {
/**
* 预约时间id
*/
private Long id;
/**
* 预约时间
*/
private String timePoint;
/**
* 预约日期id
*/
private Long bookingDateId;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,10 +1,12 @@
package com.cultural.heritage.model.vo.clothesinfo;
import com.cultural.heritage.model.vo.bookingDate.BookingDateVO;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
public class PhotoProductsVO implements Serializable {
@ -76,6 +78,12 @@ public class PhotoProductsVO implements Serializable {
private Integer isShelves;
/**
* 未来的预约情况
*/
private List<BookingDateVO> bookingDateVOList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,36 +0,0 @@
package com.cultural.heritage.model.vo.timeinterval;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class TimeIntervalVO implements Serializable {
/**
* 预约时间段id
*/
private Long id;
/**
* 时间段
*/
private String timeSlot;
/**
* 最小预约人数
*/
private Integer minNumber;
/**
* 最大预约人数
*/
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,13 @@
package com.cultural.heritage.service.book;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.BookingTime;
public interface BookingTimeService extends IService<BookingTime> {
/**
* 校验
*/
void validBookingTime(BookingTime bookingTime, boolean update);
}

View File

@ -1,13 +0,0 @@
package com.cultural.heritage.service.book;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.TimeInterval;
public interface TimeIntervalService extends IService<TimeInterval> {
/**
* 校验
*/
void validTimeInterval(TimeInterval timeInterval, boolean update);
}

View File

@ -19,17 +19,20 @@ public class BookingDateServiceImpl extends ServiceImpl<BookingDateMapper, Booki
Long dateId = bookingDate.getId();
String specificDate = bookingDate.getSpecificDate();
Integer isAvailable = bookingDate.getIsAvailable();
String type = bookingDate.getType();
Long photoProductId = bookingDate.getPhotoProductId();
if (update) {
if (dateId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "id参数错误");
}
}
if (ObjectUtils.isEmpty(photoProductId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "写真产品id参数为空");
}
if (ObjectUtils.isEmpty(isAvailable) || isAvailable != 1 && isAvailable != 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "是否可预约参数错误");
}
if (StringUtils.isAnyBlank(specificDate, type)) {
if (StringUtils.isAnyBlank(specificDate)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在字符串类型参数为空");
}

View File

@ -0,0 +1,39 @@
package com.cultural.heritage.service.book.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.mapper.BookingTimeMapper;
import com.cultural.heritage.model.entity.BookingTime;
import com.cultural.heritage.service.book.BookingTimeService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@Service
public class BookingTimeServiceImpl extends ServiceImpl<BookingTimeMapper, BookingTime> implements BookingTimeService {
/**
* 校验
*/
@Override
public void validBookingTime(BookingTime bookingTime, boolean update) {
Long id = bookingTime.getId();
String timePoint = bookingTime.getTimePoint();
Long bookingDateId = bookingTime.getBookingDateId();
if (update) {
if (id == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "预约日期id参数错误");
}
}
if (ObjectUtils.isEmpty(bookingDateId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在写真预约日期id参数为空");
}
if (StringUtils.isBlank(timePoint)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "时间段参数为空");
}
}
}

View File

@ -1,44 +0,0 @@
package com.cultural.heritage.service.book.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.mapper.TimeIntervalMapper;
import com.cultural.heritage.model.entity.TimeInterval;
import com.cultural.heritage.service.book.TimeIntervalService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@Service
public class TimeIntervalServiceImpl extends ServiceImpl<TimeIntervalMapper, TimeInterval> implements TimeIntervalService {
/**
* 校验
*/
@Override
public void validTimeInterval(TimeInterval timeInterval, boolean update) {
Long id = timeInterval.getId();
Integer minNumber = timeInterval.getMinNumber();
Integer maxNumber = timeInterval.getMaxNumber();
String timeSlot = timeInterval.getTimeSlot();
Long bookingDateId = timeInterval.getBookingDateId();
if (update) {
if (id == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "预约日期id参数错误");
}
}
if (ObjectUtils.anyNull(minNumber, maxNumber, bookingDateId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
}
if (minNumber > maxNumber) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "最小预约人数不能超过最大预约人数");
}
if (StringUtils.isBlank(timeSlot)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "时间段参数为空");
}
}
}

View File

@ -2,6 +2,6 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cultural.heritage.mapper.TimeIntervalMapper">
<mapper namespace="com.cultural.heritage.mapper.BookingTimeMapper">
</mapper>