更新了优惠券模块

This commit is contained in:
chen-xin-zhi 2025-03-01 22:18:16 +08:00
parent e9707e9c4d
commit 3fca0c6d09
4 changed files with 132 additions and 2 deletions

View File

@ -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<Boolean> addBatchBookingDate(@RequestBody List<BookingDateSingleAddRequest> bookingDateSingleAddRequestList) {
if (bookingDateSingleAddRequestList == null || bookingDateSingleAddRequestList.isEmpty()) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 批量添加当前商品的预约日期
List<BookingDate> bookingDateList = commonService.convertList(bookingDateSingleAddRequestList, BookingDate.class);
boolean saveBatch = bookingDateService.saveBatch(bookingDateList);
ThrowUtils.throwIf(!saveBatch, ErrorCode.OPERATION_ERROR, "预约日期批量添加失败");
List<BookingTime> bookingTimes = new ArrayList<>();
for (int i = 0; i < bookingDateSingleAddRequestList.size(); i++) {
Long bookingDateId = bookingDateList.get(i).getId();
List<BookingTimeAddRequest> bookingTimeAddRequestList = bookingDateSingleAddRequestList.get(i).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 result = bookingTimeService.saveBatch(bookingTimes);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "预约时间批量添加失败");
return ResultUtils.success(true);
}
}

View File

@ -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<List<ServiceGoodCardVO>> 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<String, Object> conditionMap = new HashMap<>();
conditionMap.put("isShelves", 1);
conditionMap.put("isGoodType", 0);
List<Good> goodList = commonService.findByFieldEqTargetFields(conditionMap, goodService);
goodList = goodList.stream().filter(good -> good.getName().contains(keyword)).toList();
List<ServiceGoodCardVO> serviceGoodCardVOS = commonService.convertList(goodList, ServiceGoodCardVO.class);
return ResultUtils.success(serviceGoodCardVOS);
}
/**
* 小程序端用户根据商品名和商品标签搜索常规类商品
* @param commonStringRequest 搜索关键词
* @return 服务类商品搜索结果页
*/
@PostMapping("/search/general")
@Operation(summary = "小程序端用户根据商品名和商品标签搜索常规类商品", description = "参数搜索关键词权限所有人方法名queryGeneralGoodByKeyword")
public BaseResponse<List<ServiceGoodCardVO>> 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<String, Object> conditionMap = new HashMap<>();
conditionMap.put("isShelves", 1);
conditionMap.put("isGoodType", 1);
List<Good> goodList = commonService.findByFieldEqTargetFields(conditionMap, goodService);
goodList = goodList.stream().filter(good -> {
String name = good.getName();
String label = good.getLabel();
List<String> labels = new ArrayList<>(Arrays.asList(label.split(";")));
labels.add(name);
for (String lab : labels) {
if (lab.contains(keyword)) return true;
}
return false;
}).toList();
List<ServiceGoodCardVO> serviceGoodCardVOS = commonService.convertList(goodList, ServiceGoodCardVO.class);
return ResultUtils.success(serviceGoodCardVOS);
}
/**
* 小程序端展示服务类商品卡片
* @return 服务类商品卡片列表

View File

@ -35,6 +35,12 @@ public class ServiceGoodCardVO implements Serializable {
private String goodImg;
/**
* 商品简介
*/
private String intro;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -282,8 +282,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> 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;
}