diff --git a/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java b/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java index 11988c9..a06b3bd 100644 --- a/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java +++ b/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java @@ -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 addBookingDate(@RequestBody List bookingDateAddRequestList) { - if (bookingDateAddRequestList == null) { + public BaseResponse delBookingDateById(@RequestBody CommonRequest commonRequest) { + if (commonRequest == null || commonRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } - // 添加写真预约日期 - List 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 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 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 timeIntervalAddRequestList = bookingDateAddRequest.getTimeIntervalAddRequestList(); - List 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> listBookingDateByType(@RequestBody CommonStringRequest commonStringRequest) { - if (commonStringRequest == null || StringUtils.isBlank(commonStringRequest.getType())) { + public BaseResponse 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 queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("type", type); - List bookingDateList = bookingDateService.list(queryWrapper); - List timeIntervalList = timeIntervalService.list(); - // 存储写真预约时间段的map集合(键:预约日期id, 值:预约时间段列表) - Map> timeMap = new HashMap<>(); - // 处理预约时间段,将预约时间段存入map集合 - for (TimeInterval timeInterval : timeIntervalList) { - TimeIntervalVO timeIntervalVO = new TimeIntervalVO(); - BeanUtils.copyProperties(timeInterval, timeIntervalVO); - Long bookingDateId = timeInterval.getBookingDateId(); - List timeIntervalVOS = timeMap.get(bookingDateId); - if (timeIntervalVOS == null) { - timeIntervalVOS = new ArrayList<>(); - } - timeIntervalVOS.add(timeIntervalVO); - timeMap.put(bookingDateId, timeIntervalVOS); - } - // 处理预约日期,填充当前预约日期对应的预约时间段 - List bookingDateVOList = new ArrayList<>(); - for (BookingDate bookingDate : bookingDateList) { - BookingDateVO bookingDateVO = new BookingDateVO(); - BeanUtils.copyProperties(bookingDate, bookingDateVO); - Long dateId = bookingDate.getId(); - List 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 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 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 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 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 bookingTimeAddRequestList = bookingDateSingleAddRequest.getBookingTimeAddRequestList(); + List 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 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 queryWrapper = new QueryWrapper<>(); -// queryWrapper.eq("type", type); -// return null; -// } } diff --git a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java index 9c4859e..12f3b07 100644 --- a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java +++ b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java @@ -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> map = new HashMap<>(); + + // 添加预约日期 + List bookingDateAddRequestList = photoProductsAddRequest.getBookingDateAddRequestList(); + List 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 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 bookingTimeAddRequestList = bookingDateAddRequest.getBookingTimeAddRequestList(); + List 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("photoProductId", id); + List bookingDateList = bookingDateService.list(queryWrapper); + List bookingDateIds = bookingDateList.stream().map(BookingDate::getId).toList(); + QueryWrapper 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 idList = commonBatchRequest.getIdList(); + // 删除写真产品下的预约时间 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("photoProductId", idList); + List bookingDateList = bookingDateService.list(queryWrapper); + List bookingDateIds = bookingDateList.stream().map(BookingDate::getId).toList(); + QueryWrapper 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 queryWrapper = photoProductsService.getQueryWrapper(photoProductsQueryRequest); Page page = photoProductsService.page(new Page<>(current, pageSize), queryWrapper); - // 封装服装类VO + // 获取写真产品列表 List records = page.getRecords(); - List photoProductsVOS = records.stream().map(photoProducts -> { + // 获取预约日期表 + List bookingDateList = commonService.getItemsByIds(records, bookingDateService, PhotoProducts::getId); + // 获取预约时间表 + List bookingTimeList = commonService.getItemsByIds(bookingDateList, bookingTimeService, BookingDate::getId); + // 封装成BookingTimeVO列表 + List 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 bookingDateVOS = new ArrayList<>(); + for (BookingDate bookingDate : bookingDateList) { + Long bookingDateId = bookingDate.getId(); + List 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 photoProductsVOList = new ArrayList<>(); + for (PhotoProducts photoProducts : records) { + Long photoProductsId = photoProducts.getId(); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("photoProductId", id); + List bookingDateList = bookingDateService.list(queryWrapper); + // 获取预约时间表 + List bookingTimeList = commonService.getItemsByIds(bookingDateList, bookingTimeService, BookingDate::getId); + // 封装成BookingTimeVO列表 + List 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 bookingDateVOS = new ArrayList<>(); + for (BookingDate bookingDate : bookingDateList) { + Long bookingDateId = bookingDate.getId(); + List 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 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 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); } diff --git a/src/main/java/com/cultural/heritage/controller/good/GoodController.java b/src/main/java/com/cultural/heritage/controller/good/GoodController.java index eaf142d..77b54b7 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -463,6 +463,18 @@ public class GoodController { timeMap.put(id, timePeriodVOList); } + + // 将预约时间段从小到大排序 + Set timeIds = timeMap.keySet(); + for (Long timeId : timeIds) { + List 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 dateIds = dateMap.keySet(); for (Long dateId : dateIds) { @@ -545,6 +557,17 @@ public class GoodController { timeMap.put(appId, timePeriodVOList); } + // 将预约时间段从小到大排序 + Set timeIds = timeMap.keySet(); + for (Long timeId : timeIds) { + List 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 dateIds = dateMap.keySet(); for (Long dateId : dateIds) { AppointmentDateVO appointmentDateVO = dateMap.get(dateId); diff --git a/src/main/java/com/cultural/heritage/mapper/BookingTimeMapper.java b/src/main/java/com/cultural/heritage/mapper/BookingTimeMapper.java new file mode 100644 index 0000000..7692085 --- /dev/null +++ b/src/main/java/com/cultural/heritage/mapper/BookingTimeMapper.java @@ -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 { +} diff --git a/src/main/java/com/cultural/heritage/mapper/TimeIntervalMapper.java b/src/main/java/com/cultural/heritage/mapper/TimeIntervalMapper.java deleted file mode 100644 index 62d589e..0000000 --- a/src/main/java/com/cultural/heritage/mapper/TimeIntervalMapper.java +++ /dev/null @@ -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 { -} diff --git a/src/main/java/com/cultural/heritage/model/dto/appointment/single/AppointmentDateSingleAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/appointment/single/AppointmentDateSingleAddRequest.java index df4b780..f05e99d 100644 --- a/src/main/java/com/cultural/heritage/model/dto/appointment/single/AppointmentDateSingleAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/appointment/single/AppointmentDateSingleAddRequest.java @@ -11,7 +11,7 @@ import java.util.List; @Data @Schema(description = "预约日期请求体", requiredProperties = { - "specificDate", "isAvailable", "timePeriodAddRequestList" + "goodId", "specificDate", "isAvailable", "timePeriodAddRequestList" }) public class AppointmentDateSingleAddRequest implements Serializable { diff --git a/src/main/java/com/cultural/heritage/model/dto/book/BookingDateAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateAddRequest.java similarity index 66% rename from src/main/java/com/cultural/heritage/model/dto/book/BookingDateAddRequest.java rename to src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateAddRequest.java index 9dc576e..3f8cc4b 100644 --- a/src/main/java/com/cultural/heritage/model/dto/book/BookingDateAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateAddRequest.java @@ -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 timeIntervalAddRequestList; + private List bookingTimeAddRequestList; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/book/BookingDateUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateUpdateRequest.java similarity index 94% rename from src/main/java/com/cultural/heritage/model/dto/book/BookingDateUpdateRequest.java rename to src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateUpdateRequest.java index 0e89bdd..6ae88e1 100644 --- a/src/main/java/com/cultural/heritage/model/dto/book/BookingDateUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/bookingDate/BookingDateUpdateRequest.java @@ -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; diff --git a/src/main/java/com/cultural/heritage/model/dto/bookingDate/single/BookingDateSingleAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/bookingDate/single/BookingDateSingleAddRequest.java new file mode 100644 index 0000000..4700e64 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/bookingDate/single/BookingDateSingleAddRequest.java @@ -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 bookingTimeAddRequestList; + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/bookingTime/BookingTimeAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/bookingTime/BookingTimeAddRequest.java new file mode 100644 index 0000000..200f9a3 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/bookingTime/BookingTimeAddRequest.java @@ -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; + +} diff --git a/src/main/java/com/cultural/heritage/model/dto/bookingTime/single/BookingTimeSingleAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/bookingTime/single/BookingTimeSingleAddRequest.java new file mode 100644 index 0000000..eae704e --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/bookingTime/single/BookingTimeSingleAddRequest.java @@ -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; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/good/service/ServiceGoodAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/service/ServiceGoodAddRequest.java index 010d234..e5bd231 100644 --- a/src/main/java/com/cultural/heritage/model/dto/good/service/ServiceGoodAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/good/service/ServiceGoodAddRequest.java @@ -58,9 +58,9 @@ public class ServiceGoodAddRequest implements Serializable { /** - * 未来几天的预约详情 + * 未来的预约详情 */ - @Schema(description = "未来的预约时间表") + @Schema(description = "未来的预约详情") private List appointmentDateAddRequestList; diff --git a/src/main/java/com/cultural/heritage/model/dto/photoProducts/PhotoProductsAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/photoProducts/PhotoProductsAddRequest.java index 8715969..75cacc0 100644 --- a/src/main/java/com/cultural/heritage/model/dto/photoProducts/PhotoProductsAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/photoProducts/PhotoProductsAddRequest.java @@ -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 bookingDateAddRequestList; + + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/dto/timeinterval/TimeIntervalAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/timeinterval/TimeIntervalAddRequest.java deleted file mode 100644 index 5401322..0000000 --- a/src/main/java/com/cultural/heritage/model/dto/timeinterval/TimeIntervalAddRequest.java +++ /dev/null @@ -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; - -} diff --git a/src/main/java/com/cultural/heritage/model/entity/BookingDate.java b/src/main/java/com/cultural/heritage/model/entity/BookingDate.java index fb338e8..a9ba4b8 100644 --- a/src/main/java/com/cultural/heritage/model/entity/BookingDate.java +++ b/src/main/java/com/cultural/heritage/model/entity/BookingDate.java @@ -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 diff --git a/src/main/java/com/cultural/heritage/model/entity/TimeInterval.java b/src/main/java/com/cultural/heritage/model/entity/BookingTime.java similarity index 63% rename from src/main/java/com/cultural/heritage/model/entity/TimeInterval.java rename to src/main/java/com/cultural/heritage/model/entity/BookingTime.java index 63d0868..8629f50 100644 --- a/src/main/java/com/cultural/heritage/model/entity/TimeInterval.java +++ b/src/main/java/com/cultural/heritage/model/entity/BookingTime.java @@ -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; diff --git a/src/main/java/com/cultural/heritage/model/vo/book/BookingDateVO.java b/src/main/java/com/cultural/heritage/model/vo/bookingDate/BookingDateVO.java similarity index 65% rename from src/main/java/com/cultural/heritage/model/vo/book/BookingDateVO.java rename to src/main/java/com/cultural/heritage/model/vo/bookingDate/BookingDateVO.java index bb1594c..6d3d463 100644 --- a/src/main/java/com/cultural/heritage/model/vo/book/BookingDateVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/bookingDate/BookingDateVO.java @@ -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 timeIntervalVOList; + private List bookingTimeVOList; diff --git a/src/main/java/com/cultural/heritage/model/vo/bookingTime/BookingTimeVO.java b/src/main/java/com/cultural/heritage/model/vo/bookingTime/BookingTimeVO.java new file mode 100644 index 0000000..7f1dd09 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/vo/bookingTime/BookingTimeVO.java @@ -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; +} diff --git a/src/main/java/com/cultural/heritage/model/vo/clothesinfo/PhotoProductsVO.java b/src/main/java/com/cultural/heritage/model/vo/clothesinfo/PhotoProductsVO.java index 2434381..72a3fe6 100644 --- a/src/main/java/com/cultural/heritage/model/vo/clothesinfo/PhotoProductsVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/clothesinfo/PhotoProductsVO.java @@ -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 bookingDateVOList; + + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/vo/timeinterval/TimeIntervalVO.java b/src/main/java/com/cultural/heritage/model/vo/timeinterval/TimeIntervalVO.java deleted file mode 100644 index 8ea45f0..0000000 --- a/src/main/java/com/cultural/heritage/model/vo/timeinterval/TimeIntervalVO.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/cultural/heritage/service/book/BookingTimeService.java b/src/main/java/com/cultural/heritage/service/book/BookingTimeService.java new file mode 100644 index 0000000..d8014e4 --- /dev/null +++ b/src/main/java/com/cultural/heritage/service/book/BookingTimeService.java @@ -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 { + + + /** + * 校验 + */ + void validBookingTime(BookingTime bookingTime, boolean update); +} diff --git a/src/main/java/com/cultural/heritage/service/book/TimeIntervalService.java b/src/main/java/com/cultural/heritage/service/book/TimeIntervalService.java deleted file mode 100644 index 3b41f12..0000000 --- a/src/main/java/com/cultural/heritage/service/book/TimeIntervalService.java +++ /dev/null @@ -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 { - - - /** - * 校验 - */ - void validTimeInterval(TimeInterval timeInterval, boolean update); -} diff --git a/src/main/java/com/cultural/heritage/service/book/impl/BookingDateServiceImpl.java b/src/main/java/com/cultural/heritage/service/book/impl/BookingDateServiceImpl.java index 245b5ef..d1dedfc 100644 --- a/src/main/java/com/cultural/heritage/service/book/impl/BookingDateServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/book/impl/BookingDateServiceImpl.java @@ -19,17 +19,20 @@ public class BookingDateServiceImpl extends ServiceImpl 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, "时间段参数为空"); + } + + } +} diff --git a/src/main/java/com/cultural/heritage/service/book/impl/TimeIntervalServiceImpl.java b/src/main/java/com/cultural/heritage/service/book/impl/TimeIntervalServiceImpl.java deleted file mode 100644 index 642bef6..0000000 --- a/src/main/java/com/cultural/heritage/service/book/impl/TimeIntervalServiceImpl.java +++ /dev/null @@ -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 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, "时间段参数为空"); - } - - } -} diff --git a/src/main/resources/mapper/TimeIntervalMapper.xml b/src/main/resources/mapper/BookingTimeMapper.xml similarity index 71% rename from src/main/resources/mapper/TimeIntervalMapper.xml rename to src/main/resources/mapper/BookingTimeMapper.xml index 25ac858..b58f914 100644 --- a/src/main/resources/mapper/TimeIntervalMapper.xml +++ b/src/main/resources/mapper/BookingTimeMapper.xml @@ -2,6 +2,6 @@ - + \ No newline at end of file