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 a969725..08f5dde 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -12,10 +12,16 @@ import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonDelBatchRequest; import com.cultural.heritage.model.dto.CommonRequest; +import com.cultural.heritage.model.dto.appointment.AppointmentDateAddRequest; import com.cultural.heritage.model.dto.good.GoodAddRequest; import com.cultural.heritage.model.dto.good.GoodQueryRequest; import com.cultural.heritage.model.dto.good.GoodUpdateRequest; +import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest; +import com.cultural.heritage.model.entity.AppointmentDate; +import com.cultural.heritage.model.entity.AppointmentNumber; import com.cultural.heritage.model.entity.Good; +import com.cultural.heritage.service.good.AppointmentDateService; +import com.cultural.heritage.service.good.AppointmentNumberService; import com.cultural.heritage.service.good.GoodService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -39,14 +45,23 @@ import java.util.List; @Tag(name = "商品管理模块") public class GoodController { + @Resource private GoodService goodService; + @Resource + private AppointmentNumberService appointmentNumberService; + + + @Resource + private AppointmentDateService appointmentDateService; + + /** * 添加商品 * @param goodAddRequest 商品添加请求体 - * @return + * @return 是否添加成功 */ @PostMapping("/add") @Operation(summary = "Web端管理员添加商品", description = "参数:商品添加请求体,权限:管理员(admin, boss),方法名:addGood") @@ -63,6 +78,50 @@ public class GoodController { } + + + /** + * 添加服务类商品 + * @param serviceGoodAddRequest 服务类商品添加请求体 + * @return 是否添加成功 + */ + @PostMapping("/add/service") + @Operation(summary = "Web管理员添加服务类商品", description = "参数:服务类商品添加请求体,权限:管理员(admin, boss),方法名:addServiceGood") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse addServiceGood(@RequestBody ServiceGoodAddRequest serviceGoodAddRequest) { + if (serviceGoodAddRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + // 向商品表插入服务类商品的基本信息 + Good good = new Good(); + BeanUtils.copyProperties(serviceGoodAddRequest, good); + boolean save = goodService.save(good); + ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR); + + // 向预约人数范围表插入服务类商品的预约人数信息 + Long id = good.getId(); + AppointmentNumber appointmentNumber = new AppointmentNumber(); + BeanUtils.copyProperties(serviceGoodAddRequest, appointmentNumber); + appointmentNumber.setGoodId(id); + boolean result = appointmentNumberService.save(appointmentNumber); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); + + // 向预约日期表中批量插入服务类商品的预约信息 + List appointmentDateAddRequestList = serviceGoodAddRequest.getAppointmentDateAddRequestList(); + List appointmentDates = appointmentDateAddRequestList.stream().map(appointmentDateAddRequest -> { + AppointmentDate appointmentDate = new AppointmentDate(); + BeanUtils.copyProperties(appointmentDateAddRequest, appointmentDate); + appointmentDate.setGoodId(id); + return appointmentDate; + }).toList(); + boolean isSuccess = appointmentDateService.saveBatch(appointmentDates); + ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR); + + return ResultUtils.success(true); + } + + + /** * 删除商品 * @param deleteRequest 商品删除请求体 @@ -75,12 +134,46 @@ public class GoodController { if (deleteRequest == null || deleteRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } - boolean result = goodService.removeById(deleteRequest.getId()); + Long id = deleteRequest.getId(); + boolean result = goodService.removeById(id); ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); return ResultUtils.success(true); } + + /** + * 删除服务类商品 + * @param deleteRequest 服务类商品删除请求体 + * @return 是否删除成功 + */ + @PostMapping("/delete/service") + @Operation(summary = "Web端管理员删除服务类商品", description = "参数: 商品删除请求体,权限:管理员(admin, boss),方法名:deleteServiceGood") + public BaseResponse deleteServiceGood(@RequestBody CommonRequest deleteRequest) { + if (deleteRequest == null || deleteRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + // 删除商品表中的服务类商品 + Long id = deleteRequest.getId(); + boolean result = goodService.removeById(id); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); + + // 删除预约人数范围表中与该商品关联的记录 + QueryWrapper numberQueryWrapper = new QueryWrapper<>(); + numberQueryWrapper.eq("goodId", id); + boolean remove = appointmentNumberService.remove(numberQueryWrapper); + ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR); + + // 删除预约日期表中与该商品关联的记录 + QueryWrapper dateQueryWrapper = new QueryWrapper<>(); + dateQueryWrapper.eq("goodId", id); + boolean isSuccess = appointmentDateService.remove(dateQueryWrapper); + ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR); + + return ResultUtils.success(true); + } + + /** * 更新商品 * @param goodUpdateRequest 商品更新请求体 diff --git a/src/main/java/com/cultural/heritage/model/dto/appointment/AppointmentDateAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/appointment/AppointmentDateAddRequest.java new file mode 100644 index 0000000..967e977 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/appointment/AppointmentDateAddRequest.java @@ -0,0 +1,38 @@ +package com.cultural.heritage.model.dto.appointment; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Schema(description = "预约日期请求体", requiredProperties = {"specificDate", "timeSlot", "isAvailable"}) +public class AppointmentDateAddRequest implements Serializable { + + + /** + * 预约具体日期 + */ + @Schema(description = "预约具体日期", example = "2024-11-09") + private String specificDate; + + + /** + * 预约时间段 + */ + @Schema(description = "预约时间段", example = "9:00-11:00;12:00-14:00") + private String timeSlot; + + + /** + * 是否可预约 + */ + @Schema(description = "是否可预约", example = "1") + private Integer isAvailable; + + + + @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 new file mode 100644 index 0000000..8c32946 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/good/service/ServiceGoodAddRequest.java @@ -0,0 +1,41 @@ +package com.cultural.heritage.model.dto.good.service; + +import com.cultural.heritage.model.dto.appointment.AppointmentDateAddRequest; +import com.cultural.heritage.model.dto.good.GoodAddRequest; +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 = {"minNumber", "maxNumber", "appointmentDateAddRequestList"}) +public class ServiceGoodAddRequest extends GoodAddRequest implements Serializable { + + + /** + * 最小预约人数 + */ + @Schema(description = "最小预约人数", example = "5") + private Integer minNumber; + + + /** + * 最大预约人数 + */ + @Schema(description = "最大预约人数", example = "10") + private Integer maxNumber; + + + /** + * 未来n个月的预约详情 + */ + @Schema(description = "未来n个月的预约详情") + private List appointmentDateAddRequestList; + + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/entity/AppointmentDate.java b/src/main/java/com/cultural/heritage/model/entity/AppointmentDate.java index 61899e0..c1e7d4c 100644 --- a/src/main/java/com/cultural/heritage/model/entity/AppointmentDate.java +++ b/src/main/java/com/cultural/heritage/model/entity/AppointmentDate.java @@ -36,6 +36,12 @@ public class AppointmentDate implements Serializable { private String timeSlot; + /** + * 是否可预约 + */ + private Integer isAvailable; + + /** * 商品id */ diff --git a/src/main/java/com/cultural/heritage/model/entity/AppointmentNumber.java b/src/main/java/com/cultural/heritage/model/entity/AppointmentNumber.java index 0d7d970..4ca9caf 100644 --- a/src/main/java/com/cultural/heritage/model/entity/AppointmentNumber.java +++ b/src/main/java/com/cultural/heritage/model/entity/AppointmentNumber.java @@ -1,5 +1,7 @@ package com.cultural.heritage.model.entity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -17,6 +19,7 @@ public class AppointmentNumber implements Serializable { /** * 预约人数范围id */ + @TableId(type = IdType.AUTO) private Long id; @@ -35,7 +38,7 @@ public class AppointmentNumber implements Serializable { /** * 商品id */ - private Integer goodId; + private Long goodId; @Serial