From 3fca0c6d09f2c1c5602346038b652f18a272020d Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Sat, 1 Mar 2025 22:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/BookingDateController.java | 48 +++++++++++++ .../controller/good/GoodController.java | 70 +++++++++++++++++++ .../model/vo/good/ServiceGoodCardVO.java | 6 ++ .../service/order/impl/OrderServiceImpl.java | 10 ++- 4 files changed, 132 insertions(+), 2 deletions(-) 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 b739ac6..0c2f08a 100644 --- a/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java +++ b/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java @@ -17,6 +17,7 @@ import com.cultural.heritage.model.dto.bookingTime.single.BookingTimeSingleAddRe import com.cultural.heritage.model.entity.*; import com.cultural.heritage.service.book.BookingDateService; import com.cultural.heritage.service.book.BookingTimeService; +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; @@ -28,6 +29,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.List; @RestController @@ -45,6 +47,10 @@ public class BookingDateController { private BookingTimeService bookingTimeService; + @Resource + private CommonService commonService; + + /** * Web端管理员根据id删除预约日期 @@ -188,5 +194,47 @@ public class BookingDateController { + /** + * Web端管理员批量添加预约日期 + * @param bookingDateSingleAddRequestList 预约日期添加请求体列表 + * @return 是否添加成功 + */ + @PostMapping("/addBatch") + @Operation(summary = "Web端管理员批量添加预约日期", description = "参数:预约日期添加请求体列表,权限:管理员(admin, boss),方法名:addBatchBookingDate") + @Transactional(rollbackFor = Exception.class) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse addBatchBookingDate(@RequestBody List bookingDateSingleAddRequestList) { + if (bookingDateSingleAddRequestList == null || bookingDateSingleAddRequestList.isEmpty()) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + // 批量添加当前商品的预约日期 + List bookingDateList = commonService.convertList(bookingDateSingleAddRequestList, BookingDate.class); + boolean saveBatch = bookingDateService.saveBatch(bookingDateList); + ThrowUtils.throwIf(!saveBatch, ErrorCode.OPERATION_ERROR, "预约日期批量添加失败"); + + List bookingTimes = new ArrayList<>(); + for (int i = 0; i < bookingDateSingleAddRequestList.size(); i++) { + Long bookingDateId = bookingDateList.get(i).getId(); + List bookingTimeAddRequestList = bookingDateSingleAddRequestList.get(i).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 result = bookingTimeService.saveBatch(bookingTimes); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "预约时间批量添加失败"); + + return ResultUtils.success(true); + } + + + + + + } 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 bdd7ab5..9392c91 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -6,6 +6,7 @@ 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.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.common.BaseResponse; @@ -16,6 +17,7 @@ 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.CommonStringRequest; import com.cultural.heritage.model.dto.appointment.AppointmentDateAddRequest; import com.cultural.heritage.model.dto.good.GoodAddRequest; import com.cultural.heritage.model.dto.good.GoodQueryRequest; @@ -605,6 +607,74 @@ public class GoodController { + + + + + + /** + * 小程序端用户根据商品名搜索服务类商品 + * @param commonStringRequest 搜索关键词 + * @return 常规类商品搜索结果页 + */ + @PostMapping("/search/service") + @Operation(summary = "小程序端用户根据商品名搜索服务类商品", description = "参数:搜索关键词,权限:所有人,方法名:queryServiceGoodByKeyword") + public BaseResponse> queryServiceGoodByKeyword(@RequestBody CommonStringRequest commonStringRequest) { + if (commonStringRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + String keyword = commonStringRequest.getType(); + ThrowUtils.throwIf(StringUtils.isBlank(keyword), ErrorCode.OPERATION_ERROR, "关键词不能为空"); + Map conditionMap = new HashMap<>(); + conditionMap.put("isShelves", 1); + conditionMap.put("isGoodType", 0); + List goodList = commonService.findByFieldEqTargetFields(conditionMap, goodService); + goodList = goodList.stream().filter(good -> good.getName().contains(keyword)).toList(); + List serviceGoodCardVOS = commonService.convertList(goodList, ServiceGoodCardVO.class); + return ResultUtils.success(serviceGoodCardVOS); + } + + + + + + /** + * 小程序端用户根据商品名和商品标签搜索常规类商品 + * @param commonStringRequest 搜索关键词 + * @return 服务类商品搜索结果页 + */ + @PostMapping("/search/general") + @Operation(summary = "小程序端用户根据商品名和商品标签搜索常规类商品", description = "参数:搜索关键词,权限:所有人,方法名:queryGeneralGoodByKeyword") + public BaseResponse> queryGeneralGoodByKeyword(@RequestBody CommonStringRequest commonStringRequest) { + if (commonStringRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + String keyword = commonStringRequest.getType(); + ThrowUtils.throwIf(StringUtils.isBlank(keyword), ErrorCode.OPERATION_ERROR, "关键词不能为空"); + Map conditionMap = new HashMap<>(); + conditionMap.put("isShelves", 1); + conditionMap.put("isGoodType", 1); + List goodList = commonService.findByFieldEqTargetFields(conditionMap, goodService); + goodList = goodList.stream().filter(good -> { + String name = good.getName(); + String label = good.getLabel(); + List labels = new ArrayList<>(Arrays.asList(label.split(";"))); + labels.add(name); + for (String lab : labels) { + if (lab.contains(keyword)) return true; + } + return false; + }).toList(); + List serviceGoodCardVOS = commonService.convertList(goodList, ServiceGoodCardVO.class); + return ResultUtils.success(serviceGoodCardVOS); + } + + + + + + + /** * 小程序端展示服务类商品卡片 * @return 服务类商品卡片列表 diff --git a/src/main/java/com/cultural/heritage/model/vo/good/ServiceGoodCardVO.java b/src/main/java/com/cultural/heritage/model/vo/good/ServiceGoodCardVO.java index 2729cbb..f673729 100644 --- a/src/main/java/com/cultural/heritage/model/vo/good/ServiceGoodCardVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/good/ServiceGoodCardVO.java @@ -35,6 +35,12 @@ public class ServiceGoodCardVO implements Serializable { private String goodImg; + /** + * 商品简介 + */ + private String intro; + + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java index 3a253bc..2a31dc0 100644 --- a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java @@ -282,8 +282,14 @@ public class OrderServiceImpl extends ServiceImpl implements // 清空购物车 if (isCartOrder) { - boolean remove = cartRecordService.removeBatchByIds(cartIds); - ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "清空购物车失败"); + if (isGeneral) { + boolean removeGeneral = cartRecordService.removeBatchByIds(cartIds); + ThrowUtils.throwIf(!removeGeneral, ErrorCode.OPERATION_ERROR, "清空常规类购物车失败"); + } else { + boolean removeService = cartExperienceService.removeBatchByIds(cartIds); + ThrowUtils.throwIf(!removeService, ErrorCode.OPERATION_ERROR, "清空服务类购物车失败"); + } + } return id; }